Browse Source

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.
pull/7/head
Vladimír Vondruš 13 years ago
parent
commit
616a31f4d2
  1. 2
      src/Shaders/AbstractTextShader.h
  2. 2
      src/Shaders/FlatShader.h
  3. 6
      src/Shaders/FlatShader2D.vert
  4. 2
      src/Shaders/PhongShader.h
  5. 6
      src/Shaders/TextShader2D.vert
  6. 2
      src/Shaders/VertexColorShader.h
  7. 6
      src/Shaders/VertexColorShader2D.vert

2
src/Shaders/AbstractTextShader.h

@ -33,7 +33,7 @@ namespace Magnum { namespace Shaders {
template<std::uint8_t dimensions> class AbstractTextShader: public AbstractShaderProgram {
public:
/** @brief Vertex position */
typedef Attribute<0, typename DimensionTraits<dimensions>::PointType> Position;
typedef Attribute<0, typename DimensionTraits<dimensions>::VectorType> Position;
/** @brief Texture coordinates */
typedef Attribute<1, Vector2> TextureCoordinates;

2
src/Shaders/FlatShader.h

@ -38,7 +38,7 @@ Draws whole mesh with one color.
template<std::uint8_t dimensions> class MAGNUM_SHADERS_EXPORT FlatShader: public AbstractShaderProgram {
public:
/** @brief Vertex position */
typedef Attribute<0, typename DimensionTraits<dimensions>::PointType> Position;
typedef Attribute<0, typename DimensionTraits<dimensions>::VectorType> Position;
explicit FlatShader();

6
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);
}

2
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();

6
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;
}

2
src/Shaders/VertexColorShader.h

@ -38,7 +38,7 @@ Draws vertex-colored mesh.
template<std::uint8_t dimensions> class MAGNUM_SHADERS_EXPORT VertexColorShader: public AbstractShaderProgram {
public:
/** @brief Vertex position */
typedef Attribute<0, typename DimensionTraits<dimensions>::PointType> Position;
typedef Attribute<0, typename DimensionTraits<dimensions>::VectorType> Position;
/** @brief Vertex color */
typedef Attribute<1, Color3<>> Color;

6
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;
}

Loading…
Cancel
Save