cd76dd239910057136933009ccea9037fdf853e5
[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 <Graphic3d_Group.hxx>
20 #include <Graphic3d_Structure.hxx>
21
22 #include <NCollection_List.hxx>
23 #include <OpenGl_Aspects.hxx>
24 #include <OpenGl_Element.hxx>
25
26 class OpenGl_Group;
27 class OpenGl_Structure;
28
29 struct OpenGl_ElementNode
30 {
31   OpenGl_Element*     elem;
32   OpenGl_ElementNode* next;
33   DEFINE_STANDARD_ALLOC
34 };
35
36 //! Implementation of low-level graphic group.
37 class OpenGl_Group : public Graphic3d_Group
38 {
39 public:
40
41   //! Create empty group.
42   //! Will throw exception if not created by OpenGl_Structure.
43   Standard_EXPORT OpenGl_Group (const Handle(Graphic3d_Structure)& theStruct);
44
45   Standard_EXPORT virtual void Clear (const Standard_Boolean theToUpdateStructureMgr) Standard_OVERRIDE;
46
47   //! Return line aspect.
48   virtual Handle(Graphic3d_Aspects) Aspects() const Standard_OVERRIDE
49   {
50     return myAspects != NULL
51          ? myAspects->Aspect()
52          : Handle(Graphic3d_Aspects)();
53   }
54
55   //! Update aspect.
56   Standard_EXPORT virtual void SetGroupPrimitivesAspect (const Handle(Graphic3d_Aspects)& theAspect) Standard_OVERRIDE;
57
58   //! Append aspect as an element.
59   Standard_EXPORT virtual void SetPrimitivesAspect (const Handle(Graphic3d_Aspects)& theAspect) Standard_OVERRIDE;
60
61   //! Update presentation aspects after their modification.
62   Standard_EXPORT virtual void SynchronizeAspects() Standard_OVERRIDE;
63
64   //! Replace aspects specified in the replacement map.
65   Standard_EXPORT virtual void ReplaceAspects (const Graphic3d_MapOfAspectsToAspects& theMap) Standard_OVERRIDE;
66
67   //! Add primitive array element
68   Standard_EXPORT virtual void AddPrimitiveArray (const Graphic3d_TypeOfPrimitiveArray theType,
69                                                   const Handle(Graphic3d_IndexBuffer)& theIndices,
70                                                   const Handle(Graphic3d_Buffer)&      theAttribs,
71                                                   const Handle(Graphic3d_BoundBuffer)& theBounds,
72                                                   const Standard_Boolean               theToEvalMinMax) Standard_OVERRIDE;
73
74   //! Adds a text for display
75   Standard_EXPORT virtual void AddText (const Handle(Graphic3d_Text)& theTextParams,
76                                         const Standard_Boolean theToEvalMinMax) Standard_OVERRIDE;
77   //! Add flipping element
78   Standard_EXPORT virtual void SetFlippingOptions (const Standard_Boolean theIsEnabled,
79                                                    const gp_Ax2&          theRefPlane) Standard_OVERRIDE;
80
81   //! Add stencil test element
82   Standard_EXPORT virtual void SetStencilTestOptions (const Standard_Boolean theIsEnabled) Standard_OVERRIDE;
83
84 public:
85
86   OpenGl_Structure* GlStruct() const { return (OpenGl_Structure* )(myStructure->CStructure().operator->()); }
87
88   Standard_EXPORT void AddElement (OpenGl_Element* theElem);
89
90   Standard_EXPORT virtual void Render  (const Handle(OpenGl_Workspace)& theWorkspace) const;
91   Standard_EXPORT virtual void Release (const Handle(OpenGl_Context)&   theGlCtx);
92
93   //! Returns first OpenGL element node of the group.
94   const OpenGl_ElementNode* FirstNode() const { return myFirst; }
95
96   //! Returns OpenGL aspect.
97   const OpenGl_Aspects* GlAspects() const { return myAspects; }
98
99   //! Is the group ray-tracable (contains ray-tracable elements)?
100   Standard_Boolean IsRaytracable() const { return myIsRaytracable; }
101
102   //! Dumps the content of me into the stream
103   Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
104
105 protected:
106
107   Standard_EXPORT virtual ~OpenGl_Group();
108
109 protected:
110
111   OpenGl_Aspects*     myAspects;
112   OpenGl_ElementNode* myFirst;
113   OpenGl_ElementNode* myLast;
114   Standard_Boolean    myIsRaytracable;
115
116 public:
117
118   DEFINE_STANDARD_RTTIEXT(OpenGl_Group,Graphic3d_Group) // Type definition
119
120 };
121
122 DEFINE_STANDARD_HANDLE(OpenGl_Group, Graphic3d_Group)
123
124 #endif // _OpenGl_Group_Header