MxEngine
Colors.h
1 // Copyright(c) 2019 - 2020, #Momo
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met :
6 //
7 // 1. Redistributions of source code must retain the above copyright notice, this
8 // list of conditions and the following disclaimer.
9 //
10 // 2. Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and /or other materials provided with the distribution.
13 //
14 // 3. Neither the name of the copyright holder nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 // DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 // OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 #pragma once
30 
31 #include "Platform/GraphicAPI.h"
32 #include "Core/Application/Application.h"
33 #include "Core/Macro/Macro.h"
34 #include "Utilities/Format/Format.h"
35 
36 namespace MxEngine
37 {
38  class Colors
39  {
40  public:
41  enum Palette
42  {
43  RED,
44  GREEN,
45  BLUE,
46  YELLOW,
47  AQUA,
48  PURPLE,
49  BLACK,
50  WHITE,
51  ORANGE,
52  LIME,
53  MAGENTA,
54  VIOLET,
55  SKYBLUE,
56  SPRING,
57  FLAT_NORMAL,
58  PINK,
59  SALAD,
60  GREY,
61  };
62 
63  static inline GResource<Texture> MakeTexture(uint8_t r, uint8_t g, uint8_t b)
64  {
65  auto texture = GraphicFactory::Create<Texture>();
66  uint8_t buffer[] = { r, g, b };
67  texture->Load(buffer, 1, 1);
68  return texture;
69  }
70 
71  static inline GResource<Texture> MakeTexture(float r, float g, float b)
72  {
73  return MakeTexture(MakeVector3(r, g, b));
74  }
75 
76  static inline GResource<Texture> MakeTexture(const Vector3& color)
77  {
78  uint8_t r = static_cast<uint8_t>(Clamp(color.r, 0.0f, 1.0f) * 255.0f);
79  uint8_t g = static_cast<uint8_t>(Clamp(color.g, 0.0f, 1.0f) * 255.0f);
80  uint8_t b = static_cast<uint8_t>(Clamp(color.b, 0.0f, 1.0f) * 255.0f);
81  return MakeTexture(r, g, b);
82  }
83 
84  static GResource<Texture> MakeTexture(Palette color)
85  {
86  return MakeTexture(ColorPaletteToVector3(color));
87  }
88 
89  static inline GResource<CubeMap> MakeCubeMap(uint8_t r, uint8_t g, uint8_t b)
90  {
91  auto cubemap = GraphicFactory::Create<CubeMap>();
92  uint8_t buffer[] = { r, g, b };
93  std::array<uint8_t*, 6> sides = { buffer, buffer, buffer, buffer, buffer, buffer };
94  cubemap->Load(sides, 1, 1);
95  return cubemap;
96  }
97 
98  static inline GResource<CubeMap> MakeCubeMap(float r, float g, float b)
99  {
100  return MakeCubeMap(MakeVector3(r, g, b));
101  }
102 
103  static inline GResource<CubeMap> MakeCubeMap(const Vector3& color)
104  {
105  uint8_t r = static_cast<uint8_t>(Clamp(color.r, 0.0f, 1.0f) * 255.0f);
106  uint8_t g = static_cast<uint8_t>(Clamp(color.g, 0.0f, 1.0f) * 255.0f);
107  uint8_t b = static_cast<uint8_t>(Clamp(color.b, 0.0f, 1.0f) * 255.0f);
108  return MakeCubeMap(r, g, b);
109  }
110 
111  static GResource<CubeMap> MakeCubeMap(Palette color)
112  {
113  return MakeCubeMap(ColorPaletteToVector3(color));
114  }
115 
116  static Vector3 ColorPaletteToVector3(Palette color)
117  {
118  switch (color)
119  {
120  case Colors::RED:
121  return MakeVector3(1.0f, 0.0f, 0.0f);
122  case Colors::GREEN:
123  return MakeVector3(0.0f, 1.0f, 0.0f);
124  case Colors::BLUE:
125  return MakeVector3(0.0f, 0.0f, 1.0f);
126  case Colors::YELLOW:
127  return MakeVector3(1.0f, 1.0f, 0.0f);
128  case Colors::AQUA:
129  return MakeVector3(0.0f, 1.0f, 1.0f);
130  case Colors::PURPLE:
131  return MakeVector3(1.0f, 0.0f, 1.0f);
132  case Colors::BLACK:
133  return MakeVector3(0.0f, 0.0f, 0.0f);
134  case Colors::WHITE:
135  return MakeVector3(1.0f, 1.0f, 1.0f);
136  case Colors::ORANGE:
137  return MakeVector3(1.0f, 0.5f, 0.0f);
138  case Colors::LIME:
139  return MakeVector3(0.5f, 1.0f, 0.0f);
140  case Colors::MAGENTA:
141  return MakeVector3(1.0f, 0.0f, 0.5f);
142  case Colors::VIOLET:
143  return MakeVector3(0.5f, 0.0f, 1.0f);
144  case Colors::SKYBLUE:
145  return MakeVector3(0.0f, 0.5f, 1.0f);
146  case Colors::SPRING:
147  return MakeVector3(0.0f, 1.0f, 0.5f);
148  case Colors::FLAT_NORMAL:
149  return MakeVector3(0.5f, 0.5f, 1.0f);
150  case Colors::PINK:
151  return MakeVector3(1.0f, 0.5f, 0.5f);
152  case Colors::SALAD:
153  return MakeVector3(0.5f, 1.0f, 0.5f);
154  case Colors::GREY:
155  return MakeVector3(0.5f, 0.5f, 0.5f);
156  default:
157  return MakeVector3(0.0f);
158  }
159  }
160  };
161 }
Definition: AbstractFactory.h:61
Definition: Colors.h:38
Definition: Application.cpp:49