Browse Source

Renamed AbstractShaderProgram::Attribute::Type to ScalarType.

In all other places (e.g. Math, SceneGraph), SomeClass<T>::Type is
always T. I spent twenty minutes figuring out what went wrong, so better
have this consistent.

Also update the test to check for these, as they apparently were tested
only indirectly through the MeshGLTest.
pull/51/head
Vladimír Vondruš 12 years ago
parent
commit
980503a509
  1. 18
      src/Magnum/AbstractShaderProgram.h
  2. 6
      src/Magnum/Mesh.h
  3. 14
      src/Magnum/Test/AbstractShaderProgramTest.cpp

18
src/Magnum/AbstractShaderProgram.h

@ -960,12 +960,12 @@ template<UnsignedInt location, class T> class AbstractShaderProgram::Attribute {
}; };
/** /**
* @brief Type * @brief Scalar type
* *
* Type used in shader code. * The underlying scalar type of the attribute.
* @see @ref DataType * @see @ref Type, @ref DataType
*/ */
typedef typename Implementation::Attribute<T>::Type Type; typedef typename Implementation::Attribute<T>::ScalarType ScalarType;
/** /**
* @brief Component count * @brief Component count
@ -1222,7 +1222,7 @@ template<class> struct Attribute;
/* Base for float attributes */ /* Base for float attributes */
struct FloatAttribute { struct FloatAttribute {
typedef Float Type; typedef Float ScalarType;
enum class DataType: GLenum { enum class DataType: GLenum {
UnsignedByte = GL_UNSIGNED_BYTE, UnsignedByte = GL_UNSIGNED_BYTE,
@ -1260,7 +1260,7 @@ Debug MAGNUM_EXPORT operator<<(Debug debug, FloatAttribute::DataType value);
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
/* Base for int attributes */ /* Base for int attributes */
struct IntAttribute { struct IntAttribute {
typedef Int Type; typedef Int ScalarType;
enum class DataType: GLenum { enum class DataType: GLenum {
UnsignedByte = GL_UNSIGNED_BYTE, UnsignedByte = GL_UNSIGNED_BYTE,
@ -1282,7 +1282,7 @@ Debug MAGNUM_EXPORT operator<<(Debug debug, IntAttribute::DataType value);
/* Base for unsigned int attributes */ /* Base for unsigned int attributes */
struct UnsignedIntAttribute { struct UnsignedIntAttribute {
typedef UnsignedInt Type; typedef UnsignedInt ScalarType;
typedef IntAttribute::DataType DataType; typedef IntAttribute::DataType DataType;
constexpr static DataType DefaultDataType = DataType::UnsignedInt; constexpr static DataType DefaultDataType = DataType::UnsignedInt;
@ -1299,7 +1299,7 @@ struct UnsignedIntAttribute {
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
/* Base for double attributes */ /* Base for double attributes */
struct DoubleAttribute { struct DoubleAttribute {
typedef Double Type; typedef Double ScalarType;
enum class DataType: GLenum { enum class DataType: GLenum {
Double = GL_DOUBLE Double = GL_DOUBLE
@ -1317,7 +1317,7 @@ Debug MAGNUM_EXPORT operator<<(Debug debug, DoubleAttribute::DataType value);
/* Floating-point four-component vector is absolutely special case */ /* Floating-point four-component vector is absolutely special case */
template<> struct Attribute<Math::Vector<4, Float>> { template<> struct Attribute<Math::Vector<4, Float>> {
typedef Float Type; typedef Float ScalarType;
enum class Components: GLint { enum class Components: GLint {
One = 1, One = 1,

6
src/Magnum/Mesh.h

@ -703,7 +703,7 @@ class MAGNUM_EXPORT Mesh: public AbstractObject {
} }
void addVertexBufferInternal(Buffer&, GLsizei, GLintptr) {} void addVertexBufferInternal(Buffer&, GLsizei, GLintptr) {}
template<UnsignedInt location, class T> void addVertexAttribute(typename std::enable_if<std::is_same<typename Implementation::Attribute<T>::Type, Float>::value, Buffer&>::type buffer, const AbstractShaderProgram::Attribute<location, T>& attribute, GLintptr offset, GLsizei stride) { template<UnsignedInt location, class T> void addVertexAttribute(typename std::enable_if<std::is_same<typename Implementation::Attribute<T>::ScalarType, Float>::value, Buffer&>::type buffer, const AbstractShaderProgram::Attribute<location, T>& attribute, GLintptr offset, GLsizei stride) {
for(UnsignedInt i = 0; i != AbstractShaderProgram::Attribute<location, T>::VectorCount; ++i) for(UnsignedInt i = 0; i != AbstractShaderProgram::Attribute<location, T>::VectorCount; ++i)
attributePointerInternal(Attribute{ attributePointerInternal(Attribute{
&buffer, &buffer,
@ -717,7 +717,7 @@ class MAGNUM_EXPORT Mesh: public AbstractObject {
} }
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
template<UnsignedInt location, class T> void addVertexAttribute(typename std::enable_if<std::is_integral<typename Implementation::Attribute<T>::Type>::value, Buffer&>::type buffer, const AbstractShaderProgram::Attribute<location, T>& attribute, GLintptr offset, GLsizei stride) { template<UnsignedInt location, class T> void addVertexAttribute(typename std::enable_if<std::is_integral<typename Implementation::Attribute<T>::ScalarType>::value, Buffer&>::type buffer, const AbstractShaderProgram::Attribute<location, T>& attribute, GLintptr offset, GLsizei stride) {
attributePointerInternal(IntegerAttribute{ attributePointerInternal(IntegerAttribute{
&buffer, &buffer,
location, location,
@ -729,7 +729,7 @@ class MAGNUM_EXPORT Mesh: public AbstractObject {
} }
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
template<UnsignedInt location, class T> void addVertexAttribute(typename std::enable_if<std::is_same<typename Implementation::Attribute<T>::Type, Double>::value, Buffer&>::type buffer, const AbstractShaderProgram::Attribute<location, T>& attribute, GLintptr offset, GLsizei stride) { template<UnsignedInt location, class T> void addVertexAttribute(typename std::enable_if<std::is_same<typename Implementation::Attribute<T>::ScalarType, Double>::value, Buffer&>::type buffer, const AbstractShaderProgram::Attribute<location, T>& attribute, GLintptr offset, GLsizei stride) {
for(UnsignedInt i = 0; i != AbstractShaderProgram::Attribute<location, T>::VectorCount; ++i) for(UnsignedInt i = 0; i != AbstractShaderProgram::Attribute<location, T>::VectorCount; ++i)
attributePointerInternal(LongAttribute{ attributePointerInternal(LongAttribute{
&buffer, &buffer,

14
src/Magnum/Test/AbstractShaderProgramTest.cpp

@ -76,6 +76,7 @@ AbstractShaderProgramTest::AbstractShaderProgramTest() {
void AbstractShaderProgramTest::attributeScalar() { void AbstractShaderProgramTest::attributeScalar() {
typedef AbstractShaderProgram::Attribute<3, Float> Attribute; typedef AbstractShaderProgram::Attribute<3, Float> Attribute;
CORRADE_VERIFY((std::is_same<Attribute::ScalarType, Float>{}));
CORRADE_COMPARE(Attribute::Location, 3); CORRADE_COMPARE(Attribute::Location, 3);
CORRADE_COMPARE(Attribute::VectorCount, 1); CORRADE_COMPARE(Attribute::VectorCount, 1);
@ -95,6 +96,7 @@ void AbstractShaderProgramTest::attributeScalar() {
void AbstractShaderProgramTest::attributeScalarInt() { void AbstractShaderProgramTest::attributeScalarInt() {
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
typedef AbstractShaderProgram::Attribute<3, Int> Attribute; typedef AbstractShaderProgram::Attribute<3, Int> Attribute;
CORRADE_VERIFY((std::is_same<Attribute::ScalarType, Int>{}));
CORRADE_COMPARE(Attribute::VectorCount, 1); CORRADE_COMPARE(Attribute::VectorCount, 1);
/* Default constructor */ /* Default constructor */
@ -112,6 +114,7 @@ void AbstractShaderProgramTest::attributeScalarInt() {
void AbstractShaderProgramTest::attributeScalarUnsignedInt() { void AbstractShaderProgramTest::attributeScalarUnsignedInt() {
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
typedef AbstractShaderProgram::Attribute<3, UnsignedInt> Attribute; typedef AbstractShaderProgram::Attribute<3, UnsignedInt> Attribute;
CORRADE_VERIFY((std::is_same<Attribute::ScalarType, UnsignedInt>{}));
CORRADE_COMPARE(Attribute::VectorCount, 1); CORRADE_COMPARE(Attribute::VectorCount, 1);
/* Default constructor */ /* Default constructor */
@ -129,6 +132,7 @@ void AbstractShaderProgramTest::attributeScalarUnsignedInt() {
void AbstractShaderProgramTest::attributeScalarDouble() { void AbstractShaderProgramTest::attributeScalarDouble() {
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
typedef AbstractShaderProgram::Attribute<3, Double> Attribute; typedef AbstractShaderProgram::Attribute<3, Double> Attribute;
CORRADE_VERIFY((std::is_same<Attribute::ScalarType, Double>{}));
CORRADE_COMPARE(Attribute::VectorCount, 1); CORRADE_COMPARE(Attribute::VectorCount, 1);
/* Default constructor */ /* Default constructor */
@ -141,6 +145,7 @@ void AbstractShaderProgramTest::attributeScalarDouble() {
void AbstractShaderProgramTest::attributeVector() { void AbstractShaderProgramTest::attributeVector() {
typedef AbstractShaderProgram::Attribute<3, Vector3> Attribute; typedef AbstractShaderProgram::Attribute<3, Vector3> Attribute;
CORRADE_VERIFY((std::is_same<Attribute::ScalarType, Float>{}));
CORRADE_COMPARE(Attribute::VectorCount, 1); CORRADE_COMPARE(Attribute::VectorCount, 1);
/* Default constructor */ /* Default constructor */
@ -164,6 +169,7 @@ void AbstractShaderProgramTest::attributeVector() {
void AbstractShaderProgramTest::attributeVectorInt() { void AbstractShaderProgramTest::attributeVectorInt() {
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
typedef AbstractShaderProgram::Attribute<3, Vector2i> Attribute; typedef AbstractShaderProgram::Attribute<3, Vector2i> Attribute;
CORRADE_VERIFY((std::is_same<Attribute::ScalarType, Int>{}));
CORRADE_COMPARE(Attribute::VectorCount, 1); CORRADE_COMPARE(Attribute::VectorCount, 1);
/* Default constructor */ /* Default constructor */
@ -183,6 +189,7 @@ void AbstractShaderProgramTest::attributeVectorInt() {
void AbstractShaderProgramTest::attributeVectorUnsignedInt() { void AbstractShaderProgramTest::attributeVectorUnsignedInt() {
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
typedef AbstractShaderProgram::Attribute<3, Vector4ui> Attribute; typedef AbstractShaderProgram::Attribute<3, Vector4ui> Attribute;
CORRADE_VERIFY((std::is_same<Attribute::ScalarType, UnsignedInt>{}));
CORRADE_COMPARE(Attribute::VectorCount, 1); CORRADE_COMPARE(Attribute::VectorCount, 1);
/* Default constructor */ /* Default constructor */
@ -202,6 +209,7 @@ void AbstractShaderProgramTest::attributeVectorUnsignedInt() {
void AbstractShaderProgramTest::attributeVectorDouble() { void AbstractShaderProgramTest::attributeVectorDouble() {
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
typedef AbstractShaderProgram::Attribute<3, Vector2d> Attribute; typedef AbstractShaderProgram::Attribute<3, Vector2d> Attribute;
CORRADE_VERIFY((std::is_same<Attribute::ScalarType, Double>{}));
CORRADE_COMPARE(Attribute::VectorCount, 1); CORRADE_COMPARE(Attribute::VectorCount, 1);
/* Default constructor */ /* Default constructor */
@ -220,6 +228,7 @@ void AbstractShaderProgramTest::attributeVectorDouble() {
void AbstractShaderProgramTest::attributeVector4() { void AbstractShaderProgramTest::attributeVector4() {
typedef AbstractShaderProgram::Attribute<3, Vector4> Attribute; typedef AbstractShaderProgram::Attribute<3, Vector4> Attribute;
CORRADE_VERIFY((std::is_same<Attribute::ScalarType, Float>{}));
CORRADE_COMPARE(Attribute::VectorCount, 1); CORRADE_COMPARE(Attribute::VectorCount, 1);
/* Custom type */ /* Custom type */
@ -235,6 +244,7 @@ void AbstractShaderProgramTest::attributeVector4() {
void AbstractShaderProgramTest::attributeVectorBGRA() { void AbstractShaderProgramTest::attributeVectorBGRA() {
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
typedef AbstractShaderProgram::Attribute<3, Vector4> Attribute; typedef AbstractShaderProgram::Attribute<3, Vector4> Attribute;
CORRADE_VERIFY((std::is_same<Attribute::ScalarType, Float>{}));
CORRADE_COMPARE(Attribute::VectorCount, 1); CORRADE_COMPARE(Attribute::VectorCount, 1);
/* BGRA */ /* BGRA */
@ -247,6 +257,7 @@ void AbstractShaderProgramTest::attributeVectorBGRA() {
void AbstractShaderProgramTest::attributeMatrixNxN() { void AbstractShaderProgramTest::attributeMatrixNxN() {
typedef AbstractShaderProgram::Attribute<3, Matrix3> Attribute; typedef AbstractShaderProgram::Attribute<3, Matrix3> Attribute;
CORRADE_VERIFY((std::is_same<Attribute::ScalarType, Float>{}));
CORRADE_COMPARE(Attribute::VectorCount, 3); CORRADE_COMPARE(Attribute::VectorCount, 3);
/* Default constructor */ /* Default constructor */
@ -259,6 +270,7 @@ void AbstractShaderProgramTest::attributeMatrixNxN() {
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
void AbstractShaderProgramTest::attributeMatrixMxN() { void AbstractShaderProgramTest::attributeMatrixMxN() {
typedef AbstractShaderProgram::Attribute<3, Matrix3x4> Attribute; typedef AbstractShaderProgram::Attribute<3, Matrix3x4> Attribute;
CORRADE_VERIFY((std::is_same<Attribute::ScalarType, Float>{}));
CORRADE_COMPARE(Attribute::VectorCount, 3); CORRADE_COMPARE(Attribute::VectorCount, 3);
/* Default constructor */ /* Default constructor */
@ -272,6 +284,7 @@ void AbstractShaderProgramTest::attributeMatrixMxN() {
void AbstractShaderProgramTest::attributeMatrixNxNd() { void AbstractShaderProgramTest::attributeMatrixNxNd() {
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
typedef AbstractShaderProgram::Attribute<3, Matrix4d> Attribute; typedef AbstractShaderProgram::Attribute<3, Matrix4d> Attribute;
CORRADE_VERIFY((std::is_same<Attribute::ScalarType, Double>{}));
CORRADE_COMPARE(Attribute::VectorCount, 4); CORRADE_COMPARE(Attribute::VectorCount, 4);
/* Default constructor */ /* Default constructor */
@ -287,6 +300,7 @@ void AbstractShaderProgramTest::attributeMatrixNxNd() {
void AbstractShaderProgramTest::attributeMatrixMxNd() { void AbstractShaderProgramTest::attributeMatrixMxNd() {
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
typedef AbstractShaderProgram::Attribute<3, Matrix4x2d> Attribute; typedef AbstractShaderProgram::Attribute<3, Matrix4x2d> Attribute;
CORRADE_VERIFY((std::is_same<Attribute::ScalarType, Double>{}));
CORRADE_COMPARE(Attribute::VectorCount, 4); CORRADE_COMPARE(Attribute::VectorCount, 4);
/* Default constructor */ /* Default constructor */

Loading…
Cancel
Save