OpenGl_Text now applies Polygon Offset instead of Z-shift in world coordinates for drawing background.
OpenGl_Context::SetPolygonOffset() - polygon offset state has been moved from OpenGl_Workspace to OpenGl_Context.
myViewportVirt[2] = 0;
myViewportVirt[3] = 0;
+ myPolygonOffset.Mode = Aspect_POM_Off;
+ myPolygonOffset.Factor = 0.0f;
+ myPolygonOffset.Units = 0.0f;
+
// system-dependent fields
#if defined(HAVE_EGL)
myDisplay = (Aspect_Display )EGL_NO_DISPLAY;
return myHatchStyles->SetTypeOfHatch (this, theStyle);
}
+// =======================================================================
+// function : SetPolygonOffset
+// purpose :
+// =======================================================================
+void OpenGl_Context::SetPolygonOffset (const Graphic3d_PolygonOffset& theOffset)
+{
+ const bool toFillOld = (myPolygonOffset.Mode & Aspect_POM_Fill) == Aspect_POM_Fill;
+ const bool toFillNew = (theOffset.Mode & Aspect_POM_Fill) == Aspect_POM_Fill;
+ if (toFillNew != toFillOld)
+ {
+ if (toFillNew)
+ {
+ glEnable (GL_POLYGON_OFFSET_FILL);
+ }
+ else
+ {
+ glDisable (GL_POLYGON_OFFSET_FILL);
+ }
+ }
+
+#if !defined(GL_ES_VERSION_2_0)
+ const bool toLineOld = (myPolygonOffset.Mode & Aspect_POM_Line) == Aspect_POM_Line;
+ const bool toLineNew = (theOffset.Mode & Aspect_POM_Line) == Aspect_POM_Line;
+ if (toLineNew != toLineOld)
+ {
+ if (toLineNew)
+ {
+ glEnable (GL_POLYGON_OFFSET_LINE);
+ }
+ else
+ {
+ glDisable (GL_POLYGON_OFFSET_LINE);
+ }
+ }
+
+ const bool toPointOld = (myPolygonOffset.Mode & Aspect_POM_Point) == Aspect_POM_Point;
+ const bool toPointNew = (theOffset.Mode & Aspect_POM_Point) == Aspect_POM_Point;
+ if (toPointNew != toPointOld)
+ {
+ if (toPointNew)
+ {
+ glEnable (GL_POLYGON_OFFSET_POINT);
+ }
+ else
+ {
+ glDisable (GL_POLYGON_OFFSET_POINT);
+ }
+ }
+#endif
+
+ if (myPolygonOffset.Factor != theOffset.Factor
+ || myPolygonOffset.Units != theOffset.Units)
+ {
+ glPolygonOffset (theOffset.Factor, theOffset.Units);
+ }
+ myPolygonOffset = theOffset;
+}
+
// =======================================================================
// function : ApplyModelWorldMatrix
// purpose :
//! @return old type of hatch.
Standard_EXPORT Standard_Integer SetPolygonHatchStyle (const Handle(Graphic3d_HatchStyle)& theStyle);
+ //! Sets and applies current polygon offset.
+ Standard_EXPORT void SetPolygonOffset (const Graphic3d_PolygonOffset& theOffset);
+
+ //! Returns currently applied polygon offset parameters.
+ const Graphic3d_PolygonOffset& PolygonOffset() const { return myPolygonOffset; }
+
//! Applies matrix stored in ModelWorldState to OpenGl.
Standard_EXPORT void ApplyModelWorldMatrix();
Standard_Integer myPointSpriteOrig; //!< GL_POINT_SPRITE_COORD_ORIGIN state (GL_UPPER_LEFT by default)
Standard_Integer myRenderMode; //!< value for active rendering mode
Standard_Integer myPolygonMode; //!< currently used polygon rasterization mode (glPolygonMode)
+ Graphic3d_PolygonOffset myPolygonOffset; //!< currently applied polygon offset
bool myToCullBackFaces; //!< back face culling mode enabled state (glIsEnabled (GL_CULL_FACE))
Standard_Integer myReadBuffer; //!< current read buffer
OpenGl_DrawBuffers myDrawBuffers; //!< current draw buffers
void OpenGl_Layer::Render (const Handle(OpenGl_Workspace)& theWorkspace,
const OpenGl_GlobalLayerSettings& theDefaultSettings) const
{
- const Graphic3d_PolygonOffset anAppliedOffsetParams = theWorkspace->AppliedPolygonOffset();
+ const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
+ const Graphic3d_PolygonOffset anAppliedOffsetParams = aCtx->PolygonOffset();
// myLayerSettings.ToClearDepth() is handled outside
// handle depth test
}
// handle depth offset
- theWorkspace->SetPolygonOffset (myLayerSettings.PolygonOffset());
+ aCtx->SetPolygonOffset (myLayerSettings.PolygonOffset());
// handle depth write
theWorkspace->UseDepthWrite() = myLayerSettings.ToEnableDepthWrite() && theDefaultSettings.DepthMask == GL_TRUE;
glDepthMask (theWorkspace->UseDepthWrite() ? GL_TRUE : GL_FALSE);
const Standard_Boolean hasLocalCS = !myLayerSettings.OriginTransformation().IsNull();
- const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
const Handle(OpenGl_ShaderManager)& aManager = aCtx->ShaderManager();
Handle(Graphic3d_LightSet) aLightsBack = aManager->LightSourceState().LightSources();
const bool hasOwnLights = aCtx->ColorMask() && !myLayerSettings.Lights().IsNull() && myLayerSettings.Lights() != aLightsBack;
}
// always restore polygon offset between layers rendering
- theWorkspace->SetPolygonOffset (anAppliedOffsetParams);
+ aCtx->SetPolygonOffset (anAppliedOffsetParams);
// restore environment texture
if (!myLayerSettings.UseEnvironmentTexture())
}
#endif
+ //! Auxiliary tool for setting polygon offset temporarily.
+ struct BackPolygonOffsetSentry
+ {
+ BackPolygonOffsetSentry (const Handle(OpenGl_Context)& theCtx)
+ : myCtx (theCtx),
+ myOffsetBack (!theCtx.IsNull() ? theCtx->PolygonOffset() : Graphic3d_PolygonOffset())
+ {
+ if (!theCtx.IsNull())
+ {
+ Graphic3d_PolygonOffset aPolyOffset = myOffsetBack;
+ aPolyOffset.Mode = Aspect_POM_Fill;
+ aPolyOffset.Units += 1.0f;
+ theCtx->SetPolygonOffset (aPolyOffset);
+ }
+ }
+
+ ~BackPolygonOffsetSentry()
+ {
+ if (!myCtx.IsNull())
+ {
+ myCtx->SetPolygonOffset (myOffsetBack);
+ }
+ }
+
+ private:
+ BackPolygonOffsetSentry (const BackPolygonOffsetSentry& );
+ BackPolygonOffsetSentry& operator= (const BackPolygonOffsetSentry& );
+ private:
+ const Handle(OpenGl_Context)& myCtx;
+ const Graphic3d_PolygonOffset myOffsetBack;
+ };
+
} // anonymous namespace
// =======================================================================
const OpenGl_AspectText* aTextAspect = theWorkspace->ApplyAspectText();
const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
const Handle(OpenGl_TextureSet) aPrevTexture = aCtx->BindTextures (Handle(OpenGl_TextureSet)());
-#if !defined(GL_ES_VERSION_2_0)
- const Standard_Integer aPrevPolygonMode = aCtx->SetPolygonMode (GL_FILL);
- const bool aPrevHatchingMode = aCtx->SetPolygonHatchEnabled (false);
-#endif
+
// Bind custom shader program or generate default version
aCtx->ShaderManager()->BindFontProgram (aTextAspect->ShaderProgramRes (aCtx));
{
aCtx->BindTextures (aPrevTexture);
}
-#if !defined(GL_ES_VERSION_2_0)
- aCtx->SetPolygonMode (aPrevPolygonMode);
- aCtx->SetPolygonHatchEnabled (aPrevHatchingMode);
-#endif
// restore Z buffer settings
if (theWorkspace->UseZBuffer())
}
#endif
theCtx->SetColor4fv (theColorSubs);
- setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (0.0f, 0.0f, 0.00001f));
+ setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (0.0f, 0.0f, 0.0f));
myBndVertsVbo->BindAttribute (theCtx, Graphic3d_TOA_POS);
theCtx->core20fwd->glDrawArrays (GL_TRIANGLE_STRIP, 0, 4);
{
glDisable (GL_LIGHTING);
}
+
+ const Standard_Integer aPrevPolygonMode = theCtx->SetPolygonMode (GL_FILL);
+ const bool aPrevHatchingMode = theCtx->SetPolygonHatchEnabled (false);
#endif
// setup depth test
- if (myIs2d
- || theTextAspect.Aspect()->Style() == Aspect_TOST_ANNOTATION)
+ const bool hasDepthTest = !myIs2d
+ && theTextAspect.Aspect()->Style() != Aspect_TOST_ANNOTATION;
+ if (!hasDepthTest)
{
glDisable (GL_DEPTH_TEST);
}
}
case Aspect_TODT_SUBTITLE:
{
+ BackPolygonOffsetSentry aPolygonOffsetTmp (hasDepthTest ? theCtx : Handle(OpenGl_Context)());
drawRect (theCtx, theTextAspect, theColorSubs);
break;
}
case Aspect_TODT_DEKALE:
{
+ BackPolygonOffsetSentry aPolygonOffsetTmp (hasDepthTest ? theCtx : Handle(OpenGl_Context)());
theCtx->SetColor4fv (theColorSubs);
- setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (+1.0f, +1.0f, 0.00001f));
+ setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (+1.0f, +1.0f, 0.0f));
drawText (theCtx, theTextAspect);
- setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (-1.0f, -1.0f, 0.00001f));
+ setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (-1.0f, -1.0f, 0.0f));
drawText (theCtx, theTextAspect);
- setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (-1.0f, +1.0f, 0.00001f));
+ setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (-1.0f, +1.0f, 0.0f));
drawText (theCtx, theTextAspect);
- setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (+1.0f, -1.0f, 0.00001f));
+ setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (+1.0f, -1.0f, 0.0f));
drawText (theCtx, theTextAspect);
break;
}
case Aspect_TODT_SHADOW:
{
+ BackPolygonOffsetSentry aPolygonOffsetTmp (hasDepthTest ? theCtx : Handle(OpenGl_Context)());
theCtx->SetColor4fv (theColorSubs);
- setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (+1.0f, -1.0f, 0.00001f));
+ setupMatrix (theCtx, theTextAspect, OpenGl_Vec3 (+1.0f, -1.0f, 0.0f));
drawText (theCtx, theTextAspect);
break;
}
glDisable (GL_ALPHA_TEST);
}
glDisable (GL_COLOR_LOGIC_OP);
+
+ theCtx->SetPolygonMode (aPrevPolygonMode);
+ theCtx->SetPolygonHatchEnabled (aPrevHatchingMode);
#endif
// model view matrix was modified
myAspectMarkerSet = &myDefaultAspectMarker;
myAspectMarkerApplied.Nullify();
myAspectTextSet = &myDefaultAspectText;
- myPolygonOffsetApplied= Graphic3d_PolygonOffset();
+ myGlContext->SetPolygonOffset (Graphic3d_PolygonOffset());
ApplyAspectLine();
ApplyAspectFace();
// Aspect_POM_None means: do not change current settings
if ((myAspectFaceSet->Aspect()->PolygonOffset().Mode & Aspect_POM_None) != Aspect_POM_None)
{
- if (myPolygonOffsetApplied.Mode != myAspectFaceSet->Aspect()->PolygonOffset().Mode
- || myPolygonOffsetApplied.Factor != myAspectFaceSet->Aspect()->PolygonOffset().Factor
- || myPolygonOffsetApplied.Units != myAspectFaceSet->Aspect()->PolygonOffset().Units)
- {
- SetPolygonOffset (myAspectFaceSet->Aspect()->PolygonOffset());
- }
+ myGlContext->SetPolygonOffset (myAspectFaceSet->Aspect()->PolygonOffset());
}
// Case of hidden line
return myAspectFaceSet;
}
-//=======================================================================
-//function : SetPolygonOffset
-//purpose :
-//=======================================================================
-void OpenGl_Workspace::SetPolygonOffset (const Graphic3d_PolygonOffset& theParams)
-{
- myPolygonOffsetApplied = theParams;
-
- if ((theParams.Mode & Aspect_POM_Fill) == Aspect_POM_Fill)
- {
- glEnable (GL_POLYGON_OFFSET_FILL);
- }
- else
- {
- glDisable (GL_POLYGON_OFFSET_FILL);
- }
-
-#if !defined(GL_ES_VERSION_2_0)
- if ((theParams.Mode & Aspect_POM_Line) == Aspect_POM_Line)
- {
- glEnable (GL_POLYGON_OFFSET_LINE);
- }
- else
- {
- glDisable (GL_POLYGON_OFFSET_LINE);
- }
-
- if ((theParams.Mode & Aspect_POM_Point) == Aspect_POM_Point)
- {
- glEnable (GL_POLYGON_OFFSET_POINT);
- }
- else
- {
- glDisable (GL_POLYGON_OFFSET_POINT);
- }
-#endif
- glPolygonOffset (theParams.Factor, theParams.Units);
-}
-
// =======================================================================
// function : ApplyAspectMarker
// purpose :
//! @return applied model structure matrix.
inline const OpenGl_Matrix* ModelMatrix() const { return StructureMatrix_applied; }
- //! Sets and applies current polygon offset.
- void SetPolygonOffset (const Graphic3d_PolygonOffset& theParams);
-
- //! Returns currently applied polygon offset parameters.
- const Graphic3d_PolygonOffset& AppliedPolygonOffset() { return myPolygonOffsetApplied; }
-
//! Returns capping algorithm rendering filter.
const Handle(OpenGl_CappingAlgoFilter)& DefaultCappingAlgoFilter() const
{
OpenGl_Matrix myModelViewMatrix; //!< Model matrix with applied structure transformations
- Graphic3d_PolygonOffset myPolygonOffsetApplied; //!< currently applied polygon offset
-
OpenGl_AspectFace myAspectFaceHl; //!< Hiddenline aspect
Handle(OpenGl_TextureSet) myEnvironmentTexture;