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 | |
5bd54bef | 16 | #ifndef OpenGl_PrimitiveArray_HeaderFile |
17 | #define OpenGl_PrimitiveArray_HeaderFile | |
2166f0fa | 18 | |
871fa103 | 19 | #include <Graphic3d_TypeOfPrimitiveArray.hxx> |
20 | #include <Graphic3d_IndexBuffer.hxx> | |
21 | #include <Graphic3d_BoundBuffer.hxx> | |
2166f0fa SK |
22 | |
23 | #include <OpenGl_Element.hxx> | |
24 | ||
1220d98e | 25 | class OpenGl_IndexBuffer; |
26 | class OpenGl_VertexBuffer; | |
8d3f219f | 27 | class OpenGl_GraphicDriver; |
28 | ||
7d3e64ef | 29 | //! Class for rendering of arbitrary primitive array. |
2166f0fa SK |
30 | class OpenGl_PrimitiveArray : public OpenGl_Element |
31 | { | |
32 | public: | |
8e0a2b19 | 33 | //! OpenGL does not provide a constant for "none" draw mode. |
34 | //! So we define our own one that does not conflict with GL constants and utilizes common GL invalid value. | |
1d03e66d | 35 | enum |
36 | { | |
37 | DRAW_MODE_NONE = -1 | |
38 | }; | |
2166f0fa | 39 | |
e1c659da | 40 | //! Empty constructor |
41 | Standard_EXPORT OpenGl_PrimitiveArray (const OpenGl_GraphicDriver* theDriver); | |
42 | ||
2166f0fa | 43 | //! Default constructor |
e1c659da | 44 | Standard_EXPORT OpenGl_PrimitiveArray (const OpenGl_GraphicDriver* theDriver, |
45 | const Graphic3d_TypeOfPrimitiveArray theType, | |
46 | const Handle(Graphic3d_IndexBuffer)& theIndices, | |
47 | const Handle(Graphic3d_Buffer)& theAttribs, | |
48 | const Handle(Graphic3d_BoundBuffer)& theBounds); | |
49 | ||
50 | //! Destructor | |
51 | Standard_EXPORT virtual ~OpenGl_PrimitiveArray(); | |
2166f0fa | 52 | |
2166f0fa | 53 | //! Render primitives to the window |
64c6d8df | 54 | Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const Standard_OVERRIDE; |
e1c659da | 55 | |
56 | //! Release OpenGL resources (VBOs) | |
64c6d8df | 57 | Standard_EXPORT virtual void Release (OpenGl_Context* theContext) Standard_OVERRIDE; |
5e27df78 | 58 | |
3d60d73f | 59 | //! Returns estimated GPU memory usage for holding data without considering overheads and allocation alignment rules. |
60 | Standard_EXPORT virtual Standard_Size EstimatedDataSize() const Standard_OVERRIDE; | |
61 | ||
b9f43ad1 | 62 | //! Increment draw calls statistics. |
63 | Standard_EXPORT virtual void UpdateDrawStats (Graphic3d_FrameStatsDataTmp& theStats, | |
64 | bool theIsDetailed) const Standard_OVERRIDE; | |
65 | ||
e1c659da | 66 | //! Return true if VBOs initialization has been performed. |
67 | //! VBO initialization is performed during first Render() call. | |
68 | //! Notice that this flag does not indicate VBOs validity. | |
69 | Standard_Boolean IsInitialized() const { return myIsVboInit; } | |
2166f0fa | 70 | |
536d98e2 | 71 | //! Invalidate VBO content without destruction. |
72 | void Invalidate() const { myIsVboInit = Standard_False; } | |
73 | ||
871fa103 | 74 | //! @return primitive type (GL_LINES, GL_TRIANGLES and others) |
1220d98e | 75 | Standard_Integer DrawMode() const { return myDrawMode; } |
2166f0fa | 76 | |
8e0a2b19 | 77 | //! Return TRUE if primitive type generates shaded triangulation. |
64c6d8df | 78 | virtual Standard_Boolean IsFillDrawMode() const Standard_OVERRIDE { return myIsFillType; } |
8e0a2b19 | 79 | |
871fa103 | 80 | //! @return indices array |
81 | const Handle(Graphic3d_IndexBuffer)& Indices() const { return myIndices; } | |
2166f0fa | 82 | |
871fa103 | 83 | //! @return attributes array |
84 | const Handle(Graphic3d_Buffer)& Attributes() const { return myAttribs; } | |
85 | ||
86 | //! @return bounds array | |
87 | const Handle(Graphic3d_BoundBuffer)& Bounds() const { return myBounds; } | |
88 | ||
8d3f219f | 89 | //! Returns unique ID of primitive array. |
487bf1ce | 90 | Standard_Size GetUID() const { return myUID; } |
8d3f219f | 91 | |
a79f67f8 | 92 | //! Initialize indices, attributes and bounds with new data. |
e1c659da | 93 | Standard_EXPORT void InitBuffers (const Handle(OpenGl_Context)& theContext, |
94 | const Graphic3d_TypeOfPrimitiveArray theType, | |
95 | const Handle(Graphic3d_IndexBuffer)& theIndices, | |
96 | const Handle(Graphic3d_Buffer)& theAttribs, | |
97 | const Handle(Graphic3d_BoundBuffer)& theBounds); | |
a79f67f8 | 98 | |
15669413 | 99 | public: |
100 | ||
101 | //! Returns index VBO. | |
1220d98e | 102 | const Handle(OpenGl_IndexBuffer)& IndexVbo() const { return myVboIndices; } |
15669413 | 103 | |
104 | //! Returns attributes VBO. | |
105 | const Handle(OpenGl_VertexBuffer)& AttributesVbo() const { return myVboAttribs; } | |
106 | ||
bc73b006 | 107 | //! Dumps the content of me into the stream |
108 | Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE; | |
109 | ||
0b0320e7 | 110 | protected: |
7d3e64ef | 111 | |
2166f0fa | 112 | //! VBO initialization procedures |
7d3e64ef | 113 | //! @param theCtx bound GL context |
114 | //! @param theToKeepData when true, myAttribs will not be nullified after VBO creation | |
0b0320e7 | 115 | Standard_EXPORT Standard_Boolean buildVBO (const Handle(OpenGl_Context)& theCtx, |
116 | const Standard_Boolean theToKeepData) const; | |
117 | ||
da87ddc3 | 118 | //! Patch VBO sub-date within invalidated range. |
119 | Standard_EXPORT void updateVBO (const Handle(OpenGl_Context)& theCtx) const; | |
120 | ||
34253146 | 121 | //! Release GL memory. |
0b0320e7 | 122 | Standard_EXPORT void clearMemoryGL (const Handle(OpenGl_Context)& theGlCtx) const; |
123 | ||
124 | private: | |
125 | ||
126 | //! Initialize normal (OpenGL-provided) VBO | |
127 | Standard_Boolean initNormalVbo (const Handle(OpenGl_Context)& theCtx) const; | |
2166f0fa SK |
128 | |
129 | //! Main procedure to draw array | |
7d3e64ef | 130 | void drawArray (const Handle(OpenGl_Workspace)& theWorkspace, |
8625ef7e | 131 | const Graphic3d_Vec4* theFaceColors, |
132 | const Standard_Boolean theHasVertColor) const; | |
2166f0fa SK |
133 | |
134 | //! Auxiliary procedures | |
bf5f0ca2 | 135 | void drawEdges (const Handle(OpenGl_Workspace)& theWorkspace) const; |
2166f0fa | 136 | |
7d3e64ef | 137 | void drawMarkers (const Handle(OpenGl_Workspace)& theWorkspace) const; |
a577aaab | 138 | |
a79f67f8 | 139 | //! Sets OpenGL draw mode according to the input type of primitive array. |
140 | //! If buffer of attributes is empty, draw mode is set to NONE to avoid invalid array rendering. | |
141 | //! @param theType type of primitive array. | |
142 | void setDrawMode (const Graphic3d_TypeOfPrimitiveArray theType); | |
143 | ||
e99a2f7c | 144 | //! Rebuilds the array of vertex attributes so that it can be drawn without indices. |
145 | Standard_Boolean processIndices (const Handle(OpenGl_Context)& theContext) const; | |
146 | ||
5e27df78 | 147 | protected: |
148 | ||
1220d98e | 149 | mutable Handle(OpenGl_IndexBuffer) myVboIndices; |
871fa103 | 150 | mutable Handle(OpenGl_VertexBuffer) myVboAttribs; |
151 | ||
152 | mutable Handle(Graphic3d_IndexBuffer) myIndices; | |
153 | mutable Handle(Graphic3d_Buffer) myAttribs; | |
154 | mutable Handle(Graphic3d_BoundBuffer) myBounds; | |
1220d98e | 155 | short myDrawMode; |
8e0a2b19 | 156 | mutable Standard_Boolean myIsFillType; |
871fa103 | 157 | mutable Standard_Boolean myIsVboInit; |
2166f0fa | 158 | |
8d3f219f | 159 | Standard_Size myUID; //!< Unique ID of primitive array. |
160 | ||
2166f0fa SK |
161 | public: |
162 | ||
1c35b92f | 163 | DEFINE_STANDARD_ALLOC |
2166f0fa SK |
164 | |
165 | }; | |
166 | ||
167 | #endif //OpenGl_PrimitiveArray_Header |