0027232: Configuration - fix mblen missing building issue on Android
[occt.git] / src / OpenGl / OpenGl_Structure.hxx
1 // Created on: 2011-08-01
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef OpenGl_Structure_Header
17 #define OpenGl_Structure_Header
18
19 #include <Graphic3d_CStructure.hxx>
20 #include <Graphic3d_SequenceOfHClipPlane.hxx>
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_GraphicDriver.hxx>
28 #include <OpenGl_Group.hxx>
29 #include <OpenGl_Matrix.hxx>
30 #include <OpenGl_Vec.hxx>
31 #include <OpenGl_Workspace.hxx>
32
33 #include <NCollection_List.hxx>
34 #include <InterfaceGraphic_Graphic3d.hxx>
35
36 class OpenGl_Structure;
37 class OpenGl_GraphicDriver;
38
39 typedef NCollection_List<const OpenGl_Structure* > OpenGl_ListOfStructure;
40
41 //! Implementation of low-level graphic structure.
42 class OpenGl_Structure : public Graphic3d_CStructure
43 {
44   friend class OpenGl_Group;
45
46 public:
47
48   //! Auxiliary wrapper to iterate OpenGl_Group sequence.
49   class GroupIterator
50   {
51
52   public:
53     GroupIterator (const Graphic3d_SequenceOfGroup& theGroups) : myIter (theGroups) {}
54     Standard_Boolean More() const     { return myIter.More(); }
55     void Next()                       { myIter.Next(); }
56     const OpenGl_Group* Value() const { return (const OpenGl_Group* )(myIter.Value().operator->()); }
57     OpenGl_Group*       ChangeValue() { return (OpenGl_Group* )(myIter.ChangeValue().operator->()); }
58
59   private:
60     Graphic3d_SequenceOfGroup::Iterator myIter;
61
62   };
63
64 public:
65
66   //! Create empty structure
67   Standard_EXPORT OpenGl_Structure (const Handle(Graphic3d_StructureManager)& theManager);
68
69   //! Setup structure graphic state
70   Standard_EXPORT virtual void OnVisibilityChanged() Standard_OVERRIDE;
71
72   //! Clear graphic data
73   Standard_EXPORT virtual void Clear() Standard_OVERRIDE;
74
75   //! Connect other structure to this one
76   Standard_EXPORT virtual void Connect    (Graphic3d_CStructure& theStructure) Standard_OVERRIDE;
77
78   //! Disconnect other structure to this one
79   Standard_EXPORT virtual void Disconnect (Graphic3d_CStructure& theStructure) Standard_OVERRIDE;
80
81   //! Synchronize structure aspects
82   Standard_EXPORT virtual void UpdateAspects() Standard_OVERRIDE;
83
84   //! Synchronize structure transformation
85   Standard_EXPORT virtual void UpdateTransformation() Standard_OVERRIDE;
86
87   //! Highlight entire structure with color
88   Standard_EXPORT virtual void HighlightWithColor (const Graphic3d_Vec3&  theColor,
89                                                    const Standard_Boolean theToCreate) Standard_OVERRIDE;
90
91   //! Highlight structure using boundary box
92   Standard_EXPORT virtual void HighlightWithBndBox (const Handle(Graphic3d_Structure)& theStruct,
93                                                     const Standard_Boolean             theToCreate) Standard_OVERRIDE;
94
95   //! Create shadow link to this structure
96   Standard_EXPORT virtual Handle(Graphic3d_CStructure) ShadowLink (const Handle(Graphic3d_StructureManager)& theManager) const Standard_OVERRIDE;
97
98   //! Create new group within this structure
99   Standard_EXPORT virtual Handle(Graphic3d_Group) NewGroup (const Handle(Graphic3d_Structure)& theStruct) Standard_OVERRIDE;
100
101   //! Remove group from this structure
102   Standard_EXPORT virtual void RemoveGroup (const Handle(Graphic3d_Group)& theGroup) Standard_OVERRIDE;
103
104 public:
105
106   //! @return graphic groups
107   virtual const Graphic3d_SequenceOfGroup& DrawGroups() const
108   {
109     return myGroups;
110   }
111
112   //! Access graphic driver
113   OpenGl_GraphicDriver* GlDriver() const
114   {
115     return (OpenGl_GraphicDriver* )myGraphicDriver.operator->();
116   }
117
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);
122
123   void clearHighlightBox (const Handle(OpenGl_Context)& theGlCtx);
124
125   void setHighlightColor (const Handle(OpenGl_Context)& theGlCtx,
126                           const Graphic3d_Vec3&         theColor);
127
128   void clearHighlightColor (const Handle(OpenGl_Context)& theGlCtx);
129
130   Standard_EXPORT void Clear (const Handle(OpenGl_Context)& theGlCtx);
131
132   //! Renders groups of structure without applying any attributes (i.e. transform, material etc).
133   //! @param theWorkspace current workspace
134   //! @param theHasClosed flag will be set to TRUE if structure contains at least one group of closed primitives
135   virtual void renderGeometry (const Handle(OpenGl_Workspace)& theWorkspace,
136                                bool&                           theHasClosed) const;
137
138   //! Renders groups of closed primitives without applying any attributes (i.e. transform, material etc).
139   virtual void renderClosedGeometry (const Handle(OpenGl_Workspace)& theWorkspace) const;
140
141   //! Renders the structure.
142   virtual void Render  (const Handle(OpenGl_Workspace)& theWorkspace) const;
143
144   //! Releases structure resources.
145   virtual void Release (const Handle(OpenGl_Context)& theGlCtx);
146
147   //! Marks structure as not overlapping view volume (as it is by default).
148   void ResetCullingStatus() const
149   {
150     if (!IsAlwaysRendered())
151     {
152       myIsCulled = Standard_True;
153     }
154   }
155
156   //! Marks structure as overlapping the current view volume one.
157   //! The method is called during traverse of BVH tree.
158   void MarkAsNotCulled() const { myIsCulled = Standard_False; }
159
160   //! Returns Standard_False if the structure hits the current view volume, otherwise
161   //! returns Standard_True. The default value for all structures before each traverse
162   //! of BVH tree is Standard_True.
163   Standard_Boolean IsCulled() const { return myIsCulled; }
164
165   //! Checks if the structure should be included into BVH tree or not.
166   Standard_Boolean IsAlwaysRendered() const
167   {
168     return IsInfinite
169         || IsForHighlight
170         || IsMutable
171         || Is2dText
172         || (TransformPersistence.Flags & Graphic3d_TMF_2d)           != 0
173         || (TransformPersistence.Flags & Graphic3d_TMF_PanPers)      != 0
174         || (TransformPersistence.Flags & Graphic3d_TMF_TriedronPers) != 0;
175   }
176
177   //! This method releases GL resources without actual elements destruction.
178   //! As result structure could be correctly destroyed layer without GL context
179   //! (after last window was closed for example).
180   //!
181   //! Notice however that reusage of this structure after calling this method is incorrect
182   //! and will lead to broken visualization due to loosed data.
183   Standard_EXPORT void ReleaseGlResources (const Handle(OpenGl_Context)& theGlCtx);
184
185   //! Returns instanced OpenGL structure.
186   const OpenGl_Structure* InstancedStructure() const { return myInstancedStructure; }
187
188   //! Returns OpenGL face aspect.
189   const OpenGl_AspectFace* AspectFace() const { return myAspectFace; }
190
191   //! Returns structure modification state (for ray-tracing).
192   Standard_Size ModificationState() const { return myModificationState; }
193
194   //! Resets structure modification state (for ray-tracing).
195   void ResetModificationState() const { myModificationState = 0; }
196
197   //! Is the structure ray-tracable (contains ray-tracable elements)?
198   Standard_Boolean IsRaytracable() const;
199
200 protected:
201
202   Standard_EXPORT virtual ~OpenGl_Structure();
203
204   //! Updates ray-tracable status for structure and its parents.
205   void UpdateStateIfRaytracable (const Standard_Boolean toCheck = Standard_True) const;
206
207 protected:
208
209   OpenGl_AspectLine*         myAspectLine;
210   OpenGl_AspectFace*         myAspectFace;
211   OpenGl_AspectMarker*       myAspectMarker;
212   OpenGl_AspectText*         myAspectText;
213
214   Handle(OpenGl_Group)       myHighlightBox;
215   TEL_COLOUR*                myHighlightColor;
216
217   OpenGl_Structure*          myInstancedStructure;
218
219   mutable Standard_Boolean   myIsRaytracable;
220   mutable Standard_Size      myModificationState;
221
222   mutable Standard_Boolean   myIsCulled; //!< A status specifying is structure needs to be rendered after BVH tree traverse.
223
224   Standard_Boolean           myIsMirrored; //!< Used to tell OpenGl to interpret polygons in clockwise order.
225
226 public:
227
228   DEFINE_STANDARD_RTTIEXT(OpenGl_Structure,Graphic3d_CStructure) // Type definition
229
230 };
231
232 DEFINE_STANDARD_HANDLE(OpenGl_Structure, Graphic3d_CStructure)
233
234 #endif // OpenGl_Structure_Header