0024739: TKOpenGl - port ray-tracing from OpenCL to GLSL for better integration and...
[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>
e276548b 29#include <OpenGl_NamedStatus.hxx>
2166f0fa 30
63bcc448 31#include <NCollection_List.hxx>
32#include <InterfaceGraphic_Graphic3d.hxx>
4269bd1b 33
bf75be98 34class OpenGl_Structure;
63bcc448 35class OpenGl_GraphicDriver;
bf75be98 36
37typedef NCollection_List<const OpenGl_Structure* > OpenGl_ListOfStructure;
2166f0fa 38
b64d84be 39//! Implementation of low-level graphic structure.
63bcc448 40class OpenGl_Structure : public Graphic3d_CStructure
2166f0fa 41{
e276548b 42 friend class OpenGl_Group;
5e27df78 43
b64d84be 44public:
45
46 //! Auxiliary wrapper to iterate OpenGl_Group sequence.
47 class GroupIterator
48 {
49
50 public:
51 GroupIterator (const Graphic3d_SequenceOfGroup& theGroups) : myIter (theGroups) {}
52 Standard_Boolean More() const { return myIter.More(); }
53 void Next() { myIter.Next(); }
54 const OpenGl_Group* Value() const { return (const OpenGl_Group* )(myIter.Value().operator->()); }
55 OpenGl_Group* ChangeValue() { return (OpenGl_Group* )(myIter.ChangeValue().operator->()); }
56
57 private:
58 Graphic3d_SequenceOfGroup::Iterator myIter;
59
60 };
61
5e27df78 62public:
63
63bcc448 64 //! Create empty structure
b64d84be 65 Standard_EXPORT OpenGl_Structure (const Handle(Graphic3d_StructureManager)& theManager);
63bcc448 66
67 //! Setup structure graphic state
b64d84be 68 Standard_EXPORT virtual void UpdateNamedStatus();
63bcc448 69
70 //! Clear graphic data
b64d84be 71 Standard_EXPORT virtual void Clear();
63bcc448 72
73 //! Connect other structure to this one
b64d84be 74 Standard_EXPORT virtual void Connect (Graphic3d_CStructure& theStructure);
63bcc448 75
76 //! Disconnect other structure to this one
b64d84be 77 Standard_EXPORT virtual void Disconnect (Graphic3d_CStructure& theStructure);
63bcc448 78
79 //! Synchronize structure aspects
b64d84be 80 Standard_EXPORT virtual void UpdateAspects();
2166f0fa 81
63bcc448 82 //! Synchronize structure transformation
b64d84be 83 Standard_EXPORT virtual void UpdateTransformation();
63bcc448 84
85 //! Highlight entire structure with color
b64d84be 86 Standard_EXPORT virtual void HighlightWithColor (const Graphic3d_Vec3& theColor,
87 const Standard_Boolean theToCreate);
63bcc448 88
89 //! Highlight structure using boundary box
b64d84be 90 Standard_EXPORT virtual void HighlightWithBndBox (const Handle(Graphic3d_Structure)& theStruct,
91 const Standard_Boolean theToCreate);
63bcc448 92
679ecdee 93 //! Create shadow link to this structure
b64d84be 94 Standard_EXPORT virtual Handle(Graphic3d_CStructure) ShadowLink (const Handle(Graphic3d_StructureManager)& theManager) const;
95
96 //! Create new group within this structure
97 Standard_EXPORT virtual Handle(Graphic3d_Group) NewGroup (const Handle(Graphic3d_Structure)& theStruct);
98
99 //! Remove group from this structure
100 Standard_EXPORT virtual void RemoveGroup (const Handle(Graphic3d_Group)& theGroup);
679ecdee 101
63bcc448 102public:
103
b64d84be 104 //! @return graphic groups
105 virtual const Graphic3d_SequenceOfGroup& DrawGroups() const
106 {
107 return myGroups;
108 }
109
63bcc448 110 //! Access graphic driver
111 OpenGl_GraphicDriver* GlDriver() const
112 {
113 return (OpenGl_GraphicDriver* )myGraphicDriver.operator->();
114 }
2166f0fa
SK
115
116 void SetTransformPersistence (const CALL_DEF_TRANSFORM_PERSISTENCE &ATransPers);
117
fd4a6963 118 void SetAspectLine (const CALL_DEF_CONTEXTLINE &theAspect);
119 void SetAspectFace (const CALL_DEF_CONTEXTFILLAREA& theAspect);
120 void SetAspectMarker (const CALL_DEF_CONTEXTMARKER& theAspect);
121 void SetAspectText (const CALL_DEF_CONTEXTTEXT &theAspect);
2166f0fa 122
b64d84be 123 void clearHighlightBox (const Handle(OpenGl_Context)& theGlCtx);
5e27df78 124
b64d84be 125 void setHighlightColor (const Handle(OpenGl_Context)& theGlCtx,
63bcc448 126 const Graphic3d_Vec3& theColor);
2166f0fa 127
b64d84be 128 void clearHighlightColor (const Handle(OpenGl_Context)& theGlCtx);
2166f0fa 129
e276548b 130 Standard_Boolean IsVisible() const { return !(myNamedStatus & OPENGL_NS_HIDE); }
2166f0fa 131
b64d84be 132 Standard_EXPORT void Clear (const Handle(OpenGl_Context)& theGlCtx);
2166f0fa 133
59f45b7c 134 //! Set z layer ID to display the structure in specified layer
b64d84be 135 Standard_EXPORT void SetZLayer (const Standard_Integer theLayerIndex);
59f45b7c 136
137 //! Get z layer ID
b64d84be 138 Standard_EXPORT Standard_Integer GetZLayer() const;
2166f0fa 139
5e27df78 140 virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
141 virtual void Release (const Handle(OpenGl_Context)& theGlCtx);
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
151 //! Returns list of connected OpenGL structures.
152 const OpenGl_ListOfStructure& ConnectedStructures() const { return myConnected; }
153
154 //! Returns OpenGL face aspect.
155 const OpenGl_AspectFace* AspectFace() const { return myAspectFace; }
156
157 //! Returns OpenGL transformation matrix.
158 const OpenGl_Matrix* Transformation() const { return myTransformation; }
159
160 //! Returns OpenGL persistent translation.
161 const TEL_TRANSFORM_PERSISTENCE* PersistentTranslation() const { return myTransPers; }
162
e276548b 163 //! Returns structure modification state (for ray-tracing).
164 Standard_Size ModificationState() const { return myModificationState; }
165
166 //! Resets structure modification state (for ray-tracing)
167 void ResetModificationState() const { myModificationState = 0; }
168
169 //! Is the structure ray-tracable (contains ray-tracable elements)?
170 Standard_Boolean IsRaytracable() const { return myIsRaytracable; }
171
5e27df78 172protected:
173
b64d84be 174 Standard_EXPORT virtual ~OpenGl_Structure();
5e27df78 175
e276548b 176 //! Registers ancestor connected structure (for updating ray-tracing state).
177 void RegisterAncestorStructure (const OpenGl_Structure* theStructure) const;
178
179 //! Unregisters ancestor connected structure (for updating ray-tracing state).
180 void UnregisterAncestorStructure (const OpenGl_Structure* theStructure) const;
181
d5af8626 182 //! Unregisters structure from ancestor structure (for updating ray-tracing state).
183 void UnregisterFromAncestorStructure() const;
184
e276548b 185 //! Updates modification state for structure and its parents.
186 void UpdateStateWithAncestorStructures() const;
187
188 //! Updates ray-tracable status for structure and its parents.
189 void UpdateRaytracableWithAncestorStructures() const;
190
191 //! Sets ray-tracable status for structure and its parents.
192 void SetRaytracableWithAncestorStructures() const;
193
5e27df78 194protected:
2166f0fa 195
5e27df78 196 OpenGl_Matrix* myTransformation;
197 TEL_TRANSFORM_PERSISTENCE* myTransPers;
5e27df78 198 OpenGl_AspectLine* myAspectLine;
199 OpenGl_AspectFace* myAspectFace;
200 OpenGl_AspectMarker* myAspectMarker;
201 OpenGl_AspectText* myAspectText;
63bcc448 202
b64d84be 203 Handle(OpenGl_Group) myHighlightBox;
5e27df78 204 TEL_COLOUR* myHighlightColor;
63bcc448 205
206 int myNamedStatus;
5e27df78 207 int myZLayer;
2166f0fa 208
51b10cd4 209 OpenGl_ListOfStructure myConnected;
2166f0fa 210
e276548b 211 mutable OpenGl_ListOfStructure myAncestorStructures;
212 mutable Standard_Boolean myIsRaytracable;
213 mutable Standard_Size myModificationState;
e276548b 214
5e27df78 215public:
2166f0fa 216
63bcc448 217 DEFINE_STANDARD_RTTI(OpenGl_Structure) // Type definition
5e27df78 218
2166f0fa
SK
219};
220
63bcc448 221DEFINE_STANDARD_HANDLE(OpenGl_Structure, Graphic3d_CStructure)
222
223#endif // OpenGl_Structure_Header