Browse Source

Shaders: delete 8 kB of needless shader code.

I get the best ideas on the shitter. I should go there more often.
pull/430/head
Vladimír Vondruš 6 years ago
parent
commit
fff1b6e5cf
  1. 41
      src/Magnum/Shaders/AbstractVector.vert
  2. 72
      src/Magnum/Shaders/AbstractVector2D.vert
  3. 72
      src/Magnum/Shaders/AbstractVector3D.vert
  4. 9
      src/Magnum/Shaders/DistanceFieldVector.cpp
  5. 7
      src/Magnum/Shaders/Flat.cpp
  6. 22
      src/Magnum/Shaders/Flat.vert
  7. 9
      src/Magnum/Shaders/Vector.cpp
  8. 11
      src/Magnum/Shaders/VertexColor.cpp
  9. 23
      src/Magnum/Shaders/VertexColor.vert
  10. 55
      src/Magnum/Shaders/VertexColor3D.vert
  11. 15
      src/Magnum/Shaders/resources.conf

41
src/Magnum/Shaders/Flat3D.vert → src/Magnum/Shaders/AbstractVector.vert

@ -31,11 +31,21 @@
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 0)
#endif
#ifdef TWO_DIMENSIONS
uniform highp mat3 transformationProjectionMatrix
#ifndef GL_ES
= mat3(1.0)
#endif
;
#elif defined(THREE_DIMENSIONS)
uniform highp mat4 transformationProjectionMatrix
#ifndef GL_ES
= mat4(1.0)
#endif
;
#else
#error
#endif
#ifdef TEXTURE_TRANSFORMATION
#ifdef EXPLICIT_UNIFORM_LOCATION
@ -51,31 +61,30 @@ uniform mediump mat3 textureMatrix
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = POSITION_ATTRIBUTE_LOCATION)
#endif
#ifdef TWO_DIMENSIONS
in highp vec2 position;
#elif defined(THREE_DIMENSIONS)
in highp vec4 position;
#else
#error
#endif
#ifdef TEXTURED
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = TEXTURECOORDINATES_ATTRIBUTE_LOCATION)
#endif
in mediump vec2 textureCoordinates;
out mediump vec2 interpolatedTextureCoordinates;
#endif
#ifdef VERTEX_COLOR
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = COLOR_ATTRIBUTE_LOCATION)
#endif
in lowp vec4 vertexColor;
out lowp vec4 interpolatedVertexColor;
#endif
void main() {
#ifdef TWO_DIMENSIONS
gl_Position.xywz = vec4(transformationProjectionMatrix*vec3(position, 1.0), 0.0);
#elif defined(THREE_DIMENSIONS)
gl_Position = transformationProjectionMatrix*position;
#else
#error
#endif
#ifdef TEXTURED
/* Texture coordinates, if needed */
interpolatedTextureCoordinates =
#ifdef TEXTURE_TRANSFORMATION
(textureMatrix*vec3(textureCoordinates, 1.0)).xy
@ -83,10 +92,4 @@ void main() {
textureCoordinates
#endif
;
#endif
#ifdef VERTEX_COLOR
/* Vertex colors, if enabled */
interpolatedVertexColor = vertexColor;
#endif
}

72
src/Magnum/Shaders/AbstractVector2D.vert

@ -1,72 +0,0 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019
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.
*/
#ifndef NEW_GLSL
#define in attribute
#define out varying
#endif
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 0)
#endif
uniform highp mat3 transformationProjectionMatrix
#ifndef GL_ES
= mat3(1.0)
#endif
;
#ifdef TEXTURE_TRANSFORMATION
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 1)
#endif
uniform mediump mat3 textureMatrix
#ifndef GL_ES
= mat3(1.0)
#endif
;
#endif
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = POSITION_ATTRIBUTE_LOCATION)
#endif
in highp vec2 position;
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = TEXTURECOORDINATES_ATTRIBUTE_LOCATION)
#endif
in mediump vec2 textureCoordinates;
out mediump vec2 interpolatedTextureCoordinates;
void main() {
gl_Position.xywz = vec4(transformationProjectionMatrix*vec3(position, 1.0), 0.0);
interpolatedTextureCoordinates =
#ifdef TEXTURE_TRANSFORMATION
(textureMatrix*vec3(textureCoordinates, 1.0)).xy
#else
textureCoordinates
#endif
;
}

72
src/Magnum/Shaders/AbstractVector3D.vert

@ -1,72 +0,0 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019
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.
*/
#ifndef NEW_GLSL
#define in attribute
#define out varying
#endif
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 0)
#endif
uniform highp mat4 transformationProjectionMatrix
#ifndef GL_ES
= mat4(1.0)
#endif
;
#ifdef TEXTURE_TRANSFORMATION
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 1)
#endif
uniform mediump mat3 textureMatrix
#ifndef GL_ES
= mat3(1.0)
#endif
;
#endif
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = POSITION_ATTRIBUTE_LOCATION)
#endif
in highp vec4 position;
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = TEXTURECOORDINATES_ATTRIBUTE_LOCATION)
#endif
in mediump vec2 textureCoordinates;
out mediump vec2 interpolatedTextureCoordinates;
void main() {
gl_Position = transformationProjectionMatrix*position;
interpolatedTextureCoordinates =
#ifdef TEXTURE_TRANSFORMATION
(textureMatrix*vec3(textureCoordinates, 1.0)).xy
#else
textureCoordinates
#endif
;
}

9
src/Magnum/Shaders/DistanceFieldVector.cpp

@ -40,12 +40,6 @@
namespace Magnum { namespace Shaders {
namespace {
template<UnsignedInt> constexpr const char* vertexShaderName();
template<> constexpr const char* vertexShaderName<2>() { return "AbstractVector2D.vert"; }
template<> constexpr const char* vertexShaderName<3>() { return "AbstractVector3D.vert"; }
}
template<UnsignedInt dimensions> DistanceFieldVector<dimensions>::DistanceFieldVector(const Flags flags): _flags{flags} {
#ifdef MAGNUM_BUILD_STATIC
/* Import resources on static build, if not already */
@ -64,8 +58,9 @@ template<UnsignedInt dimensions> DistanceFieldVector<dimensions>::DistanceFieldV
GL::Shader frag = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Fragment);
vert.addSource(flags & Flag::TextureTransformation ? "#define TEXTURE_TRANSFORMATION\n" : "")
.addSource(dimensions == 2 ? "#define TWO_DIMENSIONS\n" : "#define THREE_DIMENSIONS\n")
.addSource(rs.get("generic.glsl"))
.addSource(rs.get(vertexShaderName<dimensions>()));
.addSource(rs.get("AbstractVector.vert"));
frag.addSource(rs.get("generic.glsl"))
.addSource(rs.get("DistanceFieldVector.frag"));

7
src/Magnum/Shaders/Flat.cpp

@ -43,10 +43,6 @@ namespace Magnum { namespace Shaders {
namespace {
enum: Int { TextureLayer = 0 };
template<UnsignedInt> constexpr const char* vertexShaderName();
template<> constexpr const char* vertexShaderName<2>() { return "Flat2D.vert"; }
template<> constexpr const char* vertexShaderName<3>() { return "Flat3D.vert"; }
}
template<UnsignedInt dimensions> Flat<dimensions>::Flat(const Flags flags): _flags(flags) {
@ -72,8 +68,9 @@ template<UnsignedInt dimensions> Flat<dimensions>::Flat(const Flags flags): _fla
vert.addSource(flags & Flag::Textured ? "#define TEXTURED\n" : "")
.addSource(flags & Flag::VertexColor ? "#define VERTEX_COLOR\n" : "")
.addSource(flags & Flag::TextureTransformation ? "#define TEXTURE_TRANSFORMATION\n" : "")
.addSource(dimensions == 2 ? "#define TWO_DIMENSIONS\n" : "#define THREE_DIMENSIONS\n")
.addSource(rs.get("generic.glsl"))
.addSource(rs.get(vertexShaderName<dimensions>()));
.addSource(rs.get("Flat.vert"));
frag.addSource(flags & Flag::Textured ? "#define TEXTURED\n" : "")
.addSource(flags & Flag::AlphaMask ? "#define ALPHA_MASK\n" : "")
.addSource(flags & Flag::VertexColor ? "#define VERTEX_COLOR\n" : "")

22
src/Magnum/Shaders/Flat2D.vert → src/Magnum/Shaders/Flat.vert

@ -31,11 +31,21 @@
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 0)
#endif
#ifdef TWO_DIMENSIONS
uniform highp mat3 transformationProjectionMatrix
#ifndef GL_ES
= mat3(1.0)
#endif
;
#elif defined(THREE_DIMENSIONS)
uniform highp mat4 transformationProjectionMatrix
#ifndef GL_ES
= mat4(1.0)
#endif
;
#else
#error
#endif
#ifdef TEXTURE_TRANSFORMATION
#ifdef EXPLICIT_UNIFORM_LOCATION
@ -51,7 +61,13 @@ uniform mediump mat3 textureMatrix
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = POSITION_ATTRIBUTE_LOCATION)
#endif
#ifdef TWO_DIMENSIONS
in highp vec2 position;
#elif defined(THREE_DIMENSIONS)
in highp vec4 position;
#else
#error
#endif
#ifdef TEXTURED
#ifdef EXPLICIT_ATTRIB_LOCATION
@ -72,7 +88,13 @@ out lowp vec4 interpolatedVertexColor;
#endif
void main() {
#ifdef TWO_DIMENSIONS
gl_Position.xywz = vec4(transformationProjectionMatrix*vec3(position, 1.0), 0.0);
#elif defined(THREE_DIMENSIONS)
gl_Position = transformationProjectionMatrix*position;
#else
#error
#endif
#ifdef TEXTURED
/* Texture coordinates, if needed */

9
src/Magnum/Shaders/Vector.cpp

@ -40,12 +40,6 @@
namespace Magnum { namespace Shaders {
namespace {
template<UnsignedInt> constexpr const char* vertexShaderName();
template<> constexpr const char* vertexShaderName<2>() { return "AbstractVector2D.vert"; }
template<> constexpr const char* vertexShaderName<3>() { return "AbstractVector3D.vert"; }
}
template<UnsignedInt dimensions> Vector<dimensions>::Vector(const Flags flags): _flags{flags} {
#ifdef MAGNUM_BUILD_STATIC
/* Import resources on static build, if not already */
@ -64,8 +58,9 @@ template<UnsignedInt dimensions> Vector<dimensions>::Vector(const Flags flags):
GL::Shader frag = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Fragment);
vert.addSource(flags & Flag::TextureTransformation ? "#define TEXTURE_TRANSFORMATION\n" : "")
.addSource(dimensions == 2 ? "#define TWO_DIMENSIONS\n" : "#define THREE_DIMENSIONS\n")
.addSource(rs.get("generic.glsl"))
.addSource(rs.get(vertexShaderName<dimensions>()));
.addSource(rs.get("AbstractVector.vert"));
frag.addSource(rs.get("generic.glsl"))
.addSource(rs.get("Vector.frag"));

11
src/Magnum/Shaders/VertexColor.cpp

@ -39,12 +39,6 @@
namespace Magnum { namespace Shaders {
namespace {
template<UnsignedInt> constexpr const char* vertexShaderName();
template<> constexpr const char* vertexShaderName<2>() { return "VertexColor2D.vert"; }
template<> constexpr const char* vertexShaderName<3>() { return "VertexColor3D.vert"; }
}
template<UnsignedInt dimensions> VertexColor<dimensions>::VertexColor() {
#ifdef MAGNUM_BUILD_STATIC
/* Import resources on static build, if not already */
@ -62,8 +56,9 @@ template<UnsignedInt dimensions> VertexColor<dimensions>::VertexColor() {
GL::Shader vert = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Vertex);
GL::Shader frag = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Fragment);
vert.addSource(rs.get("generic.glsl"))
.addSource(rs.get(vertexShaderName<dimensions>()));
vert.addSource(dimensions == 2 ? "#define TWO_DIMENSIONS\n" : "#define THREE_DIMENSIONS\n")
.addSource(rs.get("generic.glsl"))
.addSource(rs.get("VertexColor.vert"));
frag.addSource(rs.get("generic.glsl"))
.addSource(rs.get("VertexColor.frag"));

23
src/Magnum/Shaders/VertexColor2D.vert → src/Magnum/Shaders/VertexColor.vert

@ -31,16 +31,32 @@
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 0)
#endif
#ifdef TWO_DIMENSIONS
uniform highp mat3 transformationProjectionMatrix
#ifndef GL_ES
= mat3(1.0)
#endif
;
#elif defined(THREE_DIMENSIONS)
uniform highp mat4 transformationProjectionMatrix
#ifndef GL_ES
= mat4(1.0)
#endif
;
#else
#error
#endif
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = POSITION_ATTRIBUTE_LOCATION)
#endif
#ifdef TWO_DIMENSIONS
in highp vec2 position;
#elif defined(THREE_DIMENSIONS)
in highp vec4 position;
#else
#error
#endif
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = COLOR_ATTRIBUTE_LOCATION)
@ -50,6 +66,13 @@ in lowp vec4 color;
out lowp vec4 interpolatedColor;
void main() {
#ifdef TWO_DIMENSIONS
gl_Position.xywz = vec4(transformationProjectionMatrix*vec3(position, 1.0), 0.0);
#elif defined(THREE_DIMENSIONS)
gl_Position = transformationProjectionMatrix*position;
#else
#error
#endif
interpolatedColor = color;
}

55
src/Magnum/Shaders/VertexColor3D.vert

@ -1,55 +0,0 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019
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.
*/
#ifndef NEW_GLSL
#define in attribute
#define out varying
#endif
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 0)
#endif
uniform mat4 transformationProjectionMatrix
#ifndef GL_ES
= mat4(1.0)
#endif
;
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = POSITION_ATTRIBUTE_LOCATION)
#endif
in highp vec4 position;
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = COLOR_ATTRIBUTE_LOCATION)
#endif
in lowp vec4 color;
out lowp vec4 interpolatedColor;
void main() {
gl_Position = transformationProjectionMatrix*position;
interpolatedColor = color;
}

15
src/Magnum/Shaders/resources.conf

@ -1,16 +1,10 @@
group=MagnumShaders
[file]
filename=AbstractVector2D.vert
filename=AbstractVector.vert
[file]
filename=AbstractVector3D.vert
[file]
filename=Flat2D.vert
[file]
filename=Flat3D.vert
filename=Flat.vert
[file]
filename=Flat.frag
@ -43,10 +37,7 @@ filename=Vector.frag
filename=DistanceFieldVector.frag
[file]
filename=VertexColor2D.vert
[file]
filename=VertexColor3D.vert
filename=VertexColor.vert
[file]
filename=VertexColor.frag

Loading…
Cancel
Save