mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-26 10:19:45 +03:00
0031702: Visualization, TKOpenGl - hatching interior is ignored in second View within the Viewer
Current state variables have been moved out from OpenGl_LineAttributes to OpenGl_Context.
This commit is contained in:
parent
5980a9fb23
commit
76fada6839
@ -221,6 +221,8 @@ OpenGl_Context::OpenGl_Context (const Handle(OpenGl_Caps)& theCaps)
|
|||||||
myPBRSpecIBLMapTexUnit (Graphic3d_TextureUnit_PbrIblSpecular),
|
myPBRSpecIBLMapTexUnit (Graphic3d_TextureUnit_PbrIblSpecular),
|
||||||
myFrameStats (new OpenGl_FrameStats()),
|
myFrameStats (new OpenGl_FrameStats()),
|
||||||
myActiveMockTextures (0),
|
myActiveMockTextures (0),
|
||||||
|
myActiveHatchType (Aspect_HS_SOLID),
|
||||||
|
myHatchIsEnabled (false),
|
||||||
#if !defined(GL_ES_VERSION_2_0)
|
#if !defined(GL_ES_VERSION_2_0)
|
||||||
myPointSpriteOrig (GL_UPPER_LEFT),
|
myPointSpriteOrig (GL_UPPER_LEFT),
|
||||||
myRenderMode (GL_RENDER),
|
myRenderMode (GL_RENDER),
|
||||||
@ -4339,16 +4341,29 @@ Standard_Integer OpenGl_Context::SetPolygonMode (const Standard_Integer theMode)
|
|||||||
// =======================================================================
|
// =======================================================================
|
||||||
bool OpenGl_Context::SetPolygonHatchEnabled (const bool theIsEnabled)
|
bool OpenGl_Context::SetPolygonHatchEnabled (const bool theIsEnabled)
|
||||||
{
|
{
|
||||||
if (myHatchStyles.IsNull())
|
if (core11 == NULL)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if (myHatchStyles->IsEnabled() == theIsEnabled)
|
else if (myHatchIsEnabled == theIsEnabled)
|
||||||
{
|
{
|
||||||
return 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)
|
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)
|
||||||
|
{
|
||||||
|
core11fwd->glDisable (GL_POLYGON_STIPPLE);
|
||||||
|
}
|
||||||
|
return myActiveHatchType;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (myHatchStyles.IsNull()
|
||||||
|
&& !GetResource ("OpenGl_LineAttributes", myHatchStyles))
|
||||||
{
|
{
|
||||||
// share and register for release once the resource is no longer used
|
// share and register for release once the resource is no longer used
|
||||||
myHatchStyles = new OpenGl_LineAttributes();
|
myHatchStyles = new OpenGl_LineAttributes();
|
||||||
ShareResource ("OpenGl_LineAttributes", myHatchStyles);
|
ShareResource ("OpenGl_LineAttributes", myHatchStyles);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (myHatchStyles->TypeOfHatch() == theStyle->HatchType())
|
|
||||||
{
|
|
||||||
return theStyle->HatchType();
|
|
||||||
}
|
|
||||||
|
|
||||||
return myHatchStyles->SetTypeOfHatch (this, theStyle);
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
|
@ -652,10 +652,7 @@ public:
|
|||||||
Standard_EXPORT Standard_Integer SetPolygonMode (const Standard_Integer theMode);
|
Standard_EXPORT Standard_Integer SetPolygonMode (const Standard_Integer theMode);
|
||||||
|
|
||||||
//! @return cached enabled state of polygon hatching rasterization.
|
//! @return cached enabled state of polygon hatching rasterization.
|
||||||
bool IsPolygonHatchEnabled() const
|
bool IsPolygonHatchEnabled() const { return myHatchIsEnabled; }
|
||||||
{
|
|
||||||
return !myHatchStyles.IsNull() && myHatchStyles->TypeOfHatch() != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Sets enabled state of polygon hatching rasterization
|
//! Sets enabled state of polygon hatching rasterization
|
||||||
//! without affecting currently selected hatching pattern.
|
//! without affecting currently selected hatching pattern.
|
||||||
@ -663,10 +660,7 @@ public:
|
|||||||
Standard_EXPORT bool SetPolygonHatchEnabled (const bool theIsEnabled);
|
Standard_EXPORT bool SetPolygonHatchEnabled (const bool theIsEnabled);
|
||||||
|
|
||||||
//! @return cached state of polygon hatch type.
|
//! @return cached state of polygon hatch type.
|
||||||
Standard_Integer PolygonHatchStyle() const
|
Standard_Integer PolygonHatchStyle() const { return myActiveHatchType; }
|
||||||
{
|
|
||||||
return myHatchStyles.IsNull() ? Aspect_HS_SOLID : myHatchStyles->TypeOfHatch();
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Sets polygon hatch pattern.
|
//! Sets polygon hatch pattern.
|
||||||
//! Zero-index value is a default alias for solid filling.
|
//! 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
|
Standard_Integer myActiveMockTextures; //!< currently active mock sampler objects
|
||||||
Handle(OpenGl_FrameBuffer) myDefaultFbo; //!< default Frame Buffer Object
|
Handle(OpenGl_FrameBuffer) myDefaultFbo; //!< default Frame Buffer Object
|
||||||
Handle(OpenGl_LineAttributes) myHatchStyles; //!< resource holding predefined hatch styles patterns
|
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) myTextureRgbaBlack;//!< mock black texture returning (0, 0, 0, 0)
|
||||||
Handle(OpenGl_Texture) myTextureRgbaWhite;//!< mock white texture returning (1, 1, 1, 1)
|
Handle(OpenGl_Texture) myTextureRgbaWhite;//!< mock white texture returning (1, 1, 1, 1)
|
||||||
Standard_Integer myViewport[4]; //!< current viewport
|
Standard_Integer myViewport[4]; //!< current viewport
|
||||||
|
@ -25,8 +25,6 @@ IMPLEMENT_STANDARD_RTTIEXT(OpenGl_LineAttributes,OpenGl_Resource)
|
|||||||
// purpose :
|
// purpose :
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
OpenGl_LineAttributes::OpenGl_LineAttributes()
|
OpenGl_LineAttributes::OpenGl_LineAttributes()
|
||||||
: myTypeOfHatch (0),
|
|
||||||
myIsEnabled (true)
|
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
@ -46,9 +44,9 @@ OpenGl_LineAttributes::~OpenGl_LineAttributes()
|
|||||||
// =======================================================================
|
// =======================================================================
|
||||||
void OpenGl_LineAttributes::Release (OpenGl_Context* theGlCtx)
|
void OpenGl_LineAttributes::Release (OpenGl_Context* theGlCtx)
|
||||||
{
|
{
|
||||||
// Delete surface patterns
|
|
||||||
#if !defined(GL_ES_VERSION_2_0)
|
#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())
|
for (OpenGl_MapOfHatchStylesAndIds::Iterator anIter (myStyles); anIter.More(); anIter.Next())
|
||||||
{
|
{
|
||||||
@ -69,12 +67,7 @@ unsigned int OpenGl_LineAttributes::init (const OpenGl_Context* theGlCtx,
|
|||||||
const Handle(Graphic3d_HatchStyle)& theStyle)
|
const Handle(Graphic3d_HatchStyle)& theStyle)
|
||||||
{
|
{
|
||||||
#if !defined(GL_ES_VERSION_2_0)
|
#if !defined(GL_ES_VERSION_2_0)
|
||||||
if (theGlCtx->core11 == NULL)
|
const unsigned int aListId = theGlCtx->core11->glGenLists(1);
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const unsigned int aListId = glGenLists(1);
|
|
||||||
theGlCtx->core11->glNewList ((GLuint)aListId, GL_COMPILE);
|
theGlCtx->core11->glNewList ((GLuint)aListId, GL_COMPILE);
|
||||||
theGlCtx->core11->glPolygonStipple ((const GLubyte*)theStyle->Pattern());
|
theGlCtx->core11->glPolygonStipple ((const GLubyte*)theStyle->Pattern());
|
||||||
theGlCtx->core11->glEndList();
|
theGlCtx->core11->glEndList();
|
||||||
@ -90,17 +83,16 @@ unsigned int OpenGl_LineAttributes::init (const OpenGl_Context* theGlCtx,
|
|||||||
// function : SetTypeOfHatch
|
// function : SetTypeOfHatch
|
||||||
// purpose :
|
// purpose :
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
int OpenGl_LineAttributes::SetTypeOfHatch (const OpenGl_Context* theGlCtx,
|
bool OpenGl_LineAttributes::SetTypeOfHatch (const OpenGl_Context* theGlCtx,
|
||||||
const Handle(Graphic3d_HatchStyle)& theStyle)
|
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;
|
unsigned int aGpuListId = 0;
|
||||||
if (!myStyles.Find (theStyle, aGpuListId))
|
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 !defined(GL_ES_VERSION_2_0)
|
||||||
if (theGlCtx->core11 == NULL)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else if (theStyle->HatchType() != 0)
|
|
||||||
{
|
|
||||||
theGlCtx->core11->glCallList ((GLuint)aGpuListId);
|
theGlCtx->core11->glCallList ((GLuint)aGpuListId);
|
||||||
|
|
||||||
if (myIsEnabled)
|
|
||||||
{
|
|
||||||
theGlCtx->core11fwd->glEnable (GL_POLYGON_STIPPLE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
theGlCtx->core11fwd->glDisable (GL_POLYGON_STIPPLE);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
(void )theGlCtx;
|
|
||||||
#endif
|
#endif
|
||||||
myTypeOfHatch = theStyle->HatchType();
|
return true;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
@ -18,9 +18,6 @@
|
|||||||
|
|
||||||
#include <OpenGl_Resource.hxx>
|
#include <OpenGl_Resource.hxx>
|
||||||
|
|
||||||
#include <Aspect_TypeOfLine.hxx>
|
|
||||||
#include <Aspect_TypeOfMarker.hxx>
|
|
||||||
#include <Font_FontAspect.hxx>
|
|
||||||
#include <Graphic3d_HatchStyle.hxx>
|
#include <Graphic3d_HatchStyle.hxx>
|
||||||
#include <NCollection_DataMap.hxx>
|
#include <NCollection_DataMap.hxx>
|
||||||
|
|
||||||
@ -28,26 +25,16 @@ typedef NCollection_DataMap<Handle(Graphic3d_HatchStyle), unsigned int> OpenGl_M
|
|||||||
|
|
||||||
class OpenGl_Context;
|
class OpenGl_Context;
|
||||||
|
|
||||||
//! Utility class to manage OpenGL state of polygon hatching rasterization
|
DEFINE_STANDARD_HANDLE(OpenGl_LineAttributes, OpenGl_Resource)
|
||||||
//! and keeping its cached state. The hatching rasterization is implemented
|
|
||||||
//! using glPolygonStipple function of OpenGL. State of hatching is controlled
|
//! Utility class to manage OpenGL resources of polygon hatching styles.
|
||||||
//! by two parameters - type of hatching and IsEnabled parameter.
|
//! @note the implementation is not supported by Core Profile and by ES version.
|
||||||
//! 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.
|
|
||||||
class OpenGl_LineAttributes : public OpenGl_Resource
|
class OpenGl_LineAttributes : public OpenGl_Resource
|
||||||
{
|
{
|
||||||
|
DEFINE_STANDARD_RTTIEXT(OpenGl_LineAttributes, OpenGl_Resource)
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//! Default constructor.
|
//! Default constructor.
|
||||||
//! By default the parameters are:
|
|
||||||
//! - IsEnabled (true),
|
|
||||||
//! - TypeOfHatch (0).
|
|
||||||
Standard_EXPORT OpenGl_LineAttributes();
|
Standard_EXPORT OpenGl_LineAttributes();
|
||||||
|
|
||||||
//! Default destructor.
|
//! Default destructor.
|
||||||
@ -59,35 +46,19 @@ public:
|
|||||||
//! Returns estimated GPU memory usage - not implemented.
|
//! Returns estimated GPU memory usage - not implemented.
|
||||||
virtual Standard_Size EstimatedDataSize() const Standard_OVERRIDE { return 0; }
|
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.
|
//! Sets type of the hatch.
|
||||||
Standard_EXPORT int SetTypeOfHatch (const OpenGl_Context* theGlCtx,
|
Standard_EXPORT bool SetTypeOfHatch (const OpenGl_Context* theGlCtx,
|
||||||
const Handle(Graphic3d_HatchStyle)& theStyle);
|
const Handle(Graphic3d_HatchStyle)& theStyle);
|
||||||
|
|
||||||
//! Current enabled state of the hatching rasterization.
|
private:
|
||||||
bool IsEnabled() const { return myIsEnabled; }
|
|
||||||
|
|
||||||
//! Turns on/off the hatching rasterization rasterization.
|
|
||||||
Standard_EXPORT bool SetEnabled (const OpenGl_Context* theGlCtx, const bool theToEnable);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
unsigned int init (const OpenGl_Context* theGlCtx,
|
unsigned int init (const OpenGl_Context* theGlCtx,
|
||||||
const Handle(Graphic3d_HatchStyle)& theStyle);
|
const Handle(Graphic3d_HatchStyle)& theStyle);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
int myTypeOfHatch; //!< Currently activated type of hatch
|
|
||||||
bool myIsEnabled; //!< Current enabled state of hatching rasterization.
|
|
||||||
OpenGl_MapOfHatchStylesAndIds myStyles; //!< Hatch patterns
|
OpenGl_MapOfHatchStylesAndIds myStyles; //!< Hatch patterns
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
DEFINE_STANDARD_RTTIEXT(OpenGl_LineAttributes,OpenGl_Resource)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
DEFINE_STANDARD_HANDLE(OpenGl_LineAttributes, OpenGl_Resource)
|
|
||||||
|
|
||||||
#endif // _OpenGl_LineAttributes_Header
|
#endif // _OpenGl_LineAttributes_Header
|
||||||
|
23
tests/bugs/vis/bug31702
Normal file
23
tests/bugs/vis/bug31702
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user