Browse Source

Strongly-typed Primitive enum in Mesh.

Also updated "default" constructor to include primitive type, as in many
cases only the primitive is specified and not the counts and types of
data.
vectorfields
Vladimír Vondruš 14 years ago
parent
commit
e43c1fae33
  1. 2
      src/IndexedMesh.cpp
  2. 8
      src/IndexedMesh.h
  3. 2
      src/Mesh.cpp
  4. 11
      src/Mesh.h
  5. 4
      src/MeshBuilder.h
  6. 2
      src/Primitives/Cube.h
  7. 2
      src/Primitives/Icosphere.h

2
src/IndexedMesh.cpp

@ -41,7 +41,7 @@ void IndexedMesh::draw() {
/* Bind index array, draw the elements and unbind */
_indexBuffer.bind();
glDrawElements(primitive(), _indexCount, static_cast<GLenum>(_indexType), nullptr);
glDrawElements(static_cast<GLenum>(primitive()), _indexCount, static_cast<GLenum>(_indexType), nullptr);
/* Disable vertex arrays for all attributes */
for(set<GLuint>::const_iterator it = attributes().begin(); it != attributes().end(); ++it)

8
src/IndexedMesh.h

@ -31,13 +31,13 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh {
public:
/**
* @brief Implicit constructor
* @param primitive Primitive type
*
* Allows creating the object without knowing anything about mesh data.
* Note that you have to call setPrimitive(), setVertexCount(),
* setIndexCount() and setIndexType() manually for mesh to draw
* properly.
* Note that you have to call setVertexCount(), setIndexCount() and
* setIndexType() manually for mesh to draw properly.
*/
inline IndexedMesh(): _indexBuffer(Buffer::Target::ElementArray), _indexCount(0), _indexType(Type::UnsignedShort) {}
inline IndexedMesh(Primitive primitive = Primitive::Triangles): Mesh(primitive), _indexBuffer(Buffer::Target::ElementArray), _indexCount(0), _indexType(Type::UnsignedShort) {}
/**
* @brief Constructor

2
src/Mesh.cpp

@ -57,7 +57,7 @@ void Mesh::draw() {
else glVertexAttribPointer(ait->attribute, ait->size, static_cast<GLenum>(ait->type), GL_FALSE, ait->stride, ait->pointer);
}
glDrawArrays(_primitive, 0, _vertexCount);
glDrawArrays(static_cast<GLenum>(_primitive), 0, _vertexCount);
/* Disable vertex arrays for all attributes */
for(set<GLuint>::const_iterator it = _attributes.begin(); it != _attributes.end(); ++it)

11
src/Mesh.h

@ -44,7 +44,7 @@ class MAGNUM_EXPORT Mesh {
public:
/** @brief Primitive type */
enum Primitive {
enum class Primitive: GLenum {
/**
* Single points
*/
@ -86,12 +86,13 @@ class MAGNUM_EXPORT Mesh {
/**
* @brief Implicit constructor
* @param primitive Primitive type
*
* Allows creating the object without knowing anything about mesh data.
* Note that you have to call setPrimitive() and setVertexCount()
* manually for mesh to draw properly.
* Allows creating the object without knowing anything about mesh
* data. Note that you have to call setVertexCount() manually for mesh
* to draw properly.
*/
inline Mesh(): _primitive(Triangles), _vertexCount(0), finalized(false) {}
inline Mesh(Primitive primitive = Primitive::Triangles): _primitive(primitive), _vertexCount(0), finalized(false) {}
/**
* @brief Constructor

4
src/MeshBuilder.h

@ -136,7 +136,7 @@ template<class Vertex> class MeshBuilder {
* @note The mesh is @b not cleaned before building.
*/
void build(IndexedMesh* mesh, Buffer* vertexBuffer, Buffer::Usage vertexBufferUsage, Buffer::Usage indexBufferUsage) {
mesh->setPrimitive(Mesh::Triangles);
mesh->setPrimitive(Mesh::Primitive::Triangles);
mesh->setVertexCount(_vertices.size());
vertexBuffer->setData(sizeof(Vertex)*_vertices.size(), _vertices.data(), vertexBufferUsage);
SizeBasedCall<IndexBuilder>(_vertices.size())(mesh, _indices, indexBufferUsage);
@ -150,7 +150,7 @@ template<class Vertex> class MeshBuilder {
* @see build(IndexedMesh*, Buffer*, Buffer::Usage, Buffer::Usage)
*/
IndexedMesh* build(Buffer::Usage vertexBufferUsage, Buffer::Usage indexBufferUsage) {
IndexedMesh mesh = new IndexedMesh(Mesh::Triangles, 0, 0, Type::UnsignedByte);
IndexedMesh mesh = new IndexedMesh;
Buffer* vertexBuffer = mesh.addBuffer(true);
build(mesh, vertexBuffer, vertexBufferUsage, indexBufferUsage);

2
src/Primitives/Cube.h

@ -26,7 +26,7 @@ namespace Magnum { namespace Primitives {
/** @brief %Cube primitive */
class Cube: public AbstractPrimitive<GLubyte> {
public:
inline Mesh::Primitive primitive() const { return Mesh::Triangles; }
inline Mesh::Primitive primitive() const { return Mesh::Primitive::Triangles; }
inline size_t vertexCount() const { return 8; }
inline size_t indexCount() const { return 36; }

2
src/Primitives/Icosphere.h

@ -48,7 +48,7 @@ template<size_t subdivisions> class Icosphere: public AbstractPrimitive<typename
if(vertexCount() == 0) subdivide();
}
inline Mesh::Primitive primitive() const { return Mesh::Triangles; }
inline Mesh::Primitive primitive() const { return Mesh::Primitive::Triangles; }
inline size_t vertexCount() const { return builder()->vertexCount(); }
inline size_t indexCount() const { return builder()->indexCount(); }

Loading…
Cancel
Save