1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-09 18:50:54 +03:00

0025710: Visualization - Eliminate all calls of glPushAttrib/glPopAttrib in TKOpenGl

This commit is contained in:
dbp 2015-03-24 20:30:05 +03:00 committed by apn
parent 39d24c098c
commit b34efb623c
3 changed files with 34 additions and 47 deletions

View File

@ -465,7 +465,6 @@ void OpenGl_PrimitiveArray::drawEdges (const TEL_COLOUR* theEdgeCo
const OpenGl_AspectLine* anAspect = theWorkspace->AspectLine (Standard_True);
#if !defined(GL_ES_VERSION_2_0)
glPushAttrib (GL_POLYGON_BIT);
glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
#endif
@ -522,9 +521,6 @@ void OpenGl_PrimitiveArray::drawEdges (const TEL_COLOUR* theEdgeCo
myVboAttribs->UnbindAttribute (aGlContext, Graphic3d_TOA_POS);
// restore line context
#if !defined(GL_ES_VERSION_2_0)
glPopAttrib();
#endif
theWorkspace->SetAspectLine (anAspectLineOld);
}
@ -789,6 +785,15 @@ void OpenGl_PrimitiveArray::Render (const Handle(OpenGl_Workspace)& theWorkspace
|| anAspectFace->InteriorStyle() == Aspect_IS_HIDDENLINE)
{
drawEdges (anEdgeColor, theWorkspace);
#if !defined(GL_ES_VERSION_2_0)
// restore OpenGL polygon mode if needed
if (anAspectFace->InteriorStyle() >= Aspect_IS_HATCH)
{
glPolygonMode (GL_FRONT_AND_BACK,
anAspectFace->InteriorStyle() == Aspect_IS_POINT ? GL_POINT : GL_FILL);
}
#endif
}
}

View File

@ -412,6 +412,12 @@ void OpenGl_Text::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
{
theWorkspace->EnableTexture (aPrevTexture);
}
// restore Z buffer settings
if (theWorkspace->UseZBuffer() && theWorkspace->UseDepthTest())
{
glEnable (GL_DEPTH_TEST);
}
}
// =======================================================================
@ -581,21 +587,14 @@ Handle(OpenGl_Font) OpenGl_Text::FindFont (const Handle(OpenGl_Context)& theCtx,
return aFont;
}
Handle(OpenGl_Context) aCtx = theCtx;
#if !defined(GL_ES_VERSION_2_0)
glPushAttrib (GL_TEXTURE_BIT);
#endif
aFont = new OpenGl_Font (aFontFt, theKey);
if (!aFont->Init (aCtx))
{
//glPopAttrib();
//return aFont; // out of resources?
}
#if !defined(GL_ES_VERSION_2_0)
glPopAttrib(); // texture bit
#endif
aCtx->ShareResource (theKey, aFont);
if (!aFont->Init (theCtx))
{
// out of resources?
}
theCtx->ShareResource (theKey, aFont);
}
return aFont;
}
@ -705,8 +704,6 @@ void OpenGl_Text::render (const Handle(OpenGl_PrinterContext)& thePrintCtx,
#if !defined(GL_ES_VERSION_2_0)
// push enabled flags to the stack
glPushAttrib (GL_ENABLE_BIT);
glDisable (GL_LIGHTING);
// setup depth test
@ -818,15 +815,15 @@ void OpenGl_Text::render (const Handle(OpenGl_PrinterContext)& thePrintCtx,
glEnd();
glStencilFunc (GL_ALWAYS, 0, 0xFF);
// glPopAttrib() will reset state for us
//glDisable (GL_STENCIL_TEST);
//if (!myIs2d) glEnable (GL_DEPTH_TEST);
glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
}
// revert OpenGL state
glPopAttrib(); // enable bit
// reset OpenGL state
glDisable (GL_BLEND);
glDisable (GL_ALPHA_TEST);
glDisable (GL_STENCIL_TEST);
glDisable (GL_COLOR_LOGIC_OP);
// model view matrix was modified
theCtx->WorldViewState.Pop();

View File

@ -241,7 +241,7 @@ void OpenGl_View::DrawBackground (const Handle(OpenGl_Workspace)& theWorkspace)
aCtx->ProjectionState.Pop();
aCtx->ApplyProjectionMatrix();
if (theWorkspace->UseZBuffer())
if (theWorkspace->UseZBuffer() && theWorkspace->ToRedrawGL())
{
aCtx->core11fwd->glEnable (GL_DEPTH_TEST);
}
@ -586,26 +586,18 @@ void OpenGl_View::InvalidateBVHData (const Graphic3d_ZLayerId theLayerId)
/*----------------------------------------------------------------------*/
//ExecuteViewDisplay
void OpenGl_View::RenderStructs (const Handle(OpenGl_Workspace)& AWorkspace,
void OpenGl_View::RenderStructs (const Handle(OpenGl_Workspace)& theWorkspace,
const Standard_Boolean theToDrawImmediate)
{
if ( myZLayers.NbStructures() <= 0 )
return;
const Handle(OpenGl_Context)& aCtx = AWorkspace->GetGlContext();
#if !defined(GL_ES_VERSION_2_0)
if (aCtx->core11 != NULL)
{
aCtx->core11->glPushAttrib (GL_DEPTH_BUFFER_BIT);
}
#endif
const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
//TsmPushAttri(); /* save previous graphics context */
if ( (AWorkspace->NamedStatus & OPENGL_NS_2NDPASSNEED) == 0 )
if ( (theWorkspace->NamedStatus & OPENGL_NS_2NDPASSNEED) == 0 )
{
#if !defined(GL_ES_VERSION_2_0)
const int antiAliasingMode = AWorkspace->AntiAliasingMode();
const int anAntiAliasingMode = theWorkspace->AntiAliasingMode();
#endif
if ( !myAntiAliasing )
@ -616,7 +608,7 @@ void OpenGl_View::RenderStructs (const Handle(OpenGl_Workspace)& AWorkspace,
glDisable (GL_POINT_SMOOTH);
}
glDisable(GL_LINE_SMOOTH);
if( antiAliasingMode & 2 ) glDisable(GL_POLYGON_SMOOTH);
if( anAntiAliasingMode & 2 ) glDisable(GL_POLYGON_SMOOTH);
#endif
glBlendFunc (GL_ONE, GL_ZERO);
glDisable (GL_BLEND);
@ -629,21 +621,14 @@ void OpenGl_View::RenderStructs (const Handle(OpenGl_Workspace)& AWorkspace,
glEnable(GL_POINT_SMOOTH);
}
glEnable(GL_LINE_SMOOTH);
if( antiAliasingMode & 2 ) glEnable(GL_POLYGON_SMOOTH);
if( anAntiAliasingMode & 2 ) glEnable(GL_POLYGON_SMOOTH);
#endif
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable (GL_BLEND);
}
}
myZLayers.Render (AWorkspace, theToDrawImmediate);
#if !defined(GL_ES_VERSION_2_0)
if (aCtx->core11 != NULL)
{
aCtx->core11->glPopAttrib();
}
#endif
myZLayers.Render (theWorkspace, theToDrawImmediate);
}
/*----------------------------------------------------------------------*/