Browse Source

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);
pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
a7f5bef038
  1. 4
      src/AbstractShaderProgram.h
  2. 2
      src/AbstractTexture.h
  3. 138
      src/Color.h
  4. 2
      src/CubeMapTexture.h
  5. 2
      src/CubeMapTextureArray.h
  6. 8
      src/DebugTools/ForceRenderer.h
  7. 8
      src/DebugTools/ObjectRenderer.cpp
  8. 6
      src/DebugTools/ShapeRenderer.h
  9. 6
      src/Magnum.h
  10. 2
      src/Mesh.h
  11. 2
      src/MeshTools/Interleave.h
  12. 4
      src/Renderer.cpp
  13. 4
      src/Renderer.h
  14. 4
      src/Shaders/DistanceFieldVector.h
  15. 2
      src/Shaders/Flat.h
  16. 4
      src/Shaders/MeshVisualizer.cpp
  17. 4
      src/Shaders/MeshVisualizer.h
  18. 8
      src/Shaders/Phong.h
  19. 2
      src/Shaders/Vector.h
  20. 2
      src/Shaders/VertexColor.h
  21. 8
      src/Swizzle.h
  22. 94
      src/Test/ColorTest.cpp
  23. 12
      src/Test/SwizzleTest.cpp
  24. 2
      src/Texture.h

4
src/AbstractShaderProgram.h

@ -1392,8 +1392,8 @@ template<std::size_t size_> struct Attribute<Math::Vector<size_, Double>>: Doubl
template<class T> struct Attribute<Math::Vector2<T>>: Attribute<Math::Vector<2, T>> {}; template<class T> struct Attribute<Math::Vector2<T>>: Attribute<Math::Vector<2, T>> {};
template<class T> struct Attribute<Math::Vector3<T>>: Attribute<Math::Vector<3, T>> {}; template<class T> struct Attribute<Math::Vector3<T>>: Attribute<Math::Vector<3, T>> {};
template<class T> struct Attribute<Math::Vector4<T>>: Attribute<Math::Vector<4, T>> {}; template<class T> struct Attribute<Math::Vector4<T>>: Attribute<Math::Vector<4, T>> {};
template<class T> struct Attribute<Color3<T>>: Attribute<Math::Vector3<T>> {}; template<class T> struct Attribute<BasicColor3<T>>: Attribute<Math::Vector3<T>> {};
template<class T> struct Attribute<Color4<T>>: Attribute<Math::Vector4<T>> {}; template<class T> struct Attribute<BasicColor4<T>>: Attribute<Math::Vector4<T>> {};
/* Common float and double rectangular matrix attributes */ /* Common float and double rectangular matrix attributes */
template<std::size_t cols, std::size_t rows> struct Attribute<Math::RectangularMatrix<cols, rows, Float>>: FloatAttribute, SizedAttribute<cols, rows> {}; template<std::size_t cols, std::size_t rows> struct Attribute<Math::RectangularMatrix<cols, rows, Float>>: FloatAttribute, SizedAttribute<cols, rows> {};

2
src/AbstractTexture.h

@ -203,7 +203,7 @@ class MAGNUM_EXPORT AbstractTexture {
* with @def_gl{TEXTURE_BORDER_COLOR} * with @def_gl{TEXTURE_BORDER_COLOR}
* @requires_es_extension %Extension @es_extension{NV,texture_border_clamp} * @requires_es_extension %Extension @es_extension{NV,texture_border_clamp}
*/ */
AbstractTexture* setBorderColor(const Color4<>& color) { AbstractTexture* setBorderColor(const Color4& color) {
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
(this->*parameterfvImplementation)(GL_TEXTURE_BORDER_COLOR, color.data()); (this->*parameterfvImplementation)(GL_TEXTURE_BORDER_COLOR, color.data());
#else #else

138
src/Color.h

@ -25,7 +25,7 @@
*/ */
/** @file /** @file
* @brief Class Magnum::Color3, Magnum::Color4 * @brief Class Magnum::BasicColor3, Magnum::BasicColor4, typedef Magnum::Color3, Magnum::Color4
*/ */
#include <tuple> #include <tuple>
@ -39,7 +39,7 @@ namespace Magnum {
namespace Implementation { namespace Implementation {
/* Convert color from HSV */ /* Convert color from HSV */
template<class T> typename std::enable_if<std::is_floating_point<T>::value, Color3<T>>::type fromHSV(typename Color3<T>::HSV hsv) { template<class T> typename std::enable_if<std::is_floating_point<T>::value, BasicColor3<T>>::type fromHSV(typename BasicColor3<T>::HSV hsv) {
Math::Deg<T> hue; Math::Deg<T> hue;
T saturation, value; T saturation, value;
std::tie(hue, saturation, value) = hsv; std::tie(hue, saturation, value) = hsv;
@ -65,12 +65,12 @@ template<class T> typename std::enable_if<std::is_floating_point<T>::value, Colo
default: CORRADE_ASSERT_UNREACHABLE(); default: CORRADE_ASSERT_UNREACHABLE();
} }
} }
template<class T> inline typename std::enable_if<std::is_integral<T>::value, Color3<T>>::type fromHSV(typename Color3<T>::HSV hsv) { template<class T> inline typename std::enable_if<std::is_integral<T>::value, BasicColor3<T>>::type fromHSV(typename BasicColor3<T>::HSV hsv) {
return Math::denormalize<Color3<T>>(fromHSV<typename Color3<T>::FloatingPointType>(hsv)); return Math::denormalize<BasicColor3<T>>(fromHSV<typename BasicColor3<T>::FloatingPointType>(hsv));
} }
/* Internal hue computing function */ /* Internal hue computing function */
template<class T> Math::Deg<T> hue(const Color3<T>& color, T max, T delta) { template<class T> Math::Deg<T> hue(const BasicColor3<T>& color, T max, T delta) {
T deltaInv60 = T(60)/delta; T deltaInv60 = T(60)/delta;
T hue(0); T hue(0);
@ -87,40 +87,40 @@ template<class T> Math::Deg<T> hue(const Color3<T>& color, T max, T delta) {
} }
/* Hue, saturation, value for floating-point types */ /* Hue, saturation, value for floating-point types */
template<class T> inline Math::Deg<T> hue(typename std::enable_if<std::is_floating_point<T>::value, const Color3<T>&>::type color) { template<class T> inline Math::Deg<T> hue(typename std::enable_if<std::is_floating_point<T>::value, const BasicColor3<T>&>::type color) {
T max = color.max(); T max = color.max();
T delta = max - color.min(); T delta = max - color.min();
return hue(color, max, delta); return hue(color, max, delta);
} }
template<class T> inline T saturation(typename std::enable_if<std::is_floating_point<T>::value, const Color3<T>&>::type color) { template<class T> inline T saturation(typename std::enable_if<std::is_floating_point<T>::value, const BasicColor3<T>&>::type color) {
T max = color.max(); T max = color.max();
T delta = max - color.min(); T delta = max - color.min();
return max != T(0) ? delta/max : T(0); return max != T(0) ? delta/max : T(0);
} }
template<class T> inline T value(typename std::enable_if<std::is_floating_point<T>::value, const Color3<T>&>::type color) { template<class T> inline T value(typename std::enable_if<std::is_floating_point<T>::value, const BasicColor3<T>&>::type color) {
return color.max(); return color.max();
} }
/* Hue, saturation, value for integral types */ /* Hue, saturation, value for integral types */
template<class T> inline Math::Deg<typename Color3<T>::FloatingPointType> hue(typename std::enable_if<std::is_integral<T>::value, const Color3<T>&>::type color) { template<class T> inline Math::Deg<typename BasicColor3<T>::FloatingPointType> hue(typename std::enable_if<std::is_integral<T>::value, const BasicColor3<T>&>::type color) {
return hue<typename Color3<T>::FloatingPointType>(Math::normalize<Color3<typename Color3<T>::FloatingPointType>>(color)); return hue<typename BasicColor3<T>::FloatingPointType>(Math::normalize<BasicColor3<typename BasicColor3<T>::FloatingPointType>>(color));
} }
template<class T> inline typename Color3<T>::FloatingPointType saturation(typename std::enable_if<std::is_integral<T>::value, const Color3<T>&>::type& color) { template<class T> inline typename BasicColor3<T>::FloatingPointType saturation(typename std::enable_if<std::is_integral<T>::value, const BasicColor3<T>&>::type& color) {
return saturation<typename Color3<T>::FloatingPointType>(Math::normalize<Color3<typename Color3<T>::FloatingPointType>>(color)); return saturation<typename BasicColor3<T>::FloatingPointType>(Math::normalize<BasicColor3<typename BasicColor3<T>::FloatingPointType>>(color));
} }
template<class T> inline typename Color3<T>::FloatingPointType value(typename std::enable_if<std::is_integral<T>::value, const Color3<T>&>::type color) { template<class T> inline typename BasicColor3<T>::FloatingPointType value(typename std::enable_if<std::is_integral<T>::value, const BasicColor3<T>&>::type color) {
return Math::normalize<typename Color3<T>::FloatingPointType>(color.max()); return Math::normalize<typename BasicColor3<T>::FloatingPointType>(color.max());
} }
/* Convert color to HSV */ /* Convert color to HSV */
template<class T> inline typename Color3<T>::HSV toHSV(typename std::enable_if<std::is_floating_point<T>::value, const Color3<T>&>::type color) { template<class T> inline typename BasicColor3<T>::HSV toHSV(typename std::enable_if<std::is_floating_point<T>::value, const BasicColor3<T>&>::type color) {
T max = color.max(); T max = color.max();
T delta = max - color.min(); T delta = max - color.min();
return typename Color3<T>::HSV(hue<typename Color3<T>::FloatingPointType>(color, max, delta), max != T(0) ? delta/max : T(0), max); return typename BasicColor3<T>::HSV(hue<typename BasicColor3<T>::FloatingPointType>(color, max, delta), max != T(0) ? delta/max : T(0), max);
} }
template<class T> inline typename Color3<T>::HSV toHSV(typename std::enable_if<std::is_integral<T>::value, const Color3<T>&>::type color) { template<class T> inline typename BasicColor3<T>::HSV toHSV(typename std::enable_if<std::is_integral<T>::value, const BasicColor3<T>&>::type color) {
return toHSV<typename Color3<T>::FloatingPointType>(Math::normalize<Color3<typename Color3<T>::FloatingPointType>>(color)); return toHSV<typename BasicColor3<T>::FloatingPointType>(Math::normalize<BasicColor3<typename BasicColor3<T>::FloatingPointType>>(color));
} }
/* Default alpha value */ /* 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 is always in range in range @f$ [0.0, 360.0] @f$, saturation and value in
range @f$ [0.0, 1.0] @f$. range @f$ [0.0, 1.0] @f$.
@see Color4 @see @ref Color3, @ref BasicColor4
*/ */
/* Not using template specialization because some internal functions are /* Not using template specialization because some internal functions are
impossible to explicitly instantiate */ impossible to explicitly instantiate */
#ifndef DOXYGEN_GENERATING_OUTPUT template<class T> class BasicColor3: public Math::Vector3<T> {
template<class T>
#else
template<class T = Float>
#endif
class Color3: public Math::Vector3<T> {
public: public:
/** @brief Corresponding floating-point type for HSV computation */ /** @brief Corresponding floating-point type for HSV computation */
typedef typename Math::TypeTraits<T>::FloatingPointType FloatingPointType; typedef typename Math::TypeTraits<T>::FloatingPointType FloatingPointType;
@ -172,11 +167,11 @@ class Color3: public Math::Vector3<T> {
* *
* Hue can overflow the range @f$ [0.0, 360.0] @f$. * Hue can overflow the range @f$ [0.0, 360.0] @f$.
*/ */
constexpr static Color3<T> fromHSV(HSV hsv) { constexpr static BasicColor3<T> fromHSV(HSV hsv) {
return Implementation::fromHSV<T>(hsv); return Implementation::fromHSV<T>(hsv);
} }
/** @overload */ /** @overload */
constexpr static Color3<T> fromHSV(Math::Deg<FloatingPointType> hue, FloatingPointType saturation, FloatingPointType value) { constexpr static BasicColor3<T> fromHSV(Math::Deg<FloatingPointType> hue, FloatingPointType saturation, FloatingPointType value) {
return fromHSV(std::make_tuple(hue, saturation, value)); return fromHSV(std::make_tuple(hue, saturation, value));
} }
@ -185,13 +180,13 @@ class Color3: public Math::Vector3<T> {
* *
* All components are set to zero. * All components are set to zero.
*/ */
constexpr /*implicit*/ Color3() {} constexpr /*implicit*/ BasicColor3() {}
/** /**
* @brief Gray constructor * @brief Gray constructor
* @param rgb RGB value * @param rgb RGB value
*/ */
constexpr explicit Color3(T rgb): Math::Vector3<T>(rgb) {} constexpr explicit BasicColor3(T rgb): Math::Vector3<T>(rgb) {}
/** /**
* @brief Constructor * @brief Constructor
@ -199,13 +194,13 @@ class Color3: public Math::Vector3<T> {
* @param g G value * @param g G value
* @param b B value * @param b B value
*/ */
constexpr /*implicit*/ Color3(T r, T g, T b): Math::Vector3<T>(r, g, b) {} constexpr /*implicit*/ BasicColor3(T r, T g, T b): Math::Vector3<T>(r, g, b) {}
/** @copydoc Math::Vector::Vector(const Vector<size, U>&) */ /** @copydoc Math::Vector::Vector(const Vector<size, U>&) */
template<class U> constexpr explicit Color3(const Math::Vector<3, U>& other): Math::Vector3<T>(other) {} template<class U> constexpr explicit BasicColor3(const Math::Vector<3, U>& other): Math::Vector3<T>(other) {}
/** @brief Copy constructor */ /** @brief Copy constructor */
constexpr Color3(const Math::Vector<3, T>& other): Math::Vector3<T>(other) {} constexpr BasicColor3(const Math::Vector<3, T>& other): Math::Vector3<T>(other) {}
T& r() { return Math::Vector3<T>::x(); } /**< @brief R component */ T& r() { return Math::Vector3<T>::x(); } /**< @brief R component */
constexpr T r() const { return Math::Vector3<T>::x(); } /**< @overload */ constexpr T r() const { return Math::Vector3<T>::x(); } /**< @overload */
@ -259,15 +254,19 @@ class Color3: public Math::Vector3<T> {
return Implementation::value<T>(*this); return Implementation::value<T>(*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<Float> Color3;
MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(BasicColor3, 3)
/** /**
@brief Four-component (RGBA) color @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 /* Not using template specialization because some internal functions are
impossible to explicitly instantiate */ impossible to explicitly instantiate */
@ -276,24 +275,24 @@ template<class T>
#else #else
template<class T = Float> template<class T = Float>
#endif #endif
class Color4: public Math::Vector4<T> { class BasicColor4: public Math::Vector4<T> {
public: public:
/** @copydoc Color3::FloatingPointType */ /** @copydoc BasicColor3::FloatingPointType */
typedef typename Color3<T>::FloatingPointType FloatingPointType; typedef typename BasicColor3<T>::FloatingPointType FloatingPointType;
/** @copydoc Color3::HSV */ /** @copydoc BasicColor3::HSV */
typedef typename Color3<T>::HSV HSV; typedef typename BasicColor3<T>::HSV HSV;
/** /**
* @copydoc Color3::fromHSV() * @copydoc BasicColor3::fromHSV()
* @param a Alpha value, defaults to 1.0 for floating-point types * @param a Alpha value, defaults to 1.0 for floating-point types
* and maximum positive value for integral types. * and maximum positive value for integral types.
*/ */
constexpr static Color4<T> fromHSV(HSV hsv, T a = Implementation::defaultAlpha<T>()) { constexpr static BasicColor4<T> fromHSV(HSV hsv, T a = Implementation::defaultAlpha<T>()) {
return Color4<T>(Implementation::fromHSV<T>(hsv), a); return BasicColor4<T>(Implementation::fromHSV<T>(hsv), a);
} }
/** @overload */ /** @overload */
constexpr static Color4<T> fromHSV(Math::Deg<FloatingPointType> hue, FloatingPointType saturation, FloatingPointType value, T alpha) { constexpr static BasicColor4<T> fromHSV(Math::Deg<FloatingPointType> hue, FloatingPointType saturation, FloatingPointType value, T alpha) {
return fromHSV(std::make_tuple(hue, saturation, value), alpha); return fromHSV(std::make_tuple(hue, saturation, value), alpha);
} }
@ -303,14 +302,14 @@ class Color4: public Math::Vector4<T> {
* RGB components are set to zero, A component is set to 1.0 for * RGB components are set to zero, A component is set to 1.0 for
* floating-point types and maximum positive value for integral types. * floating-point types and maximum positive value for integral types.
*/ */
constexpr /*implicit*/ Color4(): Math::Vector4<T>(T(0), T(0), T(0), Implementation::defaultAlpha<T>()) {} constexpr /*implicit*/ BasicColor4(): Math::Vector4<T>(T(0), T(0), T(0), Implementation::defaultAlpha<T>()) {}
/** /**
* @copydoc Color3::Color3(T) * @copydoc BasicColor3::BasicColor3(T)
* @param alpha Alpha value, defaults to 1.0 for floating-point types * @param alpha Alpha value, defaults to 1.0 for floating-point types
* and maximum positive value for integral types. * and maximum positive value for integral types.
*/ */
constexpr explicit Color4(T rgb, T alpha = Implementation::defaultAlpha<T>()): Math::Vector4<T>(rgb, rgb, rgb, alpha) {} constexpr explicit BasicColor4(T rgb, T alpha = Implementation::defaultAlpha<T>()): Math::Vector4<T>(rgb, rgb, rgb, alpha) {}
/** /**
* @brief Constructor * @brief Constructor
@ -320,22 +319,22 @@ class Color4: public Math::Vector4<T> {
* @param a A value, defaults to 1.0 for floating-point types and * @param a A value, defaults to 1.0 for floating-point types and
* maximum positive value for integral types. * maximum positive value for integral types.
*/ */
constexpr /*implicit*/ Color4(T r, T g, T b, T a = Implementation::defaultAlpha<T>()): Math::Vector4<T>(r, g, b, a) {} constexpr /*implicit*/ BasicColor4(T r, T g, T b, T a = Implementation::defaultAlpha<T>()): Math::Vector4<T>(r, g, b, a) {}
/** /**
* @brief Constructor * @brief Constructor
* @param rgb Three-component color * @param rgb Three-component color
* @param a A value * @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 */ is fairly common, nearly always with A set to 1 */
constexpr /*implicit*/ Color4(const Math::Vector3<T>& rgb, T a = Implementation::defaultAlpha<T>()): Math::Vector4<T>(rgb[0], rgb[1], rgb[2], a) {} constexpr /*implicit*/ BasicColor4(const Math::Vector3<T>& rgb, T a = Implementation::defaultAlpha<T>()): Math::Vector4<T>(rgb[0], rgb[1], rgb[2], a) {}
/** @copydoc Math::Vector::Vector(const Vector<size, U>&) */ /** @copydoc Math::Vector::Vector(const Vector<size, U>&) */
template<class U> constexpr explicit Color4(const Math::Vector<4, U>& other): Math::Vector4<T>(other) {} template<class U> constexpr explicit BasicColor4(const Math::Vector<4, U>& other): Math::Vector4<T>(other) {}
/** @brief Copy constructor */ /** @brief Copy constructor */
constexpr Color4(const Math::Vector<4, T>& other): Math::Vector4<T>(other) {} constexpr BasicColor4(const Math::Vector<4, T>& other): Math::Vector4<T>(other) {}
T& r() { return Math::Vector4<T>::x(); } /**< @brief R component */ T& r() { return Math::Vector4<T>::x(); } /**< @brief R component */
constexpr T r() const { return Math::Vector4<T>::x(); } /**< @overload */ constexpr T r() const { return Math::Vector4<T>::x(); } /**< @overload */
@ -352,52 +351,55 @@ class Color4: public Math::Vector4<T> {
* *
* @see swizzle() * @see swizzle()
*/ */
Color3<T>& rgb() { return Color3<T>::from(Math::Vector4<T>::data()); } BasicColor3<T>& rgb() { return BasicColor3<T>::from(Math::Vector4<T>::data()); }
constexpr Color3<T> rgb() const { return Color3<T>::from(Math::Vector4<T>::data()); } /**< @overload */ constexpr BasicColor3<T> rgb() const { return BasicColor3<T>::from(Math::Vector4<T>::data()); } /**< @overload */
/** @copydoc Color3::toHSV() */ /** @copydoc BasicColor3::toHSV() */
constexpr HSV toHSV() const { constexpr HSV toHSV() const {
return Implementation::toHSV<T>(rgb()); return Implementation::toHSV<T>(rgb());
} }
/** @copydoc Color3::hue() */ /** @copydoc BasicColor3::hue() */
constexpr Math::Deg<FloatingPointType> hue() const { constexpr Math::Deg<FloatingPointType> hue() const {
return Implementation::hue<T>(rgb()); return Implementation::hue<T>(rgb());
} }
/** @copydoc Color3::saturation() */ /** @copydoc BasicColor3::saturation() */
constexpr FloatingPointType saturation() const { constexpr FloatingPointType saturation() const {
return Implementation::saturation<T>(rgb()); return Implementation::saturation<T>(rgb());
} }
/** @copydoc Color3::value() */ /** @copydoc BasicColor3::value() */
constexpr FloatingPointType value() const { constexpr FloatingPointType value() const {
return Implementation::value<T>(rgb()); return Implementation::value<T>(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<Float> Color4;
MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(BasicColor4, 4)
/** @debugoperator{Magnum::Color3} */ /** @debugoperator{Magnum::BasicColor3} */
template<class T> inline Debug operator<<(Debug debug, const Color3<T>& value) { template<class T> inline Debug operator<<(Debug debug, const BasicColor3<T>& value) {
return debug << static_cast<const Math::Vector3<T>&>(value); return debug << static_cast<const Math::Vector3<T>&>(value);
} }
/** @debugoperator{Magnum::Color4} */ /** @debugoperator{Magnum::BasicColor4} */
template<class T> inline Debug operator<<(Debug debug, const Color4<T>& value) { template<class T> inline Debug operator<<(Debug debug, const BasicColor4<T>& value) {
return debug << static_cast<const Math::Vector4<T>&>(value); return debug << static_cast<const Math::Vector4<T>&>(value);
} }
} }
namespace Corrade { namespace Utility { namespace Corrade { namespace Utility {
/** @configurationvalue{Magnum::Color3} */ /** @configurationvalue{Magnum::BasicColor3} */
template<class T> struct ConfigurationValue<Magnum::Color3<T>>: public ConfigurationValue<Magnum::Math::Vector<3, T>> {}; template<class T> struct ConfigurationValue<Magnum::BasicColor3<T>>: public ConfigurationValue<Magnum::Math::Vector<3, T>> {};
/** @configurationvalue{Magnum::Color4} */ /** @configurationvalue{Magnum::BasicColor4} */
template<class T> struct ConfigurationValue<Magnum::Color4<T>>: public ConfigurationValue<Magnum::Math::Vector<4, T>> {}; template<class T> struct ConfigurationValue<Magnum::BasicColor4<T>>: public ConfigurationValue<Magnum::Math::Vector<4, T>> {};
}} }}
#endif #endif

2
src/CubeMapTexture.h

@ -233,7 +233,7 @@ class CubeMapTexture: public AbstractTexture {
return this; return this;
} }
#ifndef MAGNUM_TARGET_GLES3 #ifndef MAGNUM_TARGET_GLES3
CubeMapTexture* setBorderColor(const Color4<>& color) { CubeMapTexture* setBorderColor(const Color4& color) {
AbstractTexture::setBorderColor(color); AbstractTexture::setBorderColor(color);
return this; return this;
} }

2
src/CubeMapTextureArray.h

@ -243,7 +243,7 @@ class CubeMapTextureArray: public AbstractTexture {
return this; return this;
} }
#ifndef MAGNUM_TARGET_GLES3 #ifndef MAGNUM_TARGET_GLES3
CubeMapTextureArray* setBorderColor(const Color4<>& color) { CubeMapTextureArray* setBorderColor(const Color4& color) {
AbstractTexture::setBorderColor(color); AbstractTexture::setBorderColor(color);
return this; return this;
} }

8
src/DebugTools/ForceRenderer.h

@ -47,7 +47,7 @@ class ForceRendererOptions {
constexpr ForceRendererOptions(): _color(1.0f), _size(1.0f) {} constexpr ForceRendererOptions(): _color(1.0f), _size(1.0f) {}
/** @brief Color of rendered arrow */ /** @brief Color of rendered arrow */
constexpr Color4<> color() const { return _color; } constexpr Color4 color() const { return _color; }
/** /**
* @brief Set color of rendered arrow * @brief Set color of rendered arrow
@ -55,7 +55,7 @@ class ForceRendererOptions {
* *
* Default is 100% opaque white. * Default is 100% opaque white.
*/ */
ForceRendererOptions* setColor(const Color4<>& color) { ForceRendererOptions* setColor(const Color4& color) {
_color = color; _color = color;
return this; return this;
} }
@ -75,7 +75,7 @@ class ForceRendererOptions {
} }
private: private:
Color4<> _color; Color4 _color;
Float _size; Float _size;
}; };
@ -91,7 +91,7 @@ Example code:
@code @code
// Create some options // Create some options
DebugTools::ResourceManager::instance()->set("my", (new DebugTools::ForceRendererOptions) 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 // Create debug renderer for given object, use "my" options for it
Object3D* object; Object3D* object;

8
src/DebugTools/ObjectRenderer.cpp

@ -43,7 +43,7 @@ template<> struct Renderer<2> {
static ResourceKey mesh() { return {"object2d"}; } static ResourceKey mesh() { return {"object2d"}; }
static const std::array<Vector2, 8> positions; static const std::array<Vector2, 8> positions;
static const std::array<Color3<>, 8> colors; static const std::array<Color3, 8> colors;
static const std::array<UnsignedByte, 12> indices; static const std::array<UnsignedByte, 12> indices;
}; };
@ -59,7 +59,7 @@ const std::array<Vector2, 8> Renderer<2>::positions{{
{-0.1f, 0.9f} {-0.1f, 0.9f}
}}; }};
const std::array<Color3<>, 8> Renderer<2>::colors{{ const std::array<Color3, 8> Renderer<2>::colors{{
{1.0f, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f},
{1.0f, 0.0f, 0.0f}, /* X axis */ {1.0f, 0.0f, 0.0f}, /* X axis */
{1.0f, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f},
@ -88,7 +88,7 @@ template<> struct Renderer<3> {
static ResourceKey mesh() { return {"object3d"}; } static ResourceKey mesh() { return {"object3d"}; }
static const std::array<Vector3, 12> positions; static const std::array<Vector3, 12> positions;
static const std::array<Color3<>, 12> colors; static const std::array<Color3, 12> colors;
static const std::array<uint8_t, 18> indices; static const std::array<uint8_t, 18> indices;
}; };
@ -109,7 +109,7 @@ const std::array<Vector3, 12> Renderer<3>::positions{{
{-0.1f, 0.0f, 0.9f} {-0.1f, 0.0f, 0.9f}
}}; }};
const std::array<Color3<>, 12> Renderer<3>::colors{{ const std::array<Color3, 12> Renderer<3>::colors{{
{1.0f, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f},
{1.0f, 0.0f, 0.0f}, /* X axis */ {1.0f, 0.0f, 0.0f}, /* X axis */
{1.0f, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f},

6
src/DebugTools/ShapeRenderer.h

@ -83,7 +83,7 @@ class ShapeRendererOptions {
} }
/** @brief Color of rendered shape */ /** @brief Color of rendered shape */
constexpr Color4<> color() const { return _color; } constexpr Color4 color() const { return _color; }
/** /**
* @brief Set color of rendered shape * @brief Set color of rendered shape
@ -91,7 +91,7 @@ class ShapeRendererOptions {
* *
* Default is 100% opaque white. * Default is 100% opaque white.
*/ */
ShapeRendererOptions* setColor(const Color4<>& color) { ShapeRendererOptions* setColor(const Color4& color) {
_color = color; _color = color;
return this; return this;
} }
@ -112,7 +112,7 @@ class ShapeRendererOptions {
} }
private: private:
Color4<> _color; Color4 _color;
Float _pointSize; Float _pointSize;
RenderMode _renderMode; RenderMode _renderMode;
}; };

6
src/Magnum.h

@ -352,8 +352,10 @@ class BufferTexture;
enum class BufferTextureFormat: GLenum; enum class BufferTextureFormat: GLenum;
#endif #endif
template<class T = Float> class Color3; template<class> class BasicColor3;
template<class T = Float> class Color4; template<class> class BasicColor4;
typedef BasicColor3<Float> Color3;
typedef BasicColor4<Float> Color4;
enum class Version: Int; enum class Version: Int;
class Context; class Context;

2
src/Mesh.h

@ -173,7 +173,7 @@ mesh->setPrimitive(plane.primitive())
class MyShader: public AbstractShaderProgram { class MyShader: public AbstractShaderProgram {
public: public:
typedef Attribute<0, Vector3> Position; typedef Attribute<0, Vector3> Position;
typedef Attribute<1, Color4<>> Color; typedef Attribute<1, Color4> Color;
// ... // ...
}; };

2
src/MeshTools/Interleave.h

@ -160,7 +160,7 @@ achieve that, you can specify gaps between the attributes:
@code @code
std::vector<Vector4> positions; std::vector<Vector4> positions;
std::vector<GLushort> weights; std::vector<GLushort> weights;
std::vector<Color3<GLubyte>> vertexColors; std::vector<BasicColor3<GLubyte>> vertexColors;
std::size_t attributeCount; std::size_t attributeCount;
std::size_t stride; std::size_t stride;
char* data; char* data;

4
src/Renderer.cpp

@ -50,7 +50,7 @@ void Renderer::setHint(const Hint target, const HintMode mode) {
glHint(GLenum(target), GLenum(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()); 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)); 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()); glBlendColor(color.r(), color.g(), color.b(), color.a());
} }

4
src/Renderer.h

@ -238,7 +238,7 @@ class MAGNUM_EXPORT Renderer {
* Initial value is fully opaque black. * Initial value is fully opaque black.
* @see @fn_gl{ClearColor} * @see @fn_gl{ClearColor}
*/ */
static void setClearColor(const Color4<>& color); static void setClearColor(const Color4& color);
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
/** /**
@ -809,7 +809,7 @@ class MAGNUM_EXPORT Renderer {
* @see @ref Feature "Feature::Blending", setBlendEquation(), * @see @ref Feature "Feature::Blending", setBlendEquation(),
* setBlendFunction(), @fn_gl{BlendColor} * setBlendFunction(), @fn_gl{BlendColor}
*/ */
static void setBlendColor(const Color4<>& color); static void setBlendColor(const Color4& color);
/*@}*/ /*@}*/

4
src/Shaders/DistanceFieldVector.h

@ -63,7 +63,7 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT DistanceFieldVector
* *
* @see setOutlineColor() * @see setOutlineColor()
*/ */
DistanceFieldVector* setColor(const Color4<>& color) { DistanceFieldVector* setColor(const Color4& color) {
AbstractShaderProgram::setUniform(colorUniform, color); AbstractShaderProgram::setUniform(colorUniform, color);
return this; return this;
} }
@ -74,7 +74,7 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT DistanceFieldVector
* *
* @see setOutlineRange(), setColor() * @see setOutlineRange(), setColor()
*/ */
DistanceFieldVector* setOutlineColor(const Color4<>& color) { DistanceFieldVector* setOutlineColor(const Color4& color) {
AbstractShaderProgram::setUniform(outlineColorUniform, color); AbstractShaderProgram::setUniform(outlineColorUniform, color);
return this; return this;
} }

2
src/Shaders/Flat.h

@ -64,7 +64,7 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT Flat: public Abstra
* @brief Set color * @brief Set color
* @return Pointer to self (for method chaining) * @return Pointer to self (for method chaining)
*/ */
Flat<dimensions>* setColor(const Color4<>& color) { Flat<dimensions>* setColor(const Color4& color) {
setUniform(colorUniform, color); setUniform(colorUniform, color);
return this; return this;
} }

4
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) */ /* 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);
} }

4
src/Shaders/MeshVisualizer.h

@ -138,7 +138,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;
} }
@ -150,7 +150,7 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizer: public AbstractShaderProgram {
* Initial value is fully opaque black. Has effect only if * Initial value is fully opaque black. Has effect only if
* @ref Flag "Flag::Wireframe" is enabled. * @ref Flag "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;
} }

8
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)`. * 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); setUniform(ambientColorUniform, color);
return this; return this;
} }
@ -64,7 +64,7 @@ class MAGNUM_SHADERS_EXPORT Phong: public AbstractShaderProgram {
* @brief Set diffuse color * @brief Set diffuse color
* @return Pointer to self (for method chaining) * @return Pointer to self (for method chaining)
*/ */
Phong* setDiffuseColor(const Color3<>& color) { Phong* setDiffuseColor(const Color3& color) {
setUniform(diffuseColorUniform, color); setUniform(diffuseColorUniform, color);
return this; 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)`. * 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); setUniform(specularColorUniform, color);
return this; 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)`. * 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); setUniform(lightColorUniform, color);
return this; return this;
} }

2
src/Shaders/Vector.h

@ -60,7 +60,7 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT Vector: public Abst
* @brief Set fill color * @brief Set fill color
* @return Pointer to self (for method chaining) * @return Pointer to self (for method chaining)
*/ */
Vector* setColor(const Color4<>& color) { Vector* setColor(const Color4& color) {
AbstractShaderProgram::setUniform(colorUniform, color); AbstractShaderProgram::setUniform(colorUniform, color);
return this; return this;
} }

2
src/Shaders/VertexColor.h

@ -50,7 +50,7 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT VertexColor: public
typedef Attribute<0, typename DimensionTraits<dimensions>::VectorType> Position; typedef Attribute<0, typename DimensionTraits<dimensions>::VectorType> Position;
/** @brief Vertex color */ /** @brief Vertex color */
typedef Attribute<1, Color3<>> Color; typedef Attribute<1, Color3> Color;
explicit VertexColor(); explicit VertexColor();

8
src/Swizzle.h

@ -47,10 +47,10 @@ namespace Implementation {
template<class T> struct TypeForSize<2, T> { typedef Math::Vector2<typename T::Type> Type; }; template<class T> struct TypeForSize<2, T> { typedef Math::Vector2<typename T::Type> Type; };
template<class T> struct TypeForSize<3, T> { typedef Math::Vector3<typename T::Type> Type; }; template<class T> struct TypeForSize<3, T> { typedef Math::Vector3<typename T::Type> Type; };
template<class T> struct TypeForSize<4, T> { typedef Math::Vector4<typename T::Type> Type; }; template<class T> struct TypeForSize<4, T> { typedef Math::Vector4<typename T::Type> Type; };
template<class T> struct TypeForSize<3, Color3<T>> { typedef Color3<T> Type; }; template<class T> struct TypeForSize<3, BasicColor3<T>> { typedef BasicColor3<T> Type; };
template<class T> struct TypeForSize<3, Color4<T>> { typedef Color3<T> Type; }; template<class T> struct TypeForSize<3, BasicColor4<T>> { typedef BasicColor3<T> Type; };
template<class T> struct TypeForSize<4, Color3<T>> { typedef Color4<T> Type; }; template<class T> struct TypeForSize<4, BasicColor3<T>> { typedef BasicColor4<T> Type; };
template<class T> struct TypeForSize<4, Color4<T>> { typedef Color4<T> Type; }; template<class T> struct TypeForSize<4, BasicColor4<T>> { typedef BasicColor4<T> Type; };
} }
/** /**

94
src/Test/ColorTest.cpp

@ -52,10 +52,8 @@ class ColorTest: public TestSuite::Tester {
void configuration(); void configuration();
}; };
typedef Magnum::Color3<UnsignedByte> Color3; typedef Magnum::BasicColor3<UnsignedByte> Color3ub;
typedef Magnum::Color4<UnsignedByte> Color4; typedef Magnum::BasicColor4<UnsignedByte> Color4ub;
typedef Magnum::Color3<Float> Color3f;
typedef Magnum::Color4<Float> Color4f;
ColorTest::ColorTest() { ColorTest::ColorTest() {
addTests({&ColorTest::access, addTests({&ColorTest::access,
@ -77,8 +75,8 @@ ColorTest::ColorTest() {
} }
void ColorTest::access() { void ColorTest::access() {
Color3f c3(15, 255, 10); Color3ub c3(15, 255, 10);
const Color3f cc3(15, 255, 10); const Color3ub cc3(15, 255, 10);
CORRADE_COMPARE(c3.r(), 15); CORRADE_COMPARE(c3.r(), 15);
CORRADE_COMPARE(c3.g(), 255); CORRADE_COMPARE(c3.g(), 255);
@ -87,8 +85,8 @@ void ColorTest::access() {
CORRADE_COMPARE(cc3.g(), 255); CORRADE_COMPARE(cc3.g(), 255);
CORRADE_COMPARE(cc3.b(), 10); CORRADE_COMPARE(cc3.b(), 10);
Color4 c4(125, 98, 51, 22); Color4ub c4(125, 98, 51, 22);
const Color4f cc4(125, 98, 51, 22); const Color4ub cc4(125, 98, 51, 22);
CORRADE_COMPARE(c4.r(), 125); CORRADE_COMPARE(c4.r(), 125);
CORRADE_COMPARE(c4.g(), 98); CORRADE_COMPARE(c4.g(), 98);
@ -101,98 +99,98 @@ void ColorTest::access() {
} }
void ColorTest::fromHue() { void ColorTest::fromHue() {
CORRADE_COMPARE(Color3::fromHSV(Deg(27.0f), 1.0f, 1.0f), Color3(255, 114, 0)); CORRADE_COMPARE(Color3ub::fromHSV(Deg(27.0f), 1.0f, 1.0f), Color3ub(255, 114, 0));
CORRADE_COMPARE(Color3::fromHSV(Deg(86.0f), 1.0f, 1.0f), Color3(144, 255, 0)); CORRADE_COMPARE(Color3ub::fromHSV(Deg(86.0f), 1.0f, 1.0f), Color3ub(144, 255, 0));
CORRADE_COMPARE(Color3::fromHSV(Deg(134.0f), 1.0f, 1.0f), Color3(0, 255, 59)); CORRADE_COMPARE(Color3ub::fromHSV(Deg(134.0f), 1.0f, 1.0f), Color3ub(0, 255, 59));
CORRADE_COMPARE(Color3::fromHSV(Deg(191.0f), 1.0f, 1.0f), Color3(0, 208, 255)); CORRADE_COMPARE(Color3ub::fromHSV(Deg(191.0f), 1.0f, 1.0f), Color3ub(0, 208, 255));
CORRADE_COMPARE(Color3::fromHSV(Deg(269.0f), 1.0f, 1.0f), Color3(123, 0, 255)); CORRADE_COMPARE(Color3ub::fromHSV(Deg(269.0f), 1.0f, 1.0f), Color3ub(123, 0, 255));
CORRADE_COMPARE(Color3::fromHSV(Deg(317.0f), 1.0f, 1.0f), Color3(255, 0, 182)); CORRADE_COMPARE(Color3ub::fromHSV(Deg(317.0f), 1.0f, 1.0f), Color3ub(255, 0, 182));
} }
void ColorTest::hue() { void ColorTest::hue() {
CORRADE_COMPARE(Color3(255, 115, 0).hue(), Deg(27.058824f)); CORRADE_COMPARE(Color3ub(255, 115, 0).hue(), Deg(27.058824f));
CORRADE_COMPARE(Color3(145, 255, 0).hue(), Deg(85.882353f)); CORRADE_COMPARE(Color3ub(145, 255, 0).hue(), Deg(85.882353f));
CORRADE_COMPARE(Color3(0, 255, 60).hue(), Deg(134.11765f)); CORRADE_COMPARE(Color3ub(0, 255, 60).hue(), Deg(134.11765f));
CORRADE_COMPARE(Color3(0, 208, 255).hue(), Deg(191.05882f)); CORRADE_COMPARE(Color3ub(0, 208, 255).hue(), Deg(191.05882f));
CORRADE_COMPARE(Color3(123, 0, 255).hue(), Deg(268.94117f)); CORRADE_COMPARE(Color3ub(123, 0, 255).hue(), Deg(268.94117f));
CORRADE_COMPARE(Color3(255, 0, 183).hue(), Deg(316.94117f)); CORRADE_COMPARE(Color3ub(255, 0, 183).hue(), Deg(316.94117f));
} }
void ColorTest::fromSaturation() { 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() { void ColorTest::saturation() {
CORRADE_COMPARE(Color3(255, 76, 76).saturation(), 0.701961f); CORRADE_COMPARE(Color3ub(255, 76, 76).saturation(), 0.701961f);
CORRADE_COMPARE(Color3().saturation(), 0.0f); CORRADE_COMPARE(Color3ub().saturation(), 0.0f);
} }
void ColorTest::fromValue() { 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() { void ColorTest::value() {
CORRADE_COMPARE(Color3(133, 0, 0).value(), 0.521569f); CORRADE_COMPARE(Color3ub(133, 0, 0).value(), 0.521569f);
} }
void ColorTest::hsv() { 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; Deg hue;
Float saturation, value; 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(hue, Deg(229.756106f));
CORRADE_COMPARE(saturation, 0.752294f); CORRADE_COMPARE(saturation, 0.752294f);
CORRADE_COMPARE(value, 0.427451f); CORRADE_COMPARE(value, 0.427451f);
} }
void ColorTest::hsvOverflow() { void ColorTest::hsvOverflow() {
CORRADE_COMPARE(Color3::fromHSV(Deg(27.0f-360.0f), 1.0f, 1.0f), Color3(255, 114, 0)); CORRADE_COMPARE(Color3ub::fromHSV(Deg(27.0f-360.0f), 1.0f, 1.0f), Color3ub(255, 114, 0));
CORRADE_COMPARE(Color3::fromHSV(Deg(86.0f-360.0f), 1.0f, 1.0f), Color3(144, 255, 0)); CORRADE_COMPARE(Color3ub::fromHSV(Deg(86.0f-360.0f), 1.0f, 1.0f), Color3ub(144, 255, 0));
CORRADE_COMPARE(Color3::fromHSV(Deg(134.0f-360.0f), 1.0f, 1.0f), Color3(0, 255, 59)); CORRADE_COMPARE(Color3ub::fromHSV(Deg(134.0f-360.0f), 1.0f, 1.0f), Color3ub(0, 255, 59));
CORRADE_COMPARE(Color3::fromHSV(Deg(191.0f-360.0f), 1.0f, 1.0f), Color3(0, 208, 255)); CORRADE_COMPARE(Color3ub::fromHSV(Deg(191.0f-360.0f), 1.0f, 1.0f), Color3ub(0, 208, 255));
CORRADE_COMPARE(Color3::fromHSV(Deg(269.0f-360.0f), 1.0f, 1.0f), Color3(123, 0, 255)); CORRADE_COMPARE(Color3ub::fromHSV(Deg(269.0f-360.0f), 1.0f, 1.0f), Color3ub(123, 0, 255));
CORRADE_COMPARE(Color3::fromHSV(Deg(317.0f-360.0f), 1.0f, 1.0f), Color3(255, 0, 182)); CORRADE_COMPARE(Color3ub::fromHSV(Deg(317.0f-360.0f), 1.0f, 1.0f), Color3ub(255, 0, 182));
CORRADE_COMPARE(Color3::fromHSV(Deg(360.0f+27.0f), 1.0f, 1.0f), Color3(255, 114, 0)); CORRADE_COMPARE(Color3ub::fromHSV(Deg(360.0f+27.0f), 1.0f, 1.0f), Color3ub(255, 114, 0));
CORRADE_COMPARE(Color3::fromHSV(Deg(360.0f+86.0f), 1.0f, 1.0f), Color3(144, 255, 0)); CORRADE_COMPARE(Color3ub::fromHSV(Deg(360.0f+86.0f), 1.0f, 1.0f), Color3ub(144, 255, 0));
CORRADE_COMPARE(Color3::fromHSV(Deg(360.0f+134.0f), 1.0f, 1.0f), Color3(0, 255, 59)); CORRADE_COMPARE(Color3ub::fromHSV(Deg(360.0f+134.0f), 1.0f, 1.0f), Color3ub(0, 255, 59));
CORRADE_COMPARE(Color3::fromHSV(Deg(360.0f+191.0f), 1.0f, 1.0f), Color3(0, 208, 255)); CORRADE_COMPARE(Color3ub::fromHSV(Deg(360.0f+191.0f), 1.0f, 1.0f), Color3ub(0, 208, 255));
CORRADE_COMPARE(Color3::fromHSV(Deg(360.0f+269.0f), 1.0f, 1.0f), Color3(123, 0, 255)); CORRADE_COMPARE(Color3ub::fromHSV(Deg(360.0f+269.0f), 1.0f, 1.0f), Color3ub(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(360.0f+317.0f), 1.0f, 1.0f), Color3ub(255, 0, 182));
} }
void ColorTest::hsvAlpha() { 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(Color4ub::fromHSV(std::make_tuple(Deg(230.0f), 0.749f, 0.427f), 23), Color4ub(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(Deg(230.0f), 0.749f, 0.427f, 23), Color4ub(27, 40, 108, 23));
} }
void ColorTest::debug() { void ColorTest::debug() {
std::ostringstream o; 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"); CORRADE_COMPARE(o.str(), "Vector(0.5, 0.75, 1)\n");
o.str({}); 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"); CORRADE_COMPARE(o.str(), "Vector(0.5, 0.75, 0, 1)\n");
} }
void ColorTest::configuration() { void ColorTest::configuration() {
Utility::Configuration c; 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"); std::string value3("0.5 0.75 1");
c.setValue("color3", color3); c.setValue("color3", color3);
CORRADE_COMPARE(c.value("color3"), value3); CORRADE_COMPARE(c.value("color3"), value3);
CORRADE_COMPARE(c.value<Color3f>("color3"), color3); CORRADE_COMPARE(c.value<Color3>("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"); std::string value4("0.5 0.75 0 1");
c.setValue("color4", color4); c.setValue("color4", color4);
CORRADE_COMPARE(c.value("color4"), value4); CORRADE_COMPARE(c.value("color4"), value4);
CORRADE_COMPARE(c.value<Color4f>("color4"), color4); CORRADE_COMPARE(c.value<Color4>("color4"), color4);
} }
}} }}

12
src/Test/SwizzleTest.cpp

@ -50,8 +50,8 @@ void SwizzleTest::rgba() {
void SwizzleTest::type() { void SwizzleTest::type() {
constexpr Vector4i orig; constexpr Vector4i orig;
constexpr Color3<Float> origColor3; constexpr Color3 origColor3;
constexpr Color4<UnsignedByte> origColor4; constexpr BasicColor4<UnsignedByte> origColor4;
constexpr auto a = swizzle<'y', 'a'>(orig); constexpr auto a = swizzle<'y', 'a'>(orig);
CORRADE_VERIFY((std::is_same<decltype(a), const Vector2i>::value)); CORRADE_VERIFY((std::is_same<decltype(a), const Vector2i>::value));
@ -63,16 +63,16 @@ void SwizzleTest::type() {
CORRADE_VERIFY((std::is_same<decltype(c), const Vector4i>::value)); CORRADE_VERIFY((std::is_same<decltype(c), const Vector4i>::value));
constexpr auto d = swizzle<'y', 'z', 'r'>(origColor3); constexpr auto d = swizzle<'y', 'z', 'r'>(origColor3);
CORRADE_VERIFY((std::is_same<decltype(d), const Color3<Float>>::value)); CORRADE_VERIFY((std::is_same<decltype(d), const Color3>::value));
constexpr auto e = swizzle<'y', 'z', 'a'>(origColor4); constexpr auto e = swizzle<'y', 'z', 'a'>(origColor4);
CORRADE_VERIFY((std::is_same<decltype(e), const Color3<UnsignedByte>>::value)); CORRADE_VERIFY((std::is_same<decltype(e), const BasicColor3<UnsignedByte>>::value));
constexpr auto f = swizzle<'y', 'z', 'y', 'x'>(origColor3); constexpr auto f = swizzle<'y', 'z', 'y', 'x'>(origColor3);
CORRADE_VERIFY((std::is_same<decltype(f), const Color4<Float>>::value)); CORRADE_VERIFY((std::is_same<decltype(f), const Color4>::value));
constexpr auto g = swizzle<'y', 'a', 'y', 'x'>(origColor4); constexpr auto g = swizzle<'y', 'a', 'y', 'x'>(origColor4);
CORRADE_VERIFY((std::is_same<decltype(g), const Color4<UnsignedByte>>::value)); CORRADE_VERIFY((std::is_same<decltype(g), const BasicColor4<UnsignedByte>>::value));
} }
void SwizzleTest::defaultType() { void SwizzleTest::defaultType() {

2
src/Texture.h

@ -427,7 +427,7 @@ template<UnsignedInt dimensions> class Texture: public AbstractTexture {
return this; return this;
} }
#ifndef MAGNUM_TARGET_GLES3 #ifndef MAGNUM_TARGET_GLES3
Texture<Dimensions>* setBorderColor(const Color4<>& color) { Texture<Dimensions>* setBorderColor(const Color4& color) {
AbstractTexture::setBorderColor(color); AbstractTexture::setBorderColor(color);
return this; return this;
} }

Loading…
Cancel
Save