From a0f0015211920b32ff30c6f7e2e2ed77b04a155f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 1 Oct 2019 16:57:04 +0200 Subject: [PATCH] Shaders: de-inline uniform setters. Reduces includes in the header quite a lot, yay. --- doc/generated/primitives.cpp | 3 ++ doc/generated/shaders.cpp | 3 ++ doc/snippets/MagnumShaders.cpp | 2 + doc/snippets/MagnumText.cpp | 2 + src/Magnum/MeshTools/Test/CompileGLTest.cpp | 1 + src/Magnum/Shaders/DistanceFieldVector.cpp | 28 +++++++++++ src/Magnum/Shaders/DistanceFieldVector.h | 28 ++--------- src/Magnum/Shaders/Flat.cpp | 13 +++++ src/Magnum/Shaders/Flat.h | 13 +---- src/Magnum/Shaders/MeshVisualizer.cpp | 34 +++++++++++++ src/Magnum/Shaders/MeshVisualizer.h | 34 ++----------- src/Magnum/Shaders/Phong.cpp | 49 +++++++++++++++++++ src/Magnum/Shaders/Phong.h | 45 ++++------------- .../Test/DistanceFieldVectorGLTest.cpp | 9 ++-- src/Magnum/Shaders/Test/FlatGLTest.cpp | 3 ++ .../Shaders/Test/MeshVisualizerGLTest.cpp | 2 + src/Magnum/Shaders/Test/PhongGLTest.cpp | 2 + src/Magnum/Shaders/Test/VectorGLTest.cpp | 9 ++-- src/Magnum/Shaders/Test/VertexColorGLTest.cpp | 9 ++-- src/Magnum/Shaders/Vector.cpp | 18 +++++++ src/Magnum/Shaders/Vector.h | 18 ++----- src/Magnum/Shaders/VertexColor.cpp | 8 +++ src/Magnum/Shaders/VertexColor.h | 8 +-- 23 files changed, 211 insertions(+), 130 deletions(-) diff --git a/doc/generated/primitives.cpp b/doc/generated/primitives.cpp index 0034e926a..d9fcc33ab 100644 --- a/doc/generated/primitives.cpp +++ b/doc/generated/primitives.cpp @@ -50,6 +50,9 @@ #include #include #include +#include +#include +#include #include #include #include diff --git a/doc/generated/shaders.cpp b/doc/generated/shaders.cpp index d6c0f204c..2fbc128a6 100644 --- a/doc/generated/shaders.cpp +++ b/doc/generated/shaders.cpp @@ -49,6 +49,9 @@ #include #include #include +#include +#include +#include #include #include #include diff --git a/doc/snippets/MagnumShaders.cpp b/doc/snippets/MagnumShaders.cpp index 798e72918..1e455c1e5 100644 --- a/doc/snippets/MagnumShaders.cpp +++ b/doc/snippets/MagnumShaders.cpp @@ -35,6 +35,8 @@ #include "Magnum/GL/RenderbufferFormat.h" #include "Magnum/GL/Texture.h" #include "Magnum/Math/Color.h" +#include "Magnum/Math/Matrix3.h" +#include "Magnum/Math/Matrix4.h" #include "Magnum/MeshTools/Duplicate.h" #include "Magnum/Shaders/DistanceFieldVector.h" #include "Magnum/Shaders/Flat.h" diff --git a/doc/snippets/MagnumText.cpp b/doc/snippets/MagnumText.cpp index 397f64dae..058fc15b7 100644 --- a/doc/snippets/MagnumText.cpp +++ b/doc/snippets/MagnumText.cpp @@ -30,6 +30,8 @@ #include #include "Magnum/FileCallback.h" +#include "Magnum/Math/Color.h" +#include "Magnum/Math/Matrix3.h" #include "Magnum/Shaders/Vector.h" #include "Magnum/Text/AbstractFont.h" #include "Magnum/Text/DistanceFieldGlyphCache.h" diff --git a/src/Magnum/MeshTools/Test/CompileGLTest.cpp b/src/Magnum/MeshTools/Test/CompileGLTest.cpp index c6554e252..cd855ee31 100644 --- a/src/Magnum/MeshTools/Test/CompileGLTest.cpp +++ b/src/Magnum/MeshTools/Test/CompileGLTest.cpp @@ -39,6 +39,7 @@ #include "Magnum/GL/RenderbufferFormat.h" #include "Magnum/GL/Texture.h" #include "Magnum/GL/TextureFormat.h" +#include "Magnum/Math/Color.h" #include "Magnum/Math/Matrix4.h" #include "Magnum/MeshTools/Compile.h" #include "Magnum/MeshTools/Duplicate.h" diff --git a/src/Magnum/Shaders/DistanceFieldVector.cpp b/src/Magnum/Shaders/DistanceFieldVector.cpp index 8f3f05bf7..2ee306ef3 100644 --- a/src/Magnum/Shaders/DistanceFieldVector.cpp +++ b/src/Magnum/Shaders/DistanceFieldVector.cpp @@ -31,6 +31,9 @@ #include "Magnum/GL/Context.h" #include "Magnum/GL/Extensions.h" #include "Magnum/GL/Shader.h" +#include "Magnum/Math/Color.h" +#include "Magnum/Math/Matrix3.h" +#include "Magnum/Math/Matrix4.h" #include "Magnum/Shaders/Implementation/CreateCompatibilityShader.h" @@ -109,6 +112,31 @@ template DistanceFieldVector::DistanceFieldV #endif } +template DistanceFieldVector& DistanceFieldVector::setTransformationProjectionMatrix(const MatrixTypeFor& matrix) { + GL::AbstractShaderProgram::setUniform(_transformationProjectionMatrixUniform, matrix); + return *this; +} + +template DistanceFieldVector& DistanceFieldVector::setColor(const Color4& color) { + GL::AbstractShaderProgram::setUniform(_colorUniform, color); + return *this; +} + +template DistanceFieldVector& DistanceFieldVector::setOutlineColor(const Color4& color) { + GL::AbstractShaderProgram::setUniform(_outlineColorUniform, color); + return *this; +} + +template DistanceFieldVector& DistanceFieldVector::setOutlineRange(Float start, Float end) { + GL::AbstractShaderProgram::setUniform(_outlineRangeUniform, Vector2(start, end)); + return *this; +} + +template DistanceFieldVector& DistanceFieldVector::setSmoothness(Float value) { + GL::AbstractShaderProgram::setUniform(_smoothnessUniform, value); + return *this; +} + template class DistanceFieldVector<2>; template class DistanceFieldVector<3>; diff --git a/src/Magnum/Shaders/DistanceFieldVector.h b/src/Magnum/Shaders/DistanceFieldVector.h index 3fbb44968..175ae9357 100644 --- a/src/Magnum/Shaders/DistanceFieldVector.h +++ b/src/Magnum/Shaders/DistanceFieldVector.h @@ -30,9 +30,6 @@ */ #include "Magnum/DimensionTraits.h" -#include "Magnum/Math/Color.h" -#include "Magnum/Math/Matrix3.h" -#include "Magnum/Math/Matrix4.h" #include "Magnum/Shaders/AbstractVector.h" #include "Magnum/Shaders/visibility.h" @@ -107,10 +104,7 @@ template class MAGNUM_SHADERS_EXPORT DistanceFieldVector * * Initial value is an identity matrix. */ - DistanceFieldVector& setTransformationProjectionMatrix(const MatrixTypeFor& matrix) { - GL::AbstractShaderProgram::setUniform(_transformationProjectionMatrixUniform, matrix); - return *this; - } + DistanceFieldVector& setTransformationProjectionMatrix(const MatrixTypeFor& matrix); /** * @brief Set fill color @@ -119,10 +113,7 @@ template class MAGNUM_SHADERS_EXPORT DistanceFieldVector * Initial value is @cpp 0xffffffff_rgbaf @ce. * @see @ref setOutlineColor() */ - DistanceFieldVector& setColor(const Color4& color) { - GL::AbstractShaderProgram::setUniform(_colorUniform, color); - return *this; - } + DistanceFieldVector& setColor(const Color4& color); /** * @brief Set outline color @@ -132,10 +123,7 @@ template class MAGNUM_SHADERS_EXPORT DistanceFieldVector * drawn --- see @ref setOutlineRange() for more information. * @see @ref setOutlineRange(), @ref setColor() */ - DistanceFieldVector& setOutlineColor(const Color4& color) { - GL::AbstractShaderProgram::setUniform(_outlineColorUniform, color); - return *this; - } + DistanceFieldVector& setOutlineColor(const Color4& color); /** * @brief Set outline range @@ -151,10 +139,7 @@ template class MAGNUM_SHADERS_EXPORT DistanceFieldVector * * @see @ref setOutlineColor() */ - DistanceFieldVector& setOutlineRange(Float start, Float end) { - GL::AbstractShaderProgram::setUniform(_outlineRangeUniform, Vector2(start, end)); - return *this; - } + DistanceFieldVector& setOutlineRange(Float start, Float end); /** * @brief Set smoothness radius @@ -164,10 +149,7 @@ template class MAGNUM_SHADERS_EXPORT DistanceFieldVector * smaller values will make them look more crisp (but possibly * aliased). Initial value is @cpp 0.04f @ce. */ - DistanceFieldVector& setSmoothness(Float value) { - GL::AbstractShaderProgram::setUniform(_smoothnessUniform, value); - return *this; - } + DistanceFieldVector& setSmoothness(Float value); #ifndef DOXYGEN_GENERATING_OUTPUT /* Overloads to remove WTF-factor from method chaining order */ diff --git a/src/Magnum/Shaders/Flat.cpp b/src/Magnum/Shaders/Flat.cpp index 74ee895aa..8e8a326e5 100644 --- a/src/Magnum/Shaders/Flat.cpp +++ b/src/Magnum/Shaders/Flat.cpp @@ -33,6 +33,9 @@ #include "Magnum/GL/Extensions.h" #include "Magnum/GL/Shader.h" #include "Magnum/GL/Texture.h" +#include "Magnum/Math/Color.h" +#include "Magnum/Math/Matrix3.h" +#include "Magnum/Math/Matrix4.h" #include "Magnum/Shaders/Implementation/CreateCompatibilityShader.h" @@ -131,6 +134,16 @@ template Flat::Flat(const Flags flags): _fla #endif } +template Flat& Flat::setTransformationProjectionMatrix(const MatrixTypeFor& matrix) { + setUniform(_transformationProjectionMatrixUniform, matrix); + return *this; +} + +template Flat& Flat::setColor(const Magnum::Color4& color) { + setUniform(_colorUniform, color); + return *this; +} + template Flat& Flat::bindTexture(GL::Texture2D& texture) { CORRADE_ASSERT(_flags & Flag::Textured, "Shaders::Flat::bindTexture(): the shader was not created with texturing enabled", *this); diff --git a/src/Magnum/Shaders/Flat.h b/src/Magnum/Shaders/Flat.h index 9eb66ee8d..bf5278f2f 100644 --- a/src/Magnum/Shaders/Flat.h +++ b/src/Magnum/Shaders/Flat.h @@ -31,9 +31,6 @@ #include "Magnum/DimensionTraits.h" #include "Magnum/GL/AbstractShaderProgram.h" -#include "Magnum/Math/Color.h" -#include "Magnum/Math/Matrix3.h" -#include "Magnum/Math/Matrix4.h" #include "Magnum/Shaders/Generic.h" #include "Magnum/Shaders/visibility.h" @@ -278,10 +275,7 @@ template class MAGNUM_SHADERS_EXPORT Flat: public GL::Ab * * Initial value is an identity matrix. */ - Flat& setTransformationProjectionMatrix(const MatrixTypeFor& matrix) { - setUniform(_transformationProjectionMatrixUniform, matrix); - return *this; - } + Flat& setTransformationProjectionMatrix(const MatrixTypeFor& matrix); /** * @brief Set color @@ -292,10 +286,7 @@ template class MAGNUM_SHADERS_EXPORT Flat: public GL::Ab * texture. * @see @ref bindTexture() */ - Flat& setColor(const Magnum::Color4& color) { - setUniform(_colorUniform, color); - return *this; - } + Flat& setColor(const Magnum::Color4& color); /** * @brief Bind a color texture diff --git a/src/Magnum/Shaders/MeshVisualizer.cpp b/src/Magnum/Shaders/MeshVisualizer.cpp index 6f53d8de2..f3f794cbc 100644 --- a/src/Magnum/Shaders/MeshVisualizer.cpp +++ b/src/Magnum/Shaders/MeshVisualizer.cpp @@ -30,6 +30,8 @@ #include #include +#include "Magnum/Math/Color.h" +#include "Magnum/Math/Matrix4.h" #include "Magnum/GL/Context.h" #include "Magnum/GL/Extensions.h" #include "Magnum/GL/Shader.h" @@ -156,6 +158,38 @@ MeshVisualizer::MeshVisualizer(const Flags flags): _flags{flags} { #endif } +MeshVisualizer& MeshVisualizer::setTransformationProjectionMatrix(const Matrix4& matrix) { + setUniform(_transformationProjectionMatrixUniform, matrix); + return *this; +} + +MeshVisualizer& MeshVisualizer::setViewportSize(const Vector2& size) { + if(_flags & Flag::Wireframe && !(_flags & Flag::NoGeometryShader)) + setUniform(_viewportSizeUniform, size); + return *this; +} + +MeshVisualizer& MeshVisualizer::setColor(const Color4& color) { + setUniform(_colorUniform, color); + return *this; +} + +MeshVisualizer& MeshVisualizer::setWireframeColor(const Color4& color) { + if(_flags & Flag::Wireframe) setUniform(_wireframeColorUniform, color); + return *this; +} + +MeshVisualizer& MeshVisualizer::setWireframeWidth(const Float width) { + if(_flags & Flag::Wireframe) setUniform(_wireframeWidthUniform, width); + return *this; +} + +MeshVisualizer& MeshVisualizer::setSmoothness(const Float smoothness) { + if(_flags & Flag::Wireframe) + setUniform(_smoothnessUniform, smoothness); + return *this; +} + Debug& operator<<(Debug& debug, const MeshVisualizer::Flag value) { switch(value) { /* LCOV_EXCL_START */ diff --git a/src/Magnum/Shaders/MeshVisualizer.h b/src/Magnum/Shaders/MeshVisualizer.h index eca3ee980..3961a4c47 100644 --- a/src/Magnum/Shaders/MeshVisualizer.h +++ b/src/Magnum/Shaders/MeshVisualizer.h @@ -30,8 +30,6 @@ */ #include "Magnum/GL/AbstractShaderProgram.h" -#include "Magnum/Math/Color.h" -#include "Magnum/Math/Matrix4.h" #include "Magnum/Shaders/Generic.h" #include "Magnum/Shaders/visibility.h" @@ -205,10 +203,7 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizer: public GL::AbstractShaderProgram { * * Initial value is an identity matrix. */ - MeshVisualizer& setTransformationProjectionMatrix(const Matrix4& matrix) { - setUniform(_transformationProjectionMatrixUniform, matrix); - return *this; - } + MeshVisualizer& setTransformationProjectionMatrix(const Matrix4& matrix); /** * @brief Set viewport size @@ -217,11 +212,7 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizer: public GL::AbstractShaderProgram { * Has effect only if @ref Flag::Wireframe is enabled and geometry * shaders are used. Initial value is a zero vector. */ - MeshVisualizer& setViewportSize(const Vector2& size) { - if(_flags & Flag::Wireframe && !(_flags & Flag::NoGeometryShader)) - setUniform(_viewportSizeUniform, size); - return *this; - } + MeshVisualizer& setViewportSize(const Vector2& size); /** * @brief Set base object color @@ -229,10 +220,7 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizer: public GL::AbstractShaderProgram { * * Initial value is @cpp 0xffffffff_rgbaf @ce. */ - MeshVisualizer& setColor(const Color4& color) { - setUniform(_colorUniform, color); - return *this; - } + MeshVisualizer& setColor(const Color4& color); /** * @brief Set wireframe color @@ -241,10 +229,7 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizer: public GL::AbstractShaderProgram { * Initial value is @cpp 0x000000ff_rgbaf @ce. Has effect only if * @ref Flag::Wireframe is enabled. */ - MeshVisualizer& setWireframeColor(const Color4& color) { - if(_flags & Flag::Wireframe) setUniform(_wireframeColorUniform, color); - return *this; - } + MeshVisualizer& setWireframeColor(const Color4& color); /** * @brief Set wireframe width @@ -253,10 +238,7 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizer: public GL::AbstractShaderProgram { * Initial value is @cpp 1.0f @ce. Has effect only if @ref Flag::Wireframe * is enabled. */ - MeshVisualizer& setWireframeWidth(Float width) { - if(_flags & Flag::Wireframe) setUniform(_wireframeWidthUniform, width); - return *this; - } + MeshVisualizer& setWireframeWidth(Float width); /** * @brief Set line smoothness @@ -285,12 +267,6 @@ MAGNUM_SHADERS_EXPORT Debug& operator<<(Debug& debug, MeshVisualizer::Flags valu CORRADE_ENUMSET_OPERATORS(MeshVisualizer::Flags) -inline MeshVisualizer& MeshVisualizer::setSmoothness(Float smoothness) { - if(_flags & Flag::Wireframe) - setUniform(_smoothnessUniform, smoothness); - return *this; -} - }} #endif diff --git a/src/Magnum/Shaders/Phong.cpp b/src/Magnum/Shaders/Phong.cpp index 94f05e138..0c0f75d2e 100644 --- a/src/Magnum/Shaders/Phong.cpp +++ b/src/Magnum/Shaders/Phong.cpp @@ -37,6 +37,8 @@ #include "Magnum/GL/Extensions.h" #include "Magnum/GL/Shader.h" #include "Magnum/GL/Texture.h" +#include "Magnum/Math/Color.h" +#include "Magnum/Math/Matrix4.h" #include "Magnum/Shaders/Implementation/CreateCompatibilityShader.h" @@ -198,6 +200,11 @@ Phong::Phong(const Flags flags, const UnsignedInt lightCount): _flags{flags}, _l #endif } +Phong& Phong::setAmbientColor(const Magnum::Color4& color) { + setUniform(_ambientColorUniform, color); + return *this; +} + Phong& Phong::bindAmbientTexture(GL::Texture2D& texture) { CORRADE_ASSERT(_flags & Flag::AmbientTexture, "Shaders::Phong::bindAmbientTexture(): the shader was not created with ambient texture enabled", *this); @@ -205,6 +212,11 @@ Phong& Phong::bindAmbientTexture(GL::Texture2D& texture) { return *this; } +Phong& Phong::setDiffuseColor(const Magnum::Color4& color) { + if(_lightCount) setUniform(_diffuseColorUniform, color); + return *this; +} + Phong& Phong::bindDiffuseTexture(GL::Texture2D& texture) { CORRADE_ASSERT(_flags & Flag::DiffuseTexture, "Shaders::Phong::bindDiffuseTexture(): the shader was not created with diffuse texture enabled", *this); @@ -212,6 +224,11 @@ Phong& Phong::bindDiffuseTexture(GL::Texture2D& texture) { return *this; } +Phong& Phong::setSpecularColor(const Magnum::Color4& color) { + if(_lightCount) setUniform(_specularColorUniform, color); + return *this; +} + Phong& Phong::bindSpecularTexture(GL::Texture2D& texture) { CORRADE_ASSERT(_flags & Flag::SpecularTexture, "Shaders::Phong::bindSpecularTexture(): the shader was not created with specular texture enabled", *this); @@ -233,6 +250,11 @@ Phong& Phong::bindTextures(GL::Texture2D* ambient, GL::Texture2D* diffuse, GL::T return *this; } +Phong& Phong::setShininess(Float shininess) { + if(_lightCount) setUniform(_shininessUniform, shininess); + return *this; +} + Phong& Phong::setAlphaMask(Float mask) { CORRADE_ASSERT(_flags & Flag::AlphaMask, "Shaders::Phong::setAlphaMask(): the shader was not created with alpha mask enabled", *this); @@ -249,6 +271,21 @@ Phong& Phong::setObjectId(UnsignedInt id) { } #endif +Phong& Phong::setTransformationMatrix(const Matrix4& matrix) { + setUniform(_transformationMatrixUniform, matrix); + return *this; +} + +Phong& Phong::setNormalMatrix(const Matrix3x3& matrix) { + if(_lightCount) setUniform(_normalMatrixUniform, matrix); + return *this; +} + +Phong& Phong::setProjectionMatrix(const Matrix4& matrix) { + setUniform(_projectionMatrixUniform, matrix); + return *this; +} + Phong& Phong::setLightPositions(const Containers::ArrayView positions) { CORRADE_ASSERT(_lightCount == positions.size(), "Shaders::Phong::setLightPositions(): expected" << _lightCount << "items but got" << positions.size(), *this); @@ -263,6 +300,12 @@ Phong& Phong::setLightPosition(UnsignedInt id, const Vector3& position) { return *this; } +/* It's light, but can't be in the header because MSVC needs to know the size + of Vector3 for the initializer list use */ +Phong& Phong::setLightPositions(std::initializer_list lights) { + return setLightPositions({lights.begin(), lights.size()}); +} + Phong& Phong::setLightColors(const Containers::ArrayView colors) { CORRADE_ASSERT(_lightCount == colors.size(), "Shaders::Phong::setLightColors(): expected" << _lightCount << "items but got" << colors.size(), *this); @@ -270,6 +313,12 @@ Phong& Phong::setLightColors(const Containers::ArrayView c return *this; } +/* It's light, but can't be in the header because MSVC needs to know the size + of Color for the initializer list use */ +Phong& Phong::setLightColors(std::initializer_list colors) { + return setLightColors({colors.begin(), colors.size()}); +} + Phong& Phong::setLightColor(UnsignedInt id, const Magnum::Color4& color) { CORRADE_ASSERT(id < _lightCount, "Shaders::Phong::setLightColor(): light ID" << id << "is out of bounds for" << _lightCount << "lights", *this); diff --git a/src/Magnum/Shaders/Phong.h b/src/Magnum/Shaders/Phong.h index d7ca7a1ff..242b79ae1 100644 --- a/src/Magnum/Shaders/Phong.h +++ b/src/Magnum/Shaders/Phong.h @@ -30,8 +30,6 @@ */ #include "Magnum/GL/AbstractShaderProgram.h" -#include "Magnum/Math/Color.h" -#include "Magnum/Math/Matrix4.h" #include "Magnum/Shaders/Generic.h" #include "Magnum/Shaders/visibility.h" @@ -311,10 +309,7 @@ class MAGNUM_SHADERS_EXPORT Phong: public GL::AbstractShaderProgram { * ambient texture, otherwise default value is @cpp 0x00000000_rgbaf @ce. * @see @ref bindAmbientTexture() */ - Phong& setAmbientColor(const Magnum::Color4& color) { - setUniform(_ambientColorUniform, color); - return *this; - } + Phong& setAmbientColor(const Magnum::Color4& color); /** * @brief Bind an ambient texture @@ -344,10 +339,7 @@ class MAGNUM_SHADERS_EXPORT Phong: public GL::AbstractShaderProgram { * to the output in that case. * @see @ref bindDiffuseTexture() */ - Phong& setDiffuseColor(const Magnum::Color4& color) { - if(_lightCount) setUniform(_diffuseColorUniform, color); - return *this; - } + Phong& setDiffuseColor(const Magnum::Color4& color); /** * @brief Bind a diffuse texture @@ -393,10 +385,7 @@ class MAGNUM_SHADERS_EXPORT Phong: public GL::AbstractShaderProgram { * output in that case. * @see @ref bindSpecularTexture() */ - Phong& setSpecularColor(const Magnum::Color4& color) { - if(_lightCount) setUniform(_specularColorUniform, color); - return *this; - } + Phong& setSpecularColor(const Magnum::Color4& color); /** * @brief Bind a specular texture @@ -455,10 +444,7 @@ class MAGNUM_SHADERS_EXPORT Phong: public GL::AbstractShaderProgram { * function is a no-op, as specular color doesn't contribute to the * output in that case. */ - Phong& setShininess(Float shininess) { - if(_lightCount) setUniform(_shininessUniform, shininess); - return *this; - } + Phong& setShininess(Float shininess); /** * @brief Set alpha mask value @@ -494,10 +480,7 @@ class MAGNUM_SHADERS_EXPORT Phong: public GL::AbstractShaderProgram { * You need to set also @ref setNormalMatrix() with a corresponding * value. Initial value is an identity matrix. */ - Phong& setTransformationMatrix(const Matrix4& matrix) { - setUniform(_transformationMatrixUniform, matrix); - return *this; - } + Phong& setTransformationMatrix(const Matrix4& matrix); /** * @brief Set normal matrix @@ -510,10 +493,7 @@ class MAGNUM_SHADERS_EXPORT Phong: public GL::AbstractShaderProgram { * function is a no-op, as normals don't contribute to the output in * that case. */ - Phong& setNormalMatrix(const Matrix3x3& matrix) { - if(_lightCount) setUniform(_normalMatrixUniform, matrix); - return *this; - } + Phong& setNormalMatrix(const Matrix3x3& matrix); /** * @brief Set projection matrix @@ -523,10 +503,7 @@ class MAGNUM_SHADERS_EXPORT Phong: public GL::AbstractShaderProgram { * projection of the default @f$ [ -\boldsymbol{1} ; \boldsymbol{1} ] @f$ * cube). */ - Phong& setProjectionMatrix(const Matrix4& matrix) { - setUniform(_projectionMatrixUniform, matrix); - return *this; - } + Phong& setProjectionMatrix(const Matrix4& matrix); /** * @brief Set light positions @@ -542,9 +519,7 @@ class MAGNUM_SHADERS_EXPORT Phong: public GL::AbstractShaderProgram { Phong& setLightPositions(Containers::ArrayView lights); /** @overload */ - Phong& setLightPositions(std::initializer_list lights) { - return setLightPositions({lights.begin(), lights.size()}); - } + Phong& setLightPositions(std::initializer_list lights); /** * @brief Set position for given light @@ -578,9 +553,7 @@ class MAGNUM_SHADERS_EXPORT Phong: public GL::AbstractShaderProgram { Phong& setLightColors(Containers::ArrayView colors); /** @overload */ - Phong& setLightColors(std::initializer_list colors) { - return setLightColors({colors.begin(), colors.size()}); - } + Phong& setLightColors(std::initializer_list colors); /** * @brief Set position for given light diff --git a/src/Magnum/Shaders/Test/DistanceFieldVectorGLTest.cpp b/src/Magnum/Shaders/Test/DistanceFieldVectorGLTest.cpp index 9e14eab6d..296efd4c6 100644 --- a/src/Magnum/Shaders/Test/DistanceFieldVectorGLTest.cpp +++ b/src/Magnum/Shaders/Test/DistanceFieldVectorGLTest.cpp @@ -28,6 +28,9 @@ #include #include +#include "Magnum/Image.h" +#include "Magnum/ImageView.h" +#include "Magnum/PixelFormat.h" #include "Magnum/DebugTools/CompareImage.h" #include "Magnum/GL/OpenGLTester.h" #include "Magnum/GL/Framebuffer.h" @@ -36,9 +39,9 @@ #include "Magnum/GL/RenderbufferFormat.h" #include "Magnum/GL/Texture.h" #include "Magnum/GL/TextureFormat.h" -#include "Magnum/Image.h" -#include "Magnum/ImageView.h" -#include "Magnum/PixelFormat.h" +#include "Magnum/Math/Color.h" +#include "Magnum/Math/Matrix3.h" +#include "Magnum/Math/Matrix4.h" #include "Magnum/MeshTools/Compile.h" #include "Magnum/Primitives/Plane.h" #include "Magnum/Primitives/Square.h" diff --git a/src/Magnum/Shaders/Test/FlatGLTest.cpp b/src/Magnum/Shaders/Test/FlatGLTest.cpp index 3a1b2f231..a23cc9f5e 100644 --- a/src/Magnum/Shaders/Test/FlatGLTest.cpp +++ b/src/Magnum/Shaders/Test/FlatGLTest.cpp @@ -43,6 +43,9 @@ #include "Magnum/GL/Texture.h" #include "Magnum/GL/TextureFormat.h" #include "Magnum/GL/OpenGLTester.h" +#include "Magnum/Math/Color.h" +#include "Magnum/Math/Matrix3.h" +#include "Magnum/Math/Matrix4.h" #include "Magnum/MeshTools/Compile.h" #include "Magnum/Primitives/Circle.h" #include "Magnum/Primitives/UVSphere.h" diff --git a/src/Magnum/Shaders/Test/MeshVisualizerGLTest.cpp b/src/Magnum/Shaders/Test/MeshVisualizerGLTest.cpp index dbea6588f..ae9dd42c9 100644 --- a/src/Magnum/Shaders/Test/MeshVisualizerGLTest.cpp +++ b/src/Magnum/Shaders/Test/MeshVisualizerGLTest.cpp @@ -40,6 +40,8 @@ #include "Magnum/Image.h" #include "Magnum/ImageView.h" #include "Magnum/PixelFormat.h" +#include "Magnum/Math/Color.h" +#include "Magnum/Math/Matrix4.h" #include "Magnum/MeshTools/Compile.h" #include "Magnum/MeshTools/Duplicate.h" #include "Magnum/Primitives/Circle.h" diff --git a/src/Magnum/Shaders/Test/PhongGLTest.cpp b/src/Magnum/Shaders/Test/PhongGLTest.cpp index b4e2f2772..c2d97fdaf 100644 --- a/src/Magnum/Shaders/Test/PhongGLTest.cpp +++ b/src/Magnum/Shaders/Test/PhongGLTest.cpp @@ -43,6 +43,8 @@ #include "Magnum/GL/RenderbufferFormat.h" #include "Magnum/GL/Texture.h" #include "Magnum/GL/TextureFormat.h" +#include "Magnum/Math/Color.h" +#include "Magnum/Math/Matrix4.h" #include "Magnum/MeshTools/Compile.h" #include "Magnum/MeshTools/Transform.h" #include "Magnum/Primitives/Plane.h" diff --git a/src/Magnum/Shaders/Test/VectorGLTest.cpp b/src/Magnum/Shaders/Test/VectorGLTest.cpp index df9cb3c0a..72d44cad2 100644 --- a/src/Magnum/Shaders/Test/VectorGLTest.cpp +++ b/src/Magnum/Shaders/Test/VectorGLTest.cpp @@ -28,6 +28,9 @@ #include #include +#include "Magnum/Image.h" +#include "Magnum/ImageView.h" +#include "Magnum/PixelFormat.h" #include "Magnum/DebugTools/CompareImage.h" #include "Magnum/GL/Framebuffer.h" #include "Magnum/GL/Mesh.h" @@ -36,9 +39,9 @@ #include "Magnum/GL/RenderbufferFormat.h" #include "Magnum/GL/Texture.h" #include "Magnum/GL/TextureFormat.h" -#include "Magnum/Image.h" -#include "Magnum/ImageView.h" -#include "Magnum/PixelFormat.h" +#include "Magnum/Math/Color.h" +#include "Magnum/Math/Matrix3.h" +#include "Magnum/Math/Matrix4.h" #include "Magnum/MeshTools/Compile.h" #include "Magnum/Primitives/Plane.h" #include "Magnum/Primitives/Square.h" diff --git a/src/Magnum/Shaders/Test/VertexColorGLTest.cpp b/src/Magnum/Shaders/Test/VertexColorGLTest.cpp index 9e0f3182c..be7890f25 100644 --- a/src/Magnum/Shaders/Test/VertexColorGLTest.cpp +++ b/src/Magnum/Shaders/Test/VertexColorGLTest.cpp @@ -28,14 +28,17 @@ #include #include "Magnum/DebugTools/CompareImage.h" +#include "Magnum/Image.h" +#include "Magnum/ImageView.h" +#include "Magnum/PixelFormat.h" #include "Magnum/GL/OpenGLTester.h" #include "Magnum/GL/Framebuffer.h" #include "Magnum/GL/Mesh.h" #include "Magnum/GL/Renderbuffer.h" #include "Magnum/GL/RenderbufferFormat.h" -#include "Magnum/Image.h" -#include "Magnum/ImageView.h" -#include "Magnum/PixelFormat.h" +#include "Magnum/Math/Color.h" +#include "Magnum/Math/Matrix3.h" +#include "Magnum/Math/Matrix4.h" #include "Magnum/MeshTools/Compile.h" #include "Magnum/Primitives/Circle.h" #include "Magnum/Primitives/UVSphere.h" diff --git a/src/Magnum/Shaders/Vector.cpp b/src/Magnum/Shaders/Vector.cpp index 6573eba57..b14498237 100644 --- a/src/Magnum/Shaders/Vector.cpp +++ b/src/Magnum/Shaders/Vector.cpp @@ -31,6 +31,9 @@ #include "Magnum/GL/Context.h" #include "Magnum/GL/Extensions.h" #include "Magnum/GL/Shader.h" +#include "Magnum/Math/Color.h" +#include "Magnum/Math/Matrix3.h" +#include "Magnum/Math/Matrix4.h" #include "Magnum/Shaders/Implementation/CreateCompatibilityShader.h" @@ -104,6 +107,21 @@ template Vector::Vector() { #endif } +template Vector& Vector::setTransformationProjectionMatrix(const MatrixTypeFor& matrix) { + GL::AbstractShaderProgram::setUniform(_transformationProjectionMatrixUniform, matrix); + return *this; +} + +template Vector& Vector::setBackgroundColor(const Color4& color) { + GL::AbstractShaderProgram::setUniform(_backgroundColorUniform, color); + return *this; +} + +template Vector& Vector::setColor(const Color4& color) { + GL::AbstractShaderProgram::setUniform(_colorUniform, color); + return *this; +} + template class Vector<2>; template class Vector<3>; diff --git a/src/Magnum/Shaders/Vector.h b/src/Magnum/Shaders/Vector.h index 325f3906c..714259d7d 100644 --- a/src/Magnum/Shaders/Vector.h +++ b/src/Magnum/Shaders/Vector.h @@ -30,9 +30,6 @@ */ #include "Magnum/DimensionTraits.h" -#include "Magnum/Math/Color.h" -#include "Magnum/Math/Matrix3.h" -#include "Magnum/Math/Matrix4.h" #include "Magnum/Shaders/AbstractVector.h" #include "Magnum/Shaders/visibility.h" @@ -103,10 +100,7 @@ template class MAGNUM_SHADERS_EXPORT Vector: public Abst * * Default is an identity matrix. */ - Vector& setTransformationProjectionMatrix(const MatrixTypeFor& matrix) { - GL::AbstractShaderProgram::setUniform(_transformationProjectionMatrixUniform, matrix); - return *this; - } + Vector& setTransformationProjectionMatrix(const MatrixTypeFor& matrix); /** * @brief Set background color @@ -115,10 +109,7 @@ template class MAGNUM_SHADERS_EXPORT Vector: public Abst * Default is @cpp 0x00000000_rgbaf @ce. * @see @ref setColor() */ - Vector& setBackgroundColor(const Color4& color) { - GL::AbstractShaderProgram::setUniform(_backgroundColorUniform, color); - return *this; - } + Vector& setBackgroundColor(const Color4& color); /** * @brief Set fill color @@ -127,10 +118,7 @@ template class MAGNUM_SHADERS_EXPORT Vector: public Abst * Default is @cpp 0xffffffff_rgbaf @ce. * @see @ref setBackgroundColor() */ - Vector& setColor(const Color4& color) { - GL::AbstractShaderProgram::setUniform(_colorUniform, color); - return *this; - } + Vector& setColor(const Color4& color); #ifndef DOXYGEN_GENERATING_OUTPUT /* Overloads to remove WTF-factor from method chaining order */ diff --git a/src/Magnum/Shaders/VertexColor.cpp b/src/Magnum/Shaders/VertexColor.cpp index 923885e5a..935fe37fb 100644 --- a/src/Magnum/Shaders/VertexColor.cpp +++ b/src/Magnum/Shaders/VertexColor.cpp @@ -31,6 +31,9 @@ #include "Magnum/GL/Context.h" #include "Magnum/GL/Extensions.h" #include "Magnum/GL/Shader.h" +#include "Magnum/Math/Color.h" +#include "Magnum/Math/Matrix3.h" +#include "Magnum/Math/Matrix4.h" #include "Magnum/Shaders/Implementation/CreateCompatibilityShader.h" @@ -94,6 +97,11 @@ template VertexColor::VertexColor() { #endif } +template VertexColor& VertexColor::setTransformationProjectionMatrix(const MatrixTypeFor& matrix) { + setUniform(_transformationProjectionMatrixUniform, matrix); + return *this; +} + template class VertexColor<2>; template class VertexColor<3>; diff --git a/src/Magnum/Shaders/VertexColor.h b/src/Magnum/Shaders/VertexColor.h index c6edeed30..7834b7985 100644 --- a/src/Magnum/Shaders/VertexColor.h +++ b/src/Magnum/Shaders/VertexColor.h @@ -31,9 +31,6 @@ #include "Magnum/DimensionTraits.h" #include "Magnum/GL/AbstractShaderProgram.h" -#include "Magnum/Math/Color.h" -#include "Magnum/Math/Matrix3.h" -#include "Magnum/Math/Matrix4.h" #include "Magnum/Shaders/Generic.h" #include "Magnum/Shaders/visibility.h" @@ -143,10 +140,7 @@ template class MAGNUM_SHADERS_EXPORT VertexColor: public * * Default is an identity matrix. */ - VertexColor& setTransformationProjectionMatrix(const MatrixTypeFor& matrix) { - setUniform(_transformationProjectionMatrixUniform, matrix); - return *this; - } + VertexColor& setTransformationProjectionMatrix(const MatrixTypeFor& matrix); private: Int _transformationProjectionMatrixUniform{0};