26 #include "glfElementBuffer.hh"
27 #include "glfException.hh"
43 glDeleteBuffers(1, &bufferID_);
60 GLenum mode,
const void* indices)
66 numIndices_ = numIndices;
69 case GL_UNSIGNED_BYTE:
70 typeSize_ =
sizeof(GLubyte);
72 case GL_UNSIGNED_SHORT:
73 typeSize_ =
sizeof(GLushort);
76 typeSize_ =
sizeof(GLuint);
83 if (GLEW_VERSION_1_5) {
92 glGenBuffers(1, &bufferID_);
94 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferID_);
95 glBufferData(GL_ELEMENT_ARRAY_BUFFER, numIndices * typeSize_,
96 indices, GL_STATIC_DRAW);
101 array_.resize(numIndices * typeSize_);
102 memcpy(&array_[0], indices, numIndices * typeSize_);
106 GLF_THROW_ON_OPENGL_ERROR;
111 BIASASSERT(!mapped_);
115 BIASASSERT(bufferID_ != 0);
116 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferID_);
117 return glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);
129 BIASASSERT(bufferID_ != 0);
130 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferID_);
131 GLboolean result = glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
132 if (result == GL_FALSE) {
133 GLF_THROW_EXCEPTION(
"Element buffer was corrupted while mapped");
140 BIASASSERT(!mapped_);
141 BIASASSERT(first >= 0 && first < numIndices_);
142 BIASASSERT(count == -1 || (count >= 0 && (first+count) <= numIndices_));
149 const void* indices = NULL;
151 BIASASSERT(bufferID_ != 0);
152 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferID_);
154 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
155 indices = &array_[0];
158 indices = (GLubyte*)indices + (first*typeSize_);
160 glDrawElements(mode_, count, type_, indices);
162 GLF_THROW_ON_OPENGL_ERROR;
An element buffer contains vertex indices that form primitives.
void Unmap()
Unmaps the element buffer.
void * Map()
Maps the element buffer to system memory, so it can be modified after creation.
void Create(int numIndices, GLenum type, GLenum mode, const void *indices)
Creates the element buffer for the given number of indices.
void Draw(int first=0, int count=-1) const
Draw elements from the buffer.