Nebula
Loading...
Searching...
No Matches
color.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
11#include "core/types.h"
12#include "math/vec4.h"
13
14//------------------------------------------------------------------------------
15namespace Util
16{
17class Color : public Math::vec4
18{
19public:
21 Color() = default;
23 Color(const Color& c) = default;
25 Color(float r, float g, float b, float a);
27 Color(const Math::vec4& v);
29 Color(const Math::vec3& v);
31 Color(uint32_t argb);
33 explicit Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
35 static Color RGBA(uint32_t rgba);
37 static Color ARGB(uint32_t argb);
38
39 // predefined, common colors.
40
42 static const Color red;
44 static const Color green;
46 static const Color blue;
48 static const Color yellow;
50 static const Color purple;
52 static const Color orange;
54 static const Color black;
56 static const Color white;
58 static const Color gray;
59};
60
61//------------------------------------------------------------------------------
64__forceinline
65Color::Color(float r, float g, float b, float a)
66 : Math::vec4(r, g, b, a)
67{
68 // empty
69}
70
71//------------------------------------------------------------------------------
74__forceinline
76 : Math::vec4(v)
77{
78 // empty
79}
80
81//------------------------------------------------------------------------------
84__forceinline
86 : Math::vec4(v, 1.0f)
87{
88 // empty
89}
90
91//------------------------------------------------------------------------------
94__forceinline
95Color::Color(uint32_t argb)
96{
97 const float scale = 1.0f / 255.0f;
98 this->vec = _mm_setr_ps(
99 scale * ((argb >> 16) & 0xFF), scale * ((argb >> 8) & 0xFF), scale * (argb & 0xFF), scale * ((argb >> 24) & 0xFF)
100 );
101}
102//------------------------------------------------------------------------------
105__forceinline
106Color::Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
107{
108 const float scale = 1.0f / 255.0f;
109 this->vec = _mm_setr_ps(scale * r, scale * g, scale * b, scale * a);
110}
111
112//--------------------------------------------------------------------------
115__forceinline Color
116Color::RGBA(uint32_t rgba)
117{
118 return Color((uint8_t)((rgba >> 24) & 0xFF), (uint8_t)((rgba >> 16) & 0xFF), (uint8_t)((rgba >> 8) & 0xFF), (uint8_t)(rgba & 0xFF));
119}
120
121//--------------------------------------------------------------------------
124__forceinline Color
125Color::ARGB(uint32_t argb)
126{
127 return Color(argb);
128}
129
130} // namespace Util
Represents colors by four single point (32-bit) floating point numbers.
Definition color.h:18
Color()=default
static const Color blue
Predefined color. (0x0000FF)
Definition color.h:46
static const Color green
Predefined color. (0x00FF00)
Definition color.h:44
static const Color yellow
Predefined color. (0xFFFF00)
Definition color.h:48
static const Color purple
Predefined color. (0xA020F0)
Definition color.h:50
static Color ARGB(uint32_t argb)
Create color from unsigned int (R|G|B|A) -> 0..1 floats.
Definition color.h:125
static const Color white
Predefined color. (0xFFFFFF)
Definition color.h:56
static Color RGBA(uint32_t rgba)
Create color from unsigned int (A|R|G|B) -> 0..1 floats.
Definition color.h:116
static const Color gray
Predefined color. (0xBEBEBE)
Definition color.h:58
static const Color red
Predefined color. (0xFF0000)
Definition color.h:42
static const Color black
Predefined color. (0x000000)
Definition color.h:54
Color(const Color &c)=default
static const Color orange
Predefined color. (0xFFA500)
Definition color.h:52
Different curves.
Definition angularpfeedbackloop.h:17
A pinned array is an array which manages its own virtual memory.
Definition String.cs:6
A 3D vector.
Definition vec3.h:40
A 4D vector.
Definition vec4.h:24
vec4()=default
default constructor, NOTE: does NOT setup components!
__m128 vec
Definition vec4.h:97
float v[4]
Definition vec4.h:98