Browse Source

DebugTools,Shaders,TextureTools: use string view literals everywhere.

Mainly important for Shader::addSource() to prevent it from creating a
needless copy, but doesn't hurt to do the same also for
uniformLocation(), bindAttributeLocation() etc. -- it'll avoid a runtime
strlen() in that case at least.
pull/499/head
Vladimír Vondruš 3 years ago
parent
commit
3e7298f3d3
  1. 16
      src/Magnum/DebugTools/TextureImage.cpp
  2. 50
      src/Magnum/Shaders/DistanceFieldVectorGL.cpp
  3. 104
      src/Magnum/Shaders/FlatGL.cpp
  4. 14
      src/Magnum/Shaders/Implementation/CreateCompatibilityShader.h
  5. 274
      src/Magnum/Shaders/MeshVisualizerGL.cpp
  6. 158
      src/Magnum/Shaders/PhongGL.cpp
  7. 46
      src/Magnum/Shaders/VectorGL.cpp
  8. 28
      src/Magnum/Shaders/VertexColorGL.cpp
  9. 20
      src/Magnum/TextureTools/DistanceField.cpp

16
src/Magnum/DebugTools/TextureImage.cpp

@ -56,6 +56,8 @@ static void importDebugToolsResources() {
namespace Magnum { namespace DebugTools { namespace Magnum { namespace DebugTools {
#if defined(MAGNUM_TARGET_GLES) && !defined(MAGNUM_TARGET_GLES2) #if defined(MAGNUM_TARGET_GLES) && !defined(MAGNUM_TARGET_GLES2)
using namespace Containers::Literals;
namespace { namespace {
class FloatReinterpretShader: public GL::AbstractShaderProgram { class FloatReinterpretShader: public GL::AbstractShaderProgram {
@ -75,7 +77,7 @@ class FloatReinterpretShader: public GL::AbstractShaderProgram {
FloatReinterpretShader::FloatReinterpretShader() { FloatReinterpretShader::FloatReinterpretShader() {
#ifdef MAGNUM_BUILD_STATIC #ifdef MAGNUM_BUILD_STATIC
/* Import resources on static build, if not already */ /* Import resources on static build, if not already */
if(!Utility::Resource::hasGroup("MagnumDebugTools")) if(!Utility::Resource::hasGroup("MagnumDebugTools"_s))
importDebugToolsResources(); importDebugToolsResources();
#endif #endif
Utility::Resource rs{"MagnumDebugTools"}; Utility::Resource rs{"MagnumDebugTools"};
@ -83,21 +85,21 @@ FloatReinterpretShader::FloatReinterpretShader() {
GL::Shader vert{GL::Version::GLES300, GL::Shader::Type::Vertex}; GL::Shader vert{GL::Version::GLES300, GL::Shader::Type::Vertex};
GL::Shader frag{GL::Version::GLES300, GL::Shader::Type::Fragment}; GL::Shader frag{GL::Version::GLES300, GL::Shader::Type::Fragment};
if(!GL::Context::current().isExtensionSupported<GL::Extensions::MAGNUM::shader_vertex_id>()) if(!GL::Context::current().isExtensionSupported<GL::Extensions::MAGNUM::shader_vertex_id>())
vert.addSource("#define DISABLE_GL_MAGNUM_shader_vertex_id\n"); vert.addSource("#define DISABLE_GL_MAGNUM_shader_vertex_id\n"_s);
vert.addSource(rs.getString("TextureImage.vert")); vert.addSource(rs.getString("TextureImage.vert"_s));
frag.addSource(rs.getString("TextureImage.frag")); frag.addSource(rs.getString("TextureImage.frag"_s));
CORRADE_INTERNAL_ASSERT_OUTPUT(vert.compile() && frag.compile()); CORRADE_INTERNAL_ASSERT_OUTPUT(vert.compile() && frag.compile());
attachShaders({vert, frag}); attachShaders({vert, frag});
if(!GL::Context::current().isExtensionSupported<GL::Extensions::MAGNUM::shader_vertex_id>()) { if(!GL::Context::current().isExtensionSupported<GL::Extensions::MAGNUM::shader_vertex_id>()) {
bindAttributeLocation(0, "position"); bindAttributeLocation(0, "position"_s);
} }
CORRADE_INTERNAL_ASSERT_OUTPUT(link()); CORRADE_INTERNAL_ASSERT_OUTPUT(link());
levelUniform = uniformLocation("level"); levelUniform = uniformLocation("level"_s);
setUniform(uniformLocation("textureData"), 0); setUniform(uniformLocation("textureData"_s), 0);
} }
} }

50
src/Magnum/Shaders/DistanceFieldVectorGL.cpp

@ -49,6 +49,8 @@
namespace Magnum { namespace Shaders { namespace Magnum { namespace Shaders {
using namespace Containers::Literals;
namespace { namespace {
enum: Int { TextureUnit = 6 }; enum: Int { TextureUnit = 6 };
@ -91,10 +93,10 @@ template<UnsignedInt dimensions> typename DistanceFieldVectorGL<dimensions>::Com
#ifdef MAGNUM_BUILD_STATIC #ifdef MAGNUM_BUILD_STATIC
/* Import resources on static build, if not already */ /* Import resources on static build, if not already */
if(!Utility::Resource::hasGroup("MagnumShadersGL")) if(!Utility::Resource::hasGroup("MagnumShadersGL"_s))
importShaderResources(); importShaderResources();
#endif #endif
Utility::Resource rs("MagnumShadersGL"); Utility::Resource rs("MagnumShadersGL"_s);
const GL::Context& context = GL::Context::current(); const GL::Context& context = GL::Context::current();
@ -107,19 +109,19 @@ template<UnsignedInt dimensions> typename DistanceFieldVectorGL<dimensions>::Com
GL::Shader vert = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Vertex); GL::Shader vert = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Vertex);
GL::Shader frag = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Fragment); GL::Shader frag = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Fragment);
vert.addSource(configuration.flags() & Flag::TextureTransformation ? "#define TEXTURE_TRANSFORMATION\n" : "") vert.addSource(configuration.flags() & Flag::TextureTransformation ? "#define TEXTURE_TRANSFORMATION\n"_s : ""_s)
.addSource(dimensions == 2 ? "#define TWO_DIMENSIONS\n" : "#define THREE_DIMENSIONS\n"); .addSource(dimensions == 2 ? "#define TWO_DIMENSIONS\n"_s : "#define THREE_DIMENSIONS\n"_s);
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(configuration.flags() >= Flag::UniformBuffers) { if(configuration.flags() >= Flag::UniformBuffers) {
vert.addSource(Utility::format( vert.addSource(Utility::format(
"#define UNIFORM_BUFFERS\n" "#define UNIFORM_BUFFERS\n"
"#define DRAW_COUNT {}\n", "#define DRAW_COUNT {}\n",
configuration.drawCount())); configuration.drawCount()));
vert.addSource(configuration.flags() >= Flag::MultiDraw ? "#define MULTI_DRAW\n" : ""); vert.addSource(configuration.flags() >= Flag::MultiDraw ? "#define MULTI_DRAW\n"_s : ""_s);
} }
#endif #endif
vert.addSource(rs.getString("generic.glsl")) vert.addSource(rs.getString("generic.glsl"_s))
.addSource(rs.getString("Vector.vert")); .addSource(rs.getString("Vector.vert"_s));
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(configuration.flags() >= Flag::UniformBuffers) { if(configuration.flags() >= Flag::UniformBuffers) {
frag.addSource(Utility::format( frag.addSource(Utility::format(
@ -128,11 +130,11 @@ template<UnsignedInt dimensions> typename DistanceFieldVectorGL<dimensions>::Com
"#define DRAW_COUNT {}\n", "#define DRAW_COUNT {}\n",
configuration.materialCount(), configuration.materialCount(),
configuration.drawCount())); configuration.drawCount()));
frag.addSource(configuration.flags() >= Flag::MultiDraw ? "#define MULTI_DRAW\n" : ""); frag.addSource(configuration.flags() >= Flag::MultiDraw ? "#define MULTI_DRAW\n"_s : ""_s);
} }
#endif #endif
frag.addSource(rs.getString("generic.glsl")) frag.addSource(rs.getString("generic.glsl"_s))
.addSource(rs.getString("DistanceFieldVector.frag")); .addSource(rs.getString("DistanceFieldVector.frag"_s));
vert.submitCompile(); vert.submitCompile();
frag.submitCompile(); frag.submitCompile();
@ -152,8 +154,8 @@ template<UnsignedInt dimensions> typename DistanceFieldVectorGL<dimensions>::Com
if(!context.isExtensionSupported<GL::Extensions::ARB::explicit_attrib_location>(version)) if(!context.isExtensionSupported<GL::Extensions::ARB::explicit_attrib_location>(version))
#endif #endif
{ {
out.bindAttributeLocation(Position::Location, "position"); out.bindAttributeLocation(Position::Location, "position"_s);
out.bindAttributeLocation(TextureCoordinates::Location, "textureCoordinates"); out.bindAttributeLocation(TextureCoordinates::Location, "textureCoordinates"_s);
} }
#endif #endif
@ -201,17 +203,17 @@ template<UnsignedInt dimensions> DistanceFieldVectorGL<dimensions>::DistanceFiel
{ {
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(_flags >= Flag::UniformBuffers) { if(_flags >= Flag::UniformBuffers) {
if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"); if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"_s);
} else } else
#endif #endif
{ {
_transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"); _transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"_s);
if(_flags & Flag::TextureTransformation) if(_flags & Flag::TextureTransformation)
_textureMatrixUniform = uniformLocation("textureMatrix"); _textureMatrixUniform = uniformLocation("textureMatrix"_s);
_colorUniform = uniformLocation("color"); _colorUniform = uniformLocation("color"_s);
_outlineColorUniform = uniformLocation("outlineColor"); _outlineColorUniform = uniformLocation("outlineColor"_s);
_outlineRangeUniform = uniformLocation("outlineRange"); _outlineRangeUniform = uniformLocation("outlineRange"_s);
_smoothnessUniform = uniformLocation("smoothness"); _smoothnessUniform = uniformLocation("smoothness"_s);
} }
} }
@ -219,14 +221,14 @@ template<UnsignedInt dimensions> DistanceFieldVectorGL<dimensions>::DistanceFiel
if(!context.isExtensionSupported<GL::Extensions::ARB::shading_language_420pack>(state._version)) if(!context.isExtensionSupported<GL::Extensions::ARB::shading_language_420pack>(state._version))
#endif #endif
{ {
setUniform(uniformLocation("vectorTexture"), TextureUnit); setUniform(uniformLocation("vectorTexture"_s), TextureUnit);
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(_flags >= Flag::UniformBuffers) { if(_flags >= Flag::UniformBuffers) {
setUniformBlockBinding(uniformBlockIndex("TransformationProjection"), TransformationProjectionBufferBinding); setUniformBlockBinding(uniformBlockIndex("TransformationProjection"_s), TransformationProjectionBufferBinding);
setUniformBlockBinding(uniformBlockIndex("Draw"), DrawBufferBinding); setUniformBlockBinding(uniformBlockIndex("Draw"_s), DrawBufferBinding);
setUniformBlockBinding(uniformBlockIndex("Material"), MaterialBufferBinding); setUniformBlockBinding(uniformBlockIndex("Material"_s), MaterialBufferBinding);
if(_flags & Flag::TextureTransformation) if(_flags & Flag::TextureTransformation)
setUniformBlockBinding(uniformBlockIndex("TextureTransformation"), TextureTransformationBufferBinding); setUniformBlockBinding(uniformBlockIndex("TextureTransformation"_s), TextureTransformationBufferBinding);
} }
#endif #endif
} }

104
src/Magnum/Shaders/FlatGL.cpp

@ -132,10 +132,10 @@ template<UnsignedInt dimensions> typename FlatGL<dimensions>::CompileState FlatG
#ifdef MAGNUM_BUILD_STATIC #ifdef MAGNUM_BUILD_STATIC
/* Import resources on static build, if not already */ /* Import resources on static build, if not already */
if(!Utility::Resource::hasGroup("MagnumShadersGL")) if(!Utility::Resource::hasGroup("MagnumShadersGL"_s))
importShaderResources(); importShaderResources();
#endif #endif
Utility::Resource rs("MagnumShadersGL"); Utility::Resource rs("MagnumShadersGL"_s);
const GL::Context& context = GL::Context::current(); const GL::Context& context = GL::Context::current();
@ -165,18 +165,18 @@ template<UnsignedInt dimensions> typename FlatGL<dimensions>::CompileState FlatG
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
|| configuration.flags() >= Flag::ObjectIdTexture || configuration.flags() >= Flag::ObjectIdTexture
#endif #endif
) ? "#define TEXTURED\n" : "") ) ? "#define TEXTURED\n"_s : ""_s)
.addSource(configuration.flags() & Flag::VertexColor ? "#define VERTEX_COLOR\n" : "") .addSource(configuration.flags() & Flag::VertexColor ? "#define VERTEX_COLOR\n"_s : ""_s)
.addSource(configuration.flags() & Flag::TextureTransformation ? "#define TEXTURE_TRANSFORMATION\n" : "") .addSource(configuration.flags() & Flag::TextureTransformation ? "#define TEXTURE_TRANSFORMATION\n"_s : ""_s)
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
.addSource(configuration.flags() & Flag::TextureArrays ? "#define TEXTURE_ARRAYS\n" : "") .addSource(configuration.flags() & Flag::TextureArrays ? "#define TEXTURE_ARRAYS\n"_s : ""_s)
#endif #endif
.addSource(dimensions == 2 ? "#define TWO_DIMENSIONS\n" : "#define THREE_DIMENSIONS\n") .addSource(dimensions == 2 ? "#define TWO_DIMENSIONS\n"_s : "#define THREE_DIMENSIONS\n"_s)
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
.addSource(configuration.flags() >= Flag::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n" : "") .addSource(configuration.flags() >= Flag::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n"_s : ""_s)
#endif #endif
.addSource(configuration.flags() & Flag::InstancedTransformation ? "#define INSTANCED_TRANSFORMATION\n" : "") .addSource(configuration.flags() & Flag::InstancedTransformation ? "#define INSTANCED_TRANSFORMATION\n"_s : ""_s)
.addSource(configuration.flags() >= Flag::InstancedTextureOffset ? "#define INSTANCED_TEXTURE_OFFSET\n" : ""); .addSource(configuration.flags() >= Flag::InstancedTextureOffset ? "#define INSTANCED_TEXTURE_OFFSET\n"_s : ""_s);
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(configuration.jointCount()) { if(configuration.jointCount()) {
vert.addSource(Utility::format( vert.addSource(Utility::format(
@ -208,21 +208,21 @@ template<UnsignedInt dimensions> typename FlatGL<dimensions>::CompileState FlatG
"#define UNIFORM_BUFFERS\n" "#define UNIFORM_BUFFERS\n"
"#define DRAW_COUNT {}\n", "#define DRAW_COUNT {}\n",
configuration.drawCount())); configuration.drawCount()));
vert.addSource(configuration.flags() >= Flag::MultiDraw ? "#define MULTI_DRAW\n" : ""); vert.addSource(configuration.flags() >= Flag::MultiDraw ? "#define MULTI_DRAW\n"_s : ""_s);
} }
#endif #endif
vert.addSource(rs.getString("generic.glsl")) vert.addSource(rs.getString("generic.glsl"_s))
.addSource(rs.getString("Flat.vert")); .addSource(rs.getString("Flat.vert"_s));
frag.addSource(configuration.flags() & Flag::Textured ? "#define TEXTURED\n" : "") frag.addSource(configuration.flags() & Flag::Textured ? "#define TEXTURED\n"_s : ""_s)
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
.addSource(configuration.flags() & Flag::TextureArrays ? "#define TEXTURE_ARRAYS\n" : "") .addSource(configuration.flags() & Flag::TextureArrays ? "#define TEXTURE_ARRAYS\n"_s : ""_s)
#endif #endif
.addSource(configuration.flags() & Flag::AlphaMask ? "#define ALPHA_MASK\n" : "") .addSource(configuration.flags() & Flag::AlphaMask ? "#define ALPHA_MASK\n"_s : ""_s)
.addSource(configuration.flags() & Flag::VertexColor ? "#define VERTEX_COLOR\n" : "") .addSource(configuration.flags() & Flag::VertexColor ? "#define VERTEX_COLOR\n"_s : ""_s)
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
.addSource(configuration.flags() & Flag::ObjectId ? "#define OBJECT_ID\n" : "") .addSource(configuration.flags() & Flag::ObjectId ? "#define OBJECT_ID\n"_s : ""_s)
.addSource(configuration.flags() >= Flag::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n" : "") .addSource(configuration.flags() >= Flag::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n"_s : ""_s)
.addSource(configuration.flags() >= Flag::ObjectIdTexture ? "#define OBJECT_ID_TEXTURE\n" : "") .addSource(configuration.flags() >= Flag::ObjectIdTexture ? "#define OBJECT_ID_TEXTURE\n"_s : ""_s)
#endif #endif
; ;
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
@ -233,11 +233,11 @@ template<UnsignedInt dimensions> typename FlatGL<dimensions>::CompileState FlatG
"#define MATERIAL_COUNT {}\n", "#define MATERIAL_COUNT {}\n",
configuration.drawCount(), configuration.drawCount(),
configuration.materialCount())); configuration.materialCount()));
frag.addSource(configuration.flags() >= Flag::MultiDraw ? "#define MULTI_DRAW\n" : ""); frag.addSource(configuration.flags() >= Flag::MultiDraw ? "#define MULTI_DRAW\n"_s : ""_s);
} }
#endif #endif
frag.addSource(rs.getString("generic.glsl")) frag.addSource(rs.getString("generic.glsl"_s))
.addSource(rs.getString("Flat.frag")); .addSource(rs.getString("Flat.frag"_s));
vert.submitCompile(); vert.submitCompile();
frag.submitCompile(); frag.submitCompile();
@ -251,38 +251,38 @@ template<UnsignedInt dimensions> typename FlatGL<dimensions>::CompileState FlatG
if(!context.isExtensionSupported<GL::Extensions::ARB::explicit_attrib_location>(version)) if(!context.isExtensionSupported<GL::Extensions::ARB::explicit_attrib_location>(version))
#endif #endif
{ {
out.bindAttributeLocation(Position::Location, "position"); out.bindAttributeLocation(Position::Location, "position"_s);
if(configuration.flags() & Flag::Textured if(configuration.flags() & Flag::Textured
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
|| configuration.flags() >= Flag::ObjectIdTexture || configuration.flags() >= Flag::ObjectIdTexture
#endif #endif
) )
out.bindAttributeLocation(TextureCoordinates::Location, "textureCoordinates"); out.bindAttributeLocation(TextureCoordinates::Location, "textureCoordinates"_s);
if(configuration.flags() & Flag::VertexColor) if(configuration.flags() & Flag::VertexColor)
out.bindAttributeLocation(Color3::Location, "vertexColor"); /* Color4 is the same */ out.bindAttributeLocation(Color3::Location, "vertexColor"_s); /* Color4 is the same */
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(configuration.flags() & Flag::ObjectId) { if(configuration.flags() & Flag::ObjectId) {
out.bindFragmentDataLocation(ColorOutput, "color"); out.bindFragmentDataLocation(ColorOutput, "color"_s);
out.bindFragmentDataLocation(ObjectIdOutput, "objectId"); out.bindFragmentDataLocation(ObjectIdOutput, "objectId"_s);
} }
if(configuration.flags() >= Flag::InstancedObjectId) if(configuration.flags() >= Flag::InstancedObjectId)
out.bindAttributeLocation(ObjectId::Location, "instanceObjectId"); out.bindAttributeLocation(ObjectId::Location, "instanceObjectId"_s);
#endif #endif
if(configuration.flags() & Flag::InstancedTransformation) if(configuration.flags() & Flag::InstancedTransformation)
out.bindAttributeLocation(TransformationMatrix::Location, "instancedTransformationMatrix"); out.bindAttributeLocation(TransformationMatrix::Location, "instancedTransformationMatrix"_s);
if(configuration.flags() >= Flag::InstancedTextureOffset) if(configuration.flags() >= Flag::InstancedTextureOffset)
out.bindAttributeLocation(TextureOffset::Location, "instancedTextureOffset"); out.bindAttributeLocation(TextureOffset::Location, "instancedTextureOffset"_s);
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
/* Configuration::setJointCount() checks that jointCount and /* Configuration::setJointCount() checks that jointCount and
perVertexJointCount / secondaryPerVertexJointCount are either all perVertexJointCount / secondaryPerVertexJointCount are either all
zero or non-zero so we don't need to check for jointCount() here */ zero or non-zero so we don't need to check for jointCount() here */
if(configuration.perVertexJointCount()) { if(configuration.perVertexJointCount()) {
out.bindAttributeLocation(Weights::Location, "weights"); out.bindAttributeLocation(Weights::Location, "weights"_s);
out.bindAttributeLocation(JointIds::Location, "jointIds"); out.bindAttributeLocation(JointIds::Location, "jointIds"_s);
} }
if(configuration.secondaryPerVertexJointCount()) { if(configuration.secondaryPerVertexJointCount()) {
out.bindAttributeLocation(SecondaryWeights::Location, "secondaryWeights"); out.bindAttributeLocation(SecondaryWeights::Location, "secondaryWeights"_s);
out.bindAttributeLocation(SecondaryJointIds::Location, "secondaryJointIds"); out.bindAttributeLocation(SecondaryJointIds::Location, "secondaryJointIds"_s);
} }
#endif #endif
} }
@ -333,28 +333,28 @@ template<UnsignedInt dimensions> FlatGL<dimensions>::FlatGL(CompileState&& state
{ {
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(_flags >= Flag::DynamicPerVertexJointCount) if(_flags >= Flag::DynamicPerVertexJointCount)
_perVertexJointCountUniform = uniformLocation("perVertexJointCount"); _perVertexJointCountUniform = uniformLocation("perVertexJointCount"_s);
if(_flags >= Flag::UniformBuffers) { if(_flags >= Flag::UniformBuffers) {
if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"); if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"_s);
} else } else
#endif #endif
{ {
_transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"); _transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"_s);
if(_flags & Flag::TextureTransformation) if(_flags & Flag::TextureTransformation)
_textureMatrixUniform = uniformLocation("textureMatrix"); _textureMatrixUniform = uniformLocation("textureMatrix"_s);
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(_flags & Flag::TextureArrays) if(_flags & Flag::TextureArrays)
_textureLayerUniform = uniformLocation("textureLayer"); _textureLayerUniform = uniformLocation("textureLayer"_s);
#endif #endif
_colorUniform = uniformLocation("color"); _colorUniform = uniformLocation("color"_s);
if(_flags & Flag::AlphaMask) _alphaMaskUniform = uniformLocation("alphaMask"); if(_flags & Flag::AlphaMask) _alphaMaskUniform = uniformLocation("alphaMask"_s);
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(_flags & Flag::ObjectId) _objectIdUniform = uniformLocation("objectId"); if(_flags & Flag::ObjectId) _objectIdUniform = uniformLocation("objectId"_s);
#endif #endif
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(_jointCount) { if(_jointCount) {
_jointMatricesUniform = uniformLocation("jointMatrices"); _jointMatricesUniform = uniformLocation("jointMatrices"_s);
_perInstanceJointCountUniform = uniformLocation("perInstanceJointCount"); _perInstanceJointCountUniform = uniformLocation("perInstanceJointCount"_s);
} }
#endif #endif
} }
@ -364,17 +364,17 @@ template<UnsignedInt dimensions> FlatGL<dimensions>::FlatGL(CompileState&& state
if(!context.isExtensionSupported<GL::Extensions::ARB::shading_language_420pack>(state._version)) if(!context.isExtensionSupported<GL::Extensions::ARB::shading_language_420pack>(state._version))
#endif #endif
{ {
if(_flags & Flag::Textured) setUniform(uniformLocation("textureData"), TextureUnit); if(_flags & Flag::Textured) setUniform(uniformLocation("textureData"_s), TextureUnit);
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(_flags >= Flag::ObjectIdTexture) setUniform(uniformLocation("objectIdTextureData"), ObjectIdTextureUnit); if(_flags >= Flag::ObjectIdTexture) setUniform(uniformLocation("objectIdTextureData"_s), ObjectIdTextureUnit);
if(_flags >= Flag::UniformBuffers) { if(_flags >= Flag::UniformBuffers) {
setUniformBlockBinding(uniformBlockIndex("TransformationProjection"), TransformationProjectionBufferBinding); setUniformBlockBinding(uniformBlockIndex("TransformationProjection"_s), TransformationProjectionBufferBinding);
setUniformBlockBinding(uniformBlockIndex("Draw"), DrawBufferBinding); setUniformBlockBinding(uniformBlockIndex("Draw"_s), DrawBufferBinding);
if(_flags & Flag::TextureTransformation) if(_flags & Flag::TextureTransformation)
setUniformBlockBinding(uniformBlockIndex("TextureTransformation"), TextureTransformationBufferBinding); setUniformBlockBinding(uniformBlockIndex("TextureTransformation"_s), TextureTransformationBufferBinding);
setUniformBlockBinding(uniformBlockIndex("Material"), MaterialBufferBinding); setUniformBlockBinding(uniformBlockIndex("Material"_s), MaterialBufferBinding);
if(_jointCount) if(_jointCount)
setUniformBlockBinding(uniformBlockIndex("Joint"), JointBufferBinding); setUniformBlockBinding(uniformBlockIndex("Joint"_s), JointBufferBinding);
} }
#endif #endif
} }

14
src/Magnum/Shaders/Implementation/CreateCompatibilityShader.h

@ -43,30 +43,32 @@ static void importShaderResources() {
namespace Magnum { namespace Shaders { namespace Implementation { namespace Magnum { namespace Shaders { namespace Implementation {
inline GL::Shader createCompatibilityShader(const Utility::Resource& rs, GL::Version version, GL::Shader::Type type) { inline GL::Shader createCompatibilityShader(const Utility::Resource& rs, GL::Version version, GL::Shader::Type type) {
using namespace Containers::Literals;
GL::Shader shader(version, type); GL::Shader shader(version, type);
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
if(GL::Context::current().isExtensionDisabled<GL::Extensions::ARB::explicit_attrib_location>(version)) if(GL::Context::current().isExtensionDisabled<GL::Extensions::ARB::explicit_attrib_location>(version))
shader.addSource("#define DISABLE_GL_ARB_explicit_attrib_location\n"); shader.addSource("#define DISABLE_GL_ARB_explicit_attrib_location\n"_s);
if(GL::Context::current().isExtensionDisabled<GL::Extensions::ARB::shading_language_420pack>(version)) if(GL::Context::current().isExtensionDisabled<GL::Extensions::ARB::shading_language_420pack>(version))
shader.addSource("#define DISABLE_GL_ARB_shading_language_420pack\n"); shader.addSource("#define DISABLE_GL_ARB_shading_language_420pack\n"_s);
if(GL::Context::current().isExtensionDisabled<GL::Extensions::ARB::explicit_uniform_location>(version)) if(GL::Context::current().isExtensionDisabled<GL::Extensions::ARB::explicit_uniform_location>(version))
shader.addSource("#define DISABLE_GL_ARB_explicit_uniform_location\n"); shader.addSource("#define DISABLE_GL_ARB_explicit_uniform_location\n"_s);
#endif #endif
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(type == GL::Shader::Type::Vertex && GL::Context::current().isExtensionDisabled<GL::Extensions::MAGNUM::shader_vertex_id>(version)) if(type == GL::Shader::Type::Vertex && GL::Context::current().isExtensionDisabled<GL::Extensions::MAGNUM::shader_vertex_id>(version))
shader.addSource("#define DISABLE_GL_MAGNUM_shader_vertex_id\n"); shader.addSource("#define DISABLE_GL_MAGNUM_shader_vertex_id\n"_s);
#endif #endif
/* My Android emulator (running on NVidia) doesn't define GL_ES /* My Android emulator (running on NVidia) doesn't define GL_ES
preprocessor macro, thus *all* the stock shaders fail to compile */ preprocessor macro, thus *all* the stock shaders fail to compile */
/** @todo remove this when Android emulator is sane */ /** @todo remove this when Android emulator is sane */
#ifdef CORRADE_TARGET_ANDROID #ifdef CORRADE_TARGET_ANDROID
shader.addSource("#ifndef GL_ES\n#define GL_ES 1\n#endif\n"); shader.addSource("#ifndef GL_ES\n#define GL_ES 1\n#endif\n"_s);
#endif #endif
shader.addSource(rs.getString("compatibility.glsl")); shader.addSource(rs.getString("compatibility.glsl"_s));
return shader; return shader;
} }

274
src/Magnum/Shaders/MeshVisualizerGL.cpp

@ -144,7 +144,7 @@ void MeshVisualizerGLBase::assertExtensions(const FlagsBase flags) {
#ifdef MAGNUM_BUILD_STATIC #ifdef MAGNUM_BUILD_STATIC
/* Import resources on static build, if not already */ /* Import resources on static build, if not already */
if(!Utility::Resource::hasGroup("MagnumShadersGL")) if(!Utility::Resource::hasGroup("MagnumShadersGL"_s))
importShaderResources(); importShaderResources();
#endif #endif
} }
@ -176,24 +176,24 @@ GL::Version MeshVisualizerGLBase::setupShaders(GL::Shader& vert, GL::Shader& fra
vert = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Vertex); vert = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Vertex);
frag = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Fragment); frag = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Fragment);
vert.addSource(flags & FlagBase::Wireframe ? "#define WIREFRAME_RENDERING\n" : "") vert.addSource(flags & FlagBase::Wireframe ? "#define WIREFRAME_RENDERING\n"_s : ""_s)
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
.addSource(flags >= FlagBase::ObjectIdTexture ? "#define TEXTURED\n" : "") .addSource(flags >= FlagBase::ObjectIdTexture ? "#define TEXTURED\n"_s : ""_s)
.addSource(flags & FlagBase::TextureTransformation ? "#define TEXTURE_TRANSFORMATION\n" : "") .addSource(flags & FlagBase::TextureTransformation ? "#define TEXTURE_TRANSFORMATION\n"_s : ""_s)
.addSource(flags & FlagBase::TextureArrays ? "#define TEXTURE_ARRAYS\n" : "") .addSource(flags & FlagBase::TextureArrays ? "#define TEXTURE_ARRAYS\n"_s : ""_s)
.addSource(flags >= FlagBase::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n" : "") .addSource(flags >= FlagBase::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n"_s : ""_s)
#endif #endif
.addSource(flags & FlagBase::InstancedTransformation ? "#define INSTANCED_TRANSFORMATION\n" : "") .addSource(flags & FlagBase::InstancedTransformation ? "#define INSTANCED_TRANSFORMATION\n"_s : ""_s)
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
.addSource(flags >= FlagBase::InstancedTextureOffset ? "#define INSTANCED_TEXTURE_OFFSET\n" : "") .addSource(flags >= FlagBase::InstancedTextureOffset ? "#define INSTANCED_TEXTURE_OFFSET\n"_s : ""_s)
.addSource(flags & FlagBase::VertexId ? "#define VERTEX_ID\n" : "") .addSource(flags & FlagBase::VertexId ? "#define VERTEX_ID\n"_s : ""_s)
.addSource(flags >= FlagBase::PrimitiveIdFromVertexId ? "#define PRIMITIVE_ID_FROM_VERTEX_ID\n" : "") .addSource(flags >= FlagBase::PrimitiveIdFromVertexId ? "#define PRIMITIVE_ID_FROM_VERTEX_ID\n"_s : ""_s)
#endif #endif
#ifdef MAGNUM_TARGET_WEBGL #ifdef MAGNUM_TARGET_WEBGL
.addSource("#define SUBSCRIPTING_WORKAROUND\n") .addSource("#define SUBSCRIPTING_WORKAROUND\n"_s)
#elif defined(MAGNUM_TARGET_GLES2) #elif defined(MAGNUM_TARGET_GLES2)
.addSource(context.detectedDriver() & GL::Context::DetectedDriver::Angle ? .addSource(context.detectedDriver() & GL::Context::DetectedDriver::Angle ?
"#define SUBSCRIPTING_WORKAROUND\n" : "") "#define SUBSCRIPTING_WORKAROUND\n"_s : ""_s)
#endif #endif
; ;
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
@ -229,20 +229,20 @@ GL::Version MeshVisualizerGLBase::setupShaders(GL::Shader& vert, GL::Shader& fra
"#define MATERIAL_COUNT {}\n", "#define MATERIAL_COUNT {}\n",
drawCount, drawCount,
materialCount)); materialCount));
vert.addSource(flags >= FlagBase::MultiDraw ? "#define MULTI_DRAW\n" : ""); vert.addSource(flags >= FlagBase::MultiDraw ? "#define MULTI_DRAW\n"_s : ""_s);
} }
#endif #endif
frag.addSource(flags & FlagBase::Wireframe ? "#define WIREFRAME_RENDERING\n" : "") frag.addSource(flags & FlagBase::Wireframe ? "#define WIREFRAME_RENDERING\n"_s : ""_s)
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
.addSource(flags & FlagBase::ObjectId ? "#define OBJECT_ID\n" : "") .addSource(flags & FlagBase::ObjectId ? "#define OBJECT_ID\n"_s : ""_s)
.addSource(flags >= FlagBase::ObjectIdTexture ? "#define OBJECT_ID_TEXTURE\n" : "") .addSource(flags >= FlagBase::ObjectIdTexture ? "#define OBJECT_ID_TEXTURE\n"_s : ""_s)
.addSource(flags & FlagBase::TextureArrays ? "#define TEXTURE_ARRAYS\n" : "") .addSource(flags & FlagBase::TextureArrays ? "#define TEXTURE_ARRAYS\n"_s : ""_s)
.addSource(flags >= FlagBase::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n" : "") .addSource(flags >= FlagBase::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n"_s : ""_s)
.addSource(flags & FlagBase::VertexId ? "#define VERTEX_ID\n" : "") .addSource(flags & FlagBase::VertexId ? "#define VERTEX_ID\n"_s : ""_s)
.addSource(flags & FlagBase::PrimitiveId ? .addSource(flags & FlagBase::PrimitiveId ?
(flags >= FlagBase::PrimitiveIdFromVertexId ? (flags >= FlagBase::PrimitiveIdFromVertexId ?
"#define PRIMITIVE_ID_FROM_VERTEX_ID\n" : "#define PRIMITIVE_ID_FROM_VERTEX_ID\n"_s :
"#define PRIMITIVE_ID\n") : "") "#define PRIMITIVE_ID\n"_s) : ""_s)
#endif #endif
; ;
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
@ -253,7 +253,7 @@ GL::Version MeshVisualizerGLBase::setupShaders(GL::Shader& vert, GL::Shader& fra
"#define MATERIAL_COUNT {}\n", "#define MATERIAL_COUNT {}\n",
drawCount, drawCount,
materialCount)); materialCount));
frag.addSource(flags >= FlagBase::MultiDraw ? "#define MULTI_DRAW\n" : ""); frag.addSource(flags >= FlagBase::MultiDraw ? "#define MULTI_DRAW\n"_s : ""_s);
} }
#endif #endif
@ -503,42 +503,42 @@ MeshVisualizerGL2D::CompileState MeshVisualizerGL2D::compile(const Configuration
); );
Containers::Optional<GL::Shader> geom; Containers::Optional<GL::Shader> geom;
vert.addSource("#define TWO_DIMENSIONS\n") vert.addSource("#define TWO_DIMENSIONS\n"_s)
/* Pass NO_GEOMETRY_SHADER not only when NoGeometryShader but also when /* Pass NO_GEOMETRY_SHADER not only when NoGeometryShader but also when
nothing actually needs it, as that makes checks much simpler in nothing actually needs it, as that makes checks much simpler in
the shader code */ the shader code */
.addSource((configuration.flags() & Flag::NoGeometryShader) || !(configuration.flags() & Flag::Wireframe) ? .addSource((configuration.flags() & Flag::NoGeometryShader) || !(configuration.flags() & Flag::Wireframe) ?
"#define NO_GEOMETRY_SHADER\n" : "") "#define NO_GEOMETRY_SHADER\n"_s : ""_s)
.addSource(rs.getString("generic.glsl")) .addSource(rs.getString("generic.glsl"_s))
.addSource(rs.getString("MeshVisualizer.vert")); .addSource(rs.getString("MeshVisualizer.vert"_s));
frag frag
/* Pass NO_GEOMETRY_SHADER not only when NoGeometryShader but also when /* Pass NO_GEOMETRY_SHADER not only when NoGeometryShader but also when
nothing actually needs it, as that makes checks much simpler in nothing actually needs it, as that makes checks much simpler in
the shader code */ the shader code */
.addSource((configuration.flags() & Flag::NoGeometryShader) || !(configuration.flags() & Flag::Wireframe) ? .addSource((configuration.flags() & Flag::NoGeometryShader) || !(configuration.flags() & Flag::Wireframe) ?
"#define NO_GEOMETRY_SHADER\n" : ""); "#define NO_GEOMETRY_SHADER\n"_s : ""_s);
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(configuration.flags() >= Flag::UniformBuffers) if(configuration.flags() >= Flag::UniformBuffers)
frag.addSource("#define TWO_DIMENSIONS\n"); frag.addSource("#define TWO_DIMENSIONS\n"_s);
#endif #endif
frag.addSource(rs.getString("generic.glsl")) frag.addSource(rs.getString("generic.glsl"_s))
.addSource(rs.getString("MeshVisualizer.frag")); .addSource(rs.getString("MeshVisualizer.frag"_s));
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
if(configuration.flags() & Flag::Wireframe && !(configuration.flags() & Flag::NoGeometryShader)) { if(configuration.flags() & Flag::Wireframe && !(configuration.flags() & Flag::NoGeometryShader)) {
geom = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Geometry); geom = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Geometry);
(*geom) (*geom)
.addSource("#define WIREFRAME_RENDERING\n#define MAX_VERTICES 3\n") .addSource("#define WIREFRAME_RENDERING\n#define MAX_VERTICES 3\n"_s)
.addSource(baseFlags >= FlagBase::ObjectIdTexture ? "#define TEXTURED\n" : "") .addSource(baseFlags >= FlagBase::ObjectIdTexture ? "#define TEXTURED\n"_s : ""_s)
.addSource(baseFlags & FlagBase::TextureArrays ? "#define TEXTURE_ARRAYS\n" : "") .addSource(baseFlags & FlagBase::TextureArrays ? "#define TEXTURE_ARRAYS\n"_s : ""_s)
.addSource(baseFlags & FlagBase::ObjectId ? "#define OBJECT_ID\n" : "") .addSource(baseFlags & FlagBase::ObjectId ? "#define OBJECT_ID\n"_s : ""_s)
.addSource(baseFlags >= FlagBase::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n" : "") .addSource(baseFlags >= FlagBase::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n"_s : ""_s)
.addSource(baseFlags & FlagBase::VertexId ? "#define VERTEX_ID\n" : "") .addSource(baseFlags & FlagBase::VertexId ? "#define VERTEX_ID\n"_s : ""_s)
.addSource(baseFlags & FlagBase::PrimitiveId ? .addSource(baseFlags & FlagBase::PrimitiveId ?
(baseFlags >= FlagBase::PrimitiveIdFromVertexId ? (baseFlags >= FlagBase::PrimitiveIdFromVertexId ?
"#define PRIMITIVE_ID_FROM_VERTEX_ID\n" : "#define PRIMITIVE_ID_FROM_VERTEX_ID\n"_s :
"#define PRIMITIVE_ID\n") : ""); "#define PRIMITIVE_ID\n"_s) : ""_s);
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(configuration.flags() >= Flag::UniformBuffers) { if(configuration.flags() >= Flag::UniformBuffers) {
geom->addSource(Utility::format( geom->addSource(Utility::format(
@ -548,10 +548,10 @@ MeshVisualizerGL2D::CompileState MeshVisualizerGL2D::compile(const Configuration
"#define MATERIAL_COUNT {}\n", "#define MATERIAL_COUNT {}\n",
configuration.drawCount(), configuration.drawCount(),
configuration.materialCount())); configuration.materialCount()));
geom->addSource(configuration.flags() >= Flag::MultiDraw ? "#define MULTI_DRAW\n" : ""); geom->addSource(configuration.flags() >= Flag::MultiDraw ? "#define MULTI_DRAW\n"_s : ""_s);
} }
#endif #endif
geom->addSource(rs.getString("MeshVisualizer.geom")); geom->addSource(rs.getString("MeshVisualizer.geom"_s));
} }
#else #else
static_cast<void>(version); static_cast<void>(version);
@ -571,25 +571,25 @@ MeshVisualizerGL2D::CompileState MeshVisualizerGL2D::compile(const Configuration
if(!context.isExtensionSupported<GL::Extensions::ARB::explicit_attrib_location>(version)) if(!context.isExtensionSupported<GL::Extensions::ARB::explicit_attrib_location>(version))
#endif #endif
{ {
out.bindAttributeLocation(Position::Location, "position"); out.bindAttributeLocation(Position::Location, "position"_s);
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(configuration.flags() >= Flag::ObjectIdTexture) if(configuration.flags() >= Flag::ObjectIdTexture)
out.bindAttributeLocation(TextureCoordinates::Location, "textureCoordinates"); out.bindAttributeLocation(TextureCoordinates::Location, "textureCoordinates"_s);
if(configuration.flags() >= Flag::InstancedObjectId) if(configuration.flags() >= Flag::InstancedObjectId)
out.bindAttributeLocation(ObjectId::Location, "instanceObjectId"); out.bindAttributeLocation(ObjectId::Location, "instanceObjectId"_s);
#endif #endif
if(configuration.flags() & Flag::InstancedTransformation) if(configuration.flags() & Flag::InstancedTransformation)
out.bindAttributeLocation(TransformationMatrix::Location, "instancedTransformationMatrix"); out.bindAttributeLocation(TransformationMatrix::Location, "instancedTransformationMatrix"_s);
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(configuration.flags() >= Flag::InstancedTextureOffset) if(configuration.flags() >= Flag::InstancedTextureOffset)
out.bindAttributeLocation(TextureOffset::Location, "instancedTextureOffset"); out.bindAttributeLocation(TextureOffset::Location, "instancedTextureOffset"_s);
#endif #endif
#if !defined(MAGNUM_TARGET_GLES) || defined(MAGNUM_TARGET_GLES2) #if !defined(MAGNUM_TARGET_GLES) || defined(MAGNUM_TARGET_GLES2)
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
if(!context.isVersionSupported(GL::Version::GL310)) if(!context.isVersionSupported(GL::Version::GL310))
#endif #endif
{ {
out.bindAttributeLocation(VertexIndex::Location, "vertexIndex"); out.bindAttributeLocation(VertexIndex::Location, "vertexIndex"_s);
} }
#endif #endif
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
@ -597,12 +597,12 @@ MeshVisualizerGL2D::CompileState MeshVisualizerGL2D::compile(const Configuration
perVertexJointCount / secondaryPerVertexJointCount are either all perVertexJointCount / secondaryPerVertexJointCount are either all
zero or non-zero so we don't need to check for jointCount() here */ zero or non-zero so we don't need to check for jointCount() here */
if(configuration.perVertexJointCount()) { if(configuration.perVertexJointCount()) {
out.bindAttributeLocation(Weights::Location, "weights"); out.bindAttributeLocation(Weights::Location, "weights"_s);
out.bindAttributeLocation(JointIds::Location, "jointIds"); out.bindAttributeLocation(JointIds::Location, "jointIds"_s);
} }
if(configuration.secondaryPerVertexJointCount()) { if(configuration.secondaryPerVertexJointCount()) {
out.bindAttributeLocation(SecondaryWeights::Location, "secondaryWeights"); out.bindAttributeLocation(SecondaryWeights::Location, "secondaryWeights"_s);
out.bindAttributeLocation(SecondaryJointIds::Location, "secondaryJointIds"); out.bindAttributeLocation(SecondaryJointIds::Location, "secondaryJointIds"_s);
} }
#endif #endif
} }
@ -660,45 +660,45 @@ MeshVisualizerGL2D::MeshVisualizerGL2D(CompileState&& state): MeshVisualizerGL2D
/* This one is used also in the UBO case as it's usually a global /* This one is used also in the UBO case as it's usually a global
setting */ setting */
if((flags() & Flag::Wireframe) && !(flags() & Flag::NoGeometryShader)) if((flags() & Flag::Wireframe) && !(flags() & Flag::NoGeometryShader))
_viewportSizeUniform = uniformLocation("viewportSize"); _viewportSizeUniform = uniformLocation("viewportSize"_s);
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(flags() >= Flag::DynamicPerVertexJointCount) if(flags() >= Flag::DynamicPerVertexJointCount)
_perVertexJointCountUniform = uniformLocation("perVertexJointCount"); _perVertexJointCountUniform = uniformLocation("perVertexJointCount"_s);
if(flags() >= Flag::UniformBuffers) { if(flags() >= Flag::UniformBuffers) {
if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"); if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"_s);
} else } else
#endif #endif
{ {
_transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"); _transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"_s);
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(flags() & Flag::TextureTransformation) if(flags() & Flag::TextureTransformation)
_textureMatrixUniform = uniformLocation("textureMatrix"); _textureMatrixUniform = uniformLocation("textureMatrix"_s);
if(flags() & Flag::TextureArrays) if(flags() & Flag::TextureArrays)
_textureLayerUniform = uniformLocation("textureLayer"); _textureLayerUniform = uniformLocation("textureLayer"_s);
#endif #endif
if(flags() & (Flag::Wireframe if(flags() & (Flag::Wireframe
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
|Flag::ObjectId|Flag::VertexId|Flag::PrimitiveIdFromVertexId |Flag::ObjectId|Flag::VertexId|Flag::PrimitiveIdFromVertexId
#endif #endif
)) ))
_colorUniform = uniformLocation("color"); _colorUniform = uniformLocation("color"_s);
if(flags() & Flag::Wireframe) { if(flags() & Flag::Wireframe) {
_wireframeColorUniform = uniformLocation("wireframeColor"); _wireframeColorUniform = uniformLocation("wireframeColor"_s);
_wireframeWidthUniform = uniformLocation("wireframeWidth"); _wireframeWidthUniform = uniformLocation("wireframeWidth"_s);
_smoothnessUniform = uniformLocation("smoothness"); _smoothnessUniform = uniformLocation("smoothness"_s);
} }
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(flags() & (Flag::ObjectId|Flag::VertexId|Flag::PrimitiveIdFromVertexId)) { if(flags() & (Flag::ObjectId|Flag::VertexId|Flag::PrimitiveIdFromVertexId)) {
_colorMapOffsetScaleUniform = uniformLocation("colorMapOffsetScale"); _colorMapOffsetScaleUniform = uniformLocation("colorMapOffsetScale"_s);
} }
if(flags() & Flag::ObjectId) if(flags() & Flag::ObjectId)
_objectIdUniform = uniformLocation("objectId"); _objectIdUniform = uniformLocation("objectId"_s);
#endif #endif
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(_jointCount) { if(_jointCount) {
_jointMatricesUniform = uniformLocation("jointMatrices"); _jointMatricesUniform = uniformLocation("jointMatrices"_s);
_perInstanceJointCountUniform = uniformLocation("perInstanceJointCount"); _perInstanceJointCountUniform = uniformLocation("perInstanceJointCount"_s);
} }
#endif #endif
} }
@ -710,19 +710,19 @@ MeshVisualizerGL2D::MeshVisualizerGL2D(CompileState&& state): MeshVisualizerGL2D
#endif #endif
{ {
if(flags() & (Flag::ObjectId|Flag::VertexId|Flag::PrimitiveIdFromVertexId)) { if(flags() & (Flag::ObjectId|Flag::VertexId|Flag::PrimitiveIdFromVertexId)) {
setUniform(uniformLocation("colorMapTexture"), ColorMapTextureUnit); setUniform(uniformLocation("colorMapTexture"_s), ColorMapTextureUnit);
} }
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(flags() >= Flag::ObjectIdTexture) if(flags() >= Flag::ObjectIdTexture)
setUniform(uniformLocation("objectIdTextureData"), ObjectIdTextureUnit); setUniform(uniformLocation("objectIdTextureData"_s), ObjectIdTextureUnit);
if(flags() >= Flag::UniformBuffers) { if(flags() >= Flag::UniformBuffers) {
setUniformBlockBinding(uniformBlockIndex("TransformationProjection"), TransformationProjectionBufferBinding); setUniformBlockBinding(uniformBlockIndex("TransformationProjection"_s), TransformationProjectionBufferBinding);
setUniformBlockBinding(uniformBlockIndex("Draw"), DrawBufferBinding); setUniformBlockBinding(uniformBlockIndex("Draw"_s), DrawBufferBinding);
setUniformBlockBinding(uniformBlockIndex("Material"), MaterialBufferBinding); setUniformBlockBinding(uniformBlockIndex("Material"_s), MaterialBufferBinding);
if(flags() & Flag::TextureTransformation) if(flags() & Flag::TextureTransformation)
setUniformBlockBinding(uniformBlockIndex("TextureTransformation"), TextureTransformationBufferBinding); setUniformBlockBinding(uniformBlockIndex("TextureTransformation"_s), TextureTransformationBufferBinding);
if(_jointCount) if(_jointCount)
setUniformBlockBinding(uniformBlockIndex("Joint"), JointBufferBinding); setUniformBlockBinding(uniformBlockIndex("Joint"_s), JointBufferBinding);
} }
#endif #endif
} }
@ -955,7 +955,7 @@ MeshVisualizerGL3D::CompileState MeshVisualizerGL3D::compile(const Configuration
CORRADE_INTERNAL_ASSERT(!(configuration.flags() & (Flag::NormalDirection|Flag::TangentDirection|Flag::BitangentDirection|Flag::BitangentFromTangentDirection)) || version >= GL::Version::GLES310); CORRADE_INTERNAL_ASSERT(!(configuration.flags() & (Flag::NormalDirection|Flag::TangentDirection|Flag::BitangentDirection|Flag::BitangentFromTangentDirection)) || version >= GL::Version::GLES310);
#endif #endif
vert.addSource("#define THREE_DIMENSIONS\n") vert.addSource("#define THREE_DIMENSIONS\n"_s)
/* Pass NO_GEOMETRY_SHADER not only when NoGeometryShader but also when /* Pass NO_GEOMETRY_SHADER not only when NoGeometryShader but also when
nothing actually needs it, as that makes checks much simpler in nothing actually needs it, as that makes checks much simpler in
the vertex shader code */ the vertex shader code */
@ -963,16 +963,16 @@ MeshVisualizerGL3D::CompileState MeshVisualizerGL3D::compile(const Configuration
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
|Flag::TangentDirection|Flag::BitangentDirection|Flag::BitangentFromTangentDirection|Flag::NormalDirection |Flag::TangentDirection|Flag::BitangentDirection|Flag::BitangentFromTangentDirection|Flag::NormalDirection
#endif #endif
)) ? "#define NO_GEOMETRY_SHADER\n" : "") )) ? "#define NO_GEOMETRY_SHADER\n"_s : ""_s)
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
.addSource(configuration.flags() & Flag::TangentDirection ? "#define TANGENT_DIRECTION\n" : "") .addSource(configuration.flags() & Flag::TangentDirection ? "#define TANGENT_DIRECTION\n"_s : ""_s)
.addSource(configuration.flags() & Flag::BitangentFromTangentDirection ? "#define BITANGENT_FROM_TANGENT_DIRECTION\n" : "") .addSource(configuration.flags() & Flag::BitangentFromTangentDirection ? "#define BITANGENT_FROM_TANGENT_DIRECTION\n"_s : ""_s)
.addSource(configuration.flags() & Flag::BitangentDirection ? "#define BITANGENT_DIRECTION\n" : "") .addSource(configuration.flags() & Flag::BitangentDirection ? "#define BITANGENT_DIRECTION\n"_s : ""_s)
.addSource(configuration.flags() & Flag::NormalDirection ? "#define NORMAL_DIRECTION\n" : "") .addSource(configuration.flags() & Flag::NormalDirection ? "#define NORMAL_DIRECTION\n"_s : ""_s)
#endif #endif
; ;
vert.addSource(rs.getString("generic.glsl")) vert.addSource(rs.getString("generic.glsl"_s))
.addSource(rs.getString("MeshVisualizer.vert")); .addSource(rs.getString("MeshVisualizer.vert"_s));
frag frag
/* Pass NO_GEOMETRY_SHADER not only when NoGeometryShader but also when /* Pass NO_GEOMETRY_SHADER not only when NoGeometryShader but also when
nothing actually needs it, as that makes checks much simpler in nothing actually needs it, as that makes checks much simpler in
@ -981,17 +981,17 @@ MeshVisualizerGL3D::CompileState MeshVisualizerGL3D::compile(const Configuration
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
|Flag::TangentDirection|Flag::BitangentDirection|Flag::BitangentFromTangentDirection|Flag::NormalDirection |Flag::TangentDirection|Flag::BitangentDirection|Flag::BitangentFromTangentDirection|Flag::NormalDirection
#endif #endif
)) ? "#define NO_GEOMETRY_SHADER\n" : "") )) ? "#define NO_GEOMETRY_SHADER\n"_s : ""_s)
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
.addSource(configuration.flags() & (Flag::TangentDirection|Flag::BitangentFromTangentDirection|Flag::BitangentDirection|Flag::NormalDirection) ? "#define TBN_DIRECTION\n" : "") .addSource(configuration.flags() & (Flag::TangentDirection|Flag::BitangentFromTangentDirection|Flag::BitangentDirection|Flag::NormalDirection) ? "#define TBN_DIRECTION\n"_s : ""_s)
#endif #endif
; ;
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(configuration.flags() >= Flag::UniformBuffers) if(configuration.flags() >= Flag::UniformBuffers)
frag.addSource("#define THREE_DIMENSIONS\n"); frag.addSource("#define THREE_DIMENSIONS\n"_s);
#endif #endif
frag.addSource(rs.getString("generic.glsl")) frag.addSource(rs.getString("generic.glsl"_s))
.addSource(rs.getString("MeshVisualizer.frag")); .addSource(rs.getString("MeshVisualizer.frag"_s));
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
if(configuration.flags() & (Flag::Wireframe|Flag::TangentDirection|Flag::BitangentFromTangentDirection|Flag::BitangentDirection|Flag::NormalDirection) && !(configuration.flags() & Flag::NoGeometryShader)) { if(configuration.flags() & (Flag::Wireframe|Flag::TangentDirection|Flag::BitangentFromTangentDirection|Flag::BitangentDirection|Flag::NormalDirection) && !(configuration.flags() & Flag::NoGeometryShader)) {
@ -1005,19 +1005,19 @@ MeshVisualizerGL3D::CompileState MeshVisualizerGL3D::compile(const Configuration
geom = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Geometry); geom = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Geometry);
(*geom) (*geom)
.addSource(Utility::format("#define MAX_VERTICES {}\n", maxVertices)) .addSource(Utility::format("#define MAX_VERTICES {}\n", maxVertices))
.addSource(configuration.flags() & Flag::Wireframe ? "#define WIREFRAME_RENDERING\n" : "") .addSource(configuration.flags() & Flag::Wireframe ? "#define WIREFRAME_RENDERING\n"_s : ""_s)
.addSource(baseFlags >= FlagBase::ObjectIdTexture ? "#define TEXTURED\n" : "") .addSource(baseFlags >= FlagBase::ObjectIdTexture ? "#define TEXTURED\n"_s : ""_s)
.addSource(baseFlags & FlagBase::TextureArrays ? "#define TEXTURE_ARRAYS\n" : "") .addSource(baseFlags & FlagBase::TextureArrays ? "#define TEXTURE_ARRAYS\n"_s : ""_s)
.addSource(baseFlags & FlagBase::ObjectId ? "#define OBJECT_ID\n" : "") .addSource(baseFlags & FlagBase::ObjectId ? "#define OBJECT_ID\n"_s : ""_s)
.addSource(baseFlags >= FlagBase::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n" : "") .addSource(baseFlags >= FlagBase::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n"_s : ""_s)
.addSource(baseFlags & FlagBase::VertexId ? "#define VERTEX_ID\n" : "") .addSource(baseFlags & FlagBase::VertexId ? "#define VERTEX_ID\n"_s : ""_s)
.addSource(baseFlags & FlagBase::PrimitiveId ? .addSource(baseFlags & FlagBase::PrimitiveId ?
(baseFlags >= FlagBase::PrimitiveIdFromVertexId ? (baseFlags >= FlagBase::PrimitiveIdFromVertexId ?
"#define PRIMITIVE_ID_FROM_VERTEX_ID\n" : "#define PRIMITIVE_ID_FROM_VERTEX_ID\n"_s :
"#define PRIMITIVE_ID\n") : "") "#define PRIMITIVE_ID\n"_s) : ""_s)
.addSource(configuration.flags() & Flag::TangentDirection ? "#define TANGENT_DIRECTION\n" : "") .addSource(configuration.flags() & Flag::TangentDirection ? "#define TANGENT_DIRECTION\n"_s : ""_s)
.addSource(configuration.flags() & (Flag::BitangentDirection|Flag::BitangentFromTangentDirection) ? "#define BITANGENT_DIRECTION\n" : "") .addSource(configuration.flags() & (Flag::BitangentDirection|Flag::BitangentFromTangentDirection) ? "#define BITANGENT_DIRECTION\n"_s : ""_s)
.addSource(configuration.flags() & Flag::NormalDirection ? "#define NORMAL_DIRECTION\n" : ""); .addSource(configuration.flags() & Flag::NormalDirection ? "#define NORMAL_DIRECTION\n"_s : ""_s);
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(configuration.flags() >= Flag::UniformBuffers) { if(configuration.flags() >= Flag::UniformBuffers) {
geom->addSource(Utility::format( geom->addSource(Utility::format(
@ -1027,10 +1027,10 @@ MeshVisualizerGL3D::CompileState MeshVisualizerGL3D::compile(const Configuration
"#define MATERIAL_COUNT {}\n", "#define MATERIAL_COUNT {}\n",
configuration.drawCount(), configuration.drawCount(),
configuration.materialCount())); configuration.materialCount()));
geom->addSource(configuration.flags() >= Flag::MultiDraw ? "#define MULTI_DRAW\n" : ""); geom->addSource(configuration.flags() >= Flag::MultiDraw ? "#define MULTI_DRAW\n"_s : ""_s);
} }
#endif #endif
geom->addSource(rs.getString("MeshVisualizer.geom")); geom->addSource(rs.getString("MeshVisualizer.geom"_s));
} }
#else #else
static_cast<void>(version); static_cast<void>(version);
@ -1050,40 +1050,40 @@ MeshVisualizerGL3D::CompileState MeshVisualizerGL3D::compile(const Configuration
if(!context.isExtensionSupported<GL::Extensions::ARB::explicit_attrib_location>(version)) if(!context.isExtensionSupported<GL::Extensions::ARB::explicit_attrib_location>(version))
#endif #endif
{ {
out.bindAttributeLocation(Position::Location, "position"); out.bindAttributeLocation(Position::Location, "position"_s);
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(configuration.flags() >= Flag::ObjectIdTexture) if(configuration.flags() >= Flag::ObjectIdTexture)
out.bindAttributeLocation(TextureCoordinates::Location, "textureCoordinates"); out.bindAttributeLocation(TextureCoordinates::Location, "textureCoordinates"_s);
if(configuration.flags() >= Flag::InstancedObjectId) if(configuration.flags() >= Flag::InstancedObjectId)
out.bindAttributeLocation(ObjectId::Location, "instanceObjectId"); out.bindAttributeLocation(ObjectId::Location, "instanceObjectId"_s);
#endif #endif
if(configuration.flags() & Flag::InstancedTransformation) { if(configuration.flags() & Flag::InstancedTransformation) {
out.bindAttributeLocation(TransformationMatrix::Location, "instancedTransformationMatrix"); out.bindAttributeLocation(TransformationMatrix::Location, "instancedTransformationMatrix"_s);
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
if(configuration.flags() & (Flag::TangentDirection|Flag::BitangentFromTangentDirection|Flag::BitangentDirection|Flag::NormalDirection)) if(configuration.flags() & (Flag::TangentDirection|Flag::BitangentFromTangentDirection|Flag::BitangentDirection|Flag::NormalDirection))
out.bindAttributeLocation(NormalMatrix::Location, "instancedNormalMatrix"); out.bindAttributeLocation(NormalMatrix::Location, "instancedNormalMatrix"_s);
#endif #endif
} }
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(configuration.flags() >= Flag::InstancedTextureOffset) if(configuration.flags() >= Flag::InstancedTextureOffset)
out.bindAttributeLocation(TextureOffset::Location, "instancedTextureOffset"); out.bindAttributeLocation(TextureOffset::Location, "instancedTextureOffset"_s);
#endif #endif
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
if(configuration.flags() & Flag::TangentDirection || if(configuration.flags() & Flag::TangentDirection ||
configuration.flags() & Flag::BitangentFromTangentDirection) configuration.flags() & Flag::BitangentFromTangentDirection)
out.bindAttributeLocation(Tangent4::Location, "tangent"); out.bindAttributeLocation(Tangent4::Location, "tangent"_s);
if(configuration.flags() & Flag::BitangentDirection) if(configuration.flags() & Flag::BitangentDirection)
out.bindAttributeLocation(Bitangent::Location, "bitangent"); out.bindAttributeLocation(Bitangent::Location, "bitangent"_s);
if(configuration.flags() & Flag::NormalDirection || if(configuration.flags() & Flag::NormalDirection ||
configuration.flags() & Flag::BitangentFromTangentDirection) configuration.flags() & Flag::BitangentFromTangentDirection)
out.bindAttributeLocation(Normal::Location, "normal"); out.bindAttributeLocation(Normal::Location, "normal"_s);
#endif #endif
#if !defined(MAGNUM_TARGET_GLES) || defined(MAGNUM_TARGET_GLES2) #if !defined(MAGNUM_TARGET_GLES) || defined(MAGNUM_TARGET_GLES2)
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
if(!context.isVersionSupported(GL::Version::GL310)) if(!context.isVersionSupported(GL::Version::GL310))
#endif #endif
{ {
out.bindAttributeLocation(VertexIndex::Location, "vertexIndex"); out.bindAttributeLocation(VertexIndex::Location, "vertexIndex"_s);
} }
#endif #endif
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
@ -1091,12 +1091,12 @@ MeshVisualizerGL3D::CompileState MeshVisualizerGL3D::compile(const Configuration
perVertexJointCount / secondaryPerVertexJointCount are either all perVertexJointCount / secondaryPerVertexJointCount are either all
zero or non-zero so we don't need to check for jointCount() here */ zero or non-zero so we don't need to check for jointCount() here */
if(configuration.perVertexJointCount()) { if(configuration.perVertexJointCount()) {
out.bindAttributeLocation(Weights::Location, "weights"); out.bindAttributeLocation(Weights::Location, "weights"_s);
out.bindAttributeLocation(JointIds::Location, "jointIds"); out.bindAttributeLocation(JointIds::Location, "jointIds"_s);
} }
if(configuration.secondaryPerVertexJointCount()) { if(configuration.secondaryPerVertexJointCount()) {
out.bindAttributeLocation(SecondaryWeights::Location, "secondaryWeights"); out.bindAttributeLocation(SecondaryWeights::Location, "secondaryWeights"_s);
out.bindAttributeLocation(SecondaryJointIds::Location, "secondaryJointIds"); out.bindAttributeLocation(SecondaryJointIds::Location, "secondaryJointIds"_s);
} }
#endif #endif
} }
@ -1158,59 +1158,59 @@ MeshVisualizerGL3D::MeshVisualizerGL3D(CompileState&& state): MeshVisualizerGL3D
|| (flags() & (Flag::TangentDirection|Flag::BitangentFromTangentDirection|Flag::BitangentDirection|Flag::NormalDirection)) || (flags() & (Flag::TangentDirection|Flag::BitangentFromTangentDirection|Flag::BitangentDirection|Flag::NormalDirection))
#endif #endif
) )
_viewportSizeUniform = uniformLocation("viewportSize"); _viewportSizeUniform = uniformLocation("viewportSize"_s);
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(flags() >= Flag::DynamicPerVertexJointCount) if(flags() >= Flag::DynamicPerVertexJointCount)
_perVertexJointCountUniform = uniformLocation("perVertexJointCount"); _perVertexJointCountUniform = uniformLocation("perVertexJointCount"_s);
if(flags() >= Flag::UniformBuffers) { if(flags() >= Flag::UniformBuffers) {
if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"); if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"_s);
} else } else
#endif #endif
{ {
_transformationMatrixUniform = uniformLocation("transformationMatrix"); _transformationMatrixUniform = uniformLocation("transformationMatrix"_s);
_projectionMatrixUniform = uniformLocation("projectionMatrix"); _projectionMatrixUniform = uniformLocation("projectionMatrix"_s);
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(flags() & Flag::TextureTransformation) if(flags() & Flag::TextureTransformation)
_textureMatrixUniform = uniformLocation("textureMatrix"); _textureMatrixUniform = uniformLocation("textureMatrix"_s);
if(flags() & Flag::TextureArrays) if(flags() & Flag::TextureArrays)
_textureLayerUniform = uniformLocation("textureLayer"); _textureLayerUniform = uniformLocation("textureLayer"_s);
#endif #endif
if(flags() & (Flag::Wireframe if(flags() & (Flag::Wireframe
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
|Flag::ObjectId|Flag::VertexId|Flag::PrimitiveIdFromVertexId |Flag::ObjectId|Flag::VertexId|Flag::PrimitiveIdFromVertexId
#endif #endif
)) ))
_colorUniform = uniformLocation("color"); _colorUniform = uniformLocation("color"_s);
if(flags() & Flag::Wireframe) { if(flags() & Flag::Wireframe) {
_wireframeColorUniform = uniformLocation("wireframeColor"); _wireframeColorUniform = uniformLocation("wireframeColor"_s);
_wireframeWidthUniform = uniformLocation("wireframeWidth"); _wireframeWidthUniform = uniformLocation("wireframeWidth"_s);
} }
if(flags() & (Flag::Wireframe if(flags() & (Flag::Wireframe
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
|Flag::TangentDirection|Flag::BitangentFromTangentDirection|Flag::BitangentDirection|Flag::NormalDirection |Flag::TangentDirection|Flag::BitangentFromTangentDirection|Flag::BitangentDirection|Flag::NormalDirection
#endif #endif
)) { )) {
_smoothnessUniform = uniformLocation("smoothness"); _smoothnessUniform = uniformLocation("smoothness"_s);
} }
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(flags() & (Flag::ObjectId|Flag::VertexId|Flag::PrimitiveIdFromVertexId)) { if(flags() & (Flag::ObjectId|Flag::VertexId|Flag::PrimitiveIdFromVertexId)) {
_colorMapOffsetScaleUniform = uniformLocation("colorMapOffsetScale"); _colorMapOffsetScaleUniform = uniformLocation("colorMapOffsetScale"_s);
} }
if(flags() & Flag::ObjectId) if(flags() & Flag::ObjectId)
_objectIdUniform = uniformLocation("objectId"); _objectIdUniform = uniformLocation("objectId"_s);
#endif #endif
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
if(flags() & (Flag::TangentDirection|Flag::BitangentFromTangentDirection|Flag::BitangentDirection|Flag::NormalDirection)) { if(flags() & (Flag::TangentDirection|Flag::BitangentFromTangentDirection|Flag::BitangentDirection|Flag::NormalDirection)) {
_normalMatrixUniform = uniformLocation("normalMatrix"); _normalMatrixUniform = uniformLocation("normalMatrix"_s);
_lineWidthUniform = uniformLocation("lineWidth"); _lineWidthUniform = uniformLocation("lineWidth"_s);
_lineLengthUniform = uniformLocation("lineLength"); _lineLengthUniform = uniformLocation("lineLength"_s);
} }
#endif #endif
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(_jointCount) { if(_jointCount) {
_jointMatricesUniform = uniformLocation("jointMatrices"); _jointMatricesUniform = uniformLocation("jointMatrices"_s);
_perInstanceJointCountUniform = uniformLocation("perInstanceJointCount"); _perInstanceJointCountUniform = uniformLocation("perInstanceJointCount"_s);
} }
#endif #endif
} }
@ -1222,20 +1222,20 @@ MeshVisualizerGL3D::MeshVisualizerGL3D(CompileState&& state): MeshVisualizerGL3D
#endif #endif
{ {
if(flags() & (Flag::ObjectId|Flag::VertexId|Flag::PrimitiveIdFromVertexId)) { if(flags() & (Flag::ObjectId|Flag::VertexId|Flag::PrimitiveIdFromVertexId)) {
setUniform(uniformLocation("colorMapTexture"), ColorMapTextureUnit); setUniform(uniformLocation("colorMapTexture"_s), ColorMapTextureUnit);
} }
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(flags() >= Flag::ObjectIdTexture) if(flags() >= Flag::ObjectIdTexture)
setUniform(uniformLocation("objectIdTextureData"), ObjectIdTextureUnit); setUniform(uniformLocation("objectIdTextureData"_s), ObjectIdTextureUnit);
if(flags() >= Flag::UniformBuffers) { if(flags() >= Flag::UniformBuffers) {
setUniformBlockBinding(uniformBlockIndex("Projection"), ProjectionBufferBinding); setUniformBlockBinding(uniformBlockIndex("Projection"_s), ProjectionBufferBinding);
setUniformBlockBinding(uniformBlockIndex("Transformation"), TransformationBufferBinding); setUniformBlockBinding(uniformBlockIndex("Transformation"_s), TransformationBufferBinding);
setUniformBlockBinding(uniformBlockIndex("Draw"), DrawBufferBinding); setUniformBlockBinding(uniformBlockIndex("Draw"_s), DrawBufferBinding);
setUniformBlockBinding(uniformBlockIndex("Material"), MaterialBufferBinding); setUniformBlockBinding(uniformBlockIndex("Material"_s), MaterialBufferBinding);
if(flags() & Flag::TextureTransformation) if(flags() & Flag::TextureTransformation)
setUniformBlockBinding(uniformBlockIndex("TextureTransformation"), TextureTransformationBufferBinding); setUniformBlockBinding(uniformBlockIndex("TextureTransformation"_s), TextureTransformationBufferBinding);
if(_jointCount) if(_jointCount)
setUniformBlockBinding(uniformBlockIndex("Joint"), JointBufferBinding); setUniformBlockBinding(uniformBlockIndex("Joint"_s), JointBufferBinding);
} }
#endif #endif
} }

158
src/Magnum/Shaders/PhongGL.cpp

@ -147,10 +147,10 @@ PhongGL::CompileState PhongGL::compile(const Configuration& configuration) {
#ifdef MAGNUM_BUILD_STATIC #ifdef MAGNUM_BUILD_STATIC
/* Import resources on static build, if not already */ /* Import resources on static build, if not already */
if(!Utility::Resource::hasGroup("MagnumShadersGL")) if(!Utility::Resource::hasGroup("MagnumShadersGL"_s))
importShaderResources(); importShaderResources();
#endif #endif
Utility::Resource rs("MagnumShadersGL"); Utility::Resource rs("MagnumShadersGL"_s);
const GL::Context& context = GL::Context::current(); const GL::Context& context = GL::Context::current();
@ -207,20 +207,20 @@ PhongGL::CompileState PhongGL::compile(const Configuration& configuration) {
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
|| configuration.flags() >= Flag::ObjectIdTexture || configuration.flags() >= Flag::ObjectIdTexture
#endif #endif
) ? "#define TEXTURED\n" : "") ) ? "#define TEXTURED\n"_s : ""_s)
.addSource(configuration.flags() & Flag::NormalTexture ? "#define NORMAL_TEXTURE\n" : "") .addSource(configuration.flags() & Flag::NormalTexture ? "#define NORMAL_TEXTURE\n"_s : ""_s)
.addSource(configuration.flags() & Flag::Bitangent ? "#define BITANGENT\n" : "") .addSource(configuration.flags() & Flag::Bitangent ? "#define BITANGENT\n"_s : ""_s)
.addSource(configuration.flags() & Flag::VertexColor ? "#define VERTEX_COLOR\n" : "") .addSource(configuration.flags() & Flag::VertexColor ? "#define VERTEX_COLOR\n"_s : ""_s)
.addSource(configuration.flags() & Flag::TextureTransformation ? "#define TEXTURE_TRANSFORMATION\n" : "") .addSource(configuration.flags() & Flag::TextureTransformation ? "#define TEXTURE_TRANSFORMATION\n"_s : ""_s)
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
.addSource(configuration.flags() & Flag::TextureArrays ? "#define TEXTURE_ARRAYS\n" : "") .addSource(configuration.flags() & Flag::TextureArrays ? "#define TEXTURE_ARRAYS\n"_s : ""_s)
#endif #endif
.addSource(configuration.lightCount() ? "#define HAS_LIGHTS\n" : "") .addSource(configuration.lightCount() ? "#define HAS_LIGHTS\n"_s : ""_s)
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
.addSource(configuration.flags() >= Flag::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n" : "") .addSource(configuration.flags() >= Flag::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n"_s : ""_s)
#endif #endif
.addSource(configuration.flags() & Flag::InstancedTransformation ? "#define INSTANCED_TRANSFORMATION\n" : "") .addSource(configuration.flags() & Flag::InstancedTransformation ? "#define INSTANCED_TRANSFORMATION\n"_s : ""_s)
.addSource(configuration.flags() >= Flag::InstancedTextureOffset ? "#define INSTANCED_TEXTURE_OFFSET\n" : ""); .addSource(configuration.flags() >= Flag::InstancedTextureOffset ? "#define INSTANCED_TEXTURE_OFFSET\n"_s : ""_s);
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(configuration.jointCount()) { if(configuration.jointCount()) {
vert.addSource(Utility::format( vert.addSource(Utility::format(
@ -255,27 +255,27 @@ PhongGL::CompileState PhongGL::compile(const Configuration& configuration) {
"#define DRAW_COUNT {}\n", "#define DRAW_COUNT {}\n",
configuration.drawCount(), configuration.drawCount(),
configuration.lightCount())); configuration.lightCount()));
vert.addSource(configuration.flags() >= Flag::MultiDraw ? "#define MULTI_DRAW\n" : ""); vert.addSource(configuration.flags() >= Flag::MultiDraw ? "#define MULTI_DRAW\n"_s : ""_s);
} }
#endif #endif
vert.addSource(rs.getString("generic.glsl")) vert.addSource(rs.getString("generic.glsl"_s))
.addSource(rs.getString("Phong.vert")); .addSource(rs.getString("Phong.vert"_s));
frag.addSource(configuration.flags() & Flag::AmbientTexture ? "#define AMBIENT_TEXTURE\n" : "") frag.addSource(configuration.flags() & Flag::AmbientTexture ? "#define AMBIENT_TEXTURE\n"_s : ""_s)
.addSource(configuration.flags() & Flag::DiffuseTexture ? "#define DIFFUSE_TEXTURE\n" : "") .addSource(configuration.flags() & Flag::DiffuseTexture ? "#define DIFFUSE_TEXTURE\n"_s : ""_s)
.addSource(configuration.flags() & Flag::SpecularTexture ? "#define SPECULAR_TEXTURE\n" : "") .addSource(configuration.flags() & Flag::SpecularTexture ? "#define SPECULAR_TEXTURE\n"_s : ""_s)
.addSource(configuration.flags() & Flag::NormalTexture ? "#define NORMAL_TEXTURE\n" : "") .addSource(configuration.flags() & Flag::NormalTexture ? "#define NORMAL_TEXTURE\n"_s : ""_s)
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
.addSource(configuration.flags() & Flag::TextureArrays ? "#define TEXTURE_ARRAYS\n" : "") .addSource(configuration.flags() & Flag::TextureArrays ? "#define TEXTURE_ARRAYS\n"_s : ""_s)
#endif #endif
.addSource(configuration.flags() & Flag::Bitangent ? "#define BITANGENT\n" : "") .addSource(configuration.flags() & Flag::Bitangent ? "#define BITANGENT\n"_s : ""_s)
.addSource(configuration.flags() & Flag::VertexColor ? "#define VERTEX_COLOR\n" : "") .addSource(configuration.flags() & Flag::VertexColor ? "#define VERTEX_COLOR\n"_s : ""_s)
.addSource(configuration.flags() & Flag::AlphaMask ? "#define ALPHA_MASK\n" : "") .addSource(configuration.flags() & Flag::AlphaMask ? "#define ALPHA_MASK\n"_s : ""_s)
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
.addSource(configuration.flags() & Flag::ObjectId ? "#define OBJECT_ID\n" : "") .addSource(configuration.flags() & Flag::ObjectId ? "#define OBJECT_ID\n"_s : ""_s)
.addSource(configuration.flags() >= Flag::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n" : "") .addSource(configuration.flags() >= Flag::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n"_s : ""_s)
.addSource(configuration.flags() >= Flag::ObjectIdTexture ? "#define OBJECT_ID_TEXTURE\n" : "") .addSource(configuration.flags() >= Flag::ObjectIdTexture ? "#define OBJECT_ID_TEXTURE\n"_s : ""_s)
#endif #endif
.addSource(configuration.flags() & Flag::NoSpecular ? "#define NO_SPECULAR\n" : "") .addSource(configuration.flags() & Flag::NoSpecular ? "#define NO_SPECULAR\n"_s : ""_s)
; ;
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(configuration.flags() >= Flag::UniformBuffers) { if(configuration.flags() >= Flag::UniformBuffers) {
@ -287,8 +287,8 @@ PhongGL::CompileState PhongGL::compile(const Configuration& configuration) {
configuration.drawCount(), configuration.drawCount(),
configuration.materialCount(), configuration.materialCount(),
configuration.lightCount())); configuration.lightCount()));
frag.addSource(configuration.flags() >= Flag::MultiDraw ? "#define MULTI_DRAW\n" : "") frag.addSource(configuration.flags() >= Flag::MultiDraw ? "#define MULTI_DRAW\n"_s : ""_s)
.addSource(configuration.flags() >= Flag::LightCulling ? "#define LIGHT_CULLING\n" : ""); .addSource(configuration.flags() >= Flag::LightCulling ? "#define LIGHT_CULLING\n"_s : ""_s);
} else } else
#endif #endif
{ {
@ -306,8 +306,8 @@ PhongGL::CompileState PhongGL::compile(const Configuration& configuration) {
if(!(configuration.flags() >= Flag::UniformBuffers) && configuration.lightCount()) if(!(configuration.flags() >= Flag::UniformBuffers) && configuration.lightCount())
frag.addSource(std::move(lightInitializer)); frag.addSource(std::move(lightInitializer));
#endif #endif
frag.addSource(rs.getString("generic.glsl")) frag.addSource(rs.getString("generic.glsl"_s))
.addSource(rs.getString("Phong.frag")); .addSource(rs.getString("Phong.frag"_s));
vert.submitCompile(); vert.submitCompile();
frag.submitCompile(); frag.submitCompile();
@ -321,48 +321,48 @@ PhongGL::CompileState PhongGL::compile(const Configuration& configuration) {
if(!context.isExtensionSupported<GL::Extensions::ARB::explicit_attrib_location>(version)) if(!context.isExtensionSupported<GL::Extensions::ARB::explicit_attrib_location>(version))
#endif #endif
{ {
out.bindAttributeLocation(Position::Location, "position"); out.bindAttributeLocation(Position::Location, "position"_s);
if(configuration.lightCount()) if(configuration.lightCount())
out.bindAttributeLocation(Normal::Location, "normal"); out.bindAttributeLocation(Normal::Location, "normal"_s);
if((configuration.flags() & Flag::NormalTexture) && configuration.lightCount()) { if((configuration.flags() & Flag::NormalTexture) && configuration.lightCount()) {
out.bindAttributeLocation(Tangent::Location, "tangent"); out.bindAttributeLocation(Tangent::Location, "tangent"_s);
if(configuration.flags() & Flag::Bitangent) if(configuration.flags() & Flag::Bitangent)
out.bindAttributeLocation(Bitangent::Location, "bitangent"); out.bindAttributeLocation(Bitangent::Location, "bitangent"_s);
} }
if(configuration.flags() & Flag::VertexColor) if(configuration.flags() & Flag::VertexColor)
out.bindAttributeLocation(Color3::Location, "vertexColor"); /* Color4 is the same */ out.bindAttributeLocation(Color3::Location, "vertexColor"_s); /* Color4 is the same */
if(configuration.flags() & (Flag::AmbientTexture|Flag::DiffuseTexture|Flag::SpecularTexture) if(configuration.flags() & (Flag::AmbientTexture|Flag::DiffuseTexture|Flag::SpecularTexture)
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
|| configuration.flags() >= Flag::ObjectIdTexture || configuration.flags() >= Flag::ObjectIdTexture
#endif #endif
) )
out.bindAttributeLocation(TextureCoordinates::Location, "textureCoordinates"); out.bindAttributeLocation(TextureCoordinates::Location, "textureCoordinates"_s);
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(configuration.flags() & Flag::ObjectId) { if(configuration.flags() & Flag::ObjectId) {
out.bindFragmentDataLocation(ColorOutput, "color"); out.bindFragmentDataLocation(ColorOutput, "color"_s);
out.bindFragmentDataLocation(ObjectIdOutput, "objectId"); out.bindFragmentDataLocation(ObjectIdOutput, "objectId"_s);
} }
if(configuration.flags() >= Flag::InstancedObjectId) if(configuration.flags() >= Flag::InstancedObjectId)
out.bindAttributeLocation(ObjectId::Location, "instanceObjectId"); out.bindAttributeLocation(ObjectId::Location, "instanceObjectId"_s);
#endif #endif
if(configuration.flags() & Flag::InstancedTransformation) { if(configuration.flags() & Flag::InstancedTransformation) {
out.bindAttributeLocation(TransformationMatrix::Location, "instancedTransformationMatrix"); out.bindAttributeLocation(TransformationMatrix::Location, "instancedTransformationMatrix"_s);
if(configuration.lightCount()) if(configuration.lightCount())
out.bindAttributeLocation(NormalMatrix::Location, "instancedNormalMatrix"); out.bindAttributeLocation(NormalMatrix::Location, "instancedNormalMatrix"_s);
} }
if(configuration.flags() >= Flag::InstancedTextureOffset) if(configuration.flags() >= Flag::InstancedTextureOffset)
out.bindAttributeLocation(TextureOffset::Location, "instancedTextureOffset"); out.bindAttributeLocation(TextureOffset::Location, "instancedTextureOffset"_s);
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
/* Configuration::setJointCount() checks that jointCount and /* Configuration::setJointCount() checks that jointCount and
perVertexJointCount / secondaryPerVertexJointCount are either all perVertexJointCount / secondaryPerVertexJointCount are either all
zero or non-zero so we don't need to check for jointCount() here */ zero or non-zero so we don't need to check for jointCount() here */
if(configuration.perVertexJointCount()) { if(configuration.perVertexJointCount()) {
out.bindAttributeLocation(Weights::Location, "weights"); out.bindAttributeLocation(Weights::Location, "weights"_s);
out.bindAttributeLocation(JointIds::Location, "jointIds"); out.bindAttributeLocation(JointIds::Location, "jointIds"_s);
} }
if(configuration.secondaryPerVertexJointCount()) { if(configuration.secondaryPerVertexJointCount()) {
out.bindAttributeLocation(SecondaryWeights::Location, "secondaryWeights"); out.bindAttributeLocation(SecondaryWeights::Location, "secondaryWeights"_s);
out.bindAttributeLocation(SecondaryJointIds::Location, "secondaryJointIds"); out.bindAttributeLocation(SecondaryJointIds::Location, "secondaryJointIds"_s);
} }
#endif #endif
} }
@ -415,44 +415,44 @@ PhongGL::PhongGL(CompileState&& state): PhongGL{static_cast<PhongGL&&>(std::move
{ {
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(_flags >= Flag::DynamicPerVertexJointCount) if(_flags >= Flag::DynamicPerVertexJointCount)
_perVertexJointCountUniform = uniformLocation("perVertexJointCount"); _perVertexJointCountUniform = uniformLocation("perVertexJointCount"_s);
if(_flags >= Flag::UniformBuffers) { if(_flags >= Flag::UniformBuffers) {
if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"); if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"_s);
} else } else
#endif #endif
{ {
_transformationMatrixUniform = uniformLocation("transformationMatrix"); _transformationMatrixUniform = uniformLocation("transformationMatrix"_s);
if(_flags & Flag::TextureTransformation) if(_flags & Flag::TextureTransformation)
_textureMatrixUniform = uniformLocation("textureMatrix"); _textureMatrixUniform = uniformLocation("textureMatrix"_s);
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(_flags & Flag::TextureArrays) if(_flags & Flag::TextureArrays)
_textureLayerUniform = uniformLocation("textureLayer"); _textureLayerUniform = uniformLocation("textureLayer"_s);
#endif #endif
_projectionMatrixUniform = uniformLocation("projectionMatrix"); _projectionMatrixUniform = uniformLocation("projectionMatrix"_s);
_ambientColorUniform = uniformLocation("ambientColor"); _ambientColorUniform = uniformLocation("ambientColor"_s);
if(_lightCount) { if(_lightCount) {
_normalMatrixUniform = uniformLocation("normalMatrix"); _normalMatrixUniform = uniformLocation("normalMatrix"_s);
_diffuseColorUniform = uniformLocation("diffuseColor"); _diffuseColorUniform = uniformLocation("diffuseColor"_s);
if(!(_flags & Flag::NoSpecular)) { if(!(_flags & Flag::NoSpecular)) {
_specularColorUniform = uniformLocation("specularColor"); _specularColorUniform = uniformLocation("specularColor"_s);
_shininessUniform = uniformLocation("shininess"); _shininessUniform = uniformLocation("shininess"_s);
} }
if(_flags & Flag::NormalTexture) if(_flags & Flag::NormalTexture)
_normalTextureScaleUniform = uniformLocation("normalTextureScale"); _normalTextureScaleUniform = uniformLocation("normalTextureScale"_s);
_lightPositionsUniform = uniformLocation("lightPositions"); _lightPositionsUniform = uniformLocation("lightPositions"_s);
_lightColorsUniform = uniformLocation("lightColors"); _lightColorsUniform = uniformLocation("lightColors"_s);
if(!(_flags & Flag::NoSpecular)) if(!(_flags & Flag::NoSpecular))
_lightSpecularColorsUniform = uniformLocation("lightSpecularColors"); _lightSpecularColorsUniform = uniformLocation("lightSpecularColors"_s);
_lightRangesUniform = uniformLocation("lightRanges"); _lightRangesUniform = uniformLocation("lightRanges"_s);
} }
if(_flags & Flag::AlphaMask) _alphaMaskUniform = uniformLocation("alphaMask"); if(_flags & Flag::AlphaMask) _alphaMaskUniform = uniformLocation("alphaMask"_s);
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(_flags & Flag::ObjectId) _objectIdUniform = uniformLocation("objectId"); if(_flags & Flag::ObjectId) _objectIdUniform = uniformLocation("objectId"_s);
#endif #endif
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(_jointCount) { if(_jointCount) {
_jointMatricesUniform = uniformLocation("jointMatrices"); _jointMatricesUniform = uniformLocation("jointMatrices"_s);
_perInstanceJointCountUniform = uniformLocation("perInstanceJointCount"); _perInstanceJointCountUniform = uniformLocation("perInstanceJointCount"_s);
} }
#endif #endif
} }
@ -462,25 +462,25 @@ PhongGL::PhongGL(CompileState&& state): PhongGL{static_cast<PhongGL&&>(std::move
if(_flags && !context.isExtensionSupported<GL::Extensions::ARB::shading_language_420pack>(state._version)) if(_flags && !context.isExtensionSupported<GL::Extensions::ARB::shading_language_420pack>(state._version))
#endif #endif
{ {
if(_flags & Flag::AmbientTexture) setUniform(uniformLocation("ambientTexture"), AmbientTextureUnit); if(_flags & Flag::AmbientTexture) setUniform(uniformLocation("ambientTexture"_s), AmbientTextureUnit);
if(_lightCount) { if(_lightCount) {
if(_flags & Flag::DiffuseTexture) setUniform(uniformLocation("diffuseTexture"), DiffuseTextureUnit); if(_flags & Flag::DiffuseTexture) setUniform(uniformLocation("diffuseTexture"_s), DiffuseTextureUnit);
if(_flags & Flag::SpecularTexture) setUniform(uniformLocation("specularTexture"), SpecularTextureUnit); if(_flags & Flag::SpecularTexture) setUniform(uniformLocation("specularTexture"_s), SpecularTextureUnit);
if(_flags & Flag::NormalTexture) setUniform(uniformLocation("normalTexture"), NormalTextureUnit); if(_flags & Flag::NormalTexture) setUniform(uniformLocation("normalTexture"_s), NormalTextureUnit);
} }
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(_flags >= Flag::ObjectIdTexture) setUniform(uniformLocation("objectIdTextureData"), ObjectIdTextureUnit); if(_flags >= Flag::ObjectIdTexture) setUniform(uniformLocation("objectIdTextureData"_s), ObjectIdTextureUnit);
if(_flags >= Flag::UniformBuffers) { if(_flags >= Flag::UniformBuffers) {
setUniformBlockBinding(uniformBlockIndex("Projection"), ProjectionBufferBinding); setUniformBlockBinding(uniformBlockIndex("Projection"_s), ProjectionBufferBinding);
setUniformBlockBinding(uniformBlockIndex("Transformation"), TransformationBufferBinding); setUniformBlockBinding(uniformBlockIndex("Transformation"_s), TransformationBufferBinding);
setUniformBlockBinding(uniformBlockIndex("Draw"), DrawBufferBinding); setUniformBlockBinding(uniformBlockIndex("Draw"_s), DrawBufferBinding);
setUniformBlockBinding(uniformBlockIndex("Material"), MaterialBufferBinding); setUniformBlockBinding(uniformBlockIndex("Material"_s), MaterialBufferBinding);
if(_flags & Flag::TextureTransformation) if(_flags & Flag::TextureTransformation)
setUniformBlockBinding(uniformBlockIndex("TextureTransformation"), TextureTransformationBufferBinding); setUniformBlockBinding(uniformBlockIndex("TextureTransformation"_s), TextureTransformationBufferBinding);
if(_lightCount) if(_lightCount)
setUniformBlockBinding(uniformBlockIndex("Light"), LightBufferBinding); setUniformBlockBinding(uniformBlockIndex("Light"_s), LightBufferBinding);
if(_jointCount) if(_jointCount)
setUniformBlockBinding(uniformBlockIndex("Joint"), JointBufferBinding); setUniformBlockBinding(uniformBlockIndex("Joint"_s), JointBufferBinding);
} }
#endif #endif
} }

46
src/Magnum/Shaders/VectorGL.cpp

@ -49,6 +49,8 @@
namespace Magnum { namespace Shaders { namespace Magnum { namespace Shaders {
using namespace Containers::Literals;
namespace { namespace {
enum: Int { TextureUnit = 6 }; enum: Int { TextureUnit = 6 };
@ -91,10 +93,10 @@ template<UnsignedInt dimensions> typename VectorGL<dimensions>::CompileState Vec
#ifdef MAGNUM_BUILD_STATIC #ifdef MAGNUM_BUILD_STATIC
/* Import resources on static build, if not already */ /* Import resources on static build, if not already */
if(!Utility::Resource::hasGroup("MagnumShadersGL")) if(!Utility::Resource::hasGroup("MagnumShadersGL"_s))
importShaderResources(); importShaderResources();
#endif #endif
Utility::Resource rs("MagnumShadersGL"); Utility::Resource rs("MagnumShadersGL"_s);
const GL::Context& context = GL::Context::current(); const GL::Context& context = GL::Context::current();
@ -107,19 +109,19 @@ template<UnsignedInt dimensions> typename VectorGL<dimensions>::CompileState Vec
GL::Shader vert = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Vertex); GL::Shader vert = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Vertex);
GL::Shader frag = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Fragment); GL::Shader frag = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Fragment);
vert.addSource(configuration.flags() & Flag::TextureTransformation ? "#define TEXTURE_TRANSFORMATION\n" : "") vert.addSource(configuration.flags() & Flag::TextureTransformation ? "#define TEXTURE_TRANSFORMATION\n"_s : ""_s)
.addSource(dimensions == 2 ? "#define TWO_DIMENSIONS\n" : "#define THREE_DIMENSIONS\n"); .addSource(dimensions == 2 ? "#define TWO_DIMENSIONS\n"_s : "#define THREE_DIMENSIONS\n"_s);
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(configuration.flags() >= Flag::UniformBuffers) { if(configuration.flags() >= Flag::UniformBuffers) {
vert.addSource(Utility::format( vert.addSource(Utility::format(
"#define UNIFORM_BUFFERS\n" "#define UNIFORM_BUFFERS\n"
"#define DRAW_COUNT {}\n", "#define DRAW_COUNT {}\n",
configuration.drawCount())); configuration.drawCount()));
vert.addSource(configuration.flags() >= Flag::MultiDraw ? "#define MULTI_DRAW\n" : ""); vert.addSource(configuration.flags() >= Flag::MultiDraw ? "#define MULTI_DRAW\n"_s : ""_s);
} }
#endif #endif
vert.addSource(rs.getString("generic.glsl")) vert.addSource(rs.getString("generic.glsl"_s))
.addSource(rs.getString("Vector.vert")); .addSource(rs.getString("Vector.vert"_s));
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(configuration.flags() >= Flag::UniformBuffers) { if(configuration.flags() >= Flag::UniformBuffers) {
frag.addSource(Utility::format( frag.addSource(Utility::format(
@ -128,11 +130,11 @@ template<UnsignedInt dimensions> typename VectorGL<dimensions>::CompileState Vec
"#define MATERIAL_COUNT {}\n", "#define MATERIAL_COUNT {}\n",
configuration.drawCount(), configuration.drawCount(),
configuration.materialCount())); configuration.materialCount()));
frag.addSource(configuration.flags() >= Flag::MultiDraw ? "#define MULTI_DRAW\n" : ""); frag.addSource(configuration.flags() >= Flag::MultiDraw ? "#define MULTI_DRAW\n"_s : ""_s);
} }
#endif #endif
frag.addSource(rs.getString("generic.glsl")) frag.addSource(rs.getString("generic.glsl"_s))
.addSource(rs.getString("Vector.frag")); .addSource(rs.getString("Vector.frag"_s));
vert.submitCompile(); vert.submitCompile();
frag.submitCompile(); frag.submitCompile();
@ -152,8 +154,8 @@ template<UnsignedInt dimensions> typename VectorGL<dimensions>::CompileState Vec
if(!context.isExtensionSupported<GL::Extensions::ARB::explicit_attrib_location>(version)) if(!context.isExtensionSupported<GL::Extensions::ARB::explicit_attrib_location>(version))
#endif #endif
{ {
out.bindAttributeLocation(Position::Location, "position"); out.bindAttributeLocation(Position::Location, "position"_s);
out.bindAttributeLocation(TextureCoordinates::Location, "textureCoordinates"); out.bindAttributeLocation(TextureCoordinates::Location, "textureCoordinates"_s);
} }
#endif #endif
@ -202,15 +204,15 @@ template<UnsignedInt dimensions> VectorGL<dimensions>::VectorGL(CompileState&& s
{ {
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(_flags >= Flag::UniformBuffers) { if(_flags >= Flag::UniformBuffers) {
if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"); if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"_s);
} else } else
#endif #endif
{ {
_transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"); _transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"_s);
if(_flags & Flag::TextureTransformation) if(_flags & Flag::TextureTransformation)
_textureMatrixUniform = uniformLocation("textureMatrix"); _textureMatrixUniform = uniformLocation("textureMatrix"_s);
_backgroundColorUniform = uniformLocation("backgroundColor"); _backgroundColorUniform = uniformLocation("backgroundColor"_s);
_colorUniform = uniformLocation("color"); _colorUniform = uniformLocation("color"_s);
} }
} }
@ -218,14 +220,14 @@ template<UnsignedInt dimensions> VectorGL<dimensions>::VectorGL(CompileState&& s
if(!context.isExtensionSupported<GL::Extensions::ARB::shading_language_420pack>(state._version)) if(!context.isExtensionSupported<GL::Extensions::ARB::shading_language_420pack>(state._version))
#endif #endif
{ {
setUniform(uniformLocation("vectorTexture"), TextureUnit); setUniform(uniformLocation("vectorTexture"_s), TextureUnit);
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(_flags >= Flag::UniformBuffers) { if(_flags >= Flag::UniformBuffers) {
setUniformBlockBinding(uniformBlockIndex("TransformationProjection"), TransformationProjectionBufferBinding); setUniformBlockBinding(uniformBlockIndex("TransformationProjection"_s), TransformationProjectionBufferBinding);
setUniformBlockBinding(uniformBlockIndex("Draw"), DrawBufferBinding); setUniformBlockBinding(uniformBlockIndex("Draw"_s), DrawBufferBinding);
if(_flags & Flag::TextureTransformation) if(_flags & Flag::TextureTransformation)
setUniformBlockBinding(uniformBlockIndex("TextureTransformation"), TextureTransformationBufferBinding); setUniformBlockBinding(uniformBlockIndex("TextureTransformation"_s), TextureTransformationBufferBinding);
setUniformBlockBinding(uniformBlockIndex("Material"), MaterialBufferBinding); setUniformBlockBinding(uniformBlockIndex("Material"_s), MaterialBufferBinding);
} }
#endif #endif
} }

28
src/Magnum/Shaders/VertexColorGL.cpp

@ -47,6 +47,8 @@
namespace Magnum { namespace Shaders { namespace Magnum { namespace Shaders {
using namespace Containers::Literals;
namespace { namespace {
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
enum: Int { enum: Int {
@ -82,10 +84,10 @@ template<UnsignedInt dimensions> typename VertexColorGL<dimensions>::CompileStat
#ifdef MAGNUM_BUILD_STATIC #ifdef MAGNUM_BUILD_STATIC
/* Import resources on static build, if not already */ /* Import resources on static build, if not already */
if(!Utility::Resource::hasGroup("MagnumShadersGL")) if(!Utility::Resource::hasGroup("MagnumShadersGL"_s))
importShaderResources(); importShaderResources();
#endif #endif
Utility::Resource rs("MagnumShadersGL"); Utility::Resource rs("MagnumShadersGL"_s);
const GL::Context& context = GL::Context::current(); const GL::Context& context = GL::Context::current();
@ -98,20 +100,20 @@ template<UnsignedInt dimensions> typename VertexColorGL<dimensions>::CompileStat
GL::Shader vert = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Vertex); GL::Shader vert = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Vertex);
GL::Shader frag = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Fragment); GL::Shader frag = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Fragment);
vert.addSource(dimensions == 2 ? "#define TWO_DIMENSIONS\n" : "#define THREE_DIMENSIONS\n"); vert.addSource(dimensions == 2 ? "#define TWO_DIMENSIONS\n"_s : "#define THREE_DIMENSIONS\n"_s);
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(configuration.flags() >= Flag::UniformBuffers) { if(configuration.flags() >= Flag::UniformBuffers) {
vert.addSource(Utility::format( vert.addSource(Utility::format(
"#define UNIFORM_BUFFERS\n" "#define UNIFORM_BUFFERS\n"
"#define DRAW_COUNT {}\n", "#define DRAW_COUNT {}\n",
configuration.drawCount())); configuration.drawCount()));
vert.addSource(configuration.flags() >= Flag::MultiDraw ? "#define MULTI_DRAW\n" : ""); vert.addSource(configuration.flags() >= Flag::MultiDraw ? "#define MULTI_DRAW\n"_s : ""_s);
} }
#endif #endif
vert.addSource(rs.getString("generic.glsl")) vert.addSource(rs.getString("generic.glsl"_s))
.addSource(rs.getString("VertexColor.vert")); .addSource(rs.getString("VertexColor.vert"_s));
frag.addSource(rs.getString("generic.glsl")) frag.addSource(rs.getString("generic.glsl"_s))
.addSource(rs.getString("VertexColor.frag")); .addSource(rs.getString("VertexColor.frag"_s));
vert.submitCompile(); vert.submitCompile();
frag.submitCompile(); frag.submitCompile();
@ -130,8 +132,8 @@ template<UnsignedInt dimensions> typename VertexColorGL<dimensions>::CompileStat
if(!context.isExtensionSupported<GL::Extensions::ARB::explicit_attrib_location>(version)) if(!context.isExtensionSupported<GL::Extensions::ARB::explicit_attrib_location>(version))
#endif #endif
{ {
out.bindAttributeLocation(Position::Location, "position"); out.bindAttributeLocation(Position::Location, "position"_s);
out.bindAttributeLocation(Color3::Location, "color"); /* Color4 is the same */ out.bindAttributeLocation(Color3::Location, "color"_s); /* Color4 is the same */
} }
#endif #endif
@ -179,11 +181,11 @@ template<UnsignedInt dimensions> VertexColorGL<dimensions>::VertexColorGL(Compil
{ {
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(_flags >= Flag::UniformBuffers) { if(_flags >= Flag::UniformBuffers) {
if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"); if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"_s);
} else } else
#endif #endif
{ {
_transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"); _transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"_s);
} }
} }
@ -193,7 +195,7 @@ template<UnsignedInt dimensions> VertexColorGL<dimensions>::VertexColorGL(Compil
&& !context.isExtensionSupported<GL::Extensions::ARB::shading_language_420pack>(state._version) && !context.isExtensionSupported<GL::Extensions::ARB::shading_language_420pack>(state._version)
#endif #endif
) { ) {
setUniformBlockBinding(uniformBlockIndex("TransformationProjection"), TransformationProjectionBufferBinding); setUniformBlockBinding(uniformBlockIndex("TransformationProjection"_s), TransformationProjectionBufferBinding);
} }
#endif #endif

20
src/Magnum/TextureTools/DistanceField.cpp

@ -49,6 +49,8 @@ static void importTextureToolResources() {
namespace Magnum { namespace TextureTools { namespace Magnum { namespace TextureTools {
using namespace Containers::Literals;
namespace { namespace {
class DistanceFieldShader: public GL::AbstractShaderProgram { class DistanceFieldShader: public GL::AbstractShaderProgram {
@ -86,10 +88,10 @@ class DistanceFieldShader: public GL::AbstractShaderProgram {
DistanceFieldShader::DistanceFieldShader(const UnsignedInt radius) { DistanceFieldShader::DistanceFieldShader(const UnsignedInt radius) {
#ifdef MAGNUM_BUILD_STATIC #ifdef MAGNUM_BUILD_STATIC
/* Import resources on static build, if not already */ /* Import resources on static build, if not already */
if(!Utility::Resource::hasGroup("MagnumTextureTools")) if(!Utility::Resource::hasGroup("MagnumTextureTools"_s))
importTextureToolResources(); importTextureToolResources();
#endif #endif
Utility::Resource rs("MagnumTextureTools"); Utility::Resource rs("MagnumTextureTools"_s);
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
const GL::Version v = GL::Context::current().supportedVersion({GL::Version::GL320, GL::Version::GL300, GL::Version::GL210}); const GL::Version v = GL::Context::current().supportedVersion({GL::Version::GL320, GL::Version::GL300, GL::Version::GL210});
@ -100,10 +102,10 @@ DistanceFieldShader::DistanceFieldShader(const UnsignedInt radius) {
GL::Shader vert = Shaders::Implementation::createCompatibilityShader(rs, v, GL::Shader::Type::Vertex); GL::Shader vert = Shaders::Implementation::createCompatibilityShader(rs, v, GL::Shader::Type::Vertex);
GL::Shader frag = Shaders::Implementation::createCompatibilityShader(rs, v, GL::Shader::Type::Fragment); GL::Shader frag = Shaders::Implementation::createCompatibilityShader(rs, v, GL::Shader::Type::Fragment);
vert.addSource(rs.getString("FullScreenTriangle.glsl")) vert.addSource(rs.getString("FullScreenTriangle.glsl"_s))
.addSource(rs.getString("DistanceFieldShader.vert")); .addSource(rs.getString("DistanceFieldShader.vert"_s));
frag.addSource(Utility::format("#define RADIUS {}\n", radius)) frag.addSource(Utility::format("#define RADIUS {}\n", radius))
.addSource(rs.getString("DistanceFieldShader.frag")); .addSource(rs.getString("DistanceFieldShader.frag"_s));
CORRADE_INTERNAL_ASSERT_OUTPUT(vert.compile() && frag.compile()); CORRADE_INTERNAL_ASSERT_OUTPUT(vert.compile() && frag.compile());
@ -113,7 +115,7 @@ DistanceFieldShader::DistanceFieldShader(const UnsignedInt radius) {
if(!GL::Context::current().isExtensionSupported<GL::Extensions::MAGNUM::shader_vertex_id>()) if(!GL::Context::current().isExtensionSupported<GL::Extensions::MAGNUM::shader_vertex_id>())
#endif #endif
{ {
bindAttributeLocation(Position::Location, "position"); bindAttributeLocation(Position::Location, "position"_s);
} }
CORRADE_INTERNAL_ASSERT_OUTPUT(link()); CORRADE_INTERNAL_ASSERT_OUTPUT(link());
@ -122,7 +124,7 @@ DistanceFieldShader::DistanceFieldShader(const UnsignedInt radius) {
if(!GL::Context::current().isExtensionSupported<GL::Extensions::ARB::explicit_uniform_location>()) if(!GL::Context::current().isExtensionSupported<GL::Extensions::ARB::explicit_uniform_location>())
#endif #endif
{ {
scalingUniform = uniformLocation("scaling"); scalingUniform = uniformLocation("scaling"_s);
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
if(!GL::Context::current().isVersionSupported(GL::Version::GL320)) if(!GL::Context::current().isVersionSupported(GL::Version::GL320))
@ -130,7 +132,7 @@ DistanceFieldShader::DistanceFieldShader(const UnsignedInt radius) {
if(!GL::Context::current().isVersionSupported(GL::Version::GLES300)) if(!GL::Context::current().isVersionSupported(GL::Version::GLES300))
#endif #endif
{ {
imageSizeInvertedUniform = uniformLocation("imageSizeInverted"); imageSizeInvertedUniform = uniformLocation("imageSizeInverted"_s);
} }
} }
@ -138,7 +140,7 @@ DistanceFieldShader::DistanceFieldShader(const UnsignedInt radius) {
if(!GL::Context::current().isExtensionSupported<GL::Extensions::ARB::shading_language_420pack>()) if(!GL::Context::current().isExtensionSupported<GL::Extensions::ARB::shading_language_420pack>())
#endif #endif
{ {
setUniform(uniformLocation("textureData"), TextureUnit); setUniform(uniformLocation("textureData"_s), TextureUnit);
} }
} }

Loading…
Cancel
Save