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