0024394: Visualization - implement more general way for rendering of immediate objects
[occt.git] / src / OpenGl / OpenGl_Structure.hxx
CommitLineData
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
27#include <OpenGl_Group.hxx>
28#include <OpenGl_Matrix.hxx>
b7cd4ba7 29#include <OpenGl_Vec.hxx>
30#include <OpenGl_Workspace.hxx>
2166f0fa 31
63bcc448 32#include <NCollection_List.hxx>
33#include <InterfaceGraphic_Graphic3d.hxx>
4269bd1b 34
bf75be98 35class OpenGl_Structure;
63bcc448 36class OpenGl_GraphicDriver;
bf75be98 37
38typedef NCollection_List<const OpenGl_Structure* > OpenGl_ListOfStructure;
2166f0fa 39
b64d84be 40//! Implementation of low-level graphic structure.
63bcc448 41class OpenGl_Structure : public Graphic3d_CStructure
2166f0fa 42{
e276548b 43 friend class OpenGl_Group;
5e27df78 44
b64d84be 45public:
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 63public:
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
b64d84be 72 Standard_EXPORT virtual void Clear();
63bcc448 73
74 //! Connect other structure to this one
b64d84be 75 Standard_EXPORT virtual void Connect (Graphic3d_CStructure& theStructure);
63bcc448 76
77 //! Disconnect other structure to this one
b64d84be 78 Standard_EXPORT virtual void Disconnect (Graphic3d_CStructure& theStructure);
63bcc448 79
80 //! Synchronize structure aspects
b64d84be 81 Standard_EXPORT virtual void UpdateAspects();
2166f0fa 82
63bcc448 83 //! Synchronize structure transformation
b64d84be 84 Standard_EXPORT virtual void UpdateTransformation();
63bcc448 85
86 //! Highlight entire structure with color
b64d84be 87 Standard_EXPORT virtual void HighlightWithColor (const Graphic3d_Vec3& theColor,
88 const Standard_Boolean theToCreate);
63bcc448 89
90 //! Highlight structure using boundary box
b64d84be 91 Standard_EXPORT virtual void HighlightWithBndBox (const Handle(Graphic3d_Structure)& theStruct,
92 const Standard_Boolean theToCreate);
63bcc448 93
679ecdee 94 //! Create shadow link to this structure
b64d84be 95 Standard_EXPORT virtual Handle(Graphic3d_CStructure) ShadowLink (const Handle(Graphic3d_StructureManager)& theManager) const;
96
97 //! Create new group within this structure
98 Standard_EXPORT virtual Handle(Graphic3d_Group) NewGroup (const Handle(Graphic3d_Structure)& theStruct);
99
100 //! Remove group from this structure
101 Standard_EXPORT virtual void RemoveGroup (const Handle(Graphic3d_Group)& theGroup);
679ecdee 102
63bcc448 103public:
104
b64d84be 105 //! @return graphic groups
106 virtual const Graphic3d_SequenceOfGroup& DrawGroups() const
107 {
108 return myGroups;
109 }
110
63bcc448 111 //! Access graphic driver
112 OpenGl_GraphicDriver* GlDriver() const
113 {
114 return (OpenGl_GraphicDriver* )myGraphicDriver.operator->();
115 }
2166f0fa
SK
116
117 void SetTransformPersistence (const CALL_DEF_TRANSFORM_PERSISTENCE &ATransPers);
118
fd4a6963 119 void SetAspectLine (const CALL_DEF_CONTEXTLINE &theAspect);
120 void SetAspectFace (const CALL_DEF_CONTEXTFILLAREA& theAspect);
121 void SetAspectMarker (const CALL_DEF_CONTEXTMARKER& theAspect);
122 void SetAspectText (const CALL_DEF_CONTEXTTEXT &theAspect);
2166f0fa 123
b64d84be 124 void clearHighlightBox (const Handle(OpenGl_Context)& theGlCtx);
5e27df78 125
b64d84be 126 void setHighlightColor (const Handle(OpenGl_Context)& theGlCtx,
63bcc448 127 const Graphic3d_Vec3& theColor);
2166f0fa 128
b64d84be 129 void clearHighlightColor (const Handle(OpenGl_Context)& theGlCtx);
2166f0fa 130
b64d84be 131 Standard_EXPORT void Clear (const Handle(OpenGl_Context)& theGlCtx);
2166f0fa 132
0717ddc1 133 //! Renders groups of structure without applying any attributes (i.e. transform, material etc).
134 virtual void RenderGeometry (const Handle(OpenGl_Workspace)& theWorkspace) const;
135
136 //! Renders the structure.
5e27df78 137 virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
0717ddc1 138
139 //! Releases structure resources.
140 virtual void Release (const Handle(OpenGl_Context)& theGlCtx);
5e27df78 141
b7cd4ba7 142 //! Marks structure as not overlapping view volume (as it is by default).
143 void ResetCullingStatus() const
144 {
145 if (!IsAlwaysRendered())
146 {
147 myIsCulled = Standard_True;
148 }
149 }
150
151 //! Marks structure as overlapping the current view volume one.
152 //! The method is called during traverse of BVH tree.
153 void MarkAsNotCulled() const { myIsCulled = Standard_False; }
154
155 //! Returns Standard_False if the structure hits the current view volume, otherwise
156 //! returns Standard_True. The default value for all structures before each traverse
157 //! of BVH tree is Standard_True.
158 Standard_Boolean IsCulled() const { return myIsCulled; }
159
160 //! Checks if the structure should be included into BVH tree or not.
161 const Standard_Boolean IsAlwaysRendered() const
162 {
163 return IsInfinite
164 || IsForHighlight
165 || IsMutable
166 || Is2dText
167 || TransformPersistence.Flag != 0;
168 }
169
dd8a4ce9 170 //! This method releases GL resources without actual elements destruction.
e276548b 171 //! As result structure could be correctly destroyed layer without GL context
dd8a4ce9 172 //! (after last window was closed for example).
173 //!
174 //! Notice however that reusage of this structure after calling this method is incorrect
175 //! and will lead to broken visualization due to loosed data.
b64d84be 176 Standard_EXPORT void ReleaseGlResources (const Handle(OpenGl_Context)& theGlCtx);
e276548b 177
178 //! Returns list of connected OpenGL structures.
179 const OpenGl_ListOfStructure& ConnectedStructures() const { return myConnected; }
180
181 //! Returns OpenGL face aspect.
182 const OpenGl_AspectFace* AspectFace() const { return myAspectFace; }
183
184 //! Returns OpenGL transformation matrix.
185 const OpenGl_Matrix* Transformation() const { return myTransformation; }
186
187 //! Returns OpenGL persistent translation.
188 const TEL_TRANSFORM_PERSISTENCE* PersistentTranslation() const { return myTransPers; }
189
e276548b 190 //! Returns structure modification state (for ray-tracing).
191 Standard_Size ModificationState() const { return myModificationState; }
192
193 //! Resets structure modification state (for ray-tracing)
194 void ResetModificationState() const { myModificationState = 0; }
195
196 //! Is the structure ray-tracable (contains ray-tracable elements)?
197 Standard_Boolean IsRaytracable() const { return myIsRaytracable; }
198
5e27df78 199protected:
200
b64d84be 201 Standard_EXPORT virtual ~OpenGl_Structure();
5e27df78 202
e276548b 203 //! Registers ancestor connected structure (for updating ray-tracing state).
204 void RegisterAncestorStructure (const OpenGl_Structure* theStructure) const;
205
206 //! Unregisters ancestor connected structure (for updating ray-tracing state).
207 void UnregisterAncestorStructure (const OpenGl_Structure* theStructure) const;
208
d5af8626 209 //! Unregisters structure from ancestor structure (for updating ray-tracing state).
210 void UnregisterFromAncestorStructure() const;
211
e276548b 212 //! Updates modification state for structure and its parents.
213 void UpdateStateWithAncestorStructures() const;
214
215 //! Updates ray-tracable status for structure and its parents.
216 void UpdateRaytracableWithAncestorStructures() const;
217
218 //! Sets ray-tracable status for structure and its parents.
219 void SetRaytracableWithAncestorStructures() const;
220
5e27df78 221protected:
2166f0fa 222
5e27df78 223 OpenGl_Matrix* myTransformation;
224 TEL_TRANSFORM_PERSISTENCE* myTransPers;
5e27df78 225 OpenGl_AspectLine* myAspectLine;
226 OpenGl_AspectFace* myAspectFace;
227 OpenGl_AspectMarker* myAspectMarker;
228 OpenGl_AspectText* myAspectText;
63bcc448 229
b64d84be 230 Handle(OpenGl_Group) myHighlightBox;
5e27df78 231 TEL_COLOUR* myHighlightColor;
63bcc448 232
51b10cd4 233 OpenGl_ListOfStructure myConnected;
2166f0fa 234
e276548b 235 mutable OpenGl_ListOfStructure myAncestorStructures;
236 mutable Standard_Boolean myIsRaytracable;
237 mutable Standard_Size myModificationState;
e276548b 238
b7cd4ba7 239 mutable Standard_Boolean myIsCulled; //!< A status specifying is structure needs to be rendered after BVH tree traverse.
240
7d9e854b 241 Standard_Boolean myIsMirrored; //!< Used to tell OpenGl to interpret polygons in clockwise order.
242
5e27df78 243public:
2166f0fa 244
63bcc448 245 DEFINE_STANDARD_RTTI(OpenGl_Structure) // Type definition
5e27df78 246
2166f0fa
SK
247};
248
63bcc448 249DEFINE_STANDARD_HANDLE(OpenGl_Structure, Graphic3d_CStructure)
250
251#endif // OpenGl_Structure_Header