From f9f95946b1a4c7bf3992830d892253657e837f19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 5 Jan 2013 19:47:47 +0100 Subject: [PATCH] Shaders: 3D version of VertexColorShader. Fragment shader can be shared for 2D and 3D version, modified the sources accordingly. --- src/Shaders/CMakeLists.txt | 2 +- src/Shaders/VertexColorShader.cpp | 18 ++++--------- ...orShader2D.frag => VertexColorShader.frag} | 0 src/Shaders/VertexColorShader3D.vert | 25 +++++++++++++++++++ 4 files changed, 31 insertions(+), 14 deletions(-) rename src/Shaders/{VertexColorShader2D.frag => VertexColorShader.frag} (100%) create mode 100644 src/Shaders/VertexColorShader3D.vert diff --git a/src/Shaders/CMakeLists.txt b/src/Shaders/CMakeLists.txt index aa1b50560..5ea5c8577 100644 --- a/src/Shaders/CMakeLists.txt +++ b/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 diff --git a/src/Shaders/VertexColorShader.cpp b/src/Shaders/VertexColorShader.cpp index 5a687c657..67fcfde3b 100644 --- a/src/Shaders/VertexColorShader.cpp +++ b/src/Shaders/VertexColorShader.cpp @@ -23,17 +23,9 @@ namespace Magnum { namespace Shaders { namespace { - template 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 constexpr const char* vertexShaderName(); + template<> constexpr const char* vertexShaderName<2>() { return "VertexColorShader2D.vert"; } + template<> constexpr const char* vertexShaderName<3>() { return "VertexColorShader3D.vert"; } } template VertexColorShader::VertexColorShader(): transformationProjectionMatrixUniform(0) { @@ -47,12 +39,12 @@ template VertexColorShader::VertexColorShad Shader vertexShader(v, Shader::Type::Vertex); vertexShader.addSource(rs.get("compatibility.glsl")); - vertexShader.addSource(rs.get(ShaderName::vertex())); + vertexShader.addSource(rs.get(vertexShaderName())); attachShader(vertexShader); Shader fragmentShader(v, Shader::Type::Fragment); fragmentShader.addSource(rs.get("compatibility.glsl")); - fragmentShader.addSource(rs.get(ShaderName::fragment())); + fragmentShader.addSource(rs.get("VertexColorShader.frag")); attachShader(fragmentShader); #ifndef MAGNUM_TARGET_GLES diff --git a/src/Shaders/VertexColorShader2D.frag b/src/Shaders/VertexColorShader.frag similarity index 100% rename from src/Shaders/VertexColorShader2D.frag rename to src/Shaders/VertexColorShader.frag diff --git a/src/Shaders/VertexColorShader3D.vert b/src/Shaders/VertexColorShader3D.vert new file mode 100644 index 000000000..8a871000f --- /dev/null +++ b/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; +}