~ppsspp/ppsspp/ppsspp_1.3.0

« back to all changes in this revision

Viewing changes to GPU/Software/TransformUnit.h

  • Committer: Sérgio Benjamim
  • Date: 2017-01-02 00:12:05 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20170102001205-cxbta9za203nmjwm
1.3.0 source (from ppsspp_1.3.0-r160.p5.l1762.a165.t83~56~ubuntu16.04.1.tar.xz).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) 2013- PPSSPP Project.
 
2
 
 
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.
 
6
 
 
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.
 
11
 
 
12
// A copy of the GPL 2.0 should have been included with the program.
 
13
// If not, see http://www.gnu.org/licenses/
 
14
 
 
15
// Official git repository and contact information can be found at
 
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
 
17
 
 
18
#pragma once
 
19
 
 
20
#include "CommonTypes.h"
 
21
#include "GPU/Common/GPUDebugInterface.h"
 
22
#include "GPU/Math3D.h"
 
23
 
 
24
using namespace Math3D;
 
25
 
 
26
typedef u16 fixed16;
 
27
typedef u16 u10; // TODO: erm... :/
 
28
 
 
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
 
33
 
 
34
struct SplinePatch;
 
35
 
 
36
struct ScreenCoords
 
37
{
 
38
        ScreenCoords() {}
 
39
        ScreenCoords(fixed16 x, fixed16 y, u16 z) : x(x), y(y), z(z) {}
 
40
 
 
41
        fixed16 x;
 
42
        fixed16 y;
 
43
        u16 z;
 
44
 
 
45
        Vec2<fixed16> xy() const { return Vec2<fixed16>(x, y); }
 
46
 
 
47
        ScreenCoords operator * (const float t) const
 
48
        {
 
49
                return ScreenCoords((fixed16)(x * t), (fixed16)(y * t), (u16)(z * t));
 
50
        }
 
51
 
 
52
        ScreenCoords operator / (const int t) const
 
53
        {
 
54
                return ScreenCoords(x / t, y / t, z / t);
 
55
        }
 
56
 
 
57
        ScreenCoords operator + (const ScreenCoords& oth) const
 
58
        {
 
59
                return ScreenCoords(x + oth.x, y + oth.y, z + oth.z);
 
60
        }
 
61
};
 
62
 
 
63
struct DrawingCoords
 
64
{
 
65
        DrawingCoords() {}
 
66
        DrawingCoords(u10 x, u10 y, u16 z) : x(x), y(y), z(z) {}
 
67
 
 
68
        u10 x;
 
69
        u10 y;
 
70
        u16 z;
 
71
 
 
72
        Vec2<u10> xy() const { return Vec2<u10>(x, y); }
 
73
 
 
74
        DrawingCoords operator * (const float t) const
 
75
        {
 
76
                return DrawingCoords((u10)(x * t), (u10)(y * t), (u16)(z * t));
 
77
        }
 
78
 
 
79
        DrawingCoords operator + (const DrawingCoords& oth) const
 
80
        {
 
81
                return DrawingCoords(x + oth.x, y + oth.y, z + oth.z);
 
82
        }
 
83
};
 
84
 
 
85
struct VertexData
 
86
{
 
87
        void Lerp(float t, const VertexData& a, const VertexData& b)
 
88
        {
 
89
                // World coords only needed for lighting, so we don't Lerp those
 
90
 
 
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);
 
97
 
 
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);
 
101
        }
 
102
 
 
103
        ModelCoords modelpos;
 
104
        WorldCoords worldpos; // TODO: Storing this is dumb, should transform the light to clip space instead
 
105
        ClipCoords clippos;
 
106
        ScreenCoords screenpos; // TODO: Shouldn't store this ?
 
107
        Vec2<float> texturecoords;
 
108
        Vec3<float> normal;
 
109
        WorldCoords worldnormal;
 
110
        Vec4<int> color0;
 
111
        Vec3<int> color1;
 
112
        float fogdepth;
 
113
};
 
114
 
 
115
class VertexReader;
 
116
 
 
117
class TransformUnit
 
118
{
 
119
public:
 
120
        TransformUnit() {}
 
121
 
 
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);
 
129
 
 
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);
 
132
 
 
133
        static bool GetCurrentSimpleVertices(int count, std::vector<GPUDebugVertex> &vertices, std::vector<u16> &indices);
 
134
        static VertexData ReadVertex(VertexReader& vreader);
 
135
 
 
136
        static SplinePatch *patchBuffer_;
 
137
        static int patchBufferSize_;
 
138
 
 
139
        static bool outside_range_flag;
 
140
};