}
// =======================================================================
-// function : PushLightSourceState
-// purpose : Pushes state of OCCT light sources to the program
+// function : pushLightSourceState
+// purpose :
// =======================================================================
-void OpenGl_ShaderManager::PushLightSourceState (const Handle(OpenGl_ShaderProgram)& theProgram) const
+void OpenGl_ShaderManager::pushLightSourceState (const Handle(OpenGl_ShaderProgram)& theProgram) const
{
- if (myLightSourceState.Index() == theProgram->ActiveState (OpenGl_LIGHT_SOURCES_STATE))
- {
- return;
- }
-
theProgram->UpdateState (OpenGl_LIGHT_SOURCES_STATE, myLightSourceState.Index());
if (theProgram == myFfpProgram)
{
}
// =======================================================================
-// function : PushProjectionState
-// purpose : Pushes state of OCCT projection transform to the program
+// function : pushProjectionState
+// purpose :
// =======================================================================
-void OpenGl_ShaderManager::PushProjectionState (const Handle(OpenGl_ShaderProgram)& theProgram) const
+void OpenGl_ShaderManager::pushProjectionState (const Handle(OpenGl_ShaderProgram)& theProgram) const
{
- if (myProjectionState.Index() == theProgram->ActiveState (OpenGl_PROJECTION_STATE))
- {
- return;
- }
-
theProgram->UpdateState (OpenGl_PROJECTION_STATE, myProjectionState.Index());
if (theProgram == myFfpProgram)
{
}
// =======================================================================
-// function : PushModelWorldState
-// purpose : Pushes state of OCCT model-world transform to the program
+// function : pushModelWorldState
+// purpose :
// =======================================================================
-void OpenGl_ShaderManager::PushModelWorldState (const Handle(OpenGl_ShaderProgram)& theProgram) const
+void OpenGl_ShaderManager::pushModelWorldState (const Handle(OpenGl_ShaderProgram)& theProgram) const
{
- if (myModelWorldState.Index() == theProgram->ActiveState (OpenGl_MODEL_WORLD_STATE))
- {
- return;
- }
-
theProgram->UpdateState (OpenGl_MODEL_WORLD_STATE, myModelWorldState.Index());
if (theProgram == myFfpProgram)
{
}
// =======================================================================
-// function : PushWorldViewState
-// purpose : Pushes state of OCCT world-view transform to the program
+// function : pushWorldViewState
+// purpose :
// =======================================================================
-void OpenGl_ShaderManager::PushWorldViewState (const Handle(OpenGl_ShaderProgram)& theProgram) const
+void OpenGl_ShaderManager::pushWorldViewState (const Handle(OpenGl_ShaderProgram)& theProgram) const
{
if (myWorldViewState.Index() == theProgram->ActiveState (OpenGl_WORLD_VIEW_STATE))
{
}
// =======================================================================
-// function : PushClippingState
-// purpose : Pushes state of OCCT clipping planes to the program
+// function : pushClippingState
+// purpose :
// =======================================================================
-void OpenGl_ShaderManager::PushClippingState (const Handle(OpenGl_ShaderProgram)& theProgram) const
+void OpenGl_ShaderManager::pushClippingState (const Handle(OpenGl_ShaderProgram)& theProgram) const
{
- if (myClippingState.Index() == theProgram->ActiveState (OpenGl_CLIP_PLANES_STATE))
- {
- return;
- }
-
theProgram->UpdateState (OpenGl_CLIP_PLANES_STATE, myClippingState.Index());
if (theProgram == myFfpProgram)
{
}
// =======================================================================
-// function : PushMaterialState
+// function : pushMaterialState
// purpose :
// =======================================================================
-void OpenGl_ShaderManager::PushMaterialState (const Handle(OpenGl_ShaderProgram)& theProgram) const
+void OpenGl_ShaderManager::pushMaterialState (const Handle(OpenGl_ShaderProgram)& theProgram) const
{
- if (myMaterialState.Index() == theProgram->ActiveState (OpenGl_MATERIAL_STATE))
- {
- return;
- }
-
const OpenGl_Material& aFrontMat = myMaterialState.FrontMaterial();
const OpenGl_Material& aBackMat = myMaterialState.BackMaterial();
theProgram->UpdateState (OpenGl_MATERIAL_STATE, myMaterialState.Index());
}
// =======================================================================
-// function : PushOitState
-// purpose : Pushes state of OIT uniforms to the specified program
+// function : pushOitState
+// purpose :
// =======================================================================
-void OpenGl_ShaderManager::PushOitState (const Handle(OpenGl_ShaderProgram)& theProgram) const
+void OpenGl_ShaderManager::pushOitState (const Handle(OpenGl_ShaderProgram)& theProgram) const
{
- if (!theProgram->IsValid())
- {
- return;
- }
-
- if (myOitState.Index() == theProgram->ActiveState (OpenGL_OIT_STATE))
- {
- return;
- }
-
const GLint aLocOutput = theProgram->GetStateLocation (OpenGl_OCCT_OIT_OUTPUT);
if (aLocOutput != OpenGl_ShaderProgram::INVALID_LOCATION)
{
return;
}
- if (const OpenGl_ShaderUniformLocation aLocViewPort = theProgram->GetStateLocation (OpenGl_OCCT_VIEWPORT))
- {
- theProgram->SetUniform (myContext, aLocViewPort, OpenGl_Vec4 ((float )myContext->Viewport()[0], (float )myContext->Viewport()[1], (float )myContext->Viewport()[2], (float )myContext->Viewport()[3]));
- }
if (const OpenGl_ShaderUniformLocation aLocLineWidth = theProgram->GetStateLocation (OpenGl_OCCT_LINE_WIDTH))
{
theProgram->SetUniform (myContext, aLocLineWidth, theAspect->EdgeWidth() * myContext->LineWidthScale());
PushLightSourceState (aProgram);
PushMaterialState (aProgram);
PushOitState (aProgram);
+
+ if (!theProgram.IsNull())
+ {
+ if (const OpenGl_ShaderUniformLocation& aLocViewPort = theProgram->GetStateLocation (OpenGl_OCCT_VIEWPORT))
+ {
+ theProgram->SetUniform (myContext, aLocViewPort, OpenGl_Vec4 ((float )myContext->Viewport()[0], (float )myContext->Viewport()[1],
+ (float )myContext->Viewport()[2], (float )myContext->Viewport()[3]));
+ }
+ }
}
// =======================================================================
{
aUniforms.Append (OpenGl_ShaderObject::ShaderVariable ("int uPattern", Graphic3d_TOS_FRAGMENT));
aUniforms.Append (OpenGl_ShaderObject::ShaderVariable ("float uFactor", Graphic3d_TOS_FRAGMENT));
+ aUniforms.Append (OpenGl_ShaderObject::ShaderVariable ("vec4 occViewport", Graphic3d_TOS_VERTEX));
aStageInOuts.Append (OpenGl_ShaderObject::ShaderVariable ("vec2 ScreenSpaceCoord", Graphic3d_TOS_VERTEX | Graphic3d_TOS_FRAGMENT));
aSrcVertEndMain =
- EOL" ScreenSpaceCoord = gl_Position.xy / gl_Position.w;";
+ EOL" vec2 aPosition = gl_Position.xy / gl_Position.w;"
+ EOL" aPosition = aPosition * 0.5 + 0.5;"
+ EOL" ScreenSpaceCoord = aPosition.xy * occViewport.zw + occViewport.xy;";
aSrcFragMainGetColor =
- EOL" float anAngle = atan (dFdx (ScreenSpaceCoord.x), dFdy (ScreenSpaceCoord.y));"
- EOL" float aRotatePoint = gl_FragCoord.x * sin (anAngle) + gl_FragCoord.y * cos (anAngle);"
+ EOL" vec2 anAxis = vec2 (0.0);"
+ EOL" if (abs (dFdx (ScreenSpaceCoord.x)) - abs (dFdy (ScreenSpaceCoord.y)) > 0.001)"
+ EOL" {"
+ EOL" anAxis = vec2 (1.0, 0.0);"
+ EOL" }"
+ EOL" else"
+ EOL" {"
+ EOL" anAxis = vec2 (0.0, 1.0);"
+ EOL" }"
+ EOL" float aRotatePoint = dot (gl_FragCoord.xy, anAxis);"
EOL" uint aBit = uint (floor (aRotatePoint / uFactor + 0.5)) & 15U;"
EOL" if ((uint (uPattern) & (1U << aBit)) == 0U) discard;"
EOL" vec4 aColor = getFinalColor();"
//! Invalidate state of OCCT light sources.
Standard_EXPORT void UpdateLightSourceState();
+ //! Pushes current state of OCCT light sources to specified program (only on state change).
+ void PushLightSourceState (const Handle(OpenGl_ShaderProgram)& theProgram) const
+ {
+ if (myLightSourceState.Index() != theProgram->ActiveState (OpenGl_LIGHT_SOURCES_STATE))
+ {
+ pushLightSourceState (theProgram);
+ }
+ }
+
//! Pushes current state of OCCT light sources to specified program.
- Standard_EXPORT void PushLightSourceState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
+ Standard_EXPORT void pushLightSourceState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
public:
//! Updates state of OCCT projection transform.
Standard_EXPORT void UpdateProjectionStateTo (const OpenGl_Mat4& theProjectionMatrix);
+ //! Pushes current state of OCCT projection transform to specified program (only on state change).
+ void PushProjectionState (const Handle(OpenGl_ShaderProgram)& theProgram) const
+ {
+ if (myProjectionState.Index() != theProgram->ActiveState (OpenGl_PROJECTION_STATE))
+ {
+ pushProjectionState (theProgram);
+ }
+ }
+
//! Pushes current state of OCCT projection transform to specified program.
- Standard_EXPORT void PushProjectionState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
+ Standard_EXPORT void pushProjectionState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
public:
//! Updates state of OCCT model-world transform.
Standard_EXPORT void UpdateModelWorldStateTo (const OpenGl_Mat4& theModelWorldMatrix);
+ //! Pushes current state of OCCT model-world transform to specified program (only on state change).
+ void PushModelWorldState (const Handle(OpenGl_ShaderProgram)& theProgram) const
+ {
+ if (myModelWorldState.Index() != theProgram->ActiveState (OpenGl_MODEL_WORLD_STATE))
+ {
+ pushModelWorldState (theProgram);
+ }
+ }
+
//! Pushes current state of OCCT model-world transform to specified program.
- Standard_EXPORT void PushModelWorldState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
+ Standard_EXPORT void pushModelWorldState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
public:
//! Updates state of OCCT world-view transform.
Standard_EXPORT void UpdateWorldViewStateTo (const OpenGl_Mat4& theWorldViewMatrix);
+ //! Pushes current state of OCCT world-view transform to specified program (only on state change).
+ void PushWorldViewState (const Handle(OpenGl_ShaderProgram)& theProgram) const
+ {
+ if (myWorldViewState.Index() != theProgram->ActiveState (OpenGl_WORLD_VIEW_STATE))
+ {
+ pushWorldViewState (theProgram);
+ }
+ }
+
//! Pushes current state of OCCT world-view transform to specified program.
- Standard_EXPORT void PushWorldViewState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
+ Standard_EXPORT void pushWorldViewState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
public:
//! Reverts state of OCCT clipping planes.
Standard_EXPORT void RevertClippingState();
+ //! Pushes current state of OCCT clipping planes to specified program (only on state change).
+ void PushClippingState (const Handle(OpenGl_ShaderProgram)& theProgram) const
+ {
+ if (myClippingState.Index() != theProgram->ActiveState (OpenGl_CLIP_PLANES_STATE))
+ {
+ pushClippingState (theProgram);
+ }
+ }
+
//! Pushes current state of OCCT clipping planes to specified program.
- Standard_EXPORT void PushClippingState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
+ Standard_EXPORT void pushClippingState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
public:
myMaterialState.Update();
}
+ //! Pushes current state of material to specified program (only on state change).
+ void PushMaterialState (const Handle(OpenGl_ShaderProgram)& theProgram) const
+ {
+ if (myMaterialState.Index() != theProgram->ActiveState (OpenGl_MATERIAL_STATE))
+ {
+ pushMaterialState (theProgram);
+ }
+ }
+
//! Pushes current state of material to specified program.
- void PushMaterialState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
+ Standard_EXPORT void pushMaterialState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
public:
//! Returns state of OIT uniforms.
const OpenGl_OitState& OitState() const { return myOitState; }
- //! Set the state of OIT rendering pass.
+ //! Set the state of OIT rendering pass (only on state change).
//! @param theToEnableOitWrite [in] flag indicating whether the special output should be written for OIT algorithm.
//! @param theDepthFactor [in] the scalar factor of depth influence to the fragment's coverage.
void SetOitState (const bool theToEnableOitWrite, const float theDepthFactor)
}
//! Pushes state of OIT uniforms to the specified program.
- Standard_EXPORT void PushOitState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
+ void PushOitState (const Handle(OpenGl_ShaderProgram)& theProgram) const
+ {
+ if (theProgram->IsValid()
+ && myOitState.Index() != theProgram->ActiveState (OpenGL_OIT_STATE))
+ {
+ pushOitState (theProgram);
+ }
+ }
+
+ //! Pushes state of OIT uniforms to the specified program.
+ Standard_EXPORT void pushOitState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
public: