Browse Source

Shaders: don't define & format irrelevant skinning values for UBOs.

The UBO use case doesn't need any initializers or uniform locations for
these, it's just wasted allocations.
pull/617/head
Vladimír Vondruš 3 years ago
parent
commit
218aef5016
  1. 52
      src/Magnum/Shaders/FlatGL.cpp
  2. 52
      src/Magnum/Shaders/MeshVisualizerGL.cpp
  3. 56
      src/Magnum/Shaders/PhongGL.cpp

52
src/Magnum/Shaders/FlatGL.cpp

@ -179,27 +179,41 @@ template<UnsignedInt dimensions> typename FlatGL<dimensions>::CompileState FlatG
.addSource(configuration.flags() >= Flag::InstancedTextureOffset ? "#define INSTANCED_TEXTURE_OFFSET\n"_s : ""_s);
#ifndef MAGNUM_TARGET_GLES2
if(configuration.perVertexJointCount() || configuration.secondaryPerVertexJointCount()) {
vert.addSource(Utility::format(
"#define JOINT_COUNT {}\n"
"#define PER_VERTEX_JOINT_COUNT {}u\n"
"#define SECONDARY_PER_VERTEX_JOINT_COUNT {}u\n"
#ifndef MAGNUM_TARGET_GLES
"#define JOINT_MATRIX_INITIALIZER {}\n"
#endif
"#define PER_INSTANCE_JOINT_COUNT_LOCATION {}\n",
configuration.jointCount(),
configuration.perVertexJointCount(),
configuration.secondaryPerVertexJointCount(),
#ifndef MAGNUM_TARGET_GLES
((dimensions == 2 ? "mat3(1.0), "_s : "mat4(1.0), "_s)*configuration.jointCount()).exceptSuffix(2),
#endif
out._perInstanceJointCountUniform));
if(!(configuration.flags() >= Flag::UniformBuffers)) {
vert.addSource(Utility::format(
"#define JOINT_COUNT {}\n"
"#define PER_VERTEX_JOINT_COUNT {}u\n"
"#define SECONDARY_PER_VERTEX_JOINT_COUNT {}u\n"
#ifndef MAGNUM_TARGET_GLES
"#define JOINT_MATRIX_INITIALIZER {}\n"
#endif
"#define PER_INSTANCE_JOINT_COUNT_LOCATION {}\n",
configuration.jointCount(),
configuration.perVertexJointCount(),
configuration.secondaryPerVertexJointCount(),
#ifndef MAGNUM_TARGET_GLES
((dimensions == 2 ? "mat3(1.0), "_s : "mat4(1.0), "_s)*configuration.jointCount()).exceptSuffix(2),
#endif
out._perInstanceJointCountUniform));
} else {
vert.addSource(Utility::format(
"#define JOINT_COUNT {}\n"
"#define PER_VERTEX_JOINT_COUNT {}u\n"
"#define SECONDARY_PER_VERTEX_JOINT_COUNT {}u\n",
configuration.jointCount(),
configuration.perVertexJointCount(),
configuration.secondaryPerVertexJointCount()));
}
}
if(configuration.flags() >= Flag::DynamicPerVertexJointCount) {
vert.addSource(Utility::format(
"#define DYNAMIC_PER_VERTEX_JOINT_COUNT\n"
"#define PER_VERTEX_JOINT_COUNT_LOCATION {}\n",
out._perVertexJointCountUniform));
if(!(configuration.flags() >= Flag::UniformBuffers)) {
vert.addSource(Utility::format(
"#define DYNAMIC_PER_VERTEX_JOINT_COUNT\n"
"#define PER_VERTEX_JOINT_COUNT_LOCATION {}\n",
out._perVertexJointCountUniform));
} else {
vert.addSource("#define DYNAMIC_PER_VERTEX_JOINT_COUNT\n"_s);
}
}
#endif
#ifndef MAGNUM_TARGET_GLES2

52
src/Magnum/Shaders/MeshVisualizerGL.cpp

@ -198,27 +198,41 @@ GL::Version MeshVisualizerGLBase::setupShaders(GL::Shader& vert, GL::Shader& fra
;
#ifndef MAGNUM_TARGET_GLES2
if(perVertexJointCount || secondaryPerVertexJointCount) {
vert.addSource(Utility::format(
"#define JOINT_COUNT {}\n"
"#define PER_VERTEX_JOINT_COUNT {}u\n"
"#define SECONDARY_PER_VERTEX_JOINT_COUNT {}u\n"
#ifndef MAGNUM_TARGET_GLES
"#define JOINT_MATRIX_INITIALIZER {}\n"
#endif
"#define PER_INSTANCE_JOINT_COUNT_LOCATION {}\n",
jointCount,
perVertexJointCount,
secondaryPerVertexJointCount,
#ifndef MAGNUM_TARGET_GLES
((dimensions == 2 ? "mat3(1.0), "_s : "mat4(1.0), "_s)*jointCount).exceptSuffix(2),
#endif
perInstanceJointCountUniform));
if(!(flags >= FlagBase::UniformBuffers)) {
vert.addSource(Utility::format(
"#define JOINT_COUNT {}\n"
"#define PER_VERTEX_JOINT_COUNT {}u\n"
"#define SECONDARY_PER_VERTEX_JOINT_COUNT {}u\n"
#ifndef MAGNUM_TARGET_GLES
"#define JOINT_MATRIX_INITIALIZER {}\n"
#endif
"#define PER_INSTANCE_JOINT_COUNT_LOCATION {}\n",
jointCount,
perVertexJointCount,
secondaryPerVertexJointCount,
#ifndef MAGNUM_TARGET_GLES
((dimensions == 2 ? "mat3(1.0), "_s : "mat4(1.0), "_s)*jointCount).exceptSuffix(2),
#endif
perInstanceJointCountUniform));
} else {
vert.addSource(Utility::format(
"#define JOINT_COUNT {}\n"
"#define PER_VERTEX_JOINT_COUNT {}u\n"
"#define SECONDARY_PER_VERTEX_JOINT_COUNT {}u\n",
jointCount,
perVertexJointCount,
secondaryPerVertexJointCount));
}
}
if(flags >= FlagBase::DynamicPerVertexJointCount) {
vert.addSource(Utility::format(
"#define DYNAMIC_PER_VERTEX_JOINT_COUNT\n"
"#define PER_VERTEX_JOINT_COUNT_LOCATION {}\n",
perVertexJointCountUniform));
if(!(flags >= FlagBase::UniformBuffers)) {
vert.addSource(Utility::format(
"#define DYNAMIC_PER_VERTEX_JOINT_COUNT\n"
"#define PER_VERTEX_JOINT_COUNT_LOCATION {}\n",
perVertexJointCountUniform));
} else {
vert.addSource("#define DYNAMIC_PER_VERTEX_JOINT_COUNT\n"_s);
}
}
#endif
#ifndef MAGNUM_TARGET_GLES2

56
src/Magnum/Shaders/PhongGL.cpp

@ -224,29 +224,43 @@ PhongGL::CompileState PhongGL::compile(const Configuration& configuration) {
.addSource(configuration.flags() >= Flag::InstancedTextureOffset ? "#define INSTANCED_TEXTURE_OFFSET\n"_s : ""_s);
#ifndef MAGNUM_TARGET_GLES2
if(configuration.perVertexJointCount() || configuration.secondaryPerVertexJointCount()) {
vert.addSource(Utility::format(
"#define JOINT_COUNT {}\n"
"#define PER_VERTEX_JOINT_COUNT {}u\n"
"#define SECONDARY_PER_VERTEX_JOINT_COUNT {}u\n"
"#define JOINT_MATRICES_LOCATION {}\n"
#ifndef MAGNUM_TARGET_GLES
"#define JOINT_MATRIX_INITIALIZER {}\n"
#endif
"#define PER_INSTANCE_JOINT_COUNT_LOCATION {}\n",
configuration.jointCount(),
configuration.perVertexJointCount(),
configuration.secondaryPerVertexJointCount(),
out._jointMatricesUniform,
#ifndef MAGNUM_TARGET_GLES
("mat4(1.0), "_s*configuration.jointCount()).exceptSuffix(2),
#endif
out._perInstanceJointCountUniform));
if(!(configuration.flags() >= Flag::UniformBuffers)) {
vert.addSource(Utility::format(
"#define JOINT_COUNT {}\n"
"#define PER_VERTEX_JOINT_COUNT {}u\n"
"#define SECONDARY_PER_VERTEX_JOINT_COUNT {}u\n"
"#define JOINT_MATRICES_LOCATION {}\n"
#ifndef MAGNUM_TARGET_GLES
"#define JOINT_MATRIX_INITIALIZER {}\n"
#endif
"#define PER_INSTANCE_JOINT_COUNT_LOCATION {}\n",
configuration.jointCount(),
configuration.perVertexJointCount(),
configuration.secondaryPerVertexJointCount(),
out._jointMatricesUniform,
#ifndef MAGNUM_TARGET_GLES
("mat4(1.0), "_s*configuration.jointCount()).exceptSuffix(2),
#endif
out._perInstanceJointCountUniform));
} else {
vert.addSource(Utility::format(
"#define JOINT_COUNT {}\n"
"#define PER_VERTEX_JOINT_COUNT {}u\n"
"#define SECONDARY_PER_VERTEX_JOINT_COUNT {}u\n",
configuration.jointCount(),
configuration.perVertexJointCount(),
configuration.secondaryPerVertexJointCount()));
}
}
if(configuration.flags() >= Flag::DynamicPerVertexJointCount) {
vert.addSource(Utility::format(
"#define DYNAMIC_PER_VERTEX_JOINT_COUNT\n"
"#define PER_VERTEX_JOINT_COUNT_LOCATION {}\n",
out._perVertexJointCountUniform));
if(!(configuration.flags() >= Flag::UniformBuffers)) {
vert.addSource(Utility::format(
"#define DYNAMIC_PER_VERTEX_JOINT_COUNT\n"
"#define PER_VERTEX_JOINT_COUNT_LOCATION {}\n",
out._perVertexJointCountUniform));
} else {
vert.addSource("#define DYNAMIC_PER_VERTEX_JOINT_COUNT\n"_s);
}
}
#endif
#ifndef MAGNUM_TARGET_GLES2

Loading…
Cancel
Save