0030729: Visualization - TKOpenGl reports OpenGL 4.5 loading functions error on Intel...
[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 21
bf5f0ca2 22#include <OpenGl_Aspects.hxx>
2166f0fa 23
5b111128 24#include <OpenGl_GraphicDriver.hxx>
2166f0fa
SK
25#include <OpenGl_Group.hxx>
26#include <OpenGl_Matrix.hxx>
b7cd4ba7 27#include <OpenGl_Vec.hxx>
28#include <OpenGl_Workspace.hxx>
2166f0fa 29
63bcc448 30#include <NCollection_List.hxx>
4269bd1b 31
63bcc448 32class OpenGl_GraphicDriver;
bf75be98 33
d325cb7f 34DEFINE_STANDARD_HANDLE(OpenGl_Structure, Graphic3d_CStructure)
bf75be98 35typedef NCollection_List<const OpenGl_Structure* > OpenGl_ListOfStructure;
2166f0fa 36
b64d84be 37//! Implementation of low-level graphic structure.
63bcc448 38class OpenGl_Structure : public Graphic3d_CStructure
2166f0fa 39{
e276548b 40 friend class OpenGl_Group;
d325cb7f 41 DEFINE_STANDARD_RTTIEXT(OpenGl_Structure, Graphic3d_CStructure)
b64d84be 42public:
43
d325cb7f 44 //! Auxiliary wrapper to iterate OpenGl_Structure sequence.
45 typedef SubclassStructIterator<OpenGl_Structure> StructIterator;
b64d84be 46
d325cb7f 47 //! Auxiliary wrapper to iterate OpenGl_Group sequence.
48 typedef SubclassGroupIterator<OpenGl_Group> GroupIterator;
b64d84be 49
5e27df78 50public:
51
63bcc448 52 //! Create empty structure
b64d84be 53 Standard_EXPORT OpenGl_Structure (const Handle(Graphic3d_StructureManager)& theManager);
63bcc448 54
55 //! Setup structure graphic state
a1954302 56 Standard_EXPORT virtual void OnVisibilityChanged() Standard_OVERRIDE;
63bcc448 57
58 //! Clear graphic data
79104795 59 Standard_EXPORT virtual void Clear() Standard_OVERRIDE;
63bcc448 60
61 //! Connect other structure to this one
79104795 62 Standard_EXPORT virtual void Connect (Graphic3d_CStructure& theStructure) Standard_OVERRIDE;
63bcc448 63
64 //! Disconnect other structure to this one
79104795 65 Standard_EXPORT virtual void Disconnect (Graphic3d_CStructure& theStructure) Standard_OVERRIDE;
63bcc448 66
63bcc448 67 //! Synchronize structure transformation
1f7f5a90 68 Standard_EXPORT virtual void SetTransformation (const Handle(Geom_Transformation)& theTrsf) Standard_OVERRIDE;
63bcc448 69
7c3ef2f7 70 //! Set transformation persistence.
71 Standard_EXPORT virtual void SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers) Standard_OVERRIDE;
72
73 //! Set z layer ID to display the structure in specified layer
74 Standard_EXPORT virtual void SetZLayer(const Graphic3d_ZLayerId theLayerIndex) Standard_OVERRIDE;
75
8e5fb5ea 76 //! Highlights structure according to the given style and updates corresponding class fields
77 //! (highlight status and style)
98b15dbf 78 Standard_EXPORT virtual void GraphicHighlight (const Handle(Graphic3d_PresentationAttributes)& theStyle) Standard_OVERRIDE;
63bcc448 79
8e5fb5ea 80 //! Unighlights structure and updates corresponding class fields (highlight status and style)
81 Standard_EXPORT virtual void GraphicUnhighlight() Standard_OVERRIDE;
63bcc448 82
679ecdee 83 //! Create shadow link to this structure
79104795 84 Standard_EXPORT virtual Handle(Graphic3d_CStructure) ShadowLink (const Handle(Graphic3d_StructureManager)& theManager) const Standard_OVERRIDE;
b64d84be 85
86 //! Create new group within this structure
79104795 87 Standard_EXPORT virtual Handle(Graphic3d_Group) NewGroup (const Handle(Graphic3d_Structure)& theStruct) Standard_OVERRIDE;
b64d84be 88
89 //! Remove group from this structure
79104795 90 Standard_EXPORT virtual void RemoveGroup (const Handle(Graphic3d_Group)& theGroup) Standard_OVERRIDE;
679ecdee 91
63bcc448 92public:
93
94 //! Access graphic driver
95 OpenGl_GraphicDriver* GlDriver() const
96 {
97 return (OpenGl_GraphicDriver* )myGraphicDriver.operator->();
98 }
2166f0fa 99
b64d84be 100 Standard_EXPORT void Clear (const Handle(OpenGl_Context)& theGlCtx);
2166f0fa 101
0717ddc1 102 //! Renders the structure.
5e27df78 103 virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
0717ddc1 104
105 //! Releases structure resources.
106 virtual void Release (const Handle(OpenGl_Context)& theGlCtx);
5e27df78 107
dd8a4ce9 108 //! This method releases GL resources without actual elements destruction.
e276548b 109 //! As result structure could be correctly destroyed layer without GL context
dd8a4ce9 110 //! (after last window was closed for example).
111 //!
112 //! Notice however that reusage of this structure after calling this method is incorrect
113 //! and will lead to broken visualization due to loosed data.
b64d84be 114 Standard_EXPORT void ReleaseGlResources (const Handle(OpenGl_Context)& theGlCtx);
e276548b 115
d4aaad5b 116 //! Returns instanced OpenGL structure.
117 const OpenGl_Structure* InstancedStructure() const { return myInstancedStructure; }
e276548b 118
e276548b 119 //! Returns structure modification state (for ray-tracing).
120 Standard_Size ModificationState() const { return myModificationState; }
121
189f85a3 122 //! Resets structure modification state (for ray-tracing).
e276548b 123 void ResetModificationState() const { myModificationState = 0; }
124
125 //! Is the structure ray-tracable (contains ray-tracable elements)?
d4aaad5b 126 Standard_Boolean IsRaytracable() const;
e276548b 127
7c3ef2f7 128 //! Update render transformation matrix.
d325cb7f 129 Standard_EXPORT virtual void updateLayerTransformation() Standard_OVERRIDE;
7c3ef2f7 130
5e27df78 131protected:
132
b64d84be 133 Standard_EXPORT virtual ~OpenGl_Structure();
5e27df78 134
e276548b 135 //! Updates ray-tracable status for structure and its parents.
d4aaad5b 136 void UpdateStateIfRaytracable (const Standard_Boolean toCheck = Standard_True) const;
e276548b 137
3e05329c 138 //! Renders groups of structure without applying any attributes (i.e. transform, material etc).
139 //! @param theWorkspace current workspace
140 //! @param theHasClosed flag will be set to TRUE if structure contains at least one group of closed primitives
141 Standard_EXPORT void renderGeometry (const Handle(OpenGl_Workspace)& theWorkspace,
142 bool& theHasClosed) const;
143
98b15dbf 144 //! Render the bounding box.
145 Standard_EXPORT void renderBoundingBox(const Handle(OpenGl_Workspace)& theWorkspace) const;
8e5fb5ea 146
5e27df78 147protected:
2166f0fa 148
d4aaad5b 149 OpenGl_Structure* myInstancedStructure;
7c3ef2f7 150 Graphic3d_Mat4 myRenderTrsf; //!< transformation, actually used for rendering (includes Local Origin shift)
2166f0fa 151
d4aaad5b 152 mutable Standard_Boolean myIsRaytracable;
153 mutable Standard_Size myModificationState;
e276548b 154
d4aaad5b 155 Standard_Boolean myIsMirrored; //!< Used to tell OpenGl to interpret polygons in clockwise order.
7d9e854b 156
2166f0fa
SK
157};
158
63bcc448 159#endif // OpenGl_Structure_Header