CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/GPU/Common/PresentationCommon.h
Views: 1401
// Copyright (c) 2012- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#pragma once1819#include "Common/Common.h"20#include "Common/GPU/Shader.h"2122struct CardboardSettings {23bool enabled;24float leftEyeXPosition;25float rightEyeXPosition;26float screenYPosition;27float screenWidth;28float screenHeight;29};3031struct PostShaderUniforms {32float texelDelta[2]; float pixelDelta[2];33float time[4];34float timeDelta[4];35float setting[4];36float video; float pad[3];37// Used on Direct3D9.38float gl_HalfPixel[4];39};4041// Could use UI::Bounds but don't want to depend on that here.42struct FRect {43float x;44float y;45float w;46float h;47};4849FRect GetScreenFrame(float pixelWidth, float pixelHeight);50void CalculateDisplayOutputRect(FRect *rc, float origW, float origH, const FRect &frame, int rotation);5152namespace Draw {53class Buffer;54class DrawContext;55class Framebuffer;56class Pipeline;57class SamplerState;58class ShaderModule;59class Texture;60}6162struct ShaderInfo;63class TextureCacheCommon;6465enum class OutputFlags {66LINEAR = 0x0000,67NEAREST = 0x0001,68RB_SWIZZLE = 0x0002,69BACKBUFFER_FLIPPED = 0x0004, // Viewport/scissor coordinates are y-flipped.70POSITION_FLIPPED = 0x0008, // Vertex position in the shader is y-flipped relative to the screen.71PILLARBOX = 0x0010, // Squeeze the image horizontally. Used for the DarkStalkers hack.72};73ENUM_CLASS_BITOPS(OutputFlags);7475class PresentationCommon {76public:77PresentationCommon(Draw::DrawContext *draw);78~PresentationCommon();7980void UpdateDisplaySize(int w, int h) {81pixelWidth_ = w;82pixelHeight_ = h;83}8485// NOTE: Should be un-rotated width/height.86void UpdateRenderSize(int rw, int rh) {87renderWidth_ = rw;88renderHeight_ = rh;89}90void SetLanguage(ShaderLanguage lang) {91lang_ = lang;92}9394bool HasPostShader() {95return usePostShader_;96}9798bool UpdatePostShader();99100void BeginFrame() {101presentedThisFrame_ = false;102}103bool PresentedThisFrame() const {104return presentedThisFrame_;105}106void NotifyPresent() {107// Something else did the present, skipping PresentationCommon.108// If you haven't called BindFramebufferAsRenderTarget, you must not set this.109presentedThisFrame_ = true;110}111112void DeviceLost();113void DeviceRestore(Draw::DrawContext *draw);114115void UpdateUniforms(bool hasVideo);116void SourceTexture(Draw::Texture *texture, int bufferWidth, int bufferHeight);117void SourceFramebuffer(Draw::Framebuffer *fb, int bufferWidth, int bufferHeight);118void CopyToOutput(OutputFlags flags, int uvRotation, float u0, float v0, float u1, float v1);119120void CalculateRenderResolution(int *width, int *height, int *scaleFactor, bool *upscaling, bool *ssaa) const;121122protected:123void CreateDeviceObjects();124void DestroyDeviceObjects();125126void DestroyPostShader();127void DestroyStereoShader();128129static void ShowPostShaderError(const std::string &errorString);130131Draw::ShaderModule *CompileShaderModule(ShaderStage stage, ShaderLanguage lang, const std::string &src, std::string *errorString) const;132Draw::Pipeline *CreatePipeline(std::vector<Draw::ShaderModule *> shaders, bool postShader, const UniformBufferDesc *uniformDesc) const;133bool CompilePostShader(const ShaderInfo *shaderInfo, Draw::Pipeline **outPipeline) const;134bool BuildPostShader(const ShaderInfo *shaderInfo, const ShaderInfo *next, Draw::Pipeline **outPipeline);135bool AllocateFramebuffer(int w, int h);136137bool BindSource(int binding, bool bindStereo);138139void GetCardboardSettings(CardboardSettings *cardboardSettings) const;140void CalculatePostShaderUniforms(int bufferWidth, int bufferHeight, int targetWidth, int targetHeight, const ShaderInfo *shaderInfo, PostShaderUniforms *uniforms) const;141142Draw::DrawContext *draw_;143Draw::Pipeline *texColor_ = nullptr;144Draw::Pipeline *texColorRBSwizzle_ = nullptr;145Draw::SamplerState *samplerNearest_ = nullptr;146Draw::SamplerState *samplerLinear_ = nullptr;147Draw::Buffer *vdata_ = nullptr;148149std::vector<Draw::Pipeline *> postShaderPipelines_;150std::vector<Draw::Framebuffer *> postShaderFramebuffers_;151std::vector<ShaderInfo> postShaderInfo_;152std::vector<Draw::Framebuffer *> previousFramebuffers_;153154Draw::Pipeline *stereoPipeline_ = nullptr;155ShaderInfo *stereoShaderInfo_ = nullptr;156157int previousIndex_ = 0;158PostShaderUniforms previousUniforms_{};159160Draw::Texture *srcTexture_ = nullptr;161Draw::Framebuffer *srcFramebuffer_ = nullptr;162int srcWidth_ = 0;163int srcHeight_ = 0;164bool hasVideo_ = false;165166int pixelWidth_ = 0;167int pixelHeight_ = 0;168int renderWidth_ = 0;169int renderHeight_ = 0;170171bool usePostShader_ = false;172bool restorePostShader_ = false;173bool presentedThisFrame_ = false;174ShaderLanguage lang_;175176struct PrevFBO {177Draw::Framebuffer *fbo;178int w;179int h;180};181std::vector<PrevFBO> postShaderFBOUsage_;182};183184185