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