CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

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