1 // Created on: 2011-08-01
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef OpenGl_Structure_HeaderFile
17 #define OpenGl_Structure_HeaderFile
19 #include <Graphic3d_CStructure.hxx>
21 #include <OpenGl_GraphicDriver.hxx>
22 #include <OpenGl_Group.hxx>
23 #include <OpenGl_Workspace.hxx>
25 #include <NCollection_List.hxx>
28 DEFINE_STANDARD_HANDLE(OpenGl_Structure, Graphic3d_CStructure)
29 typedef NCollection_List<const OpenGl_Structure* > OpenGl_ListOfStructure;
31 //! Implementation of low-level graphic structure.
32 class OpenGl_Structure : public Graphic3d_CStructure
34 friend class OpenGl_Group;
35 DEFINE_STANDARD_RTTIEXT(OpenGl_Structure, Graphic3d_CStructure)
38 //! Auxiliary wrapper to iterate OpenGl_Structure sequence.
39 typedef SubclassStructIterator<OpenGl_Structure> StructIterator;
41 //! Auxiliary wrapper to iterate OpenGl_Group sequence.
42 typedef SubclassGroupIterator<OpenGl_Group> GroupIterator;
46 //! Create empty structure
47 Standard_EXPORT OpenGl_Structure (const Handle(Graphic3d_StructureManager)& theManager);
49 //! Setup structure graphic state
50 Standard_EXPORT virtual void OnVisibilityChanged() Standard_OVERRIDE;
52 //! Clear graphic data
53 Standard_EXPORT virtual void Clear() Standard_OVERRIDE;
55 //! Connect other structure to this one
56 Standard_EXPORT virtual void Connect (Graphic3d_CStructure& theStructure) Standard_OVERRIDE;
58 //! Disconnect other structure to this one
59 Standard_EXPORT virtual void Disconnect (Graphic3d_CStructure& theStructure) Standard_OVERRIDE;
61 //! Synchronize structure transformation
62 Standard_EXPORT virtual void SetTransformation (const Handle(TopLoc_Datum3D)& theTrsf) Standard_OVERRIDE;
64 //! Set transformation persistence.
65 Standard_EXPORT virtual void SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers) Standard_OVERRIDE;
67 //! Set z layer ID to display the structure in specified layer
68 Standard_EXPORT virtual void SetZLayer(const Graphic3d_ZLayerId theLayerIndex) Standard_OVERRIDE;
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;
74 //! Unighlights structure and updates corresponding class fields (highlight status and style)
75 Standard_EXPORT virtual void GraphicUnhighlight() Standard_OVERRIDE;
77 //! Create shadow link to this structure
78 Standard_EXPORT virtual Handle(Graphic3d_CStructure) ShadowLink (const Handle(Graphic3d_StructureManager)& theManager) const Standard_OVERRIDE;
80 //! Create new group within this structure
81 Standard_EXPORT virtual Handle(Graphic3d_Group) NewGroup (const Handle(Graphic3d_Structure)& theStruct) Standard_OVERRIDE;
83 //! Remove group from this structure
84 Standard_EXPORT virtual void RemoveGroup (const Handle(Graphic3d_Group)& theGroup) Standard_OVERRIDE;
88 //! Access graphic driver
89 OpenGl_GraphicDriver* GlDriver() const
91 return (OpenGl_GraphicDriver* )myGraphicDriver.operator->();
94 Standard_EXPORT void Clear (const Handle(OpenGl_Context)& theGlCtx);
96 //! Renders the structure.
97 Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
99 //! Releases structure resources.
100 Standard_EXPORT virtual void Release (const Handle(OpenGl_Context)& theGlCtx);
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).
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);
110 //! Returns instanced OpenGL structure.
111 const OpenGl_Structure* InstancedStructure() const { return myInstancedStructure; }
113 //! Returns structure modification state (for ray-tracing).
114 Standard_Size ModificationState() const { return myModificationState; }
116 //! Resets structure modification state (for ray-tracing).
117 void ResetModificationState() const { myModificationState = 0; }
119 //! Is the structure ray-tracable (contains ray-tracable elements)?
120 Standard_Boolean IsRaytracable() const;
122 //! Update render transformation matrix.
123 Standard_EXPORT virtual void updateLayerTransformation() Standard_OVERRIDE;
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;
130 Standard_EXPORT virtual ~OpenGl_Structure();
132 //! Updates ray-tracable status for structure and its parents.
133 void UpdateStateIfRaytracable (const Standard_Boolean toCheck = Standard_True) const;
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;
141 //! Render the bounding box.
142 Standard_EXPORT void renderBoundingBox(const Handle(OpenGl_Workspace)& theWorkspace) const;
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;
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;
167 OpenGl_Structure* myInstancedStructure;
168 Graphic3d_Mat4 myRenderTrsf; //!< transformation, actually used for rendering (includes Local Origin shift)
170 mutable Standard_Boolean myIsRaytracable;
171 mutable Standard_Size myModificationState;
173 Standard_Boolean myIsMirrored; //!< Used to tell OpenGl to interpret polygons in clockwise order.
177 #endif // OpenGl_Structure_Header