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/PresentationCommon.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/Common.h"
21
#include "Common/GPU/Shader.h"
22
23
struct CardboardSettings {
24
bool enabled;
25
float leftEyeXPosition;
26
float rightEyeXPosition;
27
float screenYPosition;
28
float screenWidth;
29
float screenHeight;
30
};
31
32
struct PostShaderUniforms {
33
float texelDelta[2]; float pixelDelta[2];
34
float time[4];
35
float timeDelta[4];
36
float setting[4];
37
float video; float pad[3];
38
// Used on Direct3D9.
39
float gl_HalfPixel[4];
40
};
41
42
// Could use UI::Bounds but don't want to depend on that here.
43
struct FRect {
44
float x;
45
float y;
46
float w;
47
float h;
48
};
49
50
FRect GetScreenFrame(float pixelWidth, float pixelHeight);
51
void CalculateDisplayOutputRect(FRect *rc, float origW, float origH, const FRect &frame, int rotation);
52
53
namespace Draw {
54
class Buffer;
55
class DrawContext;
56
class Framebuffer;
57
class Pipeline;
58
class SamplerState;
59
class ShaderModule;
60
class Texture;
61
}
62
63
struct ShaderInfo;
64
class TextureCacheCommon;
65
66
enum class OutputFlags {
67
LINEAR = 0x0000,
68
NEAREST = 0x0001,
69
RB_SWIZZLE = 0x0002,
70
BACKBUFFER_FLIPPED = 0x0004, // Viewport/scissor coordinates are y-flipped.
71
POSITION_FLIPPED = 0x0008, // Vertex position in the shader is y-flipped relative to the screen.
72
PILLARBOX = 0x0010, // Squeeze the image horizontally. Used for the DarkStalkers hack.
73
};
74
ENUM_CLASS_BITOPS(OutputFlags);
75
76
class PresentationCommon {
77
public:
78
PresentationCommon(Draw::DrawContext *draw);
79
~PresentationCommon();
80
81
void UpdateDisplaySize(int w, int h) {
82
pixelWidth_ = w;
83
pixelHeight_ = h;
84
}
85
86
// NOTE: Should be un-rotated width/height.
87
void UpdateRenderSize(int rw, int rh) {
88
renderWidth_ = rw;
89
renderHeight_ = rh;
90
}
91
void SetLanguage(ShaderLanguage lang) {
92
lang_ = lang;
93
}
94
95
bool HasPostShader() {
96
return usePostShader_;
97
}
98
99
bool UpdatePostShader();
100
101
void BeginFrame() {
102
presentedThisFrame_ = false;
103
}
104
bool PresentedThisFrame() const {
105
return presentedThisFrame_;
106
}
107
void NotifyPresent() {
108
// Something else did the present, skipping PresentationCommon.
109
// If you haven't called BindFramebufferAsRenderTarget, you must not set this.
110
presentedThisFrame_ = true;
111
}
112
113
void DeviceLost();
114
void DeviceRestore(Draw::DrawContext *draw);
115
116
void UpdateUniforms(bool hasVideo);
117
void SourceTexture(Draw::Texture *texture, int bufferWidth, int bufferHeight);
118
void SourceFramebuffer(Draw::Framebuffer *fb, int bufferWidth, int bufferHeight);
119
void CopyToOutput(OutputFlags flags, int uvRotation, float u0, float v0, float u1, float v1);
120
121
void CalculateRenderResolution(int *width, int *height, int *scaleFactor, bool *upscaling, bool *ssaa) const;
122
123
protected:
124
void CreateDeviceObjects();
125
void DestroyDeviceObjects();
126
127
void DestroyPostShader();
128
void DestroyStereoShader();
129
130
static void ShowPostShaderError(const std::string &errorString);
131
132
Draw::ShaderModule *CompileShaderModule(ShaderStage stage, ShaderLanguage lang, const std::string &src, std::string *errorString) const;
133
Draw::Pipeline *CreatePipeline(std::vector<Draw::ShaderModule *> shaders, bool postShader, const UniformBufferDesc *uniformDesc) const;
134
bool CompilePostShader(const ShaderInfo *shaderInfo, Draw::Pipeline **outPipeline) const;
135
bool BuildPostShader(const ShaderInfo *shaderInfo, const ShaderInfo *next, Draw::Pipeline **outPipeline);
136
bool AllocateFramebuffer(int w, int h);
137
138
bool BindSource(int binding, bool bindStereo);
139
140
void GetCardboardSettings(CardboardSettings *cardboardSettings) const;
141
void CalculatePostShaderUniforms(int bufferWidth, int bufferHeight, int targetWidth, int targetHeight, const ShaderInfo *shaderInfo, PostShaderUniforms *uniforms) const;
142
143
Draw::DrawContext *draw_;
144
Draw::Pipeline *texColor_ = nullptr;
145
Draw::Pipeline *texColorRBSwizzle_ = nullptr;
146
Draw::SamplerState *samplerNearest_ = nullptr;
147
Draw::SamplerState *samplerLinear_ = nullptr;
148
Draw::Buffer *vdata_ = nullptr;
149
150
std::vector<Draw::Pipeline *> postShaderPipelines_;
151
std::vector<Draw::Framebuffer *> postShaderFramebuffers_;
152
std::vector<ShaderInfo> postShaderInfo_;
153
std::vector<Draw::Framebuffer *> previousFramebuffers_;
154
155
Draw::Pipeline *stereoPipeline_ = nullptr;
156
ShaderInfo *stereoShaderInfo_ = nullptr;
157
158
int previousIndex_ = 0;
159
PostShaderUniforms previousUniforms_{};
160
161
Draw::Texture *srcTexture_ = nullptr;
162
Draw::Framebuffer *srcFramebuffer_ = nullptr;
163
int srcWidth_ = 0;
164
int srcHeight_ = 0;
165
bool hasVideo_ = false;
166
167
int pixelWidth_ = 0;
168
int pixelHeight_ = 0;
169
int renderWidth_ = 0;
170
int renderHeight_ = 0;
171
172
bool usePostShader_ = false;
173
bool restorePostShader_ = false;
174
bool presentedThisFrame_ = false;
175
ShaderLanguage lang_;
176
177
struct PrevFBO {
178
Draw::Framebuffer *fbo;
179
int w;
180
int h;
181
};
182
std::vector<PrevFBO> postShaderFBOUsage_;
183
};
184
185