Browse Source

Shaders: use generic definitions also in GLSL sources.

So each sourcs doesn't need to be manually rewritten each time the
generic definition changes.
pull/34/head
Vladimír Vondruš 13 years ago
parent
commit
51db425bdb
  1. 4
      src/Shaders/AbstractVector2D.vert
  2. 4
      src/Shaders/AbstractVector3D.vert
  3. 1
      src/Shaders/DistanceFieldVector.cpp
  4. 1
      src/Shaders/Flat.cpp
  5. 4
      src/Shaders/Flat2D.vert
  6. 4
      src/Shaders/Flat3D.vert
  7. 1
      src/Shaders/MeshVisualizer.cpp
  8. 2
      src/Shaders/MeshVisualizer.vert
  9. 1
      src/Shaders/Phong.cpp
  10. 6
      src/Shaders/Phong.vert
  11. 1
      src/Shaders/Vector.cpp
  12. 1
      src/Shaders/VertexColor.cpp
  13. 2
      src/Shaders/VertexColor2D.vert
  14. 2
      src/Shaders/VertexColor3D.vert
  15. 27
      src/Shaders/generic.glsl
  16. 3
      src/Shaders/resources.conf

4
src/Shaders/AbstractVector2D.vert

@ -34,8 +34,8 @@ uniform highp mat3 transformationProjectionMatrix;
#endif
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = 0) in highp vec2 position;
layout(location = 1) in mediump vec2 textureCoordinates;
layout(location = POSITION_ATTRIBUTE_LOCATION) in highp vec2 position;
layout(location = TEXTURECOORDINATES_ATTRIBUTE_LOCATION) in mediump vec2 textureCoordinates;
#else
in highp vec2 position;
in mediump vec2 textureCoordinates;

4
src/Shaders/AbstractVector3D.vert

@ -34,8 +34,8 @@ uniform highp mat4 transformationProjectionMatrix;
#endif
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = 0) in highp vec4 position;
layout(location = 1) in mediump vec2 textureCoordinates;
layout(location = POSITION_ATTRIBUTE_LOCATION) in highp vec4 position;
layout(location = TEXTURECOORDINATES_ATTRIBUTE_LOCATION) in mediump vec2 textureCoordinates;
#else
in highp vec4 position;
in mediump vec2 textureCoordinates;

1
src/Shaders/DistanceFieldVector.cpp

@ -49,6 +49,7 @@ template<UnsignedInt dimensions> DistanceFieldVector<dimensions>::DistanceFieldV
Shader frag(version, Shader::Type::Vertex);
frag.addSource(rs.get("compatibility.glsl"))
.addSource(rs.get("generic.glsl"))
.addSource(rs.get(vertexShaderName<dimensions>()));
CORRADE_INTERNAL_ASSERT_OUTPUT(frag.compile());
AbstractShaderProgram::attachShader(frag);

1
src/Shaders/Flat.cpp

@ -49,6 +49,7 @@ template<UnsignedInt dimensions> Flat<dimensions>::Flat(const Flags flags): tran
Shader vert(version, Shader::Type::Vertex);
vert.addSource(flags & Flag::Textured ? "#define TEXTURED\n" : "")
.addSource(rs.get("compatibility.glsl"))
.addSource(rs.get("generic.glsl"))
.addSource(rs.get(vertexShaderName<dimensions>()));
CORRADE_INTERNAL_ASSERT_OUTPUT(vert.compile());
attachShader(vert);

4
src/Shaders/Flat2D.vert

@ -34,14 +34,14 @@ uniform highp mat3 transformationProjectionMatrix;
#endif
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = 0) in highp vec2 position;
layout(location = POSITION_ATTRIBUTE_LOCATION) in highp vec2 position;
#else
in highp vec2 position;
#endif
#ifdef TEXTURED
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = 1) in mediump vec2 textureCoords;
layout(location = TEXTURECOORDINATES_ATTRIBUTE_LOCATION) in mediump vec2 textureCoords;
#else
in mediump vec2 textureCoords;
#endif

4
src/Shaders/Flat3D.vert

@ -34,14 +34,14 @@ uniform highp mat4 transformationProjectionMatrix;
#endif
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = 0) in highp vec4 position;
layout(location = POSITION_ATTRIBUTE_LOCATION) in highp vec4 position;
#else
in highp vec4 position;
#endif
#ifdef TEXTURED
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = 1) in mediump vec2 textureCoords;
layout(location = TEXTURECOORDINATES_ATTRIBUTE_LOCATION) in mediump vec2 textureCoords;
#else
in mediump vec2 textureCoords;
#endif

1
src/Shaders/MeshVisualizer.cpp

@ -56,6 +56,7 @@ MeshVisualizer::MeshVisualizer(const Flags flags): flags(flags), transformationP
vert.addSource(flags & Flag::Wireframe ? "#define WIREFRAME_RENDERING\n" : "")
.addSource(flags & Flag::NoGeometryShader ? "#define NO_GEOMETRY_SHADER\n" : "")
.addSource(rs.get("compatibility.glsl"))
.addSource(rs.get("generic.glsl"))
.addSource(rs.get("MeshVisualizer.vert"));
CORRADE_INTERNAL_ASSERT_OUTPUT(vert.compile());
vert.compile();

2
src/Shaders/MeshVisualizer.vert

@ -34,7 +34,7 @@ uniform highp mat4 transformationProjectionMatrix;
#endif
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = 0) highp in vec4 position;
layout(location = POSITION_ATTRIBUTE_LOCATION) highp in vec4 position;
#else
in highp vec4 position;
#endif

1
src/Shaders/Phong.cpp

@ -43,6 +43,7 @@ Phong::Phong(const Flags flags): transformationMatrixUniform(0), projectionMatri
Shader vert(version, Shader::Type::Vertex);
vert.addSource(flags ? "#define TEXTURED\n" : "")
.addSource(rs.get("compatibility.glsl"))
.addSource(rs.get("generic.glsl"))
.addSource(rs.get("Phong.vert"));
CORRADE_INTERNAL_ASSERT_OUTPUT(vert.compile());
attachShader(vert);

6
src/Shaders/Phong.vert

@ -40,8 +40,8 @@ uniform highp vec3 light;
#endif
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = 0) in highp vec4 position;
layout(location = 2) in mediump vec3 normal;
layout(location = POSITION_ATTRIBUTE_LOCATION) in highp vec4 position;
layout(location = NORMAL_ATTRIBUTE_LOCATION) in mediump vec3 normal;
#else
in highp vec4 position;
in mediump vec3 normal;
@ -49,7 +49,7 @@ in mediump vec3 normal;
#ifdef TEXTURED
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = 1) in mediump vec2 textureCoords;
layout(location = TEXTURECOORDINATES_ATTRIBUTE_LOCATION) in mediump vec2 textureCoords;
#else
in mediump vec2 textureCoords;
#endif

1
src/Shaders/Vector.cpp

@ -49,6 +49,7 @@ template<UnsignedInt dimensions> Vector<dimensions>::Vector(): transformationPro
Shader vert(version, Shader::Type::Vertex);
vert.addSource(rs.get("compatibility.glsl"))
.addSource(rs.get("generic.glsl"))
.addSource(rs.get(vertexShaderName<dimensions>()));
CORRADE_INTERNAL_ASSERT_OUTPUT(vert.compile());
AbstractShaderProgram::attachShader(vert);

1
src/Shaders/VertexColor.cpp

@ -48,6 +48,7 @@ template<UnsignedInt dimensions> VertexColor<dimensions>::VertexColor(): transfo
Shader vert(version, Shader::Type::Vertex);
vert.addSource(rs.get("compatibility.glsl"))
.addSource(rs.get("generic.glsl"))
.addSource(rs.get(vertexShaderName<dimensions>()));
CORRADE_INTERNAL_ASSERT_OUTPUT(vert.compile());
attachShader(vert);

2
src/Shaders/VertexColor2D.vert

@ -38,7 +38,7 @@ uniform highp mat3 transformationProjectionMatrix;
#endif
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = 0) in highp vec2 position;
layout(location = POSITION_ATTRIBUTE_LOCATION) in highp vec2 position;
layout(location = 3) in lowp vec3 color;
#else
in highp vec2 position;

2
src/Shaders/VertexColor3D.vert

@ -38,7 +38,7 @@ uniform highp mat4 transformationProjectionMatrix;
#endif
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = 0) in highp vec4 position;
layout(location = POSITION_ATTRIBUTE_LOCATION) in highp vec4 position;
layout(location = 3) in lowp vec3 color;
#else
in highp vec4 position;

27
src/Shaders/generic.glsl

@ -0,0 +1,27 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#define POSITION_ATTRIBUTE_LOCATION 0
#define TEXTURECOORDINATES_ATTRIBUTE_LOCATION 1
#define NORMAL_ATTRIBUTE_LOCATION 2

3
src/Shaders/resources.conf

@ -18,6 +18,9 @@ filename=Flat.frag
[file]
filename=FullScreenTriangle.glsl
[file]
filename=generic.glsl
[file]
filename=MeshVisualizer.vert

Loading…
Cancel
Save