-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColor.h
68 lines (51 loc) · 1.57 KB
/
Color.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#pragma once
#include "vec3.h"
struct Color
{
public:
unsigned int rgba = 0x0F000000;
void SetR(unsigned int r) restrict(amp, cpu) { rgba = rgba | ((r & 0xFF)); }
void SetG(unsigned int g) restrict(amp, cpu) { rgba = rgba | ((g & 0xFF) << 8); }
void SetB(unsigned int b) restrict(amp, cpu) { rgba = rgba | ((b & 0xFF) << 16); }
unsigned int GetR()restrict(amp, cpu) { return (rgba) & 0xFF; }
unsigned int GetG()restrict(amp, cpu) { return (rgba >> 8) & 0xFF; }
unsigned int GetB()restrict(amp, cpu) { return (rgba >> 16) & 0xFF; }
Vec3 GetRGB() restrict(amp, cpu) { return Vec3(GetR(), GetG(), GetB()); }
Color(unsigned int r, unsigned int g, unsigned int b) restrict(amp, cpu)
{
rgba |= ((b & 0xFF) << 16) | ((g & 0xFF) << 8) | ((r & 0xFF));
}
Color operator+(Color c) restrict(amp, cpu)
{
unsigned int b1 = (rgba >> 16) & 0xFF,
g1 = (rgba >> 8) & 0xFF,
r1 = rgba & 0xFF;
unsigned int b2 = (c.rgba >> 16) & 0xFF,
g2 = (c.rgba >> 8) & 0xFF,
r2 = c.rgba & 0xFF;
return Color(r1 + r2, g1 + g2, b1 + b2);
}
Color operator *(float f) restrict(amp, cpu)
{
unsigned int b = (rgba >> 16) & 0xFF,
g = (rgba >> 8) & 0xFF,
r = rgba & 0xFF;
return Color(r * f, g * f, b * f);
}
Color operator *(Vec3 f) restrict(amp, cpu)
{
unsigned int b = (rgba >> 16) & 0xFF,
g = (rgba >> 8) & 0xFF,
r = rgba & 0xFF;
return Color(r * f.x, g * f.y, b * f.z);
}
};
#ifndef __Colors
#define __Colors
Color Custom1(50,50,50);
Color White(255, 255, 255);
Color Black(0, 0, 0);
Color Red(255, 0, 0);
Color Green(0, 255, 0);
Color Blue(0, 0, 255);
#endif // !Colors