From 616a31f4d2693f65f142202861c18d149d9c014e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 22 Feb 2013 00:30:55 +0100 Subject: [PATCH] Shaders: got rid of Point2D/3D in positions in favor of Vector2/Vector3. Originally it was for more convenient usage of homogeneous coordinates in shaders themselves, but it is actually not needed: * When passing three-component vector (3D position) to `vec4`, the last coordinate is implicitly set to `1`, thus there is no need to pass it explicitly in each attribute. * On the other hand, when passing three-component vector (2D position in homogeneous coordinates) to `vec3` with Z explicitly set to `1`, it still needs some swizzle magic to extend it to `vec4` gl_Position. Passing it as two-component vector results in nearly the same magic while saving precious memory. --- src/Shaders/AbstractTextShader.h | 2 +- src/Shaders/FlatShader.h | 2 +- src/Shaders/FlatShader2D.vert | 6 +++--- src/Shaders/PhongShader.h | 2 +- src/Shaders/TextShader2D.vert | 6 +++--- src/Shaders/VertexColorShader.h | 2 +- src/Shaders/VertexColorShader2D.vert | 6 +++--- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Shaders/AbstractTextShader.h b/src/Shaders/AbstractTextShader.h index 350b519ac..8f391c1f5 100644 --- a/src/Shaders/AbstractTextShader.h +++ b/src/Shaders/AbstractTextShader.h @@ -33,7 +33,7 @@ namespace Magnum { namespace Shaders { template class AbstractTextShader: public AbstractShaderProgram { public: /** @brief Vertex position */ - typedef Attribute<0, typename DimensionTraits::PointType> Position; + typedef Attribute<0, typename DimensionTraits::VectorType> Position; /** @brief Texture coordinates */ typedef Attribute<1, Vector2> TextureCoordinates; diff --git a/src/Shaders/FlatShader.h b/src/Shaders/FlatShader.h index 93a020a4a..6eb110a3c 100644 --- a/src/Shaders/FlatShader.h +++ b/src/Shaders/FlatShader.h @@ -38,7 +38,7 @@ Draws whole mesh with one color. template class MAGNUM_SHADERS_EXPORT FlatShader: public AbstractShaderProgram { public: /** @brief Vertex position */ - typedef Attribute<0, typename DimensionTraits::PointType> Position; + typedef Attribute<0, typename DimensionTraits::VectorType> Position; explicit FlatShader(); diff --git a/src/Shaders/FlatShader2D.vert b/src/Shaders/FlatShader2D.vert index b976b595c..a976a1c7f 100644 --- a/src/Shaders/FlatShader2D.vert +++ b/src/Shaders/FlatShader2D.vert @@ -9,11 +9,11 @@ uniform highp mat3 transformationProjectionMatrix; #endif #ifdef EXPLICIT_ATTRIB_LOCATION -layout(location = 0) in highp vec3 position; +layout(location = 0) in highp vec2 position; #else -in highp vec3 position; +in highp vec2 position; #endif void main() { - gl_Position.xywz = vec4(transformationProjectionMatrix*position, 0.0); + gl_Position.xywz = vec4(transformationProjectionMatrix*vec3(position, 1.0), 0.0); } diff --git a/src/Shaders/PhongShader.h b/src/Shaders/PhongShader.h index b37d93361..a82f4c93b 100644 --- a/src/Shaders/PhongShader.h +++ b/src/Shaders/PhongShader.h @@ -35,7 +35,7 @@ otherwise falls back to GLSL 1.20. */ class MAGNUM_SHADERS_EXPORT PhongShader: public AbstractShaderProgram { public: - typedef Attribute<0, Point3D> Position; /**< @brief Vertex position */ + typedef Attribute<0, Vector3> Position; /**< @brief Vertex position */ typedef Attribute<1, Vector3> Normal; /**< @brief Normal direction */ explicit PhongShader(); diff --git a/src/Shaders/TextShader2D.vert b/src/Shaders/TextShader2D.vert index 98ee96d84..9b3816650 100644 --- a/src/Shaders/TextShader2D.vert +++ b/src/Shaders/TextShader2D.vert @@ -10,16 +10,16 @@ uniform highp mat3 transformationProjectionMatrix; #endif #ifdef EXPLICIT_ATTRIB_LOCATION -layout(location = 0) in highp vec3 position; +layout(location = 0) in highp vec2 position; layout(location = 1) in mediump vec2 textureCoordinates; #else -in highp vec3 position; +in highp vec2 position; in mediump vec2 textureCoordinates; #endif out vec2 fragmentTextureCoordinates; void main() { - gl_Position.xywz = vec4(transformationProjectionMatrix*position, 0.0); + gl_Position.xywz = vec4(transformationProjectionMatrix*vec3(position, 1.0), 0.0); fragmentTextureCoordinates = textureCoordinates; } diff --git a/src/Shaders/VertexColorShader.h b/src/Shaders/VertexColorShader.h index 3ac86aaec..4f0275d3f 100644 --- a/src/Shaders/VertexColorShader.h +++ b/src/Shaders/VertexColorShader.h @@ -38,7 +38,7 @@ Draws vertex-colored mesh. template class MAGNUM_SHADERS_EXPORT VertexColorShader: public AbstractShaderProgram { public: /** @brief Vertex position */ - typedef Attribute<0, typename DimensionTraits::PointType> Position; + typedef Attribute<0, typename DimensionTraits::VectorType> Position; /** @brief Vertex color */ typedef Attribute<1, Color3<>> Color; diff --git a/src/Shaders/VertexColorShader2D.vert b/src/Shaders/VertexColorShader2D.vert index ff300a5b1..1272488e2 100644 --- a/src/Shaders/VertexColorShader2D.vert +++ b/src/Shaders/VertexColorShader2D.vert @@ -10,16 +10,16 @@ uniform highp mat3 transformationProjectionMatrix; #endif #ifdef EXPLICIT_ATTRIB_LOCATION -layout(location = 0) in highp vec3 position; +layout(location = 0) in highp vec2 position; layout(location = 1) in lowp vec3 color; #else -in highp vec3 position; +in highp vec2 position; in lowp vec3 color; #endif out lowp vec3 interpolatedColor; void main() { - gl_Position.xywz = vec4(transformationProjectionMatrix*position, 0.0); + gl_Position.xywz = vec4(transformationProjectionMatrix*vec3(position, 1.0), 0.0); interpolatedColor = color; }