Browse Source

Shaders: added missing 3D version of text shader.

pull/7/head
Vladimír Vondruš 13 years ago
parent
commit
0cba8db268
  1. 2
      src/Shaders/CMakeLists.txt
  2. 18
      src/Shaders/TextShader.cpp
  3. 0
      src/Shaders/TextShader.frag
  4. 2
      src/Shaders/TextShader2D.vert
  5. 25
      src/Shaders/TextShader3D.vert

2
src/Shaders/CMakeLists.txt

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

18
src/Shaders/TextShader.cpp

@ -24,17 +24,9 @@
namespace Magnum { namespace Shaders { namespace Magnum { namespace Shaders {
namespace { namespace {
template<std::uint8_t dimensions> struct ShaderName {}; template<std::uint8_t> constexpr const char* vertexShaderName();
template<> constexpr const char* vertexShaderName<2>() { return "TextShader2D.vert"; }
template<> struct ShaderName<2> { template<> constexpr const char* vertexShaderName<3>() { return "TextShader3D.vert"; }
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<std::uint8_t dimensions> TextShader<dimensions>::TextShader(): transformationProjectionMatrixUniform(0), colorUniform(1) { template<std::uint8_t dimensions> TextShader<dimensions>::TextShader(): transformationProjectionMatrixUniform(0), colorUniform(1) {
@ -48,12 +40,12 @@ template<std::uint8_t dimensions> TextShader<dimensions>::TextShader(): transfor
Shader vertexShader(v, Shader::Type::Vertex); Shader vertexShader(v, Shader::Type::Vertex);
vertexShader.addSource(rs.get("compatibility.glsl")); vertexShader.addSource(rs.get("compatibility.glsl"));
vertexShader.addSource(rs.get(ShaderName<dimensions>::vertex())); vertexShader.addSource(rs.get(vertexShaderName<dimensions>()));
AbstractTextShader<dimensions>::attachShader(vertexShader); AbstractTextShader<dimensions>::attachShader(vertexShader);
Shader fragmentShader(v, Shader::Type::Fragment); Shader fragmentShader(v, Shader::Type::Fragment);
fragmentShader.addSource(rs.get("compatibility.glsl")); fragmentShader.addSource(rs.get("compatibility.glsl"));
fragmentShader.addSource(rs.get(ShaderName<dimensions>::fragment())); fragmentShader.addSource(rs.get("TextShader.frag"));
AbstractTextShader<dimensions>::attachShader(fragmentShader); AbstractTextShader<dimensions>::attachShader(fragmentShader);
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES

0
src/Shaders/TextShader2D.frag → src/Shaders/TextShader.frag

2
src/Shaders/TextShader2D.vert

@ -20,6 +20,6 @@ in mediump vec2 textureCoordinates;
out vec2 fragmentTextureCoordinates; out vec2 fragmentTextureCoordinates;
void main() { void main() {
gl_Position = vec4(transformationProjectionMatrix*position, 0.0).xywz; gl_Position.xywz = vec4(transformationProjectionMatrix*position, 0.0);
fragmentTextureCoordinates = textureCoordinates; fragmentTextureCoordinates = textureCoordinates;
} }

25
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;
}
Loading…
Cancel
Save