diff --git a/src/OpenGl/OpenGl_Context.cxx b/src/OpenGl/OpenGl_Context.cxx index 01413d530b..257f8d425f 100644 --- a/src/OpenGl/OpenGl_Context.cxx +++ b/src/OpenGl/OpenGl_Context.cxx @@ -221,6 +221,8 @@ OpenGl_Context::OpenGl_Context (const Handle(OpenGl_Caps)& theCaps) myPBRSpecIBLMapTexUnit (Graphic3d_TextureUnit_PbrIblSpecular), myFrameStats (new OpenGl_FrameStats()), myActiveMockTextures (0), + myActiveHatchType (Aspect_HS_SOLID), + myHatchIsEnabled (false), #if !defined(GL_ES_VERSION_2_0) myPointSpriteOrig (GL_UPPER_LEFT), myRenderMode (GL_RENDER), @@ -4339,16 +4341,29 @@ Standard_Integer OpenGl_Context::SetPolygonMode (const Standard_Integer theMode) // ======================================================================= bool OpenGl_Context::SetPolygonHatchEnabled (const bool theIsEnabled) { - if (myHatchStyles.IsNull()) + if (core11 == NULL) { return false; } - else if (myHatchStyles->IsEnabled() == theIsEnabled) + else if (myHatchIsEnabled == theIsEnabled) { return theIsEnabled; } - return myHatchStyles->SetEnabled (this, theIsEnabled); + const bool anOldIsEnabled = myHatchIsEnabled; +#if !defined(GL_ES_VERSION_2_0) + if (theIsEnabled + && myActiveHatchType != Aspect_HS_SOLID) + { + core11fwd->glEnable (GL_POLYGON_STIPPLE); + } + else + { + core11fwd->glDisable (GL_POLYGON_STIPPLE); + } +#endif + myHatchIsEnabled = theIsEnabled; + return anOldIsEnabled; } // ======================================================================= @@ -4357,26 +4372,43 @@ bool OpenGl_Context::SetPolygonHatchEnabled (const bool theIsEnabled) // ======================================================================= Standard_Integer OpenGl_Context::SetPolygonHatchStyle (const Handle(Graphic3d_HatchStyle)& theStyle) { - if (theStyle.IsNull()) + const Standard_Integer aNewStyle = !theStyle.IsNull() ? theStyle->HatchType() : Aspect_HS_SOLID; + if (myActiveHatchType == aNewStyle + || core11 == NULL) { - return 0; + return myActiveHatchType; } - if (myHatchStyles.IsNull()) +#if !defined(GL_ES_VERSION_2_0) + if (aNewStyle == Aspect_HS_SOLID) { - if (!GetResource ("OpenGl_LineAttributes", myHatchStyles)) + if (myHatchIsEnabled) { - // share and register for release once the resource is no longer used - myHatchStyles = new OpenGl_LineAttributes(); - ShareResource ("OpenGl_LineAttributes", myHatchStyles); + core11fwd->glDisable (GL_POLYGON_STIPPLE); } - } - if (myHatchStyles->TypeOfHatch() == theStyle->HatchType()) - { - return theStyle->HatchType(); + return myActiveHatchType; } - return myHatchStyles->SetTypeOfHatch (this, theStyle); + if (myHatchStyles.IsNull() + && !GetResource ("OpenGl_LineAttributes", myHatchStyles)) + { + // share and register for release once the resource is no longer used + myHatchStyles = new OpenGl_LineAttributes(); + ShareResource ("OpenGl_LineAttributes", myHatchStyles); + } + + const Standard_Integer anOldType = myActiveHatchType; + myActiveHatchType = aNewStyle; + myHatchStyles->SetTypeOfHatch (this, theStyle); + if (myHatchIsEnabled + && anOldType == Aspect_HS_SOLID) + { + core11fwd->glEnable (GL_POLYGON_STIPPLE); + } + return anOldType; +#else + return myActiveHatchType; +#endif } // ======================================================================= diff --git a/src/OpenGl/OpenGl_Context.hxx b/src/OpenGl/OpenGl_Context.hxx index aed802a306..916478e1a4 100644 --- a/src/OpenGl/OpenGl_Context.hxx +++ b/src/OpenGl/OpenGl_Context.hxx @@ -652,10 +652,7 @@ public: Standard_EXPORT Standard_Integer SetPolygonMode (const Standard_Integer theMode); //! @return cached enabled state of polygon hatching rasterization. - bool IsPolygonHatchEnabled() const - { - return !myHatchStyles.IsNull() && myHatchStyles->TypeOfHatch() != 0; - } + bool IsPolygonHatchEnabled() const { return myHatchIsEnabled; } //! Sets enabled state of polygon hatching rasterization //! without affecting currently selected hatching pattern. @@ -663,10 +660,7 @@ public: Standard_EXPORT bool SetPolygonHatchEnabled (const bool theIsEnabled); //! @return cached state of polygon hatch type. - Standard_Integer PolygonHatchStyle() const - { - return myHatchStyles.IsNull() ? Aspect_HS_SOLID : myHatchStyles->TypeOfHatch(); - } + Standard_Integer PolygonHatchStyle() const { return myActiveHatchType; } //! Sets polygon hatch pattern. //! Zero-index value is a default alias for solid filling. @@ -1180,6 +1174,8 @@ private: //! @name fields tracking current state Standard_Integer myActiveMockTextures; //!< currently active mock sampler objects Handle(OpenGl_FrameBuffer) myDefaultFbo; //!< default Frame Buffer Object Handle(OpenGl_LineAttributes) myHatchStyles; //!< resource holding predefined hatch styles patterns + Standard_Integer myActiveHatchType; //!< currently activated type of polygon hatch + Standard_Boolean myHatchIsEnabled; //!< current enabled state of polygon hatching rasterization Handle(OpenGl_Texture) myTextureRgbaBlack;//!< mock black texture returning (0, 0, 0, 0) Handle(OpenGl_Texture) myTextureRgbaWhite;//!< mock white texture returning (1, 1, 1, 1) Standard_Integer myViewport[4]; //!< current viewport diff --git a/src/OpenGl/OpenGl_LineAttributes.cxx b/src/OpenGl/OpenGl_LineAttributes.cxx index c4b09b4d32..58b01486d8 100644 --- a/src/OpenGl/OpenGl_LineAttributes.cxx +++ b/src/OpenGl/OpenGl_LineAttributes.cxx @@ -25,8 +25,6 @@ IMPLEMENT_STANDARD_RTTIEXT(OpenGl_LineAttributes,OpenGl_Resource) // purpose : // ======================================================================= OpenGl_LineAttributes::OpenGl_LineAttributes() -: myTypeOfHatch (0), - myIsEnabled (true) { // } @@ -46,9 +44,9 @@ OpenGl_LineAttributes::~OpenGl_LineAttributes() // ======================================================================= void OpenGl_LineAttributes::Release (OpenGl_Context* theGlCtx) { - // Delete surface patterns #if !defined(GL_ES_VERSION_2_0) - if (theGlCtx != NULL && theGlCtx->IsValid()) + if (theGlCtx != NULL + && theGlCtx->IsValid()) { for (OpenGl_MapOfHatchStylesAndIds::Iterator anIter (myStyles); anIter.More(); anIter.Next()) { @@ -56,9 +54,9 @@ void OpenGl_LineAttributes::Release (OpenGl_Context* theGlCtx) } } #else - (void )theGlCtx; + (void )theGlCtx; #endif - myStyles.Clear(); + myStyles.Clear(); } // ======================================================================= @@ -69,12 +67,7 @@ unsigned int OpenGl_LineAttributes::init (const OpenGl_Context* theGlCtx, const Handle(Graphic3d_HatchStyle)& theStyle) { #if !defined(GL_ES_VERSION_2_0) - if (theGlCtx->core11 == NULL) - { - return 0; - } - - const unsigned int aListId = glGenLists(1); + const unsigned int aListId = theGlCtx->core11->glGenLists(1); theGlCtx->core11->glNewList ((GLuint)aListId, GL_COMPILE); theGlCtx->core11->glPolygonStipple ((const GLubyte*)theStyle->Pattern()); theGlCtx->core11->glEndList(); @@ -90,17 +83,16 @@ unsigned int OpenGl_LineAttributes::init (const OpenGl_Context* theGlCtx, // function : SetTypeOfHatch // purpose : // ======================================================================= -int OpenGl_LineAttributes::SetTypeOfHatch (const OpenGl_Context* theGlCtx, - const Handle(Graphic3d_HatchStyle)& theStyle) +bool OpenGl_LineAttributes::SetTypeOfHatch (const OpenGl_Context* theGlCtx, + const Handle(Graphic3d_HatchStyle)& theStyle) { - // Return if not initialized - if (theStyle.IsNull()) + if (theStyle.IsNull() + || theStyle->HatchType() == Aspect_HS_SOLID + || theGlCtx->core11 == NULL) { - return 0; + return false; } - const int anOldType = myTypeOfHatch; - unsigned int aGpuListId = 0; if (!myStyles.Find (theStyle, aGpuListId)) { @@ -109,66 +101,7 @@ int OpenGl_LineAttributes::SetTypeOfHatch (const OpenGl_Context* t } #if !defined(GL_ES_VERSION_2_0) - if (theGlCtx->core11 == NULL) - { - return 0; - } - else if (theStyle->HatchType() != 0) - { - theGlCtx->core11->glCallList ((GLuint)aGpuListId); - - if (myIsEnabled) - { - theGlCtx->core11fwd->glEnable (GL_POLYGON_STIPPLE); - } - } - else - { - theGlCtx->core11fwd->glDisable (GL_POLYGON_STIPPLE); - } -#else - (void )theGlCtx; + theGlCtx->core11->glCallList ((GLuint)aGpuListId); #endif - myTypeOfHatch = theStyle->HatchType(); - - return anOldType; -} - -// ======================================================================= -// function : SetEnabled -// purpose : -// ======================================================================= -bool OpenGl_LineAttributes::SetEnabled (const OpenGl_Context* theGlCtx, - const bool theToEnable) -{ - // Return if not initialized - if (myStyles.IsEmpty()) - { - return false; - } - - const bool anOldIsEnabled = myIsEnabled; - -#if !defined(GL_ES_VERSION_2_0) - if (theGlCtx->core11 == NULL) - { - return 0; - } - else if (theToEnable) - { - if (myTypeOfHatch != 0) - { - theGlCtx->core11fwd->glEnable (GL_POLYGON_STIPPLE); - } - } - else - { - theGlCtx->core11fwd->glDisable (GL_POLYGON_STIPPLE); - } -#else - (void )theGlCtx; -#endif - myIsEnabled = theToEnable; - - return anOldIsEnabled; + return true; } diff --git a/src/OpenGl/OpenGl_LineAttributes.hxx b/src/OpenGl/OpenGl_LineAttributes.hxx index 926f12b8da..deefbf0675 100644 --- a/src/OpenGl/OpenGl_LineAttributes.hxx +++ b/src/OpenGl/OpenGl_LineAttributes.hxx @@ -18,9 +18,6 @@ #include -#include -#include -#include #include #include @@ -28,26 +25,16 @@ typedef NCollection_DataMap OpenGl_M class OpenGl_Context; -//! Utility class to manage OpenGL state of polygon hatching rasterization -//! and keeping its cached state. The hatching rasterization is implemented -//! using glPolygonStipple function of OpenGL. State of hatching is controlled -//! by two parameters - type of hatching and IsEnabled parameter. -//! The hatching rasterization is enabled only if non-zero index pattern type -//! is selected (zero by default is reserved for solid filling) and if -//! IsEnabled flag is set to true. The IsEnabled parameter is useful for temporarily -//! turning on/off the hatching rasterization without making any costly GL calls -//! for changing the hatch pattern. This is a sharable resource class - it creates -//! OpenGL context objects for each hatch pattern to achieve quicker switching between -//! them, thesse GL objects are freed when the resource is released by owner context. -//! @note The implementation is not supported by Core Profile and by ES version. +DEFINE_STANDARD_HANDLE(OpenGl_LineAttributes, OpenGl_Resource) + +//! Utility class to manage OpenGL resources of polygon hatching styles. +//! @note the implementation is not supported by Core Profile and by ES version. class OpenGl_LineAttributes : public OpenGl_Resource { + DEFINE_STANDARD_RTTIEXT(OpenGl_LineAttributes, OpenGl_Resource) public: //! Default constructor. - //! By default the parameters are: - //! - IsEnabled (true), - //! - TypeOfHatch (0). Standard_EXPORT OpenGl_LineAttributes(); //! Default destructor. @@ -59,35 +46,19 @@ public: //! Returns estimated GPU memory usage - not implemented. virtual Standard_Size EstimatedDataSize() const Standard_OVERRIDE { return 0; } - //! Index of currently selected type of hatch. - int TypeOfHatch() const { return myTypeOfHatch; } - //! Sets type of the hatch. - Standard_EXPORT int SetTypeOfHatch (const OpenGl_Context* theGlCtx, - const Handle(Graphic3d_HatchStyle)& theStyle); + Standard_EXPORT bool SetTypeOfHatch (const OpenGl_Context* theGlCtx, + const Handle(Graphic3d_HatchStyle)& theStyle); - //! Current enabled state of the hatching rasterization. - bool IsEnabled() const { return myIsEnabled; } - - //! Turns on/off the hatching rasterization rasterization. - Standard_EXPORT bool SetEnabled (const OpenGl_Context* theGlCtx, const bool theToEnable); - -protected: +private: unsigned int init (const OpenGl_Context* theGlCtx, const Handle(Graphic3d_HatchStyle)& theStyle); protected: - int myTypeOfHatch; //!< Currently activated type of hatch - bool myIsEnabled; //!< Current enabled state of hatching rasterization. OpenGl_MapOfHatchStylesAndIds myStyles; //!< Hatch patterns -public: - - DEFINE_STANDARD_RTTIEXT(OpenGl_LineAttributes,OpenGl_Resource) }; -DEFINE_STANDARD_HANDLE(OpenGl_LineAttributes, OpenGl_Resource) - #endif // _OpenGl_LineAttributes_Header diff --git a/tests/bugs/vis/bug31702 b/tests/bugs/vis/bug31702 new file mode 100644 index 0000000000..10408af97b --- /dev/null +++ b/tests/bugs/vis/bug31702 @@ -0,0 +1,23 @@ +puts "============" +puts "0031702: Visualization, TKOpenGl - hatching interior is ignored in second View within the Viewer" +puts "============" +puts "" + +pload MODELING VISUALIZATION +vclear +vclose * +vinit v1/v1 +box b1 100 200 300 +vdisplay -dispMode 1 b1 +vfit +vaspects b1 -interior hatch +if { [vreadpixel 201 200 -rgb -name] != "BLACK" } { puts "Error: no hatching in first view" } +vdump ${imagedir}/${casename}_v1.png + +vinit v2/v1 +box b2 100 200 300 +vdisplay -dispMode 1 b2 +vfit +vaspects b2 -interior hatch +if { [vreadpixel 201 200 -rgb -name] != "BLACK" } { puts "Error: no hatching in second view" } +vdump ${imagedir}/${casename}_v2.png