Skip to content

Commit

Permalink
DebugTools,Shaders,TextureTools: use string view literals everywhere.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mosra committed Dec 31, 2022
1 parent 6e619fc commit 44b27f5
Show file tree
Hide file tree
Showing 9 changed files with 361 additions and 349 deletions.
16 changes: 9 additions & 7 deletions src/Magnum/DebugTools/TextureImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -75,29 +77,29 @@ 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"};

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<GL::Extensions::MAGNUM::shader_vertex_id>())
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<GL::Extensions::MAGNUM::shader_vertex_id>()) {
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);
}

}
Expand Down
50 changes: 26 additions & 24 deletions src/Magnum/Shaders/DistanceFieldVectorGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@

namespace Magnum { namespace Shaders {

using namespace Containers::Literals;

namespace {
enum: Int { TextureUnit = 6 };

Expand Down Expand Up @@ -91,10 +93,10 @@ template<UnsignedInt dimensions> typename DistanceFieldVectorGL<dimensions>::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();

Expand All @@ -107,19 +109,19 @@ template<UnsignedInt dimensions> typename DistanceFieldVectorGL<dimensions>::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(
Expand All @@ -128,11 +130,11 @@ template<UnsignedInt dimensions> typename DistanceFieldVectorGL<dimensions>::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();
Expand All @@ -152,8 +154,8 @@ template<UnsignedInt dimensions> typename DistanceFieldVectorGL<dimensions>::Com
if(!context.isExtensionSupported<GL::Extensions::ARB::explicit_attrib_location>(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

Expand Down Expand Up @@ -201,32 +203,32 @@ template<UnsignedInt dimensions> DistanceFieldVectorGL<dimensions>::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);
}
}

#ifndef MAGNUM_TARGET_GLES
if(!context.isExtensionSupported<GL::Extensions::ARB::shading_language_420pack>(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
}
Expand Down
Loading

0 comments on commit 44b27f5

Please sign in to comment.