SEGS  0.4.2
Super Entity Game Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 - 2018 SEGS Team (see Authors.txt)
5  * This software is licensed! (See License.txt 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;};
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;};
69  struct { uint8_t x,y,z,w;};
70  };
71  RGBA(uint8_t r_,uint8_t g_,uint8_t b_,uint8_t a_) : r(r_),g(g_),b(b_),a(a_) {}
72  RGBA() {}
73  RGBA(uint32_t v) {
74  a = v & 0xFF;
75  v>>=8;
76  b = v & 0xFF;
77  v>>=8;
78  g = v & 0xFF;
79  v>>=8;
80  r = v & 0xFF;
81  }
82  RGBA &operator=(uint32_t v) {
83  a = v & 0xFF;
84  v>>=8;
85  b = v & 0xFF;
86  v>>=8;
87  g = v & 0xFF;
88  v>>=8;
89  r = v & 0xFF;
90  return *this;
91  }
93  b = v.B;
94  g = v.G;
95  r = v.R;
96  return *this;
97  }
98  bool rgb_are_zero() const { return !(r|g|b); }
99  uint8_t &operator[](uint8_t idx) { return v[idx];}
100  glm::vec4 toFloats() const { return glm::vec4(r/255.0f,g/255.0f,b/255.0f,a/255.0f); }
101  glm::vec3 to3Floats() const { return glm::vec3(r/255.0f,g/255.0f,b/255.0f); }
102  RGB toRGB() const { return {r,g,b}; }
103 };
104 
105 //static_assert(offsetof(RGBA,r)==0,"");
106 //static_assert(offsetof(RGBA,g)==1,"");
107 //static_assert(offsetof(RGBA,b)==2,"");
108 //static_assert(offsetof(RGBA,a)==3,"");
109 
110 static_assert(sizeof(RGBA)==4,"sizeof(RGBA)==4");
uint8_t r
Definition: Colors.h:19
Definition: Colors.h:62
RGB toRGB() const
Definition: Colors.h:102
uint8_t v[4]
Definition: Colors.h:66
uint8_t g
Definition: Colors.h:19
uint8_t B() const
Definition: Colors.h:41
uint8_t b
Definition: Colors.h:68
uint8_t y
Definition: Colors.h:69
uint32_t v
Definition: Colors.h:25
uint8_t a
Definition: Colors.h:19
RGBA(uint32_t v)
Definition: Colors.h:73
uint8_t R
Definition: Colors.h:48
URG & operator=(uint32_t x)
Definition: Colors.h:26
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
Definition: Colors.h:68
uint8_t G
Definition: Colors.h:48
uint8_t b
Definition: Colors.h:19
glm::vec3 to3Floats() const
Definition: Colors.h:101
bool rgb_are_zero() const
Definition: Colors.h:98
uint32_t val
Definition: Colors.h:18
URG(uint32_t _clr=0)
Definition: Colors.h:30
uint8_t x
Definition: Colors.h:69
ARGB()
Definition: Colors.h:21
RGBA & operator=(RGB v)
Definition: Colors.h:92
uint8_t B
Definition: Colors.h:48
uint8_t z
Definition: Colors.h:69
Definition: Colors.h:46
Definition: Colors.h:24
uint8_t A() const
Definition: Colors.h:42
Definition: Colors.h:13
uint8_t G() const
Definition: Colors.h:40
glm::vec4 toFloats() const
Definition: Colors.h:100
RGBA()
Definition: Colors.h:72
uint8_t v[4]
Definition: Colors.h:17
uint8_t & operator[](uint8_t idx)
Definition: Colors.h:99
uint8_t a
Definition: Colors.h:68
uint8_t & operator[](size_t idx)
Definition: Colors.h:49
uint8_t R() const
Definition: Colors.h:39
uint32_t val
Definition: Colors.h:67
RGBA & operator=(uint32_t v)
Definition: Colors.h:82
uint8_t g
Definition: Colors.h:68
uint8_t w
Definition: Colors.h:69
RGBA(uint8_t r_, uint8_t g_, uint8_t b_, uint8_t a_)
Definition: Colors.h:71