Browse Source

Shaders: modernize coding style.

* Always prefix private members with an underscore
 * Use in-class initialization of the uniform locations
 * Use {} for default flag value
pull/197/head
Vladimír Vondruš 9 years ago
parent
commit
d6f5f43d60
  1. 12
      src/Magnum/Shaders/DistanceFieldVector.cpp
  2. 20
      src/Magnum/Shaders/DistanceFieldVector.h
  3. 6
      src/Magnum/Shaders/Flat.cpp
  4. 11
      src/Magnum/Shaders/Flat.h
  5. 18
      src/Magnum/Shaders/MeshVisualizer.cpp
  6. 32
      src/Magnum/Shaders/MeshVisualizer.h
  7. 20
      src/Magnum/Shaders/Phong.cpp
  8. 4
      src/Magnum/Shaders/Phong.frag
  9. 39
      src/Magnum/Shaders/Phong.h
  10. 8
      src/Magnum/Shaders/Vector.cpp
  11. 12
      src/Magnum/Shaders/Vector.h
  12. 4
      src/Magnum/Shaders/VertexColor.cpp
  13. 4
      src/Magnum/Shaders/VertexColor.h

12
src/Magnum/Shaders/DistanceFieldVector.cpp

@ -41,7 +41,7 @@ namespace {
template<> constexpr const char* vertexShaderName<3>() { return "AbstractVector3D.vert"; } template<> constexpr const char* vertexShaderName<3>() { return "AbstractVector3D.vert"; }
} }
template<UnsignedInt dimensions> DistanceFieldVector<dimensions>::DistanceFieldVector(): transformationProjectionMatrixUniform(0), colorUniform(1), outlineColorUniform(2), outlineRangeUniform(3), smoothnessUniform(4) { template<UnsignedInt dimensions> DistanceFieldVector<dimensions>::DistanceFieldVector() {
#ifdef MAGNUM_BUILD_STATIC #ifdef MAGNUM_BUILD_STATIC
/* Import resources on static build, if not already */ /* Import resources on static build, if not already */
if(!Utility::Resource::hasGroup("MagnumShaders")) if(!Utility::Resource::hasGroup("MagnumShaders"))
@ -82,11 +82,11 @@ template<UnsignedInt dimensions> DistanceFieldVector<dimensions>::DistanceFieldV
if(!Context::current().isExtensionSupported<Extensions::GL::ARB::explicit_uniform_location>(version)) if(!Context::current().isExtensionSupported<Extensions::GL::ARB::explicit_uniform_location>(version))
#endif #endif
{ {
transformationProjectionMatrixUniform = AbstractShaderProgram::uniformLocation("transformationProjectionMatrix"); _transformationProjectionMatrixUniform = AbstractShaderProgram::uniformLocation("transformationProjectionMatrix");
colorUniform = AbstractShaderProgram::uniformLocation("color"); _colorUniform = AbstractShaderProgram::uniformLocation("color");
outlineColorUniform = AbstractShaderProgram::uniformLocation("outlineColor"); _outlineColorUniform = AbstractShaderProgram::uniformLocation("outlineColor");
outlineRangeUniform = AbstractShaderProgram::uniformLocation("outlineRange"); _outlineRangeUniform = AbstractShaderProgram::uniformLocation("outlineRange");
smoothnessUniform = AbstractShaderProgram::uniformLocation("smoothness"); _smoothnessUniform = AbstractShaderProgram::uniformLocation("smoothness");
} }
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES

20
src/Magnum/Shaders/DistanceFieldVector.h

@ -117,7 +117,7 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT DistanceFieldVector
* @return Reference to self (for method chaining) * @return Reference to self (for method chaining)
*/ */
DistanceFieldVector& setTransformationProjectionMatrix(const MatrixTypeFor<dimensions, Float>& matrix) { DistanceFieldVector& setTransformationProjectionMatrix(const MatrixTypeFor<dimensions, Float>& matrix) {
AbstractShaderProgram::setUniform(transformationProjectionMatrixUniform, matrix); AbstractShaderProgram::setUniform(_transformationProjectionMatrixUniform, matrix);
return *this; return *this;
} }
@ -128,7 +128,7 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT DistanceFieldVector
* @see @ref setOutlineColor() * @see @ref setOutlineColor()
*/ */
DistanceFieldVector& setColor(const Color4& color) { DistanceFieldVector& setColor(const Color4& color) {
AbstractShaderProgram::setUniform(colorUniform, color); AbstractShaderProgram::setUniform(_colorUniform, color);
return *this; return *this;
} }
@ -139,7 +139,7 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT DistanceFieldVector
* @see @ref setOutlineRange(), @ref setColor() * @see @ref setOutlineRange(), @ref setColor()
*/ */
DistanceFieldVector& setOutlineColor(const Color4& color) { DistanceFieldVector& setOutlineColor(const Color4& color) {
AbstractShaderProgram::setUniform(outlineColorUniform, color); AbstractShaderProgram::setUniform(_outlineColorUniform, color);
return *this; return *this;
} }
@ -158,7 +158,7 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT DistanceFieldVector
* @see @ref setOutlineColor() * @see @ref setOutlineColor()
*/ */
DistanceFieldVector& setOutlineRange(Float start, Float end) { DistanceFieldVector& setOutlineRange(Float start, Float end) {
AbstractShaderProgram::setUniform(outlineRangeUniform, Vector2(start, end)); AbstractShaderProgram::setUniform(_outlineRangeUniform, Vector2(start, end));
return *this; return *this;
} }
@ -171,7 +171,7 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT DistanceFieldVector
* aliased). Initial value is `0.04f`. * aliased). Initial value is `0.04f`.
*/ */
DistanceFieldVector& setSmoothness(Float value) { DistanceFieldVector& setSmoothness(Float value) {
AbstractShaderProgram::setUniform(smoothnessUniform, value); AbstractShaderProgram::setUniform(_smoothnessUniform, value);
return *this; return *this;
} }
@ -184,11 +184,11 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT DistanceFieldVector
#endif #endif
private: private:
Int transformationProjectionMatrixUniform, Int _transformationProjectionMatrixUniform{0},
colorUniform, _colorUniform{1},
outlineColorUniform, _outlineColorUniform{2},
outlineRangeUniform, _outlineRangeUniform{3},
smoothnessUniform; _smoothnessUniform{4};
}; };
/** @brief Two-dimensional distance field vector shader */ /** @brief Two-dimensional distance field vector shader */

6
src/Magnum/Shaders/Flat.cpp

@ -44,7 +44,7 @@ namespace {
template<> constexpr const char* vertexShaderName<3>() { return "Flat3D.vert"; } template<> constexpr const char* vertexShaderName<3>() { return "Flat3D.vert"; }
} }
template<UnsignedInt dimensions> Flat<dimensions>::Flat(const Flags flags): transformationProjectionMatrixUniform(0), colorUniform(1), _flags(flags) { template<UnsignedInt dimensions> Flat<dimensions>::Flat(const Flags flags): _flags(flags) {
#ifdef MAGNUM_BUILD_STATIC #ifdef MAGNUM_BUILD_STATIC
/* Import resources on static build, if not already */ /* Import resources on static build, if not already */
if(!Utility::Resource::hasGroup("MagnumShaders")) if(!Utility::Resource::hasGroup("MagnumShaders"))
@ -87,8 +87,8 @@ template<UnsignedInt dimensions> Flat<dimensions>::Flat(const Flags flags): tran
if(!Context::current().isExtensionSupported<Extensions::GL::ARB::explicit_uniform_location>(version)) if(!Context::current().isExtensionSupported<Extensions::GL::ARB::explicit_uniform_location>(version))
#endif #endif
{ {
transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"); _transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix");
colorUniform = uniformLocation("color"); _colorUniform = uniformLocation("color");
} }
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES

11
src/Magnum/Shaders/Flat.h

@ -168,7 +168,7 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT Flat: public Abstra
* @brief Constructor * @brief Constructor
* @param flags Flags * @param flags Flags
*/ */
explicit Flat(Flags flags = Flags()); explicit Flat(Flags flags = {});
/** /**
* @brief Construct without creating the underlying OpenGL object * @brief Construct without creating the underlying OpenGL object
@ -190,7 +190,7 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT Flat: public Abstra
* @return Reference to self (for method chaining) * @return Reference to self (for method chaining)
*/ */
Flat<dimensions>& setTransformationProjectionMatrix(const MatrixTypeFor<dimensions, Float>& matrix) { Flat<dimensions>& setTransformationProjectionMatrix(const MatrixTypeFor<dimensions, Float>& matrix) {
setUniform(transformationProjectionMatrixUniform, matrix); setUniform(_transformationProjectionMatrixUniform, matrix);
return *this; return *this;
} }
@ -203,7 +203,7 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT Flat: public Abstra
* @see @ref setTexture() * @see @ref setTexture()
*/ */
Flat<dimensions>& setColor(const Color4& color){ Flat<dimensions>& setColor(const Color4& color){
setUniform(colorUniform, color); setUniform(_colorUniform, color);
return *this; return *this;
} }
@ -217,10 +217,9 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT Flat: public Abstra
Flat<dimensions>& setTexture(Texture2D& texture); Flat<dimensions>& setTexture(Texture2D& texture);
private: private:
Int transformationProjectionMatrixUniform,
colorUniform;
Flags _flags; Flags _flags;
Int _transformationProjectionMatrixUniform{0},
_colorUniform{1};
}; };
/** @brief 2D flat shader */ /** @brief 2D flat shader */

18
src/Magnum/Shaders/MeshVisualizer.cpp

@ -36,7 +36,7 @@
namespace Magnum { namespace Shaders { namespace Magnum { namespace Shaders {
MeshVisualizer::MeshVisualizer(const Flags flags): flags(flags), transformationProjectionMatrixUniform(0), viewportSizeUniform(1), colorUniform(2), wireframeColorUniform(3), wireframeWidthUniform(4), smoothnessUniform(5) { MeshVisualizer::MeshVisualizer(const Flags flags): _flags{flags} {
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
if(flags & Flag::Wireframe && !(flags & Flag::NoGeometryShader)) { if(flags & Flag::Wireframe && !(flags & Flag::NoGeometryShader)) {
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
@ -47,7 +47,7 @@ MeshVisualizer::MeshVisualizer(const Flags flags): flags(flags), transformationP
#endif #endif
} }
#else #else
if(flags & Flag::Wireframe) if(_flags & Flag::Wireframe)
MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::OES::standard_derivatives); MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::OES::standard_derivatives);
#endif #endif
@ -128,21 +128,21 @@ MeshVisualizer::MeshVisualizer(const Flags flags): flags(flags), transformationP
if(!Context::current().isExtensionSupported<Extensions::GL::ARB::explicit_uniform_location>(version)) if(!Context::current().isExtensionSupported<Extensions::GL::ARB::explicit_uniform_location>(version))
#endif #endif
{ {
transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"); _transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix");
colorUniform = uniformLocation("color"); _colorUniform = uniformLocation("color");
if(flags & Flag::Wireframe) { if(flags & Flag::Wireframe) {
wireframeColorUniform = uniformLocation("wireframeColor"); _wireframeColorUniform = uniformLocation("wireframeColor");
wireframeWidthUniform = uniformLocation("wireframeWidth"); _wireframeWidthUniform = uniformLocation("wireframeWidth");
smoothnessUniform = uniformLocation("smoothness"); _smoothnessUniform = uniformLocation("smoothness");
if(!(flags & Flag::NoGeometryShader)) if(!(flags & Flag::NoGeometryShader))
viewportSizeUniform = uniformLocation("viewportSize"); _viewportSizeUniform = uniformLocation("viewportSize");
} }
} }
/* Set defaults in OpenGL ES (for desktop they are set in shader code itself) */ /* Set defaults in OpenGL ES (for desktop they are set in shader code itself) */
#ifdef MAGNUM_TARGET_GLES #ifdef MAGNUM_TARGET_GLES
setColor(Color3(1.0f)); setColor(Color3(1.0f));
if(flags & Flag::Wireframe) { if(_flags & Flag::Wireframe) {
setWireframeColor(Color3(0.0f)); setWireframeColor(Color3(0.0f));
setWireframeWidth(1.0f); setWireframeWidth(1.0f);
setSmoothness(2.0f); setSmoothness(2.0f);

32
src/Magnum/Shaders/MeshVisualizer.h

@ -204,7 +204,7 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizer: public AbstractShaderProgram {
* @brief Constructor * @brief Constructor
* @param flags Flags * @param flags Flags
*/ */
explicit MeshVisualizer(Flags flags = Flags()); explicit MeshVisualizer(Flags flags = {});
/** /**
* @brief Construct without creating the underlying OpenGL object * @brief Construct without creating the underlying OpenGL object
@ -223,7 +223,7 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizer: public AbstractShaderProgram {
* @return Reference to self (for method chaining) * @return Reference to self (for method chaining)
*/ */
MeshVisualizer& setTransformationProjectionMatrix(const Matrix4& matrix) { MeshVisualizer& setTransformationProjectionMatrix(const Matrix4& matrix) {
setUniform(transformationProjectionMatrixUniform, matrix); setUniform(_transformationProjectionMatrixUniform, matrix);
return *this; return *this;
} }
@ -235,8 +235,8 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizer: public AbstractShaderProgram {
* shaders are used. * shaders are used.
*/ */
MeshVisualizer& setViewportSize(const Vector2& size) { MeshVisualizer& setViewportSize(const Vector2& size) {
if(flags & Flag::Wireframe && !(flags & Flag::NoGeometryShader)) if(_flags & Flag::Wireframe && !(_flags & Flag::NoGeometryShader))
setUniform(viewportSizeUniform, size); setUniform(_viewportSizeUniform, size);
return *this; return *this;
} }
@ -247,7 +247,7 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizer: public AbstractShaderProgram {
* Initial value is fully opaque white. * Initial value is fully opaque white.
*/ */
MeshVisualizer& setColor(const Color4& color) { MeshVisualizer& setColor(const Color4& color) {
setUniform(colorUniform, color); setUniform(_colorUniform, color);
return *this; return *this;
} }
@ -259,7 +259,7 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizer: public AbstractShaderProgram {
* @ref Flag::Wireframe is enabled. * @ref Flag::Wireframe is enabled.
*/ */
MeshVisualizer& setWireframeColor(const Color4& color) { MeshVisualizer& setWireframeColor(const Color4& color) {
if(flags & Flag::Wireframe) setUniform(wireframeColorUniform, color); if(_flags & Flag::Wireframe) setUniform(_wireframeColorUniform, color);
return *this; return *this;
} }
@ -271,7 +271,7 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizer: public AbstractShaderProgram {
* enabled. * enabled.
*/ */
MeshVisualizer& setWireframeWidth(Float width) { MeshVisualizer& setWireframeWidth(Float width) {
if(flags & Flag::Wireframe) setUniform(wireframeWidthUniform, width); if(_flags & Flag::Wireframe) setUniform(_wireframeWidthUniform, width);
return *this; return *this;
} }
@ -285,20 +285,20 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizer: public AbstractShaderProgram {
MeshVisualizer& setSmoothness(Float smoothness); MeshVisualizer& setSmoothness(Float smoothness);
private: private:
Flags flags; Flags _flags;
Int transformationProjectionMatrixUniform, Int _transformationProjectionMatrixUniform{0},
viewportSizeUniform, _viewportSizeUniform{1},
colorUniform, _colorUniform{2},
wireframeColorUniform, _wireframeColorUniform{3},
wireframeWidthUniform, _wireframeWidthUniform{4},
smoothnessUniform; _smoothnessUniform{5};
}; };
CORRADE_ENUMSET_OPERATORS(MeshVisualizer::Flags) CORRADE_ENUMSET_OPERATORS(MeshVisualizer::Flags)
inline MeshVisualizer& MeshVisualizer::setSmoothness(Float smoothness) { inline MeshVisualizer& MeshVisualizer::setSmoothness(Float smoothness) {
if(flags & Flag::Wireframe) if(_flags & Flag::Wireframe)
setUniform(smoothnessUniform, smoothness); setUniform(_smoothnessUniform, smoothness);
return *this; return *this;
} }

20
src/Magnum/Shaders/Phong.cpp

@ -44,7 +44,7 @@ namespace {
}; };
} }
Phong::Phong(const Flags flags): transformationMatrixUniform(0), projectionMatrixUniform(1), normalMatrixUniform(2), lightUniform(3), diffuseColorUniform(4), ambientColorUniform(5), specularColorUniform(6), lightColorUniform(7), shininessUniform(8), _flags(flags) { Phong::Phong(const Flags flags): _flags(flags) {
#ifdef MAGNUM_BUILD_STATIC #ifdef MAGNUM_BUILD_STATIC
/* Import resources on static build, if not already */ /* Import resources on static build, if not already */
if(!Utility::Resource::hasGroup("MagnumShaders")) if(!Utility::Resource::hasGroup("MagnumShaders"))
@ -90,15 +90,15 @@ Phong::Phong(const Flags flags): transformationMatrixUniform(0), projectionMatri
if(!Context::current().isExtensionSupported<Extensions::GL::ARB::explicit_uniform_location>(version)) if(!Context::current().isExtensionSupported<Extensions::GL::ARB::explicit_uniform_location>(version))
#endif #endif
{ {
transformationMatrixUniform = uniformLocation("transformationMatrix"); _transformationMatrixUniform = uniformLocation("transformationMatrix");
projectionMatrixUniform = uniformLocation("projectionMatrix"); _projectionMatrixUniform = uniformLocation("projectionMatrix");
normalMatrixUniform = uniformLocation("normalMatrix"); _normalMatrixUniform = uniformLocation("normalMatrix");
lightUniform = uniformLocation("light"); _lightUniform = uniformLocation("light");
ambientColorUniform = uniformLocation("ambientColor"); _ambientColorUniform = uniformLocation("ambientColor");
diffuseColorUniform = uniformLocation("diffuseColor"); _diffuseColorUniform = uniformLocation("diffuseColor");
specularColorUniform = uniformLocation("specularColor"); _specularColorUniform = uniformLocation("specularColor");
lightColorUniform = uniformLocation("lightColor"); _lightColorUniform = uniformLocation("lightColor");
shininessUniform = uniformLocation("shininess"); _shininessUniform = uniformLocation("shininess");
} }
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES

4
src/Magnum/Shaders/Phong.frag

@ -59,7 +59,7 @@ uniform lowp sampler2D ambientTexture;
#endif #endif
#ifdef EXPLICIT_UNIFORM_LOCATION #ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 5) layout(location = 4)
#endif #endif
uniform lowp vec4 ambientColor uniform lowp vec4 ambientColor
#ifndef GL_ES #ifndef GL_ES
@ -79,7 +79,7 @@ uniform lowp sampler2D diffuseTexture;
#endif #endif
#ifdef EXPLICIT_UNIFORM_LOCATION #ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 4) layout(location = 5)
#endif #endif
uniform lowp vec4 diffuseColor uniform lowp vec4 diffuseColor
#if !defined(GL_ES) && defined(DIFFUSE_TEXTURE) #if !defined(GL_ES) && defined(DIFFUSE_TEXTURE)

39
src/Magnum/Shaders/Phong.h

@ -194,7 +194,7 @@ class MAGNUM_SHADERS_EXPORT Phong: public AbstractShaderProgram {
* @brief Constructor * @brief Constructor
* @param flags Flags * @param flags Flags
*/ */
explicit Phong(Flags flags = Flags()); explicit Phong(Flags flags = {});
/** /**
* @brief Construct without creating the underlying OpenGL object * @brief Construct without creating the underlying OpenGL object
@ -221,7 +221,7 @@ class MAGNUM_SHADERS_EXPORT Phong: public AbstractShaderProgram {
* @see @ref setAmbientTexture() * @see @ref setAmbientTexture()
*/ */
Phong& setAmbientColor(const Color4& color) { Phong& setAmbientColor(const Color4& color) {
setUniform(ambientColorUniform, color); setUniform(_ambientColorUniform, color);
return *this; return *this;
} }
@ -244,7 +244,7 @@ class MAGNUM_SHADERS_EXPORT Phong: public AbstractShaderProgram {
* @see @ref setDiffuseTexture() * @see @ref setDiffuseTexture()
*/ */
Phong& setDiffuseColor(const Color4& color) { Phong& setDiffuseColor(const Color4& color) {
setUniform(diffuseColorUniform, color); setUniform(_diffuseColorUniform, color);
return *this; return *this;
} }
@ -267,7 +267,7 @@ class MAGNUM_SHADERS_EXPORT Phong: public AbstractShaderProgram {
* @see @ref setSpecularTexture() * @see @ref setSpecularTexture()
*/ */
Phong& setSpecularColor(const Color4& color) { Phong& setSpecularColor(const Color4& color) {
setUniform(specularColorUniform, color); setUniform(_specularColorUniform, color);
return *this; return *this;
} }
@ -300,7 +300,7 @@ class MAGNUM_SHADERS_EXPORT Phong: public AbstractShaderProgram {
* If not set, default value is `80.0f`. * If not set, default value is `80.0f`.
*/ */
Phong& setShininess(Float shininess) { Phong& setShininess(Float shininess) {
setUniform(shininessUniform, shininess); setUniform(_shininessUniform, shininess);
return *this; return *this;
} }
@ -309,7 +309,7 @@ class MAGNUM_SHADERS_EXPORT Phong: public AbstractShaderProgram {
* @return Reference to self (for method chaining) * @return Reference to self (for method chaining)
*/ */
Phong& setTransformationMatrix(const Matrix4& matrix) { Phong& setTransformationMatrix(const Matrix4& matrix) {
setUniform(transformationMatrixUniform, matrix); setUniform(_transformationMatrixUniform, matrix);
return *this; return *this;
} }
@ -321,7 +321,7 @@ class MAGNUM_SHADERS_EXPORT Phong: public AbstractShaderProgram {
* must be done in the shader anyway. * must be done in the shader anyway.
*/ */
Phong& setNormalMatrix(const Matrix3x3& matrix) { Phong& setNormalMatrix(const Matrix3x3& matrix) {
setUniform(normalMatrixUniform, matrix); setUniform(_normalMatrixUniform, matrix);
return *this; return *this;
} }
@ -330,7 +330,7 @@ class MAGNUM_SHADERS_EXPORT Phong: public AbstractShaderProgram {
* @return Reference to self (for method chaining) * @return Reference to self (for method chaining)
*/ */
Phong& setProjectionMatrix(const Matrix4& matrix) { Phong& setProjectionMatrix(const Matrix4& matrix) {
setUniform(projectionMatrixUniform, matrix); setUniform(_projectionMatrixUniform, matrix);
return *this; return *this;
} }
@ -339,7 +339,7 @@ class MAGNUM_SHADERS_EXPORT Phong: public AbstractShaderProgram {
* @return Reference to self (for method chaining) * @return Reference to self (for method chaining)
*/ */
Phong& setLightPosition(const Vector3& light) { Phong& setLightPosition(const Vector3& light) {
setUniform(lightUniform, light); setUniform(_lightUniform, light);
return *this; return *this;
} }
@ -350,22 +350,21 @@ class MAGNUM_SHADERS_EXPORT Phong: public AbstractShaderProgram {
* If not set, default value is `{1.0f, 1.0f, 1.0f, 1.0f}`. * If not set, default value is `{1.0f, 1.0f, 1.0f, 1.0f}`.
*/ */
Phong& setLightColor(const Color4& color) { Phong& setLightColor(const Color4& color) {
setUniform(lightColorUniform, color); setUniform(_lightColorUniform, color);
return *this; return *this;
} }
private: private:
Int transformationMatrixUniform,
projectionMatrixUniform,
normalMatrixUniform,
lightUniform,
diffuseColorUniform,
ambientColorUniform,
specularColorUniform,
lightColorUniform,
shininessUniform;
Flags _flags; Flags _flags;
Int _transformationMatrixUniform{0},
_projectionMatrixUniform{1},
_normalMatrixUniform{2},
_lightUniform{3},
_ambientColorUniform{4},
_diffuseColorUniform{5},
_specularColorUniform{6},
_lightColorUniform{7},
_shininessUniform{8};
}; };
CORRADE_ENUMSET_OPERATORS(Phong::Flags) CORRADE_ENUMSET_OPERATORS(Phong::Flags)

8
src/Magnum/Shaders/Vector.cpp

@ -41,7 +41,7 @@ namespace {
template<> constexpr const char* vertexShaderName<3>() { return "AbstractVector3D.vert"; } template<> constexpr const char* vertexShaderName<3>() { return "AbstractVector3D.vert"; }
} }
template<UnsignedInt dimensions> Vector<dimensions>::Vector(): transformationProjectionMatrixUniform(0), backgroundColorUniform(1), colorUniform(2) { template<UnsignedInt dimensions> Vector<dimensions>::Vector() {
#ifdef MAGNUM_BUILD_STATIC #ifdef MAGNUM_BUILD_STATIC
/* Import resources on static build, if not already */ /* Import resources on static build, if not already */
if(!Utility::Resource::hasGroup("MagnumShaders")) if(!Utility::Resource::hasGroup("MagnumShaders"))
@ -82,9 +82,9 @@ template<UnsignedInt dimensions> Vector<dimensions>::Vector(): transformationPro
if(!Context::current().isExtensionSupported<Extensions::GL::ARB::explicit_uniform_location>(version)) if(!Context::current().isExtensionSupported<Extensions::GL::ARB::explicit_uniform_location>(version))
#endif #endif
{ {
transformationProjectionMatrixUniform = AbstractShaderProgram::uniformLocation("transformationProjectionMatrix"); _transformationProjectionMatrixUniform = AbstractShaderProgram::uniformLocation("transformationProjectionMatrix");
backgroundColorUniform = AbstractShaderProgram::uniformLocation("backgroundColor"); _backgroundColorUniform = AbstractShaderProgram::uniformLocation("backgroundColor");
colorUniform = AbstractShaderProgram::uniformLocation("color"); _colorUniform = AbstractShaderProgram::uniformLocation("color");
} }
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES

12
src/Magnum/Shaders/Vector.h

@ -111,7 +111,7 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT Vector: public Abst
* @return Reference to self (for method chaining) * @return Reference to self (for method chaining)
*/ */
Vector& setTransformationProjectionMatrix(const MatrixTypeFor<dimensions, Float>& matrix) { Vector& setTransformationProjectionMatrix(const MatrixTypeFor<dimensions, Float>& matrix) {
AbstractShaderProgram::setUniform(transformationProjectionMatrixUniform, matrix); AbstractShaderProgram::setUniform(_transformationProjectionMatrixUniform, matrix);
return *this; return *this;
} }
@ -123,7 +123,7 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT Vector: public Abst
* @see @ref setColor() * @see @ref setColor()
*/ */
Vector& setBackgroundColor(const Color4& color) { Vector& setBackgroundColor(const Color4& color) {
AbstractShaderProgram::setUniform(backgroundColorUniform, color); AbstractShaderProgram::setUniform(_backgroundColorUniform, color);
return *this; return *this;
} }
@ -134,7 +134,7 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT Vector: public Abst
* @see @ref setBackgroundColor() * @see @ref setBackgroundColor()
*/ */
Vector& setColor(const Color4& color) { Vector& setColor(const Color4& color) {
AbstractShaderProgram::setUniform(colorUniform, color); AbstractShaderProgram::setUniform(_colorUniform, color);
return *this; return *this;
} }
@ -147,9 +147,9 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT Vector: public Abst
#endif #endif
private: private:
Int transformationProjectionMatrixUniform, Int _transformationProjectionMatrixUniform{0},
backgroundColorUniform, _backgroundColorUniform{1},
colorUniform; _colorUniform{2};
}; };
/** @brief Two-dimensional vector shader */ /** @brief Two-dimensional vector shader */

4
src/Magnum/Shaders/VertexColor.cpp

@ -41,7 +41,7 @@ namespace {
template<> constexpr const char* vertexShaderName<3>() { return "VertexColor3D.vert"; } template<> constexpr const char* vertexShaderName<3>() { return "VertexColor3D.vert"; }
} }
template<UnsignedInt dimensions> VertexColor<dimensions>::VertexColor(): transformationProjectionMatrixUniform(0) { template<UnsignedInt dimensions> VertexColor<dimensions>::VertexColor() {
#ifdef MAGNUM_BUILD_STATIC #ifdef MAGNUM_BUILD_STATIC
/* Import resources on static build, if not already */ /* Import resources on static build, if not already */
if(!Utility::Resource::hasGroup("MagnumShaders")) if(!Utility::Resource::hasGroup("MagnumShaders"))
@ -82,7 +82,7 @@ template<UnsignedInt dimensions> VertexColor<dimensions>::VertexColor(): transfo
if(!Context::current().isExtensionSupported<Extensions::GL::ARB::explicit_uniform_location>(version)) if(!Context::current().isExtensionSupported<Extensions::GL::ARB::explicit_uniform_location>(version))
#endif #endif
{ {
transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"); _transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix");
} }
/* Set defaults in OpenGL ES (for desktop they are set in shader code itself) */ /* Set defaults in OpenGL ES (for desktop they are set in shader code itself) */

4
src/Magnum/Shaders/VertexColor.h

@ -124,12 +124,12 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT VertexColor: public
* Default is identity matrix. * Default is identity matrix.
*/ */
VertexColor<dimensions>& setTransformationProjectionMatrix(const MatrixTypeFor<dimensions, Float>& matrix) { VertexColor<dimensions>& setTransformationProjectionMatrix(const MatrixTypeFor<dimensions, Float>& matrix) {
setUniform(transformationProjectionMatrixUniform, matrix); setUniform(_transformationProjectionMatrixUniform, matrix);
return *this; return *this;
} }
private: private:
Int transformationProjectionMatrixUniform; Int _transformationProjectionMatrixUniform{0};
}; };
/** @brief 2D vertex color shader */ /** @brief 2D vertex color shader */

Loading…
Cancel
Save