mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-10 18:51:21 +03:00
0027735: Visualization, OpenGl_ShaderManager - fix clipping state management
OpenGl_CappingAlgo::RenderCapping() now updates clipping state in Shader Manager. OpenGl_View::render() clipping state setup has been moved to OpenGl_View::renderScene(). OpenGl_ShaderManager now converts position to homogeneous coordinates within clipping code GLSL. This fixes capping plane rendering with clipping planes applied. Fixed possible Clipping planes misconfiguration when FFP is used; error-prone OpenGl_Clipping::AddWorldLazy() method has been dropped.
This commit is contained in:
parent
c58b1b6257
commit
deb02f8655
@ -14,13 +14,14 @@
|
|||||||
// commercial license or contractual agreement.
|
// commercial license or contractual agreement.
|
||||||
|
|
||||||
#include <OpenGl_CappingAlgo.hxx>
|
#include <OpenGl_CappingAlgo.hxx>
|
||||||
|
|
||||||
#include <OpenGl_Workspace.hxx>
|
#include <OpenGl_Workspace.hxx>
|
||||||
#include <OpenGl_Context.hxx>
|
#include <OpenGl_Context.hxx>
|
||||||
#include <OpenGl_PrimitiveArray.hxx>
|
#include <OpenGl_PrimitiveArray.hxx>
|
||||||
#include <OpenGl_CappingPlaneResource.hxx>
|
#include <OpenGl_CappingPlaneResource.hxx>
|
||||||
#include <OpenGl_Vec.hxx>
|
#include <OpenGl_Vec.hxx>
|
||||||
#include <OpenGl_Structure.hxx>
|
#include <OpenGl_Structure.hxx>
|
||||||
#include <Graphic3d_GraphicDriver.hxx>
|
#include <OpenGl_ShaderManager.hxx>
|
||||||
|
|
||||||
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_CappingAlgoFilter,OpenGl_RenderFilter)
|
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_CappingAlgoFilter,OpenGl_RenderFilter)
|
||||||
|
|
||||||
@ -98,6 +99,7 @@ void OpenGl_CappingAlgo::RenderCapping (const Handle(OpenGl_Workspace)& theWorks
|
|||||||
const Standard_Boolean isOn = (aPlane == aRenderPlane);
|
const Standard_Boolean isOn = (aPlane == aRenderPlane);
|
||||||
aContext->ChangeClipping().SetEnabled (aContext, aPlane, isOn);
|
aContext->ChangeClipping().SetEnabled (aContext, aPlane, isOn);
|
||||||
}
|
}
|
||||||
|
aContext->ShaderManager()->UpdateClippingState();
|
||||||
|
|
||||||
glClear (GL_STENCIL_BUFFER_BIT);
|
glClear (GL_STENCIL_BUFFER_BIT);
|
||||||
glColorMask (GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
glColorMask (GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
||||||
@ -126,6 +128,7 @@ void OpenGl_CappingAlgo::RenderCapping (const Handle(OpenGl_Workspace)& theWorks
|
|||||||
const Standard_Boolean isOn = (aPlane != aRenderPlane);
|
const Standard_Boolean isOn = (aPlane != aRenderPlane);
|
||||||
aContext->ChangeClipping().SetEnabled (aContext, aPlane, isOn);
|
aContext->ChangeClipping().SetEnabled (aContext, aPlane, isOn);
|
||||||
}
|
}
|
||||||
|
aContext->ShaderManager()->UpdateClippingState();
|
||||||
|
|
||||||
// render capping plane using the generated stencil mask
|
// render capping plane using the generated stencil mask
|
||||||
glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||||
@ -135,6 +138,9 @@ void OpenGl_CappingAlgo::RenderCapping (const Handle(OpenGl_Workspace)& theWorks
|
|||||||
glEnable (GL_DEPTH_TEST);
|
glEnable (GL_DEPTH_TEST);
|
||||||
|
|
||||||
RenderPlane (theWorkspace, aRenderPlane);
|
RenderPlane (theWorkspace, aRenderPlane);
|
||||||
|
|
||||||
|
aContext->ShaderManager()->RevertClippingState();
|
||||||
|
aContext->ShaderManager()->RevertClippingState();
|
||||||
}
|
}
|
||||||
|
|
||||||
// restore previous application state
|
// restore previous application state
|
||||||
|
@ -173,18 +173,6 @@ public: //! @name Short-cuts
|
|||||||
add (theGlCtx, EquationCoords_World, thePlanes);
|
add (theGlCtx, EquationCoords_World, thePlanes);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Add planes to the context clipping at the world system of coordinates.
|
|
||||||
//! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
|
|
||||||
//! are simply ignored.
|
|
||||||
//! @param thePlanes [in/out] the list of planes to be added
|
|
||||||
//! The list then provides information on which planes were really added to clipping state.
|
|
||||||
//! This list then can be used to fall back to previous state.
|
|
||||||
inline void AddWorldLazy (const Handle(OpenGl_Context)& theGlCtx,
|
|
||||||
Graphic3d_SequenceOfHClipPlane& thePlanes)
|
|
||||||
{
|
|
||||||
addLazy (theGlCtx, EquationCoords_World, thePlanes);
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Remove all of the planes from context state.
|
//! Remove all of the planes from context state.
|
||||||
inline void RemoveAll (const Handle(OpenGl_Context)& theGlCtx)
|
inline void RemoveAll (const Handle(OpenGl_Context)& theGlCtx)
|
||||||
{
|
{
|
||||||
|
@ -228,7 +228,7 @@ const char THE_FRAG_CLIP_PLANES[] =
|
|||||||
EOL" int aClipSpace = occClipPlaneSpaces[aPlaneIter];"
|
EOL" int aClipSpace = occClipPlaneSpaces[aPlaneIter];"
|
||||||
EOL" if (aClipSpace == OccEquationCoords_World)"
|
EOL" if (aClipSpace == OccEquationCoords_World)"
|
||||||
EOL" {"
|
EOL" {"
|
||||||
EOL" if (dot (aClipEquation.xyz, PositionWorld.xyz) + aClipEquation.w < 0.0)"
|
EOL" if (dot (aClipEquation.xyz, PositionWorld.xyz / PositionWorld.w) + aClipEquation.w < 0.0)"
|
||||||
EOL" {"
|
EOL" {"
|
||||||
EOL" discard;"
|
EOL" discard;"
|
||||||
EOL" }"
|
EOL" }"
|
||||||
|
@ -558,10 +558,7 @@ void OpenGl_Structure::Render (const Handle(OpenGl_Workspace) &theWorkspace) con
|
|||||||
aCtx->ChangeClipping().AddWorld (aCtx, *aUserPlanes);
|
aCtx->ChangeClipping().AddWorld (aCtx, *aUserPlanes);
|
||||||
|
|
||||||
// Set OCCT state uniform variables
|
// Set OCCT state uniform variables
|
||||||
if (!aCtx->ShaderManager()->IsEmpty())
|
aCtx->ShaderManager()->UpdateClippingState();
|
||||||
{
|
|
||||||
aCtx->ShaderManager()->UpdateClippingState();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render groups
|
// Render groups
|
||||||
@ -587,10 +584,7 @@ void OpenGl_Structure::Render (const Handle(OpenGl_Workspace) &theWorkspace) con
|
|||||||
aCtx->ChangeClipping().Remove (aCtx, *aUserPlanes);
|
aCtx->ChangeClipping().Remove (aCtx, *aUserPlanes);
|
||||||
|
|
||||||
// Set OCCT state uniform variables
|
// Set OCCT state uniform variables
|
||||||
if (!aCtx->ShaderManager()->IsEmpty())
|
aCtx->ShaderManager()->RevertClippingState();
|
||||||
{
|
|
||||||
aCtx->ShaderManager()->RevertClippingState();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore local transformation
|
// Restore local transformation
|
||||||
|
@ -922,10 +922,6 @@ void OpenGl_View::render (Graphic3d_Camera::Projection theProjection,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
aManager->SetShadingModel (myShadingModel);
|
aManager->SetShadingModel (myShadingModel);
|
||||||
if (!aManager->IsEmpty())
|
|
||||||
{
|
|
||||||
aManager->UpdateClippingState();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Redraw 3d scene
|
// Redraw 3d scene
|
||||||
if (theProjection == Graphic3d_Camera::Projection_MonoLeftEye)
|
if (theProjection == Graphic3d_Camera::Projection_MonoLeftEye)
|
||||||
@ -954,17 +950,11 @@ void OpenGl_View::render (Graphic3d_Camera::Projection theProjection,
|
|||||||
// before drawing auxiliary stuff (trihedrons, overlayer)
|
// before drawing auxiliary stuff (trihedrons, overlayer)
|
||||||
myWorkspace->ResetAppliedAspect();
|
myWorkspace->ResetAppliedAspect();
|
||||||
|
|
||||||
aContext->ChangeClipping().RemoveAll (aContext);
|
|
||||||
|
|
||||||
if (!aManager->IsEmpty())
|
// We need to disable (unbind) all shaders programs to ensure
|
||||||
{
|
// that all objects without specified aspect will be drawn
|
||||||
aManager->RevertClippingState();
|
// correctly (such as background)
|
||||||
|
aContext->BindProgram (NULL);
|
||||||
// We need to disable (unbind) all shaders programs to ensure
|
|
||||||
// that all objects without specified aspect will be drawn
|
|
||||||
// correctly (such as background)
|
|
||||||
aContext->BindProgram (NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render trihedron
|
// Render trihedron
|
||||||
if (!theToDrawImmediate)
|
if (!theToDrawImmediate)
|
||||||
@ -1192,6 +1182,8 @@ void OpenGl_View::renderScene (Graphic3d_Camera::Projection theProjection,
|
|||||||
// add planes at loaded view matrix state
|
// add planes at loaded view matrix state
|
||||||
aContext->ChangeClipping().AddView (aContext, aSlicingPlanes);
|
aContext->ChangeClipping().AddView (aContext, aSlicingPlanes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
aContext->ShaderManager()->UpdateClippingState();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -1221,13 +1213,10 @@ void OpenGl_View::renderScene (Graphic3d_Camera::Projection theProjection,
|
|||||||
|
|
||||||
if (!aUserPlanes.IsEmpty())
|
if (!aUserPlanes.IsEmpty())
|
||||||
{
|
{
|
||||||
aContext->ChangeClipping().AddWorldLazy (aContext, aUserPlanes);
|
aContext->ChangeClipping().AddWorld (aContext, aUserPlanes);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!aContext->ShaderManager()->IsEmpty())
|
aContext->ShaderManager()->UpdateClippingState();
|
||||||
{
|
|
||||||
aContext->ShaderManager()->UpdateClippingState();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(GL_ES_VERSION_2_0)
|
#if !defined(GL_ES_VERSION_2_0)
|
||||||
@ -1314,6 +1303,16 @@ void OpenGl_View::renderScene (Graphic3d_Camera::Projection theProjection,
|
|||||||
// Apply restored view matrix.
|
// Apply restored view matrix.
|
||||||
aContext->ApplyWorldViewMatrix();
|
aContext->ApplyWorldViewMatrix();
|
||||||
|
|
||||||
|
aContext->ChangeClipping().RemoveAll (aContext);
|
||||||
|
if (!myClipPlanes.IsEmpty())
|
||||||
|
{
|
||||||
|
aContext->ShaderManager()->RevertClippingState();
|
||||||
|
}
|
||||||
|
if (myZClip.Back.IsOn || myZClip.Front.IsOn)
|
||||||
|
{
|
||||||
|
aContext->ShaderManager()->RevertClippingState();
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
// set printing scale/tiling transformation
|
// set printing scale/tiling transformation
|
||||||
if (!aPrintContext.IsNull())
|
if (!aPrintContext.IsNull())
|
||||||
|
@ -182,7 +182,7 @@ void main()
|
|||||||
int aClipSpace = occClipPlaneSpaces[anIndex];
|
int aClipSpace = occClipPlaneSpaces[anIndex];
|
||||||
if (aClipSpace == OccEquationCoords_World)
|
if (aClipSpace == OccEquationCoords_World)
|
||||||
{
|
{
|
||||||
if (dot (aClipEquation.xyz, PositionWorld.xyz) + aClipEquation.w < 0.0)
|
if (dot (aClipEquation.xyz, PositionWorld.xyz / PositionWorld.w) + aClipEquation.w < 0.0)
|
||||||
{
|
{
|
||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,8 @@ set y2_coord 320
|
|||||||
set x3_coord 73
|
set x3_coord 73
|
||||||
set y3_coord 150
|
set y3_coord 150
|
||||||
|
|
||||||
# enable FFP until bug-fix for GLSL
|
vclear
|
||||||
vcaps -ffp 1
|
vinit View1
|
||||||
|
|
||||||
vinit
|
|
||||||
box b1 0 0 0 10 10 10
|
box b1 0 0 0 10 10 10
|
||||||
box b2 30 0 0 10 40 10
|
box b2 30 0 0 10 40 10
|
||||||
box b3 -30 0 0 20 20 20
|
box b3 -30 0 0 20 20 20
|
||||||
@ -53,6 +51,3 @@ vclipplane set pln2 object b3
|
|||||||
checkcolor $x3_coord $y3_coord 0.5 0.5 0.9
|
checkcolor $x3_coord $y3_coord 0.5 0.5 0.9
|
||||||
|
|
||||||
checkview -screenshot -3d -path ${imagedir}/${test_image}.png
|
checkview -screenshot -3d -path ${imagedir}/${test_image}.png
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user