2020-05-10 05:06:22 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-05-10 23:53:15 +00:00
|
|
|
#include "GPU/Common/ShaderCommon.h"
|
|
|
|
|
2020-05-10 05:06:22 +00:00
|
|
|
struct CardboardSettings {
|
|
|
|
bool enabled;
|
|
|
|
float leftEyeXPosition;
|
|
|
|
float rightEyeXPosition;
|
|
|
|
float screenYPosition;
|
|
|
|
float screenWidth;
|
|
|
|
float screenHeight;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PostShaderUniforms {
|
|
|
|
float texelDelta[2]; float pixelDelta[2];
|
|
|
|
float time[4];
|
2020-05-10 23:53:15 +00:00
|
|
|
float video; float pad[3];
|
|
|
|
// Used on Direct3D9.
|
|
|
|
float gl_HalfPixel[4];
|
2020-05-10 05:06:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void CenterDisplayOutputRect(float *x, float *y, float *w, float *h, float origW, float origH, float frameW, float frameH, int rotation);
|
|
|
|
|
|
|
|
namespace Draw {
|
|
|
|
class Buffer;
|
|
|
|
class DrawContext;
|
2020-05-10 07:38:19 +00:00
|
|
|
class Framebuffer;
|
2020-05-10 05:06:22 +00:00
|
|
|
class Pipeline;
|
|
|
|
class SamplerState;
|
2020-05-10 23:53:15 +00:00
|
|
|
class ShaderModule;
|
2020-05-10 07:38:19 +00:00
|
|
|
class Texture;
|
2020-05-10 05:06:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct ShaderInfo;
|
|
|
|
class TextureCacheCommon;
|
|
|
|
|
|
|
|
enum class OutputFlags {
|
|
|
|
LINEAR = 0x0000,
|
|
|
|
NEAREST = 0x0001,
|
|
|
|
RB_SWIZZLE = 0x0002,
|
2020-05-10 07:38:19 +00:00
|
|
|
BACKBUFFER_FLIPPED = 0x0004,
|
2020-05-10 05:06:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
inline OutputFlags operator | (const OutputFlags &lhs, const OutputFlags &rhs) {
|
|
|
|
return OutputFlags((int)lhs | (int)rhs);
|
|
|
|
}
|
|
|
|
inline OutputFlags operator |= (OutputFlags &lhs, const OutputFlags &rhs) {
|
|
|
|
lhs = lhs | rhs;
|
|
|
|
return lhs;
|
|
|
|
}
|
|
|
|
inline bool operator & (const OutputFlags &lhs, const OutputFlags &rhs) {
|
|
|
|
return ((int)lhs & (int)rhs) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
class PresentationCommon {
|
|
|
|
public:
|
|
|
|
PresentationCommon(Draw::DrawContext *draw);
|
|
|
|
~PresentationCommon();
|
|
|
|
|
2020-05-10 23:53:15 +00:00
|
|
|
void UpdateSize(int w, int h, int rw, int rh) {
|
2020-05-10 05:06:22 +00:00
|
|
|
pixelWidth_ = w;
|
|
|
|
pixelHeight_ = h;
|
2020-05-10 23:53:15 +00:00
|
|
|
renderWidth_ = rw;
|
|
|
|
renderHeight_ = rh;
|
|
|
|
}
|
|
|
|
void SetLanguage(ShaderLanguage lang) {
|
|
|
|
lang_ = lang;
|
2020-05-10 05:06:22 +00:00
|
|
|
}
|
2020-05-10 23:53:15 +00:00
|
|
|
|
|
|
|
bool UpdatePostShader();
|
2020-05-10 05:06:22 +00:00
|
|
|
void UpdateShaderInfo(const ShaderInfo *shaderInfo);
|
|
|
|
|
|
|
|
void DeviceLost();
|
|
|
|
void DeviceRestore(Draw::DrawContext *draw);
|
|
|
|
|
|
|
|
void GetCardboardSettings(CardboardSettings *cardboardSettings);
|
2020-05-10 23:53:15 +00:00
|
|
|
void CalculatePostShaderUniforms(int bufferWidth, int bufferHeight, bool hasVideo, PostShaderUniforms *uniforms);
|
2020-05-10 05:06:22 +00:00
|
|
|
|
2020-05-10 07:38:19 +00:00
|
|
|
void SourceTexture(Draw::Texture *texture);
|
|
|
|
void SourceFramebuffer(Draw::Framebuffer *fb);
|
2020-05-10 23:53:15 +00:00
|
|
|
void CopyToOutput(OutputFlags flags, int uvRotation, float u0, float v0, float u1, float v1, const PostShaderUniforms &uniforms);
|
2020-05-10 05:06:22 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void CreateDeviceObjects();
|
|
|
|
void DestroyDeviceObjects();
|
2020-05-10 23:53:15 +00:00
|
|
|
void DestroyPostShader();
|
|
|
|
|
|
|
|
void ShowPostShaderError(const std::string &errorString);
|
|
|
|
|
|
|
|
Draw::ShaderModule *CompileShaderModule(Draw::ShaderStage stage, ShaderLanguage lang, const std::string &src, std::string *errorString);
|
|
|
|
Draw::Pipeline *CreatePipeline(std::vector<Draw::ShaderModule *> shaders, bool postShader, const Draw::UniformBufferDesc *uniformDesc);
|
|
|
|
|
|
|
|
void BindSource();
|
2020-05-10 05:06:22 +00:00
|
|
|
|
|
|
|
Draw::DrawContext *draw_;
|
|
|
|
Draw::Pipeline *texColor_ = nullptr;
|
|
|
|
Draw::Pipeline *texColorRBSwizzle_ = nullptr;
|
|
|
|
Draw::SamplerState *samplerNearest_ = nullptr;
|
|
|
|
Draw::SamplerState *samplerLinear_ = nullptr;
|
|
|
|
Draw::Buffer *vdata_ = nullptr;
|
|
|
|
Draw::Buffer *idata_ = nullptr;
|
|
|
|
|
2020-05-10 23:53:15 +00:00
|
|
|
std::vector<Draw::ShaderModule *> postShaderModules_;
|
|
|
|
std::vector<Draw::Pipeline *> postShaderPipelines_;
|
|
|
|
std::vector<Draw::Framebuffer *> postShaderFramebuffers_;
|
|
|
|
|
2020-05-10 07:38:19 +00:00
|
|
|
Draw::Texture *srcTexture_ = nullptr;
|
|
|
|
Draw::Framebuffer *srcFramebuffer_ = nullptr;
|
|
|
|
|
2020-05-10 05:06:22 +00:00
|
|
|
int pixelWidth_ = 0;
|
|
|
|
int pixelHeight_ = 0;
|
2020-05-10 23:53:15 +00:00
|
|
|
int renderWidth_ = 0;
|
|
|
|
int renderHeight_ = 0;
|
|
|
|
|
|
|
|
bool usePostShader_ = false;
|
|
|
|
bool restorePostShader_ = false;
|
2020-05-10 05:06:22 +00:00
|
|
|
bool postShaderAtOutputResolution_ = false;
|
2020-05-10 23:53:15 +00:00
|
|
|
bool postShaderIsUpscalingFilter_ = false;
|
|
|
|
ShaderLanguage lang_;
|
2020-05-10 05:06:22 +00:00
|
|
|
};
|