Browse Source

Shaders: 3D version of VertexColorShader.

Fragment shader can be shared for 2D and 3D version, modified the
sources accordingly.
pull/7/head
Vladimír Vondruš 14 years ago
parent
commit
f9f95946b1
  1. 2
      src/Shaders/CMakeLists.txt
  2. 18
      src/Shaders/VertexColorShader.cpp
  3. 0
      src/Shaders/VertexColorShader.frag
  4. 25
      src/Shaders/VertexColorShader3D.vert

2
src/Shaders/CMakeLists.txt

@ -2,7 +2,7 @@ corrade_add_resource(MagnumShaders_RCS MagnumShaders
FlatShader2D.vert FlatShader2D.frag
PhongShader.vert PhongShader.frag
TextShader2D.vert TextShader2D.frag
VertexColorShader2D.vert VertexColorShader2D.frag
VertexColorShader2D.vert VertexColorShader3D.vert VertexColorShader.frag
compatibility.glsl)
set(MagnumShaders_SRCS
FlatShader.cpp

18
src/Shaders/VertexColorShader.cpp

@ -23,17 +23,9 @@
namespace Magnum { namespace Shaders {
namespace {
template<std::uint8_t dimensions> struct ShaderName {};
template<> struct ShaderName<2> {
constexpr static const char* vertex() { return "VertexColorShader2D.vert"; }
constexpr static const char* fragment() { return "VertexColorShader2D.frag"; }
};
template<> struct ShaderName<3> {
constexpr static const char* vertex() { return "VertexColorShader3D.vert"; }
constexpr static const char* fragment() { return "VertexColorShader3D.frag"; }
};
template<std::uint8_t> constexpr const char* vertexShaderName();
template<> constexpr const char* vertexShaderName<2>() { return "VertexColorShader2D.vert"; }
template<> constexpr const char* vertexShaderName<3>() { return "VertexColorShader3D.vert"; }
}
template<std::uint8_t dimensions> VertexColorShader<dimensions>::VertexColorShader(): transformationProjectionMatrixUniform(0) {
@ -47,12 +39,12 @@ template<std::uint8_t dimensions> VertexColorShader<dimensions>::VertexColorShad
Shader vertexShader(v, Shader::Type::Vertex);
vertexShader.addSource(rs.get("compatibility.glsl"));
vertexShader.addSource(rs.get(ShaderName<dimensions>::vertex()));
vertexShader.addSource(rs.get(vertexShaderName<dimensions>()));
attachShader(vertexShader);
Shader fragmentShader(v, Shader::Type::Fragment);
fragmentShader.addSource(rs.get("compatibility.glsl"));
fragmentShader.addSource(rs.get(ShaderName<dimensions>::fragment()));
fragmentShader.addSource(rs.get("VertexColorShader.frag"));
attachShader(fragmentShader);
#ifndef MAGNUM_TARGET_GLES

0
src/Shaders/VertexColorShader2D.frag → src/Shaders/VertexColorShader.frag

25
src/Shaders/VertexColorShader3D.vert

@ -0,0 +1,25 @@
#ifndef NEW_GLSL
#define in attribute
#define out varying
#endif
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 0) uniform mat4 transformationProjectionMatrix;
#else
uniform highp mat4 transformationProjectionMatrix;
#endif
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = 0) in highp vec4 position;
layout(location = 1) in lowp vec3 color;
#else
in highp vec4 position;
in lowp vec3 color;
#endif
out lowp vec3 interpolatedColor;
void main() {
gl_Position = transformationProjectionMatrix*position;
interpolatedColor = color;
}
Loading…
Cancel
Save