2012-11-01 16:19:01 +01: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
|
2012-11-04 23:01:49 +01:00
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
2012-11-01 16:19:01 +01:00
|
|
|
|
|
|
|
// 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
|
|
|
|
|
2013-01-30 21:09:53 +01:00
|
|
|
#include <list>
|
2013-12-29 23:44:35 +01:00
|
|
|
#include <set>
|
|
|
|
#include <algorithm>
|
2013-01-30 20:40:26 +01:00
|
|
|
|
2013-07-29 22:38:02 -07:00
|
|
|
#include "gfx/gl_common.h"
|
2013-01-30 21:09:53 +01:00
|
|
|
// Keeps track of allocated FBOs.
|
|
|
|
// Also provides facilities for drawing and later converting raw
|
|
|
|
// pixel data.
|
2013-01-30 20:40:26 +01:00
|
|
|
|
2012-11-01 16:19:01 +01:00
|
|
|
|
2015-09-06 13:05:18 +02:00
|
|
|
#include "Globals.h"
|
2013-02-17 01:06:06 +01:00
|
|
|
#include "GPU/GPUCommon.h"
|
2015-09-06 13:05:18 +02:00
|
|
|
#include "GPU/GLES/FBO.h"
|
2014-09-09 08:12:42 -07:00
|
|
|
#include "GPU/Common/FramebufferCommon.h"
|
2015-05-12 21:01:15 +02:00
|
|
|
#include "Core/Config.h"
|
2012-11-01 16:19:01 +01:00
|
|
|
|
2012-12-01 02:15:46 +01:00
|
|
|
struct GLSLProgram;
|
2013-02-01 00:18:23 +01:00
|
|
|
class TextureCache;
|
2014-06-11 00:28:28 -07:00
|
|
|
class TransformDrawEngine;
|
|
|
|
class ShaderManager;
|
2012-12-01 02:15:46 +01:00
|
|
|
|
2013-06-28 14:48:36 +01:00
|
|
|
// Simple struct for asynchronous PBO readbacks
|
|
|
|
struct AsyncPBO {
|
|
|
|
GLuint handle;
|
2013-07-01 21:51:24 +01:00
|
|
|
u32 maxSize;
|
2013-06-28 14:48:36 +01:00
|
|
|
|
|
|
|
u32 fb_address;
|
|
|
|
u32 stride;
|
|
|
|
u32 height;
|
2013-07-01 21:51:24 +01:00
|
|
|
u32 size;
|
2013-07-29 23:05:59 -07:00
|
|
|
GEBufferFormat format;
|
2013-06-28 14:48:36 +01:00
|
|
|
bool reading;
|
|
|
|
};
|
|
|
|
|
2015-01-22 12:48:25 +01:00
|
|
|
struct CardboardSettings {
|
2015-01-24 20:01:09 +01:00
|
|
|
bool enabled;
|
|
|
|
float leftEyeXPosition;
|
|
|
|
float rightEyeXPosition;
|
|
|
|
float screenYPosition;
|
|
|
|
float screenWidth;
|
|
|
|
float screenHeight;
|
2015-01-22 12:48:25 +01:00
|
|
|
};
|
|
|
|
|
2014-09-09 08:12:42 -07:00
|
|
|
class FramebufferManager : public FramebufferManagerCommon {
|
2012-12-01 02:15:46 +01:00
|
|
|
public:
|
|
|
|
FramebufferManager();
|
|
|
|
~FramebufferManager();
|
|
|
|
|
2013-02-01 00:18:23 +01:00
|
|
|
void SetTextureCache(TextureCache *tc) {
|
|
|
|
textureCache_ = tc;
|
|
|
|
}
|
2013-03-16 00:40:37 +01:00
|
|
|
void SetShaderManager(ShaderManager *sm) {
|
|
|
|
shaderManager_ = sm;
|
|
|
|
}
|
2014-06-11 00:28:28 -07:00
|
|
|
void SetTransformDrawEngine(TransformDrawEngine *td) {
|
|
|
|
transformDraw_ = td;
|
|
|
|
}
|
2013-02-01 00:18:23 +01:00
|
|
|
|
2015-09-17 20:29:37 +02:00
|
|
|
void MakePixelTexture(const u8 *srcPixels, GEBufferFormat srcPixelFormat, int srcStride, int width, int height) override;
|
|
|
|
void DrawPixels(VirtualFramebuffer *vfb, int dstX, int dstY, const u8 *srcPixels, GEBufferFormat srcPixelFormat, int srcStride, int width, int height) override;
|
2015-11-01 15:34:53 +01:00
|
|
|
void DrawFramebufferToOutput(const u8 *srcPixels, GEBufferFormat srcPixelFormat, int srcStride, bool applyPostShader) override;
|
2013-10-22 12:17:40 +02:00
|
|
|
|
|
|
|
// If texture != 0, will bind it.
|
2014-05-08 15:28:25 +02:00
|
|
|
// x,y,w,h are relative to destW, destH which fill out the target completely.
|
2015-11-01 22:40:31 +01:00
|
|
|
void DrawActiveTexture(GLuint texture, float x, float y, float w, float h, float destW, float destH, float u0, float v0, float u1, float v1, GLSLProgram *program, int uvRotation);
|
2012-12-01 02:15:46 +01:00
|
|
|
|
2013-01-30 21:09:53 +01:00
|
|
|
void DestroyAllFBOs();
|
2013-01-30 20:40:26 +01:00
|
|
|
|
2014-09-13 16:47:23 -07:00
|
|
|
virtual void Init() override;
|
2013-03-03 13:00:21 +01:00
|
|
|
void EndFrame();
|
2013-01-31 19:14:57 +08:00
|
|
|
void Resized();
|
2013-06-11 11:28:41 +02:00
|
|
|
void DeviceLost();
|
2013-01-30 21:09:53 +01:00
|
|
|
void CopyDisplayToOutput();
|
2013-10-09 19:00:35 +02:00
|
|
|
void SetLineWidth();
|
2014-09-07 08:47:04 -07:00
|
|
|
void ReformatFramebufferFrom(VirtualFramebuffer *vfb, GEBufferFormat old);
|
2013-06-22 22:27:59 +02:00
|
|
|
|
2014-09-14 11:54:55 -07:00
|
|
|
void BlitFramebufferDepth(VirtualFramebuffer *src, VirtualFramebuffer *dst);
|
2014-01-19 17:28:11 -08:00
|
|
|
|
|
|
|
// For use when texturing from a framebuffer. May create a duplicate if target.
|
2015-09-13 11:14:51 -07:00
|
|
|
void BindFramebufferColor(int stage, u32 fbRawAddress, VirtualFramebuffer *framebuffer, int flags);
|
2014-01-19 17:28:11 -08:00
|
|
|
|
2014-05-08 16:09:55 +02:00
|
|
|
// Reads a rectangular subregion of a framebuffer to the right position in its backing memory.
|
2016-01-04 21:29:03 -08:00
|
|
|
void ReadFramebufferToMemory(VirtualFramebuffer *vfb, bool sync, int x, int y, int w, int h) override;
|
2016-01-05 00:02:58 -08:00
|
|
|
void DownloadFramebufferForClut(u32 fb_address, u32 loadBytes) override;
|
2013-06-25 13:50:35 +01:00
|
|
|
|
2013-02-17 01:06:06 +01:00
|
|
|
std::vector<FramebufferInfo> GetFramebufferList();
|
|
|
|
|
2015-09-17 20:29:37 +02:00
|
|
|
bool NotifyStencilUpload(u32 addr, int size, bool skipZero = false) override;
|
2013-09-21 18:52:30 +02:00
|
|
|
|
2015-09-17 20:29:37 +02:00
|
|
|
void DestroyFramebuf(VirtualFramebuffer *vfb) override;
|
|
|
|
void ResizeFramebufFBO(VirtualFramebuffer *vfb, u16 w, u16 h, bool force = false) override;
|
2013-06-23 17:05:59 +02:00
|
|
|
|
2015-08-05 12:13:14 +02:00
|
|
|
bool GetFramebuffer(u32 fb_address, int fb_stride, GEBufferFormat format, GPUDebugBuffer &buffer);
|
|
|
|
bool GetDepthbuffer(u32 fb_address, int fb_stride, u32 z_address, int z_stride, GPUDebugBuffer &buffer);
|
|
|
|
bool GetStencilbuffer(u32 fb_address, int fb_stride, GPUDebugBuffer &buffer);
|
2014-12-20 08:31:56 -08:00
|
|
|
static bool GetDisplayFramebuffer(GPUDebugBuffer &buffer);
|
2013-09-22 19:03:31 -07:00
|
|
|
|
2014-09-13 14:26:39 -07:00
|
|
|
virtual void RebindFramebuffer() override;
|
2014-03-30 00:11:01 +01:00
|
|
|
|
2014-05-31 22:41:41 -07:00
|
|
|
FBO *GetTempFBO(u16 w, u16 h, FBOColorDepth depth = FBO_8888);
|
|
|
|
|
2015-01-24 20:01:09 +01:00
|
|
|
// Cardboard Settings Calculator
|
|
|
|
struct CardboardSettings * GetCardboardSettings(struct CardboardSettings * cardboardSettings);
|
2015-01-22 12:48:25 +01:00
|
|
|
|
2014-09-09 08:12:42 -07:00
|
|
|
protected:
|
|
|
|
virtual void DisableState() override;
|
2015-11-03 22:37:19 -08:00
|
|
|
virtual void ClearBuffer(bool keepState = false) override;
|
2014-09-13 14:23:18 -07:00
|
|
|
virtual void FlushBeforeCopy() override;
|
|
|
|
virtual void DecimateFBOs() override;
|
2014-09-09 08:12:42 -07:00
|
|
|
|
2014-09-13 15:12:06 -07:00
|
|
|
// Used by ReadFramebufferToMemory and later framebuffer block copies
|
2015-11-01 13:32:03 +01:00
|
|
|
virtual void BlitFramebuffer(VirtualFramebuffer *dst, int dstX, int dstY, VirtualFramebuffer *src, int srcX, int srcY, int w, int h, int bpp) override;
|
2014-09-13 15:12:06 -07:00
|
|
|
|
2014-09-09 22:56:54 -07:00
|
|
|
virtual void NotifyRenderFramebufferCreated(VirtualFramebuffer *vfb) override;
|
2015-08-05 01:03:49 +02:00
|
|
|
virtual void NotifyRenderFramebufferSwitched(VirtualFramebuffer *prevVfb, VirtualFramebuffer *vfb, bool isClearingDepth) override;
|
2014-09-09 22:56:54 -07:00
|
|
|
virtual void NotifyRenderFramebufferUpdated(VirtualFramebuffer *vfb, bool vfbFormatChanged) override;
|
2016-01-04 20:51:43 -08:00
|
|
|
virtual bool CreateDownloadTempBuffer(VirtualFramebuffer *nvfb) override;
|
|
|
|
virtual void UpdateDownloadTempBuffer(VirtualFramebuffer *nvfb) override;
|
2014-09-09 22:56:54 -07:00
|
|
|
|
2013-06-05 23:03:23 +02:00
|
|
|
private:
|
2015-11-02 22:22:48 +01:00
|
|
|
void UpdatePostShaderUniforms(int bufferWidth, int bufferHeight, int renderWidth, int renderHeight);
|
2013-07-16 22:50:53 +02:00
|
|
|
void CompileDraw2DProgram();
|
2013-09-26 12:41:07 +02:00
|
|
|
void DestroyDraw2DProgram();
|
2013-07-16 22:50:53 +02:00
|
|
|
|
2013-09-28 22:42:13 +02:00
|
|
|
void SetNumExtraFBOs(int num);
|
|
|
|
|
2015-09-05 23:39:10 +02:00
|
|
|
void PackFramebufferAsync_(VirtualFramebuffer *vfb); // Not used under ES currently
|
2014-05-25 19:48:46 -07:00
|
|
|
void PackFramebufferSync_(VirtualFramebuffer *vfb, int x, int y, int w, int h);
|
2016-01-18 12:57:37 -08:00
|
|
|
void PackDepthbuffer(VirtualFramebuffer *vfb, int x, int y, int w, int h);
|
2013-06-25 13:50:35 +01:00
|
|
|
|
2012-12-01 02:15:46 +01:00
|
|
|
// Used by DrawPixels
|
2013-06-05 23:03:23 +02:00
|
|
|
unsigned int drawPixelsTex_;
|
2013-07-29 23:05:59 -07:00
|
|
|
GEBufferFormat drawPixelsTexFormat_;
|
2014-05-09 22:26:42 +02:00
|
|
|
int drawPixelsTexW_;
|
|
|
|
int drawPixelsTexH_;
|
2012-12-01 02:15:46 +01:00
|
|
|
|
2014-05-25 16:28:13 -07:00
|
|
|
u8 *convBuf_;
|
|
|
|
u32 convBufSize_;
|
2013-09-26 12:41:07 +02:00
|
|
|
GLSLProgram *draw2dprogram_;
|
2013-10-30 22:44:01 +01:00
|
|
|
GLSLProgram *plainColorProgram_;
|
2013-10-12 02:05:55 +02:00
|
|
|
GLSLProgram *postShaderProgram_;
|
2014-05-31 18:24:35 -07:00
|
|
|
GLSLProgram *stencilUploadProgram_;
|
2013-10-30 22:44:01 +01:00
|
|
|
int plainColorLoc_;
|
2013-12-02 17:24:20 +01:00
|
|
|
int timeLoc_;
|
2015-10-31 16:02:25 +01:00
|
|
|
int pixelDeltaLoc_;
|
|
|
|
int deltaLoc_;
|
2013-02-01 00:18:23 +01:00
|
|
|
|
|
|
|
TextureCache *textureCache_;
|
2013-03-16 00:40:37 +01:00
|
|
|
ShaderManager *shaderManager_;
|
2014-06-11 00:28:28 -07:00
|
|
|
TransformDrawEngine *transformDraw_;
|
2013-09-28 22:42:13 +02:00
|
|
|
|
2013-10-30 00:12:19 +05:00
|
|
|
// Used by post-processing shader
|
2013-09-28 22:42:13 +02:00
|
|
|
std::vector<FBO *> extraFBOs_;
|
2013-02-01 00:18:23 +01:00
|
|
|
|
2013-01-30 21:09:53 +01:00
|
|
|
bool resized_;
|
2014-05-25 17:01:28 -07:00
|
|
|
|
2014-05-31 22:41:41 -07:00
|
|
|
struct TempFBO {
|
|
|
|
FBO *fbo;
|
|
|
|
int last_frame_used;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::map<u64, TempFBO> tempFBOs_;
|
2013-10-19 14:04:46 -07:00
|
|
|
|
2015-09-05 23:39:10 +02:00
|
|
|
// Not used under ES currently.
|
2013-10-19 14:04:46 -07:00
|
|
|
AsyncPBO *pixelBufObj_; //this isn't that large
|
|
|
|
u8 currentPBO_;
|
2013-01-31 19:14:57 +08:00
|
|
|
};
|