0024637: Visualization - clean up implementation of rendering in immediate mode
[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
63bcc448 39class OpenGl_Structure : public Graphic3d_CStructure
2166f0fa 40{
e276548b 41 friend class OpenGl_Group;
5e27df78 42
43public:
44
63bcc448 45 //! Create empty structure
46 OpenGl_Structure (const Handle(Graphic3d_StructureManager)& theManager);
47
48 //! Setup structure graphic state
49 virtual void UpdateNamedStatus();
50
51 //! Clear graphic data
52 virtual void Clear();
53
54 //! Connect other structure to this one
55 virtual void Connect (Graphic3d_CStructure& theStructure);
56
57 //! Disconnect other structure to this one
58 virtual void Disconnect (Graphic3d_CStructure& theStructure);
59
60 //! Synchronize structure aspects
61 virtual void UpdateAspects();
2166f0fa 62
63bcc448 63 //! Synchronize structure transformation
64 virtual void UpdateTransformation();
65
66 //! Highlight entire structure with color
67 virtual void HighlightWithColor (const Graphic3d_Vec3& theColor,
68 const Standard_Boolean theToCreate);
69
70 //! Highlight structure using boundary box
71 virtual void HighlightWithBndBox (const Standard_Boolean theToCreate);
72
679ecdee 73 //! Create shadow link to this structure
74 virtual Handle(Graphic3d_CStructure) ShadowLink (const Handle(Graphic3d_StructureManager)& theManager) const;
75
63bcc448 76public:
77
78 //! Access graphic driver
79 OpenGl_GraphicDriver* GlDriver() const
80 {
81 return (OpenGl_GraphicDriver* )myGraphicDriver.operator->();
82 }
2166f0fa
SK
83
84 void SetTransformPersistence (const CALL_DEF_TRANSFORM_PERSISTENCE &ATransPers);
85
fd4a6963 86 void SetAspectLine (const CALL_DEF_CONTEXTLINE &theAspect);
87 void SetAspectFace (const CALL_DEF_CONTEXTFILLAREA& theAspect);
88 void SetAspectMarker (const CALL_DEF_CONTEXTMARKER& theAspect);
89 void SetAspectText (const CALL_DEF_CONTEXTTEXT &theAspect);
2166f0fa 90
5e27df78 91 void SetHighlightBox (const Handle(OpenGl_Context)& theGlCtx,
30f0ad28 92 const CALL_DEF_BOUNDBOX& theBoundBox);
5e27df78 93
94 void ClearHighlightBox (const Handle(OpenGl_Context)& theGlCtx);
95
96 void SetHighlightColor (const Handle(OpenGl_Context)& theGlCtx,
63bcc448 97 const Graphic3d_Vec3& theColor);
2166f0fa 98
5e27df78 99 void ClearHighlightColor (const Handle(OpenGl_Context)& theGlCtx);
2166f0fa 100
e276548b 101 Standard_Boolean IsVisible() const { return !(myNamedStatus & OPENGL_NS_HIDE); }
2166f0fa 102
5e27df78 103 OpenGl_Group* AddGroup();
104 void RemoveGroup (const Handle(OpenGl_Context)& theGlCtx,
105 const OpenGl_Group* theGroup);
106 void Clear (const Handle(OpenGl_Context)& theGlCtx);
2166f0fa 107
59f45b7c 108 //! Set z layer ID to display the structure in specified layer
109 void SetZLayer (const Standard_Integer theLayerIndex);
110
111 //! Get z layer ID
112 Standard_Integer GetZLayer () const;
2166f0fa 113
5e27df78 114 virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
115 virtual void Release (const Handle(OpenGl_Context)& theGlCtx);
116
dd8a4ce9 117 //! This method releases GL resources without actual elements destruction.
e276548b 118 //! As result structure could be correctly destroyed layer without GL context
dd8a4ce9 119 //! (after last window was closed for example).
120 //!
121 //! Notice however that reusage of this structure after calling this method is incorrect
122 //! and will lead to broken visualization due to loosed data.
123 void ReleaseGlResources (const Handle(OpenGl_Context)& theGlCtx);
124
e276548b 125 //! Returns list of OpenGL groups.
679ecdee 126 virtual const OpenGl_ListOfGroup& Groups() const { return myGroups; }
e276548b 127
128 //! Returns list of connected OpenGL structures.
129 const OpenGl_ListOfStructure& ConnectedStructures() const { return myConnected; }
130
131 //! Returns OpenGL face aspect.
132 const OpenGl_AspectFace* AspectFace() const { return myAspectFace; }
133
134 //! Returns OpenGL transformation matrix.
135 const OpenGl_Matrix* Transformation() const { return myTransformation; }
136
137 //! Returns OpenGL persistent translation.
138 const TEL_TRANSFORM_PERSISTENCE* PersistentTranslation() const { return myTransPers; }
139
140#ifdef HAVE_OPENCL
141
142 //! Returns structure modification state (for ray-tracing).
143 Standard_Size ModificationState() const { return myModificationState; }
144
145 //! Resets structure modification state (for ray-tracing)
146 void ResetModificationState() const { myModificationState = 0; }
147
148 //! Is the structure ray-tracable (contains ray-tracable elements)?
149 Standard_Boolean IsRaytracable() const { return myIsRaytracable; }
150
151#endif
152
5e27df78 153protected:
154
155 virtual ~OpenGl_Structure();
156
e276548b 157#ifdef HAVE_OPENCL
158
159 //! Registers ancestor connected structure (for updating ray-tracing state).
160 void RegisterAncestorStructure (const OpenGl_Structure* theStructure) const;
161
162 //! Unregisters ancestor connected structure (for updating ray-tracing state).
163 void UnregisterAncestorStructure (const OpenGl_Structure* theStructure) const;
164
d5af8626 165 //! Unregisters structure from ancestor structure (for updating ray-tracing state).
166 void UnregisterFromAncestorStructure() const;
167
e276548b 168 //! Updates modification state for structure and its parents.
169 void UpdateStateWithAncestorStructures() const;
170
171 //! Updates ray-tracable status for structure and its parents.
172 void UpdateRaytracableWithAncestorStructures() const;
173
174 //! Sets ray-tracable status for structure and its parents.
175 void SetRaytracableWithAncestorStructures() const;
176
177#endif
178
5e27df78 179protected:
2166f0fa 180
5e27df78 181 OpenGl_Matrix* myTransformation;
182 TEL_TRANSFORM_PERSISTENCE* myTransPers;
5e27df78 183 OpenGl_AspectLine* myAspectLine;
184 OpenGl_AspectFace* myAspectFace;
185 OpenGl_AspectMarker* myAspectMarker;
186 OpenGl_AspectText* myAspectText;
63bcc448 187
5e27df78 188 OpenGl_Group* myHighlightBox;
189 TEL_COLOUR* myHighlightColor;
63bcc448 190
191 int myNamedStatus;
5e27df78 192 int myZLayer;
2166f0fa 193
51b10cd4 194 OpenGl_ListOfStructure myConnected;
195 OpenGl_ListOfGroup myGroups;
2166f0fa 196
e276548b 197#ifdef HAVE_OPENCL
198 mutable OpenGl_ListOfStructure myAncestorStructures;
199 mutable Standard_Boolean myIsRaytracable;
200 mutable Standard_Size myModificationState;
201#endif
202
5e27df78 203public:
2166f0fa 204
63bcc448 205 DEFINE_STANDARD_RTTI(OpenGl_Structure) // Type definition
5e27df78 206
2166f0fa
SK
207};
208
63bcc448 209DEFINE_STANDARD_HANDLE(OpenGl_Structure, Graphic3d_CStructure)
210
211#endif // OpenGl_Structure_Header