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. 14
      src/Magnum/Shaders/FlatGL.cpp
  2. 14
      src/Magnum/Shaders/MeshVisualizerGL.cpp
  3. 14
      src/Magnum/Shaders/PhongGL.cpp

14
src/Magnum/Shaders/FlatGL.cpp

@ -179,6 +179,7 @@ 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()) {
if(!(configuration.flags() >= Flag::UniformBuffers)) {
vert.addSource(Utility::format( vert.addSource(Utility::format(
"#define JOINT_COUNT {}\n" "#define JOINT_COUNT {}\n"
"#define PER_VERTEX_JOINT_COUNT {}u\n" "#define PER_VERTEX_JOINT_COUNT {}u\n"
@ -194,12 +195,25 @@ template<UnsignedInt dimensions> typename FlatGL<dimensions>::CompileState FlatG
((dimensions == 2 ? "mat3(1.0), "_s : "mat4(1.0), "_s)*configuration.jointCount()).exceptSuffix(2), ((dimensions == 2 ? "mat3(1.0), "_s : "mat4(1.0), "_s)*configuration.jointCount()).exceptSuffix(2),
#endif #endif
out._perInstanceJointCountUniform)); 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) {
if(!(configuration.flags() >= Flag::UniformBuffers)) {
vert.addSource(Utility::format( vert.addSource(Utility::format(
"#define DYNAMIC_PER_VERTEX_JOINT_COUNT\n" "#define DYNAMIC_PER_VERTEX_JOINT_COUNT\n"
"#define PER_VERTEX_JOINT_COUNT_LOCATION {}\n", "#define PER_VERTEX_JOINT_COUNT_LOCATION {}\n",
out._perVertexJointCountUniform)); out._perVertexJointCountUniform));
} else {
vert.addSource("#define DYNAMIC_PER_VERTEX_JOINT_COUNT\n"_s);
}
} }
#endif #endif
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2

14
src/Magnum/Shaders/MeshVisualizerGL.cpp

@ -198,6 +198,7 @@ GL::Version MeshVisualizerGLBase::setupShaders(GL::Shader& vert, GL::Shader& fra
; ;
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(perVertexJointCount || secondaryPerVertexJointCount) { if(perVertexJointCount || secondaryPerVertexJointCount) {
if(!(flags >= FlagBase::UniformBuffers)) {
vert.addSource(Utility::format( vert.addSource(Utility::format(
"#define JOINT_COUNT {}\n" "#define JOINT_COUNT {}\n"
"#define PER_VERTEX_JOINT_COUNT {}u\n" "#define PER_VERTEX_JOINT_COUNT {}u\n"
@ -213,12 +214,25 @@ GL::Version MeshVisualizerGLBase::setupShaders(GL::Shader& vert, GL::Shader& fra
((dimensions == 2 ? "mat3(1.0), "_s : "mat4(1.0), "_s)*jointCount).exceptSuffix(2), ((dimensions == 2 ? "mat3(1.0), "_s : "mat4(1.0), "_s)*jointCount).exceptSuffix(2),
#endif #endif
perInstanceJointCountUniform)); 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) {
if(!(flags >= FlagBase::UniformBuffers)) {
vert.addSource(Utility::format( vert.addSource(Utility::format(
"#define DYNAMIC_PER_VERTEX_JOINT_COUNT\n" "#define DYNAMIC_PER_VERTEX_JOINT_COUNT\n"
"#define PER_VERTEX_JOINT_COUNT_LOCATION {}\n", "#define PER_VERTEX_JOINT_COUNT_LOCATION {}\n",
perVertexJointCountUniform)); perVertexJointCountUniform));
} else {
vert.addSource("#define DYNAMIC_PER_VERTEX_JOINT_COUNT\n"_s);
}
} }
#endif #endif
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2

14
src/Magnum/Shaders/PhongGL.cpp

@ -224,6 +224,7 @@ 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()) {
if(!(configuration.flags() >= Flag::UniformBuffers)) {
vert.addSource(Utility::format( vert.addSource(Utility::format(
"#define JOINT_COUNT {}\n" "#define JOINT_COUNT {}\n"
"#define PER_VERTEX_JOINT_COUNT {}u\n" "#define PER_VERTEX_JOINT_COUNT {}u\n"
@ -241,12 +242,25 @@ PhongGL::CompileState PhongGL::compile(const Configuration& configuration) {
("mat4(1.0), "_s*configuration.jointCount()).exceptSuffix(2), ("mat4(1.0), "_s*configuration.jointCount()).exceptSuffix(2),
#endif #endif
out._perInstanceJointCountUniform)); 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) {
if(!(configuration.flags() >= Flag::UniformBuffers)) {
vert.addSource(Utility::format( vert.addSource(Utility::format(
"#define DYNAMIC_PER_VERTEX_JOINT_COUNT\n" "#define DYNAMIC_PER_VERTEX_JOINT_COUNT\n"
"#define PER_VERTEX_JOINT_COUNT_LOCATION {}\n", "#define PER_VERTEX_JOINT_COUNT_LOCATION {}\n",
out._perVertexJointCountUniform)); 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