diff --git a/src/Magnum/Shaders/DistanceFieldVector.frag b/src/Magnum/Shaders/DistanceFieldVector.frag index ab6733f4f..0421f17a1 100644 --- a/src/Magnum/Shaders/DistanceFieldVector.frag +++ b/src/Magnum/Shaders/DistanceFieldVector.frag @@ -72,6 +72,7 @@ uniform lowp float smoothness #else #ifndef MULTI_DRAW +#if DRAW_COUNT > 1 #ifdef EXPLICIT_UNIFORM_LOCATION layout(location = 0) #endif @@ -80,6 +81,9 @@ uniform highp uint drawOffset = 0u #endif ; +#else +#define drawOffset 0u +#endif #define drawId drawOffset #endif diff --git a/src/Magnum/Shaders/DistanceFieldVectorGL.cpp b/src/Magnum/Shaders/DistanceFieldVectorGL.cpp index 2a9e55175..381a6b2f6 100644 --- a/src/Magnum/Shaders/DistanceFieldVectorGL.cpp +++ b/src/Magnum/Shaders/DistanceFieldVectorGL.cpp @@ -165,7 +165,7 @@ template DistanceFieldVectorGL::DistanceFiel { #ifndef MAGNUM_TARGET_GLES2 if(flags >= Flag::UniformBuffers) { - _drawOffsetUniform = uniformLocation("drawOffset"); + if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"); } else #endif { @@ -280,7 +280,7 @@ template DistanceFieldVectorGL& DistanceFiel "Shaders::DistanceFieldVectorGL::setDrawOffset(): the shader was not created with uniform buffers enabled", *this); CORRADE_ASSERT(offset < _drawCount, "Shaders::DistanceFieldVectorGL::setDrawOffset(): draw offset" << offset << "is out of bounds for" << _drawCount << "draws", *this); - setUniform(_drawOffsetUniform, offset); + if(_drawCount > 1) setUniform(_drawOffsetUniform, offset); return *this; } diff --git a/src/Magnum/Shaders/DistanceFieldVectorGL.h b/src/Magnum/Shaders/DistanceFieldVectorGL.h index 84e383bff..69290b331 100644 --- a/src/Magnum/Shaders/DistanceFieldVectorGL.h +++ b/src/Magnum/Shaders/DistanceFieldVectorGL.h @@ -445,7 +445,9 @@ template class MAGNUM_SHADERS_EXPORT DistanceFieldVector * @ref bindTransformationProjectionBuffer(), @ref bindDrawBuffer() and * @ref bindTextureTransformationBuffer() should be used for current * draw. Expects that @ref Flag::UniformBuffers is set and @p offset is - * less than @ref drawCount(). Initial value is @cpp 0 @ce. + * less than @ref drawCount(). Initial value is @cpp 0 @ce, if + * @ref drawCount() is @cpp 1 @ce, the function is a no-op as the + * shader assumes draw offset to be always zero. * * If @ref Flag::MultiDraw is set, @glsl gl_DrawID @ce is added to this * value, which makes each draw submitted via diff --git a/src/Magnum/Shaders/Flat.frag b/src/Magnum/Shaders/Flat.frag index 6b783be40..8f5e5a6d7 100644 --- a/src/Magnum/Shaders/Flat.frag +++ b/src/Magnum/Shaders/Flat.frag @@ -72,6 +72,7 @@ uniform highp uint objectId; /* defaults to zero */ #else #ifndef MULTI_DRAW +#if DRAW_COUNT > 1 #ifdef EXPLICIT_UNIFORM_LOCATION layout(location = 0) #endif @@ -80,6 +81,9 @@ uniform highp uint drawOffset = 0u #endif ; +#else +#define drawOffset 0u +#endif #define drawId drawOffset #endif diff --git a/src/Magnum/Shaders/Flat.vert b/src/Magnum/Shaders/Flat.vert index 71865a578..dfae3fcf1 100644 --- a/src/Magnum/Shaders/Flat.vert +++ b/src/Magnum/Shaders/Flat.vert @@ -92,6 +92,7 @@ uniform highp uint textureLayer; /* defaults to zero */ /* Uniform buffers */ #else +#if DRAW_COUNT > 1 #ifdef EXPLICIT_UNIFORM_LOCATION layout(location = 0) #endif @@ -100,6 +101,9 @@ uniform highp uint drawOffset = 0u #endif ; +#else +#define drawOffset 0u +#endif layout(std140 #ifdef EXPLICIT_BINDING diff --git a/src/Magnum/Shaders/FlatGL.cpp b/src/Magnum/Shaders/FlatGL.cpp index c65fdd11d..cf281c50d 100644 --- a/src/Magnum/Shaders/FlatGL.cpp +++ b/src/Magnum/Shaders/FlatGL.cpp @@ -216,7 +216,7 @@ template FlatGL::FlatGL(const Flags flags { #ifndef MAGNUM_TARGET_GLES2 if(flags >= Flag::UniformBuffers) { - _drawOffsetUniform = uniformLocation("drawOffset"); + if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"); } else #endif { @@ -342,7 +342,7 @@ template FlatGL& FlatGL::setDraw "Shaders::FlatGL::setDrawOffset(): the shader was not created with uniform buffers enabled", *this); CORRADE_ASSERT(offset < _drawCount, "Shaders::FlatGL::setDrawOffset(): draw offset" << offset << "is out of bounds for" << _drawCount << "draws", *this); - setUniform(_drawOffsetUniform, offset); + if(_drawCount > 1) setUniform(_drawOffsetUniform, offset); return *this; } diff --git a/src/Magnum/Shaders/FlatGL.h b/src/Magnum/Shaders/FlatGL.h index caf4dd6b0..ffca52dac 100644 --- a/src/Magnum/Shaders/FlatGL.h +++ b/src/Magnum/Shaders/FlatGL.h @@ -755,7 +755,9 @@ template class MAGNUM_SHADERS_EXPORT FlatGL: public GL:: * @ref bindTransformationProjectionBuffer(), @ref bindDrawBuffer() and * @ref bindTextureTransformationBuffer() should be used for current * draw. Expects that @ref Flag::UniformBuffers is set and @p offset is - * less than @ref drawCount(). Initial value is @cpp 0 @ce. + * less than @ref drawCount(). Initial value is @cpp 0 @ce, if + * @ref drawCount() is @cpp 1 @ce, the function is a no-op as the + * shader assumes draw offset to be always zero. * * If @ref Flag::MultiDraw is set, @glsl gl_DrawID @ce is added to this * value, which makes each draw submitted via diff --git a/src/Magnum/Shaders/MeshVisualizer.frag b/src/Magnum/Shaders/MeshVisualizer.frag index 6987931ba..20bb89ec7 100644 --- a/src/Magnum/Shaders/MeshVisualizer.frag +++ b/src/Magnum/Shaders/MeshVisualizer.frag @@ -111,6 +111,7 @@ uniform lowp vec2 colorMapOffsetScale #else #ifndef MULTI_DRAW +#if DRAW_COUNT > 1 #ifdef EXPLICIT_UNIFORM_LOCATION layout(location = 1) #endif @@ -119,6 +120,9 @@ uniform highp uint drawOffset = 0u #endif ; +#else +#define drawOffset 0u +#endif #define drawId drawOffset #endif diff --git a/src/Magnum/Shaders/MeshVisualizer.vert b/src/Magnum/Shaders/MeshVisualizer.vert index 6aa9ebe7b..c0e514e75 100644 --- a/src/Magnum/Shaders/MeshVisualizer.vert +++ b/src/Magnum/Shaders/MeshVisualizer.vert @@ -113,6 +113,7 @@ uniform highp float lineLength /* Uniform buffers */ #else +#if DRAW_COUNT > 1 #ifdef EXPLICIT_UNIFORM_LOCATION layout(location = 1) #endif @@ -121,6 +122,9 @@ uniform highp uint drawOffset = 0u #endif ; +#else +#define drawOffset 0u +#endif #ifdef TWO_DIMENSIONS layout(std140 diff --git a/src/Magnum/Shaders/MeshVisualizerGL.cpp b/src/Magnum/Shaders/MeshVisualizerGL.cpp index 99cfa37f1..1fc40b8ec 100644 --- a/src/Magnum/Shaders/MeshVisualizerGL.cpp +++ b/src/Magnum/Shaders/MeshVisualizerGL.cpp @@ -263,7 +263,7 @@ MeshVisualizerGLBase& MeshVisualizerGLBase::setDrawOffset(const UnsignedInt offs "Shaders::MeshVisualizerGL::setDrawOffset(): the shader was not created with uniform buffers enabled", *this); CORRADE_ASSERT(offset < _drawCount, "Shaders::MeshVisualizerGL::setDrawOffset(): draw offset" << offset << "is out of bounds for" << _drawCount << "draws", *this); - setUniform(_drawOffsetUniform, offset); + if(_drawCount > 1) setUniform(_drawOffsetUniform, offset); return *this; } @@ -426,7 +426,7 @@ MeshVisualizerGL2D::MeshVisualizerGL2D(const Flags flags #ifndef MAGNUM_TARGET_GLES2 if(flags >= Flag::UniformBuffers) { - _drawOffsetUniform = uniformLocation("drawOffset"); + if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"); } else #endif { @@ -757,7 +757,7 @@ MeshVisualizerGL3D::MeshVisualizerGL3D(const Flags flags #ifndef MAGNUM_TARGET_GLES2 if(flags >= Flag::UniformBuffers) { - _drawOffsetUniform = uniformLocation("drawOffset"); + if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"); } else #endif { diff --git a/src/Magnum/Shaders/MeshVisualizerGL.h b/src/Magnum/Shaders/MeshVisualizerGL.h index 6d8967594..878418692 100644 --- a/src/Magnum/Shaders/MeshVisualizerGL.h +++ b/src/Magnum/Shaders/MeshVisualizerGL.h @@ -495,7 +495,9 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizerGL2D: public Implementation::MeshVisua * @ref bindTransformationProjectionBuffer() and @ref bindDrawBuffer() * should be used for current draw. Expects that * @ref Flag::UniformBuffers is set and @p offset is less than - * @ref drawCount(). Initial value is @cpp 0 @ce. + * @ref drawCount(). Initial value is @cpp 0 @ce, if @ref drawCount() + * is @cpp 1 @ce, the function is a no-op as the shader assumes draw + * offset to be always zero. * * If @ref Flag::MultiDraw is set, @glsl gl_DrawID @ce is added to this * value, which makes each draw submitted via @@ -1490,7 +1492,8 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizerGL3D: public Implementation::MeshVisua * @ref bindTransformationBuffer() and @ref bindDrawBuffer() should be * used for current draw. Expects that @ref Flag::UniformBuffers is set * and @p offset is less than @ref drawCount(). Initial value is - * @cpp 0 @ce. + * @cpp 0 @ce, if @ref drawCount() is @cpp 1 @ce, the function is a + * no-op as the shader assumes draw offset to be always zero. * * If @ref Flag::MultiDraw is set, @glsl gl_DrawID @ce is added to this * value, which makes each draw submitted via diff --git a/src/Magnum/Shaders/Phong.frag b/src/Magnum/Shaders/Phong.frag index 1a1827068..57ab5b2d5 100644 --- a/src/Magnum/Shaders/Phong.frag +++ b/src/Magnum/Shaders/Phong.frag @@ -149,6 +149,7 @@ uniform lowp float lightRanges[LIGHT_COUNT] #else #ifndef MULTI_DRAW +#if DRAW_COUNT > 1 #ifdef EXPLICIT_UNIFORM_LOCATION layout(location = 0) #endif @@ -157,6 +158,9 @@ uniform highp uint drawOffset = 0u #endif ; +#else +#define drawOffset 0u +#endif #define drawId drawOffset #endif diff --git a/src/Magnum/Shaders/Phong.vert b/src/Magnum/Shaders/Phong.vert index e31635031..521c55389 100644 --- a/src/Magnum/Shaders/Phong.vert +++ b/src/Magnum/Shaders/Phong.vert @@ -114,6 +114,7 @@ uniform highp vec4 lightPositions[LIGHT_COUNT] /* Uniform buffers */ #else +#if DRAW_COUNT > 1 #ifdef EXPLICIT_UNIFORM_LOCATION layout(location = 0) #endif @@ -122,6 +123,9 @@ uniform highp uint drawOffset = 0u #endif ; +#else +#define drawOffset 0u +#endif /* Keep in sync with Phong.frag. Can't "outsource" to a common file because the #extension directive needs to be always before any code. */ diff --git a/src/Magnum/Shaders/PhongGL.cpp b/src/Magnum/Shaders/PhongGL.cpp index 30a9eceb9..0190c050e 100644 --- a/src/Magnum/Shaders/PhongGL.cpp +++ b/src/Magnum/Shaders/PhongGL.cpp @@ -326,7 +326,7 @@ PhongGL::PhongGL(const Flags flags, const UnsignedInt lightCount { #ifndef MAGNUM_TARGET_GLES2 if(flags >= Flag::UniformBuffers) { - _drawOffsetUniform = uniformLocation("drawOffset"); + if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"); } else #endif { @@ -706,7 +706,7 @@ PhongGL& PhongGL::setDrawOffset(const UnsignedInt offset) { "Shaders::PhongGL::setDrawOffset(): the shader was not created with uniform buffers enabled", *this); CORRADE_ASSERT(offset < _drawCount, "Shaders::PhongGL::setDrawOffset(): draw offset" << offset << "is out of bounds for" << _drawCount << "draws", *this); - setUniform(_drawOffsetUniform, offset); + if(_drawCount > 1) setUniform(_drawOffsetUniform, offset); return *this; } diff --git a/src/Magnum/Shaders/PhongGL.h b/src/Magnum/Shaders/PhongGL.h index 89da15b7f..aef2d67d2 100644 --- a/src/Magnum/Shaders/PhongGL.h +++ b/src/Magnum/Shaders/PhongGL.h @@ -1296,7 +1296,9 @@ class MAGNUM_SHADERS_EXPORT PhongGL: public GL::AbstractShaderProgram { * bound with @ref bindTransformationBuffer(), @ref bindDrawBuffer() * and @ref bindTextureTransformationBuffer() should be used for * current draw. Expects that @ref Flag::UniformBuffers is set and - * @p offset is less than @ref drawCount(). Initial value is @cpp 0 @ce. + * @p offset is less than @ref drawCount(). Initial value is + * @cpp 0 @ce, if @ref drawCount() is @cpp 1 @ce, the function is a + * no-op as the shader assumes draw offset to be always zero. * * If @ref Flag::MultiDraw is set, @glsl gl_DrawID @ce is added to this * value, which makes each draw submitted via diff --git a/src/Magnum/Shaders/Vector.frag b/src/Magnum/Shaders/Vector.frag index a36e3a7a6..1b78de18f 100644 --- a/src/Magnum/Shaders/Vector.frag +++ b/src/Magnum/Shaders/Vector.frag @@ -54,6 +54,7 @@ uniform lowp vec4 color #else #ifndef MULTI_DRAW +#if DRAW_COUNT > 1 #ifdef EXPLICIT_UNIFORM_LOCATION layout(location = 0) #endif @@ -62,6 +63,9 @@ uniform highp uint drawOffset = 0u #endif ; +#else +#define drawOffset 0u +#endif #define drawId drawOffset #endif diff --git a/src/Magnum/Shaders/Vector.vert b/src/Magnum/Shaders/Vector.vert index 3f38ac103..f92fe714b 100644 --- a/src/Magnum/Shaders/Vector.vert +++ b/src/Magnum/Shaders/Vector.vert @@ -76,6 +76,7 @@ uniform mediump mat3 textureMatrix /* Uniform buffers */ #else +#if DRAW_COUNT > 1 #ifdef EXPLICIT_UNIFORM_LOCATION layout(location = 0) #endif @@ -84,6 +85,9 @@ uniform highp uint drawOffset = 0u #endif ; +#else +#define drawOffset 0u +#endif layout(std140 #ifdef EXPLICIT_BINDING diff --git a/src/Magnum/Shaders/VectorGL.cpp b/src/Magnum/Shaders/VectorGL.cpp index bd98a6fdc..baeb51075 100644 --- a/src/Magnum/Shaders/VectorGL.cpp +++ b/src/Magnum/Shaders/VectorGL.cpp @@ -164,7 +164,7 @@ template VectorGL::VectorGL(const Flags flag { #ifndef MAGNUM_TARGET_GLES2 if(flags >= Flag::UniformBuffers) { - _drawOffsetUniform = uniformLocation("drawOffset"); + if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"); } else #endif { @@ -257,7 +257,7 @@ template VectorGL& VectorGL::set "Shaders::VectorGL::setDrawOffset(): the shader was not created with uniform buffers enabled", *this); CORRADE_ASSERT(offset < _drawCount, "Shaders::VectorGL::setDrawOffset(): draw offset" << offset << "is out of bounds for" << _drawCount << "draws", *this); - setUniform(_drawOffsetUniform, offset); + if(_drawCount > 1) setUniform(_drawOffsetUniform, offset); return *this; } diff --git a/src/Magnum/Shaders/VectorGL.h b/src/Magnum/Shaders/VectorGL.h index ad3160304..ef3d2bd33 100644 --- a/src/Magnum/Shaders/VectorGL.h +++ b/src/Magnum/Shaders/VectorGL.h @@ -401,7 +401,9 @@ template class MAGNUM_SHADERS_EXPORT VectorGL: public GL * @ref bindDrawBuffer() and @ref bindTextureTransformationBuffer() * should be used for current draw. Expects that * @ref Flag::UniformBuffers is set and @p offset is less than - * @ref drawCount(). Initial value is @cpp 0 @ce. + * @ref drawCount(). Initial value is @cpp 0 @ce, if @ref drawCount() + * is @cpp 1 @ce, the function is a no-op as the shader assumes draw + * offset to be always zero. * * If @ref Flag::MultiDraw is set, @glsl gl_DrawID @ce is added to this * value, which makes each draw submitted via diff --git a/src/Magnum/Shaders/VertexColor.vert b/src/Magnum/Shaders/VertexColor.vert index 53f389cae..d1fbceea0 100644 --- a/src/Magnum/Shaders/VertexColor.vert +++ b/src/Magnum/Shaders/VertexColor.vert @@ -65,6 +65,7 @@ uniform highp mat4 transformationProjectionMatrix /* Uniform buffers */ #else +#if DRAW_COUNT > 1 #ifdef EXPLICIT_UNIFORM_LOCATION layout(location = 0) #endif @@ -73,6 +74,9 @@ uniform highp uint drawOffset = 0u #endif ; +#else +#define drawOffset 0u +#endif layout(std140 #ifdef EXPLICIT_BINDING diff --git a/src/Magnum/Shaders/VertexColorGL.cpp b/src/Magnum/Shaders/VertexColorGL.cpp index 7da23cbc4..5a7c5fb9e 100644 --- a/src/Magnum/Shaders/VertexColorGL.cpp +++ b/src/Magnum/Shaders/VertexColorGL.cpp @@ -144,7 +144,7 @@ template VertexColorGL::VertexColorGL(const { #ifndef MAGNUM_TARGET_GLES2 if(flags >= Flag::UniformBuffers) { - _drawOffsetUniform = uniformLocation("drawOffset"); + if(_drawCount > 1) _drawOffsetUniform = uniformLocation("drawOffset"); } else #endif { @@ -194,7 +194,7 @@ template VertexColorGL& VertexColorGL 1) setUniform(_drawOffsetUniform, offset); return *this; } diff --git a/src/Magnum/Shaders/VertexColorGL.h b/src/Magnum/Shaders/VertexColorGL.h index c71c9688b..73b23dfa2 100644 --- a/src/Magnum/Shaders/VertexColorGL.h +++ b/src/Magnum/Shaders/VertexColorGL.h @@ -331,7 +331,9 @@ template class MAGNUM_SHADERS_EXPORT VertexColorGL: publ * @ref TransformationProjectionUniform3D buffers bound with * @ref bindTransformationProjectionBuffer() should be used for current * draw. Expects that @ref Flag::UniformBuffers is set and @p offset is - * less than @ref drawCount(). Initial value is @cpp 0 @ce. + * less than @ref drawCount(). Initial value is @cpp 0 @ce, if + * @ref drawCount() is @cpp 1 @ce, the function is a no-op as the + * shader assumes draw offset to be always zero. * * If @ref Flag::MultiDraw is set, @glsl gl_DrawID @ce is added to this * value, which makes each draw submitted via