0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[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_HeaderFile
17 #define OpenGl_Structure_HeaderFile
18
19 #include <Graphic3d_CStructure.hxx>
20
21 #include <OpenGl_GraphicDriver.hxx>
22 #include <OpenGl_Group.hxx>
23 #include <OpenGl_Workspace.hxx>
24
25 #include <NCollection_List.hxx>
26
27
28 DEFINE_STANDARD_HANDLE(OpenGl_Structure, Graphic3d_CStructure)
29 typedef NCollection_List<const OpenGl_Structure* > OpenGl_ListOfStructure;
30
31 //! Implementation of low-level graphic structure.
32 class OpenGl_Structure : public Graphic3d_CStructure
33 {
34   friend class OpenGl_Group;
35   DEFINE_STANDARD_RTTIEXT(OpenGl_Structure, Graphic3d_CStructure)
36 public:
37
38   //! Auxiliary wrapper to iterate OpenGl_Structure sequence.
39   typedef SubclassStructIterator<OpenGl_Structure> StructIterator;
40
41   //! Auxiliary wrapper to iterate OpenGl_Group sequence.
42   typedef SubclassGroupIterator<OpenGl_Group> GroupIterator;
43
44 public:
45
46   //! Create empty structure
47   Standard_EXPORT OpenGl_Structure (const Handle(Graphic3d_StructureManager)& theManager);
48
49   //! Setup structure graphic state
50   Standard_EXPORT virtual void OnVisibilityChanged() Standard_OVERRIDE;
51
52   //! Clear graphic data
53   Standard_EXPORT virtual void Clear() Standard_OVERRIDE;
54
55   //! Connect other structure to this one
56   Standard_EXPORT virtual void Connect    (Graphic3d_CStructure& theStructure) Standard_OVERRIDE;
57
58   //! Disconnect other structure to this one
59   Standard_EXPORT virtual void Disconnect (Graphic3d_CStructure& theStructure) Standard_OVERRIDE;
60
61   //! Synchronize structure transformation
62   Standard_EXPORT virtual void SetTransformation (const Handle(TopLoc_Datum3D)& theTrsf) Standard_OVERRIDE;
63
64   //! Set transformation persistence.
65   Standard_EXPORT virtual void SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers) Standard_OVERRIDE;
66
67   //! Set z layer ID to display the structure in specified layer
68   Standard_EXPORT virtual void SetZLayer(const Graphic3d_ZLayerId theLayerIndex) Standard_OVERRIDE;
69
70   //! Highlights structure according to the given style and updates corresponding class fields
71   //! (highlight status and style)
72   Standard_EXPORT virtual void GraphicHighlight (const Handle(Graphic3d_PresentationAttributes)& theStyle) Standard_OVERRIDE;
73
74   //! Unighlights structure and updates corresponding class fields (highlight status and style)
75   Standard_EXPORT virtual void GraphicUnhighlight() Standard_OVERRIDE;
76
77   //! Create shadow link to this structure
78   Standard_EXPORT virtual Handle(Graphic3d_CStructure) ShadowLink (const Handle(Graphic3d_StructureManager)& theManager) const Standard_OVERRIDE;
79
80   //! Create new group within this structure
81   Standard_EXPORT virtual Handle(Graphic3d_Group) NewGroup (const Handle(Graphic3d_Structure)& theStruct) Standard_OVERRIDE;
82
83   //! Remove group from this structure
84   Standard_EXPORT virtual void RemoveGroup (const Handle(Graphic3d_Group)& theGroup) Standard_OVERRIDE;
85
86 public:
87
88   //! Access graphic driver
89   OpenGl_GraphicDriver* GlDriver() const
90   {
91     return (OpenGl_GraphicDriver* )myGraphicDriver.operator->();
92   }
93
94   Standard_EXPORT void Clear (const Handle(OpenGl_Context)& theGlCtx);
95
96   //! Renders the structure.
97   Standard_EXPORT virtual void Render  (const Handle(OpenGl_Workspace)& theWorkspace) const;
98
99   //! Releases structure resources.
100   Standard_EXPORT virtual void Release (const Handle(OpenGl_Context)& theGlCtx);
101
102   //! This method releases GL resources without actual elements destruction.
103   //! As result structure could be correctly destroyed layer without GL context
104   //! (after last window was closed for example).
105   //!
106   //! Notice however that reusage of this structure after calling this method is incorrect
107   //! and will lead to broken visualization due to loosed data.
108   Standard_EXPORT void ReleaseGlResources (const Handle(OpenGl_Context)& theGlCtx);
109
110   //! Returns instanced OpenGL structure.
111   const OpenGl_Structure* InstancedStructure() const { return myInstancedStructure; }
112
113   //! Returns structure modification state (for ray-tracing).
114   Standard_Size ModificationState() const { return myModificationState; }
115
116   //! Resets structure modification state (for ray-tracing).
117   void ResetModificationState() const { myModificationState = 0; }
118
119   //! Is the structure ray-tracable (contains ray-tracable elements)?
120   Standard_Boolean IsRaytracable() const;
121
122   //! Update render transformation matrix.
123   Standard_EXPORT virtual void updateLayerTransformation() Standard_OVERRIDE;
124
125   //! Dumps the content of me into the stream
126   Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
127
128 protected:
129
130   Standard_EXPORT virtual ~OpenGl_Structure();
131
132   //! Updates ray-tracable status for structure and its parents.
133   void UpdateStateIfRaytracable (const Standard_Boolean toCheck = Standard_True) const;
134
135   //! Renders groups of structure without applying any attributes (i.e. transform, material etc).
136   //! @param theWorkspace current workspace
137   //! @param theHasClosed flag will be set to TRUE if structure contains at least one group of closed primitives
138   Standard_EXPORT void renderGeometry (const Handle(OpenGl_Workspace)& theWorkspace,
139                                        bool&                           theHasClosed) const;
140
141   //! Render the bounding box.
142   Standard_EXPORT void renderBoundingBox(const Handle(OpenGl_Workspace)& theWorkspace) const;
143
144   //! Apply transform persistence into context.
145   //! It disables shadows on non-3d objects when toEnable is true and restores otherwise.
146   //! @param[in]  theCtx current context
147   //! @param[in]  theTrsfPers transform persistence
148   //! @param[in]  theIsLocal specifies if transform persistence is defined locally or to entire presentation
149   //! @param[out] theOldCastShadows state of the previous cast shadows state
150   Standard_EXPORT void applyPersistence (const Handle(OpenGl_Context)& theCtx,
151                                          const Handle(Graphic3d_TransformPers)& theTrsfPersistence,
152                                          const Standard_Boolean theIsLocal,
153                                          Standard_Boolean& theOldCastShadows) const;
154
155   //! Restore context from transform persistence changes.
156   //! @param[in] theCtx current context
157   //! @param[in] theTrsfPers transform persistence
158   //! @param[in] theIsLocal specifies if transform persistence is defined locally or to entire presentation
159   //! @param[in] theOldCastShadows state of the previous cast shadows state
160   Standard_EXPORT void revertPersistence (const Handle(OpenGl_Context)& theCtx,
161                                           const Handle(Graphic3d_TransformPers)& theTrsfPersistence,
162                                           const Standard_Boolean theIsLocal,
163                                           const Standard_Boolean theOldCastShadows) const;
164
165 protected:
166
167   OpenGl_Structure*          myInstancedStructure;
168   Graphic3d_Mat4             myRenderTrsf; //!< transformation, actually used for rendering (includes Local Origin shift)
169
170   mutable Standard_Boolean   myIsRaytracable;
171   mutable Standard_Size      myModificationState;
172
173   Standard_Boolean           myIsMirrored; //!< Used to tell OpenGl to interpret polygons in clockwise order.
174
175 };
176
177 #endif // OpenGl_Structure_Header