// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
-#include <OpenGl_AspectFace.hxx>
+#include <OpenGl_Aspects.hxx>
#include <OpenGl_Context.hxx>
#include <OpenGl_GraphicDriver.hxx>
#include <OpenGl_IndexBuffer.hxx>
// function : drawEdges
// purpose :
// =======================================================================
-void OpenGl_PrimitiveArray::drawEdges (const OpenGl_Vec4& theEdgeColour,
- const Handle(OpenGl_Workspace)& theWorkspace) const
+void OpenGl_PrimitiveArray::drawEdges (const Handle(OpenGl_Workspace)& theWorkspace) const
{
const Handle(OpenGl_Context)& aGlContext = theWorkspace->GetGlContext();
if (myVboAttribs.IsNull())
return;
}
- const OpenGl_AspectLine* anAspectLineOld = theWorkspace->SetAspectLine (theWorkspace->AspectFace()->AspectEdge());
- const OpenGl_AspectLine* anAspect = theWorkspace->ApplyAspectLine();
+ const OpenGl_Aspects* anAspect = theWorkspace->Aspects();
#if !defined(GL_ES_VERSION_2_0)
const Standard_Integer aPolyModeOld = aGlContext->SetPolygonMode (GL_LINE);
#endif
if (aGlContext->core20fwd != NULL)
{
- aGlContext->ShaderManager()->BindLineProgram (Handle(OpenGl_TextureSet)(), anAspect->Aspect()->Type(),
+ aGlContext->ShaderManager()->BindLineProgram (Handle(OpenGl_TextureSet)(), anAspect->Aspect()->EdgeLineType(),
Graphic3d_TOSM_UNLIT, Graphic3d_AlphaMode_Opaque, Standard_False,
anAspect->ShaderProgramRes (aGlContext));
}
+ aGlContext->SetSampleAlphaToCoverage (aGlContext->ShaderManager()->MaterialState().HasAlphaCutoff());
const GLenum aDrawMode = !aGlContext->ActiveProgram().IsNull()
&& aGlContext->ActiveProgram()->HasTessellationStage()
? GL_PATCHES
/// 3) draw primitive's edges by vertexes if no edges and bounds array is specified
myVboAttribs->BindPositionAttribute (aGlContext);
- aGlContext->SetColor4fv (theEdgeColour);
- aGlContext->SetTypeOfLine (anAspect->Aspect()->Type());
- aGlContext->SetLineWidth (anAspect->Aspect()->Width());
+ aGlContext->SetColor4fv (theWorkspace->EdgeColor().a() >= 0.1f
+ ? theWorkspace->EdgeColor()
+ : theWorkspace->View()->BackgroundColor());
+ aGlContext->SetLineStipple(anAspect->Aspect()->LinePattern());
+ aGlContext->SetLineWidth (anAspect->Aspect()->EdgeWidth());
if (!myVboIndices.IsNull())
{
myVboAttribs->UnbindAttribute (aGlContext, Graphic3d_TOA_POS);
// restore line context
- theWorkspace->SetAspectLine (anAspectLineOld);
#if !defined(GL_ES_VERSION_2_0)
aGlContext->SetPolygonMode (aPolyModeOld);
#endif
// =======================================================================
void OpenGl_PrimitiveArray::drawMarkers (const Handle(OpenGl_Workspace)& theWorkspace) const
{
- const OpenGl_AspectMarker* anAspectMarker = theWorkspace->ApplyAspectMarker();
- const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
+ const OpenGl_Aspects* anAspectMarker = theWorkspace->Aspects();
+ const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
const GLenum aDrawMode = !aCtx->ActiveProgram().IsNull()
&& aCtx->ActiveProgram()->HasTessellationStage()
? GL_PATCHES
: myDrawMode;
-
- const Handle(OpenGl_TextureSet)& aSpriteNormRes = anAspectMarker->SpriteRes (aCtx);
- const OpenGl_PointSprite* aSpriteNorm = !aSpriteNormRes.IsNull() ? dynamic_cast<const OpenGl_PointSprite*> (aSpriteNormRes->First().get()) : NULL;
- if (aSpriteNorm != NULL
- && !aSpriteNorm->IsDisplayList())
+ if (anAspectMarker->HasPointSprite (aCtx))
{
// Textured markers will be drawn with the point sprites
aCtx->SetPointSize (anAspectMarker->MarkerSize());
aCtx->SetPointSize (1.0f);
return;
}
- else if (anAspectMarker->Aspect()->Type() == Aspect_TOM_POINT)
+ else if (anAspectMarker->Aspect()->MarkerType() == Aspect_TOM_POINT)
{
aCtx->SetPointSize (anAspectMarker->MarkerSize());
aCtx->core11fwd->glDrawArrays (aDrawMode, 0, !myVboAttribs.IsNull() ? myVboAttribs->GetElemsNb() : myAttribs->NbElements);
}
#if !defined(GL_ES_VERSION_2_0)
// Textured markers will be drawn with the glBitmap
- else if (anAspectMarker->Aspect()->Type() != Aspect_TOM_POINT
- && aSpriteNorm != NULL)
+ else if (anAspectMarker->Aspect()->MarkerType() != Aspect_TOM_POINT)
{
+ const Handle(OpenGl_PointSprite)& aSpriteNorm = anAspectMarker->SpriteRes (aCtx, false);
+ if (aSpriteNorm.IsNull())
+ {
+ return;
+ }
+
/**if (!isHilight && (myPArray->vcolours != NULL))
{
for (Standard_Integer anIter = 0; anIter < myAttribs->NbElements; anIter++)
}
}
+// =======================================================================
+// function : EstimatedDataSize
+// purpose :
+// =======================================================================
+Standard_Size OpenGl_PrimitiveArray::EstimatedDataSize() const
+{
+ Standard_Size aSize = 0;
+ if (!myVboAttribs.IsNull())
+ {
+ aSize += myVboAttribs->EstimatedDataSize();
+ }
+ if (!myVboIndices.IsNull())
+ {
+ aSize += myVboIndices->EstimatedDataSize();
+ }
+ return aSize;
+}
+
+// =======================================================================
+// function : UpdateDrawStats
+// purpose :
+// =======================================================================
+void OpenGl_PrimitiveArray::UpdateDrawStats (Graphic3d_FrameStatsDataTmp& theStats,
+ bool theIsDetailed) const
+{
+ ++theStats[Graphic3d_FrameStatsCounter_NbElemsNotCulled];
+ if (myIsFillType)
+ {
+ ++theStats[Graphic3d_FrameStatsCounter_NbElemsFillNotCulled];
+ }
+ else if (myDrawMode == GL_POINTS)
+ {
+ ++theStats[Graphic3d_FrameStatsCounter_NbElemsPointNotCulled];
+ }
+ else
+ {
+ ++theStats[Graphic3d_FrameStatsCounter_NbElemsLineNotCulled];
+ }
+
+ if (!theIsDetailed
+ || myVboAttribs.IsNull()
+ || !myVboAttribs->IsValid())
+ {
+ return;
+ }
+
+ const Standard_Integer aNbIndices = !myVboIndices.IsNull() ? myVboIndices->GetElemsNb() : myVboAttribs->GetElemsNb();
+ const Standard_Integer aNbBounds = !myBounds.IsNull() ? myBounds->NbBounds : 1;
+ switch (myDrawMode)
+ {
+ case GL_POINTS:
+ {
+ theStats[Graphic3d_FrameStatsCounter_NbPointsNotCulled] += aNbIndices;
+ break;
+ }
+ case GL_LINES:
+ {
+ theStats[Graphic3d_FrameStatsCounter_NbLinesNotCulled] += aNbIndices / 2;
+ break;
+ }
+ case GL_LINE_STRIP:
+ {
+ theStats[Graphic3d_FrameStatsCounter_NbLinesNotCulled] += aNbIndices - aNbBounds;
+ break;
+ }
+ case GL_LINES_ADJACENCY:
+ {
+ theStats[Graphic3d_FrameStatsCounter_NbLinesNotCulled] += aNbIndices / 4;
+ break;
+ }
+ case GL_LINE_STRIP_ADJACENCY:
+ {
+ theStats[Graphic3d_FrameStatsCounter_NbLinesNotCulled] += aNbIndices - 4 * aNbBounds;
+ break;
+ }
+ case GL_TRIANGLES:
+ {
+ theStats[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += aNbIndices / 3;
+ break;
+ }
+ case GL_TRIANGLE_STRIP:
+ case GL_TRIANGLE_FAN:
+ {
+ theStats[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += aNbIndices - 2 * aNbBounds;
+ break;
+ }
+ case GL_TRIANGLES_ADJACENCY:
+ {
+ theStats[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += aNbIndices / 6;
+ break;
+ }
+ case GL_TRIANGLE_STRIP_ADJACENCY:
+ {
+ theStats[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += aNbIndices - 4 * aNbBounds;
+ break;
+ }
+ #if !defined(GL_ES_VERSION_2_0)
+ case GL_QUADS:
+ {
+ theStats[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += aNbIndices / 2;
+ break;
+ }
+ case GL_QUAD_STRIP:
+ {
+ theStats[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += (aNbIndices / 2 - aNbBounds) * 2;
+ break;
+ }
+ #endif
+ }
+}
+
// =======================================================================
// function : Render
// purpose :
return;
}
- const OpenGl_AspectFace* anAspectFace = theWorkspace->ApplyAspectFace();
- const OpenGl_AspectLine* anAspectLine = theWorkspace->ApplyAspectLine();
- const OpenGl_AspectMarker* anAspectMarker = myDrawMode == GL_POINTS
- ? theWorkspace->ApplyAspectMarker()
- : theWorkspace->AspectMarker();
-
+ const OpenGl_Aspects* anAspectFace = theWorkspace->Aspects();
const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
- Handle(OpenGl_TextureSet) aTextureBack;
- bool toDrawArray = true;
+ bool toDrawArray = true, toSetLinePolygMode = false;
int toDrawInteriorEdges = 0; // 0 - no edges, 1 - glsl edges, 2 - polygonMode
if (myIsFillType)
{
}
else
{
- aCtx->SetPolygonMode (GL_LINE);
+ toSetLinePolygMode = true;
}
}
}
{
if (myDrawMode == GL_POINTS)
{
- if (anAspectMarker->Aspect()->Type() == Aspect_TOM_EMPTY)
+ if (anAspectFace->Aspect()->MarkerType() == Aspect_TOM_EMPTY)
{
return;
}
}
else
{
- if (anAspectLine->Aspect()->Type() == Aspect_TOL_EMPTY)
+ if (anAspectFace->Aspect()->LineType() == Aspect_TOL_EMPTY)
{
return;
}
}
-
- // Temporarily disable environment mapping
- aTextureBack = aCtx->BindTextures (Handle(OpenGl_TextureSet)());
}
// create VBOs on first render call
if (!myIsVboInit)
{
// compatibility - keep data to draw markers using display lists
- Standard_Boolean toKeepData = Standard_False;
- if (myDrawMode == GL_POINTS)
- {
- const Handle(OpenGl_TextureSet)& aSpriteNormRes = anAspectMarker->SpriteRes (aCtx);
- const OpenGl_PointSprite* aSpriteNorm = !aSpriteNormRes.IsNull() ? dynamic_cast<const OpenGl_PointSprite*> (aSpriteNormRes->First().get()) : NULL;
- toKeepData = aSpriteNorm != NULL
- && aSpriteNorm->IsDisplayList();
- }
+ Standard_Boolean toKeepData = myDrawMode == GL_POINTS
+ && anAspectFace->IsDisplayListSprite (aCtx);
#if defined (GL_ES_VERSION_2_0)
processIndices (aCtx);
#endif
}
Graphic3d_TypeOfShadingModel aShadingModel = Graphic3d_TOSM_UNLIT;
+ anAspectFace = theWorkspace->ApplyAspects (false); // do not bind textures before binding the program
+ const Handle(OpenGl_TextureSet)& aTextureSet = theWorkspace->TextureSet();
+ const bool toEnableEnvMap = !aTextureSet.IsNull()
+ && aTextureSet == theWorkspace->EnvironmentTexture();
if (toDrawArray)
{
const bool hasColorAttrib = !myVboAttribs.IsNull()
case GL_POINTS:
{
aShadingModel = aCtx->ShaderManager()->ChooseMarkerShadingModel (anAspectFace->ShadingModel(), hasVertNorm);
- const Handle(OpenGl_TextureSet)& aSpriteNormRes = anAspectMarker->SpriteRes (aCtx);
- const OpenGl_PointSprite* aSpriteNorm = !aSpriteNormRes.IsNull() ? dynamic_cast<const OpenGl_PointSprite*> (aSpriteNormRes->First().get()) : NULL;
- if (aSpriteNorm != NULL
- && !aSpriteNorm->IsDisplayList())
- {
- const Handle(OpenGl_TextureSet)& aSprite = toHilight && anAspectMarker->SpriteHighlightRes (aCtx)->First()->IsValid()
- ? anAspectMarker->SpriteHighlightRes (aCtx)
- : aSpriteNormRes;
- aCtx->BindTextures (aSprite);
- aCtx->ShaderManager()->BindMarkerProgram (aSprite, aShadingModel, Graphic3d_AlphaMode_Opaque, hasVertColor, anAspectMarker->ShaderProgramRes (aCtx));
- }
- else
- {
- aCtx->ShaderManager()->BindMarkerProgram (Handle(OpenGl_TextureSet)(), aShadingModel, Graphic3d_AlphaMode_Opaque, hasVertColor, anAspectMarker->ShaderProgramRes (aCtx));
- }
+ aCtx->ShaderManager()->BindMarkerProgram (aTextureSet,
+ aShadingModel, Graphic3d_AlphaMode_Opaque,
+ hasVertColor, anAspectFace->ShaderProgramRes (aCtx));
break;
}
case GL_LINES:
case GL_LINE_STRIP:
{
aShadingModel = aCtx->ShaderManager()->ChooseLineShadingModel (anAspectFace->ShadingModel(), hasVertNorm);
- aCtx->ShaderManager()->BindLineProgram (NULL,
- anAspectLine->Aspect()->Type(),
+ aCtx->ShaderManager()->BindLineProgram (Handle(OpenGl_TextureSet)(),
+ anAspectFace->Aspect()->LineType(),
aShadingModel,
Graphic3d_AlphaMode_Opaque,
hasVertColor,
- anAspectLine->ShaderProgramRes (aCtx));
+ anAspectFace->ShaderProgramRes (aCtx));
break;
}
default:
{
aShadingModel = aCtx->ShaderManager()->ChooseFaceShadingModel (anAspectFace->ShadingModel(), hasVertNorm);
- const Handle(OpenGl_TextureSet)& aTextures = aCtx->ActiveTextures();
- const Standard_Boolean toEnableEnvMap = (!aTextures.IsNull() && (aTextures == theWorkspace->EnvironmentTexture()));
- aCtx->ShaderManager()->BindFaceProgram (aTextures,
+ aCtx->ShaderManager()->BindFaceProgram (aTextureSet,
aShadingModel,
aCtx->ShaderManager()->MaterialState().HasAlphaCutoff() ? Graphic3d_AlphaMode_Mask : Graphic3d_AlphaMode_Opaque,
toDrawInteriorEdges == 1 ? anAspectFace->Aspect()->InteriorStyle() : Aspect_IS_SOLID,
{
aCtx->ShaderManager()->PushInteriorState (aCtx->ActiveProgram(), anAspectFace->Aspect());
}
+ #if !defined (GL_ES_VERSION_2_0)
+ else if (toSetLinePolygMode)
+ {
+ aCtx->SetPolygonMode (GL_LINE);
+ }
+ #else
+ (void )toSetLinePolygMode;
+ #endif
break;
}
}
- #if !defined(GL_ES_VERSION_2_0)
- // manage FFP lighting
- if (aCtx->ActiveProgram().IsNull()
- && aCtx->core11 != NULL)
+ // bind textures after GLSL program to set mock textures to slots used by program
+ aCtx->BindTextures (aTextureSet, aCtx->ActiveProgram());
+ if (!aTextureSet.IsNull()
+ && !aTextureSet->IsEmpty()
+ && myDrawMode != GL_POINTS) // transformation is not supported within point sprites
{
- if (aShadingModel == Graphic3d_TOSM_UNLIT)
- {
- glDisable (GL_LIGHTING);
- }
- else
+ if (const Handle(OpenGl_Texture)& aFirstTexture = aTextureSet->First())
{
- glEnable (GL_LIGHTING);
+ aCtx->SetTextureMatrix (aFirstTexture->Sampler()->Parameters());
}
}
- #endif
-
- if (!aCtx->ActiveTextures().IsNull()
- && !aCtx->ActiveTextures()->IsEmpty()
- && !aCtx->ActiveTextures()->First().IsNull()
- && myDrawMode != GL_POINTS) // transformation is not supported within point sprites
- {
- aCtx->SetTextureMatrix (aCtx->ActiveTextures()->First()->Sampler()->Parameters());
- }
+ aCtx->SetSampleAlphaToCoverage (aCtx->ShaderManager()->MaterialState().HasAlphaCutoff());
const Graphic3d_Vec4* aFaceColors = !myBounds.IsNull() && !toHilight && anAspectFace->Aspect()->InteriorStyle() != Aspect_IS_HIDDENLINE
? myBounds->Colors
: NULL;
+ const OpenGl_Vec4& anInteriorColor = theWorkspace->InteriorColor();
+ aCtx->SetColor4fv (anInteriorColor);
if (!myIsFillType)
{
- const OpenGl_Vec4& aLineColor = myDrawMode == GL_POINTS ? theWorkspace->MarkerColor() : theWorkspace->LineColor();
- aCtx->SetColor4fv (aLineColor);
if (myDrawMode == GL_LINES
|| myDrawMode == GL_LINE_STRIP)
{
- aCtx->SetTypeOfLine (anAspectLine->Aspect()->Type());
- aCtx->SetLineWidth (anAspectLine->Aspect()->Width());
+ aCtx->SetLineStipple(anAspectFace->Aspect()->LinePattern());
+ aCtx->SetLineWidth (anAspectFace->Aspect()->LineWidth());
}
drawArray (theWorkspace, aFaceColors, hasColorAttrib);
- aCtx->BindTextures (aTextureBack);
return;
}
- const OpenGl_Vec4& anInteriorColor = theWorkspace->InteriorColor();
- aCtx->SetColor4fv (anInteriorColor);
drawArray (theWorkspace, aFaceColors, hasColorAttrib);
// draw outline - only closed triangulation with defined vertex normals can be drawn in this way
}
else
{
- const OpenGl_Vec4& anEdgeColor = theWorkspace->EdgeColor();
- drawEdges (anEdgeColor, theWorkspace);
+ drawEdges (theWorkspace);
}
}
#endif
const Handle(Graphic3d_BoundBuffer)& theBounds)
{
// Release old graphic resources
- Release (theContext.operator->());
+ Release (theContext.get());
myIndices = theIndices;
myAttribs = theAttribs;
setDrawMode (theType);
}
+
+// =======================================================================
+// function : DumpJson
+// purpose :
+// =======================================================================
+void OpenGl_PrimitiveArray::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
+{
+ OCCT_DUMP_CLASS_BEGIN (theOStream, OpenGl_PrimitiveArray)
+
+ OCCT_DUMP_BASE_CLASS (theOStream, theDepth, OpenGl_Element)
+
+ OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myVboIndices.get())
+ OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myVboAttribs.get())
+
+ OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myIndices.get())
+ OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myAttribs.get())
+ OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myBounds.get())
+
+ OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myDrawMode)
+ OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsFillType)
+ OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsVboInit)
+ OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myUID)
+}