Browse Source

Shaders: group whole vertex/fragment shader setup together.

pull/601/head
Vladimír Vondruš 3 years ago
parent
commit
afa2b37389
  1. 13
      src/Magnum/Shaders/DistanceFieldVectorGL.cpp
  2. 13
      src/Magnum/Shaders/FlatGL.cpp
  3. 20
      src/Magnum/Shaders/MeshVisualizerGL.cpp
  4. 15
      src/Magnum/Shaders/PhongGL.cpp
  5. 13
      src/Magnum/Shaders/VectorGL.cpp
  6. 13
      src/Magnum/Shaders/VertexColorGL.cpp

13
src/Magnum/Shaders/DistanceFieldVectorGL.cpp

@ -107,8 +107,6 @@ template<UnsignedInt dimensions> typename DistanceFieldVectorGL<dimensions>::Com
#endif
GL::Shader vert = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Vertex);
GL::Shader frag = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Fragment);
vert.addSource(configuration.flags() & Flag::TextureTransformation ? "#define TEXTURE_TRANSFORMATION\n"_s : ""_s)
.addSource(dimensions == 2 ? "#define TWO_DIMENSIONS\n"_s : "#define THREE_DIMENSIONS\n"_s);
#ifndef MAGNUM_TARGET_GLES2
@ -121,7 +119,10 @@ template<UnsignedInt dimensions> typename DistanceFieldVectorGL<dimensions>::Com
}
#endif
vert.addSource(rs.getString("generic.glsl"_s))
.addSource(rs.getString("Vector.vert"_s));
.addSource(rs.getString("Vector.vert"_s))
.submitCompile();
GL::Shader frag = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Fragment);
#ifndef MAGNUM_TARGET_GLES2
if(configuration.flags() >= Flag::UniformBuffers) {
frag.addSource(Utility::format(
@ -134,10 +135,8 @@ template<UnsignedInt dimensions> typename DistanceFieldVectorGL<dimensions>::Com
}
#endif
frag.addSource(rs.getString("generic.glsl"_s))
.addSource(rs.getString("DistanceFieldVector.frag"_s));
vert.submitCompile();
frag.submitCompile();
.addSource(rs.getString("DistanceFieldVector.frag"_s))
.submitCompile();
DistanceFieldVectorGL<dimensions> out{NoInit};
out._flags = configuration.flags();

13
src/Magnum/Shaders/FlatGL.cpp

@ -159,8 +159,6 @@ template<UnsignedInt dimensions> typename FlatGL<dimensions>::CompileState FlatG
#endif
GL::Shader vert = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Vertex);
GL::Shader frag = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Fragment);
vert.addSource((configuration.flags() & Flag::Textured
#ifndef MAGNUM_TARGET_GLES2
|| configuration.flags() >= Flag::ObjectIdTexture
@ -212,7 +210,10 @@ template<UnsignedInt dimensions> typename FlatGL<dimensions>::CompileState FlatG
}
#endif
vert.addSource(rs.getString("generic.glsl"_s))
.addSource(rs.getString("Flat.vert"_s));
.addSource(rs.getString("Flat.vert"_s))
.submitCompile();
GL::Shader frag = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Fragment);
frag.addSource(configuration.flags() & Flag::Textured ? "#define TEXTURED\n"_s : ""_s)
#ifndef MAGNUM_TARGET_GLES2
.addSource(configuration.flags() & Flag::TextureArrays ? "#define TEXTURE_ARRAYS\n"_s : ""_s)
@ -237,10 +238,8 @@ template<UnsignedInt dimensions> typename FlatGL<dimensions>::CompileState FlatG
}
#endif
frag.addSource(rs.getString("generic.glsl"_s))
.addSource(rs.getString("Flat.frag"_s));
vert.submitCompile();
frag.submitCompile();
.addSource(rs.getString("Flat.frag"_s))
.submitCompile();
out.attachShaders({vert, frag});

20
src/Magnum/Shaders/MeshVisualizerGL.cpp

@ -174,8 +174,6 @@ GL::Version MeshVisualizerGLBase::setupShaders(GL::Shader& vert, GL::Shader& fra
#endif
vert = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Vertex);
frag = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Fragment);
vert.addSource(flags & FlagBase::Wireframe ? "#define WIREFRAME_RENDERING\n"_s : ""_s)
#ifndef MAGNUM_TARGET_GLES2
.addSource(flags >= FlagBase::ObjectIdTexture ? "#define TEXTURED\n"_s : ""_s)
@ -232,6 +230,8 @@ GL::Version MeshVisualizerGLBase::setupShaders(GL::Shader& vert, GL::Shader& fra
vert.addSource(flags >= FlagBase::MultiDraw ? "#define MULTI_DRAW\n"_s : ""_s);
}
#endif
frag = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Fragment);
frag.addSource(flags & FlagBase::Wireframe ? "#define WIREFRAME_RENDERING\n"_s : ""_s)
#ifndef MAGNUM_TARGET_GLES2
.addSource(flags & FlagBase::ObjectId ? "#define OBJECT_ID\n"_s : ""_s)
@ -510,7 +510,9 @@ MeshVisualizerGL2D::CompileState MeshVisualizerGL2D::compile(const Configuration
.addSource((configuration.flags() & Flag::NoGeometryShader) || !(configuration.flags() & Flag::Wireframe) ?
"#define NO_GEOMETRY_SHADER\n"_s : ""_s)
.addSource(rs.getString("generic.glsl"_s))
.addSource(rs.getString("MeshVisualizer.vert"_s));
.addSource(rs.getString("MeshVisualizer.vert"_s))
.submitCompile();
frag
/* Pass NO_GEOMETRY_SHADER not only when NoGeometryShader but also when
nothing actually needs it, as that makes checks much simpler in
@ -522,8 +524,8 @@ MeshVisualizerGL2D::CompileState MeshVisualizerGL2D::compile(const Configuration
frag.addSource("#define TWO_DIMENSIONS\n"_s);
#endif
frag.addSource(rs.getString("generic.glsl"_s))
.addSource(rs.getString("MeshVisualizer.frag"_s));
.addSource(rs.getString("MeshVisualizer.frag"_s))
.submitCompile();
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
if(configuration.flags() & Flag::Wireframe && !(configuration.flags() & Flag::NoGeometryShader)) {
@ -551,16 +553,14 @@ MeshVisualizerGL2D::CompileState MeshVisualizerGL2D::compile(const Configuration
geom->addSource(configuration.flags() >= Flag::MultiDraw ? "#define MULTI_DRAW\n"_s : ""_s);
}
#endif
geom->addSource(rs.getString("MeshVisualizer.geom"_s));
(*geom)
.addSource(rs.getString("MeshVisualizer.geom"_s))
.submitCompile();
}
#else
static_cast<void>(version);
#endif
vert.submitCompile();
frag.submitCompile();
if(geom) geom->submitCompile();
out.attachShaders({vert, frag});
if(geom) out.attachShader(*geom);

15
src/Magnum/Shaders/PhongGL.cpp

@ -185,9 +185,6 @@ PhongGL::CompileState PhongGL::compile(const Configuration& configuration) {
1 : out._perInstanceJointCountUniform + 1;
#endif
GL::Shader vert = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Vertex);
GL::Shader frag = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Fragment);
#ifndef MAGNUM_TARGET_GLES
/* Initializer for the light color / position / range arrays -- we need a
list of initializers joined by commas. For GLES we'll simply upload the
@ -203,6 +200,7 @@ PhongGL::CompileState PhongGL::compile(const Configuration& configuration) {
("1.0/0.0, "_s*configuration.lightCount()).exceptSuffix(2));
#endif
GL::Shader vert = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Vertex);
vert.addSource((configuration.flags() & (Flag::AmbientTexture|Flag::DiffuseTexture|Flag::SpecularTexture|Flag::NormalTexture)
#ifndef MAGNUM_TARGET_GLES2
|| configuration.flags() >= Flag::ObjectIdTexture
@ -259,7 +257,10 @@ PhongGL::CompileState PhongGL::compile(const Configuration& configuration) {
}
#endif
vert.addSource(rs.getString("generic.glsl"_s))
.addSource(rs.getString("Phong.vert"_s));
.addSource(rs.getString("Phong.vert"_s))
.submitCompile();
GL::Shader frag = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Fragment);
frag.addSource(configuration.flags() & Flag::AmbientTexture ? "#define AMBIENT_TEXTURE\n"_s : ""_s)
.addSource(configuration.flags() & Flag::DiffuseTexture ? "#define DIFFUSE_TEXTURE\n"_s : ""_s)
.addSource(configuration.flags() & Flag::SpecularTexture ? "#define SPECULAR_TEXTURE\n"_s : ""_s)
@ -307,10 +308,8 @@ PhongGL::CompileState PhongGL::compile(const Configuration& configuration) {
frag.addSource(std::move(lightInitializer));
#endif
frag.addSource(rs.getString("generic.glsl"_s))
.addSource(rs.getString("Phong.frag"_s));
vert.submitCompile();
frag.submitCompile();
.addSource(rs.getString("Phong.frag"_s))
.submitCompile();
out.attachShaders({vert, frag});

13
src/Magnum/Shaders/VectorGL.cpp

@ -107,8 +107,6 @@ template<UnsignedInt dimensions> typename VectorGL<dimensions>::CompileState Vec
#endif
GL::Shader vert = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Vertex);
GL::Shader frag = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Fragment);
vert.addSource(configuration.flags() & Flag::TextureTransformation ? "#define TEXTURE_TRANSFORMATION\n"_s : ""_s)
.addSource(dimensions == 2 ? "#define TWO_DIMENSIONS\n"_s : "#define THREE_DIMENSIONS\n"_s);
#ifndef MAGNUM_TARGET_GLES2
@ -121,7 +119,10 @@ template<UnsignedInt dimensions> typename VectorGL<dimensions>::CompileState Vec
}
#endif
vert.addSource(rs.getString("generic.glsl"_s))
.addSource(rs.getString("Vector.vert"_s));
.addSource(rs.getString("Vector.vert"_s))
.submitCompile();
GL::Shader frag = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Fragment);
#ifndef MAGNUM_TARGET_GLES2
if(configuration.flags() >= Flag::UniformBuffers) {
frag.addSource(Utility::format(
@ -134,10 +135,8 @@ template<UnsignedInt dimensions> typename VectorGL<dimensions>::CompileState Vec
}
#endif
frag.addSource(rs.getString("generic.glsl"_s))
.addSource(rs.getString("Vector.frag"_s));
vert.submitCompile();
frag.submitCompile();
.addSource(rs.getString("Vector.frag"_s))
.submitCompile();
VectorGL out{NoInit};
out._flags = configuration.flags();

13
src/Magnum/Shaders/VertexColorGL.cpp

@ -98,8 +98,6 @@ template<UnsignedInt dimensions> typename VertexColorGL<dimensions>::CompileStat
#endif
GL::Shader vert = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Vertex);
GL::Shader frag = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Fragment);
vert.addSource(dimensions == 2 ? "#define TWO_DIMENSIONS\n"_s : "#define THREE_DIMENSIONS\n"_s);
#ifndef MAGNUM_TARGET_GLES2
if(configuration.flags() >= Flag::UniformBuffers) {
@ -111,12 +109,13 @@ template<UnsignedInt dimensions> typename VertexColorGL<dimensions>::CompileStat
}
#endif
vert.addSource(rs.getString("generic.glsl"_s))
.addSource(rs.getString("VertexColor.vert"_s));
frag.addSource(rs.getString("generic.glsl"_s))
.addSource(rs.getString("VertexColor.frag"_s));
.addSource(rs.getString("VertexColor.vert"_s))
.submitCompile();
vert.submitCompile();
frag.submitCompile();
GL::Shader frag = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Fragment);
frag.addSource(rs.getString("generic.glsl"_s))
.addSource(rs.getString("VertexColor.frag"_s))
.submitCompile();
VertexColorGL<dimensions> out{NoInit};
out._flags = configuration.flags();

Loading…
Cancel
Save