#include <TCollection_ExtendedString.hxx>
-
-
-
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_ShaderManager,Standard_Transient)
namespace
{
+ //! Clipping planes limit (see the same definition in Declarations.glsl).
+ static const Standard_Size THE_MAX_CLIP_PLANES = 8;
+
#define EOL "\n"
//! Definition of TexCoord varying.
//! Process clipping planes in Fragment Shader.
//! Should be added at the beginning of the main() function.
-const char THE_FRAG_CLIP_PLANES[] =
+const char THE_FRAG_CLIP_PLANES_N[] =
EOL" for (int aPlaneIter = 0; aPlaneIter < occClipPlaneCount; ++aPlaneIter)"
EOL" {"
EOL" vec4 aClipEquation = occClipPlaneEquations[aPlaneIter];"
- EOL" int aClipSpace = occClipPlaneSpaces[aPlaneIter];"
- EOL" if (aClipSpace == OccEquationCoords_World)"
- EOL" {"
- EOL" if (dot (aClipEquation.xyz, PositionWorld.xyz / PositionWorld.w) + aClipEquation.w < 0.0)"
- EOL" {"
- EOL" discard;"
- EOL" }"
- EOL" }"
- EOL" else if (aClipSpace == OccEquationCoords_View)"
+ EOL" if (dot (aClipEquation.xyz, PositionWorld.xyz / PositionWorld.w) + aClipEquation.w < 0.0)"
EOL" {"
- EOL" if (dot (aClipEquation.xyz, Position.xyz) + aClipEquation.w < 0.0)"
- EOL" {"
- EOL" discard;"
- EOL" }"
+ EOL" discard;"
EOL" }"
EOL" }";
+//! Process 1 clipping plane in Fragment Shader.
+const char THE_FRAG_CLIP_PLANES_1[] =
+ EOL" vec4 aClipEquation0 = occClipPlaneEquations[0];"
+ EOL" if (dot (aClipEquation0.xyz, PositionWorld.xyz / PositionWorld.w) + aClipEquation0.w < 0.0)"
+ EOL" {"
+ EOL" discard;"
+ EOL" }";
+
+//! Process 2 clipping planes in Fragment Shader.
+const char THE_FRAG_CLIP_PLANES_2[] =
+ EOL" vec4 aClipEquation0 = occClipPlaneEquations[0];"
+ EOL" vec4 aClipEquation1 = occClipPlaneEquations[1];"
+ EOL" if (dot (aClipEquation0.xyz, PositionWorld.xyz / PositionWorld.w) + aClipEquation0.w < 0.0"
+ EOL" || dot (aClipEquation1.xyz, PositionWorld.xyz / PositionWorld.w) + aClipEquation1.w < 0.0)"
+ EOL" {"
+ EOL" discard;"
+ EOL" }";
+
}
// =======================================================================
theProgram->UpdateState (OpenGl_CLIP_PLANES_STATE, myClippingState.Index());
const GLint aLocEquations = theProgram->GetStateLocation (OpenGl_OCC_CLIP_PLANE_EQUATIONS);
- const GLint aLocSpaces = theProgram->GetStateLocation (OpenGl_OCC_CLIP_PLANE_SPACES);
- if (aLocEquations == OpenGl_ShaderProgram::INVALID_LOCATION
- && aLocSpaces == OpenGl_ShaderProgram::INVALID_LOCATION)
+ if (aLocEquations == OpenGl_ShaderProgram::INVALID_LOCATION)
{
return;
}
return;
}
- const Standard_Size MAX_CLIP_PLANES = 8;
- OpenGl_Vec4* anEquations = new OpenGl_Vec4[MAX_CLIP_PLANES];
- GLint* aSpaces = new GLint [MAX_CLIP_PLANES];
+ OpenGl_Vec4 anEquations[THE_MAX_CLIP_PLANES];
GLuint aPlaneId = 0;
for (Graphic3d_SequenceOfHClipPlane::Iterator anIter (myContext->Clipping().Planes());
anIter.More(); anIter.Next())
{
continue;
}
+ else if (aPlaneId >= THE_MAX_CLIP_PLANES)
+ {
+ myContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION,
+ GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_MEDIUM,
+ "Warning: clipping planes limit (8) has been exceeded.");
+ break;
+ }
const Graphic3d_ClipPlane::Equation& anEquation = aPlane->GetEquation();
anEquations[aPlaneId] = OpenGl_Vec4 ((float) anEquation.x(),
(float) anEquation.y(),
(float) anEquation.z(),
(float) anEquation.w());
- aSpaces[aPlaneId] = myContext->Clipping().GetEquationSpace (aPlane);
++aPlaneId;
}
theProgram->SetUniform (myContext,
theProgram->GetStateLocation (OpenGl_OCC_CLIP_PLANE_COUNT),
aPlanesNb);
- theProgram->SetUniform (myContext, aLocEquations, MAX_CLIP_PLANES, anEquations);
- theProgram->SetUniform (myContext, aLocSpaces, MAX_CLIP_PLANES, aSpaces);
-
- delete[] anEquations;
- delete[] aSpaces;
+ theProgram->SetUniform (myContext, aLocEquations, THE_MAX_CLIP_PLANES, anEquations);
}
// =======================================================================
aSrcFragExtraOut += EOL"THE_SHADER_IN vec4 VertColor;";
aSrcFragGetColor = EOL"vec4 getColor(void) { return VertColor; }";
}
- if ((theBits & OpenGl_PO_ClipPlanes) != 0)
+ if ((theBits & OpenGl_PO_ClipPlanesN) != 0)
{
aSrcVertExtraOut +=
EOL"THE_SHADER_OUT vec4 PositionWorld;"
aSrcVertExtraMain +=
EOL" PositionWorld = occModelWorldMatrix * occVertex;"
EOL" Position = occWorldViewMatrix * PositionWorld;";
- aSrcFragExtraMain += THE_FRAG_CLIP_PLANES;
+
+ if ((theBits & OpenGl_PO_ClipPlanes1) != 0)
+ {
+ aSrcFragExtraMain += THE_FRAG_CLIP_PLANES_1;
+ }
+ else if ((theBits & OpenGl_PO_ClipPlanes2) != 0)
+ {
+ aSrcFragExtraMain += THE_FRAG_CLIP_PLANES_2;
+ }
+ else
+ {
+ aSrcFragExtraMain += THE_FRAG_CLIP_PLANES_N;
+ }
}
TCollection_AsciiString aSrcVertEndMain;
aSrcVertColor = EOL"vec4 getVertColor(void) { return occVertColor; }";
}
- if ((theBits & OpenGl_PO_ClipPlanes) != 0)
+ if ((theBits & OpenGl_PO_ClipPlanesN) != 0)
{
aSrcVertExtraOut +=
EOL"THE_SHADER_OUT vec4 PositionWorld;"
aSrcVertExtraMain +=
EOL" PositionWorld = aPositionWorld;"
EOL" Position = aPosition;";
- aSrcFragExtraMain += THE_FRAG_CLIP_PLANES;
+
+ if ((theBits & OpenGl_PO_ClipPlanes1) != 0)
+ {
+ aSrcFragExtraMain += THE_FRAG_CLIP_PLANES_1;
+ }
+ else if ((theBits & OpenGl_PO_ClipPlanes2) != 0)
+ {
+ aSrcFragExtraMain += THE_FRAG_CLIP_PLANES_2;
+ }
+ else
+ {
+ aSrcFragExtraMain += THE_FRAG_CLIP_PLANES_N;
+ }
}
const TCollection_AsciiString aLights = stdComputeLighting ((theBits & OpenGl_PO_VertColor) != 0);
EOL"vec4 getVertColor(void) { return VertColor; }";
}
- if ((theBits & OpenGl_PO_ClipPlanes) != 0)
+ if ((theBits & OpenGl_PO_ClipPlanesN) != 0)
{
- aSrcFragExtraMain += THE_FRAG_CLIP_PLANES;
+ if ((theBits & OpenGl_PO_ClipPlanes1) != 0)
+ {
+ aSrcFragExtraMain += THE_FRAG_CLIP_PLANES_1;
+ }
+ else if ((theBits & OpenGl_PO_ClipPlanes2) != 0)
+ {
+ aSrcFragExtraMain += THE_FRAG_CLIP_PLANES_2;
+ }
+ else
+ {
+ aSrcFragExtraMain += THE_FRAG_CLIP_PLANES_N;
+ }
}
aSrcVert = TCollection_AsciiString()