Browse Source

Removing IndexedMesh, part 3: moved last remaining setter to Mesh.

Now only the drawing mess needs to be merged.
pull/7/head
Vladimír Vondruš 13 years ago
parent
commit
a2a66803be
  1. 11
      src/IndexedMesh.cpp
  2. 50
      src/IndexedMesh.h
  3. 11
      src/Mesh.cpp
  4. 18
      src/Mesh.h

11
src/IndexedMesh.cpp

@ -21,7 +21,6 @@
namespace Magnum {
IndexedMesh::BindIndexBufferImplementation IndexedMesh::bindIndexBufferImplementation = &IndexedMesh::bindIndexBufferImplementationDefault;
IndexedMesh::BindIndexedImplementation IndexedMesh::bindIndexedImplementation = &IndexedMesh::bindIndexedImplementationDefault;
void IndexedMesh::draw() {
@ -45,7 +44,6 @@ void IndexedMesh::initializeContextBasedFunctionality(Context* context) {
if(context->isExtensionSupported<Extensions::GL::APPLE::vertex_array_object>()) {
Debug() << "IndexedMesh: using" << Extensions::GL::APPLE::vertex_array_object::string() << "features";
bindIndexBufferImplementation = &IndexedMesh::bindIndexBufferImplementationVAO;
bindIndexedImplementation = &IndexedMesh::bindIndexedImplementationVAO;
}
#else
@ -53,15 +51,6 @@ void IndexedMesh::initializeContextBasedFunctionality(Context* context) {
#endif
}
void IndexedMesh::bindIndexBufferImplementationDefault(Buffer* buffer) {
_indexBuffer = buffer;
}
void IndexedMesh::bindIndexBufferImplementationVAO(Buffer* buffer) {
bindVAO(vao);
buffer->bind(Buffer::Target::ElementArray);
}
void IndexedMesh::bindIndexedImplementationDefault() {
if(_indexBuffer) _indexBuffer->bind(Buffer::Target::ElementArray);
else Buffer::unbind(Buffer::Target::ElementArray);

50
src/IndexedMesh.h

@ -81,19 +81,6 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh {
*/
inline explicit IndexedMesh(Primitive primitive = Primitive::Triangles): Mesh(primitive) {}
/**
* @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)
*/
inline IndexedMesh* setIndexBuffer(Buffer* buffer) {
(this->*bindIndexBufferImplementation)(buffer);
return this;
}
/**
* @brief Draw the mesh
*
@ -107,48 +94,11 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh {
*/
void draw() override;
/* Overloads to remove WTF-factor from method chaining order */
#ifndef DOXYGEN_GENERATING_OUTPUT
inline IndexedMesh* setPrimitive(Primitive primitive) {
Mesh::setPrimitive(primitive);
return this;
}
inline IndexedMesh* setVertexCount(GLsizei vertexCount) {
Mesh::setVertexCount(vertexCount);
return this;
}
inline IndexedMesh* setIndexCount(GLsizei count) {
Mesh::setIndexCount(count);
return this;
}
inline IndexedMesh* setIndexType(IndexType type) {
Mesh::setIndexType(type);
return this;
}
template<class ...T> inline IndexedMesh* addVertexBuffer(Buffer* buffer, const T&... attributes) {
Mesh::addVertexBuffer(buffer, attributes...);
return this;
}
template<class ...T> inline IndexedMesh* addInterleavedVertexBuffer(Buffer* buffer, GLintptr offset, const T&... attributes) {
Mesh::addInterleavedVertexBuffer(buffer, offset, attributes...);
return this;
}
template<GLuint location, class T> inline IndexedMesh* addVertexBufferStride(Buffer* buffer, GLintptr offset, GLsizei stride, const AbstractShaderProgram::Attribute<location, T>& attribute) {
Mesh::addVertexBufferStride(buffer, offset, stride, attribute);
return this;
}
#endif
private:
static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context);
void MAGNUM_LOCAL bind();
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();
void MAGNUM_LOCAL bindIndexedImplementationVAO();

11
src/Mesh.cpp

@ -34,6 +34,7 @@ Mesh::AttributeIPointerImplementation Mesh::attributeIPointerImplementation = &M
Mesh::AttributeLPointerImplementation Mesh::attributeLPointerImplementation = &Mesh::attributePointerImplementationDefault;
#endif
#endif
Mesh::BindIndexBufferImplementation Mesh::bindIndexBufferImplementation = &Mesh::bindIndexBufferImplementationDefault;
Mesh::BindImplementation Mesh::bindImplementation = &Mesh::bindImplementationDefault;
Mesh::UnbindImplementation Mesh::unbindImplementation = &Mesh::unbindImplementationDefault;
@ -159,6 +160,7 @@ void Mesh::initializeContextBasedFunctionality(Context* context) {
attributeLPointerImplementation = &Mesh::attributePointerImplementationVAO;
}
bindIndexBufferImplementation = &Mesh::bindIndexBufferImplementationVAO;
bindImplementation = &Mesh::bindImplementationVAO;
unbindImplementation = &Mesh::unbindImplementationVAO;
}
@ -235,6 +237,15 @@ void Mesh::attributePointerImplementationDSA(const LongAttribute& attribute) {
#endif
#endif
void Mesh::bindIndexBufferImplementationDefault(Buffer* buffer) {
_indexBuffer = buffer;
}
void Mesh::bindIndexBufferImplementationVAO(Buffer* buffer) {
bindVAO(vao);
buffer->bind(Buffer::Target::ElementArray);
}
void Mesh::bindImplementationDefault() {
for(const Attribute& attribute: attributes)
vertexAttribPointer(attribute);

18
src/Mesh.h

@ -592,6 +592,19 @@ class MAGNUM_EXPORT Mesh {
return this;
}
/**
* @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)
*/
inline Mesh* setIndexBuffer(Buffer* buffer) {
(this->*bindIndexBufferImplementation)(buffer);
return this;
}
/**
* @brief Draw the mesh
*
@ -769,6 +782,11 @@ class MAGNUM_EXPORT Mesh {
#endif
#endif
typedef void(Mesh::*BindIndexBufferImplementation)(Buffer*);
void MAGNUM_LOCAL bindIndexBufferImplementationDefault(Buffer* buffer);
void MAGNUM_LOCAL bindIndexBufferImplementationVAO(Buffer* buffer);
static BindIndexBufferImplementation bindIndexBufferImplementation;
typedef void(Mesh::*BindImplementation)();
void MAGNUM_LOCAL bindImplementationDefault();
void MAGNUM_LOCAL bindImplementationVAO();

Loading…
Cancel
Save