xref: /aosp_15_r20/external/angle/src/common/Color.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2016 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 // Color.h : Defines the Color type used throughout the ANGLE libraries
8 
9 #ifndef COMMON_COLOR_H_
10 #define COMMON_COLOR_H_
11 
12 #include <cstdint>
13 #include <cstring>
14 
15 #include "common/debug.h"
16 
17 namespace angle
18 {
19 
20 template <typename T>
21 struct Color
22 {
23     Color();
24     constexpr Color(T r, T g, T b, T a);
25 
dataColor26     const T *data() const { return &red; }
ptrColor27     T *ptr() { return &red; }
28 
fromDataColor29     static Color fromData(const T *data) { return Color(data[0], data[1], data[2], data[3]); }
writeDataColor30     void writeData(T *data) const
31     {
32         data[0] = red;
33         data[1] = green;
34         data[2] = blue;
35         data[3] = alpha;
36     }
37 
38     T red;
39     T green;
40     T blue;
41     T alpha;
42 };
43 
44 template <typename T>
45 bool operator==(const Color<T> &a, const Color<T> &b);
46 
47 template <typename T>
48 bool operator!=(const Color<T> &a, const Color<T> &b);
49 
50 typedef Color<float> ColorF;
51 typedef Color<int> ColorI;
52 typedef Color<unsigned int> ColorUI;
53 
54 ANGLE_ENABLE_STRUCT_PADDING_WARNINGS
55 struct ColorGeneric
56 {
57     inline ColorGeneric();
58     inline ColorGeneric(const ColorF &color);
59     inline ColorGeneric(const ColorI &color);
60     inline ColorGeneric(const ColorUI &color);
61 
62     enum class Type : uint32_t
63     {
64         Float = 0,
65         Int   = 1,
66         UInt  = 2
67     };
68 
69     union
70     {
71         ColorF colorF;
72         ColorI colorI;
73         ColorUI colorUI;
74     };
75 
76     Type type;
77 };
78 ANGLE_DISABLE_STRUCT_PADDING_WARNINGS
79 
80 inline bool operator==(const ColorGeneric &a, const ColorGeneric &b);
81 
82 inline bool operator!=(const ColorGeneric &a, const ColorGeneric &b);
83 
84 struct DepthStencil
85 {
DepthStencilDepthStencil86     DepthStencil() : depth(0), stencil(0) {}
87 
88     // Double is needed to represent the 32-bit integer range of GL_DEPTH_COMPONENT32.
89     double depth;
90     uint32_t stencil;
91 };
92 }  // namespace angle
93 
94 // TODO: Move this fully into the angle namespace
95 namespace gl
96 {
97 
98 template <typename T>
99 using Color        = angle::Color<T>;
100 using ColorF       = angle::ColorF;
101 using ColorI       = angle::ColorI;
102 using ColorUI      = angle::ColorUI;
103 using ColorGeneric = angle::ColorGeneric;
104 
105 }  // namespace gl
106 
107 #include "Color.inc"
108 
109 #endif  // COMMON_COLOR_H_
110