From 44b27f53bd704a7a628f58c8073606a8513e710e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 31 Dec 2022 18:18:26 +0100 Subject: [PATCH] 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. --- src/Magnum/DebugTools/TextureImage.cpp | 16 +- src/Magnum/Shaders/DistanceFieldVectorGL.cpp | 50 ++-- src/Magnum/Shaders/FlatGL.cpp | 104 +++---- .../CreateCompatibilityShader.h | 14 +- src/Magnum/Shaders/MeshVisualizerGL.cpp | 274 +++++++++--------- src/Magnum/Shaders/PhongGL.cpp | 158 +++++----- src/Magnum/Shaders/VectorGL.cpp | 46 +-- src/Magnum/Shaders/VertexColorGL.cpp | 28 +- src/Magnum/TextureTools/DistanceField.cpp | 20 +- 9 files changed, 361 insertions(+), 349 deletions(-) diff --git a/src/Magnum/DebugTools/TextureImage.cpp b/src/Magnum/DebugTools/TextureImage.cpp index bf01784f56..f30c0e6656 100644 --- a/src/Magnum/DebugTools/TextureImage.cpp +++ b/src/Magnum/DebugTools/TextureImage.cpp @@ -56,6 +56,8 @@ static void importDebugToolsResources() { namespace Magnum { namespace DebugTools { #if defined(MAGNUM_TARGET_GLES) && !defined(MAGNUM_TARGET_GLES2) +using namespace Containers::Literals; + namespace { class FloatReinterpretShader: public GL::AbstractShaderProgram { @@ -75,7 +77,7 @@ class FloatReinterpretShader: public GL::AbstractShaderProgram { FloatReinterpretShader::FloatReinterpretShader() { #ifdef MAGNUM_BUILD_STATIC /* Import resources on static build, if not already */ - if(!Utility::Resource::hasGroup("MagnumDebugTools")) + if(!Utility::Resource::hasGroup("MagnumDebugTools"_s)) importDebugToolsResources(); #endif Utility::Resource rs{"MagnumDebugTools"}; @@ -83,21 +85,21 @@ FloatReinterpretShader::FloatReinterpretShader() { GL::Shader vert{GL::Version::GLES300, GL::Shader::Type::Vertex}; GL::Shader frag{GL::Version::GLES300, GL::Shader::Type::Fragment}; if(!GL::Context::current().isExtensionSupported()) - vert.addSource("#define DISABLE_GL_MAGNUM_shader_vertex_id\n"); - vert.addSource(rs.getString("TextureImage.vert")); - frag.addSource(rs.getString("TextureImage.frag")); + vert.addSource("#define DISABLE_GL_MAGNUM_shader_vertex_id\n"_s); + vert.addSource(rs.getString("TextureImage.vert"_s)); + frag.addSource(rs.getString("TextureImage.frag"_s)); CORRADE_INTERNAL_ASSERT_OUTPUT(vert.compile() && frag.compile()); attachShaders({vert, frag}); if(!GL::Context::current().isExtensionSupported()) { - bindAttributeLocation(0, "position"); + bindAttributeLocation(0, "position"_s); } CORRADE_INTERNAL_ASSERT_OUTPUT(link()); - levelUniform = uniformLocation("level"); - setUniform(uniformLocation("textureData"), 0); + levelUniform = uniformLocation("level"_s); + setUniform(uniformLocation("textureData"_s), 0); } } diff --git a/src/Magnum/Shaders/DistanceFieldVectorGL.cpp b/src/Magnum/Shaders/DistanceFieldVectorGL.cpp index 7c6592445b..adcb2cdc1d 100644 --- a/src/Magnum/Shaders/DistanceFieldVectorGL.cpp +++ b/src/Magnum/Shaders/DistanceFieldVectorGL.cpp @@ -49,6 +49,8 @@ namespace Magnum { namespace Shaders { +using namespace Containers::Literals; + namespace { enum: Int { TextureUnit = 6 }; @@ -91,10 +93,10 @@ template typename DistanceFieldVectorGL::Com #ifdef MAGNUM_BUILD_STATIC /* Import resources on static build, if not already */ - if(!Utility::Resource::hasGroup("MagnumShadersGL")) + if(!Utility::Resource::hasGroup("MagnumShadersGL"_s)) importShaderResources(); #endif - Utility::Resource rs("MagnumShadersGL"); + Utility::Resource rs("MagnumShadersGL"_s); const GL::Context& context = GL::Context::current(); @@ -107,19 +109,19 @@ template typename DistanceFieldVectorGL::Com GL::Shader vert = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Vertex); GL::Shader frag = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Fragment); - vert.addSource(configuration.flags() & Flag::TextureTransformation ? "#define TEXTURE_TRANSFORMATION\n" : "") - .addSource(dimensions == 2 ? "#define TWO_DIMENSIONS\n" : "#define THREE_DIMENSIONS\n"); + vert.addSource(configuration.flags() & Flag::TextureTransformation ? "#define TEXTURE_TRANSFORMATION\n"_s : ""_s) + .addSource(dimensions == 2 ? "#define TWO_DIMENSIONS\n"_s : "#define THREE_DIMENSIONS\n"_s); #ifndef MAGNUM_TARGET_GLES2 if(configuration.flags() >= Flag::UniformBuffers) { vert.addSource(Utility::format( "#define UNIFORM_BUFFERS\n" "#define DRAW_COUNT {}\n", 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 - vert.addSource(rs.getString("generic.glsl")) - .addSource(rs.getString("Vector.vert")); + vert.addSource(rs.getString("generic.glsl"_s)) + .addSource(rs.getString("Vector.vert"_s)); #ifndef MAGNUM_TARGET_GLES2 if(configuration.flags() >= Flag::UniformBuffers) { frag.addSource(Utility::format( @@ -128,11 +130,11 @@ template typename DistanceFieldVectorGL::Com "#define DRAW_COUNT {}\n", configuration.materialCount(), 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 - frag.addSource(rs.getString("generic.glsl")) - .addSource(rs.getString("DistanceFieldVector.frag")); + frag.addSource(rs.getString("generic.glsl"_s)) + .addSource(rs.getString("DistanceFieldVector.frag"_s)); vert.submitCompile(); frag.submitCompile(); @@ -152,8 +154,8 @@ template typename DistanceFieldVectorGL::Com if(!context.isExtensionSupported(version)) #endif { - out.bindAttributeLocation(Position::Location, "position"); - out.bindAttributeLocation(TextureCoordinates::Location, "textureCoordinates"); + out.bindAttributeLocation(Position::Location, "position"_s); + out.bindAttributeLocation(TextureCoordinates::Location, "textureCoordinates"_s); } #endif @@ -201,17 +203,17 @@ template DistanceFieldVectorGL::DistanceFiel { #ifndef MAGNUM_TARGET_GLES2 if(_flags >= Flag::UniformBuffers) { - if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"); + if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"_s); } else #endif { - _transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"); + _transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"_s); if(_flags & Flag::TextureTransformation) - _textureMatrixUniform = uniformLocation("textureMatrix"); - _colorUniform = uniformLocation("color"); - _outlineColorUniform = uniformLocation("outlineColor"); - _outlineRangeUniform = uniformLocation("outlineRange"); - _smoothnessUniform = uniformLocation("smoothness"); + _textureMatrixUniform = uniformLocation("textureMatrix"_s); + _colorUniform = uniformLocation("color"_s); + _outlineColorUniform = uniformLocation("outlineColor"_s); + _outlineRangeUniform = uniformLocation("outlineRange"_s); + _smoothnessUniform = uniformLocation("smoothness"_s); } } @@ -219,14 +221,14 @@ template DistanceFieldVectorGL::DistanceFiel if(!context.isExtensionSupported(state._version)) #endif { - setUniform(uniformLocation("vectorTexture"), TextureUnit); + setUniform(uniformLocation("vectorTexture"_s), TextureUnit); #ifndef MAGNUM_TARGET_GLES2 if(_flags >= Flag::UniformBuffers) { - setUniformBlockBinding(uniformBlockIndex("TransformationProjection"), TransformationProjectionBufferBinding); - setUniformBlockBinding(uniformBlockIndex("Draw"), DrawBufferBinding); - setUniformBlockBinding(uniformBlockIndex("Material"), MaterialBufferBinding); + setUniformBlockBinding(uniformBlockIndex("TransformationProjection"_s), TransformationProjectionBufferBinding); + setUniformBlockBinding(uniformBlockIndex("Draw"_s), DrawBufferBinding); + setUniformBlockBinding(uniformBlockIndex("Material"_s), MaterialBufferBinding); if(_flags & Flag::TextureTransformation) - setUniformBlockBinding(uniformBlockIndex("TextureTransformation"), TextureTransformationBufferBinding); + setUniformBlockBinding(uniformBlockIndex("TextureTransformation"_s), TextureTransformationBufferBinding); } #endif } diff --git a/src/Magnum/Shaders/FlatGL.cpp b/src/Magnum/Shaders/FlatGL.cpp index 3362cea71f..f74e67199a 100644 --- a/src/Magnum/Shaders/FlatGL.cpp +++ b/src/Magnum/Shaders/FlatGL.cpp @@ -132,10 +132,10 @@ template typename FlatGL::CompileState FlatG #ifdef MAGNUM_BUILD_STATIC /* Import resources on static build, if not already */ - if(!Utility::Resource::hasGroup("MagnumShadersGL")) + if(!Utility::Resource::hasGroup("MagnumShadersGL"_s)) importShaderResources(); #endif - Utility::Resource rs("MagnumShadersGL"); + Utility::Resource rs("MagnumShadersGL"_s); const GL::Context& context = GL::Context::current(); @@ -165,18 +165,18 @@ template typename FlatGL::CompileState FlatG #ifndef MAGNUM_TARGET_GLES2 || configuration.flags() >= Flag::ObjectIdTexture #endif - ) ? "#define TEXTURED\n" : "") - .addSource(configuration.flags() & Flag::VertexColor ? "#define VERTEX_COLOR\n" : "") - .addSource(configuration.flags() & Flag::TextureTransformation ? "#define TEXTURE_TRANSFORMATION\n" : "") + ) ? "#define TEXTURED\n"_s : ""_s) + .addSource(configuration.flags() & Flag::VertexColor ? "#define VERTEX_COLOR\n"_s : ""_s) + .addSource(configuration.flags() & Flag::TextureTransformation ? "#define TEXTURE_TRANSFORMATION\n"_s : ""_s) #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 - .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 - .addSource(configuration.flags() >= Flag::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n" : "") + .addSource(configuration.flags() >= Flag::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n"_s : ""_s) #endif - .addSource(configuration.flags() & Flag::InstancedTransformation ? "#define INSTANCED_TRANSFORMATION\n" : "") - .addSource(configuration.flags() >= Flag::InstancedTextureOffset ? "#define INSTANCED_TEXTURE_OFFSET\n" : ""); + .addSource(configuration.flags() & Flag::InstancedTransformation ? "#define INSTANCED_TRANSFORMATION\n"_s : ""_s) + .addSource(configuration.flags() >= Flag::InstancedTextureOffset ? "#define INSTANCED_TEXTURE_OFFSET\n"_s : ""_s); #ifndef MAGNUM_TARGET_GLES2 if(configuration.jointCount()) { vert.addSource(Utility::format( @@ -208,21 +208,21 @@ template typename FlatGL::CompileState FlatG "#define UNIFORM_BUFFERS\n" "#define DRAW_COUNT {}\n", 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 - vert.addSource(rs.getString("generic.glsl")) - .addSource(rs.getString("Flat.vert")); - frag.addSource(configuration.flags() & Flag::Textured ? "#define TEXTURED\n" : "") + vert.addSource(rs.getString("generic.glsl"_s)) + .addSource(rs.getString("Flat.vert"_s)); + frag.addSource(configuration.flags() & Flag::Textured ? "#define TEXTURED\n"_s : ""_s) #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 - .addSource(configuration.flags() & Flag::AlphaMask ? "#define ALPHA_MASK\n" : "") - .addSource(configuration.flags() & Flag::VertexColor ? "#define VERTEX_COLOR\n" : "") + .addSource(configuration.flags() & Flag::AlphaMask ? "#define ALPHA_MASK\n"_s : ""_s) + .addSource(configuration.flags() & Flag::VertexColor ? "#define VERTEX_COLOR\n"_s : ""_s) #ifndef MAGNUM_TARGET_GLES2 - .addSource(configuration.flags() & Flag::ObjectId ? "#define OBJECT_ID\n" : "") - .addSource(configuration.flags() >= Flag::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n" : "") - .addSource(configuration.flags() >= Flag::ObjectIdTexture ? "#define OBJECT_ID_TEXTURE\n" : "") + .addSource(configuration.flags() & Flag::ObjectId ? "#define OBJECT_ID\n"_s : ""_s) + .addSource(configuration.flags() >= Flag::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n"_s : ""_s) + .addSource(configuration.flags() >= Flag::ObjectIdTexture ? "#define OBJECT_ID_TEXTURE\n"_s : ""_s) #endif ; #ifndef MAGNUM_TARGET_GLES2 @@ -233,11 +233,11 @@ template typename FlatGL::CompileState FlatG "#define MATERIAL_COUNT {}\n", configuration.drawCount(), 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 - frag.addSource(rs.getString("generic.glsl")) - .addSource(rs.getString("Flat.frag")); + frag.addSource(rs.getString("generic.glsl"_s)) + .addSource(rs.getString("Flat.frag"_s)); vert.submitCompile(); frag.submitCompile(); @@ -251,38 +251,38 @@ template typename FlatGL::CompileState FlatG if(!context.isExtensionSupported(version)) #endif { - out.bindAttributeLocation(Position::Location, "position"); + out.bindAttributeLocation(Position::Location, "position"_s); if(configuration.flags() & Flag::Textured #ifndef MAGNUM_TARGET_GLES2 || configuration.flags() >= Flag::ObjectIdTexture #endif ) - out.bindAttributeLocation(TextureCoordinates::Location, "textureCoordinates"); + out.bindAttributeLocation(TextureCoordinates::Location, "textureCoordinates"_s); 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 if(configuration.flags() & Flag::ObjectId) { - out.bindFragmentDataLocation(ColorOutput, "color"); - out.bindFragmentDataLocation(ObjectIdOutput, "objectId"); + out.bindFragmentDataLocation(ColorOutput, "color"_s); + out.bindFragmentDataLocation(ObjectIdOutput, "objectId"_s); } if(configuration.flags() >= Flag::InstancedObjectId) - out.bindAttributeLocation(ObjectId::Location, "instanceObjectId"); + out.bindAttributeLocation(ObjectId::Location, "instanceObjectId"_s); #endif if(configuration.flags() & Flag::InstancedTransformation) - out.bindAttributeLocation(TransformationMatrix::Location, "instancedTransformationMatrix"); + out.bindAttributeLocation(TransformationMatrix::Location, "instancedTransformationMatrix"_s); if(configuration.flags() >= Flag::InstancedTextureOffset) - out.bindAttributeLocation(TextureOffset::Location, "instancedTextureOffset"); + out.bindAttributeLocation(TextureOffset::Location, "instancedTextureOffset"_s); #ifndef MAGNUM_TARGET_GLES2 /* Configuration::setJointCount() checks that jointCount and perVertexJointCount / secondaryPerVertexJointCount are either all zero or non-zero so we don't need to check for jointCount() here */ if(configuration.perVertexJointCount()) { - out.bindAttributeLocation(Weights::Location, "weights"); - out.bindAttributeLocation(JointIds::Location, "jointIds"); + out.bindAttributeLocation(Weights::Location, "weights"_s); + out.bindAttributeLocation(JointIds::Location, "jointIds"_s); } if(configuration.secondaryPerVertexJointCount()) { - out.bindAttributeLocation(SecondaryWeights::Location, "secondaryWeights"); - out.bindAttributeLocation(SecondaryJointIds::Location, "secondaryJointIds"); + out.bindAttributeLocation(SecondaryWeights::Location, "secondaryWeights"_s); + out.bindAttributeLocation(SecondaryJointIds::Location, "secondaryJointIds"_s); } #endif } @@ -333,28 +333,28 @@ template FlatGL::FlatGL(CompileState&& state { #ifndef MAGNUM_TARGET_GLES2 if(_flags >= Flag::DynamicPerVertexJointCount) - _perVertexJointCountUniform = uniformLocation("perVertexJointCount"); + _perVertexJointCountUniform = uniformLocation("perVertexJointCount"_s); if(_flags >= Flag::UniformBuffers) { - if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"); + if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"_s); } else #endif { - _transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"); + _transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"_s); if(_flags & Flag::TextureTransformation) - _textureMatrixUniform = uniformLocation("textureMatrix"); + _textureMatrixUniform = uniformLocation("textureMatrix"_s); #ifndef MAGNUM_TARGET_GLES2 if(_flags & Flag::TextureArrays) - _textureLayerUniform = uniformLocation("textureLayer"); + _textureLayerUniform = uniformLocation("textureLayer"_s); #endif - _colorUniform = uniformLocation("color"); - if(_flags & Flag::AlphaMask) _alphaMaskUniform = uniformLocation("alphaMask"); + _colorUniform = uniformLocation("color"_s); + if(_flags & Flag::AlphaMask) _alphaMaskUniform = uniformLocation("alphaMask"_s); #ifndef MAGNUM_TARGET_GLES2 - if(_flags & Flag::ObjectId) _objectIdUniform = uniformLocation("objectId"); + if(_flags & Flag::ObjectId) _objectIdUniform = uniformLocation("objectId"_s); #endif #ifndef MAGNUM_TARGET_GLES2 if(_jointCount) { - _jointMatricesUniform = uniformLocation("jointMatrices"); - _perInstanceJointCountUniform = uniformLocation("perInstanceJointCount"); + _jointMatricesUniform = uniformLocation("jointMatrices"_s); + _perInstanceJointCountUniform = uniformLocation("perInstanceJointCount"_s); } #endif } @@ -364,17 +364,17 @@ template FlatGL::FlatGL(CompileState&& state if(!context.isExtensionSupported(state._version)) #endif { - if(_flags & Flag::Textured) setUniform(uniformLocation("textureData"), TextureUnit); + if(_flags & Flag::Textured) setUniform(uniformLocation("textureData"_s), TextureUnit); #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) { - setUniformBlockBinding(uniformBlockIndex("TransformationProjection"), TransformationProjectionBufferBinding); - setUniformBlockBinding(uniformBlockIndex("Draw"), DrawBufferBinding); + setUniformBlockBinding(uniformBlockIndex("TransformationProjection"_s), TransformationProjectionBufferBinding); + setUniformBlockBinding(uniformBlockIndex("Draw"_s), DrawBufferBinding); if(_flags & Flag::TextureTransformation) - setUniformBlockBinding(uniformBlockIndex("TextureTransformation"), TextureTransformationBufferBinding); - setUniformBlockBinding(uniformBlockIndex("Material"), MaterialBufferBinding); + setUniformBlockBinding(uniformBlockIndex("TextureTransformation"_s), TextureTransformationBufferBinding); + setUniformBlockBinding(uniformBlockIndex("Material"_s), MaterialBufferBinding); if(_jointCount) - setUniformBlockBinding(uniformBlockIndex("Joint"), JointBufferBinding); + setUniformBlockBinding(uniformBlockIndex("Joint"_s), JointBufferBinding); } #endif } diff --git a/src/Magnum/Shaders/Implementation/CreateCompatibilityShader.h b/src/Magnum/Shaders/Implementation/CreateCompatibilityShader.h index 00344f0d71..2112ad103c 100644 --- a/src/Magnum/Shaders/Implementation/CreateCompatibilityShader.h +++ b/src/Magnum/Shaders/Implementation/CreateCompatibilityShader.h @@ -43,30 +43,32 @@ static void importShaderResources() { namespace Magnum { namespace Shaders { namespace Implementation { inline GL::Shader createCompatibilityShader(const Utility::Resource& rs, GL::Version version, GL::Shader::Type type) { + using namespace Containers::Literals; + GL::Shader shader(version, type); #ifndef MAGNUM_TARGET_GLES if(GL::Context::current().isExtensionDisabled(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(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(version)) - shader.addSource("#define DISABLE_GL_ARB_explicit_uniform_location\n"); + shader.addSource("#define DISABLE_GL_ARB_explicit_uniform_location\n"_s); #endif #ifndef MAGNUM_TARGET_GLES2 if(type == GL::Shader::Type::Vertex && GL::Context::current().isExtensionDisabled(version)) - shader.addSource("#define DISABLE_GL_MAGNUM_shader_vertex_id\n"); + shader.addSource("#define DISABLE_GL_MAGNUM_shader_vertex_id\n"_s); #endif /* My Android emulator (running on NVidia) doesn't define GL_ES preprocessor macro, thus *all* the stock shaders fail to compile */ /** @todo remove this when Android emulator is sane */ #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 - shader.addSource(rs.getString("compatibility.glsl")); + shader.addSource(rs.getString("compatibility.glsl"_s)); return shader; } diff --git a/src/Magnum/Shaders/MeshVisualizerGL.cpp b/src/Magnum/Shaders/MeshVisualizerGL.cpp index 81103e3b82..736231cd4e 100644 --- a/src/Magnum/Shaders/MeshVisualizerGL.cpp +++ b/src/Magnum/Shaders/MeshVisualizerGL.cpp @@ -144,7 +144,7 @@ void MeshVisualizerGLBase::assertExtensions(const FlagsBase flags) { #ifdef MAGNUM_BUILD_STATIC /* Import resources on static build, if not already */ - if(!Utility::Resource::hasGroup("MagnumShadersGL")) + if(!Utility::Resource::hasGroup("MagnumShadersGL"_s)) importShaderResources(); #endif } @@ -176,24 +176,24 @@ GL::Version MeshVisualizerGLBase::setupShaders(GL::Shader& vert, GL::Shader& fra vert = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Vertex); frag = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Fragment); - vert.addSource(flags & FlagBase::Wireframe ? "#define WIREFRAME_RENDERING\n" : "") + vert.addSource(flags & FlagBase::Wireframe ? "#define WIREFRAME_RENDERING\n"_s : ""_s) #ifndef MAGNUM_TARGET_GLES2 - .addSource(flags >= FlagBase::ObjectIdTexture ? "#define TEXTURED\n" : "") - .addSource(flags & FlagBase::TextureTransformation ? "#define TEXTURE_TRANSFORMATION\n" : "") - .addSource(flags & FlagBase::TextureArrays ? "#define TEXTURE_ARRAYS\n" : "") - .addSource(flags >= FlagBase::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n" : "") + .addSource(flags >= FlagBase::ObjectIdTexture ? "#define TEXTURED\n"_s : ""_s) + .addSource(flags & FlagBase::TextureTransformation ? "#define TEXTURE_TRANSFORMATION\n"_s : ""_s) + .addSource(flags & FlagBase::TextureArrays ? "#define TEXTURE_ARRAYS\n"_s : ""_s) + .addSource(flags >= FlagBase::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n"_s : ""_s) #endif - .addSource(flags & FlagBase::InstancedTransformation ? "#define INSTANCED_TRANSFORMATION\n" : "") + .addSource(flags & FlagBase::InstancedTransformation ? "#define INSTANCED_TRANSFORMATION\n"_s : ""_s) #ifndef MAGNUM_TARGET_GLES2 - .addSource(flags >= FlagBase::InstancedTextureOffset ? "#define INSTANCED_TEXTURE_OFFSET\n" : "") - .addSource(flags & FlagBase::VertexId ? "#define VERTEX_ID\n" : "") - .addSource(flags >= FlagBase::PrimitiveIdFromVertexId ? "#define PRIMITIVE_ID_FROM_VERTEX_ID\n" : "") + .addSource(flags >= FlagBase::InstancedTextureOffset ? "#define INSTANCED_TEXTURE_OFFSET\n"_s : ""_s) + .addSource(flags & FlagBase::VertexId ? "#define VERTEX_ID\n"_s : ""_s) + .addSource(flags >= FlagBase::PrimitiveIdFromVertexId ? "#define PRIMITIVE_ID_FROM_VERTEX_ID\n"_s : ""_s) #endif #ifdef MAGNUM_TARGET_WEBGL - .addSource("#define SUBSCRIPTING_WORKAROUND\n") + .addSource("#define SUBSCRIPTING_WORKAROUND\n"_s) #elif defined(MAGNUM_TARGET_GLES2) .addSource(context.detectedDriver() & GL::Context::DetectedDriver::Angle ? - "#define SUBSCRIPTING_WORKAROUND\n" : "") + "#define SUBSCRIPTING_WORKAROUND\n"_s : ""_s) #endif ; #ifndef MAGNUM_TARGET_GLES2 @@ -229,20 +229,20 @@ GL::Version MeshVisualizerGLBase::setupShaders(GL::Shader& vert, GL::Shader& fra "#define MATERIAL_COUNT {}\n", drawCount, materialCount)); - vert.addSource(flags >= FlagBase::MultiDraw ? "#define MULTI_DRAW\n" : ""); + vert.addSource(flags >= FlagBase::MultiDraw ? "#define MULTI_DRAW\n"_s : ""_s); } #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 - .addSource(flags & FlagBase::ObjectId ? "#define OBJECT_ID\n" : "") - .addSource(flags >= FlagBase::ObjectIdTexture ? "#define OBJECT_ID_TEXTURE\n" : "") - .addSource(flags & FlagBase::TextureArrays ? "#define TEXTURE_ARRAYS\n" : "") - .addSource(flags >= FlagBase::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n" : "") - .addSource(flags & FlagBase::VertexId ? "#define VERTEX_ID\n" : "") + .addSource(flags & FlagBase::ObjectId ? "#define OBJECT_ID\n"_s : ""_s) + .addSource(flags >= FlagBase::ObjectIdTexture ? "#define OBJECT_ID_TEXTURE\n"_s : ""_s) + .addSource(flags & FlagBase::TextureArrays ? "#define TEXTURE_ARRAYS\n"_s : ""_s) + .addSource(flags >= FlagBase::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n"_s : ""_s) + .addSource(flags & FlagBase::VertexId ? "#define VERTEX_ID\n"_s : ""_s) .addSource(flags & FlagBase::PrimitiveId ? (flags >= FlagBase::PrimitiveIdFromVertexId ? - "#define PRIMITIVE_ID_FROM_VERTEX_ID\n" : - "#define PRIMITIVE_ID\n") : "") + "#define PRIMITIVE_ID_FROM_VERTEX_ID\n"_s : + "#define PRIMITIVE_ID\n"_s) : ""_s) #endif ; #ifndef MAGNUM_TARGET_GLES2 @@ -253,7 +253,7 @@ GL::Version MeshVisualizerGLBase::setupShaders(GL::Shader& vert, GL::Shader& fra "#define MATERIAL_COUNT {}\n", drawCount, materialCount)); - frag.addSource(flags >= FlagBase::MultiDraw ? "#define MULTI_DRAW\n" : ""); + frag.addSource(flags >= FlagBase::MultiDraw ? "#define MULTI_DRAW\n"_s : ""_s); } #endif @@ -503,42 +503,42 @@ MeshVisualizerGL2D::CompileState MeshVisualizerGL2D::compile(const Configuration ); Containers::Optional 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 nothing actually needs it, as that makes checks much simpler in the shader code */ .addSource((configuration.flags() & Flag::NoGeometryShader) || !(configuration.flags() & Flag::Wireframe) ? - "#define NO_GEOMETRY_SHADER\n" : "") - .addSource(rs.getString("generic.glsl")) - .addSource(rs.getString("MeshVisualizer.vert")); + "#define NO_GEOMETRY_SHADER\n"_s : ""_s) + .addSource(rs.getString("generic.glsl"_s)) + .addSource(rs.getString("MeshVisualizer.vert"_s)); frag /* Pass NO_GEOMETRY_SHADER not only when NoGeometryShader but also when nothing actually needs it, as that makes checks much simpler in the shader code */ .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 if(configuration.flags() >= Flag::UniformBuffers) - frag.addSource("#define TWO_DIMENSIONS\n"); + frag.addSource("#define TWO_DIMENSIONS\n"_s); #endif - frag.addSource(rs.getString("generic.glsl")) - .addSource(rs.getString("MeshVisualizer.frag")); + frag.addSource(rs.getString("generic.glsl"_s)) + .addSource(rs.getString("MeshVisualizer.frag"_s)); #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) if(configuration.flags() & Flag::Wireframe && !(configuration.flags() & Flag::NoGeometryShader)) { geom = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Geometry); (*geom) - .addSource("#define WIREFRAME_RENDERING\n#define MAX_VERTICES 3\n") - .addSource(baseFlags >= FlagBase::ObjectIdTexture ? "#define TEXTURED\n" : "") - .addSource(baseFlags & FlagBase::TextureArrays ? "#define TEXTURE_ARRAYS\n" : "") - .addSource(baseFlags & FlagBase::ObjectId ? "#define OBJECT_ID\n" : "") - .addSource(baseFlags >= FlagBase::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n" : "") - .addSource(baseFlags & FlagBase::VertexId ? "#define VERTEX_ID\n" : "") + .addSource("#define WIREFRAME_RENDERING\n#define MAX_VERTICES 3\n"_s) + .addSource(baseFlags >= FlagBase::ObjectIdTexture ? "#define TEXTURED\n"_s : ""_s) + .addSource(baseFlags & FlagBase::TextureArrays ? "#define TEXTURE_ARRAYS\n"_s : ""_s) + .addSource(baseFlags & FlagBase::ObjectId ? "#define OBJECT_ID\n"_s : ""_s) + .addSource(baseFlags >= FlagBase::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n"_s : ""_s) + .addSource(baseFlags & FlagBase::VertexId ? "#define VERTEX_ID\n"_s : ""_s) .addSource(baseFlags & FlagBase::PrimitiveId ? (baseFlags >= FlagBase::PrimitiveIdFromVertexId ? - "#define PRIMITIVE_ID_FROM_VERTEX_ID\n" : - "#define PRIMITIVE_ID\n") : ""); + "#define PRIMITIVE_ID_FROM_VERTEX_ID\n"_s : + "#define PRIMITIVE_ID\n"_s) : ""_s); #ifndef MAGNUM_TARGET_GLES2 if(configuration.flags() >= Flag::UniformBuffers) { geom->addSource(Utility::format( @@ -548,10 +548,10 @@ MeshVisualizerGL2D::CompileState MeshVisualizerGL2D::compile(const Configuration "#define MATERIAL_COUNT {}\n", configuration.drawCount(), 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 - geom->addSource(rs.getString("MeshVisualizer.geom")); + geom->addSource(rs.getString("MeshVisualizer.geom"_s)); } #else static_cast(version); @@ -571,25 +571,25 @@ MeshVisualizerGL2D::CompileState MeshVisualizerGL2D::compile(const Configuration if(!context.isExtensionSupported(version)) #endif { - out.bindAttributeLocation(Position::Location, "position"); + out.bindAttributeLocation(Position::Location, "position"_s); #ifndef MAGNUM_TARGET_GLES2 if(configuration.flags() >= Flag::ObjectIdTexture) - out.bindAttributeLocation(TextureCoordinates::Location, "textureCoordinates"); + out.bindAttributeLocation(TextureCoordinates::Location, "textureCoordinates"_s); if(configuration.flags() >= Flag::InstancedObjectId) - out.bindAttributeLocation(ObjectId::Location, "instanceObjectId"); + out.bindAttributeLocation(ObjectId::Location, "instanceObjectId"_s); #endif if(configuration.flags() & Flag::InstancedTransformation) - out.bindAttributeLocation(TransformationMatrix::Location, "instancedTransformationMatrix"); + out.bindAttributeLocation(TransformationMatrix::Location, "instancedTransformationMatrix"_s); #ifndef MAGNUM_TARGET_GLES2 if(configuration.flags() >= Flag::InstancedTextureOffset) - out.bindAttributeLocation(TextureOffset::Location, "instancedTextureOffset"); + out.bindAttributeLocation(TextureOffset::Location, "instancedTextureOffset"_s); #endif #if !defined(MAGNUM_TARGET_GLES) || defined(MAGNUM_TARGET_GLES2) #ifndef MAGNUM_TARGET_GLES if(!context.isVersionSupported(GL::Version::GL310)) #endif { - out.bindAttributeLocation(VertexIndex::Location, "vertexIndex"); + out.bindAttributeLocation(VertexIndex::Location, "vertexIndex"_s); } #endif #ifndef MAGNUM_TARGET_GLES2 @@ -597,12 +597,12 @@ MeshVisualizerGL2D::CompileState MeshVisualizerGL2D::compile(const Configuration perVertexJointCount / secondaryPerVertexJointCount are either all zero or non-zero so we don't need to check for jointCount() here */ if(configuration.perVertexJointCount()) { - out.bindAttributeLocation(Weights::Location, "weights"); - out.bindAttributeLocation(JointIds::Location, "jointIds"); + out.bindAttributeLocation(Weights::Location, "weights"_s); + out.bindAttributeLocation(JointIds::Location, "jointIds"_s); } if(configuration.secondaryPerVertexJointCount()) { - out.bindAttributeLocation(SecondaryWeights::Location, "secondaryWeights"); - out.bindAttributeLocation(SecondaryJointIds::Location, "secondaryJointIds"); + out.bindAttributeLocation(SecondaryWeights::Location, "secondaryWeights"_s); + out.bindAttributeLocation(SecondaryJointIds::Location, "secondaryJointIds"_s); } #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 setting */ if((flags() & Flag::Wireframe) && !(flags() & Flag::NoGeometryShader)) - _viewportSizeUniform = uniformLocation("viewportSize"); + _viewportSizeUniform = uniformLocation("viewportSize"_s); #ifndef MAGNUM_TARGET_GLES2 if(flags() >= Flag::DynamicPerVertexJointCount) - _perVertexJointCountUniform = uniformLocation("perVertexJointCount"); + _perVertexJointCountUniform = uniformLocation("perVertexJointCount"_s); if(flags() >= Flag::UniformBuffers) { - if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"); + if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"_s); } else #endif { - _transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"); + _transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"_s); #ifndef MAGNUM_TARGET_GLES2 if(flags() & Flag::TextureTransformation) - _textureMatrixUniform = uniformLocation("textureMatrix"); + _textureMatrixUniform = uniformLocation("textureMatrix"_s); if(flags() & Flag::TextureArrays) - _textureLayerUniform = uniformLocation("textureLayer"); + _textureLayerUniform = uniformLocation("textureLayer"_s); #endif if(flags() & (Flag::Wireframe #ifndef MAGNUM_TARGET_GLES2 |Flag::ObjectId|Flag::VertexId|Flag::PrimitiveIdFromVertexId #endif )) - _colorUniform = uniformLocation("color"); + _colorUniform = uniformLocation("color"_s); if(flags() & Flag::Wireframe) { - _wireframeColorUniform = uniformLocation("wireframeColor"); - _wireframeWidthUniform = uniformLocation("wireframeWidth"); - _smoothnessUniform = uniformLocation("smoothness"); + _wireframeColorUniform = uniformLocation("wireframeColor"_s); + _wireframeWidthUniform = uniformLocation("wireframeWidth"_s); + _smoothnessUniform = uniformLocation("smoothness"_s); } #ifndef MAGNUM_TARGET_GLES2 if(flags() & (Flag::ObjectId|Flag::VertexId|Flag::PrimitiveIdFromVertexId)) { - _colorMapOffsetScaleUniform = uniformLocation("colorMapOffsetScale"); + _colorMapOffsetScaleUniform = uniformLocation("colorMapOffsetScale"_s); } if(flags() & Flag::ObjectId) - _objectIdUniform = uniformLocation("objectId"); + _objectIdUniform = uniformLocation("objectId"_s); #endif #ifndef MAGNUM_TARGET_GLES2 if(_jointCount) { - _jointMatricesUniform = uniformLocation("jointMatrices"); - _perInstanceJointCountUniform = uniformLocation("perInstanceJointCount"); + _jointMatricesUniform = uniformLocation("jointMatrices"_s); + _perInstanceJointCountUniform = uniformLocation("perInstanceJointCount"_s); } #endif } @@ -710,19 +710,19 @@ MeshVisualizerGL2D::MeshVisualizerGL2D(CompileState&& state): MeshVisualizerGL2D #endif { if(flags() & (Flag::ObjectId|Flag::VertexId|Flag::PrimitiveIdFromVertexId)) { - setUniform(uniformLocation("colorMapTexture"), ColorMapTextureUnit); + setUniform(uniformLocation("colorMapTexture"_s), ColorMapTextureUnit); } #ifndef MAGNUM_TARGET_GLES2 if(flags() >= Flag::ObjectIdTexture) - setUniform(uniformLocation("objectIdTextureData"), ObjectIdTextureUnit); + setUniform(uniformLocation("objectIdTextureData"_s), ObjectIdTextureUnit); if(flags() >= Flag::UniformBuffers) { - setUniformBlockBinding(uniformBlockIndex("TransformationProjection"), TransformationProjectionBufferBinding); - setUniformBlockBinding(uniformBlockIndex("Draw"), DrawBufferBinding); - setUniformBlockBinding(uniformBlockIndex("Material"), MaterialBufferBinding); + setUniformBlockBinding(uniformBlockIndex("TransformationProjection"_s), TransformationProjectionBufferBinding); + setUniformBlockBinding(uniformBlockIndex("Draw"_s), DrawBufferBinding); + setUniformBlockBinding(uniformBlockIndex("Material"_s), MaterialBufferBinding); if(flags() & Flag::TextureTransformation) - setUniformBlockBinding(uniformBlockIndex("TextureTransformation"), TextureTransformationBufferBinding); + setUniformBlockBinding(uniformBlockIndex("TextureTransformation"_s), TextureTransformationBufferBinding); if(_jointCount) - setUniformBlockBinding(uniformBlockIndex("Joint"), JointBufferBinding); + setUniformBlockBinding(uniformBlockIndex("Joint"_s), JointBufferBinding); } #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); #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 nothing actually needs it, as that makes checks much simpler in the vertex shader code */ @@ -963,16 +963,16 @@ MeshVisualizerGL3D::CompileState MeshVisualizerGL3D::compile(const Configuration #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) |Flag::TangentDirection|Flag::BitangentDirection|Flag::BitangentFromTangentDirection|Flag::NormalDirection #endif - )) ? "#define NO_GEOMETRY_SHADER\n" : "") + )) ? "#define NO_GEOMETRY_SHADER\n"_s : ""_s) #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) - .addSource(configuration.flags() & Flag::TangentDirection ? "#define TANGENT_DIRECTION\n" : "") - .addSource(configuration.flags() & Flag::BitangentFromTangentDirection ? "#define BITANGENT_FROM_TANGENT_DIRECTION\n" : "") - .addSource(configuration.flags() & Flag::BitangentDirection ? "#define BITANGENT_DIRECTION\n" : "") - .addSource(configuration.flags() & Flag::NormalDirection ? "#define NORMAL_DIRECTION\n" : "") + .addSource(configuration.flags() & Flag::TangentDirection ? "#define TANGENT_DIRECTION\n"_s : ""_s) + .addSource(configuration.flags() & Flag::BitangentFromTangentDirection ? "#define BITANGENT_FROM_TANGENT_DIRECTION\n"_s : ""_s) + .addSource(configuration.flags() & Flag::BitangentDirection ? "#define BITANGENT_DIRECTION\n"_s : ""_s) + .addSource(configuration.flags() & Flag::NormalDirection ? "#define NORMAL_DIRECTION\n"_s : ""_s) #endif ; - vert.addSource(rs.getString("generic.glsl")) - .addSource(rs.getString("MeshVisualizer.vert")); + vert.addSource(rs.getString("generic.glsl"_s)) + .addSource(rs.getString("MeshVisualizer.vert"_s)); frag /* Pass NO_GEOMETRY_SHADER not only when NoGeometryShader but also when 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) |Flag::TangentDirection|Flag::BitangentDirection|Flag::BitangentFromTangentDirection|Flag::NormalDirection #endif - )) ? "#define NO_GEOMETRY_SHADER\n" : "") + )) ? "#define NO_GEOMETRY_SHADER\n"_s : ""_s) #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 ; #ifndef MAGNUM_TARGET_GLES2 if(configuration.flags() >= Flag::UniformBuffers) - frag.addSource("#define THREE_DIMENSIONS\n"); + frag.addSource("#define THREE_DIMENSIONS\n"_s); #endif - frag.addSource(rs.getString("generic.glsl")) - .addSource(rs.getString("MeshVisualizer.frag")); + frag.addSource(rs.getString("generic.glsl"_s)) + .addSource(rs.getString("MeshVisualizer.frag"_s)); #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)) { @@ -1005,19 +1005,19 @@ MeshVisualizerGL3D::CompileState MeshVisualizerGL3D::compile(const Configuration geom = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Geometry); (*geom) .addSource(Utility::format("#define MAX_VERTICES {}\n", maxVertices)) - .addSource(configuration.flags() & Flag::Wireframe ? "#define WIREFRAME_RENDERING\n" : "") - .addSource(baseFlags >= FlagBase::ObjectIdTexture ? "#define TEXTURED\n" : "") - .addSource(baseFlags & FlagBase::TextureArrays ? "#define TEXTURE_ARRAYS\n" : "") - .addSource(baseFlags & FlagBase::ObjectId ? "#define OBJECT_ID\n" : "") - .addSource(baseFlags >= FlagBase::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n" : "") - .addSource(baseFlags & FlagBase::VertexId ? "#define VERTEX_ID\n" : "") + .addSource(configuration.flags() & Flag::Wireframe ? "#define WIREFRAME_RENDERING\n"_s : ""_s) + .addSource(baseFlags >= FlagBase::ObjectIdTexture ? "#define TEXTURED\n"_s : ""_s) + .addSource(baseFlags & FlagBase::TextureArrays ? "#define TEXTURE_ARRAYS\n"_s : ""_s) + .addSource(baseFlags & FlagBase::ObjectId ? "#define OBJECT_ID\n"_s : ""_s) + .addSource(baseFlags >= FlagBase::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n"_s : ""_s) + .addSource(baseFlags & FlagBase::VertexId ? "#define VERTEX_ID\n"_s : ""_s) .addSource(baseFlags & FlagBase::PrimitiveId ? (baseFlags >= FlagBase::PrimitiveIdFromVertexId ? - "#define PRIMITIVE_ID_FROM_VERTEX_ID\n" : - "#define PRIMITIVE_ID\n") : "") - .addSource(configuration.flags() & Flag::TangentDirection ? "#define TANGENT_DIRECTION\n" : "") - .addSource(configuration.flags() & (Flag::BitangentDirection|Flag::BitangentFromTangentDirection) ? "#define BITANGENT_DIRECTION\n" : "") - .addSource(configuration.flags() & Flag::NormalDirection ? "#define NORMAL_DIRECTION\n" : ""); + "#define PRIMITIVE_ID_FROM_VERTEX_ID\n"_s : + "#define PRIMITIVE_ID\n"_s) : ""_s) + .addSource(configuration.flags() & Flag::TangentDirection ? "#define TANGENT_DIRECTION\n"_s : ""_s) + .addSource(configuration.flags() & (Flag::BitangentDirection|Flag::BitangentFromTangentDirection) ? "#define BITANGENT_DIRECTION\n"_s : ""_s) + .addSource(configuration.flags() & Flag::NormalDirection ? "#define NORMAL_DIRECTION\n"_s : ""_s); #ifndef MAGNUM_TARGET_GLES2 if(configuration.flags() >= Flag::UniformBuffers) { geom->addSource(Utility::format( @@ -1027,10 +1027,10 @@ MeshVisualizerGL3D::CompileState MeshVisualizerGL3D::compile(const Configuration "#define MATERIAL_COUNT {}\n", configuration.drawCount(), 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 - geom->addSource(rs.getString("MeshVisualizer.geom")); + geom->addSource(rs.getString("MeshVisualizer.geom"_s)); } #else static_cast(version); @@ -1050,40 +1050,40 @@ MeshVisualizerGL3D::CompileState MeshVisualizerGL3D::compile(const Configuration if(!context.isExtensionSupported(version)) #endif { - out.bindAttributeLocation(Position::Location, "position"); + out.bindAttributeLocation(Position::Location, "position"_s); #ifndef MAGNUM_TARGET_GLES2 if(configuration.flags() >= Flag::ObjectIdTexture) - out.bindAttributeLocation(TextureCoordinates::Location, "textureCoordinates"); + out.bindAttributeLocation(TextureCoordinates::Location, "textureCoordinates"_s); if(configuration.flags() >= Flag::InstancedObjectId) - out.bindAttributeLocation(ObjectId::Location, "instanceObjectId"); + out.bindAttributeLocation(ObjectId::Location, "instanceObjectId"_s); #endif 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(configuration.flags() & (Flag::TangentDirection|Flag::BitangentFromTangentDirection|Flag::BitangentDirection|Flag::NormalDirection)) - out.bindAttributeLocation(NormalMatrix::Location, "instancedNormalMatrix"); + out.bindAttributeLocation(NormalMatrix::Location, "instancedNormalMatrix"_s); #endif } #ifndef MAGNUM_TARGET_GLES2 if(configuration.flags() >= Flag::InstancedTextureOffset) - out.bindAttributeLocation(TextureOffset::Location, "instancedTextureOffset"); + out.bindAttributeLocation(TextureOffset::Location, "instancedTextureOffset"_s); #endif #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) if(configuration.flags() & Flag::TangentDirection || configuration.flags() & Flag::BitangentFromTangentDirection) - out.bindAttributeLocation(Tangent4::Location, "tangent"); + out.bindAttributeLocation(Tangent4::Location, "tangent"_s); if(configuration.flags() & Flag::BitangentDirection) - out.bindAttributeLocation(Bitangent::Location, "bitangent"); + out.bindAttributeLocation(Bitangent::Location, "bitangent"_s); if(configuration.flags() & Flag::NormalDirection || configuration.flags() & Flag::BitangentFromTangentDirection) - out.bindAttributeLocation(Normal::Location, "normal"); + out.bindAttributeLocation(Normal::Location, "normal"_s); #endif #if !defined(MAGNUM_TARGET_GLES) || defined(MAGNUM_TARGET_GLES2) #ifndef MAGNUM_TARGET_GLES if(!context.isVersionSupported(GL::Version::GL310)) #endif { - out.bindAttributeLocation(VertexIndex::Location, "vertexIndex"); + out.bindAttributeLocation(VertexIndex::Location, "vertexIndex"_s); } #endif #ifndef MAGNUM_TARGET_GLES2 @@ -1091,12 +1091,12 @@ MeshVisualizerGL3D::CompileState MeshVisualizerGL3D::compile(const Configuration perVertexJointCount / secondaryPerVertexJointCount are either all zero or non-zero so we don't need to check for jointCount() here */ if(configuration.perVertexJointCount()) { - out.bindAttributeLocation(Weights::Location, "weights"); - out.bindAttributeLocation(JointIds::Location, "jointIds"); + out.bindAttributeLocation(Weights::Location, "weights"_s); + out.bindAttributeLocation(JointIds::Location, "jointIds"_s); } if(configuration.secondaryPerVertexJointCount()) { - out.bindAttributeLocation(SecondaryWeights::Location, "secondaryWeights"); - out.bindAttributeLocation(SecondaryJointIds::Location, "secondaryJointIds"); + out.bindAttributeLocation(SecondaryWeights::Location, "secondaryWeights"_s); + out.bindAttributeLocation(SecondaryJointIds::Location, "secondaryJointIds"_s); } #endif } @@ -1158,59 +1158,59 @@ MeshVisualizerGL3D::MeshVisualizerGL3D(CompileState&& state): MeshVisualizerGL3D || (flags() & (Flag::TangentDirection|Flag::BitangentFromTangentDirection|Flag::BitangentDirection|Flag::NormalDirection)) #endif ) - _viewportSizeUniform = uniformLocation("viewportSize"); + _viewportSizeUniform = uniformLocation("viewportSize"_s); #ifndef MAGNUM_TARGET_GLES2 if(flags() >= Flag::DynamicPerVertexJointCount) - _perVertexJointCountUniform = uniformLocation("perVertexJointCount"); + _perVertexJointCountUniform = uniformLocation("perVertexJointCount"_s); if(flags() >= Flag::UniformBuffers) { - if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"); + if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"_s); } else #endif { - _transformationMatrixUniform = uniformLocation("transformationMatrix"); - _projectionMatrixUniform = uniformLocation("projectionMatrix"); + _transformationMatrixUniform = uniformLocation("transformationMatrix"_s); + _projectionMatrixUniform = uniformLocation("projectionMatrix"_s); #ifndef MAGNUM_TARGET_GLES2 if(flags() & Flag::TextureTransformation) - _textureMatrixUniform = uniformLocation("textureMatrix"); + _textureMatrixUniform = uniformLocation("textureMatrix"_s); if(flags() & Flag::TextureArrays) - _textureLayerUniform = uniformLocation("textureLayer"); + _textureLayerUniform = uniformLocation("textureLayer"_s); #endif if(flags() & (Flag::Wireframe #ifndef MAGNUM_TARGET_GLES2 |Flag::ObjectId|Flag::VertexId|Flag::PrimitiveIdFromVertexId #endif )) - _colorUniform = uniformLocation("color"); + _colorUniform = uniformLocation("color"_s); if(flags() & Flag::Wireframe) { - _wireframeColorUniform = uniformLocation("wireframeColor"); - _wireframeWidthUniform = uniformLocation("wireframeWidth"); + _wireframeColorUniform = uniformLocation("wireframeColor"_s); + _wireframeWidthUniform = uniformLocation("wireframeWidth"_s); } if(flags() & (Flag::Wireframe #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) |Flag::TangentDirection|Flag::BitangentFromTangentDirection|Flag::BitangentDirection|Flag::NormalDirection #endif )) { - _smoothnessUniform = uniformLocation("smoothness"); + _smoothnessUniform = uniformLocation("smoothness"_s); } #ifndef MAGNUM_TARGET_GLES2 if(flags() & (Flag::ObjectId|Flag::VertexId|Flag::PrimitiveIdFromVertexId)) { - _colorMapOffsetScaleUniform = uniformLocation("colorMapOffsetScale"); + _colorMapOffsetScaleUniform = uniformLocation("colorMapOffsetScale"_s); } if(flags() & Flag::ObjectId) - _objectIdUniform = uniformLocation("objectId"); + _objectIdUniform = uniformLocation("objectId"_s); #endif #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) if(flags() & (Flag::TangentDirection|Flag::BitangentFromTangentDirection|Flag::BitangentDirection|Flag::NormalDirection)) { - _normalMatrixUniform = uniformLocation("normalMatrix"); - _lineWidthUniform = uniformLocation("lineWidth"); - _lineLengthUniform = uniformLocation("lineLength"); + _normalMatrixUniform = uniformLocation("normalMatrix"_s); + _lineWidthUniform = uniformLocation("lineWidth"_s); + _lineLengthUniform = uniformLocation("lineLength"_s); } #endif #ifndef MAGNUM_TARGET_GLES2 if(_jointCount) { - _jointMatricesUniform = uniformLocation("jointMatrices"); - _perInstanceJointCountUniform = uniformLocation("perInstanceJointCount"); + _jointMatricesUniform = uniformLocation("jointMatrices"_s); + _perInstanceJointCountUniform = uniformLocation("perInstanceJointCount"_s); } #endif } @@ -1222,20 +1222,20 @@ MeshVisualizerGL3D::MeshVisualizerGL3D(CompileState&& state): MeshVisualizerGL3D #endif { if(flags() & (Flag::ObjectId|Flag::VertexId|Flag::PrimitiveIdFromVertexId)) { - setUniform(uniformLocation("colorMapTexture"), ColorMapTextureUnit); + setUniform(uniformLocation("colorMapTexture"_s), ColorMapTextureUnit); } #ifndef MAGNUM_TARGET_GLES2 if(flags() >= Flag::ObjectIdTexture) - setUniform(uniformLocation("objectIdTextureData"), ObjectIdTextureUnit); + setUniform(uniformLocation("objectIdTextureData"_s), ObjectIdTextureUnit); if(flags() >= Flag::UniformBuffers) { - setUniformBlockBinding(uniformBlockIndex("Projection"), ProjectionBufferBinding); - setUniformBlockBinding(uniformBlockIndex("Transformation"), TransformationBufferBinding); - setUniformBlockBinding(uniformBlockIndex("Draw"), DrawBufferBinding); - setUniformBlockBinding(uniformBlockIndex("Material"), MaterialBufferBinding); + setUniformBlockBinding(uniformBlockIndex("Projection"_s), ProjectionBufferBinding); + setUniformBlockBinding(uniformBlockIndex("Transformation"_s), TransformationBufferBinding); + setUniformBlockBinding(uniformBlockIndex("Draw"_s), DrawBufferBinding); + setUniformBlockBinding(uniformBlockIndex("Material"_s), MaterialBufferBinding); if(flags() & Flag::TextureTransformation) - setUniformBlockBinding(uniformBlockIndex("TextureTransformation"), TextureTransformationBufferBinding); + setUniformBlockBinding(uniformBlockIndex("TextureTransformation"_s), TextureTransformationBufferBinding); if(_jointCount) - setUniformBlockBinding(uniformBlockIndex("Joint"), JointBufferBinding); + setUniformBlockBinding(uniformBlockIndex("Joint"_s), JointBufferBinding); } #endif } diff --git a/src/Magnum/Shaders/PhongGL.cpp b/src/Magnum/Shaders/PhongGL.cpp index 36d35c9561..d6e49247bc 100644 --- a/src/Magnum/Shaders/PhongGL.cpp +++ b/src/Magnum/Shaders/PhongGL.cpp @@ -147,10 +147,10 @@ PhongGL::CompileState PhongGL::compile(const Configuration& configuration) { #ifdef MAGNUM_BUILD_STATIC /* Import resources on static build, if not already */ - if(!Utility::Resource::hasGroup("MagnumShadersGL")) + if(!Utility::Resource::hasGroup("MagnumShadersGL"_s)) importShaderResources(); #endif - Utility::Resource rs("MagnumShadersGL"); + Utility::Resource rs("MagnumShadersGL"_s); const GL::Context& context = GL::Context::current(); @@ -207,20 +207,20 @@ PhongGL::CompileState PhongGL::compile(const Configuration& configuration) { #ifndef MAGNUM_TARGET_GLES2 || configuration.flags() >= Flag::ObjectIdTexture #endif - ) ? "#define TEXTURED\n" : "") - .addSource(configuration.flags() & Flag::NormalTexture ? "#define NORMAL_TEXTURE\n" : "") - .addSource(configuration.flags() & Flag::Bitangent ? "#define BITANGENT\n" : "") - .addSource(configuration.flags() & Flag::VertexColor ? "#define VERTEX_COLOR\n" : "") - .addSource(configuration.flags() & Flag::TextureTransformation ? "#define TEXTURE_TRANSFORMATION\n" : "") + ) ? "#define TEXTURED\n"_s : ""_s) + .addSource(configuration.flags() & Flag::NormalTexture ? "#define NORMAL_TEXTURE\n"_s : ""_s) + .addSource(configuration.flags() & Flag::Bitangent ? "#define BITANGENT\n"_s : ""_s) + .addSource(configuration.flags() & Flag::VertexColor ? "#define VERTEX_COLOR\n"_s : ""_s) + .addSource(configuration.flags() & Flag::TextureTransformation ? "#define TEXTURE_TRANSFORMATION\n"_s : ""_s) #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 - .addSource(configuration.lightCount() ? "#define HAS_LIGHTS\n" : "") + .addSource(configuration.lightCount() ? "#define HAS_LIGHTS\n"_s : ""_s) #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 - .addSource(configuration.flags() & Flag::InstancedTransformation ? "#define INSTANCED_TRANSFORMATION\n" : "") - .addSource(configuration.flags() >= Flag::InstancedTextureOffset ? "#define INSTANCED_TEXTURE_OFFSET\n" : ""); + .addSource(configuration.flags() & Flag::InstancedTransformation ? "#define INSTANCED_TRANSFORMATION\n"_s : ""_s) + .addSource(configuration.flags() >= Flag::InstancedTextureOffset ? "#define INSTANCED_TEXTURE_OFFSET\n"_s : ""_s); #ifndef MAGNUM_TARGET_GLES2 if(configuration.jointCount()) { vert.addSource(Utility::format( @@ -255,27 +255,27 @@ PhongGL::CompileState PhongGL::compile(const Configuration& configuration) { "#define DRAW_COUNT {}\n", configuration.drawCount(), 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 - vert.addSource(rs.getString("generic.glsl")) - .addSource(rs.getString("Phong.vert")); - frag.addSource(configuration.flags() & Flag::AmbientTexture ? "#define AMBIENT_TEXTURE\n" : "") - .addSource(configuration.flags() & Flag::DiffuseTexture ? "#define DIFFUSE_TEXTURE\n" : "") - .addSource(configuration.flags() & Flag::SpecularTexture ? "#define SPECULAR_TEXTURE\n" : "") - .addSource(configuration.flags() & Flag::NormalTexture ? "#define NORMAL_TEXTURE\n" : "") + vert.addSource(rs.getString("generic.glsl"_s)) + .addSource(rs.getString("Phong.vert"_s)); + frag.addSource(configuration.flags() & Flag::AmbientTexture ? "#define AMBIENT_TEXTURE\n"_s : ""_s) + .addSource(configuration.flags() & Flag::DiffuseTexture ? "#define DIFFUSE_TEXTURE\n"_s : ""_s) + .addSource(configuration.flags() & Flag::SpecularTexture ? "#define SPECULAR_TEXTURE\n"_s : ""_s) + .addSource(configuration.flags() & Flag::NormalTexture ? "#define NORMAL_TEXTURE\n"_s : ""_s) #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 - .addSource(configuration.flags() & Flag::Bitangent ? "#define BITANGENT\n" : "") - .addSource(configuration.flags() & Flag::VertexColor ? "#define VERTEX_COLOR\n" : "") - .addSource(configuration.flags() & Flag::AlphaMask ? "#define ALPHA_MASK\n" : "") + .addSource(configuration.flags() & Flag::Bitangent ? "#define BITANGENT\n"_s : ""_s) + .addSource(configuration.flags() & Flag::VertexColor ? "#define VERTEX_COLOR\n"_s : ""_s) + .addSource(configuration.flags() & Flag::AlphaMask ? "#define ALPHA_MASK\n"_s : ""_s) #ifndef MAGNUM_TARGET_GLES2 - .addSource(configuration.flags() & Flag::ObjectId ? "#define OBJECT_ID\n" : "") - .addSource(configuration.flags() >= Flag::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n" : "") - .addSource(configuration.flags() >= Flag::ObjectIdTexture ? "#define OBJECT_ID_TEXTURE\n" : "") + .addSource(configuration.flags() & Flag::ObjectId ? "#define OBJECT_ID\n"_s : ""_s) + .addSource(configuration.flags() >= Flag::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n"_s : ""_s) + .addSource(configuration.flags() >= Flag::ObjectIdTexture ? "#define OBJECT_ID_TEXTURE\n"_s : ""_s) #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 if(configuration.flags() >= Flag::UniformBuffers) { @@ -287,8 +287,8 @@ PhongGL::CompileState PhongGL::compile(const Configuration& configuration) { configuration.drawCount(), configuration.materialCount(), configuration.lightCount())); - frag.addSource(configuration.flags() >= Flag::MultiDraw ? "#define MULTI_DRAW\n" : "") - .addSource(configuration.flags() >= Flag::LightCulling ? "#define LIGHT_CULLING\n" : ""); + frag.addSource(configuration.flags() >= Flag::MultiDraw ? "#define MULTI_DRAW\n"_s : ""_s) + .addSource(configuration.flags() >= Flag::LightCulling ? "#define LIGHT_CULLING\n"_s : ""_s); } else #endif { @@ -306,8 +306,8 @@ PhongGL::CompileState PhongGL::compile(const Configuration& configuration) { if(!(configuration.flags() >= Flag::UniformBuffers) && configuration.lightCount()) frag.addSource(std::move(lightInitializer)); #endif - frag.addSource(rs.getString("generic.glsl")) - .addSource(rs.getString("Phong.frag")); + frag.addSource(rs.getString("generic.glsl"_s)) + .addSource(rs.getString("Phong.frag"_s)); vert.submitCompile(); frag.submitCompile(); @@ -321,48 +321,48 @@ PhongGL::CompileState PhongGL::compile(const Configuration& configuration) { if(!context.isExtensionSupported(version)) #endif { - out.bindAttributeLocation(Position::Location, "position"); + out.bindAttributeLocation(Position::Location, "position"_s); if(configuration.lightCount()) - out.bindAttributeLocation(Normal::Location, "normal"); + out.bindAttributeLocation(Normal::Location, "normal"_s); if((configuration.flags() & Flag::NormalTexture) && configuration.lightCount()) { - out.bindAttributeLocation(Tangent::Location, "tangent"); + out.bindAttributeLocation(Tangent::Location, "tangent"_s); if(configuration.flags() & Flag::Bitangent) - out.bindAttributeLocation(Bitangent::Location, "bitangent"); + out.bindAttributeLocation(Bitangent::Location, "bitangent"_s); } 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) #ifndef MAGNUM_TARGET_GLES2 || configuration.flags() >= Flag::ObjectIdTexture #endif ) - out.bindAttributeLocation(TextureCoordinates::Location, "textureCoordinates"); + out.bindAttributeLocation(TextureCoordinates::Location, "textureCoordinates"_s); #ifndef MAGNUM_TARGET_GLES2 if(configuration.flags() & Flag::ObjectId) { - out.bindFragmentDataLocation(ColorOutput, "color"); - out.bindFragmentDataLocation(ObjectIdOutput, "objectId"); + out.bindFragmentDataLocation(ColorOutput, "color"_s); + out.bindFragmentDataLocation(ObjectIdOutput, "objectId"_s); } if(configuration.flags() >= Flag::InstancedObjectId) - out.bindAttributeLocation(ObjectId::Location, "instanceObjectId"); + out.bindAttributeLocation(ObjectId::Location, "instanceObjectId"_s); #endif if(configuration.flags() & Flag::InstancedTransformation) { - out.bindAttributeLocation(TransformationMatrix::Location, "instancedTransformationMatrix"); + out.bindAttributeLocation(TransformationMatrix::Location, "instancedTransformationMatrix"_s); if(configuration.lightCount()) - out.bindAttributeLocation(NormalMatrix::Location, "instancedNormalMatrix"); + out.bindAttributeLocation(NormalMatrix::Location, "instancedNormalMatrix"_s); } if(configuration.flags() >= Flag::InstancedTextureOffset) - out.bindAttributeLocation(TextureOffset::Location, "instancedTextureOffset"); + out.bindAttributeLocation(TextureOffset::Location, "instancedTextureOffset"_s); #ifndef MAGNUM_TARGET_GLES2 /* Configuration::setJointCount() checks that jointCount and perVertexJointCount / secondaryPerVertexJointCount are either all zero or non-zero so we don't need to check for jointCount() here */ if(configuration.perVertexJointCount()) { - out.bindAttributeLocation(Weights::Location, "weights"); - out.bindAttributeLocation(JointIds::Location, "jointIds"); + out.bindAttributeLocation(Weights::Location, "weights"_s); + out.bindAttributeLocation(JointIds::Location, "jointIds"_s); } if(configuration.secondaryPerVertexJointCount()) { - out.bindAttributeLocation(SecondaryWeights::Location, "secondaryWeights"); - out.bindAttributeLocation(SecondaryJointIds::Location, "secondaryJointIds"); + out.bindAttributeLocation(SecondaryWeights::Location, "secondaryWeights"_s); + out.bindAttributeLocation(SecondaryJointIds::Location, "secondaryJointIds"_s); } #endif } @@ -415,44 +415,44 @@ PhongGL::PhongGL(CompileState&& state): PhongGL{static_cast(std::move { #ifndef MAGNUM_TARGET_GLES2 if(_flags >= Flag::DynamicPerVertexJointCount) - _perVertexJointCountUniform = uniformLocation("perVertexJointCount"); + _perVertexJointCountUniform = uniformLocation("perVertexJointCount"_s); if(_flags >= Flag::UniformBuffers) { - if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"); + if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"_s); } else #endif { - _transformationMatrixUniform = uniformLocation("transformationMatrix"); + _transformationMatrixUniform = uniformLocation("transformationMatrix"_s); if(_flags & Flag::TextureTransformation) - _textureMatrixUniform = uniformLocation("textureMatrix"); + _textureMatrixUniform = uniformLocation("textureMatrix"_s); #ifndef MAGNUM_TARGET_GLES2 if(_flags & Flag::TextureArrays) - _textureLayerUniform = uniformLocation("textureLayer"); + _textureLayerUniform = uniformLocation("textureLayer"_s); #endif - _projectionMatrixUniform = uniformLocation("projectionMatrix"); - _ambientColorUniform = uniformLocation("ambientColor"); + _projectionMatrixUniform = uniformLocation("projectionMatrix"_s); + _ambientColorUniform = uniformLocation("ambientColor"_s); if(_lightCount) { - _normalMatrixUniform = uniformLocation("normalMatrix"); - _diffuseColorUniform = uniformLocation("diffuseColor"); + _normalMatrixUniform = uniformLocation("normalMatrix"_s); + _diffuseColorUniform = uniformLocation("diffuseColor"_s); if(!(_flags & Flag::NoSpecular)) { - _specularColorUniform = uniformLocation("specularColor"); - _shininessUniform = uniformLocation("shininess"); + _specularColorUniform = uniformLocation("specularColor"_s); + _shininessUniform = uniformLocation("shininess"_s); } if(_flags & Flag::NormalTexture) - _normalTextureScaleUniform = uniformLocation("normalTextureScale"); - _lightPositionsUniform = uniformLocation("lightPositions"); - _lightColorsUniform = uniformLocation("lightColors"); + _normalTextureScaleUniform = uniformLocation("normalTextureScale"_s); + _lightPositionsUniform = uniformLocation("lightPositions"_s); + _lightColorsUniform = uniformLocation("lightColors"_s); if(!(_flags & Flag::NoSpecular)) - _lightSpecularColorsUniform = uniformLocation("lightSpecularColors"); - _lightRangesUniform = uniformLocation("lightRanges"); + _lightSpecularColorsUniform = uniformLocation("lightSpecularColors"_s); + _lightRangesUniform = uniformLocation("lightRanges"_s); } - if(_flags & Flag::AlphaMask) _alphaMaskUniform = uniformLocation("alphaMask"); + if(_flags & Flag::AlphaMask) _alphaMaskUniform = uniformLocation("alphaMask"_s); #ifndef MAGNUM_TARGET_GLES2 - if(_flags & Flag::ObjectId) _objectIdUniform = uniformLocation("objectId"); + if(_flags & Flag::ObjectId) _objectIdUniform = uniformLocation("objectId"_s); #endif #ifndef MAGNUM_TARGET_GLES2 if(_jointCount) { - _jointMatricesUniform = uniformLocation("jointMatrices"); - _perInstanceJointCountUniform = uniformLocation("perInstanceJointCount"); + _jointMatricesUniform = uniformLocation("jointMatrices"_s); + _perInstanceJointCountUniform = uniformLocation("perInstanceJointCount"_s); } #endif } @@ -462,25 +462,25 @@ PhongGL::PhongGL(CompileState&& state): PhongGL{static_cast(std::move if(_flags && !context.isExtensionSupported(state._version)) #endif { - if(_flags & Flag::AmbientTexture) setUniform(uniformLocation("ambientTexture"), AmbientTextureUnit); + if(_flags & Flag::AmbientTexture) setUniform(uniformLocation("ambientTexture"_s), AmbientTextureUnit); if(_lightCount) { - if(_flags & Flag::DiffuseTexture) setUniform(uniformLocation("diffuseTexture"), DiffuseTextureUnit); - if(_flags & Flag::SpecularTexture) setUniform(uniformLocation("specularTexture"), SpecularTextureUnit); - if(_flags & Flag::NormalTexture) setUniform(uniformLocation("normalTexture"), NormalTextureUnit); + if(_flags & Flag::DiffuseTexture) setUniform(uniformLocation("diffuseTexture"_s), DiffuseTextureUnit); + if(_flags & Flag::SpecularTexture) setUniform(uniformLocation("specularTexture"_s), SpecularTextureUnit); + if(_flags & Flag::NormalTexture) setUniform(uniformLocation("normalTexture"_s), NormalTextureUnit); } #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) { - setUniformBlockBinding(uniformBlockIndex("Projection"), ProjectionBufferBinding); - setUniformBlockBinding(uniformBlockIndex("Transformation"), TransformationBufferBinding); - setUniformBlockBinding(uniformBlockIndex("Draw"), DrawBufferBinding); - setUniformBlockBinding(uniformBlockIndex("Material"), MaterialBufferBinding); + setUniformBlockBinding(uniformBlockIndex("Projection"_s), ProjectionBufferBinding); + setUniformBlockBinding(uniformBlockIndex("Transformation"_s), TransformationBufferBinding); + setUniformBlockBinding(uniformBlockIndex("Draw"_s), DrawBufferBinding); + setUniformBlockBinding(uniformBlockIndex("Material"_s), MaterialBufferBinding); if(_flags & Flag::TextureTransformation) - setUniformBlockBinding(uniformBlockIndex("TextureTransformation"), TextureTransformationBufferBinding); + setUniformBlockBinding(uniformBlockIndex("TextureTransformation"_s), TextureTransformationBufferBinding); if(_lightCount) - setUniformBlockBinding(uniformBlockIndex("Light"), LightBufferBinding); + setUniformBlockBinding(uniformBlockIndex("Light"_s), LightBufferBinding); if(_jointCount) - setUniformBlockBinding(uniformBlockIndex("Joint"), JointBufferBinding); + setUniformBlockBinding(uniformBlockIndex("Joint"_s), JointBufferBinding); } #endif } diff --git a/src/Magnum/Shaders/VectorGL.cpp b/src/Magnum/Shaders/VectorGL.cpp index b04b64f159..dbbb4edf41 100644 --- a/src/Magnum/Shaders/VectorGL.cpp +++ b/src/Magnum/Shaders/VectorGL.cpp @@ -49,6 +49,8 @@ namespace Magnum { namespace Shaders { +using namespace Containers::Literals; + namespace { enum: Int { TextureUnit = 6 }; @@ -91,10 +93,10 @@ template typename VectorGL::CompileState Vec #ifdef MAGNUM_BUILD_STATIC /* Import resources on static build, if not already */ - if(!Utility::Resource::hasGroup("MagnumShadersGL")) + if(!Utility::Resource::hasGroup("MagnumShadersGL"_s)) importShaderResources(); #endif - Utility::Resource rs("MagnumShadersGL"); + Utility::Resource rs("MagnumShadersGL"_s); const GL::Context& context = GL::Context::current(); @@ -107,19 +109,19 @@ template typename VectorGL::CompileState Vec GL::Shader vert = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Vertex); GL::Shader frag = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Fragment); - vert.addSource(configuration.flags() & Flag::TextureTransformation ? "#define TEXTURE_TRANSFORMATION\n" : "") - .addSource(dimensions == 2 ? "#define TWO_DIMENSIONS\n" : "#define THREE_DIMENSIONS\n"); + vert.addSource(configuration.flags() & Flag::TextureTransformation ? "#define TEXTURE_TRANSFORMATION\n"_s : ""_s) + .addSource(dimensions == 2 ? "#define TWO_DIMENSIONS\n"_s : "#define THREE_DIMENSIONS\n"_s); #ifndef MAGNUM_TARGET_GLES2 if(configuration.flags() >= Flag::UniformBuffers) { vert.addSource(Utility::format( "#define UNIFORM_BUFFERS\n" "#define DRAW_COUNT {}\n", 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 - vert.addSource(rs.getString("generic.glsl")) - .addSource(rs.getString("Vector.vert")); + vert.addSource(rs.getString("generic.glsl"_s)) + .addSource(rs.getString("Vector.vert"_s)); #ifndef MAGNUM_TARGET_GLES2 if(configuration.flags() >= Flag::UniformBuffers) { frag.addSource(Utility::format( @@ -128,11 +130,11 @@ template typename VectorGL::CompileState Vec "#define MATERIAL_COUNT {}\n", configuration.drawCount(), 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 - frag.addSource(rs.getString("generic.glsl")) - .addSource(rs.getString("Vector.frag")); + frag.addSource(rs.getString("generic.glsl"_s)) + .addSource(rs.getString("Vector.frag"_s)); vert.submitCompile(); frag.submitCompile(); @@ -152,8 +154,8 @@ template typename VectorGL::CompileState Vec if(!context.isExtensionSupported(version)) #endif { - out.bindAttributeLocation(Position::Location, "position"); - out.bindAttributeLocation(TextureCoordinates::Location, "textureCoordinates"); + out.bindAttributeLocation(Position::Location, "position"_s); + out.bindAttributeLocation(TextureCoordinates::Location, "textureCoordinates"_s); } #endif @@ -202,15 +204,15 @@ template VectorGL::VectorGL(CompileState&& s { #ifndef MAGNUM_TARGET_GLES2 if(_flags >= Flag::UniformBuffers) { - if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"); + if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"_s); } else #endif { - _transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"); + _transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"_s); if(_flags & Flag::TextureTransformation) - _textureMatrixUniform = uniformLocation("textureMatrix"); - _backgroundColorUniform = uniformLocation("backgroundColor"); - _colorUniform = uniformLocation("color"); + _textureMatrixUniform = uniformLocation("textureMatrix"_s); + _backgroundColorUniform = uniformLocation("backgroundColor"_s); + _colorUniform = uniformLocation("color"_s); } } @@ -218,14 +220,14 @@ template VectorGL::VectorGL(CompileState&& s if(!context.isExtensionSupported(state._version)) #endif { - setUniform(uniformLocation("vectorTexture"), TextureUnit); + setUniform(uniformLocation("vectorTexture"_s), TextureUnit); #ifndef MAGNUM_TARGET_GLES2 if(_flags >= Flag::UniformBuffers) { - setUniformBlockBinding(uniformBlockIndex("TransformationProjection"), TransformationProjectionBufferBinding); - setUniformBlockBinding(uniformBlockIndex("Draw"), DrawBufferBinding); + setUniformBlockBinding(uniformBlockIndex("TransformationProjection"_s), TransformationProjectionBufferBinding); + setUniformBlockBinding(uniformBlockIndex("Draw"_s), DrawBufferBinding); if(_flags & Flag::TextureTransformation) - setUniformBlockBinding(uniformBlockIndex("TextureTransformation"), TextureTransformationBufferBinding); - setUniformBlockBinding(uniformBlockIndex("Material"), MaterialBufferBinding); + setUniformBlockBinding(uniformBlockIndex("TextureTransformation"_s), TextureTransformationBufferBinding); + setUniformBlockBinding(uniformBlockIndex("Material"_s), MaterialBufferBinding); } #endif } diff --git a/src/Magnum/Shaders/VertexColorGL.cpp b/src/Magnum/Shaders/VertexColorGL.cpp index d1018559c8..9f7658f5d9 100644 --- a/src/Magnum/Shaders/VertexColorGL.cpp +++ b/src/Magnum/Shaders/VertexColorGL.cpp @@ -47,6 +47,8 @@ namespace Magnum { namespace Shaders { +using namespace Containers::Literals; + namespace { #ifndef MAGNUM_TARGET_GLES2 enum: Int { @@ -82,10 +84,10 @@ template typename VertexColorGL::CompileStat #ifdef MAGNUM_BUILD_STATIC /* Import resources on static build, if not already */ - if(!Utility::Resource::hasGroup("MagnumShadersGL")) + if(!Utility::Resource::hasGroup("MagnumShadersGL"_s)) importShaderResources(); #endif - Utility::Resource rs("MagnumShadersGL"); + Utility::Resource rs("MagnumShadersGL"_s); const GL::Context& context = GL::Context::current(); @@ -98,20 +100,20 @@ template typename VertexColorGL::CompileStat GL::Shader vert = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Vertex); GL::Shader frag = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Fragment); - vert.addSource(dimensions == 2 ? "#define TWO_DIMENSIONS\n" : "#define THREE_DIMENSIONS\n"); + vert.addSource(dimensions == 2 ? "#define TWO_DIMENSIONS\n"_s : "#define THREE_DIMENSIONS\n"_s); #ifndef MAGNUM_TARGET_GLES2 if(configuration.flags() >= Flag::UniformBuffers) { vert.addSource(Utility::format( "#define UNIFORM_BUFFERS\n" "#define DRAW_COUNT {}\n", 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 - vert.addSource(rs.getString("generic.glsl")) - .addSource(rs.getString("VertexColor.vert")); - frag.addSource(rs.getString("generic.glsl")) - .addSource(rs.getString("VertexColor.frag")); + vert.addSource(rs.getString("generic.glsl"_s)) + .addSource(rs.getString("VertexColor.vert"_s)); + frag.addSource(rs.getString("generic.glsl"_s)) + .addSource(rs.getString("VertexColor.frag"_s)); vert.submitCompile(); frag.submitCompile(); @@ -130,8 +132,8 @@ template typename VertexColorGL::CompileStat if(!context.isExtensionSupported(version)) #endif { - out.bindAttributeLocation(Position::Location, "position"); - out.bindAttributeLocation(Color3::Location, "color"); /* Color4 is the same */ + out.bindAttributeLocation(Position::Location, "position"_s); + out.bindAttributeLocation(Color3::Location, "color"_s); /* Color4 is the same */ } #endif @@ -179,11 +181,11 @@ template VertexColorGL::VertexColorGL(Compil { #ifndef MAGNUM_TARGET_GLES2 if(_flags >= Flag::UniformBuffers) { - if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"); + if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"_s); } else #endif { - _transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"); + _transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"_s); } } @@ -193,7 +195,7 @@ template VertexColorGL::VertexColorGL(Compil && !context.isExtensionSupported(state._version) #endif ) { - setUniformBlockBinding(uniformBlockIndex("TransformationProjection"), TransformationProjectionBufferBinding); + setUniformBlockBinding(uniformBlockIndex("TransformationProjection"_s), TransformationProjectionBufferBinding); } #endif diff --git a/src/Magnum/TextureTools/DistanceField.cpp b/src/Magnum/TextureTools/DistanceField.cpp index 6fd8cd1b31..f1eca6c3ce 100644 --- a/src/Magnum/TextureTools/DistanceField.cpp +++ b/src/Magnum/TextureTools/DistanceField.cpp @@ -49,6 +49,8 @@ static void importTextureToolResources() { namespace Magnum { namespace TextureTools { +using namespace Containers::Literals; + namespace { class DistanceFieldShader: public GL::AbstractShaderProgram { @@ -86,10 +88,10 @@ class DistanceFieldShader: public GL::AbstractShaderProgram { DistanceFieldShader::DistanceFieldShader(const UnsignedInt radius) { #ifdef MAGNUM_BUILD_STATIC /* Import resources on static build, if not already */ - if(!Utility::Resource::hasGroup("MagnumTextureTools")) + if(!Utility::Resource::hasGroup("MagnumTextureTools"_s)) importTextureToolResources(); #endif - Utility::Resource rs("MagnumTextureTools"); + Utility::Resource rs("MagnumTextureTools"_s); #ifndef MAGNUM_TARGET_GLES 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 frag = Shaders::Implementation::createCompatibilityShader(rs, v, GL::Shader::Type::Fragment); - vert.addSource(rs.getString("FullScreenTriangle.glsl")) - .addSource(rs.getString("DistanceFieldShader.vert")); + vert.addSource(rs.getString("FullScreenTriangle.glsl"_s)) + .addSource(rs.getString("DistanceFieldShader.vert"_s)); 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()); @@ -113,7 +115,7 @@ DistanceFieldShader::DistanceFieldShader(const UnsignedInt radius) { if(!GL::Context::current().isExtensionSupported()) #endif { - bindAttributeLocation(Position::Location, "position"); + bindAttributeLocation(Position::Location, "position"_s); } CORRADE_INTERNAL_ASSERT_OUTPUT(link()); @@ -122,7 +124,7 @@ DistanceFieldShader::DistanceFieldShader(const UnsignedInt radius) { if(!GL::Context::current().isExtensionSupported()) #endif { - scalingUniform = uniformLocation("scaling"); + scalingUniform = uniformLocation("scaling"_s); #ifndef MAGNUM_TARGET_GLES 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)) #endif { - imageSizeInvertedUniform = uniformLocation("imageSizeInverted"); + imageSizeInvertedUniform = uniformLocation("imageSizeInverted"_s); } } @@ -138,7 +140,7 @@ DistanceFieldShader::DistanceFieldShader(const UnsignedInt radius) { if(!GL::Context::current().isExtensionSupported()) #endif { - setUniform(uniformLocation("textureData"), TextureUnit); + setUniform(uniformLocation("textureData"_s), TextureUnit); } }