Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2011-08-01 |
2 | // Created by: Sergey ZERCHANINOV | |
973c2be1 | 3 | // Copyright (c) 2011-2014 OPEN CASCADE SAS |
b311480e | 4 | // |
973c2be1 | 5 | // This file is part of Open CASCADE Technology software library. |
b311480e | 6 | // |
d5f74e42 | 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 | |
973c2be1 | 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. | |
b311480e | 12 | // |
973c2be1 | 13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. | |
b311480e | 15 | |
2166f0fa SK |
16 | #ifndef OpenGl_Structure_Header |
17 | #define OpenGl_Structure_Header | |
18 | ||
63bcc448 | 19 | #include <Graphic3d_CStructure.hxx> |
20 | #include <Graphic3d_SequenceOfHClipPlane.hxx> | |
2166f0fa SK |
21 | |
22 | #include <OpenGl_AspectLine.hxx> | |
23 | #include <OpenGl_AspectFace.hxx> | |
24 | #include <OpenGl_AspectMarker.hxx> | |
25 | #include <OpenGl_AspectText.hxx> | |
26 | ||
5b111128 | 27 | #include <OpenGl_GraphicDriver.hxx> |
2166f0fa SK |
28 | #include <OpenGl_Group.hxx> |
29 | #include <OpenGl_Matrix.hxx> | |
b7cd4ba7 | 30 | #include <OpenGl_Vec.hxx> |
31 | #include <OpenGl_Workspace.hxx> | |
2166f0fa | 32 | |
63bcc448 | 33 | #include <NCollection_List.hxx> |
4269bd1b | 34 | |
bf75be98 | 35 | class OpenGl_Structure; |
63bcc448 | 36 | class OpenGl_GraphicDriver; |
bf75be98 | 37 | |
38 | typedef NCollection_List<const OpenGl_Structure* > OpenGl_ListOfStructure; | |
2166f0fa | 39 | |
b64d84be | 40 | //! Implementation of low-level graphic structure. |
63bcc448 | 41 | class OpenGl_Structure : public Graphic3d_CStructure |
2166f0fa | 42 | { |
e276548b | 43 | friend class OpenGl_Group; |
5e27df78 | 44 | |
b64d84be | 45 | public: |
46 | ||
47 | //! Auxiliary wrapper to iterate OpenGl_Group sequence. | |
48 | class GroupIterator | |
49 | { | |
50 | ||
51 | public: | |
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->()); } | |
57 | ||
58 | private: | |
59 | Graphic3d_SequenceOfGroup::Iterator myIter; | |
60 | ||
61 | }; | |
62 | ||
5e27df78 | 63 | public: |
64 | ||
63bcc448 | 65 | //! Create empty structure |
b64d84be | 66 | Standard_EXPORT OpenGl_Structure (const Handle(Graphic3d_StructureManager)& theManager); |
63bcc448 | 67 | |
68 | //! Setup structure graphic state | |
a1954302 | 69 | Standard_EXPORT virtual void OnVisibilityChanged() Standard_OVERRIDE; |
63bcc448 | 70 | |
71 | //! Clear graphic data | |
79104795 | 72 | Standard_EXPORT virtual void Clear() Standard_OVERRIDE; |
63bcc448 | 73 | |
74 | //! Connect other structure to this one | |
79104795 | 75 | Standard_EXPORT virtual void Connect (Graphic3d_CStructure& theStructure) Standard_OVERRIDE; |
63bcc448 | 76 | |
77 | //! Disconnect other structure to this one | |
79104795 | 78 | Standard_EXPORT virtual void Disconnect (Graphic3d_CStructure& theStructure) Standard_OVERRIDE; |
63bcc448 | 79 | |
63bcc448 | 80 | //! Synchronize structure transformation |
1f7f5a90 | 81 | Standard_EXPORT virtual void SetTransformation (const Handle(Geom_Transformation)& theTrsf) Standard_OVERRIDE; |
63bcc448 | 82 | |
7c3ef2f7 | 83 | //! Set transformation persistence. |
84 | Standard_EXPORT virtual void SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers) Standard_OVERRIDE; | |
85 | ||
86 | //! Set z layer ID to display the structure in specified layer | |
87 | Standard_EXPORT virtual void SetZLayer(const Graphic3d_ZLayerId theLayerIndex) Standard_OVERRIDE; | |
88 | ||
8e5fb5ea | 89 | //! Highlights structure according to the given style and updates corresponding class fields |
90 | //! (highlight status and style) | |
98b15dbf | 91 | Standard_EXPORT virtual void GraphicHighlight (const Handle(Graphic3d_PresentationAttributes)& theStyle) Standard_OVERRIDE; |
63bcc448 | 92 | |
8e5fb5ea | 93 | //! Unighlights structure and updates corresponding class fields (highlight status and style) |
94 | Standard_EXPORT virtual void GraphicUnhighlight() Standard_OVERRIDE; | |
63bcc448 | 95 | |
679ecdee | 96 | //! Create shadow link to this structure |
79104795 | 97 | Standard_EXPORT virtual Handle(Graphic3d_CStructure) ShadowLink (const Handle(Graphic3d_StructureManager)& theManager) const Standard_OVERRIDE; |
b64d84be | 98 | |
99 | //! Create new group within this structure | |
79104795 | 100 | Standard_EXPORT virtual Handle(Graphic3d_Group) NewGroup (const Handle(Graphic3d_Structure)& theStruct) Standard_OVERRIDE; |
b64d84be | 101 | |
102 | //! Remove group from this structure | |
79104795 | 103 | Standard_EXPORT virtual void RemoveGroup (const Handle(Graphic3d_Group)& theGroup) Standard_OVERRIDE; |
679ecdee | 104 | |
63bcc448 | 105 | public: |
106 | ||
107 | //! Access graphic driver | |
108 | OpenGl_GraphicDriver* GlDriver() const | |
109 | { | |
110 | return (OpenGl_GraphicDriver* )myGraphicDriver.operator->(); | |
111 | } | |
2166f0fa | 112 | |
b64d84be | 113 | Standard_EXPORT void Clear (const Handle(OpenGl_Context)& theGlCtx); |
2166f0fa | 114 | |
0717ddc1 | 115 | //! Renders the structure. |
5e27df78 | 116 | virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const; |
0717ddc1 | 117 | |
118 | //! Releases structure resources. | |
119 | virtual void Release (const Handle(OpenGl_Context)& theGlCtx); | |
5e27df78 | 120 | |
15669413 | 121 | //! Marks structure as culled/not culled - note that IsAlwaysRendered() is ignored here! |
122 | void SetCulled (Standard_Boolean theIsCulled) const { myIsCulled = theIsCulled; } | |
b7cd4ba7 | 123 | |
124 | //! Marks structure as overlapping the current view volume one. | |
125 | //! The method is called during traverse of BVH tree. | |
126 | void MarkAsNotCulled() const { myIsCulled = Standard_False; } | |
127 | ||
128 | //! Returns Standard_False if the structure hits the current view volume, otherwise | |
129 | //! returns Standard_True. The default value for all structures before each traverse | |
130 | //! of BVH tree is Standard_True. | |
131 | Standard_Boolean IsCulled() const { return myIsCulled; } | |
132 | ||
133 | //! Checks if the structure should be included into BVH tree or not. | |
487bf1ce | 134 | Standard_Boolean IsAlwaysRendered() const |
b7cd4ba7 | 135 | { |
136 | return IsInfinite | |
137 | || IsForHighlight | |
138 | || IsMutable | |
139 | || Is2dText | |
778cd667 | 140 | || (!myTrsfPers.IsNull() && myTrsfPers->IsTrihedronOr2d()); |
b7cd4ba7 | 141 | } |
142 | ||
dd8a4ce9 | 143 | //! This method releases GL resources without actual elements destruction. |
e276548b | 144 | //! As result structure could be correctly destroyed layer without GL context |
dd8a4ce9 | 145 | //! (after last window was closed for example). |
146 | //! | |
147 | //! Notice however that reusage of this structure after calling this method is incorrect | |
148 | //! and will lead to broken visualization due to loosed data. | |
b64d84be | 149 | Standard_EXPORT void ReleaseGlResources (const Handle(OpenGl_Context)& theGlCtx); |
e276548b | 150 | |
d4aaad5b | 151 | //! Returns instanced OpenGL structure. |
152 | const OpenGl_Structure* InstancedStructure() const { return myInstancedStructure; } | |
e276548b | 153 | |
e276548b | 154 | //! Returns structure modification state (for ray-tracing). |
155 | Standard_Size ModificationState() const { return myModificationState; } | |
156 | ||
189f85a3 | 157 | //! Resets structure modification state (for ray-tracing). |
e276548b | 158 | void ResetModificationState() const { myModificationState = 0; } |
159 | ||
160 | //! Is the structure ray-tracable (contains ray-tracable elements)? | |
d4aaad5b | 161 | Standard_Boolean IsRaytracable() const; |
e276548b | 162 | |
7c3ef2f7 | 163 | //! Update render transformation matrix. |
164 | Standard_EXPORT void updateLayerTransformation(); | |
165 | ||
5e27df78 | 166 | protected: |
167 | ||
b64d84be | 168 | Standard_EXPORT virtual ~OpenGl_Structure(); |
5e27df78 | 169 | |
e276548b | 170 | //! Updates ray-tracable status for structure and its parents. |
d4aaad5b | 171 | void UpdateStateIfRaytracable (const Standard_Boolean toCheck = Standard_True) const; |
e276548b | 172 | |
3e05329c | 173 | //! Renders groups of structure without applying any attributes (i.e. transform, material etc). |
174 | //! @param theWorkspace current workspace | |
175 | //! @param theHasClosed flag will be set to TRUE if structure contains at least one group of closed primitives | |
176 | Standard_EXPORT void renderGeometry (const Handle(OpenGl_Workspace)& theWorkspace, | |
177 | bool& theHasClosed) const; | |
178 | ||
98b15dbf | 179 | //! Render the bounding box. |
180 | Standard_EXPORT void renderBoundingBox(const Handle(OpenGl_Workspace)& theWorkspace) const; | |
8e5fb5ea | 181 | |
5e27df78 | 182 | protected: |
2166f0fa | 183 | |
d4aaad5b | 184 | OpenGl_Structure* myInstancedStructure; |
7c3ef2f7 | 185 | Graphic3d_Mat4 myRenderTrsf; //!< transformation, actually used for rendering (includes Local Origin shift) |
2166f0fa | 186 | |
d4aaad5b | 187 | mutable Standard_Boolean myIsRaytracable; |
188 | mutable Standard_Size myModificationState; | |
e276548b | 189 | |
d4aaad5b | 190 | mutable Standard_Boolean myIsCulled; //!< A status specifying is structure needs to be rendered after BVH tree traverse. |
b7cd4ba7 | 191 | |
d4aaad5b | 192 | Standard_Boolean myIsMirrored; //!< Used to tell OpenGl to interpret polygons in clockwise order. |
7d9e854b | 193 | |
5e27df78 | 194 | public: |
2166f0fa | 195 | |
92efcf78 | 196 | DEFINE_STANDARD_RTTIEXT(OpenGl_Structure,Graphic3d_CStructure) // Type definition |
5e27df78 | 197 | |
2166f0fa SK |
198 | }; |
199 | ||
63bcc448 | 200 | DEFINE_STANDARD_HANDLE(OpenGl_Structure, Graphic3d_CStructure) |
201 | ||
202 | #endif // OpenGl_Structure_Header |