Move all the GL/D3D9 FBO code into thin3d.

This commit is contained in:
Henrik Rydgard 2017-02-04 18:46:12 +01:00
parent abf7a7abe0
commit f1c96c056d
47 changed files with 984 additions and 1090 deletions

View File

@ -814,6 +814,8 @@ add_library(native STATIC
ext/native/file/vfs.h
ext/native/file/zip_read.cpp
ext/native/file/zip_read.h
ext/native/gfx/GLStateCache.cpp
ext/native/gfx/GLStateCache.h
ext/native/gfx/gl_common.h
ext/native/gfx/gl_debug_log.cpp
ext/native/gfx/gl_debug_log.h
@ -1084,8 +1086,6 @@ set(GPU_GLES
GPU/GLES/FBO.h
GPU/GLES/GPU_GLES.cpp
GPU/GLES/GPU_GLES.h
GPU/GLES/GLStateCache.cpp
GPU/GLES/GLStateCache.h
GPU/GLES/FragmentShaderGeneratorGLES.cpp
GPU/GLES/FragmentShaderGeneratorGLES.h
GPU/GLES/FragmentTestCacheGLES.cpp
@ -1156,8 +1156,6 @@ set(GPU_D3D9
GPU/Directx9/TextureScalerDX9.h
GPU/Directx9/VertexShaderGeneratorDX9.cpp
GPU/Directx9/VertexShaderGeneratorDX9.h
GPU/Directx9/helper/dx_fbo.cpp
GPU/Directx9/helper/dx_fbo.h
)

View File

@ -230,13 +230,7 @@ bool TakeGameScreenshot(const char *filename, ScreenshotFormat fmt, ScreenshotTy
w = maxRes > 0 ? 480 * maxRes : PSP_CoreParameter().renderWidth;
h = maxRes > 0 ? 272 * maxRes : PSP_CoreParameter().renderHeight;
} else {
if (GetGPUBackend() == GPUBackend::OPENGL) {
success = GPU_GLES::GetOutputFramebuffer(buf);
#ifdef _WIN32
} else if (GetGPUBackend() == GPUBackend::DIRECT3D9) {
success = DX9::GPU_DX9::GetOutputFramebuffer(buf);
#endif
}
success = gpuDebug->GetOutputFramebuffer(buf);
}
if (!success) {

View File

@ -20,7 +20,7 @@
#include "Common/Log.h"
#include "Core/Reporting.h"
#include "GPU/GPUState.h"
#include "GPU/GLES/GLStateCache.h"
#include "ext/native/gfx/GLStateCache.h"
#include "GPU/Common/DepalettizeShaderCommon.h"

View File

@ -46,9 +46,8 @@ enum {
FBO_READFBOMEMORY_MIN = 2
};
struct FBO;
namespace DX9 {
struct FBO_DX9;
namespace Draw {
class Framebuffer;
}
class VulkanFBO;
@ -91,11 +90,7 @@ struct VirtualFramebuffer {
// TODO: Handle fbo and colorDepth better.
u8 colorDepth;
union {
FBO *fbo;
DX9::FBO_DX9 *fbo_dx9;
VulkanFBO *fbo_vk;
};
Draw::Framebuffer *fbo;
u16 drawnWidth;
u16 drawnHeight;

View File

@ -237,6 +237,10 @@ public:
return false;
}
virtual bool GetOutputFramebuffer(GPUDebugBuffer &buffer) {
return false;
}
// TODO:
// cached framebuffers / textures / vertices?
// get content of specific framebuffer / texture?

View File

@ -16,6 +16,7 @@
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include <map>
#include <d3d9.h>
#include "base/logging.h"
#include "Common/Log.h"

View File

@ -16,6 +16,7 @@
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include <map>
#include <d3d9.h>
#include "Common/CommonTypes.h"
#include "GPU/ge_constants.h"

View File

@ -16,6 +16,7 @@
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include "math/lin/matrix4x4.h"
#include "ext/native/thin3d/thin3d.h"
#include "Common/ColorConv.h"
#include "Core/Host.h"
@ -28,8 +29,6 @@
#include "GPU/Debugger/Stepping.h"
#include "gfx/d3d9_state.h"
#include "helper/dx_fbo.h"
#include "GPU/Common/FramebufferCommon.h"
#include "GPU/Common/TextureDecoder.h"
#include "GPU/Directx9/FramebufferDX9.h"
@ -165,7 +164,7 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
drawPixelsTex_->Release();
}
for (auto it = tempFBOs_.begin(), end = tempFBOs_.end(); it != end; ++it) {
fbo_destroy(it->second.fbo);
delete it->second.fbo;
}
for (auto it = offscreenSurfaces_.begin(), end = offscreenSurfaces_.end(); it != end; ++it) {
it->second.surface->Release();
@ -262,8 +261,8 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
}
void FramebufferManagerDX9::DrawPixels(VirtualFramebuffer *vfb, int dstX, int dstY, const u8 *srcPixels, GEBufferFormat srcPixelFormat, int srcStride, int width, int height) {
if (useBufferedRendering_ && vfb && vfb->fbo_dx9) {
fbo_bind_as_render_target(vfb->fbo_dx9);
if (useBufferedRendering_ && vfb && vfb->fbo) {
draw_->fbo_bind_as_render_target(vfb->fbo);
D3DVIEWPORT9 vp{ 0, 0, vfb->renderWidth, vfb->renderHeight, 0.0f, 1.0f };
pD3Ddevice->SetViewport(&vp);
} else {
@ -349,9 +348,9 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
void FramebufferManagerDX9::DestroyFramebuf(VirtualFramebuffer *v) {
textureCache_->NotifyFramebuffer(v->fb_address, v, NOTIFY_FB_DESTROYED);
if (v->fbo_dx9) {
fbo_destroy(v->fbo_dx9);
v->fbo_dx9 = 0;
if (v->fbo) {
delete v->fbo;
v->fbo = nullptr;
}
// Wipe some pointers
@ -368,10 +367,10 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
}
void FramebufferManagerDX9::RebindFramebuffer() {
if (currentRenderVfb_ && currentRenderVfb_->fbo_dx9) {
fbo_bind_as_render_target(currentRenderVfb_->fbo_dx9);
if (currentRenderVfb_ && currentRenderVfb_->fbo) {
draw_->fbo_bind_as_render_target(currentRenderVfb_->fbo);
} else {
fbo_bind_backbuffer_as_render_target();
draw_->fbo_bind_backbuffer_as_render_target();
}
}
@ -399,49 +398,49 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
}
if (trueColor) {
vfb->colorDepth = FBO_8888;
vfb->colorDepth = Draw::FBO_8888;
} else {
switch (vfb->format) {
case GE_FORMAT_4444:
vfb->colorDepth = FBO_4444;
vfb->colorDepth = Draw::FBO_4444;
break;
case GE_FORMAT_5551:
vfb->colorDepth = FBO_5551;
vfb->colorDepth = Draw::FBO_5551;
break;
case GE_FORMAT_565:
vfb->colorDepth = FBO_565;
vfb->colorDepth = Draw::FBO_565;
break;
case GE_FORMAT_8888:
default:
vfb->colorDepth = FBO_8888;
vfb->colorDepth = Draw::FBO_8888;
break;
}
}
textureCache_->ForgetLastTexture();
fbo_bind_backbuffer_as_render_target();
draw_->fbo_bind_backbuffer_as_render_target();
if (!useBufferedRendering_) {
if (vfb->fbo_dx9) {
fbo_destroy(vfb->fbo_dx9);
vfb->fbo_dx9 = 0;
if (vfb->fbo) {
delete vfb->fbo;
vfb->fbo = nullptr;
}
return;
}
vfb->fbo_dx9 = fbo_create({ vfb->renderWidth, vfb->renderHeight, 1, 1, true, (FBOColorDepth)vfb->colorDepth });
if (old.fbo_dx9) {
vfb->fbo = draw_->fbo_create({ vfb->renderWidth, vfb->renderHeight, 1, 1, true, (Draw::FBColorDepth)vfb->colorDepth });
if (old.fbo) {
INFO_LOG(SCEGE, "Resizing FBO for %08x : %i x %i x %i", vfb->fb_address, w, h, vfb->format);
if (vfb->fbo) {
fbo_bind_as_render_target(vfb->fbo_dx9);
draw_->fbo_bind_as_render_target(vfb->fbo);
ClearBuffer();
if (!skipCopy && !g_Config.bDisableSlowFramebufEffects) {
BlitFramebuffer(vfb, 0, 0, &old, 0, 0, std::min(vfb->bufferWidth, vfb->width), std::min(vfb->height, vfb->bufferHeight), 0);
}
}
fbo_destroy(old.fbo_dx9);
if (vfb->fbo_dx9) {
fbo_bind_as_render_target(vfb->fbo_dx9);
delete old.fbo;
if (vfb->fbo) {
draw_->fbo_bind_as_render_target(vfb->fbo);
}
}
@ -452,7 +451,7 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
void FramebufferManagerDX9::NotifyRenderFramebufferCreated(VirtualFramebuffer *vfb) {
if (!useBufferedRendering_) {
fbo_bind_backbuffer_as_render_target();
draw_->fbo_bind_backbuffer_as_render_target();
// Let's ignore rendering to targets that have not (yet) been displayed.
gstate_c.skipDrawReason |= SKIPDRAW_NON_DISPLAYED_FB;
}
@ -480,20 +479,20 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
textureCache_->ForgetLastTexture();
if (useBufferedRendering_) {
if (vfb->fbo_dx9) {
fbo_bind_as_render_target(vfb->fbo_dx9);
if (vfb->fbo) {
draw_->fbo_bind_as_render_target(vfb->fbo);
} else {
// wtf? This should only happen very briefly when toggling bBufferedRendering
fbo_bind_backbuffer_as_render_target();
draw_->fbo_bind_backbuffer_as_render_target();
}
} else {
if (vfb->fbo_dx9) {
if (vfb->fbo) {
// wtf? This should only happen very briefly when toggling bBufferedRendering
textureCache_->NotifyFramebuffer(vfb->fb_address, vfb, NOTIFY_FB_DESTROYED);
fbo_destroy(vfb->fbo_dx9);
vfb->fbo_dx9 = nullptr;
delete vfb->fbo;
vfb->fbo = nullptr;
}
fbo_bind_backbuffer_as_render_target();
draw_->fbo_bind_backbuffer_as_render_target();
// Let's ignore rendering to targets that have not (yet) been displayed.
if (vfb->usageFlags & FB_USAGE_DISPLAYED_FRAMEBUFFER) {
@ -506,7 +505,7 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
// Copy depth pixel value from the read framebuffer to the draw framebuffer
if (prevVfb && !g_Config.bDisableSlowFramebufEffects) {
if (!prevVfb->fbo_dx9 || !vfb->fbo_dx9 || !useBufferedRendering_ || !prevVfb->depthUpdated || isClearingDepth) {
if (!prevVfb->fbo || !vfb->fbo || !useBufferedRendering_ || !prevVfb->depthUpdated || isClearingDepth) {
// If depth wasn't updated, then we're at least "two degrees" away from the data.
// This is an optimization: it probably doesn't need to be copied in this case.
} else {
@ -547,11 +546,11 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
}
void FramebufferManagerDX9::ReformatFramebufferFrom(VirtualFramebuffer *vfb, GEBufferFormat old) {
if (!useBufferedRendering_ || !vfb->fbo_dx9) {
if (!useBufferedRendering_ || !vfb->fbo) {
return;
}
fbo_bind_as_render_target(vfb->fbo_dx9);
draw_->fbo_bind_as_render_target(vfb->fbo);
// Technically, we should at this point re-interpret the bytes of the old format to the new.
// That might get tricky, and could cause unnecessary slowness in some games.
@ -630,10 +629,10 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
bool matchingSize = src->width == dst->width && src->height == dst->height;
if (matchingDepthBuffer && matchingSize) {
// Doesn't work. Use a shader maybe?
fbo_bind_backbuffer_as_render_target();
draw_->fbo_bind_backbuffer_as_render_target();
LPDIRECT3DTEXTURE9 srcTex = (LPDIRECT3DTEXTURE9)fbo_get_api_texture(src->fbo_dx9, FB_DEPTH_BIT, 0);
LPDIRECT3DTEXTURE9 dstTex = (LPDIRECT3DTEXTURE9)fbo_get_api_texture(dst->fbo_dx9, FB_DEPTH_BIT, 0);
LPDIRECT3DTEXTURE9 srcTex = (LPDIRECT3DTEXTURE9)draw_->fbo_get_api_texture(src->fbo, Draw::FB_DEPTH_BIT, 0);
LPDIRECT3DTEXTURE9 dstTex = (LPDIRECT3DTEXTURE9)draw_->fbo_get_api_texture(dst->fbo, Draw::FB_DEPTH_BIT, 0);
if (srcTex && dstTex) {
D3DSURFACE_DESC srcDesc;
@ -674,7 +673,7 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
}
}
FBO_DX9 *FramebufferManagerDX9::GetTempFBO(u16 w, u16 h, FBOColorDepth depth) {
Draw::Framebuffer *FramebufferManagerDX9::GetTempFBO(u16 w, u16 h, Draw::FBColorDepth depth) {
u64 key = ((u64)depth << 32) | ((u32)w << 16) | h;
auto it = tempFBOs_.find(key);
if (it != tempFBOs_.end()) {
@ -683,10 +682,10 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
}
textureCache_->ForgetLastTexture();
FBO_DX9 *fbo = fbo_create({ w, h, 1, 1, false, depth });
Draw::Framebuffer *fbo = draw_->fbo_create({ w, h, 1, 1, false, depth });
if (!fbo)
return fbo;
fbo_bind_as_render_target(fbo);
draw_->fbo_bind_as_render_target(fbo);
dxstate.viewport.force(0, 0, w, h);
ClearBuffer(true);
dxstate.viewport.restore();
@ -745,10 +744,10 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
}
if (!skipCopy && currentRenderVfb_ && framebuffer->fb_address == gstate.getFrameBufRawAddress()) {
// TODO: Maybe merge with bvfbs_? Not sure if those could be packing, and they're created at a different size.
FBO_DX9 *renderCopy = GetTempFBO(framebuffer->renderWidth, framebuffer->renderHeight, (FBOColorDepth)framebuffer->colorDepth);
Draw::Framebuffer *renderCopy = GetTempFBO(framebuffer->renderWidth, framebuffer->renderHeight, (Draw::FBColorDepth)framebuffer->colorDepth);
if (renderCopy) {
VirtualFramebuffer copyInfo = *framebuffer;
copyInfo.fbo_dx9 = renderCopy;
copyInfo.fbo = renderCopy;
int x = 0;
int y = 0;
@ -773,19 +772,19 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
BlitFramebuffer(&copyInfo, x, y, framebuffer, x, y, w, h, 0);
RebindFramebuffer();
fbo_bind_as_texture(renderCopy, stage, FB_COLOR_BIT, 0);
draw_->fbo_bind_as_texture(renderCopy, stage, Draw::FB_COLOR_BIT, 0);
} else {
fbo_bind_as_texture(framebuffer->fbo_dx9, stage, FB_COLOR_BIT, 0);
draw_->fbo_bind_as_texture(framebuffer->fbo, stage, Draw::FB_COLOR_BIT, 0);
}
} else {
fbo_bind_as_texture(framebuffer->fbo_dx9, stage, FB_COLOR_BIT, 0);
draw_->fbo_bind_as_texture(framebuffer->fbo, stage, Draw::FB_COLOR_BIT, 0);
}
}
void FramebufferManagerDX9::CopyDisplayToOutput() {
DownloadFramebufferOnSwitch(currentRenderVfb_);
fbo_bind_backbuffer_as_render_target();
draw_->fbo_bind_backbuffer_as_render_target();
currentRenderVfb_ = 0;
if (displayFramebufPtr_ == 0) {
@ -885,7 +884,7 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
if (vfb->fbo) {
DEBUG_LOG(SCEGE, "Displaying FBO %08x", vfb->fb_address);
DisableState();
fbo_bind_as_texture(vfb->fbo_dx9, 0, FB_COLOR_BIT, 0);
draw_->fbo_bind_as_texture(vfb->fbo, 0, Draw::FB_COLOR_BIT, 0);
// Output coordinates
float x, y, w, h;
@ -900,12 +899,12 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
if (1) {
const u32 rw = PSP_CoreParameter().pixelWidth;
const u32 rh = PSP_CoreParameter().pixelHeight;
bool result = fbo_blit(vfb->fbo_dx9,
bool result = draw_->fbo_blit(vfb->fbo,
(LONG)(u0 * vfb->renderWidth), (LONG)(v0 * vfb->renderHeight), (LONG)(u1 * vfb->renderWidth), (LONG)(v1 * vfb->renderHeight),
nullptr,
(LONG)(x * rw / w), (LONG)(y * rh / h), (LONG)((x + w) * rw / w), (LONG)((y + h) * rh / h),
FB_COLOR_BIT,
g_Config.iBufFilter == SCALE_LINEAR ? FB_BLIT_LINEAR : FB_BLIT_NEAREST);
Draw::FB_COLOR_BIT,
g_Config.iBufFilter == SCALE_LINEAR ? Draw::FB_BLIT_LINEAR : Draw::FB_BLIT_NEAREST);
if (!result) {
ERROR_LOG_REPORT_ONCE(blit_fail, G3D, "fbo_blit_color failed on display");
DXSetViewport(0, 0, PSP_CoreParameter().pixelWidth, PSP_CoreParameter().pixelHeight, 0.0f, 1.0f);
@ -1005,15 +1004,15 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
}
bool FramebufferManagerDX9::CreateDownloadTempBuffer(VirtualFramebuffer *nvfb) {
nvfb->colorDepth = FBO_8888;
nvfb->colorDepth = Draw::FBO_8888;
nvfb->fbo_dx9 = fbo_create({ nvfb->width, nvfb->height, 1, 1, true, (FBOColorDepth)nvfb->colorDepth });
if (!(nvfb->fbo_dx9)) {
nvfb->fbo = draw_->fbo_create({ nvfb->width, nvfb->height, 1, 1, true, (Draw::FBColorDepth)nvfb->colorDepth });
if (!(nvfb->fbo)) {
ERROR_LOG(SCEGE, "Error creating FBO! %i x %i", nvfb->renderWidth, nvfb->renderHeight);
return false;
}
fbo_bind_as_render_target(nvfb->fbo_dx9);
draw_->fbo_bind_as_render_target(nvfb->fbo);
ClearBuffer();
return true;
}
@ -1025,7 +1024,7 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
void FramebufferManagerDX9::BlitFramebuffer(VirtualFramebuffer *dst, int dstX, int dstY, VirtualFramebuffer *src, int srcX, int srcY, int w, int h, int bpp) {
if (!dst->fbo || !src->fbo || !useBufferedRendering_) {
// This can happen if they recently switched from non-buffered.
fbo_bind_backbuffer_as_render_target();
draw_->fbo_bind_backbuffer_as_render_target();
return;
}
@ -1052,23 +1051,23 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
int dstY2 = (dstY + h) * dstYFactor;
// Direct3D 9 doesn't support rect -> self.
FBO_DX9 *srcFBO = src->fbo_dx9;
Draw::Framebuffer *srcFBO = src->fbo;
if (src == dst) {
FBO_DX9 *tempFBO = GetTempFBO(src->renderWidth, src->renderHeight, (FBOColorDepth)src->colorDepth);
HRESULT hr = fbo_blit(
src->fbo_dx9, srcX1, srcY1, srcX2, srcY2,
Draw::Framebuffer *tempFBO = GetTempFBO(src->renderWidth, src->renderHeight, (Draw::FBColorDepth)src->colorDepth);
bool result = draw_->fbo_blit(
src->fbo, srcX1, srcY1, srcX2, srcY2,
tempFBO, dstX1, dstY1, dstX2, dstY2,
FB_COLOR_BIT, FB_BLIT_NEAREST);
if (SUCCEEDED(hr)) {
Draw::FB_COLOR_BIT, Draw::FB_BLIT_NEAREST);
if (result) {
srcFBO = tempFBO;
}
}
HRESULT hr = fbo_blit(
bool result = draw_->fbo_blit(
srcFBO, srcX1, srcY1, srcX2, srcY2,
dst->fbo_dx9, dstX1, dstY1, dstX2, dstY2,
FB_COLOR_BIT, FB_BLIT_NEAREST);
if (FAILED(hr)) {
ERROR_LOG_REPORT(G3D, "fbo_blit_color failed in blit: %08x (%08x -> %08x)", hr, src->fb_address, dst->fb_address);
dst->fbo, dstX1, dstY1, dstX2, dstY2,
Draw::FB_COLOR_BIT, Draw::FB_BLIT_NEAREST);
if (!result) {
ERROR_LOG_REPORT(G3D, "fbo_blit_color failed in blit: %08x (%08x -> %08x)", src->fb_address, dst->fb_address);
}
}
@ -1125,7 +1124,7 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
void FramebufferManagerDX9::PackFramebufferDirectx9_(VirtualFramebuffer *vfb, int x, int y, int w, int h) {
if (!vfb->fbo) {
ERROR_LOG_REPORT_ONCE(vfbfbozero, SCEGE, "PackFramebufferDirectx9_: vfb->fbo == 0");
fbo_bind_backbuffer_as_render_target();
draw_->fbo_bind_backbuffer_as_render_target();
return;
}
@ -1136,7 +1135,7 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
// Right now that's always 8888.
DEBUG_LOG(HLE, "Reading framebuffer to mem, fb_address = %08x", fb_address);
LPDIRECT3DSURFACE9 renderTarget = (LPDIRECT3DSURFACE9)fbo_get_api_texture(vfb->fbo_dx9, FB_COLOR_BIT | FB_SURFACE_BIT, 0);
LPDIRECT3DSURFACE9 renderTarget = (LPDIRECT3DSURFACE9)draw_->fbo_get_api_texture(vfb->fbo, Draw::FB_COLOR_BIT | Draw::FB_SURFACE_BIT, 0);
D3DSURFACE_DESC desc;
renderTarget->GetDesc(&desc);
@ -1175,7 +1174,7 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
DEBUG_LOG(SCEGE, "Reading depthbuffer to mem at %08x for vfb=%08x", z_address, vfb->fb_address);
LPDIRECT3DTEXTURE9 tex = (LPDIRECT3DTEXTURE9)fbo_get_api_texture(vfb->fbo_dx9, FB_DEPTH_BIT, 0);
LPDIRECT3DTEXTURE9 tex = (LPDIRECT3DTEXTURE9)draw_->fbo_get_api_texture(vfb->fbo, Draw::FB_DEPTH_BIT, 0);
if (tex) {
D3DSURFACE_DESC desc;
D3DLOCKED_RECT locked;
@ -1273,7 +1272,7 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
void FramebufferManagerDX9::DecimateFBOs() {
if (g_Config.iRenderingMode != FB_NON_BUFFERED_MODE) {
fbo_bind_backbuffer_as_render_target();
draw_->fbo_bind_backbuffer_as_render_target();
}
currentRenderVfb_ = 0;
bool updateVram = !(g_Config.iRenderingMode == FB_NON_BUFFERED_MODE || g_Config.iRenderingMode == FB_BUFFERED_MODE);
@ -1302,7 +1301,7 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
for (auto it = tempFBOs_.begin(); it != tempFBOs_.end(); ) {
int age = frameLastFramebufUsed_ - it->second.last_frame_used;
if (age > FBO_OLD_AGE) {
fbo_destroy(it->second.fbo);
delete it->second.fbo;
tempFBOs_.erase(it++);
} else {
++it;
@ -1332,7 +1331,7 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
}
void FramebufferManagerDX9::DestroyAllFBOs(bool forceDelete) {
fbo_bind_backbuffer_as_render_target();
draw_->fbo_bind_backbuffer_as_render_target();
currentRenderVfb_ = 0;
displayFramebuf_ = 0;
prevDisplayFramebuf_ = 0;
@ -1352,7 +1351,7 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
bvfbs_.clear();
for (auto it = tempFBOs_.begin(), end = tempFBOs_.end(); it != end; ++it) {
fbo_destroy(it->second.fbo);
delete it->second.fbo;
}
tempFBOs_.clear();
@ -1393,19 +1392,19 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
buffer = GPUDebugBuffer(Memory::GetPointer(fb_address | 0x04000000), fb_stride, 512, fb_format);
return true;
}
LPDIRECT3DSURFACE9 renderTarget = vfb->fbo_dx9 ? (LPDIRECT3DSURFACE9)fbo_get_api_texture(vfb->fbo_dx9, FB_COLOR_BIT | FB_SURFACE_BIT, 0) : nullptr;
LPDIRECT3DSURFACE9 renderTarget = vfb->fbo ? (LPDIRECT3DSURFACE9)draw_->fbo_get_api_texture(vfb->fbo, Draw::FB_COLOR_BIT | Draw::FB_SURFACE_BIT, 0) : nullptr;
bool success = false;
if (renderTarget) {
FBO_DX9 *tempFBO = nullptr;
Draw::Framebuffer *tempFBO = nullptr;
int w = vfb->renderWidth, h = vfb->renderHeight;
if (maxRes > 0 && vfb->renderWidth > vfb->width * maxRes) {
// Let's resize. We must stretch to a render target first.
w = vfb->width * maxRes;
h = vfb->height * maxRes;
tempFBO = fbo_create({ w, h, 1, 1, false, FBO_8888 });
if (fbo_blit(vfb->fbo_dx9, 0, 0, vfb->renderWidth, vfb->renderHeight, tempFBO, 0, 0, w, h, FB_COLOR_BIT, g_Config.iBufFilter == SCALE_LINEAR ? FB_BLIT_LINEAR : FB_BLIT_NEAREST)) {
renderTarget = (LPDIRECT3DSURFACE9)fbo_get_api_texture(tempFBO, FB_COLOR_BIT | FB_SURFACE_BIT, 0);
tempFBO = draw_->fbo_create({ w, h, 1, 1, false, Draw::FBO_8888 });
if (draw_->fbo_blit(vfb->fbo, 0, 0, vfb->renderWidth, vfb->renderHeight, tempFBO, 0, 0, w, h, Draw::FB_COLOR_BIT, g_Config.iBufFilter == SCALE_LINEAR ? Draw::FB_BLIT_LINEAR : Draw::FB_BLIT_NEAREST)) {
renderTarget = (LPDIRECT3DSURFACE9)draw_->fbo_get_api_texture(tempFBO, Draw::FB_COLOR_BIT | Draw::FB_SURFACE_BIT, 0);
}
}
@ -1414,7 +1413,7 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
success = GetRenderTargetFramebuffer(renderTarget, offscreen, w, h, buffer);
}
if (tempFBO) {
fbo_destroy(tempFBO);
delete tempFBO;
}
}
@ -1422,7 +1421,7 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
}
bool FramebufferManagerDX9::GetOutputFramebuffer(GPUDebugBuffer &buffer) {
fbo_bind_backbuffer_as_render_target();
draw_->fbo_bind_backbuffer_as_render_target();
LPDIRECT3DSURFACE9 renderTarget = nullptr;
HRESULT hr = pD3Ddevice->GetRenderTarget(0, &renderTarget);
@ -1484,7 +1483,7 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
}
bool success = false;
LPDIRECT3DTEXTURE9 tex = (LPDIRECT3DTEXTURE9)fbo_get_api_texture(vfb->fbo_dx9, FB_DEPTH_BIT, 0);
LPDIRECT3DTEXTURE9 tex = (LPDIRECT3DTEXTURE9)draw_->fbo_get_api_texture(vfb->fbo, Draw::FB_DEPTH_BIT, 0);
if (tex) {
D3DSURFACE_DESC desc;
D3DLOCKED_RECT locked;
@ -1528,7 +1527,7 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
}
bool success = false;
LPDIRECT3DTEXTURE9 tex = (LPDIRECT3DTEXTURE9)fbo_get_api_texture(vfb->fbo_dx9, FB_DEPTH_BIT, 0);
LPDIRECT3DTEXTURE9 tex = (LPDIRECT3DTEXTURE9)draw_->fbo_get_api_texture(vfb->fbo, Draw::FB_DEPTH_BIT, 0);
if (tex) {
D3DSURFACE_DESC desc;
D3DLOCKED_RECT locked;

View File

@ -23,7 +23,6 @@
#include "d3d9.h"
#include "GPU/Directx9/helper/dx_fbo.h"
// Keeps track of allocated FBOs.
// Also provides facilities for drawing and later converting raw
// pixel data.
@ -33,6 +32,7 @@
#include "GPU/GPUCommon.h"
#include "GPU/Common/FramebufferCommon.h"
#include "Core/Config.h"
#include "ext/native/thin3d/thin3d.h"
namespace DX9 {
@ -85,11 +85,11 @@ public:
bool GetCurrentFramebuffer(GPUDebugBuffer &buffer, GPUDebugFramebufferType type, int maxRes);
bool GetCurrentDepthbuffer(GPUDebugBuffer &buffer);
bool GetCurrentStencilbuffer(GPUDebugBuffer &buffer);
static bool GetOutputFramebuffer(GPUDebugBuffer &buffer);
bool GetOutputFramebuffer(GPUDebugBuffer &buffer);
virtual void RebindFramebuffer() override;
FBO_DX9 *GetTempFBO(u16 w, u16 h, FBOColorDepth depth = FBO_8888);
Draw::Framebuffer *GetTempFBO(u16 w, u16 h, Draw::FBColorDepth depth = Draw::FBO_8888);
LPDIRECT3DSURFACE9 GetOffscreenSurface(LPDIRECT3DSURFACE9 similarSurface, VirtualFramebuffer *vfb);
LPDIRECT3DSURFACE9 GetOffscreenSurface(D3DFORMAT fmt, u32 w, u32 h);
@ -142,12 +142,12 @@ private:
DrawEngineDX9 *drawEngine_;
// Used by post-processing shader
std::vector<FBO *> extraFBOs_;
std::vector<Draw::Framebuffer *> extraFBOs_;
bool resized_;
struct TempFBO {
FBO_DX9 *fbo;
Draw::Framebuffer *fbo;
int last_frame_used;
};
struct OffscreenSurface {

View File

@ -1082,7 +1082,7 @@ bool GPU_DX9::GetCurrentClut(GPUDebugBuffer &buffer) {
}
bool GPU_DX9::GetOutputFramebuffer(GPUDebugBuffer &buffer) {
return FramebufferManagerDX9::GetOutputFramebuffer(buffer);
return framebufferManagerDX9_->GetOutputFramebuffer(buffer);
}
bool GPU_DX9::GetCurrentSimpleVertices(int count, std::vector<GPUDebugVertex> &vertices, std::vector<u16> &indices) {

View File

@ -25,7 +25,6 @@
#include "GPU/Directx9/DrawEngineDX9.h"
#include "GPU/Directx9/TextureCacheDX9.h"
#include "GPU/Directx9/DepalettizeShaderDX9.h"
#include "GPU/Directx9/helper/dx_fbo.h"
#include "GPU/Common/VertexDecoderCommon.h"
namespace DX9 {
@ -71,7 +70,7 @@ public:
bool GetCurrentStencilbuffer(GPUDebugBuffer &buffer) override;
bool GetCurrentTexture(GPUDebugBuffer &buffer, int level) override;
bool GetCurrentClut(GPUDebugBuffer &buffer) override;
static bool GetOutputFramebuffer(GPUDebugBuffer &buffer);
bool GetOutputFramebuffer(GPUDebugBuffer &buffer) override;
bool GetCurrentSimpleVertices(int count, std::vector<GPUDebugVertex> &vertices, std::vector<u16> &indices) override;
typedef void (GPU_DX9::*CmdFunc)(u32 op, u32 diff);

View File

@ -0,0 +1,4 @@
#pragma once
#include "helper/global.h"
#include "ext/native/gfx/dx_state.h"

View File

@ -15,10 +15,12 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include <d3d9.h>
#include "base/logging.h"
#include "gfx/d3d9_state.h"
#include "helper/dx_fbo.h"
#include "ext/native/thin3d/thin3d.h"
#include "Core/Reporting.h"
#include "GPU/Directx9/FramebufferDX9.h"
#include "GPU/Directx9/PixelShaderGeneratorDX9.h"
@ -218,8 +220,8 @@ bool FramebufferManagerDX9::NotifyStencilUpload(u32 addr, int size, bool skipZer
u16 w = dstBuffer->renderWidth;
u16 h = dstBuffer->renderHeight;
if (dstBuffer->fbo_dx9) {
fbo_bind_as_render_target(dstBuffer->fbo_dx9);
if (dstBuffer->fbo) {
draw_->fbo_bind_as_render_target(dstBuffer->fbo);
}
D3DVIEWPORT9 vp{ 0, 0, w, h, 0.0f, 1.0f };
pD3Ddevice->SetViewport(&vp);

View File

@ -573,9 +573,9 @@ void TextureCacheDX9::SetTextureFramebuffer(TexCacheEntry *entry, VirtualFramebu
nextTexture_ = entry;
} else {
if (framebuffer->fbo_dx9) {
fbo_destroy(framebuffer->fbo_dx9);
framebuffer->fbo_dx9 = 0;
if (framebuffer->fbo) {
delete framebuffer->fbo;
framebuffer->fbo = nullptr;
}
pD3Ddevice->SetTexture(0, NULL);
gstate_c.needShaderTexClamp = false;
@ -779,8 +779,8 @@ void TextureCacheDX9::ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFrame
if (pshader) {
LPDIRECT3DTEXTURE9 clutTexture = depalShaderCache_->GetClutTexture(clutFormat, clutHash_, clutBuf_);
FBO_DX9 *depalFBO = framebufferManager_->GetTempFBO(framebuffer->renderWidth, framebuffer->renderHeight, FBO_8888);
fbo_bind_as_render_target(depalFBO);
Draw::Framebuffer *depalFBO = framebufferManager_->GetTempFBO(framebuffer->renderWidth, framebuffer->renderHeight, Draw::FBO_8888);
draw_->fbo_bind_as_render_target(depalFBO);
shaderManager_->DirtyLastShader();
float xoff = -0.5f / framebuffer->renderWidth;
@ -802,7 +802,7 @@ void TextureCacheDX9::ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFrame
shaderApply.Shade();
fbo_bind_as_texture(depalFBO, 0, FB_COLOR_BIT, 0);
draw_->fbo_bind_as_texture(depalFBO, 0, Draw::FB_COLOR_BIT, 0);
const u32 bytesPerColor = clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16);
const u32 clutTotalColors = clutMaxBytes_ / bytesPerColor;

View File

@ -18,9 +18,9 @@
#pragma once
#include <map>
#include <d3d9.h>
#include "../Globals.h"
#include "helper/dx_fbo.h"
#include "GPU/GPU.h"
#include "GPU/GPUInterface.h"
#include "GPU/Directx9/TextureScalerDX9.h"

View File

@ -1,195 +0,0 @@
// 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/.
#include <algorithm>
#include <cstdint>
#include <cstring>
#include <cstdio>
#include "base/logging.h"
#include "dx_fbo.h"
#include "gfx/d3d9_state.h"
namespace DX9 {
struct FBO_DX9 {
uint32_t id;
LPDIRECT3DSURFACE9 surf;
LPDIRECT3DSURFACE9 depthstencil;
LPDIRECT3DTEXTURE9 tex;
LPDIRECT3DTEXTURE9 depthstenciltex;
int width;
int height;
DX9::FBOColorDepth colorDepth;
};
static LPDIRECT3DSURFACE9 deviceRTsurf;
static LPDIRECT3DSURFACE9 deviceDSsurf;
static bool supportsINTZ = false;
static LPDIRECT3DDEVICE9 g_device;
#define FB_DIV 1
#define FOURCC_INTZ ((D3DFORMAT)(MAKEFOURCC('I', 'N', 'T', 'Z')))
void fbo_init(LPDIRECT3D9 d3d, LPDIRECT3DDEVICE9 device) {
g_device = device;
g_device->GetRenderTarget(0, &deviceRTsurf);
g_device->GetDepthStencilSurface(&deviceDSsurf);
if (d3d) {
D3DDISPLAYMODE displayMode;
d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &displayMode);
// To be safe, make sure both the display format and the FBO format support INTZ.
HRESULT displayINTZ = d3d->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, displayMode.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, FOURCC_INTZ);
HRESULT fboINTZ = d3d->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_A8R8G8B8, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, FOURCC_INTZ);
supportsINTZ = SUCCEEDED(displayINTZ) && SUCCEEDED(fboINTZ);
}
}
void fbo_shutdown() {
deviceRTsurf->Release();
deviceDSsurf->Release();
}
FBO_DX9 *fbo_create(const FramebufferDesc &desc) {
static uint32_t id = 0;
FBO_DX9 *fbo = new FBO_DX9();
fbo->width = desc.width;
fbo->height = desc.height;
fbo->colorDepth = desc.colorDepth;
fbo->depthstenciltex = nullptr;
HRESULT rtResult = g_device->CreateTexture(fbo->width, fbo->height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &fbo->tex, NULL);
if (FAILED(rtResult)) {
ELOG("Failed to create render target");
delete fbo;
return NULL;
}
fbo->tex->GetSurfaceLevel(0, &fbo->surf);
HRESULT dsResult;
if (supportsINTZ) {
dsResult = g_device->CreateTexture(fbo->width, fbo->height, 1, D3DUSAGE_DEPTHSTENCIL, FOURCC_INTZ, D3DPOOL_DEFAULT, &fbo->depthstenciltex, NULL);
if (SUCCEEDED(dsResult)) {
dsResult = fbo->depthstenciltex->GetSurfaceLevel(0, &fbo->depthstencil);
}
} else {
dsResult = g_device->CreateDepthStencilSurface(fbo->width, fbo->height, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, 0, FALSE, &fbo->depthstencil, NULL);
}
if (FAILED(dsResult)) {
ELOG("Failed to create depth buffer");
fbo->surf->Release();
fbo->tex->Release();
if (fbo->depthstenciltex) {
fbo->depthstenciltex->Release();
}
delete fbo;
return NULL;
}
fbo->id = id++;
return fbo;
}
void fbo_destroy(FBO_DX9 *fbo) {
fbo->tex->Release();
fbo->surf->Release();
fbo->depthstencil->Release();
if (fbo->depthstenciltex) {
fbo->depthstenciltex->Release();
}
delete fbo;
}
void fbo_bind_backbuffer_as_render_target() {
g_device->SetRenderTarget(0, deviceRTsurf);
g_device->SetDepthStencilSurface(deviceDSsurf);
dxstate.scissorRect.restore();
dxstate.viewport.restore();
}
void fbo_resolve(FBO_DX9 *fbo) {
}
void fbo_bind_as_render_target(FBO_DX9 *fbo) {
g_device->SetRenderTarget(0, fbo->surf);
g_device->SetDepthStencilSurface(fbo->depthstencil);
dxstate.scissorRect.restore();
dxstate.viewport.restore();
}
uintptr_t fbo_get_api_texture(FBO_DX9 *fbo, int channelBits, int attachment) {
if (channelBits & FB_SURFACE_BIT) {
switch (channelBits & 7) {
case FB_DEPTH_BIT:
return (uintptr_t)fbo->depthstencil;
case FB_STENCIL_BIT:
return (uintptr_t)fbo->depthstencil;
case FB_COLOR_BIT:
default:
return (uintptr_t)fbo->surf;
}
} else {
switch (channelBits & 7) {
case FB_DEPTH_BIT:
return (uintptr_t)fbo->depthstenciltex;
case FB_STENCIL_BIT:
return 0; // Can't texture from stencil
case FB_COLOR_BIT:
default:
return (uintptr_t)fbo->tex;
}
}
}
LPDIRECT3DSURFACE9 fbo_get_color_for_read(FBO_DX9 *fbo) {
return fbo->surf;
}
void fbo_bind_as_texture(FBO_DX9 *fbo, int binding, FBOChannel channelBit, int color) {
switch (channelBit) {
case FB_DEPTH_BIT:
if (fbo->depthstenciltex) {
g_device->SetTexture(binding, fbo->depthstenciltex);
}
break;
case FB_COLOR_BIT:
default:
if (fbo->tex) {
g_device->SetTexture(binding, fbo->tex);
}
break;
}
}
void fbo_get_dimensions(FBO_DX9 *fbo, int *w, int *h) {
*w = fbo->width;
*h = fbo->height;
}
bool fbo_blit(FBO_DX9 *src, int srcX1, int srcY1, int srcX2, int srcY2, FBO_DX9 *dst, int dstX1, int dstY1, int dstX2, int dstY2, int channelBits, FBBlitFilter filter) {
if (channelBits != FB_COLOR_BIT)
return false;
RECT srcRect{ (LONG)srcX1, (LONG)srcY1, (LONG)srcX2, (LONG)srcY2 };
RECT dstRect{ (LONG)dstX1, (LONG)dstY1, (LONG)dstX2, (LONG)dstY2 };
LPDIRECT3DSURFACE9 srcSurf = src ? src->surf : deviceRTsurf;
LPDIRECT3DSURFACE9 dstSurf = dst ? dst->surf : deviceRTsurf;
return SUCCEEDED(g_device->StretchRect(srcSurf, &srcRect, dstSurf, &dstRect, filter == FB_BLIT_LINEAR ? D3DTEXF_LINEAR : D3DTEXF_POINT));
}
} // namespace

View File

@ -1,85 +0,0 @@
// 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
#include <d3d9.h>
// Simple wrapper around FBO functionality.
// Very C-ish API because that's what I felt like, and it's cool to completely
// hide the data from callers...
namespace DX9 {
struct FBO_DX9;
enum FBOColorDepth {
FBO_8888,
FBO_565,
FBO_4444,
FBO_5551,
};
enum FBOChannel {
FB_COLOR_BIT = 1,
FB_DEPTH_BIT = 2,
FB_STENCIL_BIT = 4,
FB_SURFACE_BIT = 32,
};
enum FBBlitFilter {
FB_BLIT_NEAREST = 0,
FB_BLIT_LINEAR = 1,
};
struct FramebufferDesc {
int width;
int height;
int depth;
int numColorAttachments;
bool z_stencil;
FBOColorDepth colorDepth;
};
// Creates a simple FBO with a RGBA32 color buffer stored in a texture, and
// optionally an accompanying Z/stencil buffer.
// No mipmap support.
// num_color_textures must be 1 for now.
// you lose bound texture state.
// On some hardware, you might get a 24-bit depth buffer even though you only wanted a 16-bit one.
FBO_DX9 *fbo_create(const FramebufferDesc &desc);
void fbo_destroy(FBO_DX9 *fbo);
bool fbo_blit(FBO_DX9 *src, int srcX1, int srcY1, int srcX2, int srcY2, FBO_DX9 *dst, int dstX1, int dstY1, int dstX2, int dstY2, int channelBits, FBBlitFilter filter);
// These functions should be self explanatory.
void fbo_bind_as_render_target(FBO_DX9 *fbo);
// color must be 0.
void fbo_bind_as_texture(FBO_DX9 *fbo, int binding, FBOChannel channelBit, int color);
void fbo_bind_backbuffer_as_render_target();
void fbo_get_dimensions(FBO_DX9 *fbo, int *w, int *h);
void fbo_resolve(FBO_DX9 *fbo);
// Escape route until we complete the API
uintptr_t fbo_get_api_texture(FBO_DX9 *fbo, int channelBits, int attachment);
// To get default depth and rt surface
void fbo_init(LPDIRECT3D9 d3d, LPDIRECT3DDEVICE9 device);
void fbo_shutdown();
};

View File

@ -22,7 +22,7 @@
#include "Core/Reporting.h"
#include "DepalettizeShaderGLES.h"
#include "GPU/GLES/TextureCacheGLES.h"
#include "GPU/GLES/GLStateCache.h"
#include "ext/native/gfx/GLStateCache.h"
#include "GPU/Common/DepalettizeShaderCommon.h"
static const int DEPAL_TEXTURE_OLD_AGE = 120;

View File

@ -82,7 +82,7 @@
#include "GPU/Common/SplineCommon.h"
#include "GPU/Common/VertexDecoderCommon.h"
#include "GPU/Common/SoftwareTransformCommon.h"
#include "GPU/GLES/GLStateCache.h"
#include "ext/native/gfx/GLStateCache.h"
#include "GPU/GLES/FragmentTestCacheGLES.h"
#include "GPU/GLES/StateMappingGLES.h"
#include "GPU/GLES/TextureCacheGLES.h"

View File

@ -1,429 +0,0 @@
// 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/.
#include <string.h>
#include "base/logging.h"
#include "gfx/gl_common.h"
#include "GPU/GLES/GLStateCache.h"
#include "GPU/GLES/FBO.h"
#ifdef IOS
extern void bindDefaultFBO();
#endif
struct FBO {
GLuint handle;
GLuint color_texture;
GLuint z_stencil_buffer; // Either this is set, or the two below.
GLuint z_buffer;
GLuint stencil_buffer;
int width;
int height;
FBOColorDepth colorDepth;
};
static GLuint currentDrawHandle_ = 0;
static GLuint currentReadHandle_ = 0;
// On PC, we always use GL_DEPTH24_STENCIL8.
// On Android, we try to use what's available.
#ifndef USING_GLES2
FBO *fbo_ext_create(const FramebufferDesc &desc) {
FBO *fbo = new FBO();
fbo->width = desc.width;
fbo->height = desc.height;
fbo->colorDepth = desc.colorDepth;
// Color texture is same everywhere
glGenFramebuffersEXT(1, &fbo->handle);
glGenTextures(1, &fbo->color_texture);
// Create the surfaces.
glBindTexture(GL_TEXTURE_2D, fbo->color_texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// TODO: We could opt to only create 16-bit render targets on slow devices. For later.
switch (fbo->colorDepth) {
case FBO_8888:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fbo->width, fbo->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
break;
case FBO_4444:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fbo->width, fbo->height, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, NULL);
break;
case FBO_5551:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fbo->width, fbo->height, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, NULL);
break;
case FBO_565:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, fbo->width, fbo->height, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, NULL);
break;
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
fbo->stencil_buffer = 0;
fbo->z_buffer = 0;
// 24-bit Z, 8-bit stencil
glGenRenderbuffersEXT(1, &fbo->z_stencil_buffer);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fbo->z_stencil_buffer);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_STENCIL_EXT, fbo->width, fbo->height);
//glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH24_STENCIL8, width, height);
// Bind it all together
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo->handle);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, fbo->color_texture, 0);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, fbo->z_stencil_buffer);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, fbo->z_stencil_buffer);
GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
switch(status) {
case GL_FRAMEBUFFER_COMPLETE_EXT:
// ILOG("Framebuffer verified complete.");
break;
case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
ELOG("GL_FRAMEBUFFER_UNSUPPORTED");
break;
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
ELOG("GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT ");
break;
default:
FLOG("Other framebuffer error: %i", status);
break;
}
// Unbind state we don't need
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
glBindTexture(GL_TEXTURE_2D, 0);
currentDrawHandle_ = fbo->handle;
currentReadHandle_ = fbo->handle;
return fbo;
}
#endif
int fbo_preferred_z_bitdepth() {
// This matches the fbo_create() logic.
if (gl_extensions.IsGLES) {
if (gl_extensions.OES_packed_depth_stencil) {
return 24;
}
return gl_extensions.OES_depth24 ? 24 : 16;
} else {
return 24;
}
}
FBO *fbo_create(const FramebufferDesc &desc) {
CheckGLExtensions();
#ifndef USING_GLES2
if (!gl_extensions.ARB_framebuffer_object && gl_extensions.EXT_framebuffer_object) {
return fbo_ext_create(desc);
} else if (!gl_extensions.ARB_framebuffer_object) {
return nullptr;
}
// If GLES2, we have basic FBO support and can just proceed.
#endif
FBO *fbo = new FBO();
fbo->width = desc.width;
fbo->height = desc.height;
fbo->colorDepth = desc.colorDepth;
// Color texture is same everywhere
glGenFramebuffers(1, &fbo->handle);
glGenTextures(1, &fbo->color_texture);
// Create the surfaces.
glBindTexture(GL_TEXTURE_2D, fbo->color_texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// TODO: We could opt to only create 16-bit render targets on slow devices. For later.
switch (fbo->colorDepth) {
case FBO_8888:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fbo->width, fbo->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
break;
case FBO_4444:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fbo->width, fbo->height, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, NULL);
break;
case FBO_5551:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fbo->width, fbo->height, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, NULL);
break;
case FBO_565:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, fbo->width, fbo->height, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, NULL);
break;
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
if (gl_extensions.IsGLES) {
if (gl_extensions.OES_packed_depth_stencil) {
ILOG("Creating %i x %i FBO using DEPTH24_STENCIL8", fbo->width, fbo->height);
// Standard method
fbo->stencil_buffer = 0;
fbo->z_buffer = 0;
// 24-bit Z, 8-bit stencil combined
glGenRenderbuffers(1, &fbo->z_stencil_buffer);
glBindRenderbuffer(GL_RENDERBUFFER, fbo->z_stencil_buffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, fbo->width, fbo->height);
// Bind it all together
glBindFramebuffer(GL_FRAMEBUFFER, fbo->handle);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbo->color_texture, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fbo->z_stencil_buffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, fbo->z_stencil_buffer);
} else {
ILOG("Creating %i x %i FBO using separate stencil", fbo->width, fbo->height);
// TEGRA
fbo->z_stencil_buffer = 0;
// 16/24-bit Z, separate 8-bit stencil
glGenRenderbuffers(1, &fbo->z_buffer);
glBindRenderbuffer(GL_RENDERBUFFER, fbo->z_buffer);
// Don't forget to make sure fbo_standard_z_depth() matches.
glRenderbufferStorage(GL_RENDERBUFFER, gl_extensions.OES_depth24 ? GL_DEPTH_COMPONENT24 : GL_DEPTH_COMPONENT16, fbo->width, fbo->height);
// 8-bit stencil buffer
glGenRenderbuffers(1, &fbo->stencil_buffer);
glBindRenderbuffer(GL_RENDERBUFFER, fbo->stencil_buffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, fbo->width, fbo->height);
// Bind it all together
glBindFramebuffer(GL_FRAMEBUFFER, fbo->handle);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbo->color_texture, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fbo->z_buffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, fbo->stencil_buffer);
}
} else {
fbo->stencil_buffer = 0;
fbo->z_buffer = 0;
// 24-bit Z, 8-bit stencil
glGenRenderbuffers(1, &fbo->z_stencil_buffer);
glBindRenderbuffer(GL_RENDERBUFFER, fbo->z_stencil_buffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, fbo->width, fbo->height);
// Bind it all together
glBindFramebuffer(GL_FRAMEBUFFER, fbo->handle);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbo->color_texture, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fbo->z_stencil_buffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, fbo->z_stencil_buffer);
}
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
switch (status) {
case GL_FRAMEBUFFER_COMPLETE:
// ILOG("Framebuffer verified complete.");
break;
case GL_FRAMEBUFFER_UNSUPPORTED:
ELOG("GL_FRAMEBUFFER_UNSUPPORTED");
break;
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
ELOG("GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT ");
break;
default:
FLOG("Other framebuffer error: %i", status);
break;
}
// Unbind state we don't need
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glBindTexture(GL_TEXTURE_2D, 0);
currentDrawHandle_ = fbo->handle;
currentReadHandle_ = fbo->handle;
return fbo;
}
static GLenum fbo_get_fb_target(bool read, GLuint **cached) {
bool supportsBlit = gl_extensions.ARB_framebuffer_object;
if (gl_extensions.IsGLES) {
supportsBlit = (gl_extensions.GLES3 || gl_extensions.NV_framebuffer_blit);
}
// Note: GL_FRAMEBUFFER_EXT and GL_FRAMEBUFFER have the same value, same with _NV.
if (supportsBlit) {
if (read) {
*cached = &currentReadHandle_;
return GL_READ_FRAMEBUFFER;
} else {
*cached = &currentDrawHandle_;
return GL_DRAW_FRAMEBUFFER;
}
} else {
*cached = &currentDrawHandle_;
return GL_FRAMEBUFFER;
}
}
static void fbo_bind_fb_target(bool read, GLuint name) {
GLuint *cached;
GLenum target = fbo_get_fb_target(read, &cached);
if (*cached != name) {
if (gl_extensions.ARB_framebuffer_object || gl_extensions.IsGLES) {
glBindFramebuffer(target, name);
} else {
#ifndef USING_GLES2
glBindFramebufferEXT(target, name);
#endif
}
*cached = name;
}
}
static void fbo_unbind() {
#ifndef USING_GLES2
if (gl_extensions.ARB_framebuffer_object || gl_extensions.IsGLES) {
glBindFramebuffer(GL_FRAMEBUFFER, 0);
} else if (gl_extensions.EXT_framebuffer_object) {
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}
#else
glBindFramebuffer(GL_FRAMEBUFFER, 0);
#endif
#ifdef IOS
bindDefaultFBO();
#endif
currentDrawHandle_ = 0;
currentReadHandle_ = 0;
}
void fbo_bind_as_render_target(FBO *fbo) {
// Without FBO_ARB / GLES3, this will collide with bind_for_read, but there's nothing
// in ES 2.0 that actually separate them anyway of course, so doesn't matter.
fbo_bind_fb_target(false, fbo->handle);
// Always restore viewport after render target binding
glstate.viewport.restore();
}
void fbo_bind_backbuffer_as_render_target() {
fbo_unbind();
}
// For GL_EXT_FRAMEBUFFER_BLIT and similar.
void fbo_bind_for_read(FBO *fbo) {
fbo_bind_fb_target(true, fbo->handle);
}
void fbo_copy_image(FBO *src, int srcLevel, int srcX, int srcY, int srcZ, FBO *dst, int dstLevel, int dstX, int dstY, int dstZ, int width, int height, int depth) {
#if defined(USING_GLES2)
#ifndef IOS
glCopyImageSubDataOES(
src->color_texture, GL_TEXTURE_2D, srcLevel, srcX, srcY, srcZ,
dst->color_texture, GL_TEXTURE_2D, dstLevel, dstX, dstY, dstZ,
width, height, depth);
return;
#endif
#else
if (gl_extensions.ARB_copy_image) {
glCopyImageSubData(
src->color_texture, GL_TEXTURE_2D, srcLevel, srcX, srcY, srcZ,
dst->color_texture, GL_TEXTURE_2D, dstLevel, dstX, dstY, dstZ,
width, height, depth);
return;
} else if (gl_extensions.NV_copy_image) {
// Older, pre GL 4.x NVIDIA cards.
glCopyImageSubDataNV(
src->color_texture, GL_TEXTURE_2D, srcLevel, srcX, srcY, srcZ,
dst->color_texture, GL_TEXTURE_2D, dstLevel, dstX, dstY, dstZ,
width, height, depth);
return;
}
#endif
}
void fbo_blit(FBO *src, int srcX1, int srcY1, int srcX2, int srcY2, FBO *dst, int dstX1, int dstY1, int dstX2, int dstY2, int channels, FBBlitFilter linearFilter) {
GLuint bits = 0;
if (channels & FB_COLOR_BIT)
bits |= GL_COLOR_BUFFER_BIT;
if (channels & FB_DEPTH_BIT)
bits |= GL_DEPTH_BUFFER_BIT;
if (channels & FB_STENCIL_BIT)
bits |= GL_STENCIL_BUFFER_BIT;
fbo_bind_as_render_target(dst);
fbo_bind_for_read(src);
if (gl_extensions.GLES3 || gl_extensions.ARB_framebuffer_object) {
glBlitFramebuffer(srcX1, srcY1, srcX2, srcY2, dstX1, dstY1, dstX2, dstY2, bits, linearFilter == FB_BLIT_LINEAR ? GL_LINEAR : GL_NEAREST);
#if defined(USING_GLES2) && defined(__ANDROID__) // We only support this extension on Android, it's not even available on PC.
} else if (gl_extensions.NV_framebuffer_blit) {
glBlitFramebufferNV(srcX1, srcY1, srcX2, srcY2, dstX1, dstY1, dstX2, dstY2, bits, linearFilter == FB_BLIT_LINEAR ? GL_LINEAR : GL_NEAREST);
#endif // defined(USING_GLES2) && defined(__ANDROID__)
}
}
uintptr_t fbo_get_api_texture(FBO *fbo, FBOChannel channelBit, int attachment) {
// Unimplemented
return 0;
}
void fbo_bind_as_texture(FBO *fbo, int binding, FBOChannel channelBit, int color) {
// glActiveTexture(GL_TEXTURE0 + binding);
switch (channelBit) {
case FB_COLOR_BIT:
default:
if (fbo) {
glBindTexture(GL_TEXTURE_2D, fbo->color_texture);
}
break;
}
}
void fbo_destroy(FBO *fbo) {
if (gl_extensions.ARB_framebuffer_object || gl_extensions.IsGLES) {
glBindFramebuffer(GL_FRAMEBUFFER, fbo->handle);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glDeleteFramebuffers(1, &fbo->handle);
glDeleteRenderbuffers(1, &fbo->z_stencil_buffer);
glDeleteRenderbuffers(1, &fbo->z_buffer);
glDeleteRenderbuffers(1, &fbo->stencil_buffer);
} else if (gl_extensions.EXT_framebuffer_object) {
#ifndef USING_GLES2
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo->handle);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER_EXT, 0);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glDeleteFramebuffersEXT(1, &fbo->handle);
glDeleteRenderbuffersEXT(1, &fbo->z_stencil_buffer);
#endif
}
currentDrawHandle_ = 0;
currentReadHandle_ = 0;
glDeleteTextures(1, &fbo->color_texture);
delete fbo;
}
void fbo_get_dimensions(FBO *fbo, int *w, int *h) {
*w = fbo->width;
*h = fbo->height;
}

View File

@ -1,80 +0,0 @@
// 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
// Simple wrapper around FBO functionality.
// Very C-ish API because that's what I felt like, and it's cool to completely
// hide the data from callers...
#include "gfx/gl_common.h"
struct FBO;
enum FBOColorDepth {
FBO_8888,
FBO_565,
FBO_4444,
FBO_5551,
};
enum FBOChannel {
FB_COLOR_BIT = 1,
FB_DEPTH_BIT = 2,
FB_STENCIL_BIT = 4,
};
enum FBBlitFilter {
FB_BLIT_NEAREST = 0,
FB_BLIT_LINEAR = 1,
};
struct FramebufferDesc {
int width;
int height;
int depth;
int numColorAttachments;
bool z_stencil;
FBOColorDepth colorDepth;
};
// Creates a simple FBO with a RGBA32 color buffer stored in a texture, and
// optionally an accompanying Z/stencil buffer.
// No mipmap support.
// num_color_textures must be 1 for now.
// you lose bound texture state.
// On some hardware, you might get a 24-bit depth buffer even though you only wanted a 16-bit one.
FBO *fbo_create(const FramebufferDesc &desc);
void fbo_destroy(FBO *fbo);
void fbo_copy_image(FBO *src, int level, int x, int y, int z, FBO *dst, int dstLevel, int dstX, int dstY, int dstZ, int width, int height, int depth);
void fbo_blit(FBO *src, int srcX1, int srcY1, int srcX2, int srcY2, FBO *dst, int dstX1, int dstY1, int dstX2, int dstY2, int channelBits, FBBlitFilter filter);
int fbo_preferred_z_bitdepth();
// These functions should be self explanatory.
void fbo_bind_as_render_target(FBO *fbo);
// color must be 0, for now.
void fbo_bind_as_texture(FBO *fbo, int binding, FBOChannel channelBit, int attachment);
void fbo_bind_for_read(FBO *fbo);
void fbo_bind_backbuffer_as_render_target();
uintptr_t fbo_get_api_texture(FBO *fbo, FBOChannel channelBit, int attachment);
void fbo_get_dimensions(FBO *fbo, int *w, int *h);

View File

@ -19,7 +19,7 @@
#include <map>
#include "Common/CommonTypes.h"
#include "GPU/GLES/GLStateCache.h"
#include "ext/native/gfx/GLStateCache.h"
#include "GPU/GLES/TextureCacheGLES.h"
#include "GPU/ge_constants.h"

View File

@ -21,6 +21,7 @@
#include "profiler/profiler.h"
#include "gfx_es2/glsl_program.h"
#include "native/thin3d/thin3d.h"
#include "base/timeutil.h"
#include "math/lin/matrix4x4.h"
@ -39,8 +40,7 @@
#include "GPU/Common/TextureDecoder.h"
#include "GPU/Common/FramebufferCommon.h"
#include "GPU/Debugger/Stepping.h"
#include "GPU/GLES/GLStateCache.h"
#include "GPU/GLES/FBO.h"
#include "ext/native/gfx/GLStateCache.h"
#include "GPU/GLES/FramebufferManagerGLES.h"
#include "GPU/GLES/TextureCacheGLES.h"
#include "GPU/GLES/DrawEngineGLES.h"
@ -116,21 +116,21 @@ void FramebufferManagerGLES::DisableState() {
void FramebufferManagerGLES::SetNumExtraFBOs(int num) {
for (size_t i = 0; i < extraFBOs_.size(); i++) {
fbo_destroy(extraFBOs_[i]);
delete extraFBOs_[i];
}
extraFBOs_.clear();
for (int i = 0; i < num; i++) {
// No depth/stencil for post processing
FBO *fbo = fbo_create({ (int)renderWidth_, (int)renderHeight_, 1, 1, false, FBO_8888 });
Draw::Framebuffer *fbo = draw_->fbo_create({ (int)renderWidth_, (int)renderHeight_, 1, 1, false, Draw::FBO_8888 });
extraFBOs_.push_back(fbo);
// The new FBO is still bound after creation, but let's bind it anyway.
fbo_bind_as_render_target(fbo);
draw_->fbo_bind_as_render_target(fbo);
ClearBuffer();
}
currentRenderVfb_ = 0;
fbo_bind_backbuffer_as_render_target();
draw_->fbo_bind_backbuffer_as_render_target();
}
void FramebufferManagerGLES::CompileDraw2DProgram() {
@ -273,7 +273,7 @@ FramebufferManagerGLES::~FramebufferManagerGLES() {
SetNumExtraFBOs(0);
for (auto it = tempFBOs_.begin(), end = tempFBOs_.end(); it != end; ++it) {
fbo_destroy(it->second.fbo);
delete it->second.fbo;
}
delete [] pixelBufObj_;
@ -362,7 +362,7 @@ void FramebufferManagerGLES::MakePixelTexture(const u8 *srcPixels, GEBufferForma
void FramebufferManagerGLES::DrawPixels(VirtualFramebuffer *vfb, int dstX, int dstY, const u8 *srcPixels, GEBufferFormat srcPixelFormat, int srcStride, int width, int height) {
float v0 = 0.0f, v1 = 1.0f;
if (useBufferedRendering_ && vfb && vfb->fbo) {
fbo_bind_as_render_target(vfb->fbo);
draw_->fbo_bind_as_render_target(vfb->fbo);
glViewport(0, 0, vfb->renderWidth, vfb->renderHeight);
} else {
// We are drawing to the back buffer so need to flip.
@ -532,8 +532,8 @@ void FramebufferManagerGLES::DrawActiveTexture(GLuint texture, float x, float y,
void FramebufferManagerGLES::DestroyFramebuf(VirtualFramebuffer *v) {
textureCache_->NotifyFramebuffer(v->fb_address, v, NOTIFY_FB_DESTROYED);
if (v->fbo) {
fbo_destroy(v->fbo);
v->fbo = 0;
delete v->fbo;
v->fbo = nullptr;
}
// Wipe some pointers
@ -551,9 +551,9 @@ void FramebufferManagerGLES::DestroyFramebuf(VirtualFramebuffer *v) {
void FramebufferManagerGLES::RebindFramebuffer() {
if (currentRenderVfb_ && currentRenderVfb_->fbo) {
fbo_bind_as_render_target(currentRenderVfb_->fbo);
draw_->fbo_bind_as_render_target(currentRenderVfb_->fbo);
} else {
fbo_bind_backbuffer_as_render_target();
draw_->fbo_bind_backbuffer_as_render_target();
}
if (g_Config.iRenderingMode == FB_NON_BUFFERED_MODE)
glstate.viewport.restore();
@ -583,49 +583,49 @@ void FramebufferManagerGLES::ResizeFramebufFBO(VirtualFramebuffer *vfb, u16 w, u
}
if (trueColor) {
vfb->colorDepth = FBO_8888;
vfb->colorDepth = Draw::FBO_8888;
} else {
switch (vfb->format) {
case GE_FORMAT_4444:
vfb->colorDepth = FBO_4444;
vfb->colorDepth = Draw::FBO_4444;
break;
case GE_FORMAT_5551:
vfb->colorDepth = FBO_5551;
vfb->colorDepth = Draw::FBO_5551;
break;
case GE_FORMAT_565:
vfb->colorDepth = FBO_565;
vfb->colorDepth = Draw::FBO_565;
break;
case GE_FORMAT_8888:
default:
vfb->colorDepth = FBO_8888;
vfb->colorDepth = Draw::FBO_8888;
break;
}
}
textureCache_->ForgetLastTexture();
fbo_bind_backbuffer_as_render_target();
draw_->fbo_bind_backbuffer_as_render_target();
if (!useBufferedRendering_) {
if (vfb->fbo) {
fbo_destroy(vfb->fbo);
vfb->fbo = 0;
delete vfb->fbo;
vfb->fbo = nullptr;
}
return;
}
vfb->fbo = fbo_create({ vfb->renderWidth, vfb->renderHeight, 1, 1, true, (FBOColorDepth)vfb->colorDepth });
vfb->fbo = draw_->fbo_create({ vfb->renderWidth, vfb->renderHeight, 1, 1, true, (Draw::FBColorDepth)vfb->colorDepth });
if (old.fbo) {
INFO_LOG(SCEGE, "Resizing FBO for %08x : %i x %i x %i", vfb->fb_address, w, h, vfb->format);
if (vfb->fbo) {
fbo_bind_as_render_target(vfb->fbo);
draw_->fbo_bind_as_render_target(vfb->fbo);
ClearBuffer();
if (!skipCopy && !g_Config.bDisableSlowFramebufEffects) {
BlitFramebuffer(vfb, 0, 0, &old, 0, 0, std::min(vfb->bufferWidth, vfb->width), std::min(vfb->height, vfb->bufferHeight), 0);
}
}
fbo_destroy(old.fbo);
delete old.fbo;
if (vfb->fbo) {
fbo_bind_as_render_target(vfb->fbo);
draw_->fbo_bind_as_render_target(vfb->fbo);
}
}
@ -636,7 +636,7 @@ void FramebufferManagerGLES::ResizeFramebufFBO(VirtualFramebuffer *vfb, u16 w, u
void FramebufferManagerGLES::NotifyRenderFramebufferCreated(VirtualFramebuffer *vfb) {
if (!useBufferedRendering_) {
fbo_bind_backbuffer_as_render_target();
draw_->fbo_bind_backbuffer_as_render_target();
// Let's ignore rendering to targets that have not (yet) been displayed.
gstate_c.skipDrawReason |= SKIPDRAW_NON_DISPLAYED_FB;
}
@ -663,19 +663,19 @@ void FramebufferManagerGLES::NotifyRenderFramebufferSwitched(VirtualFramebuffer
if (useBufferedRendering_) {
if (vfb->fbo) {
fbo_bind_as_render_target(vfb->fbo);
draw_->fbo_bind_as_render_target(vfb->fbo);
} else {
// wtf? This should only happen very briefly when toggling bBufferedRendering
fbo_bind_backbuffer_as_render_target();
draw_->fbo_bind_backbuffer_as_render_target();
}
} else {
if (vfb->fbo) {
// wtf? This should only happen very briefly when toggling bBufferedRendering
textureCache_->NotifyFramebuffer(vfb->fb_address, vfb, NOTIFY_FB_DESTROYED);
fbo_destroy(vfb->fbo);
vfb->fbo = 0;
delete vfb->fbo;
vfb->fbo = nullptr;
}
fbo_bind_backbuffer_as_render_target();
draw_->fbo_bind_backbuffer_as_render_target();
// Let's ignore rendering to targets that have not (yet) been displayed.
if (vfb->usageFlags & FB_USAGE_DISPLAYED_FRAMEBUFFER) {
@ -747,7 +747,7 @@ void FramebufferManagerGLES::ReformatFramebufferFrom(VirtualFramebuffer *vfb, GE
return;
}
fbo_bind_as_render_target(vfb->fbo);
draw_->fbo_bind_as_render_target(vfb->fbo);
// Technically, we should at this point re-interpret the bytes of the old format to the new.
// That might get tricky, and could cause unnecessary slowness in some games.
@ -786,14 +786,14 @@ void FramebufferManagerGLES::BlitFramebufferDepth(VirtualFramebuffer *src, Virtu
if (gstate_c.Supports(GPU_SUPPORTS_ARB_FRAMEBUFFER_BLIT | GPU_SUPPORTS_NV_FRAMEBUFFER_BLIT)) {
// Let's only do this if not clearing depth.
glstate.scissorTest.force(false);
fbo_blit(src->fbo, 0, 0, w, h, dst->fbo, 0, 0, w, h, FB_DEPTH_BIT, FB_BLIT_NEAREST);
draw_->fbo_blit(src->fbo, 0, 0, w, h, dst->fbo, 0, 0, w, h, Draw::FB_DEPTH_BIT, Draw::FB_BLIT_NEAREST);
// WARNING: If we set dst->depthUpdated here, our optimization above would be pointless.
glstate.scissorTest.restore();
}
}
}
FBO *FramebufferManagerGLES::GetTempFBO(u16 w, u16 h, FBOColorDepth depth) {
Draw::Framebuffer *FramebufferManagerGLES::GetTempFBO(u16 w, u16 h, Draw::FBColorDepth depth) {
u64 key = ((u64)depth << 32) | ((u32)w << 16) | h;
auto it = tempFBOs_.find(key);
if (it != tempFBOs_.end()) {
@ -802,10 +802,10 @@ FBO *FramebufferManagerGLES::GetTempFBO(u16 w, u16 h, FBOColorDepth depth) {
}
textureCache_->ForgetLastTexture();
FBO *fbo = fbo_create({ w, h, 1, 1, false, depth });
Draw::Framebuffer *fbo = draw_->fbo_create({ w, h, 1, 1, false, depth });
if (!fbo)
return fbo;
fbo_bind_as_render_target(fbo);
draw_->fbo_bind_as_render_target(fbo);
ClearBuffer(true);
const TempFBO info = {fbo, gpuStats.numFlips};
tempFBOs_[key] = info;
@ -836,7 +836,7 @@ void FramebufferManagerGLES::BindFramebufferColor(int stage, u32 fbRawAddress, V
}
if (!skipCopy && currentRenderVfb_ && framebuffer->fb_address == fbRawAddress) {
// TODO: Maybe merge with bvfbs_? Not sure if those could be packing, and they're created at a different size.
FBO *renderCopy = GetTempFBO(framebuffer->renderWidth, framebuffer->renderHeight, (FBOColorDepth)framebuffer->colorDepth);
Draw::Framebuffer *renderCopy = GetTempFBO(framebuffer->renderWidth, framebuffer->renderHeight, (Draw::FBColorDepth)framebuffer->colorDepth);
if (renderCopy) {
VirtualFramebuffer copyInfo = *framebuffer;
copyInfo.fbo = renderCopy;
@ -863,12 +863,12 @@ void FramebufferManagerGLES::BindFramebufferColor(int stage, u32 fbRawAddress, V
BlitFramebuffer(&copyInfo, x, y, framebuffer, x, y, w, h, 0);
fbo_bind_as_texture(renderCopy, 0, FB_COLOR_BIT, 0);
draw_->fbo_bind_as_texture(renderCopy, 0, Draw::FB_COLOR_BIT, 0);
} else {
fbo_bind_as_texture(framebuffer->fbo, 0, FB_COLOR_BIT, 0);
draw_->fbo_bind_as_texture(framebuffer->fbo, 0, Draw::FB_COLOR_BIT, 0);
}
} else {
fbo_bind_as_texture(framebuffer->fbo, 0, FB_COLOR_BIT, 0);
draw_->fbo_bind_as_texture(framebuffer->fbo, 0, Draw::FB_COLOR_BIT, 0);
}
if (stage != GL_TEXTURE0) {
@ -906,7 +906,7 @@ void FramebufferManagerGLES::CopyDisplayToOutput() {
DownloadFramebufferOnSwitch(currentRenderVfb_);
glstate.viewport.set(0, 0, pixelWidth_, pixelHeight_);
fbo_bind_backbuffer_as_render_target();
draw_->fbo_bind_backbuffer_as_render_target();
currentRenderVfb_ = 0;
if (displayFramebufPtr_ == 0) {
@ -1015,7 +1015,7 @@ void FramebufferManagerGLES::CopyDisplayToOutput() {
DEBUG_LOG(SCEGE, "Displaying FBO %08x", vfb->fb_address);
DisableState();
fbo_bind_as_texture(vfb->fbo, 0, FB_COLOR_BIT, 0);
draw_->fbo_bind_as_texture(vfb->fbo, 0, Draw::FB_COLOR_BIT, 0);
int uvRotation = (g_Config.iRenderingMode != FB_NON_BUFFERED_MODE) ? g_Config.iInternalScreenRotation : ROTATION_LOCKED_HORIZONTAL;
@ -1049,16 +1049,16 @@ void FramebufferManagerGLES::CopyDisplayToOutput() {
}
} else if (usePostShader_ && extraFBOs_.size() == 1 && !postShaderAtOutputResolution_) {
// An additional pass, post-processing shader to the extra FBO.
fbo_bind_as_render_target(extraFBOs_[0]);
draw_->fbo_bind_as_render_target(extraFBOs_[0]);
int fbo_w, fbo_h;
fbo_get_dimensions(extraFBOs_[0], &fbo_w, &fbo_h);
draw_->fbo_get_dimensions(extraFBOs_[0], &fbo_w, &fbo_h);
glstate.viewport.set(0, 0, fbo_w, fbo_h);
shaderManager_->DirtyLastShader(); // dirty lastShader_
glsl_bind(postShaderProgram_);
UpdatePostShaderUniforms(vfb->bufferWidth, vfb->bufferHeight, renderWidth_, renderHeight_);
DrawActiveTexture(0, 0, 0, fbo_w, fbo_h, fbo_w, fbo_h, 0.0f, 0.0f, 1.0f, 1.0f, postShaderProgram_, ROTATION_LOCKED_HORIZONTAL);
fbo_bind_backbuffer_as_render_target();
draw_->fbo_bind_backbuffer_as_render_target();
// Use the extra FBO, with applied post-processing shader, as a texture.
// fbo_bind_as_texture(extraFBOs_[0], FB_COLOR_BIT, 0);
@ -1066,7 +1066,7 @@ void FramebufferManagerGLES::CopyDisplayToOutput() {
ERROR_LOG(G3D, "WTF?");
return;
}
fbo_bind_as_texture(extraFBOs_[0], 0, FB_COLOR_BIT, 0);
draw_->fbo_bind_as_texture(extraFBOs_[0], 0, Draw::FB_COLOR_BIT, 0);
// We are doing the DrawActiveTexture call directly to the backbuffer after here. Hence, we must
// flip V.
@ -1087,7 +1087,7 @@ void FramebufferManagerGLES::CopyDisplayToOutput() {
}
if (gl_extensions.GLES3 && glInvalidateFramebuffer != nullptr) {
fbo_bind_as_render_target(extraFBOs_[0]);
draw_->fbo_bind_as_render_target(extraFBOs_[0]);
GLenum attachments[3] = { GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT };
glInvalidateFramebuffer(GL_FRAMEBUFFER, 3, attachments);
}
@ -1197,28 +1197,28 @@ bool FramebufferManagerGLES::CreateDownloadTempBuffer(VirtualFramebuffer *nvfb)
if (!gstate_c.Supports(GPU_PREFER_CPU_DOWNLOAD)) {
switch (nvfb->format) {
case GE_FORMAT_4444:
nvfb->colorDepth = FBO_4444;
nvfb->colorDepth = Draw::FBO_4444;
break;
case GE_FORMAT_5551:
nvfb->colorDepth = FBO_5551;
nvfb->colorDepth = Draw::FBO_5551;
break;
case GE_FORMAT_565:
nvfb->colorDepth = FBO_565;
nvfb->colorDepth = Draw::FBO_565;
break;
case GE_FORMAT_8888:
default:
nvfb->colorDepth = FBO_8888;
nvfb->colorDepth = Draw::FBO_8888;
break;
}
}
nvfb->fbo = fbo_create({ nvfb->width, nvfb->height, 1, 1, false, (FBOColorDepth)nvfb->colorDepth });
nvfb->fbo = draw_->fbo_create({ nvfb->width, nvfb->height, 1, 1, false, (Draw::FBColorDepth)nvfb->colorDepth });
if (!nvfb->fbo) {
ERROR_LOG(SCEGE, "Error creating FBO! %i x %i", nvfb->renderWidth, nvfb->renderHeight);
return false;
}
fbo_bind_as_render_target(nvfb->fbo);
draw_->fbo_bind_as_render_target(nvfb->fbo);
ClearBuffer();
glDisable(GL_DITHER);
return true;
@ -1229,11 +1229,11 @@ void FramebufferManagerGLES::UpdateDownloadTempBuffer(VirtualFramebuffer *nvfb)
// Discard the previous contents of this buffer where possible.
if (gl_extensions.GLES3 && glInvalidateFramebuffer != nullptr) {
fbo_bind_as_render_target(nvfb->fbo);
draw_->fbo_bind_as_render_target(nvfb->fbo);
GLenum attachments[3] = { GL_COLOR_ATTACHMENT0, GL_STENCIL_ATTACHMENT, GL_DEPTH_ATTACHMENT };
glInvalidateFramebuffer(GL_FRAMEBUFFER, 3, attachments);
} else if (gl_extensions.IsGLES) {
fbo_bind_as_render_target(nvfb->fbo);
draw_->fbo_bind_as_render_target(nvfb->fbo);
ClearBuffer();
}
}
@ -1241,7 +1241,7 @@ void FramebufferManagerGLES::UpdateDownloadTempBuffer(VirtualFramebuffer *nvfb)
void FramebufferManagerGLES::BlitFramebuffer(VirtualFramebuffer *dst, int dstX, int dstY, VirtualFramebuffer *src, int srcX, int srcY, int w, int h, int bpp) {
if (!dst->fbo || !src->fbo || !useBufferedRendering_) {
// This can happen if they recently switched from non-buffered.
fbo_bind_backbuffer_as_render_target();
draw_->fbo_bind_backbuffer_as_render_target();
return;
}
@ -1286,17 +1286,17 @@ void FramebufferManagerGLES::BlitFramebuffer(VirtualFramebuffer *dst, int dstX,
const bool xOverlap = src == dst && srcX2 > dstX1 && srcX1 < dstX2;
const bool yOverlap = src == dst && srcY2 > dstY1 && srcY1 < dstY2;
if (sameSize && sameDepth && srcInsideBounds && dstInsideBounds && !(xOverlap && yOverlap)) {
fbo_copy_image(src->fbo, 0, srcX1, srcY1, 0, dst->fbo, 0, dstX1, dstY1, 0, dstX2 - dstX1, dstY2 - dstY1, 1);
draw_->fbo_copy_image(src->fbo, 0, srcX1, srcY1, 0, dst->fbo, 0, dstX1, dstY1, 0, dstX2 - dstX1, dstY2 - dstY1, 1);
return;
}
}
glstate.scissorTest.force(false);
if (useBlit) {
fbo_blit(src->fbo, srcX1, srcY1, srcX2, srcY2, dst->fbo, dstX1, dstY1, dstX2, dstY2, FB_COLOR_BIT, FB_BLIT_NEAREST);
draw_->fbo_blit(src->fbo, srcX1, srcY1, srcX2, srcY2, dst->fbo, dstX1, dstY1, dstX2, dstY2, Draw::FB_COLOR_BIT, Draw::FB_BLIT_NEAREST);
} else {
fbo_bind_as_render_target(dst->fbo);
fbo_bind_as_texture(src->fbo, 0, FB_COLOR_BIT, 0);
draw_->fbo_bind_as_render_target(dst->fbo);
draw_->fbo_bind_as_texture(src->fbo, 0, Draw::FB_COLOR_BIT, 0);
// Make sure our 2D drawing program is ready. Compiles only if not already compiled.
CompileDraw2DProgram();
@ -1576,7 +1576,7 @@ void FramebufferManagerGLES::PackFramebufferAsync_(VirtualFramebuffer *vfb) {
u32 fb_address = (0x04000000) | vfb->fb_address;
if (vfb->fbo) {
fbo_bind_for_read(vfb->fbo);
draw_->fbo_bind_for_read(vfb->fbo);
} else {
ERROR_LOG_REPORT_ONCE(vfbfbozero, SCEGE, "PackFramebufferAsync_: vfb->fbo == 0");
return;
@ -1619,7 +1619,7 @@ void FramebufferManagerGLES::PackFramebufferAsync_(VirtualFramebuffer *vfb) {
void FramebufferManagerGLES::PackFramebufferSync_(VirtualFramebuffer *vfb, int x, int y, int w, int h) {
if (vfb->fbo) {
fbo_bind_for_read(vfb->fbo);
draw_->fbo_bind_for_read(vfb->fbo);
} else {
ERROR_LOG_REPORT_ONCE(vfbfbozero, SCEGE, "PackFramebufferSync_: vfb->fbo == 0");
return;
@ -1685,7 +1685,7 @@ void FramebufferManagerGLES::PackFramebufferSync_(VirtualFramebuffer *vfb, int x
void FramebufferManagerGLES::PackDepthbuffer(VirtualFramebuffer *vfb, int x, int y, int w, int h) {
if (vfb->fbo) {
fbo_bind_for_read(vfb->fbo);
draw_->fbo_bind_for_read(vfb->fbo);
} else {
ERROR_LOG_REPORT_ONCE(vfbfbozero, SCEGE, "PackDepthbuffer: vfb->fbo == 0");
return;
@ -1788,11 +1788,11 @@ void FramebufferManagerGLES::EndFrame() {
continue;
}
fbo_bind_as_render_target(temp.second.fbo);
draw_->fbo_bind_as_render_target(temp.second.fbo);
GLenum attachments[3] = { GL_COLOR_ATTACHMENT0, GL_STENCIL_ATTACHMENT, GL_DEPTH_ATTACHMENT };
glInvalidateFramebuffer(GL_FRAMEBUFFER, 3, attachments);
}
fbo_bind_backbuffer_as_render_target();
draw_->fbo_bind_backbuffer_as_render_target();
}
}
@ -1822,7 +1822,7 @@ std::vector<FramebufferInfo> FramebufferManagerGLES::GetFramebufferList() {
}
void FramebufferManagerGLES::DecimateFBOs() {
fbo_bind_backbuffer_as_render_target();
draw_->fbo_bind_backbuffer_as_render_target();
currentRenderVfb_ = 0;
for (size_t i = 0; i < vfbs_.size(); ++i) {
@ -1849,7 +1849,7 @@ void FramebufferManagerGLES::DecimateFBOs() {
for (auto it = tempFBOs_.begin(); it != tempFBOs_.end(); ) {
int age = frameLastFramebufUsed_ - it->second.last_frame_used;
if (age > FBO_OLD_AGE) {
fbo_destroy(it->second.fbo);
delete it->second.fbo;
tempFBOs_.erase(it++);
} else {
++it;
@ -1869,7 +1869,7 @@ void FramebufferManagerGLES::DecimateFBOs() {
}
void FramebufferManagerGLES::DestroyAllFBOs(bool forceDelete) {
fbo_bind_backbuffer_as_render_target();
draw_->fbo_bind_backbuffer_as_render_target();
currentRenderVfb_ = 0;
displayFramebuf_ = 0;
prevDisplayFramebuf_ = 0;
@ -1889,11 +1889,11 @@ void FramebufferManagerGLES::DestroyAllFBOs(bool forceDelete) {
bvfbs_.clear();
for (auto it = tempFBOs_.begin(), end = tempFBOs_.end(); it != end; ++it) {
fbo_destroy(it->second.fbo);
delete it->second.fbo;
}
tempFBOs_.clear();
fbo_bind_backbuffer_as_render_target();
draw_->fbo_bind_backbuffer_as_render_target();
DisableState();
}
@ -1930,7 +1930,7 @@ bool FramebufferManagerGLES::GetFramebuffer(u32 fb_address, int fb_stride, GEBuf
w = vfb->width * maxRes;
h = vfb->height * maxRes;
FBO *tempFBO = GetTempFBO(w, h);
Draw::Framebuffer *tempFBO = GetTempFBO(w, h);
VirtualFramebuffer tempVfb = *vfb;
tempVfb.fbo = tempFBO;
tempVfb.bufferWidth = vfb->width;
@ -1939,9 +1939,9 @@ bool FramebufferManagerGLES::GetFramebuffer(u32 fb_address, int fb_stride, GEBuf
tempVfb.renderHeight = h;
BlitFramebuffer(&tempVfb, 0, 0, vfb, 0, 0, vfb->width, vfb->height, 0);
fbo_bind_for_read(tempFBO);
draw_->fbo_bind_for_read(tempFBO);
} else {
fbo_bind_for_read(vfb->fbo);
draw_->fbo_bind_for_read(vfb->fbo);
}
}
@ -1986,7 +1986,7 @@ bool FramebufferManagerGLES::GetDepthbuffer(u32 fb_address, int fb_stride, u32 z
buffer.Allocate(vfb->renderWidth, vfb->renderHeight, GPU_DBG_FORMAT_FLOAT, !useBufferedRendering_);
}
if (vfb->fbo)
fbo_bind_for_read(vfb->fbo);
draw_->fbo_bind_for_read(vfb->fbo);
if (gl_extensions.GLES3 || !gl_extensions.IsGLES)
glReadBuffer(GL_COLOR_ATTACHMENT0);
glPixelStorei(GL_PACK_ALIGNMENT, 4);
@ -2011,7 +2011,7 @@ bool FramebufferManagerGLES::GetStencilbuffer(u32 fb_address, int fb_stride, GPU
#ifndef USING_GLES2
buffer.Allocate(vfb->renderWidth, vfb->renderHeight, GPU_DBG_FORMAT_8BIT, !useBufferedRendering_);
if (vfb->fbo)
fbo_bind_for_read(vfb->fbo);
draw_->fbo_bind_for_read(vfb->fbo);
if (gl_extensions.GLES3 || !gl_extensions.IsGLES)
glReadBuffer(GL_COLOR_ATTACHMENT0);
glPixelStorei(GL_PACK_ALIGNMENT, 2);

View File

@ -22,6 +22,7 @@
#include <algorithm>
#include "gfx/gl_common.h"
#include "ext/native/thin3d/thin3d.h"
// Keeps track of allocated FBOs.
// Also provides facilities for drawing and later converting raw
// pixel data.
@ -29,7 +30,6 @@
#include "Globals.h"
#include "GPU/GPUCommon.h"
#include "GPU/GLES/FBO.h"
#include "GPU/Common/FramebufferCommon.h"
#include "Core/Config.h"
@ -115,7 +115,7 @@ public:
virtual void RebindFramebuffer() override;
FBO *GetTempFBO(u16 w, u16 h, FBOColorDepth depth = FBO_8888);
Draw::Framebuffer *GetTempFBO(u16 w, u16 h, Draw::FBColorDepth depth = Draw::FBO_8888);
// Cardboard Settings Calculator
struct CardboardSettings * GetCardboardSettings(struct CardboardSettings * cardboardSettings);
@ -169,12 +169,12 @@ private:
DrawEngineGLES *drawEngine_;
// Used by post-processing shader
std::vector<FBO *> extraFBOs_;
std::vector<Draw::Framebuffer *> extraFBOs_;
bool resized_;
struct TempFBO {
FBO *fbo;
Draw::Framebuffer *fbo;
int last_frame_used;
};

View File

@ -36,7 +36,7 @@
#include "GPU/GeDisasm.h"
#include "GPU/Common/FramebufferCommon.h"
#include "GPU/GLES/GLStateCache.h"
#include "ext/native/gfx/GLStateCache.h"
#include "GPU/GLES/ShaderManagerGLES.h"
#include "GPU/GLES/GPU_GLES.h"
#include "GPU/GLES/FramebufferManagerGLES.h"
@ -485,6 +485,11 @@ GPU_GLES::GPU_GLES(GraphicsContext *gfxCtx, Draw::DrawContext *draw)
}
}
// HACK
int fbo_preferred_z_bitdepth() {
return 24;
}
GPU_GLES::~GPU_GLES() {
framebufferManagerGL_->DestroyAllFBOs(true);
shaderManagerGL_->ClearCache(true);

View File

@ -21,7 +21,6 @@
#include <deque>
#include "GPU/GPUCommon.h"
#include "GPU/GLES/FBO.h"
#include "GPU/GLES/FramebufferManagerGLES.h"
#include "GPU/GLES/DrawEngineGLES.h"
#include "GPU/GLES/TextureCacheGLES.h"

View File

@ -36,7 +36,7 @@
#include "GPU/Math3D.h"
#include "GPU/GPUState.h"
#include "GPU/ge_constants.h"
#include "GPU/GLES/GLStateCache.h"
#include "ext/native/gfx/GLStateCache.h"
#include "GPU/GLES/ShaderManagerGLES.h"
#include "GPU/GLES/DrawEngineGLES.h"
#include "FramebufferManagerGLES.h"

View File

@ -30,7 +30,7 @@
#include "Core/Config.h"
#include "Core/Reporting.h"
#include "GPU/GLES/GPU_GLES.h"
#include "GPU/GLES/GLStateCache.h"
#include "ext/native/gfx/GLStateCache.h"
#include "GPU/GLES/ShaderManagerGLES.h"
#include "GPU/GLES/TextureCacheGLES.h"
#include "GPU/GLES/FramebufferManagerGLES.h"

View File

@ -17,7 +17,7 @@
#include "gfx_es2/glsl_program.h"
#include "Core/Reporting.h"
#include "GPU/GLES/GLStateCache.h"
#include "ext/native/gfx/GLStateCache.h"
#include "GPU/GLES/FramebufferManagerGLES.h"
#include "GPU/GLES/ShaderManagerGLES.h"
#include "GPU/GLES/TextureCacheGLES.h"
@ -180,12 +180,12 @@ bool FramebufferManagerGLES::NotifyStencilUpload(u32 addr, int size, bool skipZe
u16 w = useBlit ? dstBuffer->bufferWidth : dstBuffer->renderWidth;
u16 h = useBlit ? dstBuffer->bufferHeight : dstBuffer->renderHeight;
FBO *blitFBO = NULL;
Draw::Framebuffer *blitFBO = nullptr;
if (useBlit) {
blitFBO = GetTempFBO(w, h, FBO_8888);
fbo_bind_as_render_target(blitFBO);
blitFBO = GetTempFBO(w, h, Draw::FBO_8888);
draw_->fbo_bind_as_render_target(blitFBO);
} else if (dstBuffer->fbo) {
fbo_bind_as_render_target(dstBuffer->fbo);
draw_->fbo_bind_as_render_target(dstBuffer->fbo);
}
glViewport(0, 0, w, h);
@ -220,7 +220,7 @@ bool FramebufferManagerGLES::NotifyStencilUpload(u32 addr, int size, bool skipZe
glstate.stencilMask.set(0xFF);
if (useBlit) {
fbo_blit(blitFBO, 0, 0, w, h, dstBuffer->fbo, 0, 0, dstBuffer->renderWidth, dstBuffer->renderHeight, FB_STENCIL_BIT, FB_BLIT_NEAREST);
draw_->fbo_blit(blitFBO, 0, 0, w, h, dstBuffer->fbo, 0, 0, dstBuffer->renderWidth, dstBuffer->renderHeight, Draw::FB_STENCIL_BIT, Draw::FB_BLIT_NEAREST);
}
RebindFramebuffer();

View File

@ -30,7 +30,7 @@
#include "Core/Reporting.h"
#include "GPU/ge_constants.h"
#include "GPU/GPUState.h"
#include "GPU/GLES/GLStateCache.h"
#include "ext/native/gfx/GLStateCache.h"
#include "GPU/GLES/TextureCacheGLES.h"
#include "GPU/GLES/FramebufferManagerGLES.h"
#include "GPU/GLES/FragmentShaderGeneratorGLES.h"
@ -637,8 +637,8 @@ void TextureCacheGLES::SetTextureFramebuffer(TexCacheEntry *entry, VirtualFrameb
nextTexture_ = entry;
} else {
if (framebuffer->fbo) {
fbo_destroy(framebuffer->fbo);
framebuffer->fbo = 0;
delete framebuffer->fbo;
framebuffer->fbo = nullptr;
}
glBindTexture(GL_TEXTURE_2D, 0);
gstate_c.needShaderTexClamp = false;
@ -849,8 +849,8 @@ void TextureCacheGLES::ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFram
}
if (depal) {
GLuint clutTexture = depalShaderCache_->GetClutTexture(clutFormat, clutHash_, clutBuf_);
FBO *depalFBO = framebufferManager_->GetTempFBO(framebuffer->renderWidth, framebuffer->renderHeight, FBO_8888);
fbo_bind_as_render_target(depalFBO);
Draw::Framebuffer *depalFBO = framebufferManager_->GetTempFBO(framebuffer->renderWidth, framebuffer->renderHeight, Draw::FBO_8888);
draw_->fbo_bind_as_render_target(depalFBO);
shaderManager_->DirtyLastShader();
TextureShaderApplier shaderApply(depal, framebuffer->bufferWidth, framebuffer->bufferHeight, framebuffer->renderWidth, framebuffer->renderHeight);
@ -867,7 +867,7 @@ void TextureCacheGLES::ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFram
shaderApply.Shade();
fbo_bind_as_texture(depalFBO, 0, FB_COLOR_BIT, 0);
draw_->fbo_bind_as_texture(depalFBO, 0, Draw::FB_COLOR_BIT, 0);
const u32 bytesPerColor = clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16);
const u32 clutTotalColors = clutMaxBytes_ / bytesPerColor;

View File

@ -20,11 +20,10 @@
#include <map>
#include "gfx_es2/gpu_features.h"
#include "gfx/gl_common.h"
#include "Globals.h"
#include "GPU/GPUInterface.h"
#include "GPU/GPUState.h"
#include "GPU/GLES/FBO.h"
#include "GPU/GLES/TextureScalerGLES.h"
#include "GPU/Common/TextureCacheCommon.h"

View File

@ -206,7 +206,6 @@
<ClInclude Include="Debugger\Stepping.h" />
<ClInclude Include="Directx9\DepalettizeShaderDX9.h" />
<ClInclude Include="Directx9\GPU_DX9.h" />
<ClInclude Include="Directx9\helper\dx_fbo.h" />
<ClInclude Include="Directx9\PixelShaderGeneratorDX9.h" />
<ClInclude Include="Directx9\FramebufferDX9.h" />
<ClInclude Include="Directx9\ShaderManagerDX9.h" />
@ -217,12 +216,10 @@
<ClInclude Include="ge_constants.h" />
<ClInclude Include="GeDisasm.h" />
<ClInclude Include="GLES\DepalettizeShaderGLES.h" />
<ClInclude Include="GLES\FBO.h" />
<ClInclude Include="GLES\FragmentShaderGeneratorGLES.h" />
<ClInclude Include="GLES\FragmentTestCacheGLES.h" />
<ClInclude Include="GLES\FramebufferManagerGLES.h" />
<ClInclude Include="GLES\GPU_GLES.h" />
<ClInclude Include="GLES\GLStateCache.h" />
<ClInclude Include="GLES\ShaderManagerGLES.h" />
<ClInclude Include="GLES\StateMappingGLES.h" />
<ClInclude Include="GLES\TextureCacheGLES.h" />
@ -293,7 +290,6 @@
<ClCompile Include="Debugger\Stepping.cpp" />
<ClCompile Include="Directx9\DepalettizeShaderDX9.cpp" />
<ClCompile Include="Directx9\GPU_DX9.cpp" />
<ClCompile Include="Directx9\helper\dx_fbo.cpp" />
<ClCompile Include="Directx9\PixelShaderGeneratorDX9.cpp" />
<ClCompile Include="Directx9\FramebufferDX9.cpp" />
<ClCompile Include="Directx9\ShaderManagerDX9.cpp" />
@ -305,12 +301,10 @@
<ClCompile Include="Directx9\VertexShaderGeneratorDX9.cpp" />
<ClCompile Include="GeDisasm.cpp" />
<ClCompile Include="GLES\DepalettizeShaderGLES.cpp" />
<ClCompile Include="GLES\FBO.cpp" />
<ClCompile Include="GLES\FragmentShaderGeneratorGLES.cpp" />
<ClCompile Include="GLES\FragmentTestCacheGLES.cpp" />
<ClCompile Include="GLES\FramebufferManagerGLES.cpp" />
<ClCompile Include="GLES\GPU_GLES.cpp" />
<ClCompile Include="GLES\GLStateCache.cpp" />
<ClCompile Include="GLES\ShaderManagerGLES.cpp" />
<ClCompile Include="GLES\StateMappingGLES.cpp" />
<ClCompile Include="GLES\StencilBufferGLES.cpp" />
@ -350,4 +344,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>

View File

@ -150,15 +150,6 @@
<ClInclude Include="GPU.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="GLES\FBO.h">
<Filter>GLES</Filter>
</ClInclude>
<ClInclude Include="Directx9\helper\dx_fbo.h">
<Filter>DirectX9\helper</Filter>
</ClInclude>
<ClInclude Include="GLES\GLStateCache.h">
<Filter>GLES</Filter>
</ClInclude>
<ClInclude Include="Common\ShaderCommon.h">
<Filter>Common</Filter>
</ClInclude>
@ -365,15 +356,6 @@
<ClCompile Include="GPU.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="GLES\FBO.cpp">
<Filter>GLES</Filter>
</ClCompile>
<ClCompile Include="Directx9\helper\dx_fbo.cpp">
<Filter>DirectX9\helper</Filter>
</ClCompile>
<ClCompile Include="GLES\GLStateCache.cpp">
<Filter>GLES</Filter>
</ClCompile>
<ClCompile Include="Common\GPUStateUtils.cpp">
<Filter>Common</Filter>
</ClCompile>
@ -447,4 +429,4 @@
<Filter>GLES</Filter>
</ClCompile>
</ItemGroup>
</Project>
</Project>

View File

@ -22,6 +22,7 @@
#include "base/timeutil.h"
#include "math/lin/matrix4x4.h"
#include "ext/native/thin3d/thin3d.h"
#include "Common/Vulkan/VulkanContext.h"
#include "Common/Vulkan/VulkanMemory.h"
@ -402,7 +403,7 @@ void FramebufferManagerVulkan::DrawPixels(VirtualFramebuffer *vfb, int dstX, int
VkViewport vp;
vp.minDepth = 0.0;
vp.maxDepth = 1.0;
if (useBufferedRendering_ && vfb && vfb->fbo_vk) {
if (useBufferedRendering_ && vfb && vfb->fbo) {
vp.x = 0;
vp.y = 0;
vp.width = vfb->renderWidth;
@ -537,9 +538,9 @@ void FramebufferManagerVulkan::DrawTexture(VulkanTexture *texture, float x, floa
void FramebufferManagerVulkan::DestroyFramebuf(VirtualFramebuffer *v) {
textureCache_->NotifyFramebuffer(v->fb_address, v, NOTIFY_FB_DESTROYED);
if (v->fbo_vk) {
delete v->fbo_vk;
v->fbo_vk = 0;
if (v->fbo) {
delete v->fbo;
v->fbo = 0;
}
// Wipe some pointers
@ -608,31 +609,31 @@ void FramebufferManagerVulkan::ResizeFramebufFBO(VirtualFramebuffer *vfb, u16 w,
textureCache_->ForgetLastTexture();
if (!useBufferedRendering_) {
if (vfb->fbo_vk) {
delete vfb->fbo_vk;
vfb->fbo_vk = 0;
if (vfb->fbo) {
delete vfb->fbo;
vfb->fbo = 0;
}
return;
}
vfb->fbo_vk = new VulkanFBO();
vfb->fbo = new VulkanFBO();
// bo_create(vfb->renderWidth, vfb->renderHeight, 1, true, (FBOColorDepth)vfb->colorDepth);
if (old.fbo_vk) {
if (old.fbo) {
INFO_LOG(SCEGE, "Resizing FBO for %08x : %i x %i x %i", vfb->fb_address, w, h, vfb->format);
if (vfb->fbo_vk) {
/// fbo_bind_as_render_target(vfb->fbo_vk);
if (vfb->fbo) {
/// fbo_bind_as_render_target(vfb->fbo);
ClearBuffer();
if (!skipCopy && !g_Config.bDisableSlowFramebufEffects) {
BlitFramebuffer(vfb, 0, 0, &old, 0, 0, std::min(vfb->bufferWidth, vfb->width), std::min(vfb->height, vfb->bufferHeight), 0);
}
}
delete old.fbo_vk;
if (vfb->fbo_vk) {
// fbo_bind_as_render_target(vfb->fbo_vk);
delete old.fbo;
if (vfb->fbo) {
// fbo_bind_as_render_target(vfb->fbo);
}
}
if (!vfb->fbo_vk) {
if (!vfb->fbo) {
ERROR_LOG(SCEGE, "Error creating FBO! %i x %i", vfb->renderWidth, vfb->renderHeight);
}
*/
@ -660,15 +661,15 @@ void FramebufferManagerVulkan::NotifyRenderFramebufferSwitched(VirtualFramebuffe
textureCache_->ForgetLastTexture();
if (useBufferedRendering_) {
if (vfb->fbo_vk) {
// vfb->fbo_vk->GetColorImageView();
if (vfb->fbo) {
// vfb->fbo->GetColorImageView();
}
} else {
if (vfb->fbo_vk) {
if (vfb->fbo) {
// wtf? This should only happen very briefly when toggling bBufferedRendering
textureCache_->NotifyFramebuffer(vfb->fb_address, vfb, NOTIFY_FB_DESTROYED);
delete vfb->fbo_vk;
vfb->fbo_vk = nullptr;
delete vfb->fbo;
vfb->fbo = nullptr;
}
// Let's ignore rendering to targets that have not (yet) been displayed.
@ -682,7 +683,7 @@ void FramebufferManagerVulkan::NotifyRenderFramebufferSwitched(VirtualFramebuffe
// Copy depth pixel value from the read framebuffer to the draw framebuffer
if (prevVfb && !g_Config.bDisableSlowFramebufEffects) {
if (!prevVfb->fbo_vk || !vfb->fbo_vk || !useBufferedRendering_ || !prevVfb->depthUpdated || isClearingDepth) {
if (!prevVfb->fbo || !vfb->fbo || !useBufferedRendering_ || !prevVfb->depthUpdated || isClearingDepth) {
// If depth wasn't updated, then we're at least "two degrees" away from the data.
// This is an optimization: it probably doesn't need to be copied in this case.
} else {
@ -730,7 +731,7 @@ int FramebufferManagerVulkan::GetLineWidth() {
}
void FramebufferManagerVulkan::ReformatFramebufferFrom(VirtualFramebuffer *vfb, GEBufferFormat old) {
if (!useBufferedRendering_ || !vfb->fbo_vk) {
if (!useBufferedRendering_ || !vfb->fbo) {
return;
}
@ -767,8 +768,8 @@ void FramebufferManagerVulkan::BlitFramebufferDepth(VirtualFramebuffer *src, Vir
region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
region.extent = { dst->renderWidth, dst->renderHeight, 1 };
region.extent.depth = 1;
// vkCmdCopyImage(curCmd_, src->fbo_vk->GetDepthStencil()->GetImage(), VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
// dst->fbo_vk->GetDepthStencil()->GetImage(), VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, 1, &region);
// vkCmdCopyImage(curCmd_, src->fbo->GetDepthStencil()->GetImage(), VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
// dst->fbo->GetDepthStencil()->GetImage(), VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, 1, &region);
// If we set dst->depthUpdated here, our optimization above would be pointless.
}
@ -779,7 +780,7 @@ VulkanTexture *FramebufferManagerVulkan::GetFramebufferColor(u32 fbRawAddress, V
framebuffer = currentRenderVfb_;
}
if (!framebuffer->fbo_vk || !useBufferedRendering_) {
if (!framebuffer->fbo || !useBufferedRendering_) {
gstate_c.skipDrawReason |= SKIPDRAW_BAD_FB_TEXTURE;
return nullptr;
}
@ -792,13 +793,13 @@ VulkanTexture *FramebufferManagerVulkan::GetFramebufferColor(u32 fbRawAddress, V
}
if (!skipCopy && currentRenderVfb_ && framebuffer->fb_address == fbRawAddress) {
// TODO: Enable the below code
return framebuffer->fbo_vk->GetColor();
return nullptr; // framebuffer->fbo->GetColor();
/*
// TODO: Maybe merge with bvfbs_? Not sure if those could be packing, and they're created at a different size.
VulkanFBO *renderCopy = GetTempFBO(framebuffer->renderWidth, framebuffer->renderHeight, (FBOColorDepth)framebuffer->colorDepth);
if (renderCopy) {
VirtualFramebuffer copyInfo = *framebuffer;
copyInfo.fbo_vk = renderCopy;
copyInfo.fbo = renderCopy;
int x = 0;
int y = 0;
@ -824,11 +825,11 @@ VulkanTexture *FramebufferManagerVulkan::GetFramebufferColor(u32 fbRawAddress, V
return nullptr; // fbo_bind_color_as_texture(renderCopy, 0);
} else {
return framebuffer->fbo_vk->GetColor();
return framebuffer->fbo->GetColor();
}
*/
} else {
return framebuffer->fbo_vk->GetColor();
return nullptr; // framebuffer->fbo->GetColor();
}
}
@ -945,7 +946,7 @@ void FramebufferManagerVulkan::CopyDisplayToOutput() {
}
displayFramebuf_ = vfb;
if (vfb->fbo_vk) {
if (vfb->fbo) {
struct CardboardSettings cardboardSettings;
GetCardboardSettings(&cardboardSettings);
@ -953,8 +954,9 @@ void FramebufferManagerVulkan::CopyDisplayToOutput() {
// We should not be in a renderpass here so can just copy.
// GLuint colorTexture = fbo_get_color_texture(vfb->fbo_vk);
VulkanTexture *colorTexture = vfb->fbo_vk->GetColor();
// GLuint colorTexture = fbo_get_color_texture(vfb->fbo);
// VulkanTexture *colorTexture = vfb->fbo->GetColor();
VulkanTexture *colorTexture = nullptr;
int uvRotation = (g_Config.iRenderingMode != FB_NON_BUFFERED_MODE) ? g_Config.iInternalScreenRotation : ROTATION_LOCKED_HORIZONTAL;
@ -1652,8 +1654,8 @@ bool FramebufferManagerVulkan::GetFramebuffer(u32 fb_address, int fb_stride, GEB
}
buffer.Allocate(vfb->renderWidth, vfb->renderHeight, GE_FORMAT_8888, false, true);
if (vfb->fbo_vk)
fbo_bind_for_read(vfb->fbo_vk);
if (vfb->fbo)
fbo_bind_for_read(vfb->fbo);
if (gl_extensions.GLES3 || !gl_extensions.IsGLES)
glReadBuffer(GL_COLOR_ATTACHMENT0);

View File

@ -22,6 +22,7 @@
#include "i18n/i18n.h"
#include "math/math_util.h"
#include "profiler/profiler.h"
#include "thin3d/thin3d.h"
#include "Common/ColorConv.h"
#include "Core/Config.h"
#include "Core/Host.h"
@ -637,9 +638,9 @@ void TextureCacheVulkan::SetTextureFramebuffer(TexCacheEntry *entry, VirtualFram
nextTexture_ = entry;
} else {
if (framebuffer->fbo_vk) {
delete framebuffer->fbo_vk;
framebuffer->fbo_vk = 0;
if (framebuffer->fbo) {
delete framebuffer->fbo;
framebuffer->fbo = nullptr;
}
gstate_c.needShaderTexClamp = false;
}

View File

@ -1,5 +1,5 @@
#include "debugger_memorytex.h"
#include "GPU/GLES/GLStateCache.h"
#include "gfx/GLStateCache.h"
#include "gfx/gl_common.h"
#include "gfx/gl_lost_manager.h"
#include "ui_debugger_memorytex.h"

View File

@ -2,7 +2,6 @@
#include <d3d9.h>
#include "gfx/d3d9_state.h"
#include "GPU/Directx9/helper/dx_fbo.h"
#include "base/logging.h"
#include "util/text/utf8.h"
@ -165,8 +164,6 @@ bool D3D9Context::Init(HINSTANCE hInst, HWND wnd, std::string *error_message) {
DX9::pD3Ddevice = device;
DX9::pD3DdeviceEx = deviceEx;
DX9::fbo_init(d3d, device);
if (deviceEx && IsWin7OrLater()) {
// TODO: This makes it slower?
//deviceEx->SetMaximumFrameLatency(1);
@ -184,7 +181,7 @@ void D3D9Context::Resize() {
bool h_changed = pp.BackBufferHeight != yres;
if (device && (w_changed || h_changed)) {
DX9::fbo_shutdown();
// DX9::fbo_shutdown();
pp.BackBufferWidth = xres;
pp.BackBufferHeight = yres;
@ -194,12 +191,12 @@ void D3D9Context::Resize() {
ERROR_LOG_REPORT(G3D, "Unable to reset D3D device");
PanicAlert("Unable to reset D3D9 device");
}
DX9::fbo_init(d3d, device);
// DX9::fbo_init(d3d, device);
}
}
void D3D9Context::Shutdown() {
DX9::fbo_shutdown();
// DX9::fbo_shutdown();
device->EndScene();
device->Release();
d3d->Release();

View File

@ -229,7 +229,6 @@ EXEC_AND_LIB_FILES := \
$(SRC)/GPU/GLES/FramebufferManagerGLES.cpp \
$(SRC)/GPU/GLES/DepalettizeShaderGLES.cpp \
$(SRC)/GPU/GLES/GPU_GLES.cpp.arm \
$(SRC)/GPU/GLES/GLStateCache.cpp.arm \
$(SRC)/GPU/GLES/FBO.cpp \
$(SRC)/GPU/GLES/StencilBufferGLES.cpp.arm \
$(SRC)/GPU/GLES/TextureCacheGLES.cpp.arm \

View File

@ -74,6 +74,7 @@ LOCAL_SRC_FILES :=\
gfx_es2/gl3stub.c \
gfx_es2/draw_buffer.cpp.arm \
gfx_es2/draw_text.cpp.arm \
gfx/GLStateCache.cpp.arm \
gfx/gl_debug_log.cpp \
gfx/gl_lost_manager.cpp \
gfx/texture_atlas.cpp \

View File

@ -2,7 +2,7 @@
#include "base/logging.h"
#include "GPU/GLES/GLStateCache.h"
#include "gfx/GLStateCache.h"
OpenGLState glstate;

View File

@ -1,8 +1,6 @@
#pragma once
#include <functional>
#include <string.h>
#include <string>
#include "gfx/gl_common.h"
#include "gfx_es2/gpu_features.h"

View File

@ -231,6 +231,7 @@
<ClInclude Include="file\free.h" />
<ClInclude Include="gfx\d3d9_shader.h" />
<ClInclude Include="gfx\d3d9_state.h" />
<ClInclude Include="gfx\GLStateCache.h" />
<ClInclude Include="gfx\gl_common.h" />
<ClInclude Include="gfx\gl_debug_log.h" />
<ClInclude Include="gfx\gl_lost_manager.h" />
@ -684,6 +685,7 @@
<ClCompile Include="file\free.cpp" />
<ClCompile Include="gfx\d3d9_shader.cpp" />
<ClCompile Include="gfx\d3d9_state.cpp" />
<ClCompile Include="gfx\GLStateCache.cpp" />
<ClCompile Include="gfx\gl_debug_log.cpp" />
<ClCompile Include="gfx\gl_lost_manager.cpp" />
<ClCompile Include="gfx\texture_atlas.cpp" />
@ -748,4 +750,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>

View File

@ -317,6 +317,12 @@
<ClInclude Include="gfx\d3d9_state.h">
<Filter>gfx</Filter>
</ClInclude>
<ClInclude Include="gfx\GLStateCache.h">
<Filter>gfx</Filter>
</ClInclude>
<ClInclude Include="gfx\dx_state.h">
<Filter>gfx</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="gfx\gl_debug_log.cpp">
@ -763,6 +769,12 @@
<ClCompile Include="gfx\d3d9_state.cpp">
<Filter>gfx</Filter>
</ClCompile>
<ClCompile Include="gfx\GLStateCache.cpp">
<Filter>gfx</Filter>
</ClCompile>
<ClCompile Include="gfx\dx_state.cpp">
<Filter>gfx</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="gfx">
@ -835,4 +847,4 @@
<UniqueIdentifier>{06c6305a-a646-485b-85b9-645a24dd6553}</UniqueIdentifier>
</Filter>
</ItemGroup>
</Project>
</Project>

View File

@ -310,6 +310,34 @@ enum class NativeObject {
DEVICE_EX,
};
enum FBColorDepth {
FBO_8888,
FBO_565,
FBO_4444,
FBO_5551,
};
enum FBChannel {
FB_COLOR_BIT = 1,
FB_DEPTH_BIT = 2,
FB_STENCIL_BIT = 4,
FB_SURFACE_BIT = 32, // Used in conjunction with the others in D3D9 to get surfaces through get_api_texture
};
enum FBBlitFilter {
FB_BLIT_NEAREST = 0,
FB_BLIT_LINEAR = 1,
};
struct FramebufferDesc {
int width;
int height;
int depth;
int numColorAttachments;
bool z_stencil;
FBColorDepth colorDepth;
};
// Binary compatible with D3D11 viewport.
struct Viewport {
float TopLeftX;
@ -344,6 +372,10 @@ class DepthStencilState : public RefCountedObject {
public:
};
class Framebuffer : public RefCountedObject {
public:
};
class Buffer : public RefCountedObject {
public:
virtual void SetData(const uint8_t *data, size_t size) = 0;
@ -520,10 +552,28 @@ public:
// Resources
virtual Buffer *CreateBuffer(size_t size, uint32_t usageFlags) = 0;
virtual Texture *CreateTexture(const TextureDesc &desc) = 0;
// On some hardware, you might get a 24-bit depth buffer even though you only wanted a 16-bit one.
virtual Framebuffer *fbo_create(const FramebufferDesc &desc) = 0;
virtual ShaderModule *CreateShaderModule(ShaderStage stage, ShaderLanguage language, const uint8_t *data, size_t dataSize) = 0;
virtual Pipeline *CreateGraphicsPipeline(const PipelineDesc &desc) = 0;
virtual void fbo_copy_image(Framebuffer *src, int level, int x, int y, int z, Framebuffer *dst, int dstLevel, int dstX, int dstY, int dstZ, int width, int height, int depth) = 0;
virtual bool fbo_blit(Framebuffer *src, int srcX1, int srcY1, int srcX2, int srcY2, Framebuffer *dst, int dstX1, int dstY1, int dstX2, int dstY2, int channelBits, FBBlitFilter filter) = 0;
virtual int fbo_preferred_z_bitdepth() = 0;
// These functions should be self explanatory.
virtual void fbo_bind_as_render_target(Framebuffer *fbo) = 0;
// color must be 0, for now.
virtual void fbo_bind_as_texture(Framebuffer *fbo, int binding, FBChannel channelBit, int attachment) = 0;
virtual void fbo_bind_for_read(Framebuffer *fbo) = 0;
virtual void fbo_bind_backbuffer_as_render_target() = 0;
virtual uintptr_t fbo_get_api_texture(Framebuffer *fbo, int channelBits, int attachment) = 0;
virtual void fbo_get_dimensions(Framebuffer *fbo, int *w, int *h) = 0;
// Dynamic state
virtual void SetScissorRect(int left, int top, int width, int height) = 0;
virtual void SetViewports(int count, Viewport *viewports) = 0;
@ -583,4 +633,4 @@ DrawContext *T3DCreateD3D11Context(ID3D11Device *device, ID3D11DeviceContext *co
DrawContext *T3DCreateVulkanContext(VulkanContext *context);
} // namespace Draw
} // namespace Draw

View File

@ -19,6 +19,7 @@
#include "math/lin/matrix4x4.h"
#include "thin3d/thin3d.h"
#include "thin3d/d3dx9_loader.h"
#include "gfx/d3d9_state.h"
namespace Draw {
@ -548,6 +549,23 @@ public:
InputLayout *CreateInputLayout(const InputLayoutDesc &desc) override;
Texture *CreateTexture(const TextureDesc &desc) override;
Framebuffer *fbo_create(const FramebufferDesc &desc) override;
void fbo_copy_image(Framebuffer *src, int level, int x, int y, int z, Framebuffer *dst, int dstLevel, int dstX, int dstY, int dstZ, int width, int height, int depth) override {}
bool fbo_blit(Framebuffer *src, int srcX1, int srcY1, int srcX2, int srcY2, Framebuffer *dst, int dstX1, int dstY1, int dstX2, int dstY2, int channelBits, FBBlitFilter filter) override;
int fbo_preferred_z_bitdepth() override { return 24; }
// These functions should be self explanatory.
void fbo_bind_as_render_target(Framebuffer *fbo) override;
// color must be 0, for now.
void fbo_bind_as_texture(Framebuffer *fbo, int binding, FBChannel channelBit, int attachment) override;
void fbo_bind_for_read(Framebuffer *fbo) override {}
void fbo_bind_backbuffer_as_render_target() override;
uintptr_t fbo_get_api_texture(Framebuffer *fbo, int channelBits, int attachment) override;
void fbo_get_dimensions(Framebuffer *fbo, int *w, int *h) override;
void BindTextures(int start, int count, Texture **textures) override;
void BindSamplerStates(int start, int count, SamplerState **states) override {
for (int i = 0; i < count; ++i) {
@ -622,8 +640,16 @@ private:
int curVBufferOffsets_[4];
D3D9Buffer *curIBuffer_;
int curIBufferOffset_;
// Framebuffer state
LPDIRECT3DSURFACE9 deviceRTsurf = 0;
LPDIRECT3DSURFACE9 deviceDSsurf = 0;
bool supportsINTZ = false;
};
#define FB_DIV 1
#define FOURCC_INTZ ((D3DFORMAT)(MAKEFOURCC('I', 'N', 'T', 'Z')))
D3D9Context::D3D9Context(IDirect3D9 *d3d, IDirect3D9Ex *d3dEx, int adapterId, IDirect3DDevice9 *device, IDirect3DDevice9Ex *deviceEx)
: d3d_(d3d), d3dEx_(d3dEx), adapterId_(adapterId), device_(device), deviceEx_(deviceEx), caps_{} {
CreatePresets();
@ -636,9 +662,23 @@ D3D9Context::D3D9Context(IDirect3D9 *d3d, IDirect3D9Ex *d3dEx, int adapterId, ID
caps_.multiViewport = false;
caps_.anisoSupported = true;
caps_.depthRangeMinusOneToOne = false;
device_->GetRenderTarget(0, &deviceRTsurf);
device_->GetDepthStencilSurface(&deviceDSsurf);
if (d3d) {
D3DDISPLAYMODE displayMode;
d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &displayMode);
// To be safe, make sure both the display format and the FBO format support INTZ.
HRESULT displayINTZ = d3d->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, displayMode.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, FOURCC_INTZ);
HRESULT fboINTZ = d3d->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_A8R8G8B8, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, FOURCC_INTZ);
supportsINTZ = SUCCEEDED(displayINTZ) && SUCCEEDED(fboINTZ);
}
}
D3D9Context::~D3D9Context() {
deviceRTsurf->Release();
deviceDSsurf->Release();
}
ShaderModule *D3D9Context::CreateShaderModule(ShaderStage stage, ShaderLanguage language, const uint8_t *data, size_t size) {
@ -950,6 +990,153 @@ void D3D9ShaderModule::SetMatrix4x4(LPDIRECT3DDEVICE9 device, const char *name,
}
}
class D3D9Framebuffer : public Framebuffer {
public:
~D3D9Framebuffer();
uint32_t id;
LPDIRECT3DSURFACE9 surf;
LPDIRECT3DSURFACE9 depthstencil;
LPDIRECT3DTEXTURE9 tex;
LPDIRECT3DTEXTURE9 depthstenciltex;
int width;
int height;
FBColorDepth colorDepth;
};
Framebuffer *D3D9Context::fbo_create(const FramebufferDesc &desc) {
static uint32_t id = 0;
D3D9Framebuffer *fbo = new D3D9Framebuffer{};
fbo->width = desc.width;
fbo->height = desc.height;
fbo->colorDepth = desc.colorDepth;
fbo->depthstenciltex = nullptr;
HRESULT rtResult = device_->CreateTexture(fbo->width, fbo->height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &fbo->tex, NULL);
if (FAILED(rtResult)) {
ELOG("Failed to create render target");
delete fbo;
return NULL;
}
fbo->tex->GetSurfaceLevel(0, &fbo->surf);
HRESULT dsResult;
if (supportsINTZ) {
dsResult = device_->CreateTexture(fbo->width, fbo->height, 1, D3DUSAGE_DEPTHSTENCIL, FOURCC_INTZ, D3DPOOL_DEFAULT, &fbo->depthstenciltex, NULL);
if (SUCCEEDED(dsResult)) {
dsResult = fbo->depthstenciltex->GetSurfaceLevel(0, &fbo->depthstencil);
}
} else {
dsResult = device_->CreateDepthStencilSurface(fbo->width, fbo->height, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, 0, FALSE, &fbo->depthstencil, NULL);
}
if (FAILED(dsResult)) {
ELOG("Failed to create depth buffer");
fbo->surf->Release();
fbo->tex->Release();
if (fbo->depthstenciltex) {
fbo->depthstenciltex->Release();
}
delete fbo;
return NULL;
}
fbo->id = id++;
return fbo;
}
D3D9Framebuffer::~D3D9Framebuffer() {
tex->Release();
surf->Release();
depthstencil->Release();
if (depthstenciltex) {
depthstenciltex->Release();
}
}
void D3D9Context::fbo_bind_backbuffer_as_render_target() {
using namespace DX9;
device_->SetRenderTarget(0, deviceRTsurf);
device_->SetDepthStencilSurface(deviceDSsurf);
dxstate.scissorRect.restore();
dxstate.viewport.restore();
}
void D3D9Context::fbo_bind_as_render_target(Framebuffer *fbo) {
using namespace DX9;
D3D9Framebuffer *fb = (D3D9Framebuffer *)fbo;
device_->SetRenderTarget(0, fb->surf);
device_->SetDepthStencilSurface(fb->depthstencil);
dxstate.scissorRect.restore();
dxstate.viewport.restore();
}
uintptr_t D3D9Context::fbo_get_api_texture(Framebuffer *fbo, int channelBits, int attachment) {
D3D9Framebuffer *fb = (D3D9Framebuffer *)fbo;
if (channelBits & FB_SURFACE_BIT) {
switch (channelBits & 7) {
case FB_DEPTH_BIT:
return (uintptr_t)fb->depthstencil;
case FB_STENCIL_BIT:
return (uintptr_t)fb->depthstencil;
case FB_COLOR_BIT:
default:
return (uintptr_t)fb->surf;
}
} else {
switch (channelBits & 7) {
case FB_DEPTH_BIT:
return (uintptr_t)fb->depthstenciltex;
case FB_STENCIL_BIT:
return 0; // Can't texture from stencil
case FB_COLOR_BIT:
default:
return (uintptr_t)fb->tex;
}
}
}
LPDIRECT3DSURFACE9 fbo_get_color_for_read(D3D9Framebuffer *fbo) {
return fbo->surf;
}
void D3D9Context::fbo_bind_as_texture(Framebuffer *fbo, int binding, FBChannel channelBit, int color) {
D3D9Framebuffer *fb = (D3D9Framebuffer *)fbo;
switch (channelBit) {
case FB_DEPTH_BIT:
if (fb->depthstenciltex) {
device_->SetTexture(binding, fb->depthstenciltex);
}
break;
case FB_COLOR_BIT:
default:
if (fb->tex) {
device_->SetTexture(binding, fb->tex);
}
break;
}
}
void D3D9Context::fbo_get_dimensions(Framebuffer *fbo, int *w, int *h) {
D3D9Framebuffer *fb = (D3D9Framebuffer *)fbo;
*w = fb->width;
*h = fb->height;
}
bool D3D9Context::fbo_blit(Framebuffer *srcfb, int srcX1, int srcY1, int srcX2, int srcY2, Framebuffer *dstfb, int dstX1, int dstY1, int dstX2, int dstY2, int channelBits, FBBlitFilter filter) {
D3D9Framebuffer *src = (D3D9Framebuffer *)srcfb;
D3D9Framebuffer *dst = (D3D9Framebuffer *)dstfb;
if (channelBits != FB_COLOR_BIT)
return false;
RECT srcRect{ (LONG)srcX1, (LONG)srcY1, (LONG)srcX2, (LONG)srcY2 };
RECT dstRect{ (LONG)dstX1, (LONG)dstY1, (LONG)dstX2, (LONG)dstY2 };
LPDIRECT3DSURFACE9 srcSurf = src ? src->surf : deviceRTsurf;
LPDIRECT3DSURFACE9 dstSurf = dst ? dst->surf : deviceRTsurf;
return SUCCEEDED(device_->StretchRect(srcSurf, &srcRect, dstSurf, &dstRect, filter == FB_BLIT_LINEAR ? D3DTEXF_LINEAR : D3DTEXF_POINT));
}
DrawContext *T3DCreateDX9Context(IDirect3D9 *d3d, IDirect3D9Ex *d3dEx, int adapterId, IDirect3DDevice9 *device, IDirect3DDevice9Ex *deviceEx) {
int d3dx_ver = LoadD3DX9Dynamic();
if (!d3dx_ver) {

View File

@ -8,6 +8,7 @@
#include "math/lin/matrix4x4.h"
#include "thin3d/thin3d.h"
#include "gfx/gl_common.h"
#include "gfx/GLStateCache.h"
#include "gfx_es2/gpu_features.h"
#include "gfx/gl_lost_manager.h"
@ -488,6 +489,8 @@ private:
std::map<std::string, UniformInfo> uniforms_;
};
class OpenGLFramebuffer;
class OpenGLContext : public DrawContext {
public:
OpenGLContext();
@ -509,12 +512,29 @@ public:
BlendState *CreateBlendState(const BlendStateDesc &desc) override;
SamplerState *CreateSamplerState(const SamplerStateDesc &desc) override;
RasterState *CreateRasterState(const RasterStateDesc &desc) override;
Buffer *CreateBuffer(size_t size, uint32_t usageFlags) override;
Pipeline *CreateGraphicsPipeline(const PipelineDesc &desc) override;
InputLayout *CreateInputLayout(const InputLayoutDesc &desc) override;
ShaderModule *CreateShaderModule(ShaderStage stage, ShaderLanguage language, const uint8_t *data, size_t dataSize) override;
Texture *CreateTexture(const TextureDesc &desc) override;
Buffer *CreateBuffer(size_t size, uint32_t usageFlags) override;
Framebuffer *fbo_create(const FramebufferDesc &desc) override;
void fbo_copy_image(Framebuffer *src, int level, int x, int y, int z, Framebuffer *dst, int dstLevel, int dstX, int dstY, int dstZ, int width, int height, int depth) override;
bool fbo_blit(Framebuffer *src, int srcX1, int srcY1, int srcX2, int srcY2, Framebuffer *dst, int dstX1, int dstY1, int dstX2, int dstY2, int channelBits, FBBlitFilter filter) override;
int fbo_preferred_z_bitdepth() override;
// These functions should be self explanatory.
void fbo_bind_as_render_target(Framebuffer *fbo) override;
// color must be 0, for now.
void fbo_bind_as_texture(Framebuffer *fbo, int binding, FBChannel channelBit, int attachment) override;
void fbo_bind_for_read(Framebuffer *fbo) override;
void fbo_bind_backbuffer_as_render_target() override;
uintptr_t fbo_get_api_texture(Framebuffer *fbo, int channelBits, int attachment) override;
void fbo_get_dimensions(Framebuffer *fbo, int *w, int *h) override;
void BindSamplerStates(int start, int count, SamplerState **states) override {
if (samplerStates_.size() < (size_t)(start + count)) {
@ -610,6 +630,11 @@ public:
return 0;
}
OpenGLFramebuffer *fbo_ext_create(const FramebufferDesc &desc);
void fbo_bind_fb_target(bool read, GLuint name);
GLenum fbo_get_fb_target(bool read, GLuint **cached);
void fbo_unbind();
private:
std::vector<OpenGLSamplerState *> samplerStates_;
DeviceCaps caps_;
@ -620,6 +645,10 @@ private:
int curVBufferOffsets_[4];
OpenGLBuffer *curIBuffer_;
int curIBufferOffset_;
// Framebuffer state
GLuint currentDrawHandle_ = 0;
GLuint currentReadHandle_ = 0;
};
OpenGLContext::OpenGLContext() {
@ -1171,6 +1200,418 @@ void OpenGLInputLayout::Unapply() {
}
}
class OpenGLFramebuffer : public Framebuffer {
public:
~OpenGLFramebuffer();
GLuint handle;
GLuint color_texture;
GLuint z_stencil_buffer; // Either this is set, or the two below.
GLuint z_buffer;
GLuint stencil_buffer;
int width;
int height;
FBColorDepth colorDepth;
};
#ifdef IOS
extern void bindDefaultFBO();
#endif
// On PC, we always use GL_DEPTH24_STENCIL8.
// On Android, we try to use what's available.
#ifndef USING_GLES2
OpenGLFramebuffer *OpenGLContext::fbo_ext_create(const FramebufferDesc &desc) {
OpenGLFramebuffer *fbo = new OpenGLFramebuffer();
fbo->width = desc.width;
fbo->height = desc.height;
fbo->colorDepth = desc.colorDepth;
// Color texture is same everywhere
glGenFramebuffersEXT(1, &fbo->handle);
glGenTextures(1, &fbo->color_texture);
// Create the surfaces.
glBindTexture(GL_TEXTURE_2D, fbo->color_texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// TODO: We could opt to only create 16-bit render targets on slow devices. For later.
switch (fbo->colorDepth) {
case FBO_8888:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fbo->width, fbo->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
break;
case FBO_4444:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fbo->width, fbo->height, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, NULL);
break;
case FBO_5551:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fbo->width, fbo->height, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, NULL);
break;
case FBO_565:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, fbo->width, fbo->height, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, NULL);
break;
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
fbo->stencil_buffer = 0;
fbo->z_buffer = 0;
// 24-bit Z, 8-bit stencil
glGenRenderbuffersEXT(1, &fbo->z_stencil_buffer);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fbo->z_stencil_buffer);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_STENCIL_EXT, fbo->width, fbo->height);
//glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH24_STENCIL8, width, height);
// Bind it all together
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo->handle);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, fbo->color_texture, 0);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, fbo->z_stencil_buffer);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, fbo->z_stencil_buffer);
GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
switch (status) {
case GL_FRAMEBUFFER_COMPLETE_EXT:
// ILOG("Framebuffer verified complete.");
break;
case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
ELOG("GL_FRAMEBUFFER_UNSUPPORTED");
break;
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
ELOG("GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT ");
break;
default:
FLOG("Other framebuffer error: %i", status);
break;
}
// Unbind state we don't need
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
glBindTexture(GL_TEXTURE_2D, 0);
currentDrawHandle_ = fbo->handle;
currentReadHandle_ = fbo->handle;
return fbo;
}
#endif
int OpenGLContext::fbo_preferred_z_bitdepth() {
// This matches the fbo_create() logic.
if (gl_extensions.IsGLES) {
if (gl_extensions.OES_packed_depth_stencil) {
return 24;
}
return gl_extensions.OES_depth24 ? 24 : 16;
} else {
return 24;
}
}
Framebuffer *OpenGLContext::fbo_create(const FramebufferDesc &desc) {
CheckGLExtensions();
#ifndef USING_GLES2
if (!gl_extensions.ARB_framebuffer_object && gl_extensions.EXT_framebuffer_object) {
return fbo_ext_create(desc);
} else if (!gl_extensions.ARB_framebuffer_object) {
return nullptr;
}
// If GLES2, we have basic FBO support and can just proceed.
#endif
OpenGLFramebuffer *fbo = new OpenGLFramebuffer();
fbo->width = desc.width;
fbo->height = desc.height;
fbo->colorDepth = desc.colorDepth;
// Color texture is same everywhere
glGenFramebuffers(1, &fbo->handle);
glGenTextures(1, &fbo->color_texture);
// Create the surfaces.
glBindTexture(GL_TEXTURE_2D, fbo->color_texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// TODO: We could opt to only create 16-bit render targets on slow devices. For later.
switch (fbo->colorDepth) {
case FBO_8888:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fbo->width, fbo->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
break;
case FBO_4444:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fbo->width, fbo->height, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, NULL);
break;
case FBO_5551:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fbo->width, fbo->height, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, NULL);
break;
case FBO_565:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, fbo->width, fbo->height, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, NULL);
break;
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
if (gl_extensions.IsGLES) {
if (gl_extensions.OES_packed_depth_stencil) {
ILOG("Creating %i x %i FBO using DEPTH24_STENCIL8", fbo->width, fbo->height);
// Standard method
fbo->stencil_buffer = 0;
fbo->z_buffer = 0;
// 24-bit Z, 8-bit stencil combined
glGenRenderbuffers(1, &fbo->z_stencil_buffer);
glBindRenderbuffer(GL_RENDERBUFFER, fbo->z_stencil_buffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, fbo->width, fbo->height);
// Bind it all together
glBindFramebuffer(GL_FRAMEBUFFER, fbo->handle);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbo->color_texture, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fbo->z_stencil_buffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, fbo->z_stencil_buffer);
} else {
ILOG("Creating %i x %i FBO using separate stencil", fbo->width, fbo->height);
// TEGRA
fbo->z_stencil_buffer = 0;
// 16/24-bit Z, separate 8-bit stencil
glGenRenderbuffers(1, &fbo->z_buffer);
glBindRenderbuffer(GL_RENDERBUFFER, fbo->z_buffer);
// Don't forget to make sure fbo_standard_z_depth() matches.
glRenderbufferStorage(GL_RENDERBUFFER, gl_extensions.OES_depth24 ? GL_DEPTH_COMPONENT24 : GL_DEPTH_COMPONENT16, fbo->width, fbo->height);
// 8-bit stencil buffer
glGenRenderbuffers(1, &fbo->stencil_buffer);
glBindRenderbuffer(GL_RENDERBUFFER, fbo->stencil_buffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, fbo->width, fbo->height);
// Bind it all together
glBindFramebuffer(GL_FRAMEBUFFER, fbo->handle);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbo->color_texture, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fbo->z_buffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, fbo->stencil_buffer);
}
} else {
fbo->stencil_buffer = 0;
fbo->z_buffer = 0;
// 24-bit Z, 8-bit stencil
glGenRenderbuffers(1, &fbo->z_stencil_buffer);
glBindRenderbuffer(GL_RENDERBUFFER, fbo->z_stencil_buffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, fbo->width, fbo->height);
// Bind it all together
glBindFramebuffer(GL_FRAMEBUFFER, fbo->handle);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbo->color_texture, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fbo->z_stencil_buffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, fbo->z_stencil_buffer);
}
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
switch (status) {
case GL_FRAMEBUFFER_COMPLETE:
// ILOG("Framebuffer verified complete.");
break;
case GL_FRAMEBUFFER_UNSUPPORTED:
ELOG("GL_FRAMEBUFFER_UNSUPPORTED");
break;
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
ELOG("GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT ");
break;
default:
FLOG("Other framebuffer error: %i", status);
break;
}
// Unbind state we don't need
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glBindTexture(GL_TEXTURE_2D, 0);
currentDrawHandle_ = fbo->handle;
currentReadHandle_ = fbo->handle;
return fbo;
}
GLenum OpenGLContext::fbo_get_fb_target(bool read, GLuint **cached) {
bool supportsBlit = gl_extensions.ARB_framebuffer_object;
if (gl_extensions.IsGLES) {
supportsBlit = (gl_extensions.GLES3 || gl_extensions.NV_framebuffer_blit);
}
// Note: GL_FRAMEBUFFER_EXT and GL_FRAMEBUFFER have the same value, same with _NV.
if (supportsBlit) {
if (read) {
*cached = &currentReadHandle_;
return GL_READ_FRAMEBUFFER;
} else {
*cached = &currentDrawHandle_;
return GL_DRAW_FRAMEBUFFER;
}
} else {
*cached = &currentDrawHandle_;
return GL_FRAMEBUFFER;
}
}
void OpenGLContext::fbo_bind_fb_target(bool read, GLuint name) {
GLuint *cached;
GLenum target = fbo_get_fb_target(read, &cached);
if (*cached != name) {
if (gl_extensions.ARB_framebuffer_object || gl_extensions.IsGLES) {
glBindFramebuffer(target, name);
} else {
#ifndef USING_GLES2
glBindFramebufferEXT(target, name);
#endif
}
*cached = name;
}
}
void OpenGLContext::fbo_unbind() {
#ifndef USING_GLES2
if (gl_extensions.ARB_framebuffer_object || gl_extensions.IsGLES) {
glBindFramebuffer(GL_FRAMEBUFFER, 0);
} else if (gl_extensions.EXT_framebuffer_object) {
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}
#else
glBindFramebuffer(GL_FRAMEBUFFER, 0);
#endif
#ifdef IOS
bindDefaultFBO();
#endif
currentDrawHandle_ = 0;
currentReadHandle_ = 0;
}
void OpenGLContext::fbo_bind_as_render_target(Framebuffer *fbo) {
OpenGLFramebuffer *fb = (OpenGLFramebuffer *)fbo;
// Without FBO_ARB / GLES3, this will collide with bind_for_read, but there's nothing
// in ES 2.0 that actually separate them anyway of course, so doesn't matter.
fbo_bind_fb_target(false, fb->handle);
// Always restore viewport after render target binding
glstate.viewport.restore();
}
void OpenGLContext::fbo_bind_backbuffer_as_render_target() {
fbo_unbind();
}
// For GL_EXT_FRAMEBUFFER_BLIT and similar.
void OpenGLContext::fbo_bind_for_read(Framebuffer *fbo) {
OpenGLFramebuffer *fb = (OpenGLFramebuffer *)fbo;
fbo_bind_fb_target(true, fb->handle);
}
void OpenGLContext::fbo_copy_image(Framebuffer *fbsrc, int srcLevel, int srcX, int srcY, int srcZ, Framebuffer *fbdst, int dstLevel, int dstX, int dstY, int dstZ, int width, int height, int depth) {
OpenGLFramebuffer *src = (OpenGLFramebuffer *)fbsrc;
OpenGLFramebuffer *dst = (OpenGLFramebuffer *)fbdst;
#if defined(USING_GLES2)
#ifndef IOS
glCopyImageSubDataOES(
src->color_texture, GL_TEXTURE_2D, srcLevel, srcX, srcY, srcZ,
dst->color_texture, GL_TEXTURE_2D, dstLevel, dstX, dstY, dstZ,
width, height, depth);
return;
#endif
#else
if (gl_extensions.ARB_copy_image) {
glCopyImageSubData(
src->color_texture, GL_TEXTURE_2D, srcLevel, srcX, srcY, srcZ,
dst->color_texture, GL_TEXTURE_2D, dstLevel, dstX, dstY, dstZ,
width, height, depth);
return;
} else if (gl_extensions.NV_copy_image) {
// Older, pre GL 4.x NVIDIA cards.
glCopyImageSubDataNV(
src->color_texture, GL_TEXTURE_2D, srcLevel, srcX, srcY, srcZ,
dst->color_texture, GL_TEXTURE_2D, dstLevel, dstX, dstY, dstZ,
width, height, depth);
return;
}
#endif
}
bool OpenGLContext::fbo_blit(Framebuffer *fbsrc, int srcX1, int srcY1, int srcX2, int srcY2, Framebuffer *fbdst, int dstX1, int dstY1, int dstX2, int dstY2, int channels, FBBlitFilter linearFilter) {
OpenGLFramebuffer *src = (OpenGLFramebuffer *)fbsrc;
OpenGLFramebuffer *dst = (OpenGLFramebuffer *)fbdst;
GLuint bits = 0;
if (channels & FB_COLOR_BIT)
bits |= GL_COLOR_BUFFER_BIT;
if (channels & FB_DEPTH_BIT)
bits |= GL_DEPTH_BUFFER_BIT;
if (channels & FB_STENCIL_BIT)
bits |= GL_STENCIL_BUFFER_BIT;
fbo_bind_as_render_target(dst);
fbo_bind_for_read(src);
if (gl_extensions.GLES3 || gl_extensions.ARB_framebuffer_object) {
glBlitFramebuffer(srcX1, srcY1, srcX2, srcY2, dstX1, dstY1, dstX2, dstY2, bits, linearFilter == FB_BLIT_LINEAR ? GL_LINEAR : GL_NEAREST);
#if defined(USING_GLES2) && defined(__ANDROID__) // We only support this extension on Android, it's not even available on PC.
return true;
} else if (gl_extensions.NV_framebuffer_blit) {
glBlitFramebufferNV(srcX1, srcY1, srcX2, srcY2, dstX1, dstY1, dstX2, dstY2, bits, linearFilter == FB_BLIT_LINEAR ? GL_LINEAR : GL_NEAREST);
#endif // defined(USING_GLES2) && defined(__ANDROID__)
return true;
} else {
return false;
}
}
uintptr_t OpenGLContext::fbo_get_api_texture(Framebuffer *fbo, int channelBits, int attachment) {
// Unimplemented
return 0;
}
void OpenGLContext::fbo_bind_as_texture(Framebuffer *fbo, int binding, FBChannel channelBit, int color) {
OpenGLFramebuffer *fb = (OpenGLFramebuffer *)fbo;
// glActiveTexture(GL_TEXTURE0 + binding);
switch (channelBit) {
case FB_COLOR_BIT:
default:
if (fbo) {
glBindTexture(GL_TEXTURE_2D, fb->color_texture);
}
break;
}
}
OpenGLFramebuffer::~OpenGLFramebuffer() {
if (gl_extensions.ARB_framebuffer_object || gl_extensions.IsGLES) {
glBindFramebuffer(GL_FRAMEBUFFER, handle);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glDeleteFramebuffers(1, &handle);
glDeleteRenderbuffers(1, &z_stencil_buffer);
glDeleteRenderbuffers(1, &z_buffer);
glDeleteRenderbuffers(1, &stencil_buffer);
} else if (gl_extensions.EXT_framebuffer_object) {
#ifndef USING_GLES2
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, handle);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER_EXT, 0);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glDeleteFramebuffersEXT(1, &handle);
glDeleteRenderbuffersEXT(1, &z_stencil_buffer);
#endif
}
glDeleteTextures(1, &color_texture);
}
void OpenGLContext::fbo_get_dimensions(Framebuffer *fbo, int *w, int *h) {
OpenGLFramebuffer *fb = (OpenGLFramebuffer *)fbo;
*w = fb->width;
*h = fb->height;
}
uint32_t OpenGLContext::GetDataFormatSupport(DataFormat fmt) const {
switch (fmt) {
case DataFormat::B8G8R8A8_UNORM:

View File

@ -359,7 +359,6 @@ public:
DepthStencilState *CreateDepthStencilState(const DepthStencilStateDesc &desc) override;
BlendState *CreateBlendState(const BlendStateDesc &desc) override;
Buffer *CreateBuffer(size_t size, uint32_t usageFlags) override;
InputLayout *CreateInputLayout(const InputLayoutDesc &desc) override;
SamplerState *CreateSamplerState(const SamplerStateDesc &desc) override;
RasterState *CreateRasterState(const RasterStateDesc &desc) override;
@ -367,6 +366,24 @@ public:
ShaderModule *CreateShaderModule(ShaderStage stage, ShaderLanguage language, const uint8_t *data, size_t dataSize) override;
Texture *CreateTexture(const TextureDesc &desc) override;
Buffer *CreateBuffer(size_t size, uint32_t usageFlags) override;
Framebuffer *fbo_create(const FramebufferDesc &desc) override { return nullptr; }
void fbo_copy_image(Framebuffer *src, int level, int x, int y, int z, Framebuffer *dst, int dstLevel, int dstX, int dstY, int dstZ, int width, int height, int depth) override {}
bool fbo_blit(Framebuffer *src, int srcX1, int srcY1, int srcX2, int srcY2, Framebuffer *dst, int dstX1, int dstY1, int dstX2, int dstY2, int channelBits, FBBlitFilter filter) override { return true; }
int fbo_preferred_z_bitdepth() override { return 24; }
// These functions should be self explanatory.
void fbo_bind_as_render_target(Framebuffer *fbo) override {}
// color must be 0, for now.
void fbo_bind_as_texture(Framebuffer *fbo, int binding, FBChannel channelBit, int attachment) override {}
void fbo_bind_for_read(Framebuffer *fbo) override {}
void fbo_bind_backbuffer_as_render_target() override {}
uintptr_t fbo_get_api_texture(Framebuffer *fbo, int channelBit, int attachment) override { return 0; }
void fbo_get_dimensions(Framebuffer *fbo, int *w, int *h) override {}
void SetScissorRect(int left, int top, int width, int height) override;
void SetViewports(int count, Viewport *viewports) override;