#include <OpenGl_CappingPlaneResource.hxx>
#include <OpenGl_Vec.hxx>
#include <OpenGl_Structure.hxx>
-
-IMPLEMENT_STANDARD_HANDLE(OpenGl_CappingAlgoFilter, OpenGl_RenderFilter)
-IMPLEMENT_STANDARD_RTTIEXT(OpenGl_CappingAlgoFilter, OpenGl_RenderFilter)
-
-Handle(OpenGl_RenderFilter) OpenGl_CappingAlgo::myRenderFilter;
-OpenGl_AspectFace OpenGl_CappingAlgo::myFrontCulling;
-OpenGl_AspectFace OpenGl_CappingAlgo::myNoneCulling;
-Standard_Boolean OpenGl_CappingAlgo::myIsInit = Standard_False;
+#include <Graphic3d_GraphicDriver.hxx>
namespace
{
- static const OpenGl_Vec4 THE_CAPPING_PLN_VERTS[12] =
- { OpenGl_Vec4 ( 0.0f, 0.0f, 0.0f, 1.0f),
- OpenGl_Vec4 ( 1.0f, 0.0f, 0.0f, 0.0f),
- OpenGl_Vec4 ( 0.0f, 0.0f, 1.0f, 0.0f),
- OpenGl_Vec4 ( 0.0f, 0.0f, 0.0f, 1.0f),
- OpenGl_Vec4 ( 0.0f, 0.0f, 1.0f, 0.0f),
- OpenGl_Vec4 (-1.0f, 0.0f, 0.0f, 0.0f),
- OpenGl_Vec4 ( 0.0f, 0.0f, 0.0f, 1.0f),
- OpenGl_Vec4 (-1.0f, 0.0f, 0.0f, 0.0f),
- OpenGl_Vec4 ( 0.0f, 0.0f,-1.0f, 0.0f),
- OpenGl_Vec4 ( 0.0f, 0.0f, 0.0f, 1.0f),
- OpenGl_Vec4 ( 0.0f, 0.0f,-1.0f, 0.0f),
- OpenGl_Vec4 ( 1.0f, 0.0f, 0.0f, 0.0f) };
-
- static const OpenGl_Vec4 THE_CAPPING_PLN_TCOORD[12] =
- { OpenGl_Vec4 ( 0.0f, 0.0f, 0.0f, 1.0f),
- OpenGl_Vec4 ( 1.0f, 0.0f, 0.0f, 0.0f),
- OpenGl_Vec4 ( 0.0f, 1.0f, 0.0f, 0.0f),
- OpenGl_Vec4 ( 0.0f, 0.0f, 0.0f, 1.0f),
- OpenGl_Vec4 ( 0.0f, 1.0f, 0.0f, 0.0f),
- OpenGl_Vec4 (-1.0f, 0.0f, 0.0f, 0.0f),
- OpenGl_Vec4 ( 0.0f, 0.0f, 0.0f, 1.0f),
- OpenGl_Vec4 (-1.0f, 0.0f, 0.0f, 0.0f),
- OpenGl_Vec4 ( 0.0f,-1.0f, 0.0f, 0.0f),
- OpenGl_Vec4 ( 0.0f, 0.0f, 0.0f, 1.0f),
- OpenGl_Vec4 ( 0.0f,-1.0f, 0.0f, 0.0f),
- OpenGl_Vec4 ( 1.0f, 0.0f, 0.0f, 0.0f) };
-};
+#if !defined(GL_ES_VERSION_2_0)
+ static const GLint THE_FILLPRIM_FROM = GL_TRIANGLES;
+ static const GLint THE_FILLPRIM_TO = GL_POLYGON;
+#else
+ static const GLint THE_FILLPRIM_FROM = GL_TRIANGLES;
+ static const GLint THE_FILLPRIM_TO = GL_TRIANGLE_FAN;
+#endif
+}
// =======================================================================
// function : RenderCapping
return;
}
- // init internal data
- Init();
-
// remember current aspect face defined in workspace
const OpenGl_AspectFace* aFaceAsp = theWorkspace->AspectFace (Standard_False);
// replace primitive groups rendering filter
- static Handle(OpenGl_CappingAlgoFilter) aCappingFilter = new OpenGl_CappingAlgoFilter();
Handle(OpenGl_RenderFilter) aRenderFilter = theWorkspace->GetRenderFilter();
- theWorkspace->SetRenderFilter (aCappingFilter);
+ theWorkspace->SetRenderFilter (theWorkspace->DefaultCappingAlgoFilter());
// prepare for rendering the clip planes
glEnable (GL_STENCIL_TEST);
+ // remember current state of depth
+ // function and change its value
+ GLint aDepthFuncPrev;
+ glGetIntegerv (GL_DEPTH_FUNC, &aDepthFuncPrev);
+ glDepthFunc (GL_LESS);
+
// generate capping for every clip plane
for (aCappingIt.Init (aContextPlanes); aCappingIt.More(); aCappingIt.Next())
{
{
const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
const Standard_Boolean isOn = (aPlane == aRenderPlane);
- aContext->ChangeClipping().SetEnabled (aPlane, isOn);
+ aContext->ChangeClipping().SetEnabled (aContext, aPlane, isOn);
}
glClear (GL_STENCIL_BUFFER_BIT);
glColorMask (GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
// override aspects, disable culling
- theWorkspace->SetAspectFace (NoneCulling());
+ theWorkspace->SetAspectFace (&theWorkspace->NoneCulling());
theWorkspace->AspectFace (Standard_True);
// evaluate number of pair faces
}
// override material, cull back faces
- theWorkspace->SetAspectFace (FrontCulling());
+ theWorkspace->SetAspectFace (&theWorkspace->FrontCulling());
theWorkspace->AspectFace (Standard_True);
// enable all clip plane except the rendered one
{
const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
const Standard_Boolean isOn = (aPlane != aRenderPlane);
- aContext->ChangeClipping().SetEnabled (aPlane, isOn);
+ aContext->ChangeClipping().SetEnabled (aContext, aPlane, isOn);
}
// render capping plane using the generated stencil mask
glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glDepthMask (GL_TRUE);
- glDepthFunc (GL_LESS);
glStencilFunc (GL_EQUAL, 1, 0x01);
glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);
glEnable (GL_DEPTH_TEST);
// restore previous application state
glClear (GL_STENCIL_BUFFER_BIT);
+ glDepthFunc (aDepthFuncPrev);
glStencilFunc (GL_ALWAYS, 0, 0xFF);
glDisable (GL_STENCIL_TEST);
// enable clipping
for (aCappingIt.Init (aContextPlanes); aCappingIt.More(); aCappingIt.Next())
{
- aContext->ChangeClipping().SetEnabled (aCappingIt.Value(), Standard_True);
+ aContext->ChangeClipping().SetEnabled (aContext, aCappingIt.Value(), Standard_True);
}
// restore rendering aspects
theWorkspace->SetAspectFace (aPlaneAspect);
}
- // apply aspect for rendering
- theWorkspace->AspectFace (Standard_True);
-
// set identity model matrix
- const OpenGl_Matrix* aModelMatrix = theWorkspace->SetStructureMatrix (&OpenGl_IdentityMatrix);
-
- glMultMatrixf ((const GLfloat*)aPlaneRes->Orientation());
- glNormal3f (0.0f, 1.0f, 0.0f);
- glEnableClientState (GL_VERTEX_ARRAY);
- glVertexPointer (4, GL_FLOAT, 0, (GLfloat* )&THE_CAPPING_PLN_VERTS);
- glEnableClientState (GL_TEXTURE_COORD_ARRAY);
- glTexCoordPointer (4, GL_FLOAT, 0, (GLfloat*)&THE_CAPPING_PLN_TCOORD);
- glDrawArrays (GL_TRIANGLES, 0, 12);
- glDisableClientState (GL_VERTEX_ARRAY);
- glDisableClientState (GL_TEXTURE_COORD_ARRAY);
-
- theWorkspace->SetStructureMatrix (aModelMatrix, true);
+ aContext->ModelWorldState.Push();
+ aContext->ModelWorldState.SetCurrent (OpenGl_Mat4::Map (*aPlaneRes->Orientation()->mat));
+ aContext->ApplyModelViewMatrix();
+
+ aPlaneRes->Primitives().Render (theWorkspace);
+
+ aContext->ModelWorldState.Pop();
+ aContext->ApplyModelViewMatrix();
+
theWorkspace->SetAspectFace (aFaceAspect);
// set delayed resource release
aContext->ReleaseResource (aResId, Standard_True);
}
-// =======================================================================
-// function : Init
-// purpose :
-// =======================================================================
-void OpenGl_CappingAlgo::Init()
-{
- if (myIsInit)
- return;
-
- myRenderFilter = new OpenGl_CappingAlgoFilter();
- myNoneCulling.ChangeCullingMode() = TelCullNone;
- myNoneCulling.ChangeEdge() = 0;
-
- myFrontCulling.ChangeCullingMode() = TelCullBack;
- myFrontCulling.ChangeEdge() = 0;
-
- myIsInit = Standard_True;
-}
-
// =======================================================================
// function : CanRender
// purpose :
{
const OpenGl_PrimitiveArray* aPArray = dynamic_cast<const OpenGl_PrimitiveArray*> (theElement);
return aPArray != NULL
- && aPArray->DrawMode() >= GL_TRIANGLES
- && aPArray->DrawMode() <= GL_POLYGON;
+ && aPArray->DrawMode() >= THE_FILLPRIM_FROM
+ && aPArray->DrawMode() <= THE_FILLPRIM_TO;
}