summaryrefslogtreecommitdiff
path: root/src/video_core/rasterizer.cpp
diff options
context:
space:
mode:
authorGravatar Tony Wasserka2014-08-17 12:31:19 +0200
committerGravatar Tony Wasserka2014-08-25 22:03:18 +0200
commit9679d231df0bc8fac9e0e596ab78750bb38ef248 (patch)
treef80fe9c3396c3c83aacc06c26ddf3643140b20ae /src/video_core/rasterizer.cpp
parentPica/DebugUtils: Add convenient tev setup printer. (diff)
downloadyuzu-9679d231df0bc8fac9e0e596ab78750bb38ef248.tar.gz
yuzu-9679d231df0bc8fac9e0e596ab78750bb38ef248.tar.xz
yuzu-9679d231df0bc8fac9e0e596ab78750bb38ef248.zip
Pica/Rasterizer: Add texturing support.
Diffstat (limited to 'src/video_core/rasterizer.cpp')
-rw-r--r--src/video_core/rasterizer.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/video_core/rasterizer.cpp b/src/video_core/rasterizer.cpp
index 5a4155c84..1bd32e8d0 100644
--- a/src/video_core/rasterizer.cpp
+++ b/src/video_core/rasterizer.cpp
@@ -11,6 +11,8 @@
11#include "rasterizer.h" 11#include "rasterizer.h"
12#include "vertex_shader.h" 12#include "vertex_shader.h"
13 13
14#include "debug_utils/debug_utils.h"
15
14namespace Pica { 16namespace Pica {
15 17
16namespace Rasterizer { 18namespace Rasterizer {
@@ -165,6 +167,62 @@ void ProcessTriangle(const VertexShader::OutputVertex& v0,
165 (u8)(GetInterpolatedAttribute(v0.color.a(), v1.color.a(), v2.color.a()).ToFloat32() * 255) 167 (u8)(GetInterpolatedAttribute(v0.color.a(), v1.color.a(), v2.color.a()).ToFloat32() * 255)
166 }; 168 };
167 169
170 Math::Vec4<u8> texture_color{};
171 float24 u = GetInterpolatedAttribute(v0.tc0.u(), v1.tc0.u(), v2.tc0.u());
172 float24 v = GetInterpolatedAttribute(v0.tc0.v(), v1.tc0.v(), v2.tc0.v());
173 if (registers.texturing_enable) {
174 // Images are split into 8x8 tiles. Each tile is composed of four 4x4 subtiles each
175 // of which is composed of four 2x2 subtiles each of which is composed of four texels.
176 // Each structure is embedded into the next-bigger one in a diagonal pattern, e.g.
177 // texels are laid out in a 2x2 subtile like this:
178 // 2 3
179 // 0 1
180 //
181 // The full 8x8 tile has the texels arranged like this:
182 //
183 // 42 43 46 47 58 59 62 63
184 // 40 41 44 45 56 57 60 61
185 // 34 35 38 39 50 51 54 55
186 // 32 33 36 37 48 49 52 53
187 // 10 11 14 15 26 27 30 31
188 // 08 09 12 13 24 25 28 29
189 // 02 03 06 07 18 19 22 23
190 // 00 01 04 05 16 17 20 21
191
192 // TODO: This is currently hardcoded for RGB8
193 u32* texture_data = (u32*)Memory::GetPointer(registers.texture0.GetPhysicalAddress());
194
195 // TODO(neobrain): Not sure if this swizzling pattern is used for all textures.
196 // To be flexible in case different but similar patterns are used, we keep this
197 // somewhat inefficient code around for now.
198 int s = (int)(u * float24::FromFloat32(registers.texture0.width)).ToFloat32();
199 int t = (int)(v * float24::FromFloat32(registers.texture0.height)).ToFloat32();
200 int texel_index_within_tile = 0;
201 for (int block_size_index = 0; block_size_index < 3; ++block_size_index) {
202 int sub_tile_width = 1 << block_size_index;
203 int sub_tile_height = 1 << block_size_index;
204
205 int sub_tile_index = (s & sub_tile_width) << block_size_index;
206 sub_tile_index += 2 * ((t & sub_tile_height) << block_size_index);
207 texel_index_within_tile += sub_tile_index;
208 }
209
210 const int block_width = 8;
211 const int block_height = 8;
212
213 int coarse_s = (s / block_width) * block_width;
214 int coarse_t = (t / block_height) * block_height;
215
216 const int row_stride = registers.texture0.width * 3;
217 u8* source_ptr = (u8*)texture_data + coarse_s * block_height * 3 + coarse_t * row_stride + texel_index_within_tile * 3;
218 texture_color.r() = source_ptr[2];
219 texture_color.g() = source_ptr[1];
220 texture_color.b() = source_ptr[0];
221 texture_color.a() = 0xFF;
222
223 DebugUtils::DumpTexture(registers.texture0, (u8*)texture_data);
224 }
225
168 // Texture environment - consists of 6 stages of color and alpha combining. 226 // Texture environment - consists of 6 stages of color and alpha combining.
169 // 227 //
170 // Color combiners take three input color values from some source (e.g. interpolated 228 // Color combiners take three input color values from some source (e.g. interpolated
@@ -184,6 +242,9 @@ void ProcessTriangle(const VertexShader::OutputVertex& v0,
184 case Source::PrimaryColor: 242 case Source::PrimaryColor:
185 return primary_color.rgb(); 243 return primary_color.rgb();
186 244
245 case Source::Texture0:
246 return texture_color.rgb();
247
187 case Source::Constant: 248 case Source::Constant:
188 return {tev_stage.const_r, tev_stage.const_g, tev_stage.const_b}; 249 return {tev_stage.const_r, tev_stage.const_g, tev_stage.const_b};
189 250
@@ -201,6 +262,9 @@ void ProcessTriangle(const VertexShader::OutputVertex& v0,
201 case Source::PrimaryColor: 262 case Source::PrimaryColor:
202 return primary_color.a(); 263 return primary_color.a();
203 264
265 case Source::Texture0:
266 return texture_color.a();
267
204 case Source::Constant: 268 case Source::Constant:
205 return tev_stage.const_a; 269 return tev_stage.const_a;
206 270