SEGS  0.6.1-develop [3e741b81]
Super Entity Game Server
Colors.h
Go to the documentation of this file.
1 /*
2  * SEGS - Super Entity Game Server
3  * http://www.segs.io/
4  * Copyright (c) 2006 - 2019 SEGS Team (see AUTHORS.md)
5  * This software is licensed under the terms of the 3-clause BSD License. See LICENSE.md for details.
6  */
7 
8 #pragma once
9 #include <glm/vec3.hpp>
10 #include <glm/vec4.hpp>
11 #include <stdint.h>
12 
13 struct ARGB
14 {
15  union
16  {
17  uint8_t v[4];
18  uint32_t val;
19  struct { uint8_t a,r,g,b;} argb;
20  };
21  ARGB() {}
22  ARGB(uint32_t _v) { val =_v;}
23 };
24 struct URG {
25  uint32_t v;
26  URG & operator=(uint32_t x) {
27  v=x;
28  return *this;
29  }
30  URG(uint32_t _clr=0) : v(_clr) {}
31  URG(uint8_t r,uint8_t g,uint8_t b,uint8_t a) {
32  v = uint32_t(r) |
33  (uint32_t(g)<<8) |
34  (uint32_t(b)<<16) |
35  (uint32_t(a)<<24);
36  }
37  //my_groupfileload_4C2460 thinks v&0xFF is alpha
38  //my_light_493560 thinks otherwise ??
39  uint8_t R() const { return v & 0xFF; }
40  uint8_t G() const { return (v>>8) & 0xFF; }
41  uint8_t B() const { return (v>>16) & 0xFF; }
42  uint8_t A() const { return (v>>24) & 0xFF; }
43 
44 };
45 #pragma pack(push,1)
46 struct RGB
47 {
48  uint8_t R,G,B;
49  uint8_t &operator[](size_t idx)
50  {
51  assert(idx<3);
52  if(idx==0)
53  return R;
54  if(idx==1)
55  return G;
56  return B;
57  }
58 };
59 #pragma pack(pop)
60 static_assert(sizeof(RGB)==3,"sizeof(RGB)==3");
61 
62 struct RGBA
63 {
64  union
65  {
66  uint8_t v[4];
67  uint32_t val;
68  struct { uint8_t r,g,b,a;} rgba;
69  struct { uint8_t x,y,z,w;} xyzw ;
70  };
71  RGBA(uint8_t r_,uint8_t g_,uint8_t b_,uint8_t a_) {
72  rgba.r = r_;
73  rgba.g = g_;
74  rgba.b = b_;
75  rgba.a = a_;
76  }
77  RGBA() {}
78  RGBA(uint32_t v) {
79  rgba.a = v & 0xFF;
80  v>>=8;
81  rgba.b = v & 0xFF;
82  v>>=8;
83  rgba.g = v & 0xFF;
84  v>>=8;
85  rgba.r = v & 0xFF;
86  }
87  RGBA &operator=(uint32_t v) {
88  rgba.a = v & 0xFF;
89  v>>=8;
90  rgba.b = v & 0xFF;
91  v>>=8;
92  rgba.g = v & 0xFF;
93  v>>=8;
94  rgba.r = v & 0xFF;
95  return *this;
96  }
98  rgba.b = v.B;
99  rgba.g = v.G;
100  rgba.r = v.R;
101  return *this;
102  }
103  bool rgb_are_zero() const { return !(rgba.r|rgba.g|rgba.b); }
104  uint8_t &operator[](uint8_t idx) { return v[idx];}
105  glm::vec4 toFloats() const { return glm::vec4(
106  rgba.r/255.0f,rgba.g/255.0f,rgba.b/255.0f,rgba.a/255.0f); }
107  glm::vec3 to3Floats() const { return glm::vec3(
108  rgba.r/255.0f,rgba.g/255.0f,rgba.b/255.0f); }
109  RGB toRGB() const { return {rgba.r,rgba.g,rgba.b}; }
110 };
111 static_assert(sizeof(RGBA)==4,"sizeof(RGBA)==4");
uint8_t r
Definition: Colors.h:19
Definition: Colors.h:62
uint8_t g
Definition: Colors.h:19
uint8_t G() const
Definition: Colors.h:40
uint8_t b
Definition: Colors.h:68
uint32_t v
Definition: Colors.h:25
uint8_t a
Definition: Colors.h:19
RGBA(uint32_t v)
Definition: Colors.h:78
uint8_t R
Definition: Colors.h:48
URG & operator=(uint32_t x)
Definition: Colors.h:26
struct ARGB::@0::@2 argb
ARGB(uint32_t _v)
Definition: Colors.h:22
URG(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
Definition: Colors.h:31
uint8_t R() const
Definition: Colors.h:39
uint8_t r
Definition: Colors.h:68
uint8_t G
Definition: Colors.h:48
uint8_t b
Definition: Colors.h:19
glm::vec4 toFloats() const
Definition: Colors.h:105
uint32_t val
Definition: Colors.h:18
URG(uint32_t _clr=0)
Definition: Colors.h:30
ARGB()
Definition: Colors.h:21
RGBA & operator=(RGB v)
Definition: Colors.h:97
uint8_t B
Definition: Colors.h:48
uint8_t z
Definition: Colors.h:69
Definition: Colors.h:46
Definition: Colors.h:24
uint8_t B() const
Definition: Colors.h:41
Definition: Colors.h:13
RGBA()
Definition: Colors.h:77
uint8_t v[4]
Definition: Colors.h:17
uint8_t & operator[](uint8_t idx)
Definition: Colors.h:104
uint8_t a
Definition: Colors.h:68
uint8_t & operator[](size_t idx)
Definition: Colors.h:49
uint8_t A() const
Definition: Colors.h:42
uint32_t val
Definition: Colors.h:67
glm::vec3 to3Floats() const
Definition: Colors.h:107
RGBA & operator=(uint32_t v)
Definition: Colors.h:87
bool rgb_are_zero() const
Definition: Colors.h:103
RGBA(uint8_t r_, uint8_t g_, uint8_t b_, uint8_t a_)
Definition: Colors.h:71
RGB toRGB() const
Definition: Colors.h:109