Browse Source

Reworked Mesh / IndexedMesh to use new type traits and Type enum.

pull/279/head
Vladimír Vondruš 14 years ago
parent
commit
e77b38d20b
  1. 15
      src/IndexedMesh.cpp
  2. 35
      src/Mesh.cpp
  3. 8
      src/Mesh.h

15
src/IndexedMesh.cpp

@ -34,18 +34,9 @@ void IndexedMesh::draw() {
/* Bind all attributes to this buffer */
for(vector<Attribute>::const_iterator ait = it->second.second.begin(); ait != it->second.second.end(); ++ait)
switch(ait->type) {
case GL_BYTE:
case GL_UNSIGNED_BYTE:
case GL_SHORT:
case GL_UNSIGNED_SHORT:
case GL_INT:
case GL_UNSIGNED_INT:
glVertexAttribIPointer(ait->attribute, ait->size, ait->type, ait->stride, ait->pointer);
break;
default:
glVertexAttribPointer(ait->attribute, ait->size, ait->type, GL_FALSE, ait->stride, ait->pointer);
}
if(TypeInfo::isIntegral(ait->type))
glVertexAttribIPointer(ait->attribute, ait->size, static_cast<GLenum>(ait->type), ait->stride, ait->pointer);
else glVertexAttribPointer(ait->attribute, ait->size, static_cast<GLenum>(ait->type), GL_FALSE, ait->stride, ait->pointer);
}
/* Bind index array, draw the elements and unbind */

35
src/Mesh.cpp

@ -52,18 +52,9 @@ void Mesh::draw() {
/* Bind all attributes to this buffer */
for(vector<Attribute>::const_iterator ait = it->second.second.begin(); ait != it->second.second.end(); ++ait)
switch(ait->type) {
case GL_BYTE:
case GL_UNSIGNED_BYTE:
case GL_SHORT:
case GL_UNSIGNED_SHORT:
case GL_INT:
case GL_UNSIGNED_INT:
glVertexAttribIPointer(ait->attribute, ait->size, ait->type, ait->stride, ait->pointer);
break;
default:
glVertexAttribPointer(ait->attribute, ait->size, ait->type, GL_FALSE, ait->stride, ait->pointer);
}
if(TypeInfo::isIntegral(ait->type))
glVertexAttribIPointer(ait->attribute, ait->size, static_cast<GLenum>(ait->type), ait->stride, ait->pointer);
else glVertexAttribPointer(ait->attribute, ait->size, static_cast<GLenum>(ait->type), GL_FALSE, ait->stride, ait->pointer);
}
glDrawArrays(_primitive, 0, _vertexCount);
@ -92,7 +83,7 @@ void Mesh::finalize() {
ait->pointer = reinterpret_cast<const GLvoid*>(stride);
/* Add attribute size (per vertex) to stride */
stride += ait->size*sizeOf(ait->type);
stride += ait->size*TypeInfo::sizeOf(ait->type);
}
/* Set computed stride for all attributes */
@ -108,7 +99,7 @@ void Mesh::finalize() {
ait->pointer = reinterpret_cast<const GLvoid*>(position);
/* Add attribute size (for all vertices) to position */
position += ait->size*sizeOf(ait->type)*_vertexCount;
position += ait->size*TypeInfo::sizeOf(ait->type)*_vertexCount;
}
}
}
@ -117,7 +108,7 @@ void Mesh::finalize() {
finalized = true;
}
void Mesh::bindAttribute(Buffer* buffer, GLuint attribute, GLint size, GLenum type) {
void Mesh::bindAttribute(Buffer* buffer, GLuint attribute, GLint size, Type type) {
/* The mesh is finalized or attribute is already bound, nothing to do */
if(finalized || _attributes.find(attribute) != _attributes.end()) return;
@ -136,18 +127,4 @@ void Mesh::bindAttribute(Buffer* buffer, GLuint attribute, GLint size, GLenum ty
_attributes.insert(attribute);
}
GLsizei Mesh::sizeOf(GLenum type) {
switch(type) {
case GL_BYTE: return sizeof(GLbyte);
case GL_UNSIGNED_BYTE: return sizeof(GLubyte);
case GL_SHORT: return sizeof(GLshort);
case GL_UNSIGNED_SHORT: return sizeof(GLushort);
case GL_INT: return sizeof(GLint);
case GL_UNSIGNED_INT: return sizeof(GLuint);
case GL_FLOAT: return sizeof(GLfloat);
case GL_DOUBLE: return sizeof(GLdouble);
default: return 0;
}
}
}

8
src/Mesh.h

@ -157,7 +157,7 @@ class MAGNUM_EXPORT Mesh {
* function does nothing.
*/
template<class T> inline void bindAttribute(Buffer* buffer, GLuint attribute) {
bindAttribute(buffer, attribute, TypeTraits<T>::count(), static_cast<GLenum>(TypeTraits<T>::glType()));
bindAttribute(buffer, attribute, TypeTraits<T>::count(), TypeTraits<T>::glType());
}
/**
@ -173,7 +173,7 @@ class MAGNUM_EXPORT Mesh {
struct Attribute {
GLuint attribute; /**< @brief Attribute ID */
GLint size; /**< @brief How many items of @c type are in the attribute */
GLenum type; /**< @brief Attribute item type */
Type type; /**< @brief Attribute item type */
GLsizei stride; /**< @brief Distance of two adjacent attributes of this type in interleaved buffer */
const GLvoid* pointer; /**< @brief Pointer to first attribute of this type in the buffer */
};
@ -217,9 +217,7 @@ class MAGNUM_EXPORT Mesh {
std::map<Buffer*, std::pair<bool, std::vector<Attribute> > > _buffers;
std::set<GLuint> _attributes;
void bindAttribute(Buffer* buffer, GLuint attribute, GLint size, GLenum type);
GLsizei sizeOf(GLenum type);
void bindAttribute(Buffer* buffer, GLuint attribute, GLint size, Type type);
};
}

Loading…
Cancel
Save