summaryrefslogtreecommitdiff
path: root/src/video_core
diff options
context:
space:
mode:
authorGravatar archshift2015-05-24 12:20:31 -0700
committerGravatar archshift2015-05-30 11:17:37 -0700
commit76690392bf8923d7172936836d15e3caebb26cf0 (patch)
treee5896ecb4f042e88a650f4ad2287393e2346c094 /src/video_core
parentMove video_core/math.h to common/vector_math.h (diff)
downloadyuzu-76690392bf8923d7172936836d15e3caebb26cf0.tar.gz
yuzu-76690392bf8923d7172936836d15e3caebb26cf0.tar.xz
yuzu-76690392bf8923d7172936836d15e3caebb26cf0.zip
Move video_core/color.h to common/color.h
Diffstat (limited to 'src/video_core')
-rw-r--r--src/video_core/CMakeLists.txt1
-rw-r--r--src/video_core/color.h214
-rw-r--r--src/video_core/debug_utils/debug_utils.cpp2
-rw-r--r--src/video_core/rasterizer.cpp2
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp3
5 files changed, 4 insertions, 218 deletions
diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt
index f50f73b52..5c7f4ae18 100644
--- a/src/video_core/CMakeLists.txt
+++ b/src/video_core/CMakeLists.txt
@@ -29,7 +29,6 @@ set(HEADERS
29 renderer_opengl/pica_to_gl.h 29 renderer_opengl/pica_to_gl.h
30 renderer_opengl/renderer_opengl.h 30 renderer_opengl/renderer_opengl.h
31 clipper.h 31 clipper.h
32 color.h
33 command_processor.h 32 command_processor.h
34 gpu_debugger.h 33 gpu_debugger.h
35 hwrasterizer_base.h 34 hwrasterizer_base.h
diff --git a/src/video_core/color.h b/src/video_core/color.h
deleted file mode 100644
index 422fdc8af..000000000
--- a/src/video_core/color.h
+++ /dev/null
@@ -1,214 +0,0 @@
1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include "common/common_types.h"
8#include "common/swap.h"
9#include "common/vector_math.h"
10
11namespace Color {
12
13/// Convert a 1-bit color component to 8 bit
14inline u8 Convert1To8(u8 value) {
15 return value * 255;
16}
17
18/// Convert a 4-bit color component to 8 bit
19inline u8 Convert4To8(u8 value) {
20 return (value << 4) | value;
21}
22
23/// Convert a 5-bit color component to 8 bit
24inline u8 Convert5To8(u8 value) {
25 return (value << 3) | (value >> 2);
26}
27
28/// Convert a 6-bit color component to 8 bit
29inline u8 Convert6To8(u8 value) {
30 return (value << 2) | (value >> 4);
31}
32
33/// Convert a 8-bit color component to 1 bit
34inline u8 Convert8To1(u8 value) {
35 return value >> 7;
36}
37
38/// Convert a 8-bit color component to 4 bit
39inline u8 Convert8To4(u8 value) {
40 return value >> 4;
41}
42
43/// Convert a 8-bit color component to 5 bit
44inline u8 Convert8To5(u8 value) {
45 return value >> 3;
46}
47
48/// Convert a 8-bit color component to 6 bit
49inline u8 Convert8To6(u8 value) {
50 return value >> 2;
51}
52
53/**
54 * Decode a color stored in RGBA8 format
55 * @param bytes Pointer to encoded source color
56 * @return Result color decoded as Math::Vec4<u8>
57 */
58inline const Math::Vec4<u8> DecodeRGBA8(const u8* bytes) {
59 return { bytes[3], bytes[2], bytes[1], bytes[0] };
60}
61
62/**
63 * Decode a color stored in RGB8 format
64 * @param bytes Pointer to encoded source color
65 * @return Result color decoded as Math::Vec4<u8>
66 */
67inline const Math::Vec4<u8> DecodeRGB8(const u8* bytes) {
68 return { bytes[2], bytes[1], bytes[0], 255 };
69}
70
71/**
72 * Decode a color stored in RGB565 format
73 * @param bytes Pointer to encoded source color
74 * @return Result color decoded as Math::Vec4<u8>
75 */
76inline const Math::Vec4<u8> DecodeRGB565(const u8* bytes) {
77 const u16_le pixel = *reinterpret_cast<const u16_le*>(bytes);
78 return { Convert5To8((pixel >> 11) & 0x1F), Convert6To8((pixel >> 5) & 0x3F),
79 Convert5To8(pixel & 0x1F), 255 };
80}
81
82/**
83 * Decode a color stored in RGB5A1 format
84 * @param bytes Pointer to encoded source color
85 * @return Result color decoded as Math::Vec4<u8>
86 */
87inline const Math::Vec4<u8> DecodeRGB5A1(const u8* bytes) {
88 const u16_le pixel = *reinterpret_cast<const u16_le*>(bytes);
89 return { Convert5To8((pixel >> 11) & 0x1F), Convert5To8((pixel >> 6) & 0x1F),
90 Convert5To8((pixel >> 1) & 0x1F), Convert1To8(pixel & 0x1) };
91}
92
93/**
94 * Decode a color stored in RGBA4 format
95 * @param bytes Pointer to encoded source color
96 * @return Result color decoded as Math::Vec4<u8>
97 */
98inline const Math::Vec4<u8> DecodeRGBA4(const u8* bytes) {
99 const u16_le pixel = *reinterpret_cast<const u16_le*>(bytes);
100 return { Convert4To8((pixel >> 12) & 0xF), Convert4To8((pixel >> 8) & 0xF),
101 Convert4To8((pixel >> 4) & 0xF), Convert4To8(pixel & 0xF) };
102}
103
104/**
105 * Decode a depth value stored in D16 format
106 * @param bytes Pointer to encoded source value
107 * @return Depth value as an u32
108 */
109inline u32 DecodeD16(const u8* bytes) {
110 return *reinterpret_cast<const u16_le*>(bytes);
111}
112
113/**
114 * Decode a depth value stored in D24 format
115 * @param bytes Pointer to encoded source value
116 * @return Depth value as an u32
117 */
118inline u32 DecodeD24(const u8* bytes) {
119 return (bytes[2] << 16) | (bytes[1] << 8) | bytes[0];
120}
121
122/**
123 * Decode a depth value and a stencil value stored in D24S8 format
124 * @param bytes Pointer to encoded source values
125 * @return Resulting values stored as a Math::Vec2
126 */
127inline const Math::Vec2<u32> DecodeD24S8(const u8* bytes) {
128 return { static_cast<u32>((bytes[2] << 16) | (bytes[1] << 8) | bytes[0]), bytes[3] };
129}
130
131/**
132 * Encode a color as RGBA8 format
133 * @param color Source color to encode
134 * @param bytes Destination pointer to store encoded color
135 */
136inline void EncodeRGBA8(const Math::Vec4<u8>& color, u8* bytes) {
137 bytes[3] = color.r();
138 bytes[2] = color.g();
139 bytes[1] = color.b();
140 bytes[0] = color.a();
141}
142
143/**
144 * Encode a color as RGB8 format
145 * @param color Source color to encode
146 * @param bytes Destination pointer to store encoded color
147 */
148inline void EncodeRGB8(const Math::Vec4<u8>& color, u8* bytes) {
149 bytes[2] = color.r();
150 bytes[1] = color.g();
151 bytes[0] = color.b();
152}
153
154/**
155 * Encode a color as RGB565 format
156 * @param color Source color to encode
157 * @param bytes Destination pointer to store encoded color
158 */
159inline void EncodeRGB565(const Math::Vec4<u8>& color, u8* bytes) {
160 *reinterpret_cast<u16_le*>(bytes) = (Convert8To5(color.r()) << 11) |
161 (Convert8To6(color.g()) << 5) | Convert8To5(color.b());
162}
163
164/**
165 * Encode a color as RGB5A1 format
166 * @param color Source color to encode
167 * @param bytes Destination pointer to store encoded color
168 */
169inline void EncodeRGB5A1(const Math::Vec4<u8>& color, u8* bytes) {
170 *reinterpret_cast<u16_le*>(bytes) = (Convert8To5(color.r()) << 11) |
171 (Convert8To5(color.g()) << 6) | (Convert8To5(color.b()) << 1) | Convert8To1(color.a());
172}
173
174/**
175 * Encode a color as RGBA4 format
176 * @param color Source color to encode
177 * @param bytes Destination pointer to store encoded color
178 */
179inline void EncodeRGBA4(const Math::Vec4<u8>& color, u8* bytes) {
180 *reinterpret_cast<u16_le*>(bytes) = (Convert8To4(color.r()) << 12) |
181 (Convert8To4(color.g()) << 8) | (Convert8To4(color.b()) << 4) | Convert8To4(color.a());
182}
183
184/**
185 * Encode a 16 bit depth value as D16 format
186 * @param value 16 bit source depth value to encode
187 * @param bytes Pointer where to store the encoded value
188 */
189inline void EncodeD16(u32 value, u8* bytes) {
190 *reinterpret_cast<u16_le*>(bytes) = value & 0xFFFF;
191}
192
193/**
194 * Encode a 24 bit depth value as D24 format
195 * @param value 24 bit source depth value to encode
196 * @param bytes Pointer where to store the encoded value
197 */
198inline void EncodeD24(u32 value, u8* bytes) {
199 bytes[0] = value & 0xFF;
200 bytes[1] = (value >> 8) & 0xFF;
201 bytes[2] = (value >> 16) & 0xFF;
202}
203
204/**
205 * Encode a 24 bit depth and 8 bit stencil values as D24S8 format
206 * @param depth 24 bit source depth value to encode
207 * @param stencil 8 bit source stencil value to encode
208 * @param bytes Pointer where to store the encoded value
209 */
210inline void EncodeD24S8(u32 depth, u8 stencil, u8* bytes) {
211 *reinterpret_cast<u32_le*>(bytes) = (stencil << 24) | depth;
212}
213
214} // namespace
diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp
index 5392dae21..7b8ab72b6 100644
--- a/src/video_core/debug_utils/debug_utils.cpp
+++ b/src/video_core/debug_utils/debug_utils.cpp
@@ -17,11 +17,11 @@
17#include <nihstro/shader_binary.h> 17#include <nihstro/shader_binary.h>
18 18
19#include "common/assert.h" 19#include "common/assert.h"
20#include "common/color.h"
20#include "common/file_util.h" 21#include "common/file_util.h"
21#include "common/math_util.h" 22#include "common/math_util.h"
22#include "common/vector_math.h" 23#include "common/vector_math.h"
23 24
24#include "video_core/color.h"
25#include "video_core/pica.h" 25#include "video_core/pica.h"
26#include "video_core/utils.h" 26#include "video_core/utils.h"
27#include "video_core/video_core.h" 27#include "video_core/video_core.h"
diff --git a/src/video_core/rasterizer.cpp b/src/video_core/rasterizer.cpp
index 6df3a74f2..93288be2c 100644
--- a/src/video_core/rasterizer.cpp
+++ b/src/video_core/rasterizer.cpp
@@ -4,6 +4,7 @@
4 4
5#include <algorithm> 5#include <algorithm>
6 6
7#include "common/color.h"
7#include "common/common_types.h" 8#include "common/common_types.h"
8#include "common/math_util.h" 9#include "common/math_util.h"
9#include "common/profiler.h" 10#include "common/profiler.h"
@@ -13,7 +14,6 @@
13 14
14#include "debug_utils/debug_utils.h" 15#include "debug_utils/debug_utils.h"
15#include "math.h" 16#include "math.h"
16#include "color.h"
17#include "pica.h" 17#include "pica.h"
18#include "rasterizer.h" 18#include "rasterizer.h"
19#include "vertex_shader.h" 19#include "vertex_shader.h"
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index bacdb7172..e33a712c6 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -2,10 +2,11 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include "common/color.h"
6
5#include "core/settings.h" 7#include "core/settings.h"
6#include "core/hw/gpu.h" 8#include "core/hw/gpu.h"
7 9
8#include "video_core/color.h"
9#include "video_core/pica.h" 10#include "video_core/pica.h"
10#include "video_core/utils.h" 11#include "video_core/utils.h"
11#include "video_core/renderer_opengl/gl_rasterizer.h" 12#include "video_core/renderer_opengl/gl_rasterizer.h"