Browse Source

Removing IndexedMesh, part 2: moved all member variables to Mesh.

As Mesh constructor is not exactly trivial, moved it to source, allowing
to hide another function pointer variable.
pull/7/head
Vladimír Vondruš 13 years ago
parent
commit
b20c83f258
  1. 44
      src/IndexedMesh.h
  2. 9
      src/Mesh.cpp
  3. 39
      src/Mesh.h

44
src/IndexedMesh.h

@ -79,7 +79,7 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh {
* Creates indexed mesh with zero vertex count, zero index count and
* no vertex or index buffers.
*/
inline explicit IndexedMesh(Primitive primitive = Primitive::Triangles): Mesh(primitive), _indexBuffer(nullptr), _indexCount(0), _indexType(IndexType::UnsignedInt) {}
inline explicit IndexedMesh(Primitive primitive = Primitive::Triangles): Mesh(primitive) {}
/**
* @brief Set index buffer
@ -90,36 +90,6 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh {
*/
IndexedMesh* setIndexBuffer(Buffer* buffer);
/** @brief Index count */
inline GLsizei indexCount() const { return _indexCount; }
/**
* @brief Set index count
* @return Pointer to self (for method chaining)
*
* Default is zero.
* @see setIndexBuffer(), setIndexType(), MeshTools::compressIndices()
*/
inline IndexedMesh* setIndexCount(GLsizei count) {
_indexCount = count;
return this;
}
/** @brief Index type */
inline IndexType indexType() const { return _indexType; }
/**
* @brief Set index type
* @return Pointer to self (for method chaining)
*
* Default is @ref IndexType "IndexType::UnsignedInt".
* @see setIndexBuffer(), setIndexCount(), MeshTools::compressIndices()
*/
inline IndexedMesh* setIndexType(IndexType type) {
_indexType = type;
return this;
}
/**
* @brief Draw the mesh
*
@ -143,6 +113,14 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh {
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;
@ -171,10 +149,6 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh {
void MAGNUM_LOCAL bindIndexedImplementationDefault();
void MAGNUM_LOCAL bindIndexedImplementationVAO();
static MAGNUM_LOCAL BindIndexedImplementation bindIndexedImplementation;
Buffer* _indexBuffer;
GLsizei _indexCount;
IndexType _indexType;
};
}

9
src/Mesh.cpp

@ -47,6 +47,10 @@ std::size_t Mesh::indexSize(IndexType type) {
CORRADE_INTERNAL_ASSERT(false);
}
Mesh::Mesh(Primitive primitive): _primitive(primitive), _vertexCount(0), _indexBuffer(nullptr), _indexCount(0), _indexType(IndexType::UnsignedInt) {
(this->*createImplementation)();
}
Mesh::~Mesh() {
/* Remove current vao from the state */
GLuint& current = Context::current()->state()->mesh->currentVAO;
@ -55,7 +59,7 @@ Mesh::~Mesh() {
(this->*destroyImplementation)();
}
Mesh::Mesh(Mesh&& other): vao(other.vao), _primitive(other._primitive), _vertexCount(other._vertexCount), attributes(std::move(other.attributes))
Mesh::Mesh(Mesh&& other): vao(other.vao), _primitive(other._primitive), _vertexCount(other._vertexCount), _indexBuffer(other._indexBuffer), _indexCount(other._indexCount), _indexType(other._indexType), attributes(std::move(other.attributes))
#ifndef MAGNUM_TARGET_GLES2
, integerAttributes(std::move(other.integerAttributes))
#ifndef MAGNUM_TARGET_GLES
@ -72,6 +76,9 @@ Mesh& Mesh::operator=(Mesh&& other) {
vao = other.vao;
_primitive = other._primitive;
_vertexCount = other._vertexCount;
_indexBuffer = other._indexBuffer;
_indexCount = other._indexCount;
_indexType = other._indexType;
attributes = std::move(other.attributes);
#ifndef MAGNUM_TARGET_GLES2
integerAttributes = std::move(other.integerAttributes);

39
src/Mesh.h

@ -385,9 +385,7 @@ class MAGNUM_EXPORT Mesh {
* @see setPrimitive(), setVertexCount(), @fn_gl{GenVertexArrays} (if
* @extension{APPLE,vertex_array_object} is available)
*/
inline explicit Mesh(Primitive primitive = Primitive::Triangles): _primitive(primitive), _vertexCount(0) {
(this->*createImplementation)();
}
explicit Mesh(Primitive primitive = Primitive::Triangles);
/** @brief Move constructor */
Mesh(Mesh&& other);
@ -435,6 +433,36 @@ class MAGNUM_EXPORT Mesh {
return this;
}
/** @brief Index count */
inline GLsizei indexCount() const { return _indexCount; }
/**
* @brief Set index count
* @return Pointer to self (for method chaining)
*
* Default is zero.
* @see setIndexBuffer(), setIndexType(), MeshTools::compressIndices()
*/
inline Mesh* setIndexCount(GLsizei count) {
_indexCount = count;
return this;
}
/** @brief Index type */
inline IndexType indexType() const { return _indexType; }
/**
* @brief Set index type
* @return Pointer to self (for method chaining)
*
* Default is @ref IndexType "IndexType::UnsignedInt".
* @see setIndexBuffer(), setIndexCount(), MeshTools::compressIndices()
*/
inline Mesh* setIndexType(IndexType type) {
_indexType = type;
return this;
}
/**
* @brief Add buffer with non-interleaved vertex attributes for use with given shader
* @return Pointer to self (for method chaining)
@ -716,7 +744,7 @@ class MAGNUM_EXPORT Mesh {
typedef void(Mesh::*CreateImplementation)();
void MAGNUM_LOCAL createImplementationDefault();
void MAGNUM_LOCAL createImplementationVAO();
static CreateImplementation createImplementation;
static MAGNUM_LOCAL CreateImplementation createImplementation;
typedef void(Mesh::*DestroyImplementation)();
void MAGNUM_LOCAL destroyImplementationDefault();
@ -762,6 +790,9 @@ class MAGNUM_EXPORT Mesh {
GLuint vao;
Primitive _primitive;
GLsizei _vertexCount;
Buffer* _indexBuffer;
GLsizei _indexCount;
IndexType _indexType;
std::vector<Attribute> attributes;
#ifndef MAGNUM_TARGET_GLES2

Loading…
Cancel
Save