0024406: Visualization - crash on re-usage of the same primitive array
[occt.git] / src / OpenGl / OpenGl_Group.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_Group_Header
17 #define _OpenGl_Group_Header
18
19 #include <InterfaceGraphic_Graphic3d.hxx>
20 #include <Graphic3d_Group.hxx>
21 #include <Graphic3d_Structure.hxx>
22
23 #include <NCollection_List.hxx>
24 #include <OpenGl_AspectLine.hxx>
25 #include <OpenGl_AspectFace.hxx>
26 #include <OpenGl_AspectMarker.hxx>
27 #include <OpenGl_AspectText.hxx>
28 #include <OpenGl_Element.hxx>
29
30 class OpenGl_Group;
31 class OpenGl_Structure;
32
33 struct OpenGl_ElementNode
34 {
35   OpenGl_Element*     elem;
36   OpenGl_ElementNode* next;
37   DEFINE_STANDARD_ALLOC
38 };
39
40 //! Implementation of low-level graphic group.
41 class OpenGl_Group : public Graphic3d_Group
42 {
43 public:
44
45   //! Create empty group.
46   //! Will throw exception if not created by OpenGl_Structure.
47   Standard_EXPORT OpenGl_Group (const Handle(Graphic3d_Structure)& theStruct);
48
49   Standard_EXPORT virtual void Clear (const Standard_Boolean theToUpdateStructureMgr);
50
51   //! Update line aspect
52   Standard_EXPORT virtual void UpdateAspectLine   (const Standard_Boolean theIsGlobal);
53
54   //! Update fill aspect
55   Standard_EXPORT virtual void UpdateAspectFace   (const Standard_Boolean theIsGlobal);
56
57   //! Update marker aspect
58   Standard_EXPORT virtual void UpdateAspectMarker (const Standard_Boolean theIsGlobal);
59
60   //! Update text aspect
61   Standard_EXPORT virtual void UpdateAspectText   (const Standard_Boolean theIsGlobal);
62
63   //! Add primitive array element
64   Standard_EXPORT virtual void AddPrimitiveArray (const Graphic3d_TypeOfPrimitiveArray theType,
65                                                   const Handle(Graphic3d_IndexBuffer)& theIndices,
66                                                   const Handle(Graphic3d_Buffer)&      theAttribs,
67                                                   const Handle(Graphic3d_BoundBuffer)& theBounds,
68                                                   const Standard_Boolean               theToEvalMinMax);
69
70   //! Add text element
71   Standard_EXPORT virtual void Text (const Standard_CString                  theTextUtf,
72                                      const Graphic3d_Vertex&                 thePoint,
73                                      const Standard_Real                     theHeight,
74                                      const Quantity_PlaneAngle               theAngle,
75                                      const Graphic3d_TextPath                theTp,
76                                      const Graphic3d_HorizontalTextAlignment theHta,
77                                      const Graphic3d_VerticalTextAlignment   theVta,
78                                      const Standard_Boolean                  theToEvalMinMax);
79
80   //! Add UserDraw element using obsolete API
81   Standard_EXPORT virtual void UserDraw (const Standard_Address theObject,
82                                          const Standard_Boolean theToEvalMinMax,
83                                          const Standard_Boolean theContainsFacet);
84
85   //! Add flipping element
86   Standard_EXPORT virtual void SetFlippingOptions (const Standard_Boolean theIsEnabled,
87                                                    const gp_Ax2&          theRefPlane);
88
89   //! Add stencil test element
90   Standard_EXPORT virtual void SetStencilTestOptions (const Standard_Boolean theIsEnabled);
91
92 public:
93
94   OpenGl_Structure* GlStruct() const { return (OpenGl_Structure* )(myStructure->CStructure().operator->()); }
95
96   Standard_EXPORT void AddElement (OpenGl_Element* theElem);
97
98   Standard_EXPORT virtual void Render  (const Handle(OpenGl_Workspace)& theWorkspace) const;
99   Standard_EXPORT virtual void Release (const Handle(OpenGl_Context)&   theGlCtx);
100
101   //! Returns first OpenGL element node of the group.
102   const OpenGl_ElementNode* FirstNode() const { return myFirst; }
103
104   //! Returns OpenGL face aspect.
105   const OpenGl_AspectFace* AspectFace() const { return myAspectFace; }
106
107   //! Returns modification state for ray-tracing.
108   Standard_Size ModificationState() const { return myModificationState; }
109
110   //! Is the group ray-tracable (contains ray-tracable elements)?
111   Standard_Boolean IsRaytracable() const { return myIsRaytracable; }
112
113   //! Accessor to line aspect (to be removed)
114   CALL_DEF_CONTEXTLINE& ChangeContextLine() { return ContextLine; }
115
116 protected:
117
118   Standard_EXPORT virtual ~OpenGl_Group();
119
120 protected:
121
122   OpenGl_AspectLine*     myAspectLine;
123   OpenGl_AspectFace*     myAspectFace;
124   OpenGl_AspectMarker*   myAspectMarker;
125   OpenGl_AspectText*     myAspectText;
126
127   OpenGl_ElementNode*    myFirst;
128   OpenGl_ElementNode*    myLast;
129
130   Standard_Boolean       myIsRaytracable;
131   Standard_Size          myModificationState;
132
133 public:
134
135   DEFINE_STANDARD_RTTI(OpenGl_Group) // Type definition
136
137 };
138
139 DEFINE_STANDARD_HANDLE(OpenGl_Group, Graphic3d_Group)
140
141 #endif // _OpenGl_Group_Header