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); .addSource(configuration.flags() >= Flag::InstancedTextureOffset ? "#define INSTANCED_TEXTURE_OFFSET\n"_s : ""_s);
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(configuration.perVertexJointCount() || configuration.secondaryPerVertexJointCount()) { if(configuration.perVertexJointCount() || configuration.secondaryPerVertexJointCount()) {
vert.addSource(Utility::format( if(!(configuration.flags() >= Flag::UniformBuffers)) {
"#define JOINT_COUNT {}\n" vert.addSource(Utility::format(
"#define PER_VERTEX_JOINT_COUNT {}u\n" "#define JOINT_COUNT {}\n"
"#define SECONDARY_PER_VERTEX_JOINT_COUNT {}u\n" "#define PER_VERTEX_JOINT_COUNT {}u\n"
#ifndef MAGNUM_TARGET_GLES "#define SECONDARY_PER_VERTEX_JOINT_COUNT {}u\n"
"#define JOINT_MATRIX_INITIALIZER {}\n" #ifndef MAGNUM_TARGET_GLES
#endif "#define JOINT_MATRIX_INITIALIZER {}\n"
"#define PER_INSTANCE_JOINT_COUNT_LOCATION {}\n", #endif
configuration.jointCount(), "#define PER_INSTANCE_JOINT_COUNT_LOCATION {}\n",
configuration.perVertexJointCount(), configuration.jointCount(),
configuration.secondaryPerVertexJointCount(), configuration.perVertexJointCount(),
#ifndef MAGNUM_TARGET_GLES configuration.secondaryPerVertexJointCount(),
((dimensions == 2 ? "mat3(1.0), "_s : "mat4(1.0), "_s)*configuration.jointCount()).exceptSuffix(2), #ifndef MAGNUM_TARGET_GLES
#endif ((dimensions == 2 ? "mat3(1.0), "_s : "mat4(1.0), "_s)*configuration.jointCount()).exceptSuffix(2),
out._perInstanceJointCountUniform)); #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) { if(configuration.flags() >= Flag::DynamicPerVertexJointCount) {
vert.addSource(Utility::format( if(!(configuration.flags() >= Flag::UniformBuffers)) {
"#define DYNAMIC_PER_VERTEX_JOINT_COUNT\n" vert.addSource(Utility::format(
"#define PER_VERTEX_JOINT_COUNT_LOCATION {}\n", "#define DYNAMIC_PER_VERTEX_JOINT_COUNT\n"
out._perVertexJointCountUniform)); "#define PER_VERTEX_JOINT_COUNT_LOCATION {}\n",
out._perVertexJointCountUniform));
} else {
vert.addSource("#define DYNAMIC_PER_VERTEX_JOINT_COUNT\n"_s);
}
} }
#endif #endif
#ifndef MAGNUM_TARGET_GLES2 #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 #ifndef MAGNUM_TARGET_GLES2
if(perVertexJointCount || secondaryPerVertexJointCount) { if(perVertexJointCount || secondaryPerVertexJointCount) {
vert.addSource(Utility::format( if(!(flags >= FlagBase::UniformBuffers)) {
"#define JOINT_COUNT {}\n" vert.addSource(Utility::format(
"#define PER_VERTEX_JOINT_COUNT {}u\n" "#define JOINT_COUNT {}\n"
"#define SECONDARY_PER_VERTEX_JOINT_COUNT {}u\n" "#define PER_VERTEX_JOINT_COUNT {}u\n"
#ifndef MAGNUM_TARGET_GLES "#define SECONDARY_PER_VERTEX_JOINT_COUNT {}u\n"
"#define JOINT_MATRIX_INITIALIZER {}\n" #ifndef MAGNUM_TARGET_GLES
#endif "#define JOINT_MATRIX_INITIALIZER {}\n"
"#define PER_INSTANCE_JOINT_COUNT_LOCATION {}\n", #endif
jointCount, "#define PER_INSTANCE_JOINT_COUNT_LOCATION {}\n",
perVertexJointCount, jointCount,
secondaryPerVertexJointCount, perVertexJointCount,
#ifndef MAGNUM_TARGET_GLES secondaryPerVertexJointCount,
((dimensions == 2 ? "mat3(1.0), "_s : "mat4(1.0), "_s)*jointCount).exceptSuffix(2), #ifndef MAGNUM_TARGET_GLES
#endif ((dimensions == 2 ? "mat3(1.0), "_s : "mat4(1.0), "_s)*jointCount).exceptSuffix(2),
perInstanceJointCountUniform)); #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) { if(flags >= FlagBase::DynamicPerVertexJointCount) {
vert.addSource(Utility::format( if(!(flags >= FlagBase::UniformBuffers)) {
"#define DYNAMIC_PER_VERTEX_JOINT_COUNT\n" vert.addSource(Utility::format(
"#define PER_VERTEX_JOINT_COUNT_LOCATION {}\n", "#define DYNAMIC_PER_VERTEX_JOINT_COUNT\n"
perVertexJointCountUniform)); "#define PER_VERTEX_JOINT_COUNT_LOCATION {}\n",
perVertexJointCountUniform));
} else {
vert.addSource("#define DYNAMIC_PER_VERTEX_JOINT_COUNT\n"_s);
}
} }
#endif #endif
#ifndef MAGNUM_TARGET_GLES2 #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); .addSource(configuration.flags() >= Flag::InstancedTextureOffset ? "#define INSTANCED_TEXTURE_OFFSET\n"_s : ""_s);
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(configuration.perVertexJointCount() || configuration.secondaryPerVertexJointCount()) { if(configuration.perVertexJointCount() || configuration.secondaryPerVertexJointCount()) {
vert.addSource(Utility::format( if(!(configuration.flags() >= Flag::UniformBuffers)) {
"#define JOINT_COUNT {}\n" vert.addSource(Utility::format(
"#define PER_VERTEX_JOINT_COUNT {}u\n" "#define JOINT_COUNT {}\n"
"#define SECONDARY_PER_VERTEX_JOINT_COUNT {}u\n" "#define PER_VERTEX_JOINT_COUNT {}u\n"
"#define JOINT_MATRICES_LOCATION {}\n" "#define SECONDARY_PER_VERTEX_JOINT_COUNT {}u\n"
#ifndef MAGNUM_TARGET_GLES "#define JOINT_MATRICES_LOCATION {}\n"
"#define JOINT_MATRIX_INITIALIZER {}\n" #ifndef MAGNUM_TARGET_GLES
#endif "#define JOINT_MATRIX_INITIALIZER {}\n"
"#define PER_INSTANCE_JOINT_COUNT_LOCATION {}\n", #endif
configuration.jointCount(), "#define PER_INSTANCE_JOINT_COUNT_LOCATION {}\n",
configuration.perVertexJointCount(), configuration.jointCount(),
configuration.secondaryPerVertexJointCount(), configuration.perVertexJointCount(),
out._jointMatricesUniform, configuration.secondaryPerVertexJointCount(),
#ifndef MAGNUM_TARGET_GLES out._jointMatricesUniform,
("mat4(1.0), "_s*configuration.jointCount()).exceptSuffix(2), #ifndef MAGNUM_TARGET_GLES
#endif ("mat4(1.0), "_s*configuration.jointCount()).exceptSuffix(2),
out._perInstanceJointCountUniform)); #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) { if(configuration.flags() >= Flag::DynamicPerVertexJointCount) {
vert.addSource(Utility::format( if(!(configuration.flags() >= Flag::UniformBuffers)) {
"#define DYNAMIC_PER_VERTEX_JOINT_COUNT\n" vert.addSource(Utility::format(
"#define PER_VERTEX_JOINT_COUNT_LOCATION {}\n", "#define DYNAMIC_PER_VERTEX_JOINT_COUNT\n"
out._perVertexJointCountUniform)); "#define PER_VERTEX_JOINT_COUNT_LOCATION {}\n",
out._perVertexJointCountUniform));
} else {
vert.addSource("#define DYNAMIC_PER_VERTEX_JOINT_COUNT\n"_s);
}
} }
#endif #endif
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2

Loading…
Cancel
Save