1 // Created on: 2011-08-01
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef OpenGl_Structure_Header
17 #define OpenGl_Structure_Header
19 #include <Graphic3d_CStructure.hxx>
20 #include <Graphic3d_SequenceOfHClipPlane.hxx>
22 #include <OpenGl_AspectLine.hxx>
23 #include <OpenGl_AspectFace.hxx>
24 #include <OpenGl_AspectMarker.hxx>
25 #include <OpenGl_AspectText.hxx>
27 #include <OpenGl_GraphicDriver.hxx>
28 #include <OpenGl_Group.hxx>
29 #include <OpenGl_Matrix.hxx>
30 #include <OpenGl_Vec.hxx>
31 #include <OpenGl_Workspace.hxx>
33 #include <NCollection_List.hxx>
35 class OpenGl_Structure;
36 class OpenGl_GraphicDriver;
38 typedef NCollection_List<const OpenGl_Structure* > OpenGl_ListOfStructure;
40 //! Implementation of low-level graphic structure.
41 class OpenGl_Structure : public Graphic3d_CStructure
43 friend class OpenGl_Group;
47 //! Auxiliary wrapper to iterate OpenGl_Group sequence.
52 GroupIterator (const Graphic3d_SequenceOfGroup& theGroups) : myIter (theGroups) {}
53 Standard_Boolean More() const { return myIter.More(); }
54 void Next() { myIter.Next(); }
55 const OpenGl_Group* Value() const { return (const OpenGl_Group* )(myIter.Value().operator->()); }
56 OpenGl_Group* ChangeValue() { return (OpenGl_Group* )(myIter.ChangeValue().operator->()); }
59 Graphic3d_SequenceOfGroup::Iterator myIter;
65 //! Create empty structure
66 Standard_EXPORT OpenGl_Structure (const Handle(Graphic3d_StructureManager)& theManager);
68 //! Setup structure graphic state
69 Standard_EXPORT virtual void OnVisibilityChanged() Standard_OVERRIDE;
71 //! Clear graphic data
72 Standard_EXPORT virtual void Clear() Standard_OVERRIDE;
74 //! Connect other structure to this one
75 Standard_EXPORT virtual void Connect (Graphic3d_CStructure& theStructure) Standard_OVERRIDE;
77 //! Disconnect other structure to this one
78 Standard_EXPORT virtual void Disconnect (Graphic3d_CStructure& theStructure) Standard_OVERRIDE;
80 //! Synchronize structure transformation
81 Standard_EXPORT virtual void SetTransformation (const Handle(Geom_Transformation)& theTrsf) Standard_OVERRIDE;
83 //! Set transformation persistence.
84 Standard_EXPORT virtual void SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers) Standard_OVERRIDE;
86 //! Set z layer ID to display the structure in specified layer
87 Standard_EXPORT virtual void SetZLayer(const Graphic3d_ZLayerId theLayerIndex) Standard_OVERRIDE;
89 //! Highlights structure according to the given style and updates corresponding class fields
90 //! (highlight status and style)
91 Standard_EXPORT virtual void GraphicHighlight (const Handle(Graphic3d_PresentationAttributes)& theStyle,
92 const Handle(Graphic3d_Structure)& theStruct) Standard_OVERRIDE;
94 //! Unighlights structure and updates corresponding class fields (highlight status and style)
95 Standard_EXPORT virtual void GraphicUnhighlight() Standard_OVERRIDE;
97 //! Create shadow link to this structure
98 Standard_EXPORT virtual Handle(Graphic3d_CStructure) ShadowLink (const Handle(Graphic3d_StructureManager)& theManager) const Standard_OVERRIDE;
100 //! Create new group within this structure
101 Standard_EXPORT virtual Handle(Graphic3d_Group) NewGroup (const Handle(Graphic3d_Structure)& theStruct) Standard_OVERRIDE;
103 //! Remove group from this structure
104 Standard_EXPORT virtual void RemoveGroup (const Handle(Graphic3d_Group)& theGroup) Standard_OVERRIDE;
108 //! Access graphic driver
109 OpenGl_GraphicDriver* GlDriver() const
111 return (OpenGl_GraphicDriver* )myGraphicDriver.operator->();
114 Standard_EXPORT void Clear (const Handle(OpenGl_Context)& theGlCtx);
116 //! Renders the structure.
117 virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
119 //! Releases structure resources.
120 virtual void Release (const Handle(OpenGl_Context)& theGlCtx);
122 //! Marks structure as culled/not culled.
123 void SetCulled (Standard_Boolean theIsCulled) const
125 myIsCulled = theIsCulled && !IsAlwaysRendered();
128 //! Marks structure as overlapping the current view volume one.
129 //! The method is called during traverse of BVH tree.
130 void MarkAsNotCulled() const { myIsCulled = Standard_False; }
132 //! Returns Standard_False if the structure hits the current view volume, otherwise
133 //! returns Standard_True. The default value for all structures before each traverse
134 //! of BVH tree is Standard_True.
135 Standard_Boolean IsCulled() const { return myIsCulled; }
137 //! Checks if the structure should be included into BVH tree or not.
138 Standard_Boolean IsAlwaysRendered() const
144 || (!myTrsfPers.IsNull() && myTrsfPers->IsTrihedronOr2d());
147 //! This method releases GL resources without actual elements destruction.
148 //! As result structure could be correctly destroyed layer without GL context
149 //! (after last window was closed for example).
151 //! Notice however that reusage of this structure after calling this method is incorrect
152 //! and will lead to broken visualization due to loosed data.
153 Standard_EXPORT void ReleaseGlResources (const Handle(OpenGl_Context)& theGlCtx);
155 //! Returns instanced OpenGL structure.
156 const OpenGl_Structure* InstancedStructure() const { return myInstancedStructure; }
158 //! Returns structure modification state (for ray-tracing).
159 Standard_Size ModificationState() const { return myModificationState; }
161 //! Resets structure modification state (for ray-tracing).
162 void ResetModificationState() const { myModificationState = 0; }
164 //! Is the structure ray-tracable (contains ray-tracable elements)?
165 Standard_Boolean IsRaytracable() const;
167 //! Update render transformation matrix.
168 Standard_EXPORT void updateLayerTransformation();
172 Standard_EXPORT virtual ~OpenGl_Structure();
174 //! Updates ray-tracable status for structure and its parents.
175 void UpdateStateIfRaytracable (const Standard_Boolean toCheck = Standard_True) const;
177 //! Renders groups of structure without applying any attributes (i.e. transform, material etc).
178 //! @param theWorkspace current workspace
179 //! @param theHasClosed flag will be set to TRUE if structure contains at least one group of closed primitives
180 Standard_EXPORT void renderGeometry (const Handle(OpenGl_Workspace)& theWorkspace,
181 bool& theHasClosed) const;
183 //! Highlight structure using boundary box
184 Standard_EXPORT void highlightWithBndBox (const Handle(Graphic3d_Structure)& theStruct);
186 //! Invalidates highlight box and releases graphic resources it uses
187 Standard_EXPORT void clearHighlightBox (const Handle(OpenGl_Context)& theGlCtx);
191 Handle(OpenGl_Group) myHighlightBox;
193 OpenGl_Structure* myInstancedStructure;
194 Graphic3d_Mat4 myRenderTrsf; //!< transformation, actually used for rendering (includes Local Origin shift)
196 mutable Standard_Boolean myIsRaytracable;
197 mutable Standard_Size myModificationState;
199 mutable Standard_Boolean myIsCulled; //!< A status specifying is structure needs to be rendered after BVH tree traverse.
201 Standard_Boolean myIsMirrored; //!< Used to tell OpenGl to interpret polygons in clockwise order.
205 DEFINE_STANDARD_RTTIEXT(OpenGl_Structure,Graphic3d_CStructure) // Type definition
209 DEFINE_STANDARD_HANDLE(OpenGl_Structure, Graphic3d_CStructure)
211 #endif // OpenGl_Structure_Header