summaryrefslogtreecommitdiff
path: root/src/video_core/clipper.cpp
diff options
context:
space:
mode:
authorGravatar Yuri Kunde Schlesner2016-12-18 23:43:37 -0800
committerGravatar Yuri Kunde Schlesner2017-01-29 21:31:38 -0800
commitdcdffabfe69d0cecd2d8c0c1f217b884b20af643 (patch)
tree4d2214f4a878ac16e1df941fb5c763b9869ba6cc /src/video_core/clipper.cpp
parentVideoCore/Shader: Clean up OutputVertex::FromAttributeBuffer (diff)
downloadyuzu-dcdffabfe69d0cecd2d8c0c1f217b884b20af643.tar.gz
yuzu-dcdffabfe69d0cecd2d8c0c1f217b884b20af643.tar.xz
yuzu-dcdffabfe69d0cecd2d8c0c1f217b884b20af643.zip
VideoCore: Extract swrast-specific data from OutputVertex
Diffstat (limited to 'src/video_core/clipper.cpp')
-rw-r--r--src/video_core/clipper.cpp24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/video_core/clipper.cpp b/src/video_core/clipper.cpp
index 05b5cea73..0774ffc53 100644
--- a/src/video_core/clipper.cpp
+++ b/src/video_core/clipper.cpp
@@ -18,6 +18,8 @@
18#include "video_core/rasterizer.h" 18#include "video_core/rasterizer.h"
19#include "video_core/shader/shader.h" 19#include "video_core/shader/shader.h"
20 20
21using Pica::Rasterizer::Vertex;
22
21namespace Pica { 23namespace Pica {
22 24
23namespace Clipper { 25namespace Clipper {
@@ -29,20 +31,20 @@ public:
29 float24::FromFloat32(0), float24::FromFloat32(0))) 31 float24::FromFloat32(0), float24::FromFloat32(0)))
30 : coeffs(coeffs), bias(bias) {} 32 : coeffs(coeffs), bias(bias) {}
31 33
32 bool IsInside(const OutputVertex& vertex) const { 34 bool IsInside(const Vertex& vertex) const {
33 return Math::Dot(vertex.pos + bias, coeffs) <= float24::FromFloat32(0); 35 return Math::Dot(vertex.pos + bias, coeffs) <= float24::FromFloat32(0);
34 } 36 }
35 37
36 bool IsOutSide(const OutputVertex& vertex) const { 38 bool IsOutSide(const Vertex& vertex) const {
37 return !IsInside(vertex); 39 return !IsInside(vertex);
38 } 40 }
39 41
40 OutputVertex GetIntersection(const OutputVertex& v0, const OutputVertex& v1) const { 42 Vertex GetIntersection(const Vertex& v0, const Vertex& v1) const {
41 float24 dp = Math::Dot(v0.pos + bias, coeffs); 43 float24 dp = Math::Dot(v0.pos + bias, coeffs);
42 float24 dp_prev = Math::Dot(v1.pos + bias, coeffs); 44 float24 dp_prev = Math::Dot(v1.pos + bias, coeffs);
43 float24 factor = dp_prev / (dp_prev - dp); 45 float24 factor = dp_prev / (dp_prev - dp);
44 46
45 return OutputVertex::Lerp(factor, v0, v1); 47 return Vertex::Lerp(factor, v0, v1);
46 } 48 }
47 49
48private: 50private:
@@ -51,7 +53,7 @@ private:
51 Math::Vec4<float24> bias; 53 Math::Vec4<float24> bias;
52}; 54};
53 55
54static void InitScreenCoordinates(OutputVertex& vtx) { 56static void InitScreenCoordinates(Vertex& vtx) {
55 struct { 57 struct {
56 float24 halfsize_x; 58 float24 halfsize_x;
57 float24 offset_x; 59 float24 offset_x;
@@ -91,8 +93,8 @@ void ProcessTriangle(const OutputVertex& v0, const OutputVertex& v1, const Outpu
91 // introduces at most 1 new vertex to the polygon. Since we start with a triangle and have a 93 // introduces at most 1 new vertex to the polygon. Since we start with a triangle and have a
92 // fixed 6 clipping planes, the maximum number of vertices of the clipped polygon is 3 + 6 = 9. 94 // fixed 6 clipping planes, the maximum number of vertices of the clipped polygon is 3 + 6 = 9.
93 static const size_t MAX_VERTICES = 9; 95 static const size_t MAX_VERTICES = 9;
94 static_vector<OutputVertex, MAX_VERTICES> buffer_a = {v0, v1, v2}; 96 static_vector<Vertex, MAX_VERTICES> buffer_a = {v0, v1, v2};
95 static_vector<OutputVertex, MAX_VERTICES> buffer_b; 97 static_vector<Vertex, MAX_VERTICES> buffer_b;
96 auto* output_list = &buffer_a; 98 auto* output_list = &buffer_a;
97 auto* input_list = &buffer_b; 99 auto* input_list = &buffer_b;
98 100
@@ -123,7 +125,7 @@ void ProcessTriangle(const OutputVertex& v0, const OutputVertex& v1, const Outpu
123 std::swap(input_list, output_list); 125 std::swap(input_list, output_list);
124 output_list->clear(); 126 output_list->clear();
125 127
126 const OutputVertex* reference_vertex = &input_list->back(); 128 const Vertex* reference_vertex = &input_list->back();
127 129
128 for (const auto& vertex : *input_list) { 130 for (const auto& vertex : *input_list) {
129 // NOTE: This algorithm changes vertex order in some cases! 131 // NOTE: This algorithm changes vertex order in some cases!
@@ -148,9 +150,9 @@ void ProcessTriangle(const OutputVertex& v0, const OutputVertex& v1, const Outpu
148 InitScreenCoordinates((*output_list)[1]); 150 InitScreenCoordinates((*output_list)[1]);
149 151
150 for (size_t i = 0; i < output_list->size() - 2; i++) { 152 for (size_t i = 0; i < output_list->size() - 2; i++) {
151 OutputVertex& vtx0 = (*output_list)[0]; 153 Vertex& vtx0 = (*output_list)[0];
152 OutputVertex& vtx1 = (*output_list)[i + 1]; 154 Vertex& vtx1 = (*output_list)[i + 1];
153 OutputVertex& vtx2 = (*output_list)[i + 2]; 155 Vertex& vtx2 = (*output_list)[i + 2];
154 156
155 InitScreenCoordinates(vtx2); 157 InitScreenCoordinates(vtx2);
156 158