Browse Source

Saving index buffer pointer only if not using VAOs.

With VAOs it is not used anyway, might remove the member variable for
platforms with mandatory VAO support altogether.
pull/7/head
Vladimír Vondruš 13 years ago
parent
commit
9449e330d2
  1. 16
      src/IndexedMesh.cpp
  2. 14
      src/IndexedMesh.h

16
src/IndexedMesh.cpp

@ -24,12 +24,6 @@ namespace Magnum {
IndexedMesh::BindIndexBufferImplementation IndexedMesh::bindIndexBufferImplementation = &IndexedMesh::bindIndexBufferImplementationDefault;
IndexedMesh::BindIndexedImplementation IndexedMesh::bindIndexedImplementation = &IndexedMesh::bindIndexedImplementationDefault;
IndexedMesh* IndexedMesh::setIndexBuffer(Buffer* buffer) {
_indexBuffer = buffer;
(this->*bindIndexBufferImplementation)();
return this;
}
void IndexedMesh::draw() {
if(!_indexCount) return;
@ -41,8 +35,6 @@ void IndexedMesh::draw() {
}
void IndexedMesh::bind() {
CORRADE_ASSERT(!_indexCount || _indexBuffer, "IndexedMesh: index buffer must be added if index count is non-zero", );
Mesh::bind();
(this->*bindIndexedImplementation)();
}
@ -61,11 +53,13 @@ void IndexedMesh::initializeContextBasedFunctionality(Context* context) {
#endif
}
void IndexedMesh::bindIndexBufferImplementationDefault() {}
void IndexedMesh::bindIndexBufferImplementationDefault(Buffer* buffer) {
_indexBuffer = buffer;
}
void IndexedMesh::bindIndexBufferImplementationVAO() {
void IndexedMesh::bindIndexBufferImplementationVAO(Buffer* buffer) {
bindVAO(vao);
_indexBuffer->bind(Buffer::Target::ElementArray);
buffer->bind(Buffer::Target::ElementArray);
}
void IndexedMesh::bindIndexedImplementationDefault() {

14
src/IndexedMesh.h

@ -83,12 +83,16 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh {
/**
* @brief Set index buffer
* @return Pointer to self (for method chaining)
*
* @see setIndexCount(), setIndexType(), MeshTools::compressIndices(),
* @fn_gl{BindVertexArray}, @fn_gl{BindBuffer} (if
* @extension{APPLE,vertex_array_object} is available)
*/
IndexedMesh* setIndexBuffer(Buffer* buffer);
inline IndexedMesh* setIndexBuffer(Buffer* buffer) {
(this->*bindIndexBufferImplementation)(buffer);
return this;
}
/**
* @brief Draw the mesh
@ -140,10 +144,10 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh {
void MAGNUM_LOCAL bind();
typedef void(IndexedMesh::*BindIndexBufferImplementation)();
void MAGNUM_LOCAL bindIndexBufferImplementationDefault();
void MAGNUM_LOCAL bindIndexBufferImplementationVAO();
static MAGNUM_LOCAL BindIndexBufferImplementation bindIndexBufferImplementation;
typedef void(IndexedMesh::*BindIndexBufferImplementation)(Buffer*);
void MAGNUM_LOCAL bindIndexBufferImplementationDefault(Buffer* buffer);
void MAGNUM_LOCAL bindIndexBufferImplementationVAO(Buffer* buffer);
static BindIndexBufferImplementation bindIndexBufferImplementation;
typedef void(IndexedMesh::*BindIndexedImplementation)();
void MAGNUM_LOCAL bindIndexedImplementationDefault();

Loading…
Cancel
Save