0024113: Provide missing OpenGl_VertexBuffer::SubData() specializations
[occt.git] / src / OpenGl / OpenGl_VertexBuffer.hxx
CommitLineData
5e27df78 1// Created by: Kirill GAVRILOV
2// Copyright (c) 2012 OPEN CASCADE SAS
3//
4// The content of this file is subject to the Open CASCADE Technology Public
5// License Version 6.5 (the "License"). You may not use the content of this file
6// except in compliance with the License. Please obtain a copy of the License
7// at http://www.opencascade.org and read it completely before using this file.
8//
9// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11//
12// The Original Code and all software distributed under the License is
13// distributed on an "AS IS" basis, without warranty of any kind, and the
14// Initial Developer hereby disclaims all such warranties, including without
15// limitation, any warranties of merchantability, fitness for a particular
16// purpose or non-infringement. Please see the License for the specific terms
17// and conditions governing the rights and limitations under the License.
18
19#ifndef _OpenGl_VertexBuffer_H__
20#define _OpenGl_VertexBuffer_H__
21
22#include <OpenGl_GlCore20.hxx>
23#include <OpenGl_Resource.hxx>
24
25class Handle(OpenGl_Context);
26class OpenGl_Context;
27
28//! Vertex Buffer Object - is a general storage object for vertex attributes (position, normal, color).
29//! Notice that you should use OpenGl_IndexBuffer specialization for array of indices.
30class OpenGl_VertexBuffer : public OpenGl_Resource
31{
32
33public:
34
35 //! Helpful constants
36 static const GLuint NO_BUFFER = 0;
37
38public:
39
40 //! Create uninitialized VBO.
41 Standard_EXPORT OpenGl_VertexBuffer();
42
43 //! Destroy object.
44 Standard_EXPORT virtual ~OpenGl_VertexBuffer();
45
46 Standard_EXPORT virtual GLenum GetTarget() const;
47
48 //! @return true if current object was initialized
49 inline bool IsValid() const
50 {
51 return myBufferId != NO_BUFFER;
52 }
53
54 //! @return the number of components per generic vertex attribute.
55 inline GLuint GetComponentsNb() const
56 {
57 return myComponentsNb;
58 }
59
60 //! @return number of vertex attributes / number of vertices.
61 inline GLsizei GetElemsNb() const
62 {
63 return myElemsNb;
64 }
65
66 //! @return data type of each component in the array.
67 inline GLenum GetDataType() const
68 {
69 return myDataType;
70 }
71
72 //! Creates VBO name (id) if not yet generated.
73 //! Data should be initialized by another method.
74 Standard_EXPORT bool Create (const Handle(OpenGl_Context)& theGlCtx);
75
76 //! Destroy object - will release GPU memory if any.
77 Standard_EXPORT virtual void Release (const OpenGl_Context* theGlCtx);
78
79 //! Bind this VBO.
80 Standard_EXPORT void Bind (const Handle(OpenGl_Context)& theGlCtx) const;
81
82 //! Unbind this VBO.
83 Standard_EXPORT void Unbind (const Handle(OpenGl_Context)& theGlCtx) const;
84
85 //! Notice that VBO will be unbound after this call.
86 //! @param theComponentsNb - specifies the number of components per generic vertex attribute; must be 1, 2, 3, or 4;
87 //! @param theElemsNb - elements count;
88 //! @param theData - pointer to GLfloat data (vertices/normals etc.).
89 Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theGlCtx,
90 const GLuint theComponentsNb,
91 const GLsizei theElemsNb,
92 const GLfloat* theData);
93
94 //! Notice that VBO will be unbound after this call.
95 //! @param theComponentsNb - specifies the number of components per generic vertex attribute; must be 1, 2, 3, or 4;
96 //! @param theElemsNb - elements count;
97 //! @param theData - pointer to GLuint data (indices etc.).
98 Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theGlCtx,
99 const GLuint theComponentsNb,
100 const GLsizei theElemsNb,
101 const GLuint* theData);
102
103 //! Notice that VBO will be unbound after this call.
104 //! @param theComponentsNb - specifies the number of components per generic vertex attribute; must be 1, 2, 3, or 4;
105 //! @param theElemsNb - elements count;
106 //! @param theData - pointer to GLubyte data (indices/colors etc.).
107 Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theGlCtx,
108 const GLuint theComponentsNb,
109 const GLsizei theElemsNb,
110 const GLubyte* theData);
111
112 //! Notice that VBO will be unbound after this call.
113 //! Function replaces portion of data within this VBO using glBufferSubData().
114 //! The VBO should be initialized before call.
115 //! @param theElemFrom - element id from which replace buffer data (>=0);
99d99a6d 116 //! @param theElemsNb - elements count (theElemFrom + theElemsNb <= GetElemsNb());
5e27df78 117 //! @param theData - pointer to GLfloat data.
118 Standard_EXPORT bool SubData (const Handle(OpenGl_Context)& theGlCtx,
119 const GLsizei theElemFrom,
120 const GLsizei theElemsNb,
121 const GLfloat* theData);
122
99d99a6d 123 //! Notice that VBO will be unbound after this call.
124 //! Function replaces portion of data within this VBO using glBufferSubData().
125 //! The VBO should be initialized before call.
126 //! @param theElemFrom element id from which replace buffer data (>=0);
127 //! @param theElemsNb elements count (theElemFrom + theElemsNb <= GetElemsNb());
128 //! @param theData pointer to GLuint data.
129 Standard_EXPORT bool SubData (const Handle(OpenGl_Context)& theGlCtx,
130 const GLsizei theElemFrom,
131 const GLsizei theElemsNb,
132 const GLuint* theData);
133
134 //! Notice that VBO will be unbound after this call.
135 //! Function replaces portion of data within this VBO using glBufferSubData().
136 //! The VBO should be initialized before call.
137 //! @param theElemFrom element id from which replace buffer data (>=0);
138 //! @param theElemsNb elements count (theElemFrom + theElemsNb <= GetElemsNb());
139 //! @param theData pointer to GLubyte data.
140 Standard_EXPORT bool SubData (const Handle(OpenGl_Context)& theGlCtx,
141 const GLsizei theElemFrom,
142 const GLsizei theElemsNb,
143 const GLubyte* theData);
144
5e27df78 145 //! Bind this VBO to active GLSL program.
146 Standard_EXPORT void BindVertexAttrib (const Handle(OpenGl_Context)& theGlCtx,
147 const GLuint theAttribLoc) const;
148
149 //! Unbind any VBO from active GLSL program.
150 Standard_EXPORT void UnbindVertexAttrib (const Handle(OpenGl_Context)& theGlCtx,
151 const GLuint theAttribLoc) const;
152
153 //! Bind this VBO as fixed pipeline attribute.
154 //! @param theGlCtx - handle to bound GL context;
155 //! @param theMode - array mode (GL_VERTEX_ARRAY, GL_NORMAL_ARRAY, GL_COLOR_ARRAY, GL_INDEX_ARRAY, GL_TEXTURE_COORD_ARRAY).
156 Standard_EXPORT void BindFixed (const Handle(OpenGl_Context)& theGlCtx,
157 const GLenum theMode) const;
158
159 //! Unbind this VBO as fixed pipeline attribute.
160 //! @param theGlCtx - handle to bound GL context;
161 //! @param theMode - array mode.
162 Standard_EXPORT void UnbindFixed (const Handle(OpenGl_Context)& theGlCtx,
163 const GLenum theMode) const;
164
165protected:
166
167 GLuint myBufferId; //!< VBO name (index)
168 GLuint myComponentsNb; //!< Number of components per generic vertex attribute, must be 1, 2, 3, or 4
169 GLsizei myElemsNb; //!< Number of vertex attributes / number of vertices
170 GLenum myDataType; //!< Data type (GL_FLOAT, GL_UNSIGNED_INT, GL_UNSIGNED_BYTE etc.)
171
172public:
173
174 DEFINE_STANDARD_RTTI(OpenGl_VertexBuffer) // Type definition
175
176};
177
178DEFINE_STANDARD_HANDLE(OpenGl_VertexBuffer, OpenGl_Resource)
179
180#endif // _OpenGl_VertexBuffer_H__