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.
* @see @ref DataType
* The underlying scalar type of the attribute.
* @see @ref Type, @ref DataType
*/
typedef typename Implementation::Attribute<T>::Type Type;
typedef typename Implementation::Attribute<T>::ScalarType ScalarType;
/**
* @brief Component count
@ -1222,7 +1222,7 @@ template<class> struct Attribute;
/* Base for float attributes */
struct FloatAttribute {
typedef Float Type;
typedef Float ScalarType;
enum class DataType: GLenum {
UnsignedByte = GL_UNSIGNED_BYTE,
@ -1260,7 +1260,7 @@ Debug MAGNUM_EXPORT operator<<(Debug debug, FloatAttribute::DataType value);
#ifndef MAGNUM_TARGET_GLES2
/* Base for int attributes */
struct IntAttribute {
typedef Int Type;
typedef Int ScalarType;
enum class DataType: GLenum {
UnsignedByte = GL_UNSIGNED_BYTE,
@ -1282,7 +1282,7 @@ Debug MAGNUM_EXPORT operator<<(Debug debug, IntAttribute::DataType value);
/* Base for unsigned int attributes */
struct UnsignedIntAttribute {
typedef UnsignedInt Type;
typedef UnsignedInt ScalarType;
typedef IntAttribute::DataType DataType;
constexpr static DataType DefaultDataType = DataType::UnsignedInt;
@ -1299,7 +1299,7 @@ struct UnsignedIntAttribute {
#ifndef MAGNUM_TARGET_GLES
/* Base for double attributes */
struct DoubleAttribute {
typedef Double Type;
typedef Double ScalarType;
enum class DataType: GLenum {
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 */
template<> struct Attribute<Math::Vector<4, Float>> {
typedef Float Type;
typedef Float ScalarType;
enum class Components: GLint {
One = 1,

6
src/Magnum/Mesh.h

@ -703,7 +703,7 @@ class MAGNUM_EXPORT Mesh: public AbstractObject {
}
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)
attributePointerInternal(Attribute{
&buffer,
@ -717,7 +717,7 @@ class MAGNUM_EXPORT Mesh: public AbstractObject {
}
#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{
&buffer,
location,
@ -729,7 +729,7 @@ class MAGNUM_EXPORT Mesh: public AbstractObject {
}
#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)
attributePointerInternal(LongAttribute{
&buffer,

14
src/Magnum/Test/AbstractShaderProgramTest.cpp

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

Loading…
Cancel
Save