OpenGl_Workspace::updateMaterial() - do not activate writing into Depth buffer without Graphic3d_ZLayerDepthWrite flag.
Add method OpenGl_Workspace::UseDepthWrite() to track glDepthMask() state.
Drop the following outdated API methods conflicting with Z-layers API:
- V3d_View::EnableDepthTest(), V3d_View::IsDepthTestEnabled()
- Visual3d_View::ZBufferIsActivated(), Visual3d_View::SetZBufferActivity(), Visual3d_View::EnableDepthTest(), Visual3d_View::IsDepthTestEnabled()
- Graphic3d_GraphicDriver::SetDepthTestEnabled(), Graphic3d_GraphicDriver::IsDepthTestEnabled()
Activate Z-buffer by default, and manage it state only by Z-layer flags.
ZClipBackPlane (0.0f),
DepthFrontPlane (0.0f),
DepthBackPlane (0.0f),
- ZBufferActivity (0),
Model (0),
Visualization (0),
NbActiveLight (0),
float DepthFrontPlane;
float DepthBackPlane;
- int ZBufferActivity;
int Model;
int Visualization;
is deferred;
---Purpose: call_togl_backfacing
- SetDepthTestEnabled( me; view : CView from Graphic3d;
- isEnabled : Boolean from Standard )
- is deferred;
- ---Purpose: call_togl_depthtest
-
- IsDepthTestEnabled( me; view : CView from Graphic3d )
- returns Boolean from Standard is deferred;
- ---Purpose: call_togl_isdepthtest
-
ReadDepths( me;
view : CView from Graphic3d;
x, y : Integer;
const Standard_CString theFileName,
const Aspect_PrintAlgo thePrintAlgorithm = Aspect_PA_STRETCH,
const Standard_Real theScaleFactor = 1.0) const;
- Standard_EXPORT void SetDepthTestEnabled (const Graphic3d_CView& view,const Standard_Boolean isEnabled) const;
- Standard_EXPORT Standard_Boolean IsDepthTestEnabled (const Graphic3d_CView& view) const;
//! Reads depths of shown pixels of the given rectangle (glReadPixels with GL_DEPTH_COMPONENT)
Standard_EXPORT void ReadDepths (const Graphic3d_CView& view,const Standard_Integer x,const Standard_Integer y,const Standard_Integer width,const Standard_Integer height,const Standard_Address buffer) const;
if (aCView)
{
aCView->View->SetVisualisation(ACView.Context);
- aCView->WS->UseZBuffer() = ( ACView.Context.Visualization == 0? (ACView.Context.ZBufferActivity == 1) : (ACView.Context.ZBufferActivity != 0) );
}
}
#include <OpenGl_CView.hxx>
-void OpenGl_GraphicDriver::SetDepthTestEnabled( const Graphic3d_CView& ACView, const Standard_Boolean isEnabled ) const
-{
- const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
- if (aCView)
- aCView->WS->UseDepthTest() = isEnabled;
-}
-
-Standard_Boolean OpenGl_GraphicDriver::IsDepthTestEnabled( const Graphic3d_CView& ACView ) const
-{
- const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
- if (aCView)
- return aCView->WS->UseDepthTest();
- return Standard_False;
-}
-
void OpenGl_GraphicDriver::ReadDepths( const Graphic3d_CView& ACView,
const Standard_Integer x,
const Standard_Integer y,
{
glClear (GL_DEPTH_BUFFER_BIT);
}
-
+
// handle depth test
if (IsSettingEnabled (Graphic3d_ZLayerDepthTest))
{
{
glDepthFunc (GL_ALWAYS);
}
-
+
// handle depth offset
if (IsSettingEnabled (Graphic3d_ZLayerDepthOffset))
{
}
// handle depth write
- glDepthMask (IsSettingEnabled (Graphic3d_ZLayerDepthWrite) ? GL_TRUE : GL_FALSE);
+ theWorkspace->UseDepthWrite() = IsSettingEnabled (Graphic3d_ZLayerDepthWrite);
+ glDepthMask (theWorkspace->UseDepthWrite() ? GL_TRUE : GL_FALSE);
// render priority list
theWorkspace->IsCullingEnabled() ? renderTraverse (theWorkspace) : renderAll (theWorkspace);
}
// restore Z buffer settings
- if (theWorkspace->UseZBuffer() && theWorkspace->UseDepthTest())
+ if (theWorkspace->UseZBuffer())
{
glEnable (GL_DEPTH_TEST);
}
#endif
// setup depth test
- if (!myIs2d
- && theTextAspect.StyleType() != Aspect_TOST_ANNOTATION)
- {
- glEnable (GL_DEPTH_TEST);
- }
- else
+ if (myIs2d
+ || theTextAspect.StyleType() == Aspect_TOST_ANNOTATION)
{
glDisable (GL_DEPTH_TEST);
}
return;
}
- aCtx->core11fwd->glDisable (GL_DEPTH_TEST);
+ const Standard_Boolean wasUsedZBuffer = theWorkspace->SetUseZBuffer (Standard_False);
+ if (wasUsedZBuffer)
+ {
+ aCtx->core11fwd->glDisable (GL_DEPTH_TEST);
+ }
aCtx->WorldViewState.Push();
aCtx->ProjectionState.Push();
aCtx->ApplyProjectionMatrix();
aCtx->ApplyWorldViewMatrix();
- if (theWorkspace->UseZBuffer())
+ if (wasUsedZBuffer)
{
+ theWorkspace->SetUseZBuffer (Standard_True);
aCtx->core11fwd->glEnable (GL_DEPTH_TEST);
}
}
myTransientDrawToFront (Standard_True),
myBackBufferRestored (Standard_False),
myIsImmediateDrawn (Standard_False),
- myUseZBuffer (Standard_False),
- myUseDepthTest (Standard_True),
+ myUseZBuffer (Standard_True),
+ myUseDepthWrite (Standard_True),
myUseGLLight (Standard_True),
myIsCullingEnabled (Standard_False),
myFrameCounter (0),
// request reset of material
NamedStatus |= OPENGL_NS_RESMAT;
- GLbitfield toClear = GL_COLOR_BUFFER_BIT;
- if (myUseZBuffer)
- {
- glDepthFunc (GL_LEQUAL);
- glDepthMask (GL_TRUE);
- if (myUseDepthTest)
- {
- glEnable (GL_DEPTH_TEST);
- }
- else
- {
- glDisable (GL_DEPTH_TEST);
- }
+ myUseZBuffer = Standard_True;
+ myUseDepthWrite = Standard_True;
+ GLbitfield toClear = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT;
+ glDepthFunc (GL_LEQUAL);
+ glDepthMask (GL_TRUE);
+ glEnable (GL_DEPTH_TEST);
- #if !defined(GL_ES_VERSION_2_0)
- glClearDepth (1.0);
- #else
- glClearDepthf (1.0f);
- #endif
- toClear |= GL_DEPTH_BUFFER_BIT;
- }
- else
- {
- glDisable (GL_DEPTH_TEST);
- }
+#if !defined(GL_ES_VERSION_2_0)
+ glClearDepth (1.0);
+#else
+ glClearDepthf (1.0f);
+#endif
if (NamedStatus & OPENGL_NS_WHITEBACK)
{
// set background to white
glClearColor (1.0f, 1.0f, 1.0f, 1.0f);
- toClear |= GL_DEPTH_BUFFER_BIT;
}
else
{
Handle(OpenGl_Workspace) aWS (this);
- if (myUseZBuffer)
- {
- glDepthFunc (GL_LEQUAL);
- glDepthMask (GL_TRUE);
- if (myUseDepthTest)
- {
- glEnable (GL_DEPTH_TEST);
- }
- else
- {
- glDisable (GL_DEPTH_TEST);
- }
-
- #if !defined(GL_ES_VERSION_2_0)
- glClearDepth (1.0);
- #else
- glClearDepthf (1.0f);
- #endif
- }
- else
- {
- glDisable (GL_DEPTH_TEST);
- }
+ myUseZBuffer = Standard_True;
+ myUseDepthWrite = Standard_True;
+ glDepthFunc (GL_LEQUAL);
+ glDepthMask (GL_TRUE);
+ glEnable (GL_DEPTH_TEST);
+#if !defined(GL_ES_VERSION_2_0)
+ glClearDepth (1.0);
+#else
+ glClearDepthf (1.0f);
+#endif
myView->Render (myPrintContext, aWS, theDrawFbo, theProjection,
theCView, theCUnderLayer, theCOverLayer, Standard_True);
if (!myView->ImmediateStructures().IsEmpty())
{
+ myUseZBuffer = Standard_False;
glDisable (GL_DEPTH_TEST);
}
for (OpenGl_IndexedMapOfStructure::Iterator anIter (myView->ImmediateStructures()); anIter.More(); anIter.Next())
Image_PixMap& theImage,
const Graphic3d_BufferType& theBufferType);
- Standard_Boolean& UseZBuffer() { return myUseZBuffer; }
- Standard_Boolean& UseDepthTest() { return myUseDepthTest; }
- Standard_Boolean& UseGLLight() { return myUseGLLight; }
+ //! Setup Z-buffer usage flag (without affecting GL state!).
+ //! Returns previously set flag.
+ Standard_Boolean SetUseZBuffer (const Standard_Boolean theToUse)
+ {
+ const Standard_Boolean wasUsed = myUseZBuffer;
+ myUseZBuffer = theToUse;
+ return wasUsed;
+ }
+
+ Standard_Boolean& UseZBuffer() { return myUseZBuffer; }
+ Standard_Boolean& UseDepthWrite() { return myUseDepthWrite; }
+ Standard_Boolean& UseGLLight() { return myUseGLLight; }
Standard_Integer AntiAliasingMode() const { return myAntiAliasingMode; }
Standard_Boolean myBackBufferRestored;
Standard_Boolean myIsImmediateDrawn; //!< flag indicates that immediate mode buffer contains some data
Standard_Boolean myUseZBuffer;
- Standard_Boolean myUseDepthTest;
+ Standard_Boolean myUseDepthWrite;
Standard_Boolean myUseGLLight;
Standard_Boolean myIsCullingEnabled; //!< frustum culling flag
myMatTmp.Diffuse.a() = aProps->trans;
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable (GL_BLEND);
- glDepthMask (GL_FALSE);
+ if (myUseDepthWrite)
+ {
+ glDepthMask (GL_FALSE);
+ }
}
else
{
glBlendFunc (GL_ONE, GL_ZERO);
glDisable (GL_BLEND);
}
- glDepthMask (GL_TRUE);
+ if (myUseDepthWrite)
+ {
+ glDepthMask (GL_TRUE);
+ }
}
}
-- -> Add method Dump()
-- THA - 17/08/00 Thomas HARTL <t-hartl@muenchen.matra-dtv.fr>
-- -> Add Print method (works only under Windows).
--- SAV - 22/10/01
--- -> Add EnableDepthTest() & IsDepthTestEnabled().
-- VSV - 28/05/02: ZBUFFER mode of Trihedron
-- SAV - 23/12/02 -> Added methods to set background image
-- NKV - 23/07/07 -> Define custom projection and model view matrixes
---Level : Public
---Purpose : Returns current state of the back faces display
- EnableDepthTest( me; enable : Boolean from Standard = Standard_True )
- is static;
- ---Level: Public
- ---Purpose: turns on/off opengl depth testing
-
- IsDepthTestEnabled( me ) returns Boolean from Standard
- is static;
- ---Level: Public
- ---Purpose: returns the current state of the depth testing
-
EnableGLLight( me; enable : Boolean from Standard = Standard_True )
is static;
---Level: Public
//BUC61045 25/10/01 SAV ; added functionality to control gl lighting from higher API
-void V3d_View::EnableDepthTest( const Standard_Boolean enable ) const
-{
- MyView->EnableDepthTest( enable );
-}
-
-Standard_Boolean V3d_View::IsDepthTestEnabled() const
-{
- return MyView->IsDepthTestEnabled();
-}
-
void V3d_View::EnableGLLight( const Standard_Boolean enable ) const
{
MyView->EnableGLLight( enable );
-- of a Set. Improves performance of Selection
-- mechanisms
--- SAV - 22/10/01 -> Add EnableDepthTest() & IsDepthTestEnabled() methods.
-- SAV - 25/10/01 -> Add EnableGLLight() & IsGLLightEnabled() methods.
-- VSV - 28/05/02: ZBUFFER mode of Trihedron
-- SAV - 23/12/02 Added methods too set background image
-- or insufficient memory.
-- Warning: Works only under Windows.
- ZBufferIsActivated ( me )
- returns Boolean from Standard
- is static;
- ---Level: Advanced
- ---Purpose: Returns Standard_True if the ZBuffer is activated
- -- in the view <me> and Standard_False if not.
- ---Category: Internal methods
-
- SetZBufferActivity ( me : mutable; AnActivity : Integer from Standard )
- is static;
- ---Level: Advanced
- ---Purpose: Activates the ZBuffer if the integer <AnActivity>
- -- is equal to 1.
- -- Deactivates the ZBuffer if the integer <AnActivity>
- -- is equal to 0.
- -- If the integer <AnActivity> is equal to -1 then
- -- - the ZBuffer is activated if
- -- me->Context ().Visualization () == Visual3d_TOV_SHADING
- -- - the ZBuffer is deactivated if
- -- me->Context ().Visualization () == Visual3d_TOV_WIREFRAME
- ---Category: Internal methods
-
UnderLayer ( me )
returns Layer from Visual3d;
---Level: Internal
---Category: Private methods
---C++: return const &
- EnableDepthTest( me; enable : Boolean from Standard )
- is static;
- ---Level: Public
- ---Purpose: turns on/off opengl depth
-
- IsDepthTestEnabled( me ) returns Boolean from Standard
- is static;
- ---Level: Public
- ---Purpose: returns current state of the opengl depth testing
-
ReadDepths( me; x,y,width,height: Integer from Standard;
buffer : Address )
is static;
MyCView.WsId = -1;
MyCView.DefWindow.IsDefined = 0;
MyCView.Context.NbActiveLight = 0;
- MyCView.Context.ZBufferActivity = -1;
MyCView.Backfacing = 0;
MyCView.ptrUnderLayer = 0;
}
}
- // If the activation/desactivation of ZBuffer should be automatic
- // depending on the presence or absence of facets.
- if (myViewManager->ZBufferAuto())
- {
- const Standard_Boolean containsFacet = ContainsFacet();
- const Standard_Boolean hasZBuffer = ZBufferIsActivated();
- if (containsFacet && !hasZBuffer)
- {
- SetZBufferActivity (1); // If the view contains facets and if ZBuffer is not active
- }
- else if (!containsFacet && hasZBuffer)
- {
- SetZBufferActivity (0); // If the view does not contain facets and if ZBuffer is active
- }
- }
-
Update (myViewManager->UpdateMode());
}
myGraphicDriver->ResetDeviceLostFlag();
}
- // set up Z buffer state before redrawing
- if (myViewManager->ZBufferAuto())
- {
- const Standard_Boolean hasFacet = ContainsFacet();
- const Standard_Boolean hasZBuffer = ZBufferIsActivated();
- // if the view contains facets and if ZBuffer is not active
- if (hasFacet && !hasZBuffer)
- {
- SetZBufferActivity (1);
- }
- // if the view contains only facets and if ZBuffer is active
- if (!hasFacet && hasZBuffer)
- {
- SetZBufferActivity (0);
- }
- }
-
if (myStructuresUpdated)
{
AutoZFit();
return MyCView.ViewId;
}
-// =======================================================================
-// function : ZBufferIsActivated
-// purpose :
-// =======================================================================
-Standard_Boolean Visual3d_View::ZBufferIsActivated() const
-{
- if (IsDeleted()
- || !IsDefined()
- || !IsActive())
- {
- return Standard_False;
- }
-
- if (MyCView.Context.ZBufferActivity == -1)
- {
- // not forced by the programmer => depends on the type of visualisation
- return MyContext.Visualization () == Visual3d_TOV_SHADING;
- }
- return MyCView.Context.ZBufferActivity != 0; // 0 or 1 => forced by the programmer
-}
-
-// =======================================================================
-// function : SetZBufferActivity
-// purpose :
-// =======================================================================
-void Visual3d_View::SetZBufferActivity (const Standard_Integer theActivity)
-{
- if (IsDeleted()
- || MyCView.Context.ZBufferActivity == theActivity
- || !IsDefined()
- || !IsActive())
- {
- return;
- }
-
- MyCView.Context.ZBufferActivity = theActivity;
- myGraphicDriver->SetVisualisation (MyCView);
-}
-
// =======================================================================
// function : UpdateView
// purpose :
return Visual3d_TOBM_DISABLE;
}
-// =======================================================================
-// function : EnableDepthTest
-// purpose :
-// =======================================================================
-void Visual3d_View::EnableDepthTest (const Standard_Boolean theToEnable) const
-{
- myGraphicDriver->SetDepthTestEnabled (MyCView, theToEnable);
-}
-
-// =======================================================================
-// function : IsDepthTestEnabled
-// purpose :
-// =======================================================================
-Standard_Boolean Visual3d_View::IsDepthTestEnabled() const
-{
- return myGraphicDriver->IsDepthTestEnabled (MyCView);
-}
-
// =======================================================================
// function : ReadDepths
// purpose :
void Visual3d_ViewManager::SetZBufferAuto (const Standard_Boolean AFlag)
{
- if (MyZBufferAuto && AFlag) return;
- if (! MyZBufferAuto && ! AFlag) return;
-
- // if pass from False to True :
- // no problem, at the next view update, it
- // will properly ask questions to answer (SetVisualisation)
- // if pass from True to False :
- // it is necessary to modify ZBufferActivity at each view so that
- // zbuffer could be active only if required by context.
- // In this case -1 is passed so that the view ask itself the question
- // Note : 0 forces the desactivation, 1 forces the activation
- if (! AFlag)
- {
- for(int i=1; i<=MyDefinedView.Length(); i++)
- {
- (MyDefinedView.Value(i))->SetZBufferActivity(-1);
- }
- }
MyZBufferAuto = AFlag;
}
--- /dev/null
+puts "==========="
+puts "0026149: Visualization - depth buffer should not be written within Z-layers without Graphic3d_ZLayerDepthWrite flag"
+puts "Check that objects drawn in Graphic3d_ZLayerId_BotOSD layer do not overlap objects in Graphic3d_ZLayerId_Default layer."
+puts "==========="
+
+pload MODELING VISUALIZATION
+vinit View1
+vclear
+vaxo
+
+text2brep tcc "Center" Times-Roman 30
+vdisplay tcc -2d -underlay
+polyline lcc -50 -50 0 -50 50 0 50 50 0 50 0 0 0 -50 0 -50 -50 0
+vdisplay lcc -2d -underlay
+
+text2brep tbl "Bottom-Left" Times-Roman 30
+vdisplay tbl -2d -trsfPersPos -1 -1 5 -underlay
+polyline lbl 0 0 0 0 100 0 100 100 0 100 50 0 50 0 0 0 0 0
+vdisplay lbl -2d -trsfPersPos -1 -1 3 -underlay
+
+text2brep ttl "Top-Left" Times-Roman 30 x=-27 y=0
+vdisplay ttl -2d -trsfPersPos -1 1 30 -underlay
+polyline ltl 0 -100 0 0 0 0 100 0 0 100 -50 0 50 -100 0 0 -100 0
+vdisplay ltl -2d -trsfPersPos -1 1 3 -underlay
+
+text2brep ttr "Top-Right" Times-Roman 30 x=-100 y=0
+vdisplay ttr -2d -trsfPersPos 1 1 30 -underlay
+polyline ltr -100 -100 0 -100 0 0 0 0 0 0 -50 0 -50 -100 0 -100 -100 0
+vdisplay ltr -2d -trsfPersPos 1 1 3 -underlay
+
+text2brep tbr "Bottom-Right" Times-Roman 30 x=-165 y=0
+vdisplay tbr -2d -trsfPersPos 1 -1 5 -underlay
+polyline lbr -100 0 0 -100 100 0 0 100 0 0 50 0 -50 0 0 -100 0 0
+vdisplay lbr -2d -trsfPersPos 1 -1 3 -underlay
+
+box b 1 2 3
+vdisplay b
+vfit
+vsetdispmode b 1
+
+vdump ${imagedir}/${casename}.png