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/Software/Rasterizer.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 <functional>
21
#include "GPU/Software/DrawPixel.h"
22
#include "GPU/Software/FuncId.h"
23
#include "GPU/Software/Sampler.h"
24
#include "GPU/Software/TransformUnit.h" // for DrawingCoords
25
26
#ifdef _DEBUG
27
#define SOFTGPU_MEMORY_TAGGING_BASIC
28
#endif
29
// #define SOFTGPU_MEMORY_TAGGING_DETAILED
30
31
struct GPUDebugBuffer;
32
struct BinCoords;
33
class BinManager;
34
35
namespace Rasterizer {
36
37
enum class RasterizerStateFlags {
38
NONE = 0,
39
VERTEX_NON_FULL_WHITE = 0x0001,
40
VERTEX_ALPHA_NON_ZERO = 0x0002,
41
VERTEX_ALPHA_NON_FULL = 0x0004,
42
VERTEX_HAS_FOG = 0x0008,
43
44
CLUT_ALPHA_CHECKED = 0x0010,
45
CLUT_ALPHA_NON_FULL = 0x0020,
46
CLUT_ALPHA_NON_ZERO = 0x0040,
47
48
VERTEX_FLAT_RESET = VERTEX_NON_FULL_WHITE | VERTEX_ALPHA_NON_FULL | VERTEX_ALPHA_NON_ZERO | VERTEX_HAS_FOG,
49
50
OPTIMIZED = 0x0001'0000,
51
OPTIMIZED_BLEND_SRC = 0x0002'0000,
52
OPTIMIZED_BLEND_DST = 0x0004'0000,
53
OPTIMIZED_BLEND_OFF = 0x0008'0000,
54
OPTIMIZED_TEXREPLACE = 0x0010'0000,
55
OPTIMIZED_FOG_OFF = 0x0020'0000,
56
OPTIMIZED_ALPHATEST_OFF_NE = 0x0040'0000,
57
OPTIMIZED_ALPHATEST_OFF_GT = 0x0080'0000,
58
OPTIMIZED_ALPHATEST_ON = 0x0100'0000,
59
60
// Anything that changes the actual pixel or sampler func.
61
OPTIMIZED_PIXELID = OPTIMIZED_BLEND_SRC | OPTIMIZED_BLEND_DST | OPTIMIZED_BLEND_OFF | OPTIMIZED_FOG_OFF | OPTIMIZED_ALPHATEST_OFF_NE | OPTIMIZED_ALPHATEST_OFF_GT | OPTIMIZED_ALPHATEST_ON,
62
OPTIMIZED_SAMPLERID = OPTIMIZED_TEXREPLACE,
63
64
INVALID = 0x7FFFFFFF,
65
};
66
ENUM_CLASS_BITOPS(RasterizerStateFlags);
67
68
struct RasterizerState {
69
PixelFuncID pixelID;
70
SamplerID samplerID;
71
SingleFunc drawPixel;
72
Sampler::LinearFunc linear;
73
Sampler::NearestFunc nearest;
74
uint32_t texaddr[8]{};
75
uint16_t texbufw[8]{};
76
const u8 *texptr[8]{};
77
float textureLodSlope;
78
RasterizerStateFlags flags = RasterizerStateFlags::NONE;
79
RasterizerStateFlags lastFlags = RasterizerStateFlags::INVALID;
80
81
struct {
82
uint8_t maxTexLevel : 3;
83
bool enableTextures : 1;
84
uint8_t texLevelMode : 2;
85
bool shadeGouraud : 1;
86
bool throughMode : 1;
87
int8_t texLevelOffset : 8;
88
bool mipFilt : 1;
89
bool minFilt : 1;
90
bool magFilt : 1;
91
bool antialiasLines : 1;
92
bool textureProj : 1;
93
};
94
95
#if defined(SOFTGPU_MEMORY_TAGGING_DETAILED) || defined(SOFTGPU_MEMORY_TAGGING_BASIC)
96
uint32_t listPC;
97
#endif
98
99
GETexLevelMode TexLevelMode() const {
100
return GETexLevelMode(texLevelMode);
101
}
102
};
103
104
void ComputeRasterizerState(RasterizerState *state, BinManager *binner);
105
void CalculateRasterStateFlags(RasterizerState *state, const VertexData &v0);
106
void CalculateRasterStateFlags(RasterizerState *state, const VertexData &v0, const VertexData &v1, bool forceFlat);
107
void CalculateRasterStateFlags(RasterizerState *state, const VertexData &v0, const VertexData &v1, const VertexData &v2);
108
bool OptimizeRasterState(RasterizerState *state);
109
110
// Draws a triangle if its vertices are specified in counter-clockwise order
111
void DrawTriangle(const VertexData &v0, const VertexData &v1, const VertexData &v2, const BinCoords &range, const RasterizerState &state);
112
void DrawRectangle(const VertexData &v0, const VertexData &v1, const BinCoords &range, const RasterizerState &state);
113
void DrawPoint(const VertexData &v0, const BinCoords &range, const RasterizerState &state);
114
void DrawLine(const VertexData &v0, const VertexData &v1, const BinCoords &range, const RasterizerState &state);
115
void ClearRectangle(const VertexData &v0, const VertexData &v1, const BinCoords &range, const RasterizerState &state);
116
117
bool GetCurrentTexture(GPUDebugBuffer &buffer, int level);
118
119
} // namespace Rasterizer
120
121