From 40131e1f4cec409016e3b245886e28c91b060316 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 8 Feb 2019 19:30:15 +0300 Subject: [PATCH] 0030491: Visualization - OpenGl_Element inherits Standard_Transient --- src/OpenGl/OpenGl_AspectFace.cxx | 11 ++- src/OpenGl/OpenGl_AspectFace.hxx | 8 +- src/OpenGl/OpenGl_AspectLine.cxx | 2 + src/OpenGl/OpenGl_AspectLine.hxx | 1 + src/OpenGl/OpenGl_AspectMarker.cxx | 2 + src/OpenGl/OpenGl_AspectMarker.hxx | 1 + src/OpenGl/OpenGl_AspectText.cxx | 2 + src/OpenGl/OpenGl_AspectText.hxx | 2 +- src/OpenGl/OpenGl_BackgroundArray.cxx | 4 +- src/OpenGl/OpenGl_BackgroundArray.hxx | 1 + src/OpenGl/OpenGl_CappingAlgo.cxx | 10 +-- src/OpenGl/OpenGl_CappingPlaneResource.cxx | 2 +- src/OpenGl/OpenGl_CappingPlaneResource.hxx | 4 +- src/OpenGl/OpenGl_Context.cxx | 4 +- src/OpenGl/OpenGl_Context.hxx | 6 +- src/OpenGl/OpenGl_Element.cxx | 2 + src/OpenGl/OpenGl_Element.hxx | 11 +-- src/OpenGl/OpenGl_Flipper.cxx | 2 + src/OpenGl/OpenGl_Flipper.hxx | 1 + src/OpenGl/OpenGl_FrameStats.cxx | 13 +-- src/OpenGl/OpenGl_FrameStatsPrs.cxx | 4 +- src/OpenGl/OpenGl_FrameStatsPrs.hxx | 1 + src/OpenGl/OpenGl_GraduatedTrihedron.cxx | 6 +- src/OpenGl/OpenGl_GraduatedTrihedron.hxx | 1 + src/OpenGl/OpenGl_Group.cxx | 94 +++++++++----------- src/OpenGl/OpenGl_Group.hxx | 42 ++++----- src/OpenGl/OpenGl_PrimitiveArray.cxx | 21 +++-- src/OpenGl/OpenGl_PrimitiveArray.hxx | 1 + src/OpenGl/OpenGl_SceneGeometry.cxx | 21 ++--- src/OpenGl/OpenGl_SceneGeometry.hxx | 5 +- src/OpenGl/OpenGl_StencilTest.cxx | 2 + src/OpenGl/OpenGl_StencilTest.hxx | 1 + src/OpenGl/OpenGl_Structure.cxx | 8 +- src/OpenGl/OpenGl_Text.cxx | 8 +- src/OpenGl/OpenGl_Text.hxx | 2 +- src/OpenGl/OpenGl_View.cxx | 6 +- src/OpenGl/OpenGl_View.hxx | 10 +-- src/OpenGl/OpenGl_View_Raytrace.cxx | 27 +++--- src/OpenGl/OpenGl_View_Redraw.cxx | 2 +- src/OpenGl/OpenGl_Workspace.cxx | 77 +++++++++------- src/OpenGl/OpenGl_Workspace.hxx | 54 +++++------ src/ViewerTest/ViewerTest_OpenGlCommands.cxx | 4 +- 42 files changed, 247 insertions(+), 239 deletions(-) diff --git a/src/OpenGl/OpenGl_AspectFace.cxx b/src/OpenGl/OpenGl_AspectFace.cxx index dcd13a2100..a967d4cb81 100644 --- a/src/OpenGl/OpenGl_AspectFace.cxx +++ b/src/OpenGl/OpenGl_AspectFace.cxx @@ -32,6 +32,8 @@ #include +IMPLEMENT_STANDARD_RTTIEXT(OpenGl_AspectFace, OpenGl_Element) + namespace { //! Initialize default material in this way for backward compatibility. @@ -66,6 +68,7 @@ OpenGl_AspectFace::OpenGl_AspectFace() THE_DEFAULT_MATERIAL, THE_DEFAULT_MATERIAL)), myShadingModel (Graphic3d_TOSM_UNLIT) { + myAspectEdge = new OpenGl_AspectLine(); myAspect->SetShadingModel (myShadingModel); myAspect->SetHatchStyle (Handle(Graphic3d_HatchStyle)()); } @@ -77,6 +80,8 @@ OpenGl_AspectFace::OpenGl_AspectFace() OpenGl_AspectFace::OpenGl_AspectFace (const Handle(Graphic3d_AspectFillArea3d)& theAspect) : myShadingModel (Graphic3d_TOSM_DEFAULT) { + myAspectEdge = new OpenGl_AspectLine(); + SetAspect (theAspect); } @@ -97,9 +102,9 @@ void OpenGl_AspectFace::SetAspect (const Handle(Graphic3d_AspectFillArea3d)& the ? theAspect->ShadingModel() : Graphic3d_TOSM_UNLIT; - myAspectEdge.Aspect()->SetColor (theAspect->EdgeColor()); - myAspectEdge.Aspect()->SetType (theAspect->EdgeLineType()); - myAspectEdge.Aspect()->SetWidth (theAspect->EdgeWidth()); + myAspectEdge->Aspect()->SetColor (theAspect->EdgeColor()); + myAspectEdge->Aspect()->SetType (theAspect->EdgeLineType()); + myAspectEdge->Aspect()->SetWidth (theAspect->EdgeWidth()); // update texture binding myResources.UpdateTexturesRediness (myAspect->TextureSet()); diff --git a/src/OpenGl/OpenGl_AspectFace.hxx b/src/OpenGl/OpenGl_AspectFace.hxx index 8d93a114d6..ee32e54510 100644 --- a/src/OpenGl/OpenGl_AspectFace.hxx +++ b/src/OpenGl/OpenGl_AspectFace.hxx @@ -28,7 +28,7 @@ class OpenGl_Texture; //! The element holding Graphic3d_AspectFillArea3d. class OpenGl_AspectFace : public OpenGl_Element { - + DEFINE_STANDARD_RTTIEXT(OpenGl_AspectFace, OpenGl_Element) public: //! Empty constructor. @@ -44,10 +44,10 @@ public: Standard_EXPORT void SetAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspect); //! Set edge aspect. - void SetAspectEdge (const OpenGl_AspectLine* theAspectEdge) { myAspectEdge = *theAspectEdge; } + void SetAspectEdge (const Handle(OpenGl_AspectLine)& theAspectEdge) { myAspectEdge = theAspectEdge; } //! @return edge aspect. - const OpenGl_AspectLine* AspectEdge() const { return &myAspectEdge; } + const Handle(OpenGl_AspectLine)& AspectEdge() const { return myAspectEdge; } //! Returns Shading Model. Graphic3d_TypeOfShadingModel ShadingModel() const { return myShadingModel; } @@ -140,7 +140,7 @@ protected: } myResources; Handle(Graphic3d_AspectFillArea3d) myAspect; - OpenGl_AspectLine myAspectEdge; + Handle(OpenGl_AspectLine) myAspectEdge; Graphic3d_TypeOfShadingModel myShadingModel; public: diff --git a/src/OpenGl/OpenGl_AspectLine.cxx b/src/OpenGl/OpenGl_AspectLine.cxx index 31fbe7d7e7..d2b06e86c5 100644 --- a/src/OpenGl/OpenGl_AspectLine.cxx +++ b/src/OpenGl/OpenGl_AspectLine.cxx @@ -21,6 +21,8 @@ #include #include +IMPLEMENT_STANDARD_RTTIEXT(OpenGl_AspectLine, OpenGl_Element) + namespace { static const TCollection_AsciiString THE_EMPTY_KEY; diff --git a/src/OpenGl/OpenGl_AspectLine.hxx b/src/OpenGl/OpenGl_AspectLine.hxx index a44bd54671..2fd70fd20e 100644 --- a/src/OpenGl/OpenGl_AspectLine.hxx +++ b/src/OpenGl/OpenGl_AspectLine.hxx @@ -26,6 +26,7 @@ class OpenGl_ShaderProgram; //! The element holding Graphic3d_AspectLine3d. class OpenGl_AspectLine : public OpenGl_Element { + DEFINE_STANDARD_RTTIEXT(OpenGl_AspectLine, OpenGl_Element) public: //! Empty constructor. diff --git a/src/OpenGl/OpenGl_AspectMarker.cxx b/src/OpenGl/OpenGl_AspectMarker.cxx index d12df9a0cb..20157e072b 100644 --- a/src/OpenGl/OpenGl_AspectMarker.cxx +++ b/src/OpenGl/OpenGl_AspectMarker.cxx @@ -27,6 +27,8 @@ #include #include +IMPLEMENT_STANDARD_RTTIEXT(OpenGl_AspectMarker, OpenGl_Element) + namespace { static const TCollection_AsciiString THE_EMPTY_KEY; diff --git a/src/OpenGl/OpenGl_AspectMarker.hxx b/src/OpenGl/OpenGl_AspectMarker.hxx index c4178aa4b4..7eb3955054 100644 --- a/src/OpenGl/OpenGl_AspectMarker.hxx +++ b/src/OpenGl/OpenGl_AspectMarker.hxx @@ -29,6 +29,7 @@ class OpenGl_ShaderProgram; //! The element holding Graphic3d_AspectMarker3d. class OpenGl_AspectMarker : public OpenGl_Element { + DEFINE_STANDARD_RTTIEXT(OpenGl_AspectMarker, OpenGl_Element) public: //! Empty constructor. diff --git a/src/OpenGl/OpenGl_AspectText.cxx b/src/OpenGl/OpenGl_AspectText.cxx index 540c6ac97d..ab7c9d7ccd 100755 --- a/src/OpenGl/OpenGl_AspectText.cxx +++ b/src/OpenGl/OpenGl_AspectText.cxx @@ -21,6 +21,8 @@ #include #include +IMPLEMENT_STANDARD_RTTIEXT(OpenGl_AspectText, OpenGl_Element) + namespace { static const TCollection_AsciiString THE_EMPTY_KEY; diff --git a/src/OpenGl/OpenGl_AspectText.hxx b/src/OpenGl/OpenGl_AspectText.hxx index 2596b878a8..d41596d870 100755 --- a/src/OpenGl/OpenGl_AspectText.hxx +++ b/src/OpenGl/OpenGl_AspectText.hxx @@ -28,7 +28,7 @@ class OpenGl_ShaderProgram; //! Text representation parameters class OpenGl_AspectText : public OpenGl_Element { - + DEFINE_STANDARD_RTTIEXT(OpenGl_AspectText, OpenGl_Element) public: //! Empty constructor. diff --git a/src/OpenGl/OpenGl_BackgroundArray.cxx b/src/OpenGl/OpenGl_BackgroundArray.cxx index f760dcfc98..17e5611692 100644 --- a/src/OpenGl/OpenGl_BackgroundArray.cxx +++ b/src/OpenGl/OpenGl_BackgroundArray.cxx @@ -21,6 +21,8 @@ #include #include +IMPLEMENT_STANDARD_RTTIEXT(OpenGl_BackgroundArray, OpenGl_PrimitiveArray) + // ======================================================================= // method : Constructor // purpose : @@ -337,7 +339,7 @@ Standard_Boolean OpenGl_BackgroundArray::createTextureArray (const Handle(OpenGl // Get texture parameters const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext(); - const OpenGl_AspectFace* anAspectFace = theWorkspace->AspectFace(); + const Handle(OpenGl_AspectFace)& anAspectFace = theWorkspace->AspectFace(); GLfloat aTextureWidth = (GLfloat )anAspectFace->TextureSet (aCtx)->First()->SizeX(); GLfloat aTextureHeight = (GLfloat )anAspectFace->TextureSet (aCtx)->First()->SizeY(); diff --git a/src/OpenGl/OpenGl_BackgroundArray.hxx b/src/OpenGl/OpenGl_BackgroundArray.hxx index 8458736415..1f01b74c01 100644 --- a/src/OpenGl/OpenGl_BackgroundArray.hxx +++ b/src/OpenGl/OpenGl_BackgroundArray.hxx @@ -28,6 +28,7 @@ //! gradient or texture background rendering. class OpenGl_BackgroundArray : public OpenGl_PrimitiveArray { + DEFINE_STANDARD_RTTIEXT(OpenGl_BackgroundArray, OpenGl_PrimitiveArray) public: //! Main constructor. diff --git a/src/OpenGl/OpenGl_CappingAlgo.cxx b/src/OpenGl/OpenGl_CappingAlgo.cxx index 4338d502d5..274aea5385 100755 --- a/src/OpenGl/OpenGl_CappingAlgo.cxx +++ b/src/OpenGl/OpenGl_CappingAlgo.cxx @@ -104,8 +104,8 @@ namespace theStencilSentry.Init(); // check if capping plane should be rendered within current pass (only opaque / only transparent) - const OpenGl_AspectFace* anObjAspectFace = aRenderPlane->ToUseObjectProperties() ? aGroupIter.Value()->AspectFace() : NULL; - thePlane->Update (aContext, anObjAspectFace != NULL ? anObjAspectFace->Aspect() : Handle(Graphic3d_AspectFillArea3d)()); + const Handle(OpenGl_AspectFace) anObjAspectFace = aRenderPlane->ToUseObjectProperties() ? aGroupIter.Value()->AspectFace() : NULL; + thePlane->Update (aContext, !anObjAspectFace.IsNull() ? anObjAspectFace->Aspect() : Handle(Graphic3d_AspectFillArea3d)()); theWorkspace->SetAspectFace (thePlane->AspectFace()); theWorkspace->SetRenderFilter (aPrevFilter); if (!theWorkspace->ShouldRender (&thePlane->Primitives())) @@ -124,7 +124,7 @@ namespace const bool aColorMaskBack = aContext->SetColorMask (false); // override aspects, disable culling - theWorkspace->SetAspectFace (&theWorkspace->NoneCulling()); + theWorkspace->SetAspectFace (theWorkspace->NoneCulling()); theWorkspace->ApplyAspectFace(); // evaluate number of pair faces @@ -156,7 +156,7 @@ namespace } // override material, cull back faces - theWorkspace->SetAspectFace (&theWorkspace->FrontCulling()); + theWorkspace->SetAspectFace (theWorkspace->FrontCulling()); theWorkspace->ApplyAspectFace(); // enable all clip plane except the rendered one @@ -207,7 +207,7 @@ void OpenGl_CappingAlgo::RenderCapping (const Handle(OpenGl_Workspace)& theWorks } // remember current aspect face defined in workspace - const OpenGl_AspectFace* aFaceAsp = theWorkspace->AspectFace(); + const Handle(OpenGl_AspectFace) aFaceAsp = theWorkspace->AspectFace(); // only filled primitives should be rendered const Standard_Integer aPrevFilter = theWorkspace->RenderFilter(); diff --git a/src/OpenGl/OpenGl_CappingPlaneResource.cxx b/src/OpenGl/OpenGl_CappingPlaneResource.cxx index d551231791..f961d375c2 100755 --- a/src/OpenGl/OpenGl_CappingPlaneResource.cxx +++ b/src/OpenGl/OpenGl_CappingPlaneResource.cxx @@ -124,7 +124,7 @@ void OpenGl_CappingPlaneResource::Release (OpenGl_Context* theContext) // ======================================================================= void OpenGl_CappingPlaneResource::updateAspect (const Handle(Graphic3d_AspectFillArea3d)& theObjAspect) { - if (myAspect == NULL) + if (myAspect.IsNull()) { myAspect = new OpenGl_AspectFace(); myAspectMod = myPlaneRoot->MCountAspect() - 1; // mark out of sync diff --git a/src/OpenGl/OpenGl_CappingPlaneResource.hxx b/src/OpenGl/OpenGl_CappingPlaneResource.hxx index 7ac029f9f7..4145cd231e 100755 --- a/src/OpenGl/OpenGl_CappingPlaneResource.hxx +++ b/src/OpenGl/OpenGl_CappingPlaneResource.hxx @@ -61,7 +61,7 @@ public: const Handle(Graphic3d_ClipPlane)& Plane() const { return myPlaneRoot; } //! @return aspect face for rendering capping surface. - inline const OpenGl_AspectFace* AspectFace() const { return myAspect; } + inline const Handle(OpenGl_AspectFace)& AspectFace() const { return myAspect; } //! @return evaluated orientation matrix to transform infinite plane. inline const OpenGl_Matrix* Orientation() const { return &myOrientation; } @@ -81,7 +81,7 @@ private: OpenGl_PrimitiveArray myPrimitives; //!< vertices and texture coordinates for rendering OpenGl_Matrix myOrientation; //!< plane transformation matrix. - OpenGl_AspectFace* myAspect; //!< capping face aspect. + Handle(OpenGl_AspectFace) myAspect; //!< capping face aspect. Handle(Graphic3d_ClipPlane) myPlaneRoot; //!< parent clipping plane structure. Handle(Graphic3d_AspectFillArea3d) myFillAreaAspect; //!< own capping aspect unsigned int myEquationMod; //!< modification counter for plane equation. diff --git a/src/OpenGl/OpenGl_Context.cxx b/src/OpenGl/OpenGl_Context.cxx index 52509f4c15..89a632c57d 100644 --- a/src/OpenGl/OpenGl_Context.cxx +++ b/src/OpenGl/OpenGl_Context.cxx @@ -3165,7 +3165,7 @@ Handle(OpenGl_FrameBuffer) OpenGl_Context::SetDefaultFrameBuffer (const Handle(O // function : SetShadingMaterial // purpose : // ======================================================================= -void OpenGl_Context::SetShadingMaterial (const OpenGl_AspectFace* theAspect, +void OpenGl_Context::SetShadingMaterial (Handle(OpenGl_AspectFace)& theAspect, const Handle(Graphic3d_PresentationAttributes)& theHighlight) { const Handle(Graphic3d_AspectFillArea3d)& anAspect = (!theHighlight.IsNull() && !theHighlight->BasicFillAreaAspect().IsNull()) @@ -3237,7 +3237,7 @@ void OpenGl_Context::SetShadingMaterial (const OpenGl_AspectFace* theAspect, // function : CheckIsTransparent // purpose : // ======================================================================= -Standard_Boolean OpenGl_Context::CheckIsTransparent (const OpenGl_AspectFace* theAspect, +Standard_Boolean OpenGl_Context::CheckIsTransparent (Handle(OpenGl_AspectFace)& theAspect, const Handle(Graphic3d_PresentationAttributes)& theHighlight, Standard_ShortReal& theAlphaFront, Standard_ShortReal& theAlphaBack) diff --git a/src/OpenGl/OpenGl_Context.hxx b/src/OpenGl/OpenGl_Context.hxx index 13bf652ba2..d74c8d5cb5 100644 --- a/src/OpenGl/OpenGl_Context.hxx +++ b/src/OpenGl/OpenGl_Context.hxx @@ -696,17 +696,17 @@ public: //! @name methods to alter or retrieve current state Standard_EXPORT Standard_Boolean BindProgram (const Handle(OpenGl_ShaderProgram)& theProgram); //! Setup current shading material. - Standard_EXPORT void SetShadingMaterial (const OpenGl_AspectFace* theAspect, + Standard_EXPORT void SetShadingMaterial (Handle(OpenGl_AspectFace)& theAspect, const Handle(Graphic3d_PresentationAttributes)& theHighlight); //! Checks if transparency is required for the given aspect and highlight style. - Standard_EXPORT static Standard_Boolean CheckIsTransparent (const OpenGl_AspectFace* theAspect, + Standard_EXPORT static Standard_Boolean CheckIsTransparent (Handle(OpenGl_AspectFace)& theAspect, const Handle(Graphic3d_PresentationAttributes)& theHighlight, Standard_ShortReal& theAlphaFront, Standard_ShortReal& theAlphaBack); //! Checks if transparency is required for the given aspect and highlight style. - static Standard_Boolean CheckIsTransparent (const OpenGl_AspectFace* theAspect, + static Standard_Boolean CheckIsTransparent (Handle(OpenGl_AspectFace)& theAspect, const Handle(Graphic3d_PresentationAttributes)& theHighlight) { Standard_ShortReal anAlphaFront = 1.0f, anAlphaBack = 1.0f; diff --git a/src/OpenGl/OpenGl_Element.cxx b/src/OpenGl/OpenGl_Element.cxx index 0d5c53f5d5..9ffd180a7f 100755 --- a/src/OpenGl/OpenGl_Element.cxx +++ b/src/OpenGl/OpenGl_Element.cxx @@ -15,6 +15,8 @@ #include +IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Element, Standard_Transient) + // ======================================================================= // function : OpenGl_Element // purpose : diff --git a/src/OpenGl/OpenGl_Element.hxx b/src/OpenGl/OpenGl_Element.hxx index 8a14275a1a..4d23ded051 100644 --- a/src/OpenGl/OpenGl_Element.hxx +++ b/src/OpenGl/OpenGl_Element.hxx @@ -23,8 +23,9 @@ class OpenGl_Workspace; class OpenGl_Context; //! Base interface for drawable elements. -class OpenGl_Element +class OpenGl_Element : public Standard_Transient { + DEFINE_STANDARD_RTTIEXT(OpenGl_Element, Standard_Transient) public: Standard_EXPORT OpenGl_Element(); @@ -40,18 +41,14 @@ public: //! Pointer to the context is used because this method might be called //! when the context is already being destroyed and usage of a handle //! would be unsafe - template static void Destroy (OpenGl_Context* theContext, - theResource_t*& theElement) + Handle(OpenGl_Element)& theElement) { - if (theElement == NULL) + if (theElement.IsNull()) { return; } - theElement->Release (theContext); - OpenGl_Element* anElement = theElement; - delete anElement; theElement = NULL; } diff --git a/src/OpenGl/OpenGl_Flipper.cxx b/src/OpenGl/OpenGl_Flipper.cxx index 3a5a0673b1..c8797f56eb 100755 --- a/src/OpenGl/OpenGl_Flipper.cxx +++ b/src/OpenGl/OpenGl_Flipper.cxx @@ -22,6 +22,8 @@ #include +IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Flipper, OpenGl_Element) + // ======================================================================= // function : Constructor // purpose : diff --git a/src/OpenGl/OpenGl_Flipper.hxx b/src/OpenGl/OpenGl_Flipper.hxx index 7f159c5db9..14d92ca80b 100755 --- a/src/OpenGl/OpenGl_Flipper.hxx +++ b/src/OpenGl/OpenGl_Flipper.hxx @@ -27,6 +27,7 @@ class gp_Ax2; //! Originally, this element serves for need of flipping the 3D text of dimension presentations. class OpenGl_Flipper : public OpenGl_Element { + DEFINE_STANDARD_RTTIEXT(OpenGl_Flipper, OpenGl_Element) public: //! Construct rendering element to flip model-view matrix diff --git a/src/OpenGl/OpenGl_FrameStats.cxx b/src/OpenGl/OpenGl_FrameStats.cxx index cb64c5a186..4fda2dfb9c 100644 --- a/src/OpenGl/OpenGl_FrameStats.cxx +++ b/src/OpenGl/OpenGl_FrameStats.cxx @@ -203,9 +203,10 @@ void OpenGl_FrameStats::updateStructures (Standard_Integer theViewId, for (OpenGl_Structure::GroupIterator aGroupIter (aStruct->Groups()); aGroupIter.More(); aGroupIter.Next()) { const OpenGl_Group* aGroup = aGroupIter.Value(); - for (const OpenGl_ElementNode* aNodeIter = aGroup->FirstNode(); aNodeIter != NULL; aNodeIter = aNodeIter->next) + for (OpenGl_ElementNodes::Iterator anElemIterator (aGroup->GetElements()); anElemIterator.More(); anElemIterator.Next()) { - if (const OpenGl_PrimitiveArray* aPrim = dynamic_cast (aNodeIter->elem)) + Handle(OpenGl_PrimitiveArray) aPrim = Handle(OpenGl_PrimitiveArray)::DownCast (anElemIterator.Value()); + if (!aPrim.IsNull()) { myCountersTmp[Graphic3d_FrameStatsCounter_EstimatedBytesGeom] += estimatedDataSize (aPrim->AttributesVbo()); myCountersTmp[Graphic3d_FrameStatsCounter_EstimatedBytesGeom] += estimatedDataSize (aPrim->IndexVbo()); @@ -225,9 +226,10 @@ void OpenGl_FrameStats::updateStructures (Standard_Integer theViewId, for (OpenGl_Structure::GroupIterator aGroupIter (aStruct->Groups()); aGroupIter.More(); aGroupIter.Next()) { const OpenGl_Group* aGroup = aGroupIter.Value(); - for (const OpenGl_ElementNode* aNodeIter = aGroup->FirstNode(); aNodeIter != NULL; aNodeIter = aNodeIter->next) + for (OpenGl_ElementNodes::Iterator anElemIterator (aGroup->GetElements()); anElemIterator.More(); anElemIterator.Next()) { - if (const OpenGl_PrimitiveArray* aPrim = dynamic_cast (aNodeIter->elem)) + Handle(OpenGl_PrimitiveArray) aPrim = Handle(OpenGl_PrimitiveArray)::DownCast (anElemIterator.Value()); + if (!aPrim.IsNull()) { ++myCountersTmp[Graphic3d_FrameStatsCounter_NbElemsNotCulled]; if (theToCountMem) @@ -311,9 +313,8 @@ void OpenGl_FrameStats::updateStructures (Standard_Integer theViewId, ++myCountersTmp[Graphic3d_FrameStatsCounter_NbElemsLineNotCulled]; } } - else if (const OpenGl_Text* aText = dynamic_cast (aNodeIter->elem)) + else if (!Handle(OpenGl_Text)::DownCast(anElemIterator.Value()).IsNull()) { - (void )aText; ++myCountersTmp[Graphic3d_FrameStatsCounter_NbElemsNotCulled]; ++myCountersTmp[Graphic3d_FrameStatsCounter_NbElemsTextNotCulled]; } diff --git a/src/OpenGl/OpenGl_FrameStatsPrs.cxx b/src/OpenGl/OpenGl_FrameStatsPrs.cxx index b4ddc31932..e6a8a0f71c 100644 --- a/src/OpenGl/OpenGl_FrameStatsPrs.cxx +++ b/src/OpenGl/OpenGl_FrameStatsPrs.cxx @@ -19,6 +19,8 @@ #include +IMPLEMENT_STANDARD_RTTIEXT(OpenGl_FrameStatsPrs, OpenGl_Element) + namespace { //! Auxiliary structure defining vertex with two attributes. @@ -361,7 +363,7 @@ void OpenGl_FrameStatsPrs::Render (const Handle(OpenGl_Workspace)& theWorkspace) glDepthMask (GL_FALSE); } - const OpenGl_AspectText* aTextAspectBack = theWorkspace->SetAspectText (&myTextAspect); + const Handle(OpenGl_AspectText)& aTextAspectBack = theWorkspace->SetAspectText (&myTextAspect); aCtx->ModelWorldState.Push(); aCtx->ModelWorldState.ChangeCurrent().InitIdentity(); diff --git a/src/OpenGl/OpenGl_FrameStatsPrs.hxx b/src/OpenGl/OpenGl_FrameStatsPrs.hxx index 35231640c1..04ba8b292d 100644 --- a/src/OpenGl/OpenGl_FrameStatsPrs.hxx +++ b/src/OpenGl/OpenGl_FrameStatsPrs.hxx @@ -25,6 +25,7 @@ class OpenGl_VertexBuffer; //! Element rendering frame statistics. class OpenGl_FrameStatsPrs : public OpenGl_Element { + DEFINE_STANDARD_RTTIEXT(OpenGl_FrameStatsPrs, OpenGl_Element) public: //! Default constructor. diff --git a/src/OpenGl/OpenGl_GraduatedTrihedron.cxx b/src/OpenGl/OpenGl_GraduatedTrihedron.cxx index ecb35c61bc..db4279298b 100755 --- a/src/OpenGl/OpenGl_GraduatedTrihedron.cxx +++ b/src/OpenGl/OpenGl_GraduatedTrihedron.cxx @@ -32,6 +32,8 @@ #include #endif +IMPLEMENT_STANDARD_RTTIEXT(OpenGl_GraduatedTrihedron, OpenGl_Element) + namespace { static const OpenGl_TextParam THE_LABEL_PARAMS = @@ -605,8 +607,8 @@ void OpenGl_GraduatedTrihedron::Render (const Handle(OpenGl_Workspace)& theWorks Standard_ExtCharacter anAxesState = getGridAxes (aCorners, aGridAxes); // Remember current aspects - const OpenGl_AspectLine* anOldAspectLine = theWorkspace->AspectLine(); - const OpenGl_AspectText* anOldAspectText = theWorkspace->AspectText(); + const Handle(OpenGl_AspectLine)& anOldAspectLine = theWorkspace->AspectLine(); + const Handle(OpenGl_AspectText)& anOldAspectText = theWorkspace->AspectText(); OpenGl_Mat4 aModelMatrix; aModelMatrix.Convert (aContext->WorldViewState.Current()); diff --git a/src/OpenGl/OpenGl_GraduatedTrihedron.hxx b/src/OpenGl/OpenGl_GraduatedTrihedron.hxx index ac1da0f960..ea9f6bd6ab 100755 --- a/src/OpenGl/OpenGl_GraduatedTrihedron.hxx +++ b/src/OpenGl/OpenGl_GraduatedTrihedron.hxx @@ -34,6 +34,7 @@ class OpenGl_View; //! @sa Graphic3d_GraduatedTrihedron class OpenGl_GraduatedTrihedron : public OpenGl_Element { + DEFINE_STANDARD_RTTIEXT(OpenGl_GraduatedTrihedron, OpenGl_Element) public: DEFINE_STANDARD_ALLOC diff --git a/src/OpenGl/OpenGl_Group.cxx b/src/OpenGl/OpenGl_Group.cxx index 8e0b41514b..2f3b99da0d 100644 --- a/src/OpenGl/OpenGl_Group.cxx +++ b/src/OpenGl/OpenGl_Group.cxx @@ -40,7 +40,7 @@ namespace //! should be rendered or not. //! @return True if element passes the check and renders, static bool renderFiltered (const Handle(OpenGl_Workspace)& theWorkspace, - OpenGl_Element* theElement) + const Handle(OpenGl_Element)& theElement) { if (!theWorkspace->ShouldRender (theElement)) { @@ -58,12 +58,6 @@ namespace // ======================================================================= OpenGl_Group::OpenGl_Group (const Handle(Graphic3d_Structure)& theStruct) : Graphic3d_Group (theStruct), - myAspectLine(NULL), - myAspectFace(NULL), - myAspectMarker(NULL), - myAspectText(NULL), - myFirst(NULL), - myLast(NULL), myIsRaytracable (Standard_False) { Handle(OpenGl_Structure) aStruct = Handle(OpenGl_Structure)::DownCast (myStructure->CStructure()); @@ -93,7 +87,7 @@ void OpenGl_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectLine3d return; } - if (myAspectLine == NULL) + if (myAspectLine.IsNull()) { myAspectLine = new OpenGl_AspectLine (theAspect); } @@ -110,7 +104,7 @@ void OpenGl_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectLine3d // ======================================================================= void OpenGl_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& theAspect) { - if (myAspectLine == NULL) + if (myAspectLine.IsNull()) { SetGroupPrimitivesAspect (theAspect); return; @@ -120,7 +114,7 @@ void OpenGl_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& th return; } - OpenGl_AspectLine* anAspectLine = new OpenGl_AspectLine (theAspect); + Handle(OpenGl_AspectLine) anAspectLine = new OpenGl_AspectLine (theAspect); AddElement (anAspectLine); Update(); } @@ -136,7 +130,7 @@ void OpenGl_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectFillAr return; } - if (myAspectFace == NULL) + if (myAspectFace.IsNull()) { myAspectFace = new OpenGl_AspectFace (theAspect); } @@ -163,7 +157,7 @@ void OpenGl_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectFillAr // ======================================================================= void OpenGl_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspect) { - if (myAspectFace == NULL) + if (myAspectFace.IsNull()) { SetGroupPrimitivesAspect (theAspect); return; @@ -173,7 +167,7 @@ void OpenGl_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d) return; } - OpenGl_AspectFace* anAspectFace = new OpenGl_AspectFace (theAspect); + Handle(OpenGl_AspectFace) anAspectFace = new OpenGl_AspectFace (theAspect); AddElement (anAspectFace); Update(); } @@ -189,7 +183,7 @@ void OpenGl_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectMarker return; } - if (myAspectMarker == NULL) + if (myAspectMarker.IsNull()) { myAspectMarker = new OpenGl_AspectMarker (theAspMarker); } @@ -206,7 +200,7 @@ void OpenGl_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectMarker // ======================================================================= void OpenGl_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& theAspMarker) { - if (myAspectMarker == NULL) + if (myAspectMarker.IsNull()) { SetGroupPrimitivesAspect (theAspMarker); return; @@ -216,7 +210,7 @@ void OpenGl_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& return; } - OpenGl_AspectMarker* anAspectMarker = new OpenGl_AspectMarker (theAspMarker); + Handle(OpenGl_AspectMarker) anAspectMarker = new OpenGl_AspectMarker (theAspMarker); AddElement (anAspectMarker); Update(); } @@ -232,7 +226,7 @@ void OpenGl_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectText3d return; } - if (myAspectText == NULL) + if (myAspectText.IsNull()) { myAspectText = new OpenGl_AspectText (theAspText); } @@ -249,7 +243,7 @@ void OpenGl_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectText3d // ======================================================================= void OpenGl_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& theAspText) { - if (myAspectText == NULL) + if (myAspectText.IsNull()) { SetGroupPrimitivesAspect (theAspText); return; @@ -259,7 +253,7 @@ void OpenGl_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& th return; } - OpenGl_AspectText* anAspectText = new OpenGl_AspectText (theAspText); + Handle(OpenGl_AspectText) anAspectText = new OpenGl_AspectText (theAspText); AddElement (anAspectText); Update(); } @@ -270,25 +264,25 @@ void OpenGl_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& th // ======================================================================= void OpenGl_Group::SynchronizeAspects() { - if (myAspectFace != NULL) + if (!myAspectFace.IsNull()) { myAspectFace->SynchronizeAspects(); } - if (myAspectLine != NULL) + if (!myAspectLine.IsNull()) { myAspectLine->SynchronizeAspects(); } - if (myAspectMarker != NULL) + if (!myAspectMarker.IsNull()) { myAspectMarker->SynchronizeAspects(); } - if (myAspectText != NULL) + if (!myAspectText.IsNull()) { myAspectText->SynchronizeAspects(); } - for (OpenGl_ElementNode* aNode = myFirst; aNode != NULL; aNode = aNode->next) + for (OpenGl_ElementNodes::Iterator anElemIterator(myElements); anElemIterator.More(); anElemIterator.Next()) { - aNode->elem->SynchronizeAspects(); + anElemIterator.ChangeValue()->SynchronizeAspects(); } } @@ -311,7 +305,7 @@ void OpenGl_Group::AddPrimitiveArray (const Graphic3d_TypeOfPrimitiveArray theTy OpenGl_Structure* aStruct = GlStruct(); const OpenGl_GraphicDriver* aDriver = aStruct->GlDriver(); - OpenGl_PrimitiveArray* anArray = new OpenGl_PrimitiveArray (aDriver, theType, theIndices, theAttribs, theBounds); + Handle(OpenGl_PrimitiveArray) anArray = new OpenGl_PrimitiveArray (aDriver, theType, theIndices, theAttribs, theBounds); AddElement (anArray); Graphic3d_Group::AddPrimitiveArray (theType, theIndices, theAttribs, theBounds, theToEvalMinMax); @@ -341,7 +335,7 @@ void OpenGl_Group::Text (const Standard_CString theTextUtf, aParams.HAlign = theHta; aParams.VAlign = theVta; const OpenGl_Vec3 aPoint (thePoint.X(), thePoint.Y(), thePoint.Z()); - OpenGl_Text* aText = new OpenGl_Text (theTextUtf, aPoint, aParams); + Handle(OpenGl_Text) aText = new OpenGl_Text (theTextUtf, aPoint, aParams); AddElement (aText); Graphic3d_Group::Text (theTextUtf, thePoint, theHeight, theAngle, theTp, theHta, theVta, theToEvalMinMax); @@ -373,7 +367,7 @@ void OpenGl_Group::Text (const Standard_CString theTextUtf, aParams.HAlign = theHTA; aParams.VAlign = theVTA; - OpenGl_Text* aText = new OpenGl_Text (theTextUtf, theOrientation, aParams, theHasOwnAnchor != Standard_False); + Handle(OpenGl_Text) aText = new OpenGl_Text (theTextUtf, theOrientation, aParams, theHasOwnAnchor != Standard_False); AddElement (aText); @@ -396,7 +390,7 @@ void OpenGl_Group::Text (const Standard_CString theTextUtf, void OpenGl_Group::SetFlippingOptions (const Standard_Boolean theIsEnabled, const gp_Ax2& theRefPlane) { - OpenGl_Flipper* aFlipper = new OpenGl_Flipper (theRefPlane); + Handle(OpenGl_Flipper) aFlipper = new OpenGl_Flipper (theRefPlane); aFlipper->SetOptions (theIsEnabled); AddElement (aFlipper); } @@ -407,7 +401,7 @@ void OpenGl_Group::SetFlippingOptions (const Standard_Boolean theIsEnabled, // ======================================================================= void OpenGl_Group::SetStencilTestOptions (const Standard_Boolean theIsEnabled) { - OpenGl_StencilTest* aStencilTest = new OpenGl_StencilTest(); + Handle(OpenGl_StencilTest) aStencilTest = new OpenGl_StencilTest(); aStencilTest->SetOptions (theIsEnabled); AddElement (aStencilTest); } @@ -416,16 +410,11 @@ void OpenGl_Group::SetStencilTestOptions (const Standard_Boolean theIsEnabled) // function : AddElement // purpose : // ======================================================================= -void OpenGl_Group::AddElement (OpenGl_Element* theElem) +void OpenGl_Group::AddElement (Handle(OpenGl_Element) theElem) { - OpenGl_ElementNode *aNode = new OpenGl_ElementNode(); + myElements.Append (theElem); - aNode->elem = theElem; - aNode->next = NULL; - (myLast? myLast->next : myFirst) = aNode; - myLast = aNode; - - if (OpenGl_Raytrace::IsRaytracedElement (aNode)) + if (OpenGl_Raytrace::IsRaytracedElement (theElem)) { myIsRaytracable = Standard_True; @@ -446,19 +435,19 @@ void OpenGl_Group::Render (const Handle(OpenGl_Workspace)& theWorkspace) const // Setup aspects theWorkspace->SetAllowFaceCulling (myIsClosed && !theWorkspace->GetGlContext()->Clipping().IsClippingOrCappingOn()); - const OpenGl_AspectLine* aBackAspectLine = theWorkspace->AspectLine(); - const OpenGl_AspectFace* aBackAspectFace = theWorkspace->AspectFace(); - const OpenGl_AspectMarker* aBackAspectMarker = theWorkspace->AspectMarker(); - const OpenGl_AspectText* aBackAspectText = theWorkspace->AspectText(); - const bool isLineSet = myAspectLine && renderFiltered (theWorkspace, myAspectLine); - const bool isFaceSet = myAspectFace && renderFiltered (theWorkspace, myAspectFace); - const bool isMarkerSet = myAspectMarker && renderFiltered (theWorkspace, myAspectMarker); - const bool isTextSet = myAspectText && renderFiltered (theWorkspace, myAspectText); + const Handle(OpenGl_AspectLine)& aBackAspectLine = theWorkspace->AspectLine(); + const Handle(OpenGl_AspectFace)& aBackAspectFace = theWorkspace->AspectFace(); + const Handle(OpenGl_AspectMarker)& aBackAspectMarker = theWorkspace->AspectMarker(); + const Handle(OpenGl_AspectText)& aBackAspectText = theWorkspace->AspectText(); + const bool isLineSet = !myAspectLine.IsNull() && renderFiltered (theWorkspace, myAspectLine); + const bool isFaceSet = !myAspectFace.IsNull() && renderFiltered (theWorkspace, myAspectFace); + const bool isMarkerSet = !myAspectMarker.IsNull() && renderFiltered (theWorkspace, myAspectMarker); + const bool isTextSet = !myAspectText.IsNull() && renderFiltered (theWorkspace, myAspectText); // Render group elements - for (OpenGl_ElementNode* aNodeIter = myFirst; aNodeIter != NULL; aNodeIter = aNodeIter->next) + for (OpenGl_ElementNodes::Iterator anElemIterator(myElements); anElemIterator.More(); anElemIterator.Next()) { - renderFiltered (theWorkspace, aNodeIter->elem); + renderFiltered (theWorkspace, anElemIterator.Value()); } // Restore aspects @@ -499,14 +488,11 @@ void OpenGl_Group::Clear (const Standard_Boolean theToUpdateStructureMgr) void OpenGl_Group::Release (const Handle(OpenGl_Context)& theGlCtx) { // Delete elements - while (myFirst != NULL) + for (OpenGl_ElementNodes::Iterator anElemIterator(myElements); anElemIterator.More(); anElemIterator.Next()) { - OpenGl_ElementNode* aNext = myFirst->next; - OpenGl_Element::Destroy (theGlCtx.operator->(), myFirst->elem); - delete myFirst; - myFirst = aNext; + OpenGl_Element::Destroy (theGlCtx.operator->(), anElemIterator.ChangeValue()); } - myLast = NULL; + myElements.Clear(); OpenGl_Element::Destroy (theGlCtx.operator->(), myAspectLine); OpenGl_Element::Destroy (theGlCtx.operator->(), myAspectFace); diff --git a/src/OpenGl/OpenGl_Group.hxx b/src/OpenGl/OpenGl_Group.hxx index eb779abad7..2ada742370 100644 --- a/src/OpenGl/OpenGl_Group.hxx +++ b/src/OpenGl/OpenGl_Group.hxx @@ -29,12 +29,7 @@ class OpenGl_Group; class OpenGl_Structure; -struct OpenGl_ElementNode -{ - OpenGl_Element* elem; - OpenGl_ElementNode* next; - DEFINE_STANDARD_ALLOC -}; +typedef NCollection_List OpenGl_ElementNodes; //! Implementation of low-level graphic group. class OpenGl_Group : public Graphic3d_Group @@ -50,9 +45,9 @@ public: //! Return line aspect. virtual Handle(Graphic3d_AspectLine3d) LineAspect() const Standard_OVERRIDE { - return myAspectLine != NULL - ? myAspectLine->Aspect() - : Handle(Graphic3d_AspectLine3d)(); + return !myAspectLine.IsNull() + ? myAspectLine->Aspect() + : Handle(Graphic3d_AspectLine3d)(); } //! Update line aspect. @@ -64,9 +59,9 @@ public: //! Return marker aspect. virtual Handle(Graphic3d_AspectMarker3d) MarkerAspect() const Standard_OVERRIDE { - return myAspectMarker != NULL - ? myAspectMarker->Aspect() - : Handle(Graphic3d_AspectMarker3d)(); + return !myAspectMarker.IsNull() + ? myAspectMarker->Aspect() + : Handle(Graphic3d_AspectMarker3d)(); } //! Update marker aspect. @@ -78,7 +73,7 @@ public: //! Return fill area aspect. virtual Handle(Graphic3d_AspectFillArea3d) FillAreaAspect() const Standard_OVERRIDE { - return myAspectFace != NULL + return !myAspectFace.IsNull() ? myAspectFace->Aspect() : Handle(Graphic3d_AspectFillArea3d)(); } @@ -92,7 +87,7 @@ public: //! Return marker aspect. virtual Handle(Graphic3d_AspectText3d) TextAspect() const Standard_OVERRIDE { - return myAspectText != NULL + return !myAspectText.IsNull() ? myAspectText->Aspect() : Handle(Graphic3d_AspectText3d)(); } @@ -145,16 +140,16 @@ public: OpenGl_Structure* GlStruct() const { return (OpenGl_Structure* )(myStructure->CStructure().operator->()); } - Standard_EXPORT void AddElement (OpenGl_Element* theElem); + Standard_EXPORT void AddElement (Handle(OpenGl_Element) theElem); Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const; Standard_EXPORT virtual void Release (const Handle(OpenGl_Context)& theGlCtx); - //! Returns first OpenGL element node of the group. - const OpenGl_ElementNode* FirstNode() const { return myFirst; } + //! Returns OpenGl elements of the group + const OpenGl_ElementNodes& GetElements() const { return myElements; } //! Returns OpenGL face aspect. - const OpenGl_AspectFace* AspectFace() const { return myAspectFace; } + const Handle(OpenGl_AspectFace)& AspectFace() const { return myAspectFace; } //! Is the group ray-tracable (contains ray-tracable elements)? Standard_Boolean IsRaytracable() const { return myIsRaytracable; } @@ -165,13 +160,12 @@ protected: protected: - OpenGl_AspectLine* myAspectLine; - OpenGl_AspectFace* myAspectFace; - OpenGl_AspectMarker* myAspectMarker; - OpenGl_AspectText* myAspectText; + Handle(OpenGl_AspectLine) myAspectLine; + Handle(OpenGl_AspectFace) myAspectFace; + Handle(OpenGl_AspectMarker) myAspectMarker; + Handle(OpenGl_AspectText) myAspectText; - OpenGl_ElementNode* myFirst; - OpenGl_ElementNode* myLast; + OpenGl_ElementNodes myElements; Standard_Boolean myIsRaytracable; diff --git a/src/OpenGl/OpenGl_PrimitiveArray.cxx b/src/OpenGl/OpenGl_PrimitiveArray.cxx index 8986de7bb6..f0ffc320f9 100644 --- a/src/OpenGl/OpenGl_PrimitiveArray.cxx +++ b/src/OpenGl/OpenGl_PrimitiveArray.cxx @@ -13,12 +13,13 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. +#include + #include #include #include #include #include -#include #include #include #include @@ -28,6 +29,8 @@ #include #include +IMPLEMENT_STANDARD_RTTIEXT(OpenGl_PrimitiveArray, OpenGl_Element) + namespace { //! Convert data type to GL info @@ -502,8 +505,8 @@ void OpenGl_PrimitiveArray::drawEdges (const OpenGl_Vec4& theEdgeCo return; } - const OpenGl_AspectLine* anAspectLineOld = theWorkspace->SetAspectLine (theWorkspace->AspectFace()->AspectEdge()); - const OpenGl_AspectLine* anAspect = theWorkspace->ApplyAspectLine(); + const Handle(OpenGl_AspectLine) anAspectLineOld = theWorkspace->SetAspectLine (theWorkspace->AspectFace()->AspectEdge()); + const Handle(OpenGl_AspectLine) anAspect = theWorkspace->ApplyAspectLine(); #if !defined(GL_ES_VERSION_2_0) glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); @@ -588,8 +591,8 @@ void OpenGl_PrimitiveArray::drawEdges (const OpenGl_Vec4& theEdgeCo // ======================================================================= void OpenGl_PrimitiveArray::drawMarkers (const Handle(OpenGl_Workspace)& theWorkspace) const { - const OpenGl_AspectMarker* anAspectMarker = theWorkspace->ApplyAspectMarker(); - const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext(); + const Handle(OpenGl_AspectMarker) anAspectMarker = theWorkspace->ApplyAspectMarker(); + const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext(); const GLenum aDrawMode = !aCtx->ActiveProgram().IsNull() && aCtx->ActiveProgram()->HasTessellationStage() ? GL_PATCHES @@ -765,9 +768,9 @@ void OpenGl_PrimitiveArray::Render (const Handle(OpenGl_Workspace)& theWorkspace return; } - const OpenGl_AspectFace* anAspectFace = theWorkspace->ApplyAspectFace(); - const OpenGl_AspectLine* anAspectLine = theWorkspace->ApplyAspectLine(); - const OpenGl_AspectMarker* anAspectMarker = myDrawMode == GL_POINTS + const Handle(OpenGl_AspectFace) anAspectFace = theWorkspace->ApplyAspectFace(); + const Handle(OpenGl_AspectLine) anAspectLine = theWorkspace->ApplyAspectLine(); + const Handle(OpenGl_AspectMarker) anAspectMarker = myDrawMode == GL_POINTS ? theWorkspace->ApplyAspectMarker() : theWorkspace->AspectMarker(); @@ -1041,7 +1044,7 @@ Standard_Boolean OpenGl_PrimitiveArray::processIndices (const Handle(OpenGl_Cont return Standard_True; } - if (myAttribs->NbElements > std::numeric_limits::max()) + if (myAttribs->NbElements > IntegerLast()/*std::numeric_limits::max()*/) { Handle(Graphic3d_Buffer) anAttribs = new Graphic3d_Buffer (new NCollection_AlignedAllocator (16)); if (!anAttribs->Init (myIndices->NbElements, myAttribs->AttributesArray(), myAttribs->NbAttributes)) diff --git a/src/OpenGl/OpenGl_PrimitiveArray.hxx b/src/OpenGl/OpenGl_PrimitiveArray.hxx index 811b222071..d10de8c0f1 100644 --- a/src/OpenGl/OpenGl_PrimitiveArray.hxx +++ b/src/OpenGl/OpenGl_PrimitiveArray.hxx @@ -31,6 +31,7 @@ class OpenGl_GraphicDriver; //! Class for rendering of arbitrary primitive array. class OpenGl_PrimitiveArray : public OpenGl_Element { + DEFINE_STANDARD_RTTIEXT(OpenGl_PrimitiveArray, OpenGl_Element) public: //! OpenGL does not provide a constant for "none" draw mode. //! So we define our own one that does not conflict with GL constants and utilizes common GL invalid value. diff --git a/src/OpenGl/OpenGl_SceneGeometry.cxx b/src/OpenGl/OpenGl_SceneGeometry.cxx index 530bf57048..71dcd2eb64 100644 --- a/src/OpenGl/OpenGl_SceneGeometry.cxx +++ b/src/OpenGl/OpenGl_SceneGeometry.cxx @@ -593,21 +593,10 @@ namespace OpenGl_Raytrace // function : IsRaytracedElement // purpose : Checks to see if the element contains ray-trace geometry // ======================================================================= - Standard_Boolean IsRaytracedElement (const OpenGl_ElementNode* theNode) + Standard_Boolean IsRaytracedElement (const Handle(OpenGl_Element) theElement) { - OpenGl_PrimitiveArray* anArray = dynamic_cast (theNode->elem); - return anArray != NULL - && anArray->DrawMode() >= GL_TRIANGLES; - } - - // ======================================================================= - // function : IsRaytracedElement - // purpose : Checks to see if the element contains ray-trace geometry - // ======================================================================= - Standard_Boolean IsRaytracedElement (const OpenGl_Element* theElement) - { - const OpenGl_PrimitiveArray* anArray = dynamic_cast (theElement); - return anArray != NULL + Handle(OpenGl_PrimitiveArray) anArray = Handle(OpenGl_PrimitiveArray)::DownCast (theElement); + return !anArray.IsNull() && anArray->DrawMode() >= GL_TRIANGLES; } @@ -617,9 +606,9 @@ namespace OpenGl_Raytrace // ======================================================================= Standard_Boolean IsRaytracedGroup (const OpenGl_Group* theGroup) { - for (const OpenGl_ElementNode* aNode = theGroup->FirstNode(); aNode != NULL; aNode = aNode->next) + for (OpenGl_ElementNodes::Iterator anElemIterator (theGroup->GetElements()); anElemIterator.More(); anElemIterator.Next()) { - if (IsRaytracedElement (aNode)) + if (IsRaytracedElement (anElemIterator.Value())) { return Standard_True; } diff --git a/src/OpenGl/OpenGl_SceneGeometry.hxx b/src/OpenGl/OpenGl_SceneGeometry.hxx index 8fa64e2959..dc12f204c0 100644 --- a/src/OpenGl/OpenGl_SceneGeometry.hxx +++ b/src/OpenGl/OpenGl_SceneGeometry.hxx @@ -36,10 +36,7 @@ namespace OpenGl_Raytrace Standard_Boolean IsRaytracedGroup (const OpenGl_Group* theGroup); //! Checks to see if the element contains ray-trace geometry. - Standard_Boolean IsRaytracedElement (const OpenGl_ElementNode* theNode); - - //! Checks to see if the element contains ray-trace geometry. - Standard_Boolean IsRaytracedElement (const OpenGl_Element* theElement); + Standard_Boolean IsRaytracedElement (const Handle(OpenGl_Element) theElement); } //! Stores properties of surface material. diff --git a/src/OpenGl/OpenGl_StencilTest.cxx b/src/OpenGl/OpenGl_StencilTest.cxx index ba5dab14a4..c1240b0950 100755 --- a/src/OpenGl/OpenGl_StencilTest.cxx +++ b/src/OpenGl/OpenGl_StencilTest.cxx @@ -16,6 +16,8 @@ #include #include +IMPLEMENT_STANDARD_RTTIEXT(OpenGl_StencilTest, OpenGl_Element) + OpenGl_StencilTest::OpenGl_StencilTest() { // diff --git a/src/OpenGl/OpenGl_StencilTest.hxx b/src/OpenGl/OpenGl_StencilTest.hxx index f540c199e9..5771d1086e 100755 --- a/src/OpenGl/OpenGl_StencilTest.hxx +++ b/src/OpenGl/OpenGl_StencilTest.hxx @@ -20,6 +20,7 @@ class OpenGl_StencilTest : public OpenGl_Element { + DEFINE_STANDARD_RTTIEXT(OpenGl_StencilTest, OpenGl_Element) public: //! Default constructor diff --git a/src/OpenGl/OpenGl_Structure.cxx b/src/OpenGl/OpenGl_Structure.cxx index c21435cd5d..5a4f2cb42e 100644 --- a/src/OpenGl/OpenGl_Structure.cxx +++ b/src/OpenGl/OpenGl_Structure.cxx @@ -460,10 +460,10 @@ void OpenGl_Structure::Render (const Handle(OpenGl_Workspace) &theWorkspace) con aCtx->ApplyModelViewMatrix(); // remember aspects - const OpenGl_AspectLine* aPrevAspectLine = theWorkspace->AspectLine(); - const OpenGl_AspectFace* aPrevAspectFace = theWorkspace->AspectFace(); - const OpenGl_AspectMarker* aPrevAspectMarker = theWorkspace->AspectMarker(); - const OpenGl_AspectText* aPrevAspectText = theWorkspace->AspectText(); + const Handle(OpenGl_AspectLine)& aPrevAspectLine = theWorkspace->AspectLine(); + const Handle(OpenGl_AspectFace)& aPrevAspectFace = theWorkspace->AspectFace(); + const Handle(OpenGl_AspectMarker)& aPrevAspectMarker = theWorkspace->AspectMarker(); + const Handle(OpenGl_AspectText)& aPrevAspectText = theWorkspace->AspectText(); // Apply correction for mirror transform if (myIsMirrored) diff --git a/src/OpenGl/OpenGl_Text.cxx b/src/OpenGl/OpenGl_Text.cxx index 3ca3e6a126..aea8b5002e 100644 --- a/src/OpenGl/OpenGl_Text.cxx +++ b/src/OpenGl/OpenGl_Text.cxx @@ -29,6 +29,8 @@ #include #include +IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Text, OpenGl_Element) + namespace { static const GLdouble THE_IDENTITY_MATRIX[16] = @@ -353,10 +355,10 @@ void OpenGl_Text::StringSize (const Handle(OpenGl_Context)& theCtx, // ======================================================================= void OpenGl_Text::Render (const Handle(OpenGl_Workspace)& theWorkspace) const { - theWorkspace->SetAspectFace (&theWorkspace->FontFaceAspect()); + theWorkspace->SetAspectFace (theWorkspace->FontFaceAspect()); theWorkspace->ApplyAspectFace(); - const OpenGl_AspectText* aTextAspect = theWorkspace->ApplyAspectText(); - const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext(); + const Handle(OpenGl_AspectText) aTextAspect = theWorkspace->ApplyAspectText(); + const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext(); const Handle(OpenGl_TextureSet) aPrevTexture = aCtx->BindTextures (Handle(OpenGl_TextureSet)()); // Bind custom shader program or generate default version diff --git a/src/OpenGl/OpenGl_Text.hxx b/src/OpenGl/OpenGl_Text.hxx index e076ae1981..09b9e5acf2 100755 --- a/src/OpenGl/OpenGl_Text.hxx +++ b/src/OpenGl/OpenGl_Text.hxx @@ -33,7 +33,7 @@ //! Text rendering class OpenGl_Text : public OpenGl_Element { - + DEFINE_STANDARD_RTTIEXT(OpenGl_Text, OpenGl_Element) public: //! Main constructor diff --git a/src/OpenGl/OpenGl_View.cxx b/src/OpenGl/OpenGl_View.cxx index 789961ea09..7cb26b309d 100644 --- a/src/OpenGl/OpenGl_View.cxx +++ b/src/OpenGl/OpenGl_View.cxx @@ -143,15 +143,15 @@ void OpenGl_View::ReleaseGlResources (const Handle(OpenGl_Context)& theCtx) myTextureEnv.Nullify(); } - if (myTextureParams != NULL) + if (!myTextureParams.IsNull()) { myTextureParams->Release (theCtx.operator->()); } - if (myBgGradientArray != NULL) + if (!myBgGradientArray.IsNull()) { myBgGradientArray->Release (theCtx.operator->()); } - if (myBgTextureArray != NULL) + if (!myBgTextureArray.IsNull()) { myBgTextureArray->Release (theCtx.operator->()); } diff --git a/src/OpenGl/OpenGl_View.hxx b/src/OpenGl/OpenGl_View.hxx index b318974261..029f2a1eca 100644 --- a/src/OpenGl/OpenGl_View.hxx +++ b/src/OpenGl/OpenGl_View.hxx @@ -520,9 +520,9 @@ protected: //! @name Rendering properties protected: //! @name Background parameters - OpenGl_AspectFace* myTextureParams; //!< Stores texture and its parameters for textured background - OpenGl_BackgroundArray* myBgGradientArray; //!< Primitive array for gradient background - OpenGl_BackgroundArray* myBgTextureArray; //!< Primitive array for texture background + Handle(OpenGl_AspectFace) myTextureParams; //!< Stores texture and its parameters for textured background + Handle(OpenGl_BackgroundArray) myBgGradientArray; //!< Primitive array for gradient background + Handle(OpenGl_BackgroundArray) myBgTextureArray; //!< Primitive array for texture background protected: //! @name data types related to ray-tracing @@ -776,11 +776,11 @@ protected: //! @name methods related to ray-tracing const Handle(OpenGl_Context)& theGlContext); //! Creates ray-tracing material properties. - OpenGl_RaytraceMaterial convertMaterial (const OpenGl_AspectFace* theAspect, + OpenGl_RaytraceMaterial convertMaterial (const Handle(OpenGl_AspectFace)& theAspect, const Handle(OpenGl_Context)& theGlContext); //! Adds OpenGL primitive array to ray-traced scene geometry. - Handle(OpenGl_TriangleSet) addRaytracePrimitiveArray (const OpenGl_PrimitiveArray* theArray, + Handle(OpenGl_TriangleSet) addRaytracePrimitiveArray (const Handle(OpenGl_PrimitiveArray) theArray, const Standard_Integer theMatID, const OpenGl_Mat4* theTrans); diff --git a/src/OpenGl/OpenGl_View_Raytrace.cxx b/src/OpenGl/OpenGl_View_Raytrace.cxx index 60322e1059..93e35a8580 100644 --- a/src/OpenGl/OpenGl_View_Raytrace.cxx +++ b/src/OpenGl/OpenGl_View_Raytrace.cxx @@ -144,11 +144,10 @@ Standard_Boolean OpenGl_View::updateRaytraceGeometry (const RaytraceUpdateMode for (OpenGl_Structure::GroupIterator aGroupIter (aStructure->Groups()); aGroupIter.More(); aGroupIter.Next()) { // Extract OpenGL elements from the group (primitives arrays) - for (const OpenGl_ElementNode* aNode = aGroupIter.Value()->FirstNode(); aNode != NULL; aNode = aNode->next) + for (OpenGl_ElementNodes::Iterator anElemIterator (aGroupIter.Value()->GetElements()); anElemIterator.More(); anElemIterator.Next()) { - OpenGl_PrimitiveArray* aPrimArray = dynamic_cast (aNode->elem); - - if (aPrimArray != NULL) + Handle(OpenGl_PrimitiveArray) aPrimArray = Handle(OpenGl_PrimitiveArray)::DownCast (anElemIterator.Value()); + if (!aPrimArray.IsNull()) { anArrayIDs.insert (aPrimArray->GetUID()); } @@ -344,7 +343,7 @@ void buildTextureTransform (const Handle(Graphic3d_TextureParams)& theParams, BV // function : convertMaterial // purpose : Creates ray-tracing material properties // ======================================================================= -OpenGl_RaytraceMaterial OpenGl_View::convertMaterial (const OpenGl_AspectFace* theAspect, +OpenGl_RaytraceMaterial OpenGl_View::convertMaterial (const Handle(OpenGl_AspectFace)& theAspect, const Handle(OpenGl_Context)& theGlContext) { OpenGl_RaytraceMaterial theMaterial; @@ -509,7 +508,7 @@ Standard_Boolean OpenGl_View::addRaytraceGroups (const OpenGl_Structure* { // Get group material OpenGl_RaytraceMaterial aGroupMaterial; - if (aGroupIter.Value()->AspectFace() != NULL) + if (!aGroupIter.Value()->AspectFace().IsNull()) { aGroupMaterial = convertMaterial ( aGroupIter.Value()->AspectFace(), theGlContext); @@ -519,14 +518,14 @@ Standard_Boolean OpenGl_View::addRaytraceGroups (const OpenGl_Structure* // Use group material if available, otherwise use structure material myRaytraceGeometry.Materials.push_back ( - aGroupIter.Value()->AspectFace() != NULL ? aGroupMaterial : theStructMat); + !aGroupIter.Value()->AspectFace().IsNull() ? aGroupMaterial : theStructMat); // Add OpenGL elements from group (extract primitives arrays and aspects) - for (const OpenGl_ElementNode* aNode = aGroupIter.Value()->FirstNode(); aNode != NULL; aNode = aNode->next) + for (OpenGl_ElementNodes::Iterator anElemIterator (aGroupIter.Value()->GetElements()); anElemIterator.More(); anElemIterator.Next()) { - OpenGl_AspectFace* anAspect = dynamic_cast (aNode->elem); + Handle(OpenGl_AspectFace) anAspect = Handle(OpenGl_AspectFace)::DownCast (anElemIterator.Value()); - if (anAspect != NULL) + if (!anAspect.IsNull()) { aMatID = static_cast (myRaytraceGeometry.Materials.size()); @@ -536,9 +535,9 @@ Standard_Boolean OpenGl_View::addRaytraceGroups (const OpenGl_Structure* } else { - OpenGl_PrimitiveArray* aPrimArray = dynamic_cast (aNode->elem); + Handle(OpenGl_PrimitiveArray) aPrimArray = Handle(OpenGl_PrimitiveArray)::DownCast (anElemIterator.Value()); - if (aPrimArray != NULL) + if (!aPrimArray.IsNull()) { std::map::iterator aSetIter = myArrayToTrianglesMap.find (aPrimArray->GetUID()); @@ -585,7 +584,7 @@ Standard_Boolean OpenGl_View::addRaytraceGroups (const OpenGl_Structure* // function : addRaytracePrimitiveArray // purpose : Adds OpenGL primitive array to ray-traced scene geometry // ======================================================================= -Handle(OpenGl_TriangleSet) OpenGl_View::addRaytracePrimitiveArray (const OpenGl_PrimitiveArray* theArray, +Handle(OpenGl_TriangleSet) OpenGl_View::addRaytracePrimitiveArray (const Handle(OpenGl_PrimitiveArray) theArray, const Standard_Integer theMaterial, const OpenGl_Mat4* theTransform) { @@ -2680,7 +2679,7 @@ Standard_Boolean OpenGl_View::setUniformState (const Standard_Integer the } // Set background colors (only gradient background supported) - if (myBgGradientArray != NULL && myBgGradientArray->IsDefined()) + if (!myBgGradientArray.IsNull() && myBgGradientArray->IsDefined()) { theProgram->SetUniform (theGlContext, myUniformLocations[theProgramId][OpenGl_RT_uBackColorTop], myBgGradientArray->GradientColor (0)); diff --git a/src/OpenGl/OpenGl_View_Redraw.cxx b/src/OpenGl/OpenGl_View_Redraw.cxx index b88fcd15a4..7acfdb795d 100644 --- a/src/OpenGl/OpenGl_View_Redraw.cxx +++ b/src/OpenGl/OpenGl_View_Redraw.cxx @@ -125,7 +125,7 @@ void OpenGl_View::drawBackground (const Handle(OpenGl_Workspace)& theWorkspace) { aCtx->core11fwd->glDisable (GL_BLEND); - const OpenGl_AspectFace* anOldAspectFace = theWorkspace->SetAspectFace (myTextureParams); + const Handle(OpenGl_AspectFace) anOldAspectFace = theWorkspace->SetAspectFace (myTextureParams); myBgTextureArray->Render (theWorkspace); theWorkspace->SetAspectFace (anOldAspectFace); } diff --git a/src/OpenGl/OpenGl_Workspace.cxx b/src/OpenGl/OpenGl_Workspace.cxx index ab9fa99203..7c5abcb6b2 100644 --- a/src/OpenGl/OpenGl_Workspace.cxx +++ b/src/OpenGl/OpenGl_Workspace.cxx @@ -123,16 +123,25 @@ OpenGl_Workspace::OpenGl_Workspace (OpenGl_View* theView, const Handle(OpenGl_Wi myNbSkippedTranspElems (0), myRenderFilter (OpenGl_RenderFilter_Empty), // - myAspectLineSet (&myDefaultAspectLine), - myAspectFaceSet (&myDefaultAspectFace), - myAspectMarkerSet (&myDefaultAspectMarker), - myAspectTextSet (&myDefaultAspectText), - // ViewMatrix_applied (&myDefaultMatrix), StructureMatrix_applied (&myDefaultMatrix), myToAllowFaceCulling (false), myModelViewMatrix (myDefaultMatrix) { + myDefaultAspectLine = new OpenGl_AspectLine(); + myDefaultAspectFace = new OpenGl_AspectFace(); + myDefaultAspectMarker = new OpenGl_AspectMarker(); + myDefaultAspectText = new OpenGl_AspectText(); + + myNoneCulling = new OpenGl_AspectFace(); + myFrontCulling = new OpenGl_AspectFace(); + myFontFaceAspect = new OpenGl_AspectFace(); + + myAspectLineSet = myDefaultAspectLine; + myAspectFaceSet = myDefaultAspectFace; + myAspectMarkerSet = myDefaultAspectMarker; + myAspectTextSet = myDefaultAspectText; + if (!myGlContext.IsNull() && myGlContext->MakeCurrent()) { myGlContext->core11fwd->glPixelStorei (GL_UNPACK_ALIGNMENT, 1); @@ -155,16 +164,16 @@ OpenGl_Workspace::OpenGl_Workspace (OpenGl_View* theView, const Handle(OpenGl_Wi #endif } - myFontFaceAspect.Aspect()->SetAlphaMode (Graphic3d_AlphaMode_Mask, 0.285f); - myFontFaceAspect.Aspect()->SetShadingModel (Graphic3d_TOSM_UNLIT); + myFontFaceAspect->Aspect()->SetAlphaMode (Graphic3d_AlphaMode_Mask, 0.285f); + myFontFaceAspect->Aspect()->SetShadingModel (Graphic3d_TOSM_UNLIT); - myNoneCulling .Aspect()->SetSuppressBackFaces (false); - myNoneCulling .Aspect()->SetDrawEdges (false); - myNoneCulling .Aspect()->SetAlphaMode (Graphic3d_AlphaMode_Opaque); + myNoneCulling->Aspect()->SetSuppressBackFaces (false); + myNoneCulling->Aspect()->SetDrawEdges (false); + myNoneCulling->Aspect()->SetAlphaMode (Graphic3d_AlphaMode_Opaque); - myFrontCulling.Aspect()->SetSuppressBackFaces (true); - myFrontCulling.Aspect()->SetDrawEdges (false); - myFrontCulling.Aspect()->SetAlphaMode (Graphic3d_AlphaMode_Opaque); + myFrontCulling->Aspect()->SetSuppressBackFaces (true); + myFrontCulling->Aspect()->SetDrawEdges (false); + myFrontCulling->Aspect()->SetAlphaMode (Graphic3d_AlphaMode_Opaque); } // ======================================================================= @@ -206,12 +215,12 @@ void OpenGl_Workspace::ResetAppliedAspect() myHighlightStyle.Nullify(); myToAllowFaceCulling = false; - myAspectLineSet = &myDefaultAspectLine; - myAspectFaceSet = &myDefaultAspectFace; + myAspectLineSet = myDefaultAspectLine; + myAspectFaceSet = myDefaultAspectFace; myAspectFaceApplied.Nullify(); - myAspectMarkerSet = &myDefaultAspectMarker; + myAspectMarkerSet = myDefaultAspectMarker; myAspectMarkerApplied.Nullify(); - myAspectTextSet = &myDefaultAspectText; + myAspectTextSet = myDefaultAspectText; myGlContext->SetPolygonOffset (Graphic3d_PolygonOffset()); ApplyAspectLine(); @@ -219,8 +228,8 @@ void OpenGl_Workspace::ResetAppliedAspect() ApplyAspectMarker(); ApplyAspectText(); - myGlContext->SetTypeOfLine (myDefaultAspectLine.Aspect()->Type()); - myGlContext->SetLineWidth (myDefaultAspectLine.Aspect()->Width()); + myGlContext->SetTypeOfLine (myDefaultAspectLine->Aspect()->Type()); + myGlContext->SetLineWidth (myDefaultAspectLine->Aspect()->Width()); } // ======================================================================= @@ -229,9 +238,9 @@ void OpenGl_Workspace::ResetAppliedAspect() // ======================================================================= Graphic3d_PolygonOffset OpenGl_Workspace::SetDefaultPolygonOffset (const Graphic3d_PolygonOffset& theOffset) { - Graphic3d_PolygonOffset aPrev = myDefaultAspectFace.Aspect()->PolygonOffset(); - myDefaultAspectFace.Aspect()->SetPolygonOffset (theOffset); - if (myAspectFaceApplied == myDefaultAspectFace.Aspect() + Graphic3d_PolygonOffset aPrev = myDefaultAspectFace->Aspect()->PolygonOffset(); + myDefaultAspectFace->Aspect()->SetPolygonOffset (theOffset); + if (myAspectFaceApplied == myDefaultAspectFace->Aspect() || myAspectFaceApplied.IsNull() || (myAspectFaceApplied->PolygonOffset().Mode & Aspect_POM_None) == Aspect_POM_None) { @@ -244,9 +253,9 @@ Graphic3d_PolygonOffset OpenGl_Workspace::SetDefaultPolygonOffset (const Graphic // function : SetAspectLine // purpose : // ======================================================================= -const OpenGl_AspectLine* OpenGl_Workspace::SetAspectLine (const OpenGl_AspectLine* theAspect) +const Handle(OpenGl_AspectLine) OpenGl_Workspace::SetAspectLine (const Handle(OpenGl_AspectLine)& theAspect) { - const OpenGl_AspectLine* aPrevAspectLine = myAspectLineSet; + Handle(OpenGl_AspectLine) aPrevAspectLine = myAspectLineSet; myAspectLineSet = theAspect; return aPrevAspectLine; } @@ -255,9 +264,9 @@ const OpenGl_AspectLine* OpenGl_Workspace::SetAspectLine (const OpenGl_AspectLin // function : SetAspectFace // purpose : // ======================================================================= -const OpenGl_AspectFace * OpenGl_Workspace::SetAspectFace (const OpenGl_AspectFace* theAspect) +const Handle(OpenGl_AspectFace) OpenGl_Workspace::SetAspectFace (const Handle(OpenGl_AspectFace)& theAspect) { - const OpenGl_AspectFace* aPrevAspectFace = myAspectFaceSet; + Handle(OpenGl_AspectFace) aPrevAspectFace = myAspectFaceSet; myAspectFaceSet = theAspect; return aPrevAspectFace; } @@ -266,9 +275,9 @@ const OpenGl_AspectFace * OpenGl_Workspace::SetAspectFace (const OpenGl_AspectFa // function : SetAspectMarker // purpose : // ======================================================================= -const OpenGl_AspectMarker* OpenGl_Workspace::SetAspectMarker (const OpenGl_AspectMarker* theAspect) +const Handle(OpenGl_AspectMarker) OpenGl_Workspace::SetAspectMarker (const Handle(OpenGl_AspectMarker)& theAspect) { - const OpenGl_AspectMarker* aPrevAspectMarker = myAspectMarkerSet; + Handle(OpenGl_AspectMarker) aPrevAspectMarker = myAspectMarkerSet; myAspectMarkerSet = theAspect; return aPrevAspectMarker; } @@ -277,9 +286,9 @@ const OpenGl_AspectMarker* OpenGl_Workspace::SetAspectMarker (const OpenGl_Aspec // function : SetAspectText // purpose : // ======================================================================= -const OpenGl_AspectText * OpenGl_Workspace::SetAspectText (const OpenGl_AspectText* theAspect) +const Handle(OpenGl_AspectText) OpenGl_Workspace::SetAspectText (const Handle(OpenGl_AspectText)& theAspect) { - const OpenGl_AspectText* aPrevAspectText = myAspectTextSet; + Handle(OpenGl_AspectText) aPrevAspectText = myAspectTextSet; myAspectTextSet = theAspect; return aPrevAspectText; } @@ -288,7 +297,7 @@ const OpenGl_AspectText * OpenGl_Workspace::SetAspectText (const OpenGl_AspectTe // function : ApplyAspectFace // purpose : // ======================================================================= -const OpenGl_AspectFace* OpenGl_Workspace::ApplyAspectFace() +const Handle(OpenGl_AspectFace)& OpenGl_Workspace::ApplyAspectFace() { if (myView->BackfacingModel() == Graphic3d_TOBM_AUTOMATIC) { @@ -395,7 +404,7 @@ const OpenGl_AspectFace* OpenGl_Workspace::ApplyAspectFace() // function : ApplyAspectMarker // purpose : // ======================================================================= -const OpenGl_AspectMarker* OpenGl_Workspace::ApplyAspectMarker() +const Handle(OpenGl_AspectMarker)& OpenGl_Workspace::ApplyAspectMarker() { if (myAspectMarkerSet->Aspect() != myAspectMarkerApplied) { @@ -486,7 +495,7 @@ Standard_Boolean OpenGl_Workspace::BufferDump (const Handle(OpenGl_FrameBuffer)& // function : ShouldRender // purpose : // ======================================================================= -bool OpenGl_Workspace::ShouldRender (const OpenGl_Element* theElement) +bool OpenGl_Workspace::ShouldRender (const Handle(OpenGl_Element)& theElement) { // render only non-raytracable elements when RayTracing is enabled if ((myRenderFilter & OpenGl_RenderFilter_NonRaytraceableOnly) != 0) @@ -522,7 +531,7 @@ bool OpenGl_Workspace::ShouldRender (const OpenGl_Element* theElement) { if (!theElement->IsFillDrawMode()) { - if (dynamic_cast (theElement) == NULL) + if (Handle(OpenGl_AspectFace)::DownCast(theElement).IsNull()) { return false; } diff --git a/src/OpenGl/OpenGl_Workspace.hxx b/src/OpenGl/OpenGl_Workspace.hxx index fad9e8adf6..d059102195 100644 --- a/src/OpenGl/OpenGl_Workspace.hxx +++ b/src/OpenGl/OpenGl_Workspace.hxx @@ -163,44 +163,44 @@ public: } //! Currently set line aspect (can differ from applied). - const OpenGl_AspectLine* AspectLine() const { return myAspectLineSet; } + const Handle(OpenGl_AspectLine)& AspectLine() const { return myAspectLineSet; } //! Currently set face aspect (can differ from applied). - const OpenGl_AspectFace* AspectFace() const { return myAspectFaceSet; } + const Handle(OpenGl_AspectFace) AspectFace() const { return myAspectFaceSet; } //! Currently set marker aspect (can differ from applied). - const OpenGl_AspectMarker* AspectMarker() const { return myAspectMarkerSet; } + const Handle(OpenGl_AspectMarker)& AspectMarker() const { return myAspectMarkerSet; } //! Currently set text aspect (can differ from applied). - const OpenGl_AspectText* AspectText() const { return myAspectTextSet; } + const Handle(OpenGl_AspectText)& AspectText() const { return myAspectTextSet; } //! Assign new line aspect (will be applied within ApplyAspectLine()). - Standard_EXPORT const OpenGl_AspectLine* SetAspectLine (const OpenGl_AspectLine* theAspect); + Standard_EXPORT const Handle(OpenGl_AspectLine) SetAspectLine (const Handle(OpenGl_AspectLine)& theAspect); //! Assign new face aspect (will be applied within ApplyAspectFace()). - Standard_EXPORT const OpenGl_AspectFace* SetAspectFace (const OpenGl_AspectFace* theAspect); + Standard_EXPORT const Handle(OpenGl_AspectFace) SetAspectFace (const Handle(OpenGl_AspectFace)& theAspect); //! Assign new marker aspect (will be applied within ApplyAspectMarker()). - Standard_EXPORT const OpenGl_AspectMarker* SetAspectMarker (const OpenGl_AspectMarker* theAspect); + Standard_EXPORT const Handle(OpenGl_AspectMarker) SetAspectMarker (const Handle(OpenGl_AspectMarker)& theAspect); //! Assign new text aspect (will be applied within ApplyAspectText()). - Standard_EXPORT const OpenGl_AspectText* SetAspectText (const OpenGl_AspectText* theAspect); + Standard_EXPORT const Handle(OpenGl_AspectText) SetAspectText (const Handle(OpenGl_AspectText)& theAspect); //! Apply line aspect. //! @return aspect set by SetAspectLine() - const OpenGl_AspectLine* ApplyAspectLine() { return myAspectLineSet; } + const Handle(OpenGl_AspectLine) ApplyAspectLine() { return myAspectLineSet; } //! Apply face aspect. //! @return aspect set by SetAspectFace() - Standard_EXPORT const OpenGl_AspectFace* ApplyAspectFace(); + Standard_EXPORT const Handle(OpenGl_AspectFace)& ApplyAspectFace(); //! Apply marker aspect. //! @return aspect set by SetAspectMarker() - Standard_EXPORT const OpenGl_AspectMarker* ApplyAspectMarker(); + Standard_EXPORT const Handle(OpenGl_AspectMarker)& ApplyAspectMarker(); //! Apply text aspect. //! @return aspect set by SetAspectText() - const OpenGl_AspectText* ApplyAspectText() { return myAspectTextSet; } + const Handle(OpenGl_AspectText)& ApplyAspectText() { return myAspectTextSet; } //! Clear the applied aspect state to default values. void ResetAppliedAspect(); @@ -216,7 +216,7 @@ public: //! Checks whether the element can be rendered or not. //! @param theElement [in] the element to check //! @return True if element can be rendered - bool ShouldRender (const OpenGl_Element* theElement); + bool ShouldRender (const Handle(OpenGl_Element)& theElement); //! Return the number of skipped transparent elements within active OpenGl_RenderFilter_OpaqueOnly filter. //! @sa OpenGl_LayerList::Render() @@ -233,13 +233,13 @@ public: inline const OpenGl_Matrix* ModelMatrix() const { return StructureMatrix_applied; } //! Returns face aspect for textured font rendering. - const OpenGl_AspectFace& FontFaceAspect() const { return myFontFaceAspect; } + const Handle(OpenGl_AspectFace)& FontFaceAspect() const { return myFontFaceAspect; } //! Returns face aspect for none culling mode. - const OpenGl_AspectFace& NoneCulling() const { return myNoneCulling; } + const Handle(OpenGl_AspectFace)& NoneCulling() const { return myNoneCulling; } //! Returns face aspect for front face culling mode. - const OpenGl_AspectFace& FrontCulling() const { return myFrontCulling; } + const Handle(OpenGl_AspectFace)& FrontCulling() const { return myFrontCulling; } //! Sets a new environment texture. void SetEnvironmentTexture (const Handle(OpenGl_TextureSet)& theTexture) { myEnvironmentTexture = theTexture; } @@ -254,26 +254,26 @@ protected: //! @name protected fields Handle(OpenGl_Context) myGlContext; Standard_Boolean myUseZBuffer; Standard_Boolean myUseDepthWrite; - OpenGl_AspectFace myNoneCulling; - OpenGl_AspectFace myFrontCulling; - OpenGl_AspectFace myFontFaceAspect; + Handle(OpenGl_AspectFace) myNoneCulling; + Handle(OpenGl_AspectFace) myFrontCulling; + Handle(OpenGl_AspectFace) myFontFaceAspect; protected: //! @name fields related to status Standard_Integer myNbSkippedTranspElems; //!< counter of skipped transparent elements for OpenGl_LayerList two rendering passes method Standard_Integer myRenderFilter; //!< active filter for skipping rendering of elements by some criteria (multiple render passes) - OpenGl_AspectLine myDefaultAspectLine; - OpenGl_AspectFace myDefaultAspectFace; - OpenGl_AspectMarker myDefaultAspectMarker; - OpenGl_AspectText myDefaultAspectText; + Handle(OpenGl_AspectLine) myDefaultAspectLine; + Handle(OpenGl_AspectFace) myDefaultAspectFace; + Handle(OpenGl_AspectMarker) myDefaultAspectMarker; + Handle(OpenGl_AspectText) myDefaultAspectText; - const OpenGl_AspectLine* myAspectLineSet; - const OpenGl_AspectFace* myAspectFaceSet; + Handle(OpenGl_AspectLine) myAspectLineSet; + Handle(OpenGl_AspectFace) myAspectFaceSet; Handle(Graphic3d_AspectFillArea3d) myAspectFaceApplied; - const OpenGl_AspectMarker* myAspectMarkerSet; + Handle(OpenGl_AspectMarker) myAspectMarkerSet; Handle(Graphic3d_AspectMarker3d) myAspectMarkerApplied; - const OpenGl_AspectText* myAspectTextSet; + Handle(OpenGl_AspectText) myAspectTextSet; Handle(Graphic3d_PresentationAttributes) myAspectFaceAppliedWithHL; const OpenGl_Matrix* ViewMatrix_applied; diff --git a/src/ViewerTest/ViewerTest_OpenGlCommands.cxx b/src/ViewerTest/ViewerTest_OpenGlCommands.cxx index 3a614a3e7c..39e7ab2f3a 100644 --- a/src/ViewerTest/ViewerTest_OpenGlCommands.cxx +++ b/src/ViewerTest/ViewerTest_OpenGlCommands.cxx @@ -158,9 +158,9 @@ void VUserDrawObj::Render(const Handle(OpenGl_Workspace)& theWorkspace) const const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext(); // To test linking against OpenGl_Workspace and all aspect classes - const OpenGl_AspectMarker* aMA = theWorkspace->AspectMarker(); + const Handle(OpenGl_AspectMarker)& aMA = theWorkspace->AspectMarker(); aMA->Aspect()->Type(); - const OpenGl_AspectText* aTA = theWorkspace->AspectText(); + const Handle(OpenGl_AspectText)& aTA = theWorkspace->AspectText(); aTA->Aspect()->Font(); OpenGl_Vec4 aColor = theWorkspace->LineColor(); -- 2.39.5