summaryrefslogtreecommitdiff
path: root/src/video_core/swrasterizer/rasterizer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/video_core/swrasterizer/rasterizer.cpp')
-rw-r--r--src/video_core/swrasterizer/rasterizer.cpp53
1 files changed, 51 insertions, 2 deletions
diff --git a/src/video_core/swrasterizer/rasterizer.cpp b/src/video_core/swrasterizer/rasterizer.cpp
index e9edf0360..8b7b1defb 100644
--- a/src/video_core/swrasterizer/rasterizer.cpp
+++ b/src/video_core/swrasterizer/rasterizer.cpp
@@ -5,6 +5,7 @@
5#include <algorithm> 5#include <algorithm>
6#include <array> 6#include <array>
7#include <cmath> 7#include <cmath>
8#include <tuple>
8#include "common/assert.h" 9#include "common/assert.h"
9#include "common/bit_field.h" 10#include "common/bit_field.h"
10#include "common/color.h" 11#include "common/color.h"
@@ -70,6 +71,49 @@ static int SignedArea(const Math::Vec2<Fix12P4>& vtx1, const Math::Vec2<Fix12P4>
70 return Math::Cross(vec1, vec2).z; 71 return Math::Cross(vec1, vec2).z;
71}; 72};
72 73
74/// Convert a 3D vector for cube map coordinates to 2D texture coordinates along with the face name
75static std::tuple<float24, float24, PAddr> ConvertCubeCoord(float24 u, float24 v, float24 w,
76 const TexturingRegs& regs) {
77 const float abs_u = std::abs(u.ToFloat32());
78 const float abs_v = std::abs(v.ToFloat32());
79 const float abs_w = std::abs(w.ToFloat32());
80 float24 x, y, z;
81 PAddr addr;
82 if (abs_u > abs_v && abs_u > abs_w) {
83 if (u > float24::FromFloat32(0)) {
84 addr = regs.GetCubePhysicalAddress(TexturingRegs::CubeFace::PositiveX);
85 y = -v;
86 } else {
87 addr = regs.GetCubePhysicalAddress(TexturingRegs::CubeFace::NegativeX);
88 y = v;
89 }
90 x = -w;
91 z = u;
92 } else if (abs_v > abs_w) {
93 if (v > float24::FromFloat32(0)) {
94 addr = regs.GetCubePhysicalAddress(TexturingRegs::CubeFace::PositiveY);
95 x = u;
96 } else {
97 addr = regs.GetCubePhysicalAddress(TexturingRegs::CubeFace::NegativeY);
98 x = -u;
99 }
100 y = w;
101 z = v;
102 } else {
103 if (w > float24::FromFloat32(0)) {
104 addr = regs.GetCubePhysicalAddress(TexturingRegs::CubeFace::PositiveZ);
105 y = -v;
106 } else {
107 addr = regs.GetCubePhysicalAddress(TexturingRegs::CubeFace::NegativeZ);
108 y = v;
109 }
110 x = u;
111 z = w;
112 }
113 const float24 half = float24::FromFloat32(0.5f);
114 return std::make_tuple(x / z * half + half, y / z * half + half, addr);
115}
116
73MICROPROFILE_DEFINE(GPU_Rasterization, "GPU", "Rasterization", MP_RGB(50, 50, 240)); 117MICROPROFILE_DEFINE(GPU_Rasterization, "GPU", "Rasterization", MP_RGB(50, 50, 240));
74 118
75/** 119/**
@@ -284,10 +328,16 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve
284 328
285 // Only unit 0 respects the texturing type (according to 3DBrew) 329 // Only unit 0 respects the texturing type (according to 3DBrew)
286 // TODO: Refactor so cubemaps and shadowmaps can be handled 330 // TODO: Refactor so cubemaps and shadowmaps can be handled
331 PAddr texture_address = texture.config.GetPhysicalAddress();
287 if (i == 0) { 332 if (i == 0) {
288 switch (texture.config.type) { 333 switch (texture.config.type) {
289 case TexturingRegs::TextureConfig::Texture2D: 334 case TexturingRegs::TextureConfig::Texture2D:
290 break; 335 break;
336 case TexturingRegs::TextureConfig::TextureCube: {
337 auto w = GetInterpolatedAttribute(v0.tc0_w, v1.tc0_w, v2.tc0_w);
338 std::tie(u, v, texture_address) = ConvertCubeCoord(u, v, w, regs.texturing);
339 break;
340 }
291 case TexturingRegs::TextureConfig::Projection2D: { 341 case TexturingRegs::TextureConfig::Projection2D: {
292 auto tc0_w = GetInterpolatedAttribute(v0.tc0_w, v1.tc0_w, v2.tc0_w); 342 auto tc0_w = GetInterpolatedAttribute(v0.tc0_w, v1.tc0_w, v2.tc0_w);
293 u /= tc0_w; 343 u /= tc0_w;
@@ -322,8 +372,7 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve
322 t = texture.config.height - 1 - 372 t = texture.config.height - 1 -
323 GetWrappedTexCoord(texture.config.wrap_t, t, texture.config.height); 373 GetWrappedTexCoord(texture.config.wrap_t, t, texture.config.height);
324 374
325 u8* texture_data = 375 const u8* texture_data = Memory::GetPhysicalPointer(texture_address);
326 Memory::GetPhysicalPointer(texture.config.GetPhysicalAddress());
327 auto info = 376 auto info =
328 Texture::TextureInfo::FromPicaRegister(texture.config, texture.format); 377 Texture::TextureInfo::FromPicaRegister(texture.config, texture.format);
329 378