From a7f5bef038a9bf4b042955ff9e6c7d0450e8d25f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 3 Jul 2013 15:04:15 +0200 Subject: [PATCH] Getting rid of <>, part 1: Color classes. Inspired in STL, base templated class is renamed to BasicColor{3,4} and typedef'd with Float type to Color{3, 4}. It is much nicer to write this: Color3(1.0f) Color3::fromHSV(25.0_degf, 0.5f, 0.9f); instead of this: Color3<>(1.0f); Color3<>::fromHSV(25.0_degf, 0.5f, 0.9f); --- src/AbstractShaderProgram.h | 4 +- src/AbstractTexture.h | 2 +- src/Color.h | 138 +++++++++++++++--------------- src/CubeMapTexture.h | 2 +- src/CubeMapTextureArray.h | 2 +- src/DebugTools/ForceRenderer.h | 8 +- src/DebugTools/ObjectRenderer.cpp | 8 +- src/DebugTools/ShapeRenderer.h | 6 +- src/Magnum.h | 6 +- src/Mesh.h | 2 +- src/MeshTools/Interleave.h | 2 +- src/Renderer.cpp | 4 +- src/Renderer.h | 4 +- src/Shaders/DistanceFieldVector.h | 4 +- src/Shaders/Flat.h | 2 +- src/Shaders/MeshVisualizer.cpp | 4 +- src/Shaders/MeshVisualizer.h | 4 +- src/Shaders/Phong.h | 8 +- src/Shaders/Vector.h | 2 +- src/Shaders/VertexColor.h | 2 +- src/Swizzle.h | 8 +- src/Test/ColorTest.cpp | 94 ++++++++++---------- src/Test/SwizzleTest.cpp | 12 +-- src/Texture.h | 2 +- 24 files changed, 166 insertions(+), 164 deletions(-) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 9a1b61679..214f0df94 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -1392,8 +1392,8 @@ template struct Attribute>: Doubl template struct Attribute>: Attribute> {}; template struct Attribute>: Attribute> {}; template struct Attribute>: Attribute> {}; -template struct Attribute>: Attribute> {}; -template struct Attribute>: Attribute> {}; +template struct Attribute>: Attribute> {}; +template struct Attribute>: Attribute> {}; /* Common float and double rectangular matrix attributes */ template struct Attribute>: FloatAttribute, SizedAttribute {}; diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index 0cf278646..e4b13f069 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -203,7 +203,7 @@ class MAGNUM_EXPORT AbstractTexture { * with @def_gl{TEXTURE_BORDER_COLOR} * @requires_es_extension %Extension @es_extension{NV,texture_border_clamp} */ - AbstractTexture* setBorderColor(const Color4<>& color) { + AbstractTexture* setBorderColor(const Color4& color) { #ifndef MAGNUM_TARGET_GLES (this->*parameterfvImplementation)(GL_TEXTURE_BORDER_COLOR, color.data()); #else diff --git a/src/Color.h b/src/Color.h index e38290eec..410990944 100644 --- a/src/Color.h +++ b/src/Color.h @@ -25,7 +25,7 @@ */ /** @file - * @brief Class Magnum::Color3, Magnum::Color4 + * @brief Class Magnum::BasicColor3, Magnum::BasicColor4, typedef Magnum::Color3, Magnum::Color4 */ #include @@ -39,7 +39,7 @@ namespace Magnum { namespace Implementation { /* Convert color from HSV */ -template typename std::enable_if::value, Color3>::type fromHSV(typename Color3::HSV hsv) { +template typename std::enable_if::value, BasicColor3>::type fromHSV(typename BasicColor3::HSV hsv) { Math::Deg hue; T saturation, value; std::tie(hue, saturation, value) = hsv; @@ -65,12 +65,12 @@ template typename std::enable_if::value, Colo default: CORRADE_ASSERT_UNREACHABLE(); } } -template inline typename std::enable_if::value, Color3>::type fromHSV(typename Color3::HSV hsv) { - return Math::denormalize>(fromHSV::FloatingPointType>(hsv)); +template inline typename std::enable_if::value, BasicColor3>::type fromHSV(typename BasicColor3::HSV hsv) { + return Math::denormalize>(fromHSV::FloatingPointType>(hsv)); } /* Internal hue computing function */ -template Math::Deg hue(const Color3& color, T max, T delta) { +template Math::Deg hue(const BasicColor3& color, T max, T delta) { T deltaInv60 = T(60)/delta; T hue(0); @@ -87,40 +87,40 @@ template Math::Deg hue(const Color3& color, T max, T delta) { } /* Hue, saturation, value for floating-point types */ -template inline Math::Deg hue(typename std::enable_if::value, const Color3&>::type color) { +template inline Math::Deg hue(typename std::enable_if::value, const BasicColor3&>::type color) { T max = color.max(); T delta = max - color.min(); return hue(color, max, delta); } -template inline T saturation(typename std::enable_if::value, const Color3&>::type color) { +template inline T saturation(typename std::enable_if::value, const BasicColor3&>::type color) { T max = color.max(); T delta = max - color.min(); return max != T(0) ? delta/max : T(0); } -template inline T value(typename std::enable_if::value, const Color3&>::type color) { +template inline T value(typename std::enable_if::value, const BasicColor3&>::type color) { return color.max(); } /* Hue, saturation, value for integral types */ -template inline Math::Deg::FloatingPointType> hue(typename std::enable_if::value, const Color3&>::type color) { - return hue::FloatingPointType>(Math::normalize::FloatingPointType>>(color)); +template inline Math::Deg::FloatingPointType> hue(typename std::enable_if::value, const BasicColor3&>::type color) { + return hue::FloatingPointType>(Math::normalize::FloatingPointType>>(color)); } -template inline typename Color3::FloatingPointType saturation(typename std::enable_if::value, const Color3&>::type& color) { - return saturation::FloatingPointType>(Math::normalize::FloatingPointType>>(color)); +template inline typename BasicColor3::FloatingPointType saturation(typename std::enable_if::value, const BasicColor3&>::type& color) { + return saturation::FloatingPointType>(Math::normalize::FloatingPointType>>(color)); } -template inline typename Color3::FloatingPointType value(typename std::enable_if::value, const Color3&>::type color) { - return Math::normalize::FloatingPointType>(color.max()); +template inline typename BasicColor3::FloatingPointType value(typename std::enable_if::value, const BasicColor3&>::type color) { + return Math::normalize::FloatingPointType>(color.max()); } /* Convert color to HSV */ -template inline typename Color3::HSV toHSV(typename std::enable_if::value, const Color3&>::type color) { +template inline typename BasicColor3::HSV toHSV(typename std::enable_if::value, const BasicColor3&>::type color) { T max = color.max(); T delta = max - color.min(); - return typename Color3::HSV(hue::FloatingPointType>(color, max, delta), max != T(0) ? delta/max : T(0), max); + return typename BasicColor3::HSV(hue::FloatingPointType>(color, max, delta), max != T(0) ? delta/max : T(0), max); } -template inline typename Color3::HSV toHSV(typename std::enable_if::value, const Color3&>::type color) { - return toHSV::FloatingPointType>(Math::normalize::FloatingPointType>>(color)); +template inline typename BasicColor3::HSV toHSV(typename std::enable_if::value, const BasicColor3&>::type color) { + return toHSV::FloatingPointType>(Math::normalize::FloatingPointType>>(color)); } /* Default alpha value */ @@ -144,16 +144,11 @@ Conversion from and to HSV is done always using floating-point types, so hue is always in range in range @f$ [0.0, 360.0] @f$, saturation and value in range @f$ [0.0, 1.0] @f$. -@see Color4 +@see @ref Color3, @ref BasicColor4 */ /* Not using template specialization because some internal functions are impossible to explicitly instantiate */ -#ifndef DOXYGEN_GENERATING_OUTPUT -template -#else -template -#endif -class Color3: public Math::Vector3 { +template class BasicColor3: public Math::Vector3 { public: /** @brief Corresponding floating-point type for HSV computation */ typedef typename Math::TypeTraits::FloatingPointType FloatingPointType; @@ -172,11 +167,11 @@ class Color3: public Math::Vector3 { * * Hue can overflow the range @f$ [0.0, 360.0] @f$. */ - constexpr static Color3 fromHSV(HSV hsv) { + constexpr static BasicColor3 fromHSV(HSV hsv) { return Implementation::fromHSV(hsv); } /** @overload */ - constexpr static Color3 fromHSV(Math::Deg hue, FloatingPointType saturation, FloatingPointType value) { + constexpr static BasicColor3 fromHSV(Math::Deg hue, FloatingPointType saturation, FloatingPointType value) { return fromHSV(std::make_tuple(hue, saturation, value)); } @@ -185,13 +180,13 @@ class Color3: public Math::Vector3 { * * All components are set to zero. */ - constexpr /*implicit*/ Color3() {} + constexpr /*implicit*/ BasicColor3() {} /** * @brief Gray constructor * @param rgb RGB value */ - constexpr explicit Color3(T rgb): Math::Vector3(rgb) {} + constexpr explicit BasicColor3(T rgb): Math::Vector3(rgb) {} /** * @brief Constructor @@ -199,13 +194,13 @@ class Color3: public Math::Vector3 { * @param g G value * @param b B value */ - constexpr /*implicit*/ Color3(T r, T g, T b): Math::Vector3(r, g, b) {} + constexpr /*implicit*/ BasicColor3(T r, T g, T b): Math::Vector3(r, g, b) {} /** @copydoc Math::Vector::Vector(const Vector&) */ - template constexpr explicit Color3(const Math::Vector<3, U>& other): Math::Vector3(other) {} + template constexpr explicit BasicColor3(const Math::Vector<3, U>& other): Math::Vector3(other) {} /** @brief Copy constructor */ - constexpr Color3(const Math::Vector<3, T>& other): Math::Vector3(other) {} + constexpr BasicColor3(const Math::Vector<3, T>& other): Math::Vector3(other) {} T& r() { return Math::Vector3::x(); } /**< @brief R component */ constexpr T r() const { return Math::Vector3::x(); } /**< @overload */ @@ -259,15 +254,19 @@ class Color3: public Math::Vector3 { return Implementation::value(*this); } - MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(Color3, 3) + MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(BasicColor3, 3) }; -MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Color3, 3) +/** @brief Three-component (RGB) float color */ +typedef BasicColor3 Color3; + +MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(BasicColor3, 3) /** @brief Four-component (RGBA) color -See Color3 for more information. +See @ref BasicColor3 for more information. +@see @ref Color4 */ /* Not using template specialization because some internal functions are impossible to explicitly instantiate */ @@ -276,24 +275,24 @@ template #else template #endif -class Color4: public Math::Vector4 { +class BasicColor4: public Math::Vector4 { public: - /** @copydoc Color3::FloatingPointType */ - typedef typename Color3::FloatingPointType FloatingPointType; + /** @copydoc BasicColor3::FloatingPointType */ + typedef typename BasicColor3::FloatingPointType FloatingPointType; - /** @copydoc Color3::HSV */ - typedef typename Color3::HSV HSV; + /** @copydoc BasicColor3::HSV */ + typedef typename BasicColor3::HSV HSV; /** - * @copydoc Color3::fromHSV() + * @copydoc BasicColor3::fromHSV() * @param a Alpha value, defaults to 1.0 for floating-point types * and maximum positive value for integral types. */ - constexpr static Color4 fromHSV(HSV hsv, T a = Implementation::defaultAlpha()) { - return Color4(Implementation::fromHSV(hsv), a); + constexpr static BasicColor4 fromHSV(HSV hsv, T a = Implementation::defaultAlpha()) { + return BasicColor4(Implementation::fromHSV(hsv), a); } /** @overload */ - constexpr static Color4 fromHSV(Math::Deg hue, FloatingPointType saturation, FloatingPointType value, T alpha) { + constexpr static BasicColor4 fromHSV(Math::Deg hue, FloatingPointType saturation, FloatingPointType value, T alpha) { return fromHSV(std::make_tuple(hue, saturation, value), alpha); } @@ -303,14 +302,14 @@ class Color4: public Math::Vector4 { * RGB components are set to zero, A component is set to 1.0 for * floating-point types and maximum positive value for integral types. */ - constexpr /*implicit*/ Color4(): Math::Vector4(T(0), T(0), T(0), Implementation::defaultAlpha()) {} + constexpr /*implicit*/ BasicColor4(): Math::Vector4(T(0), T(0), T(0), Implementation::defaultAlpha()) {} /** - * @copydoc Color3::Color3(T) + * @copydoc BasicColor3::BasicColor3(T) * @param alpha Alpha value, defaults to 1.0 for floating-point types * and maximum positive value for integral types. */ - constexpr explicit Color4(T rgb, T alpha = Implementation::defaultAlpha()): Math::Vector4(rgb, rgb, rgb, alpha) {} + constexpr explicit BasicColor4(T rgb, T alpha = Implementation::defaultAlpha()): Math::Vector4(rgb, rgb, rgb, alpha) {} /** * @brief Constructor @@ -320,22 +319,22 @@ class Color4: public Math::Vector4 { * @param a A value, defaults to 1.0 for floating-point types and * maximum positive value for integral types. */ - constexpr /*implicit*/ Color4(T r, T g, T b, T a = Implementation::defaultAlpha()): Math::Vector4(r, g, b, a) {} + constexpr /*implicit*/ BasicColor4(T r, T g, T b, T a = Implementation::defaultAlpha()): Math::Vector4(r, g, b, a) {} /** * @brief Constructor * @param rgb Three-component color * @param a A value */ - /* Not marked as explicit, because conversion from Color3 to Color4 + /* Not marked as explicit, because conversion from BasicColor3 to BasicColor4 is fairly common, nearly always with A set to 1 */ - constexpr /*implicit*/ Color4(const Math::Vector3& rgb, T a = Implementation::defaultAlpha()): Math::Vector4(rgb[0], rgb[1], rgb[2], a) {} + constexpr /*implicit*/ BasicColor4(const Math::Vector3& rgb, T a = Implementation::defaultAlpha()): Math::Vector4(rgb[0], rgb[1], rgb[2], a) {} /** @copydoc Math::Vector::Vector(const Vector&) */ - template constexpr explicit Color4(const Math::Vector<4, U>& other): Math::Vector4(other) {} + template constexpr explicit BasicColor4(const Math::Vector<4, U>& other): Math::Vector4(other) {} /** @brief Copy constructor */ - constexpr Color4(const Math::Vector<4, T>& other): Math::Vector4(other) {} + constexpr BasicColor4(const Math::Vector<4, T>& other): Math::Vector4(other) {} T& r() { return Math::Vector4::x(); } /**< @brief R component */ constexpr T r() const { return Math::Vector4::x(); } /**< @overload */ @@ -352,52 +351,55 @@ class Color4: public Math::Vector4 { * * @see swizzle() */ - Color3& rgb() { return Color3::from(Math::Vector4::data()); } - constexpr Color3 rgb() const { return Color3::from(Math::Vector4::data()); } /**< @overload */ + BasicColor3& rgb() { return BasicColor3::from(Math::Vector4::data()); } + constexpr BasicColor3 rgb() const { return BasicColor3::from(Math::Vector4::data()); } /**< @overload */ - /** @copydoc Color3::toHSV() */ + /** @copydoc BasicColor3::toHSV() */ constexpr HSV toHSV() const { return Implementation::toHSV(rgb()); } - /** @copydoc Color3::hue() */ + /** @copydoc BasicColor3::hue() */ constexpr Math::Deg hue() const { return Implementation::hue(rgb()); } - /** @copydoc Color3::saturation() */ + /** @copydoc BasicColor3::saturation() */ constexpr FloatingPointType saturation() const { return Implementation::saturation(rgb()); } - /** @copydoc Color3::value() */ + /** @copydoc BasicColor3::value() */ constexpr FloatingPointType value() const { return Implementation::value(rgb()); } - MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(Color4, 4) + MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(BasicColor4, 4) }; -MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Color4, 4) +/** @brief Four-component (RGBA) float color */ +typedef BasicColor4 Color4; + +MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(BasicColor4, 4) -/** @debugoperator{Magnum::Color3} */ -template inline Debug operator<<(Debug debug, const Color3& value) { +/** @debugoperator{Magnum::BasicColor3} */ +template inline Debug operator<<(Debug debug, const BasicColor3& value) { return debug << static_cast&>(value); } -/** @debugoperator{Magnum::Color4} */ -template inline Debug operator<<(Debug debug, const Color4& value) { +/** @debugoperator{Magnum::BasicColor4} */ +template inline Debug operator<<(Debug debug, const BasicColor4& value) { return debug << static_cast&>(value); } } namespace Corrade { namespace Utility { - /** @configurationvalue{Magnum::Color3} */ - template struct ConfigurationValue>: public ConfigurationValue> {}; + /** @configurationvalue{Magnum::BasicColor3} */ + template struct ConfigurationValue>: public ConfigurationValue> {}; - /** @configurationvalue{Magnum::Color4} */ - template struct ConfigurationValue>: public ConfigurationValue> {}; + /** @configurationvalue{Magnum::BasicColor4} */ + template struct ConfigurationValue>: public ConfigurationValue> {}; }} #endif diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index 2308568f2..7d93fbb4a 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -233,7 +233,7 @@ class CubeMapTexture: public AbstractTexture { return this; } #ifndef MAGNUM_TARGET_GLES3 - CubeMapTexture* setBorderColor(const Color4<>& color) { + CubeMapTexture* setBorderColor(const Color4& color) { AbstractTexture::setBorderColor(color); return this; } diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h index 7219706c8..617e3066d 100644 --- a/src/CubeMapTextureArray.h +++ b/src/CubeMapTextureArray.h @@ -243,7 +243,7 @@ class CubeMapTextureArray: public AbstractTexture { return this; } #ifndef MAGNUM_TARGET_GLES3 - CubeMapTextureArray* setBorderColor(const Color4<>& color) { + CubeMapTextureArray* setBorderColor(const Color4& color) { AbstractTexture::setBorderColor(color); return this; } diff --git a/src/DebugTools/ForceRenderer.h b/src/DebugTools/ForceRenderer.h index f0af13d9b..fdc32978b 100644 --- a/src/DebugTools/ForceRenderer.h +++ b/src/DebugTools/ForceRenderer.h @@ -47,7 +47,7 @@ class ForceRendererOptions { constexpr ForceRendererOptions(): _color(1.0f), _size(1.0f) {} /** @brief Color of rendered arrow */ - constexpr Color4<> color() const { return _color; } + constexpr Color4 color() const { return _color; } /** * @brief Set color of rendered arrow @@ -55,7 +55,7 @@ class ForceRendererOptions { * * Default is 100% opaque white. */ - ForceRendererOptions* setColor(const Color4<>& color) { + ForceRendererOptions* setColor(const Color4& color) { _color = color; return this; } @@ -75,7 +75,7 @@ class ForceRendererOptions { } private: - Color4<> _color; + Color4 _color; Float _size; }; @@ -91,7 +91,7 @@ Example code: @code // Create some options DebugTools::ResourceManager::instance()->set("my", (new DebugTools::ForceRendererOptions) - ->setScale(5.0f)->setColor(Color3<>::fromHSV(120.0_degf, 1.0f, 0.7f))); + ->setScale(5.0f)->setColor(Color3::fromHSV(120.0_degf, 1.0f, 0.7f))); // Create debug renderer for given object, use "my" options for it Object3D* object; diff --git a/src/DebugTools/ObjectRenderer.cpp b/src/DebugTools/ObjectRenderer.cpp index ed5cc13ab..e81064260 100644 --- a/src/DebugTools/ObjectRenderer.cpp +++ b/src/DebugTools/ObjectRenderer.cpp @@ -43,7 +43,7 @@ template<> struct Renderer<2> { static ResourceKey mesh() { return {"object2d"}; } static const std::array positions; - static const std::array, 8> colors; + static const std::array colors; static const std::array indices; }; @@ -59,7 +59,7 @@ const std::array Renderer<2>::positions{{ {-0.1f, 0.9f} }}; -const std::array, 8> Renderer<2>::colors{{ +const std::array Renderer<2>::colors{{ {1.0f, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, /* X axis */ {1.0f, 0.0f, 0.0f}, @@ -88,7 +88,7 @@ template<> struct Renderer<3> { static ResourceKey mesh() { return {"object3d"}; } static const std::array positions; - static const std::array, 12> colors; + static const std::array colors; static const std::array indices; }; @@ -109,7 +109,7 @@ const std::array Renderer<3>::positions{{ {-0.1f, 0.0f, 0.9f} }}; -const std::array, 12> Renderer<3>::colors{{ +const std::array Renderer<3>::colors{{ {1.0f, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, /* X axis */ {1.0f, 0.0f, 0.0f}, diff --git a/src/DebugTools/ShapeRenderer.h b/src/DebugTools/ShapeRenderer.h index a237cab71..3ec2dc1f4 100644 --- a/src/DebugTools/ShapeRenderer.h +++ b/src/DebugTools/ShapeRenderer.h @@ -83,7 +83,7 @@ class ShapeRendererOptions { } /** @brief Color of rendered shape */ - constexpr Color4<> color() const { return _color; } + constexpr Color4 color() const { return _color; } /** * @brief Set color of rendered shape @@ -91,7 +91,7 @@ class ShapeRendererOptions { * * Default is 100% opaque white. */ - ShapeRendererOptions* setColor(const Color4<>& color) { + ShapeRendererOptions* setColor(const Color4& color) { _color = color; return this; } @@ -112,7 +112,7 @@ class ShapeRendererOptions { } private: - Color4<> _color; + Color4 _color; Float _pointSize; RenderMode _renderMode; }; diff --git a/src/Magnum.h b/src/Magnum.h index 53475bb91..a54c2467c 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -352,8 +352,10 @@ class BufferTexture; enum class BufferTextureFormat: GLenum; #endif -template class Color3; -template class Color4; +template class BasicColor3; +template class BasicColor4; +typedef BasicColor3 Color3; +typedef BasicColor4 Color4; enum class Version: Int; class Context; diff --git a/src/Mesh.h b/src/Mesh.h index 2db8523d9..a68d8bbe7 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -173,7 +173,7 @@ mesh->setPrimitive(plane.primitive()) class MyShader: public AbstractShaderProgram { public: typedef Attribute<0, Vector3> Position; - typedef Attribute<1, Color4<>> Color; + typedef Attribute<1, Color4> Color; // ... }; diff --git a/src/MeshTools/Interleave.h b/src/MeshTools/Interleave.h index 8745a5da3..e95ec8ebd 100644 --- a/src/MeshTools/Interleave.h +++ b/src/MeshTools/Interleave.h @@ -160,7 +160,7 @@ achieve that, you can specify gaps between the attributes: @code std::vector positions; std::vector weights; -std::vector> vertexColors; +std::vector> vertexColors; std::size_t attributeCount; std::size_t stride; char* data; diff --git a/src/Renderer.cpp b/src/Renderer.cpp index 7fb8ed7a5..d823af8d8 100644 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -50,7 +50,7 @@ void Renderer::setHint(const Hint target, const HintMode mode) { glHint(GLenum(target), GLenum(mode)); } -void Renderer::setClearColor(const Color4<>& color) { +void Renderer::setClearColor(const Color4& color) { glClearColor(color.r(), color.g(), color.b(), color.a()); } @@ -152,7 +152,7 @@ void Renderer::setBlendFunction(const BlendFunction sourceRgb, const BlendFuncti glBlendFuncSeparate(GLenum(sourceRgb), GLenum(destinationRgb), GLenum(sourceAlpha), GLenum(destinationAlpha)); } -void Renderer::setBlendColor(const Color4<>& color) { +void Renderer::setBlendColor(const Color4& color) { glBlendColor(color.r(), color.g(), color.b(), color.a()); } diff --git a/src/Renderer.h b/src/Renderer.h index e66e8311b..e6cbc7609 100644 --- a/src/Renderer.h +++ b/src/Renderer.h @@ -238,7 +238,7 @@ class MAGNUM_EXPORT Renderer { * Initial value is fully opaque black. * @see @fn_gl{ClearColor} */ - static void setClearColor(const Color4<>& color); + static void setClearColor(const Color4& color); #ifndef MAGNUM_TARGET_GLES /** @@ -809,7 +809,7 @@ class MAGNUM_EXPORT Renderer { * @see @ref Feature "Feature::Blending", setBlendEquation(), * setBlendFunction(), @fn_gl{BlendColor} */ - static void setBlendColor(const Color4<>& color); + static void setBlendColor(const Color4& color); /*@}*/ diff --git a/src/Shaders/DistanceFieldVector.h b/src/Shaders/DistanceFieldVector.h index ab6455e57..50ad57051 100644 --- a/src/Shaders/DistanceFieldVector.h +++ b/src/Shaders/DistanceFieldVector.h @@ -63,7 +63,7 @@ template class MAGNUM_SHADERS_EXPORT DistanceFieldVector * * @see setOutlineColor() */ - DistanceFieldVector* setColor(const Color4<>& color) { + DistanceFieldVector* setColor(const Color4& color) { AbstractShaderProgram::setUniform(colorUniform, color); return this; } @@ -74,7 +74,7 @@ template class MAGNUM_SHADERS_EXPORT DistanceFieldVector * * @see setOutlineRange(), setColor() */ - DistanceFieldVector* setOutlineColor(const Color4<>& color) { + DistanceFieldVector* setOutlineColor(const Color4& color) { AbstractShaderProgram::setUniform(outlineColorUniform, color); return this; } diff --git a/src/Shaders/Flat.h b/src/Shaders/Flat.h index be01877fd..69e9cccf0 100644 --- a/src/Shaders/Flat.h +++ b/src/Shaders/Flat.h @@ -64,7 +64,7 @@ template class MAGNUM_SHADERS_EXPORT Flat: public Abstra * @brief Set color * @return Pointer to self (for method chaining) */ - Flat* setColor(const Color4<>& color) { + Flat* setColor(const Color4& color) { setUniform(colorUniform, color); return this; } diff --git a/src/Shaders/MeshVisualizer.cpp b/src/Shaders/MeshVisualizer.cpp index 7a5393e4a..0ad479de6 100644 --- a/src/Shaders/MeshVisualizer.cpp +++ b/src/Shaders/MeshVisualizer.cpp @@ -115,9 +115,9 @@ MeshVisualizer::MeshVisualizer(const Flags flags): flags(flags), transformationP /* Set defaults in OpenGL ES (for desktop they are set in shader code itself) */ #ifdef MAGNUM_TARGET_GLES - setColor(Color3<>(1.0f)); + setColor(Color3(1.0f)); if(flags & Flag::Wireframe) { - setWireframeColor(Color3<>(0.0f)); + setWireframeColor(Color3(0.0f)); setWireframeWidth(1.0f); setSmoothness(2.0f); } diff --git a/src/Shaders/MeshVisualizer.h b/src/Shaders/MeshVisualizer.h index cb75305d2..e48aaefbd 100644 --- a/src/Shaders/MeshVisualizer.h +++ b/src/Shaders/MeshVisualizer.h @@ -138,7 +138,7 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizer: public AbstractShaderProgram { * * Initial value is fully opaque white. */ - MeshVisualizer* setColor(const Color4<>& color) { + MeshVisualizer* setColor(const Color4& color) { setUniform(colorUniform, color); return this; } @@ -150,7 +150,7 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizer: public AbstractShaderProgram { * Initial value is fully opaque black. Has effect only if * @ref Flag "Flag::Wireframe" is enabled. */ - MeshVisualizer* setWireframeColor(const Color4<>& color) { + MeshVisualizer* setWireframeColor(const Color4& color) { if(flags & Flag::Wireframe) setUniform(wireframeColorUniform, color); return this; } diff --git a/src/Shaders/Phong.h b/src/Shaders/Phong.h index 7bce3636b..f153dc761 100644 --- a/src/Shaders/Phong.h +++ b/src/Shaders/Phong.h @@ -55,7 +55,7 @@ class MAGNUM_SHADERS_EXPORT Phong: public AbstractShaderProgram { * * If not set, default value is `(0.0f, 0.0f, 0.0f)`. */ - Phong* setAmbientColor(const Color3<>& color) { + Phong* setAmbientColor(const Color3& color) { setUniform(ambientColorUniform, color); return this; } @@ -64,7 +64,7 @@ class MAGNUM_SHADERS_EXPORT Phong: public AbstractShaderProgram { * @brief Set diffuse color * @return Pointer to self (for method chaining) */ - Phong* setDiffuseColor(const Color3<>& color) { + Phong* setDiffuseColor(const Color3& color) { setUniform(diffuseColorUniform, color); return this; } @@ -75,7 +75,7 @@ class MAGNUM_SHADERS_EXPORT Phong: public AbstractShaderProgram { * * If not set, default value is `(1.0f, 1.0f, 1.0f)`. */ - Phong* setSpecularColor(const Color3<>& color) { + Phong* setSpecularColor(const Color3& color) { setUniform(specularColorUniform, color); return this; } @@ -126,7 +126,7 @@ class MAGNUM_SHADERS_EXPORT Phong: public AbstractShaderProgram { * * If not set, default value is `(1.0f, 1.0f, 1.0f)`. */ - Phong* setLightColor(const Color3<>& color) { + Phong* setLightColor(const Color3& color) { setUniform(lightColorUniform, color); return this; } diff --git a/src/Shaders/Vector.h b/src/Shaders/Vector.h index 9c86a0f3e..f4d7e61c2 100644 --- a/src/Shaders/Vector.h +++ b/src/Shaders/Vector.h @@ -60,7 +60,7 @@ template class MAGNUM_SHADERS_EXPORT Vector: public Abst * @brief Set fill color * @return Pointer to self (for method chaining) */ - Vector* setColor(const Color4<>& color) { + Vector* setColor(const Color4& color) { AbstractShaderProgram::setUniform(colorUniform, color); return this; } diff --git a/src/Shaders/VertexColor.h b/src/Shaders/VertexColor.h index e47630e46..d50eea060 100644 --- a/src/Shaders/VertexColor.h +++ b/src/Shaders/VertexColor.h @@ -50,7 +50,7 @@ template class MAGNUM_SHADERS_EXPORT VertexColor: public typedef Attribute<0, typename DimensionTraits::VectorType> Position; /** @brief Vertex color */ - typedef Attribute<1, Color3<>> Color; + typedef Attribute<1, Color3> Color; explicit VertexColor(); diff --git a/src/Swizzle.h b/src/Swizzle.h index 07216c3b1..2072f7223 100644 --- a/src/Swizzle.h +++ b/src/Swizzle.h @@ -47,10 +47,10 @@ namespace Implementation { template struct TypeForSize<2, T> { typedef Math::Vector2 Type; }; template struct TypeForSize<3, T> { typedef Math::Vector3 Type; }; template struct TypeForSize<4, T> { typedef Math::Vector4 Type; }; - template struct TypeForSize<3, Color3> { typedef Color3 Type; }; - template struct TypeForSize<3, Color4> { typedef Color3 Type; }; - template struct TypeForSize<4, Color3> { typedef Color4 Type; }; - template struct TypeForSize<4, Color4> { typedef Color4 Type; }; + template struct TypeForSize<3, BasicColor3> { typedef BasicColor3 Type; }; + template struct TypeForSize<3, BasicColor4> { typedef BasicColor3 Type; }; + template struct TypeForSize<4, BasicColor3> { typedef BasicColor4 Type; }; + template struct TypeForSize<4, BasicColor4> { typedef BasicColor4 Type; }; } /** diff --git a/src/Test/ColorTest.cpp b/src/Test/ColorTest.cpp index 52b815f65..93da6047c 100644 --- a/src/Test/ColorTest.cpp +++ b/src/Test/ColorTest.cpp @@ -52,10 +52,8 @@ class ColorTest: public TestSuite::Tester { void configuration(); }; -typedef Magnum::Color3 Color3; -typedef Magnum::Color4 Color4; -typedef Magnum::Color3 Color3f; -typedef Magnum::Color4 Color4f; +typedef Magnum::BasicColor3 Color3ub; +typedef Magnum::BasicColor4 Color4ub; ColorTest::ColorTest() { addTests({&ColorTest::access, @@ -77,8 +75,8 @@ ColorTest::ColorTest() { } void ColorTest::access() { - Color3f c3(15, 255, 10); - const Color3f cc3(15, 255, 10); + Color3ub c3(15, 255, 10); + const Color3ub cc3(15, 255, 10); CORRADE_COMPARE(c3.r(), 15); CORRADE_COMPARE(c3.g(), 255); @@ -87,8 +85,8 @@ void ColorTest::access() { CORRADE_COMPARE(cc3.g(), 255); CORRADE_COMPARE(cc3.b(), 10); - Color4 c4(125, 98, 51, 22); - const Color4f cc4(125, 98, 51, 22); + Color4ub c4(125, 98, 51, 22); + const Color4ub cc4(125, 98, 51, 22); CORRADE_COMPARE(c4.r(), 125); CORRADE_COMPARE(c4.g(), 98); @@ -101,98 +99,98 @@ void ColorTest::access() { } void ColorTest::fromHue() { - CORRADE_COMPARE(Color3::fromHSV(Deg(27.0f), 1.0f, 1.0f), Color3(255, 114, 0)); - CORRADE_COMPARE(Color3::fromHSV(Deg(86.0f), 1.0f, 1.0f), Color3(144, 255, 0)); - CORRADE_COMPARE(Color3::fromHSV(Deg(134.0f), 1.0f, 1.0f), Color3(0, 255, 59)); - CORRADE_COMPARE(Color3::fromHSV(Deg(191.0f), 1.0f, 1.0f), Color3(0, 208, 255)); - CORRADE_COMPARE(Color3::fromHSV(Deg(269.0f), 1.0f, 1.0f), Color3(123, 0, 255)); - CORRADE_COMPARE(Color3::fromHSV(Deg(317.0f), 1.0f, 1.0f), Color3(255, 0, 182)); + CORRADE_COMPARE(Color3ub::fromHSV(Deg(27.0f), 1.0f, 1.0f), Color3ub(255, 114, 0)); + CORRADE_COMPARE(Color3ub::fromHSV(Deg(86.0f), 1.0f, 1.0f), Color3ub(144, 255, 0)); + CORRADE_COMPARE(Color3ub::fromHSV(Deg(134.0f), 1.0f, 1.0f), Color3ub(0, 255, 59)); + CORRADE_COMPARE(Color3ub::fromHSV(Deg(191.0f), 1.0f, 1.0f), Color3ub(0, 208, 255)); + CORRADE_COMPARE(Color3ub::fromHSV(Deg(269.0f), 1.0f, 1.0f), Color3ub(123, 0, 255)); + CORRADE_COMPARE(Color3ub::fromHSV(Deg(317.0f), 1.0f, 1.0f), Color3ub(255, 0, 182)); } void ColorTest::hue() { - CORRADE_COMPARE(Color3(255, 115, 0).hue(), Deg(27.058824f)); - CORRADE_COMPARE(Color3(145, 255, 0).hue(), Deg(85.882353f)); - CORRADE_COMPARE(Color3(0, 255, 60).hue(), Deg(134.11765f)); - CORRADE_COMPARE(Color3(0, 208, 255).hue(), Deg(191.05882f)); - CORRADE_COMPARE(Color3(123, 0, 255).hue(), Deg(268.94117f)); - CORRADE_COMPARE(Color3(255, 0, 183).hue(), Deg(316.94117f)); + CORRADE_COMPARE(Color3ub(255, 115, 0).hue(), Deg(27.058824f)); + CORRADE_COMPARE(Color3ub(145, 255, 0).hue(), Deg(85.882353f)); + CORRADE_COMPARE(Color3ub(0, 255, 60).hue(), Deg(134.11765f)); + CORRADE_COMPARE(Color3ub(0, 208, 255).hue(), Deg(191.05882f)); + CORRADE_COMPARE(Color3ub(123, 0, 255).hue(), Deg(268.94117f)); + CORRADE_COMPARE(Color3ub(255, 0, 183).hue(), Deg(316.94117f)); } void ColorTest::fromSaturation() { - CORRADE_COMPARE(Color3::fromHSV(Deg(0.0f), 0.702f, 1.0f), Color3(255, 75, 75)); + CORRADE_COMPARE(Color3ub::fromHSV(Deg(0.0f), 0.702f, 1.0f), Color3ub(255, 75, 75)); } void ColorTest::saturation() { - CORRADE_COMPARE(Color3(255, 76, 76).saturation(), 0.701961f); - CORRADE_COMPARE(Color3().saturation(), 0.0f); + CORRADE_COMPARE(Color3ub(255, 76, 76).saturation(), 0.701961f); + CORRADE_COMPARE(Color3ub().saturation(), 0.0f); } void ColorTest::fromValue() { - CORRADE_COMPARE(Color3::fromHSV(Deg(0.0f), 1.0f, 0.522f), Color3(133, 0, 0)); + CORRADE_COMPARE(Color3ub::fromHSV(Deg(0.0f), 1.0f, 0.522f), Color3ub(133, 0, 0)); } void ColorTest::value() { - CORRADE_COMPARE(Color3(133, 0, 0).value(), 0.521569f); + CORRADE_COMPARE(Color3ub(133, 0, 0).value(), 0.521569f); } void ColorTest::hsv() { - CORRADE_COMPARE(Color3::fromHSV(Deg(230.0f), 0.749f, 0.427f), Color3(27, 40, 108)); + CORRADE_COMPARE(Color3ub::fromHSV(Deg(230.0f), 0.749f, 0.427f), Color3ub(27, 40, 108)); Deg hue; Float saturation, value; - std::tie(hue, saturation, value) = Color3(27, 41, 109).toHSV(); + std::tie(hue, saturation, value) = Color3ub(27, 41, 109).toHSV(); CORRADE_COMPARE(hue, Deg(229.756106f)); CORRADE_COMPARE(saturation, 0.752294f); CORRADE_COMPARE(value, 0.427451f); } void ColorTest::hsvOverflow() { - CORRADE_COMPARE(Color3::fromHSV(Deg(27.0f-360.0f), 1.0f, 1.0f), Color3(255, 114, 0)); - CORRADE_COMPARE(Color3::fromHSV(Deg(86.0f-360.0f), 1.0f, 1.0f), Color3(144, 255, 0)); - CORRADE_COMPARE(Color3::fromHSV(Deg(134.0f-360.0f), 1.0f, 1.0f), Color3(0, 255, 59)); - CORRADE_COMPARE(Color3::fromHSV(Deg(191.0f-360.0f), 1.0f, 1.0f), Color3(0, 208, 255)); - CORRADE_COMPARE(Color3::fromHSV(Deg(269.0f-360.0f), 1.0f, 1.0f), Color3(123, 0, 255)); - CORRADE_COMPARE(Color3::fromHSV(Deg(317.0f-360.0f), 1.0f, 1.0f), Color3(255, 0, 182)); - - CORRADE_COMPARE(Color3::fromHSV(Deg(360.0f+27.0f), 1.0f, 1.0f), Color3(255, 114, 0)); - CORRADE_COMPARE(Color3::fromHSV(Deg(360.0f+86.0f), 1.0f, 1.0f), Color3(144, 255, 0)); - CORRADE_COMPARE(Color3::fromHSV(Deg(360.0f+134.0f), 1.0f, 1.0f), Color3(0, 255, 59)); - CORRADE_COMPARE(Color3::fromHSV(Deg(360.0f+191.0f), 1.0f, 1.0f), Color3(0, 208, 255)); - CORRADE_COMPARE(Color3::fromHSV(Deg(360.0f+269.0f), 1.0f, 1.0f), Color3(123, 0, 255)); - CORRADE_COMPARE(Color3::fromHSV(Deg(360.0f+317.0f), 1.0f, 1.0f), Color3(255, 0, 182)); + CORRADE_COMPARE(Color3ub::fromHSV(Deg(27.0f-360.0f), 1.0f, 1.0f), Color3ub(255, 114, 0)); + CORRADE_COMPARE(Color3ub::fromHSV(Deg(86.0f-360.0f), 1.0f, 1.0f), Color3ub(144, 255, 0)); + CORRADE_COMPARE(Color3ub::fromHSV(Deg(134.0f-360.0f), 1.0f, 1.0f), Color3ub(0, 255, 59)); + CORRADE_COMPARE(Color3ub::fromHSV(Deg(191.0f-360.0f), 1.0f, 1.0f), Color3ub(0, 208, 255)); + CORRADE_COMPARE(Color3ub::fromHSV(Deg(269.0f-360.0f), 1.0f, 1.0f), Color3ub(123, 0, 255)); + CORRADE_COMPARE(Color3ub::fromHSV(Deg(317.0f-360.0f), 1.0f, 1.0f), Color3ub(255, 0, 182)); + + CORRADE_COMPARE(Color3ub::fromHSV(Deg(360.0f+27.0f), 1.0f, 1.0f), Color3ub(255, 114, 0)); + CORRADE_COMPARE(Color3ub::fromHSV(Deg(360.0f+86.0f), 1.0f, 1.0f), Color3ub(144, 255, 0)); + CORRADE_COMPARE(Color3ub::fromHSV(Deg(360.0f+134.0f), 1.0f, 1.0f), Color3ub(0, 255, 59)); + CORRADE_COMPARE(Color3ub::fromHSV(Deg(360.0f+191.0f), 1.0f, 1.0f), Color3ub(0, 208, 255)); + CORRADE_COMPARE(Color3ub::fromHSV(Deg(360.0f+269.0f), 1.0f, 1.0f), Color3ub(123, 0, 255)); + CORRADE_COMPARE(Color3ub::fromHSV(Deg(360.0f+317.0f), 1.0f, 1.0f), Color3ub(255, 0, 182)); } void ColorTest::hsvAlpha() { - CORRADE_COMPARE(Color4::fromHSV(std::make_tuple(Deg(230.0f), 0.749f, 0.427f), 23), Color4(27, 40, 108, 23)); - CORRADE_COMPARE(Color4::fromHSV(Deg(230.0f), 0.749f, 0.427f, 23), Color4(27, 40, 108, 23)); + CORRADE_COMPARE(Color4ub::fromHSV(std::make_tuple(Deg(230.0f), 0.749f, 0.427f), 23), Color4ub(27, 40, 108, 23)); + CORRADE_COMPARE(Color4ub::fromHSV(Deg(230.0f), 0.749f, 0.427f, 23), Color4ub(27, 40, 108, 23)); } void ColorTest::debug() { std::ostringstream o; - Debug(&o) << Color3f(0.5f, 0.75f, 1.0f); + Debug(&o) << Color3(0.5f, 0.75f, 1.0f); CORRADE_COMPARE(o.str(), "Vector(0.5, 0.75, 1)\n"); o.str({}); - Debug(&o) << Color4f(0.5f, 0.75f, 0.0f, 1.0f); + Debug(&o) << Color4(0.5f, 0.75f, 0.0f, 1.0f); CORRADE_COMPARE(o.str(), "Vector(0.5, 0.75, 0, 1)\n"); } void ColorTest::configuration() { Utility::Configuration c; - Color3f color3(0.5f, 0.75f, 1.0f); + Color3 color3(0.5f, 0.75f, 1.0f); std::string value3("0.5 0.75 1"); c.setValue("color3", color3); CORRADE_COMPARE(c.value("color3"), value3); - CORRADE_COMPARE(c.value("color3"), color3); + CORRADE_COMPARE(c.value("color3"), color3); - Color4f color4(0.5f, 0.75f, 0.0f, 1.0f); + Color4 color4(0.5f, 0.75f, 0.0f, 1.0f); std::string value4("0.5 0.75 0 1"); c.setValue("color4", color4); CORRADE_COMPARE(c.value("color4"), value4); - CORRADE_COMPARE(c.value("color4"), color4); + CORRADE_COMPARE(c.value("color4"), color4); } }} diff --git a/src/Test/SwizzleTest.cpp b/src/Test/SwizzleTest.cpp index a128b3555..2cf321668 100644 --- a/src/Test/SwizzleTest.cpp +++ b/src/Test/SwizzleTest.cpp @@ -50,8 +50,8 @@ void SwizzleTest::rgba() { void SwizzleTest::type() { constexpr Vector4i orig; - constexpr Color3 origColor3; - constexpr Color4 origColor4; + constexpr Color3 origColor3; + constexpr BasicColor4 origColor4; constexpr auto a = swizzle<'y', 'a'>(orig); CORRADE_VERIFY((std::is_same::value)); @@ -63,16 +63,16 @@ void SwizzleTest::type() { CORRADE_VERIFY((std::is_same::value)); constexpr auto d = swizzle<'y', 'z', 'r'>(origColor3); - CORRADE_VERIFY((std::is_same>::value)); + CORRADE_VERIFY((std::is_same::value)); constexpr auto e = swizzle<'y', 'z', 'a'>(origColor4); - CORRADE_VERIFY((std::is_same>::value)); + CORRADE_VERIFY((std::is_same>::value)); constexpr auto f = swizzle<'y', 'z', 'y', 'x'>(origColor3); - CORRADE_VERIFY((std::is_same>::value)); + CORRADE_VERIFY((std::is_same::value)); constexpr auto g = swizzle<'y', 'a', 'y', 'x'>(origColor4); - CORRADE_VERIFY((std::is_same>::value)); + CORRADE_VERIFY((std::is_same>::value)); } void SwizzleTest::defaultType() { diff --git a/src/Texture.h b/src/Texture.h index dce833157..90c5a8e9d 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -427,7 +427,7 @@ template class Texture: public AbstractTexture { return this; } #ifndef MAGNUM_TARGET_GLES3 - Texture* setBorderColor(const Color4<>& color) { + Texture* setBorderColor(const Color4& color) { AbstractTexture::setBorderColor(color); return this; }