Commit 7a43dc85 authored by Robert Menzel's avatar Robert Menzel
Browse files

added some comments, clean up, less redundant code

parent eb5193ef
...@@ -6,6 +6,24 @@ ...@@ -6,6 +6,24 @@
#ifndef ACGL_OPENGL_OBJECTS_ARRAYBUFFER_HH #ifndef ACGL_OPENGL_OBJECTS_ARRAYBUFFER_HH
#define ACGL_OPENGL_OBJECTS_ARRAYBUFFER_HH #define ACGL_OPENGL_OBJECTS_ARRAYBUFFER_HH
/*
* An ArrayBuffer holds an array of per-vertex data. In its simplest form an
* array of one attribute, for example the vertex position or texture-coordinate.
* An ArrayBuffer however can also hold multiple attributes in an interleaved
* way.
*
* An ArrayBuffer can be drawn directly or indexed in combination with an
* ElementArrayBuffer.
*
* The combination of (multiple) attributes of (multiple) ArrayBuffers
* and one (optional) ElementArrayBuffer is a VertexBufferObject or VertexArrayObject.
*
* Note: In some documents ArrayBuffers (and sometimes ElementArrayBuffers) are
* called VertexBufferObjects, VBOs. The original extension that introduced
* these two new buffer types was called ARB_vertex_buffer_object but the buffers
* itself are called ArrayBuffer and ElementArrayBuffer.
*/
#include <ACGL/ACGL.hh> #include <ACGL/ACGL.hh>
#include <ACGL/Base/Macros.hh> #include <ACGL/Base/Macros.hh>
...@@ -153,44 +171,33 @@ public: ...@@ -153,44 +171,33 @@ public:
setAttributePointer(index, _indexInShader); setAttributePointer(index, _indexInShader);
return true; return true;
} }
//! Set data for this buffer //! Set data for this buffer and change its size, usage and mode
//! Note: The function is not const, because it changes the corresponding GPU data inline void setData(
inline void setData(const GLvoid* _pData) const GLvoid* _pData,
GLsizei _elements,
GLenum _usage,
GLenum _mode)
{ {
glBindBuffer(GL_ARRAY_BUFFER, mContext); mUsage = _usage;
glBufferData( mMode = _mode;
GL_ARRAY_BUFFER, setData( _pData, _elements );
mStride * mElements,
_pData,
mUsage);
} }
//! Set data for this buffer and change its size //! Set data for this buffer and change its size
inline void setData( inline void setData(
const GLvoid* _pData, const GLvoid* _pData,
GLsizei _elements) GLsizei _elements)
{ {
mElements = _elements; mElements = _elements;
glBindBuffer(GL_ARRAY_BUFFER, mContext); setData( _pData );
glBufferData(
GL_ARRAY_BUFFER,
mStride * mElements,
_pData,
mUsage);
} }
//! Set data for this buffer and change its size //! Set data for this buffer
inline void setData( //! Note: The function is not const, because it changes the corresponding GPU data
const GLvoid* _pData, inline void setData(const GLvoid* _pData)
GLsizei _elements,
GLenum _usage,
GLenum _mode)
{ {
mElements = _elements;
mUsage = _usage;
mMode = _mode;
glBindBuffer(GL_ARRAY_BUFFER, mContext); glBindBuffer(GL_ARRAY_BUFFER, mContext);
glBufferData( glBufferData(
GL_ARRAY_BUFFER, GL_ARRAY_BUFFER,
......
...@@ -6,6 +6,20 @@ ...@@ -6,6 +6,20 @@
#ifndef ACGL_OPENGL_OBJECTS_ELEMENTBUFFERDATA_HH #ifndef ACGL_OPENGL_OBJECTS_ELEMENTBUFFERDATA_HH
#define ACGL_OPENGL_OBJECTS_ELEMENTBUFFERDATA_HH #define ACGL_OPENGL_OBJECTS_ELEMENTBUFFERDATA_HH
/*
* An ElementArrayBuffer is an index into ArrayBuffers and defines which
* elements of that array should be drawn in which order.
*
* The combination of (multiple) attributes of (multiple) ArrayBuffers
* and one (optional) ElementArrayBuffer is a VertexBufferObject or VertexArrayObject.
*
* Note: In some documents ElementArrayBuffer are called VertexBufferObjects, VBOs
* or IndexBufferObjects (IBOs). But ArrayBuffers can also be called VBOs...
* The original extension that introduced these two new buffer types was called
* ARB_vertex_buffer_object but the buffers itself are called ArrayBuffer and
* ElementArrayBuffer.
*/
#include <ACGL/ACGL.hh> #include <ACGL/ACGL.hh>
#include <ACGL/Base/Macros.hh> #include <ACGL/Base/Macros.hh>
...@@ -27,8 +41,8 @@ class ElementArrayBuffer ...@@ -27,8 +41,8 @@ class ElementArrayBuffer
public: public:
ElementArrayBuffer( ElementArrayBuffer(
GLenum _usage = GL_STATIC_DRAW, GLenum _usage = GL_STATIC_DRAW,
GLenum _mode = GL_TRIANGLES, GLenum _mode = GL_TRIANGLES,
GLenum _type = GL_UNSIGNED_INT) GLenum _type = GL_UNSIGNED_INT)
: mContext(0), : mContext(0),
mUsage(_usage), mUsage(_usage),
mMode(_mode), mMode(_mode),
...@@ -96,30 +110,26 @@ public: ...@@ -96,30 +110,26 @@ public:
} }
//! Set data for this buffer //! Set data for this buffer
//! Note: The function is not const, because it changes the corresponding GPU data
inline void setData( inline void setData(
const GLvoid* _pData) const GLvoid* _pData,
GLsizei _elements)
{ {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mContext); mElements = _elements;
glBufferData( setData( _pData );
GL_ELEMENT_ARRAY_BUFFER,
mElements * mSizeOfType,
_pData,
mUsage);
} }
//! Set data for this buffer //! Set data for this buffer
//! Note: The function is not const, because it changes the corresponding GPU data
inline void setData( inline void setData(
const GLvoid* _pData, const GLvoid* _pData)
GLsizei _elements)
{ {
mElements = _elements;
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mContext); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mContext);
glBufferData( glBufferData(
GL_ELEMENT_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER,
mElements * mSizeOfType, mElements * mSizeOfType,
_pData, _pData,
mUsage); mUsage);
openGLRareError();
} }
// =================================================================================================== \/ // =================================================================================================== \/
......
...@@ -6,6 +6,14 @@ ...@@ -6,6 +6,14 @@
#ifndef ACGL_OPENGL_OBJECTS_VERTEXBUFFEROBJECT_HH #ifndef ACGL_OPENGL_OBJECTS_VERTEXBUFFEROBJECT_HH
#define ACGL_OPENGL_OBJECTS_VERTEXBUFFEROBJECT_HH #define ACGL_OPENGL_OBJECTS_VERTEXBUFFEROBJECT_HH
/*
* A VertexBufferObject combines the two tightly related buffers from the
* ARB_vertex_buffer_object extension.
*
* M Attributes from N ArrayBuffer and one (optional) ElementArrayBuffer form
* one VertexBufferObject.
*/
#include <ACGL/ACGL.hh> #include <ACGL/ACGL.hh>
#include <ACGL/Base/Macros.hh> #include <ACGL/Base/Macros.hh>
...@@ -124,7 +132,7 @@ public: ...@@ -124,7 +132,7 @@ public:
enable(); enable();
draw(); draw();
disable(); disable();
}; }
void drawElements(void) const void drawElements(void) const
{ {
...@@ -160,5 +168,4 @@ ACGL_SHARED_TYPEDEF(VertexBufferObject) ...@@ -160,5 +168,4 @@ ACGL_SHARED_TYPEDEF(VertexBufferObject)
} // OpenGL } // OpenGL
} // ACGL } // ACGL
#endif // ACGL_OPENGL_OBJECTS_VERTEXBUFFEROBJECT_HH #endif // ACGL_OPENGL_OBJECTS_VERTEXBUFFEROBJECT_HH
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment