From 4dd96d699388bdca8fc2a1bb0b7fca77fb30ab34 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sun, 5 Feb 2017 20:19:43 +0100 Subject: [PATCH] Remove dx_fbo dependency on global.h --- GPU/Directx9/helper/dx_fbo.cpp | 36 +++++++++++++++++----------------- GPU/Directx9/helper/dx_fbo.h | 4 +++- Windows/GPU/D3D9Context.cpp | 4 ++-- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/GPU/Directx9/helper/dx_fbo.cpp b/GPU/Directx9/helper/dx_fbo.cpp index b39b4749c0..88944dda1b 100644 --- a/GPU/Directx9/helper/dx_fbo.cpp +++ b/GPU/Directx9/helper/dx_fbo.cpp @@ -16,11 +16,10 @@ // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. #include +#include +#include +#include -#include "global.h" -#include -#include -#include #include "base/logging.h" #include "dx_fbo.h" #include "dx_state.h" @@ -42,13 +41,14 @@ struct FBO_DX9 { 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) { - pD3Ddevice->GetRenderTarget(0, &deviceRTsurf); - pD3Ddevice->GetDepthStencilSurface(&deviceDSsurf); +void fbo_init(LPDIRECT3D9 d3d, LPDIRECT3DDEVICE9 device) { + g_device = device; + g_device->GetRenderTarget(0, &deviceRTsurf); + g_device->GetDepthStencilSurface(&deviceDSsurf); if (d3d) { D3DDISPLAYMODE displayMode; @@ -75,7 +75,7 @@ FBO_DX9 *fbo_create(const FramebufferDesc &desc) { fbo->colorDepth = desc.colorDepth; fbo->depthstenciltex = nullptr; - HRESULT rtResult = pD3Ddevice->CreateTexture(fbo->width, fbo->height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &fbo->tex, NULL); + 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; @@ -85,12 +85,12 @@ FBO_DX9 *fbo_create(const FramebufferDesc &desc) { HRESULT dsResult; if (supportsINTZ) { - dsResult = pD3Ddevice->CreateTexture(fbo->width, fbo->height, 1, D3DUSAGE_DEPTHSTENCIL, FOURCC_INTZ, D3DPOOL_DEFAULT, &fbo->depthstenciltex, NULL); + 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 = pD3Ddevice->CreateDepthStencilSurface(fbo->width, fbo->height, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, 0, FALSE, &fbo->depthstencil, NULL); + 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"); @@ -117,8 +117,8 @@ void fbo_destroy(FBO_DX9 *fbo) { } void fbo_bind_backbuffer_as_render_target() { - pD3Ddevice->SetRenderTarget(0, deviceRTsurf); - pD3Ddevice->SetDepthStencilSurface(deviceDSsurf); + g_device->SetRenderTarget(0, deviceRTsurf); + g_device->SetDepthStencilSurface(deviceDSsurf); dxstate.scissorRect.restore(); dxstate.viewport.restore(); } @@ -127,8 +127,8 @@ void fbo_resolve(FBO_DX9 *fbo) { } void fbo_bind_as_render_target(FBO_DX9 *fbo) { - pD3Ddevice->SetRenderTarget(0, fbo->surf); - pD3Ddevice->SetDepthStencilSurface(fbo->depthstencil); + g_device->SetRenderTarget(0, fbo->surf); + g_device->SetDepthStencilSurface(fbo->depthstencil); dxstate.scissorRect.restore(); dxstate.viewport.restore(); } @@ -165,13 +165,13 @@ void fbo_bind_as_texture(FBO_DX9 *fbo, int binding, FBOChannel channelBit, int c switch (channelBit) { case FB_DEPTH_BIT: if (fbo->depthstenciltex) { - pD3Ddevice->SetTexture(binding, fbo->depthstenciltex); + g_device->SetTexture(binding, fbo->depthstenciltex); } break; case FB_COLOR_BIT: default: if (fbo->tex) { - pD3Ddevice->SetTexture(binding, fbo->tex); + g_device->SetTexture(binding, fbo->tex); } break; } @@ -189,7 +189,7 @@ bool fbo_blit(FBO_DX9 *src, int srcX1, int srcY1, int srcX2, int srcY2, FBO_DX9 RECT dstRect{ (LONG)dstX1, (LONG)dstY1, (LONG)dstX2, (LONG)dstY2 }; LPDIRECT3DSURFACE9 srcSurf = src ? src->surf : deviceRTsurf; LPDIRECT3DSURFACE9 dstSurf = dst ? dst->surf : deviceRTsurf; - return SUCCEEDED(pD3Ddevice->StretchRect(srcSurf, &srcRect, dstSurf, &dstRect, filter == FB_BLIT_LINEAR ? D3DTEXF_LINEAR : D3DTEXF_POINT)); + return SUCCEEDED(g_device->StretchRect(srcSurf, &srcRect, dstSurf, &dstRect, filter == FB_BLIT_LINEAR ? D3DTEXF_LINEAR : D3DTEXF_POINT)); } } // namespace diff --git a/GPU/Directx9/helper/dx_fbo.h b/GPU/Directx9/helper/dx_fbo.h index f75e3fcd96..a49349344f 100644 --- a/GPU/Directx9/helper/dx_fbo.h +++ b/GPU/Directx9/helper/dx_fbo.h @@ -17,6 +17,8 @@ #pragma once +#include + // 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... @@ -77,7 +79,7 @@ void fbo_resolve(FBO_DX9 *fbo); 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); +void fbo_init(LPDIRECT3D9 d3d, LPDIRECT3DDEVICE9 device); void fbo_shutdown(); }; \ No newline at end of file diff --git a/Windows/GPU/D3D9Context.cpp b/Windows/GPU/D3D9Context.cpp index 8db277e784..89acfba263 100644 --- a/Windows/GPU/D3D9Context.cpp +++ b/Windows/GPU/D3D9Context.cpp @@ -165,7 +165,7 @@ bool D3D9Context::Init(HINSTANCE hInst, HWND wnd, std::string *error_message) { DX9::pD3Ddevice = device; DX9::pD3DdeviceEx = deviceEx; - DX9::fbo_init(d3d); + DX9::fbo_init(d3d, device); if (deviceEx && IsWin7OrLater()) { // TODO: This makes it slower? @@ -194,7 +194,7 @@ void D3D9Context::Resize() { ERROR_LOG_REPORT(G3D, "Unable to reset D3D device"); PanicAlert("Unable to reset D3D9 device"); } - DX9::fbo_init(d3d); + DX9::fbo_init(d3d, device); } }