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/GLES/DrawEngineGLES.h
Views: 1401
1
// Copyright (c) 2012- 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/Data/Collections/Hashmaps.h"
21
#include "Common/GPU/OpenGL/GLCommon.h"
22
#include "Common/GPU/OpenGL/GLRenderManager.h"
23
24
#include "GPU/GPUState.h"
25
#include "GPU/Common/GPUDebugInterface.h"
26
#include "GPU/Common/IndexGenerator.h"
27
#include "GPU/Common/VertexDecoderCommon.h"
28
#include "GPU/Common/DrawEngineCommon.h"
29
#include "GPU/Common/GPUStateUtils.h"
30
#include "GPU/Common/FragmentShaderGenerator.h"
31
32
class LinkedShader;
33
class ShaderManagerGLES;
34
class TextureCacheGLES;
35
class FramebufferManagerGLES;
36
class FramebufferManagerCommon;
37
class TextureCacheCommon;
38
class FragmentTestCacheGLES;
39
struct TransformedVertex;
40
41
struct DecVtxFormat;
42
43
class TessellationDataTransferGLES : public TessellationDataTransfer {
44
private:
45
GLRTexture *data_tex[3]{};
46
int prevSizeU = 0, prevSizeV = 0;
47
int prevSizeWU = 0, prevSizeWV = 0;
48
GLRenderManager *renderManager_;
49
public:
50
TessellationDataTransferGLES(GLRenderManager *renderManager)
51
: renderManager_(renderManager) { }
52
~TessellationDataTransferGLES() {
53
EndFrame();
54
}
55
// Send spline/bezier's control points and weights to vertex shader through floating point texture.
56
void SendDataToShader(const SimpleVertex *const *points, int size_u, int size_v, u32 vertType, const Spline::Weight2D &weights) override;
57
void EndFrame(); // Queues textures for deletion.
58
};
59
60
// Handles transform, lighting and drawing.
61
class DrawEngineGLES : public DrawEngineCommon {
62
public:
63
DrawEngineGLES(Draw::DrawContext *draw);
64
~DrawEngineGLES();
65
66
void SetShaderManager(ShaderManagerGLES *shaderManager) {
67
shaderManager_ = shaderManager;
68
}
69
void SetTextureCache(TextureCacheGLES *textureCache) {
70
textureCache_ = textureCache;
71
}
72
void SetFramebufferManager(FramebufferManagerGLES *fbManager) {
73
framebufferManager_ = fbManager;
74
}
75
void SetFragmentTestCache(FragmentTestCacheGLES *testCache) {
76
fragmentTestCache_ = testCache;
77
}
78
79
void DeviceLost() override;
80
void DeviceRestore(Draw::DrawContext *draw) override;
81
82
void ClearTrackedVertexArrays() override {}
83
84
void BeginFrame();
85
void EndFrame();
86
87
// So that this can be inlined
88
void Flush() {
89
if (!numDrawVerts_)
90
return;
91
DoFlush();
92
}
93
94
void FinishDeferred() {
95
if (!numDrawVerts_)
96
return;
97
DoFlush();
98
}
99
100
void DispatchFlush() override {
101
if (!numDrawVerts_)
102
return;
103
Flush();
104
}
105
106
void ClearInputLayoutMap();
107
108
static bool SupportsHWTessellation() ;
109
110
protected:
111
bool UpdateUseHWTessellation(bool enable) const override;
112
113
private:
114
void Invalidate(InvalidationCallbackFlags flags);
115
116
void InitDeviceObjects();
117
void DestroyDeviceObjects();
118
119
void DoFlush();
120
void ApplyDrawState(int prim);
121
void ApplyDrawStateLate(bool setStencil, int stencilValue);
122
123
GLRInputLayout *SetupDecFmtForDraw(const DecVtxFormat &decFmt);
124
125
struct FrameData {
126
GLPushBuffer *pushVertex;
127
GLPushBuffer *pushIndex;
128
};
129
FrameData frameData_[GLRenderManager::MAX_INFLIGHT_FRAMES];
130
131
DenseHashMap<uint32_t, GLRInputLayout *> inputLayoutMap_;
132
133
GLRInputLayout *softwareInputLayout_ = nullptr;
134
GLRenderManager *render_;
135
136
// Other
137
ShaderManagerGLES *shaderManager_ = nullptr;
138
TextureCacheGLES *textureCache_ = nullptr;
139
FramebufferManagerGLES *framebufferManager_ = nullptr;
140
FragmentTestCacheGLES *fragmentTestCache_ = nullptr;
141
Draw::DrawContext *draw_;
142
143
// Need to preserve the scissor for use when clearing.
144
ViewportAndScissor vpAndScissor_{};
145
// Need to preserve writemask, easiest way.
146
GenericStencilFuncState stencilState_{};
147
148
int bufferDecimationCounter_ = 0;
149
int lastRenderStepId_ = -1;
150
151
// Hardware tessellation
152
TessellationDataTransferGLES *tessDataTransferGLES;
153
};
154
155