Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2011-07-13 |
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_PrimitiveArray_Header |
17 | #define OpenGl_PrimitiveArray_Header | |
18 | ||
871fa103 | 19 | #include <OpenGl_IndexBuffer.hxx> |
2166f0fa | 20 | |
bf75be98 | 21 | #include <InterfaceGraphic_Graphic3d.hxx> |
2166f0fa | 22 | #include <Aspect_InteriorStyle.hxx> |
a577aaab | 23 | #include <Aspect_TypeOfMarker.hxx> |
871fa103 | 24 | #include <Graphic3d_TypeOfPrimitiveArray.hxx> |
25 | #include <Graphic3d_IndexBuffer.hxx> | |
26 | #include <Graphic3d_BoundBuffer.hxx> | |
2166f0fa SK |
27 | |
28 | #include <OpenGl_Element.hxx> | |
29 | ||
8d3f219f | 30 | class OpenGl_GraphicDriver; |
7d3e64ef | 31 | class Handle(OpenGl_ShaderProgram); |
8d3f219f | 32 | |
7d3e64ef | 33 | //! Class for rendering of arbitrary primitive array. |
2166f0fa SK |
34 | class OpenGl_PrimitiveArray : public OpenGl_Element |
35 | { | |
36 | public: | |
871fa103 | 37 | // OpenGL does not provide a constant for "none" draw mode. |
1d03e66d | 38 | // So we define our own one that does not conflict with GL constants |
871fa103 | 39 | // and utilizes common GL invalid value |
1d03e66d | 40 | enum |
41 | { | |
42 | DRAW_MODE_NONE = -1 | |
43 | }; | |
2166f0fa | 44 | |
e1c659da | 45 | //! Empty constructor |
46 | Standard_EXPORT OpenGl_PrimitiveArray (const OpenGl_GraphicDriver* theDriver); | |
47 | ||
2166f0fa | 48 | //! Default constructor |
e1c659da | 49 | Standard_EXPORT OpenGl_PrimitiveArray (const OpenGl_GraphicDriver* theDriver, |
50 | const Graphic3d_TypeOfPrimitiveArray theType, | |
51 | const Handle(Graphic3d_IndexBuffer)& theIndices, | |
52 | const Handle(Graphic3d_Buffer)& theAttribs, | |
53 | const Handle(Graphic3d_BoundBuffer)& theBounds); | |
54 | ||
55 | //! Destructor | |
56 | Standard_EXPORT virtual ~OpenGl_PrimitiveArray(); | |
2166f0fa | 57 | |
2166f0fa | 58 | //! Render primitives to the window |
e1c659da | 59 | Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const; |
60 | ||
61 | //! Release OpenGL resources (VBOs) | |
62 | Standard_EXPORT virtual void Release (OpenGl_Context* theContext); | |
5e27df78 | 63 | |
e1c659da | 64 | //! Return true if VBOs initialization has been performed. |
65 | //! VBO initialization is performed during first Render() call. | |
66 | //! Notice that this flag does not indicate VBOs validity. | |
67 | Standard_Boolean IsInitialized() const { return myIsVboInit; } | |
2166f0fa | 68 | |
536d98e2 | 69 | //! Invalidate VBO content without destruction. |
70 | void Invalidate() const { myIsVboInit = Standard_False; } | |
71 | ||
871fa103 | 72 | //! @return primitive type (GL_LINES, GL_TRIANGLES and others) |
73 | GLint DrawMode() const { return myDrawMode; } | |
2166f0fa | 74 | |
871fa103 | 75 | //! @return indices array |
76 | const Handle(Graphic3d_IndexBuffer)& Indices() const { return myIndices; } | |
2166f0fa | 77 | |
871fa103 | 78 | //! @return attributes array |
79 | const Handle(Graphic3d_Buffer)& Attributes() const { return myAttribs; } | |
80 | ||
81 | //! @return bounds array | |
82 | const Handle(Graphic3d_BoundBuffer)& Bounds() const { return myBounds; } | |
83 | ||
8d3f219f | 84 | //! Returns unique ID of primitive array. |
85 | const Standard_Size GetUID() const { return myUID; } | |
86 | ||
a79f67f8 | 87 | //! Initialize indices, attributes and bounds with new data. |
e1c659da | 88 | Standard_EXPORT void InitBuffers (const Handle(OpenGl_Context)& theContext, |
89 | const Graphic3d_TypeOfPrimitiveArray theType, | |
90 | const Handle(Graphic3d_IndexBuffer)& theIndices, | |
91 | const Handle(Graphic3d_Buffer)& theAttribs, | |
92 | const Handle(Graphic3d_BoundBuffer)& theBounds); | |
a79f67f8 | 93 | |
0b0320e7 | 94 | protected: |
7d3e64ef | 95 | |
2166f0fa | 96 | //! VBO initialization procedures |
7d3e64ef | 97 | //! @param theCtx bound GL context |
98 | //! @param theToKeepData when true, myAttribs will not be nullified after VBO creation | |
0b0320e7 | 99 | Standard_EXPORT Standard_Boolean buildVBO (const Handle(OpenGl_Context)& theCtx, |
100 | const Standard_Boolean theToKeepData) const; | |
101 | ||
102 | Standard_EXPORT void clearMemoryGL (const Handle(OpenGl_Context)& theGlCtx) const; | |
103 | ||
104 | private: | |
105 | ||
106 | //! Initialize normal (OpenGL-provided) VBO | |
107 | Standard_Boolean initNormalVbo (const Handle(OpenGl_Context)& theCtx) const; | |
2166f0fa SK |
108 | |
109 | //! Main procedure to draw array | |
7d3e64ef | 110 | void drawArray (const Handle(OpenGl_Workspace)& theWorkspace, |
8625ef7e | 111 | const Graphic3d_Vec4* theFaceColors, |
112 | const Standard_Boolean theHasVertColor) const; | |
2166f0fa SK |
113 | |
114 | //! Auxiliary procedures | |
7d3e64ef | 115 | void drawEdges (const TEL_COLOUR* theEdgeColour, |
2166f0fa SK |
116 | const Handle(OpenGl_Workspace)& theWorkspace) const; |
117 | ||
7d3e64ef | 118 | void drawMarkers (const Handle(OpenGl_Workspace)& theWorkspace) const; |
a577aaab | 119 | |
a79f67f8 | 120 | //! Sets OpenGL draw mode according to the input type of primitive array. |
121 | //! If buffer of attributes is empty, draw mode is set to NONE to avoid invalid array rendering. | |
122 | //! @param theType type of primitive array. | |
123 | void setDrawMode (const Graphic3d_TypeOfPrimitiveArray theType); | |
124 | ||
5e27df78 | 125 | protected: |
126 | ||
7d3e64ef | 127 | mutable Handle(OpenGl_VertexBuffer) myVboIndices; |
871fa103 | 128 | mutable Handle(OpenGl_VertexBuffer) myVboAttribs; |
129 | ||
130 | mutable Handle(Graphic3d_IndexBuffer) myIndices; | |
131 | mutable Handle(Graphic3d_Buffer) myAttribs; | |
132 | mutable Handle(Graphic3d_BoundBuffer) myBounds; | |
133 | GLint myDrawMode; | |
134 | mutable Standard_Boolean myIsVboInit; | |
2166f0fa | 135 | |
8d3f219f | 136 | Standard_Size myUID; //!< Unique ID of primitive array. |
137 | ||
2166f0fa SK |
138 | public: |
139 | ||
1c35b92f | 140 | DEFINE_STANDARD_ALLOC |
2166f0fa SK |
141 | |
142 | }; | |
143 | ||
144 | #endif //OpenGl_PrimitiveArray_Header |