diff --git a/src/Shaders/CMakeLists.txt b/src/Shaders/CMakeLists.txt index 95a50b182..f4591c4fe 100644 --- a/src/Shaders/CMakeLists.txt +++ b/src/Shaders/CMakeLists.txt @@ -1,7 +1,7 @@ corrade_add_resource(MagnumShaders_RCS MagnumShaders FlatShader2D.vert FlatShader3D.vert FlatShader.frag PhongShader.vert PhongShader.frag - TextShader2D.vert TextShader2D.frag + TextShader2D.vert TextShader3D.vert TextShader.frag VertexColorShader2D.vert VertexColorShader3D.vert VertexColorShader.frag compatibility.glsl) set(MagnumShaders_SRCS diff --git a/src/Shaders/TextShader.cpp b/src/Shaders/TextShader.cpp index a5d9a950b..e1265e784 100644 --- a/src/Shaders/TextShader.cpp +++ b/src/Shaders/TextShader.cpp @@ -24,17 +24,9 @@ namespace Magnum { namespace Shaders { namespace { - template struct ShaderName {}; - - template<> struct ShaderName<2> { - constexpr static const char* vertex() { return "TextShader2D.vert"; } - constexpr static const char* fragment() { return "TextShader2D.frag"; } - }; - - template<> struct ShaderName<3> { - constexpr static const char* vertex() { return "TextShader3D.vert"; } - constexpr static const char* fragment() { return "TextShader3D.frag"; } - }; + template constexpr const char* vertexShaderName(); + template<> constexpr const char* vertexShaderName<2>() { return "TextShader2D.vert"; } + template<> constexpr const char* vertexShaderName<3>() { return "TextShader3D.vert"; } } template TextShader::TextShader(): transformationProjectionMatrixUniform(0), colorUniform(1) { @@ -48,12 +40,12 @@ template TextShader::TextShader(): transfor Shader vertexShader(v, Shader::Type::Vertex); vertexShader.addSource(rs.get("compatibility.glsl")); - vertexShader.addSource(rs.get(ShaderName::vertex())); + vertexShader.addSource(rs.get(vertexShaderName())); AbstractTextShader::attachShader(vertexShader); Shader fragmentShader(v, Shader::Type::Fragment); fragmentShader.addSource(rs.get("compatibility.glsl")); - fragmentShader.addSource(rs.get(ShaderName::fragment())); + fragmentShader.addSource(rs.get("TextShader.frag")); AbstractTextShader::attachShader(fragmentShader); #ifndef MAGNUM_TARGET_GLES diff --git a/src/Shaders/TextShader2D.frag b/src/Shaders/TextShader.frag similarity index 100% rename from src/Shaders/TextShader2D.frag rename to src/Shaders/TextShader.frag diff --git a/src/Shaders/TextShader2D.vert b/src/Shaders/TextShader2D.vert index 9d030d59d..98ee96d84 100644 --- a/src/Shaders/TextShader2D.vert +++ b/src/Shaders/TextShader2D.vert @@ -20,6 +20,6 @@ in mediump vec2 textureCoordinates; out vec2 fragmentTextureCoordinates; void main() { - gl_Position = vec4(transformationProjectionMatrix*position, 0.0).xywz; + gl_Position.xywz = vec4(transformationProjectionMatrix*position, 0.0); fragmentTextureCoordinates = textureCoordinates; } diff --git a/src/Shaders/TextShader3D.vert b/src/Shaders/TextShader3D.vert new file mode 100644 index 000000000..5204e41b4 --- /dev/null +++ b/src/Shaders/TextShader3D.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 mediump vec2 textureCoordinates; +#else +in highp vec4 position; +in mediump vec2 textureCoordinates; +#endif + +out vec2 fragmentTextureCoordinates; + +void main() { + gl_Position = transformationProjectionMatrix*position; + fragmentTextureCoordinates = textureCoordinates; +}