0025990: Visualization - result of compilation depends on the order of included OCCT...
[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
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 30class OpenGl_GraphicDriver;
7d3e64ef 31class Handle(OpenGl_ShaderProgram);
8d3f219f 32
7d3e64ef 33//! Class for rendering of arbitrary primitive array.
2166f0fa
SK
34class OpenGl_PrimitiveArray : public OpenGl_Element
35{
36public:
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
SK
44
45 //! Default constructor
8d3f219f 46 OpenGl_PrimitiveArray (const OpenGl_GraphicDriver* theDriver,
47 const Graphic3d_TypeOfPrimitiveArray theType,
871fa103 48 const Handle(Graphic3d_IndexBuffer)& theIndices,
49 const Handle(Graphic3d_Buffer)& theAttribs,
50 const Handle(Graphic3d_BoundBuffer)& theBounds);
2166f0fa 51
2166f0fa 52 //! Render primitives to the window
5e27df78 53 virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
54
10b9c7df 55 virtual void Release (OpenGl_Context* theContext);
2166f0fa 56
871fa103 57 //! @return primitive type (GL_LINES, GL_TRIANGLES and others)
58 GLint DrawMode() const { return myDrawMode; }
2166f0fa 59
871fa103 60 //! @return indices array
61 const Handle(Graphic3d_IndexBuffer)& Indices() const { return myIndices; }
2166f0fa 62
871fa103 63 //! @return attributes array
64 const Handle(Graphic3d_Buffer)& Attributes() const { return myAttribs; }
65
66 //! @return bounds array
67 const Handle(Graphic3d_BoundBuffer)& Bounds() const { return myBounds; }
68
8d3f219f 69 //! Returns unique ID of primitive array.
70 const Standard_Size GetUID() const { return myUID; }
71
a79f67f8 72 //! Initialize indices, attributes and bounds with new data.
73 void InitBuffers (const Handle(OpenGl_Context)& theContext,
74 const Graphic3d_TypeOfPrimitiveArray theType,
75 const Handle(Graphic3d_IndexBuffer)& theIndices,
76 const Handle(Graphic3d_Buffer)& theAttribs,
77 const Handle(Graphic3d_BoundBuffer)& theBounds);
78
0b0320e7 79protected:
7d3e64ef 80
2166f0fa 81 //! VBO initialization procedures
7d3e64ef 82 //! @param theCtx bound GL context
83 //! @param theToKeepData when true, myAttribs will not be nullified after VBO creation
0b0320e7 84 Standard_EXPORT Standard_Boolean buildVBO (const Handle(OpenGl_Context)& theCtx,
85 const Standard_Boolean theToKeepData) const;
86
87 Standard_EXPORT void clearMemoryGL (const Handle(OpenGl_Context)& theGlCtx) const;
88
89private:
90
91 //! Initialize normal (OpenGL-provided) VBO
92 Standard_Boolean initNormalVbo (const Handle(OpenGl_Context)& theCtx) const;
2166f0fa
SK
93
94 //! Main procedure to draw array
7d3e64ef 95 void drawArray (const Handle(OpenGl_Workspace)& theWorkspace,
8625ef7e 96 const Graphic3d_Vec4* theFaceColors,
97 const Standard_Boolean theHasVertColor) const;
2166f0fa
SK
98
99 //! Auxiliary procedures
7d3e64ef 100 void drawEdges (const TEL_COLOUR* theEdgeColour,
2166f0fa
SK
101 const Handle(OpenGl_Workspace)& theWorkspace) const;
102
7d3e64ef 103 void drawMarkers (const Handle(OpenGl_Workspace)& theWorkspace) const;
a577aaab 104
a79f67f8 105 //! Sets OpenGL draw mode according to the input type of primitive array.
106 //! If buffer of attributes is empty, draw mode is set to NONE to avoid invalid array rendering.
107 //! @param theType type of primitive array.
108 void setDrawMode (const Graphic3d_TypeOfPrimitiveArray theType);
109
2166f0fa
SK
110protected:
111
5e27df78 112 //! Destructor
113 virtual ~OpenGl_PrimitiveArray();
114
115protected:
116
7d3e64ef 117 mutable Handle(OpenGl_VertexBuffer) myVboIndices;
871fa103 118 mutable Handle(OpenGl_VertexBuffer) myVboAttribs;
119
120 mutable Handle(Graphic3d_IndexBuffer) myIndices;
121 mutable Handle(Graphic3d_Buffer) myAttribs;
122 mutable Handle(Graphic3d_BoundBuffer) myBounds;
123 GLint myDrawMode;
124 mutable Standard_Boolean myIsVboInit;
2166f0fa 125
8d3f219f 126 Standard_Size myUID; //!< Unique ID of primitive array.
127
2166f0fa
SK
128public:
129
1c35b92f 130 DEFINE_STANDARD_ALLOC
2166f0fa
SK
131
132};
133
134#endif //OpenGl_PrimitiveArray_Header