From 976377f0a4009f33654eb468c98c631a01be1230 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 17 Jan 2013 14:20:38 +0100 Subject: [PATCH] Moved code to check allowed attribute types to internal implementation. TypeTraits class is now not needed at all. --- src/AbstractShaderProgram.h | 57 +++++++++++++++++++++++++++++++++++-- src/Mesh.h | 8 +++--- 2 files changed, 58 insertions(+), 7 deletions(-) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 6ba5e4866..cb16c0b2a 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -23,7 +23,6 @@ #include #include "Magnum.h" -#include "TypeTraits.h" #include "magnumVisibility.h" @@ -34,6 +33,7 @@ namespace Magnum { #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { template struct Attribute; + template struct AttributeTraits; } #endif @@ -266,7 +266,7 @@ mesh.draw(); Only types listed here (and their subclasses and specializations, such as @ref Matrix3 or Color4) can be used for setting uniforms and specifying -vertex attributes. See also TypeTraits::AttributeType. +vertex attributes. @section AbstractShaderProgram-performance-optimization Performance optimizations @@ -329,7 +329,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * Type used in shader code. * @see DataType */ - typedef typename TypeTraits::AttributeType Type; + typedef typename Implementation::AttributeTraits::AttributeType Type; /** * @brief Data type @@ -1261,6 +1261,57 @@ template struct Attribute>: public Attribute template struct Attribute>: public Attribute> {}; template struct Attribute>: public Attribute> {}; +/* Types allowed as GLSL attributes */ +template<> struct AttributeTraits { typedef GLuint AttributeType; }; +template<> struct AttributeTraits { typedef GLint AttributeType; }; +template<> struct AttributeTraits { typedef GLfloat AttributeType; }; +#ifndef MAGNUM_TARGET_GLES +template<> struct AttributeTraits { typedef GLdouble AttributeType; }; +#endif + +/* Only some vectors can be used as attributes */ +template struct VectorAttributeTraits {}; +template<> struct VectorAttributeTraits { typedef GLuint AttributeType; }; +template<> struct VectorAttributeTraits { typedef GLint AttributeType; }; +template<> struct VectorAttributeTraits { typedef GLfloat AttributeType; }; +#ifndef MAGNUM_TARGET_GLES +template<> struct VectorAttributeTraits { typedef GLdouble AttributeType; }; +#endif + +template struct AttributeTraits>: VectorAttributeTraits {}; +template struct AttributeTraits>: VectorAttributeTraits {}; +template struct AttributeTraits>: VectorAttributeTraits {}; + +template struct AttributeTraits>: AttributeTraits> {}; +template struct AttributeTraits>: AttributeTraits> {}; +template struct AttributeTraits>: AttributeTraits> {}; +template struct AttributeTraits>: AttributeTraits> {}; +template struct AttributeTraits>: AttributeTraits> {}; +template struct AttributeTraits>: AttributeTraits> {}; +template struct AttributeTraits>: AttributeTraits> {}; + +/* Only some floating-point matrices can be used as attributes */ +template struct MatrixAttributeTraits {}; +template<> struct MatrixAttributeTraits { typedef GLfloat AttributeType; }; +#ifndef MAGNUM_TARGET_GLES +template<> struct MatrixAttributeTraits { typedef GLdouble AttributeType; }; +#endif + +template struct AttributeTraits>: MatrixAttributeTraits {}; +template struct AttributeTraits>: MatrixAttributeTraits {}; +template struct AttributeTraits>: MatrixAttributeTraits {}; +#ifndef MAGNUM_TARGET_GLES2 +template struct AttributeTraits>: MatrixAttributeTraits {}; +template struct AttributeTraits>: MatrixAttributeTraits {}; +template struct AttributeTraits>: MatrixAttributeTraits {}; +template struct AttributeTraits>: MatrixAttributeTraits {}; +template struct AttributeTraits>: MatrixAttributeTraits {}; +template struct AttributeTraits>: MatrixAttributeTraits {}; +#endif + +template struct AttributeTraits>: MatrixAttributeTraits {}; +template struct AttributeTraits>: MatrixAttributeTraits {}; + } #endif diff --git a/src/Mesh.h b/src/Mesh.h index 778ed86cf..5018fa63c 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -21,9 +21,9 @@ #include #include +#include #include "AbstractShaderProgram.h" -#include "TypeTraits.h" namespace Magnum { @@ -627,7 +627,7 @@ class MAGNUM_EXPORT Mesh { } inline void addInterleavedVertexBufferInternal(Buffer*, GLsizei, GLintptr) {} - template inline void addVertexAttribute(typename std::enable_if::AttributeType, GLfloat>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute& attribute, GLintptr offset, GLsizei stride) { + template inline void addVertexAttribute(typename std::enable_if::AttributeType, GLfloat>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute& attribute, GLintptr offset, GLsizei stride) { for(GLuint i = 0; i != Implementation::Attribute::vectorCount(); ++i) { attributes.push_back({ buffer, @@ -644,7 +644,7 @@ class MAGNUM_EXPORT Mesh { } #ifndef MAGNUM_TARGET_GLES2 - template inline void addVertexAttribute(typename std::enable_if::AttributeType>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute& attribute, GLintptr offset, GLsizei stride) { + template inline void addVertexAttribute(typename std::enable_if::AttributeType>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute& attribute, GLintptr offset, GLsizei stride) { integerAttributes.push_back({ buffer, location, @@ -658,7 +658,7 @@ class MAGNUM_EXPORT Mesh { } #ifndef MAGNUM_TARGET_GLES - template inline void addVertexAttribute(typename std::enable_if::AttributeType, GLdouble>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute& attribute, GLintptr offset, GLsizei stride) { + template inline void addVertexAttribute(typename std::enable_if::AttributeType, GLdouble>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute& attribute, GLintptr offset, GLsizei stride) { for(GLuint i = 0; i != Implementation::Attribute::vectorCount(); ++i) { longAttributes.push_back({ buffer,