1
// Copyright (c) 2013- PPSSPP Project.
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
20
#include "CommonTypes.h"
21
#include "GPU/Common/GPUDebugInterface.h"
22
#include "GPU/Math3D.h"
24
using namespace Math3D;
27
typedef u16 u10; // TODO: erm... :/
29
typedef Vec3<float> ModelCoords;
30
typedef Vec3<float> WorldCoords;
31
typedef Vec3<float> ViewCoords;
32
typedef Vec4<float> ClipCoords; // Range: -w <= x/y/z <= w
39
ScreenCoords(fixed16 x, fixed16 y, u16 z) : x(x), y(y), z(z) {}
45
Vec2<fixed16> xy() const { return Vec2<fixed16>(x, y); }
47
ScreenCoords operator * (const float t) const
49
return ScreenCoords((fixed16)(x * t), (fixed16)(y * t), (u16)(z * t));
52
ScreenCoords operator / (const int t) const
54
return ScreenCoords(x / t, y / t, z / t);
57
ScreenCoords operator + (const ScreenCoords& oth) const
59
return ScreenCoords(x + oth.x, y + oth.y, z + oth.z);
66
DrawingCoords(u10 x, u10 y, u16 z) : x(x), y(y), z(z) {}
72
Vec2<u10> xy() const { return Vec2<u10>(x, y); }
74
DrawingCoords operator * (const float t) const
76
return DrawingCoords((u10)(x * t), (u10)(y * t), (u16)(z * t));
79
DrawingCoords operator + (const DrawingCoords& oth) const
81
return DrawingCoords(x + oth.x, y + oth.y, z + oth.z);
87
void Lerp(float t, const VertexData& a, const VertexData& b)
89
// World coords only needed for lighting, so we don't Lerp those
91
modelpos = ::Lerp(a.modelpos, b.modelpos, t);
92
clippos = ::Lerp(a.clippos, b.clippos, t);
93
screenpos = ::Lerp(a.screenpos, b.screenpos, t); // TODO: Should use a LerpInt (?)
94
texturecoords = ::Lerp(a.texturecoords, b.texturecoords, t);
95
normal = ::Lerp(a.normal, b.normal, t);
96
fogdepth = ::Lerp(a.fogdepth, b.fogdepth, t);
98
u16 t_int = (u16)(t*256);
99
color0 = LerpInt<Vec4<int>,256>(a.color0, b.color0, t_int);
100
color1 = LerpInt<Vec3<int>,256>(a.color1, b.color1, t_int);
103
ModelCoords modelpos;
104
WorldCoords worldpos; // TODO: Storing this is dumb, should transform the light to clip space instead
106
ScreenCoords screenpos; // TODO: Shouldn't store this ?
107
Vec2<float> texturecoords;
109
WorldCoords worldnormal;
122
static WorldCoords ModelToWorldNormal(const ModelCoords& coords);
123
static WorldCoords ModelToWorld(const ModelCoords& coords);
124
static ViewCoords WorldToView(const WorldCoords& coords);
125
static ClipCoords ViewToClip(const ViewCoords& coords);
126
static ScreenCoords ClipToScreen(const ClipCoords& coords);
127
static DrawingCoords ScreenToDrawing(const ScreenCoords& coords);
128
static ScreenCoords DrawingToScreen(const DrawingCoords& coords);
130
static void SubmitSpline(void* control_points, void* indices, int count_u, int count_v, int type_u, int type_v, GEPatchPrimType prim_type, u32 vertex_type);
131
static void SubmitPrimitive(void* vertices, void* indices, u32 prim_type, int vertex_count, u32 vertex_type, int *bytesRead);
133
static bool GetCurrentSimpleVertices(int count, std::vector<GPUDebugVertex> &vertices, std::vector<u16> &indices);
134
static VertexData ReadVertex(VertexReader& vreader);
136
static SplinePatch *patchBuffer_;
137
static int patchBufferSize_;
139
static bool outside_range_flag;