26 #include "glfVertexBuffer.hh"
27 #include "glfException.hh"
43 glDeleteBuffers(1, &bufferID_);
67 numVertices_ = numVertices;
72 if (GLEW_VERSION_1_5) {
73 useBuffer_ =
true & useBuffer;
81 glGenBuffers(1, &bufferID_);
83 glBindBuffer(GL_ARRAY_BUFFER, bufferID_);
84 glBufferData(GL_ARRAY_BUFFER,
86 data, GL_STATIC_DRAW);
96 GLF_THROW_ON_OPENGL_ERROR;
101 BIASASSERT(!mapped_);
105 BIASASSERT(bufferID_ != 0);
106 glBindBuffer(GL_ARRAY_BUFFER, bufferID_);
107 return glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
119 BIASASSERT(bufferID_ != 0);
120 glBindBuffer(GL_ARRAY_BUFFER, bufferID_);
121 GLboolean result = glUnmapBuffer(GL_ARRAY_BUFFER);
122 if (result == GL_FALSE) {
123 GLF_THROW_EXCEPTION(
"Vertex buffer was corrupted while mapped");
136 BIASASSERT(bufferID_ != 0);
137 glBindBuffer(GL_ARRAY_BUFFER, bufferID_);
140 glBindBuffer(GL_ARRAY_BUFFER, 0);
141 format_.
Bind(array_);
int GetNumVertices() const
Returns the number of vertices in the vertex buffer.
A vertex buffer contains an array of vertices that can be used for rendering.
void Unmap()
Unmaps the vertex buffer.
void * Map()
Maps the vertex buffer to system memory, so it can be modified after creation.
void Create(int numVertices, const glfVertexFormat &format, const void *data=NULL, bool useBufferIfPossible=true)
Creates the vertex buffer for the given number of vertices and vertex format.
void Bind() const
Binds the vertex buffer in OpenGL.