Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/GPU/Common/SoftwareTransformCommon.h
3186 views
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 <vector>
21
#include "Common/CommonTypes.h"
22
#include "Common/Math/lin/matrix4x4.h"
23
#include "GPU/Common/VertexDecoderCommon.h"
24
#include "GPU/Common/TransformCommon.h"
25
26
class FramebufferManagerCommon;
27
class TextureCacheCommon;
28
29
enum SoftwareTransformAction {
30
SW_NOT_READY,
31
SW_DRAW_INDEXED,
32
SW_CLEAR,
33
};
34
35
struct SoftwareTransformResult {
36
SoftwareTransformAction action;
37
u32 color;
38
float depth;
39
40
bool setStencil;
41
u8 stencilValue;
42
43
bool setSafeSize;
44
u32 safeWidth;
45
u32 safeHeight;
46
47
TransformedVertex *drawBuffer;
48
int drawNumTrans;
49
bool pixelMapped;
50
};
51
52
struct SoftwareTransformParams {
53
u8 *decoded;
54
TransformedVertex *transformed;
55
TransformedVertex *transformedExpanded;
56
FramebufferManagerCommon *fbman;
57
TextureCacheCommon *texCache;
58
bool allowClear;
59
bool allowSeparateAlphaClear;
60
bool flippedY;
61
bool usesHalfZ;
62
};
63
64
// Converts an index buffer to make the provoking vertex the last.
65
// In-place. So, better not be doing this on GPU memory!
66
// TODO: We could do this already during index decode.
67
void IndexBufferProvokingLastToFirst(int prim, u16 *inds, int indsSize);
68
69
class SoftwareTransform {
70
public:
71
SoftwareTransform(SoftwareTransformParams &params) : params_(params) {}
72
73
void SetProjMatrix(const float mtx[14], bool invertedX, bool invertedY, const Lin::Vec3 &trans, const Lin::Vec3 &scale);
74
void Transform(int prim, u32 vertexType, const DecVtxFormat &decVtxFormat, int numDecodedVerts, SoftwareTransformResult *result);
75
76
// NOTE: The viewport must be up to date!
77
// indsSize is in indices, not bytes.
78
void BuildDrawingParams(int prim, int vertexCount, u32 vertType, u16 *&inds, int indsSize, int &numDecodedVerts, int vertsSize, SoftwareTransformResult *result);
79
80
protected:
81
void CalcCullParams(float &minZValue, float &maxZValue) const;
82
bool ExpandRectangles(int vertexCount, int &numDecodedVerts, int vertsSize, u16 *&inds, int indsSize, const TransformedVertex *transformed, TransformedVertex *transformedExpanded, int &numTrans, bool throughmode, bool *pixelMappedExactly) const;
83
static bool ExpandLines(int vertexCount, int &numDecodedVerts, int vertsSize, u16 *&inds, int indsSize, const TransformedVertex *transformed, TransformedVertex *transformedExpanded, int &numTrans, bool throughmode) ;
84
static bool ExpandPoints(int vertexCount, int &numDecodedVerts, int vertsSize, u16 *&inds, int indsSize, const TransformedVertex *transformed, TransformedVertex *transformedExpanded, int &numTrans, bool throughmode) ;
85
86
const SoftwareTransformParams &params_;
87
Lin::Matrix4x4 projMatrix_;
88
};
89
90
// Slow. See description in the cpp file.
91
u32 NormalizeVertices(SimpleVertex *sverts, u8 *bufPtr, const u8 *inPtr, int lowerBound, int upperBound, const VertexDecoder *dec, u32 vertType);
92
bool GetCurrentDrawAsDebugVertices(DrawEngineCommon *drawEngine, int count, std::vector<GPUDebugVertex> &vertices, std::vector<u16> &indices);
93
94