diff --git a/GPU/Directx9/FramebufferDX9.cpp b/GPU/Directx9/FramebufferDX9.cpp index 9ab669d65e..a6cc0bc2b5 100644 --- a/GPU/Directx9/FramebufferDX9.cpp +++ b/GPU/Directx9/FramebufferDX9.cpp @@ -1062,14 +1062,62 @@ namespace DX9 { bool FramebufferManagerDX9::GetCurrentFramebuffer(GPUDebugBuffer &buffer) { - return true; + u32 fb_address = gstate.getFrameBufRawAddress(); + int fb_stride = gstate.FrameBufStride(); + + VirtualFramebufferDX9 *vfb = currentRenderVfb_; + if (!vfb) { + vfb = GetVFBAt(fb_address); + } + + if (!vfb) { + // If there's no vfb and we're drawing there, must be memory? + buffer = GPUDebugBuffer(Memory::GetPointer(fb_address | 0x04000000), fb_stride, 512, gstate.FrameBufFormat()); + return true; + } + + LPDIRECT3DSURFACE9 renderTarget; + HRESULT hr; + hr = pD3Ddevice->GetRenderTarget(0, &renderTarget); + if (!renderTarget || !SUCCEEDED(hr)) + return false; + + D3DSURFACE_DESC desc; + renderTarget->GetDesc(&desc); + + LPDIRECT3DSURFACE9 offscreen; + hr = pD3Ddevice->CreateOffscreenPlainSurface(desc.Width, desc.Height, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &offscreen, NULL); + if (!SUCCEEDED(hr)) + return false; + + bool success = false; + hr = pD3Ddevice->GetRenderTargetData(renderTarget, offscreen); + if (SUCCEEDED(hr)) { + D3DLOCKED_RECT locked; + RECT rect = {0, 0, vfb->renderWidth, vfb->renderHeight}; + hr = offscreen->LockRect(&locked, &rect, D3DLOCK_READONLY); + if (SUCCEEDED(hr)) { + // TODO: Handle the other formats? + // TODO: BGRA. + buffer.Allocate(locked.Pitch / 4, vfb->renderHeight, GE_FORMAT_8888, false, true); + memcpy(buffer.GetData(), locked.pBits, locked.Pitch * vfb->renderHeight); + offscreen->UnlockRect(); + success = true; + } + } + + offscreen->Release(); + + return success; } bool FramebufferManagerDX9::GetCurrentDepthbuffer(GPUDebugBuffer &buffer) { + // TODO: Is this possible? return false; } bool FramebufferManagerDX9::GetCurrentStencilbuffer(GPUDebugBuffer &buffer) { + // TODO: Is this possible? return false; } diff --git a/GPU/Directx9/GPU_DX9.cpp b/GPU/Directx9/GPU_DX9.cpp index e9864e2e32..7539369114 100644 --- a/GPU/Directx9/GPU_DX9.cpp +++ b/GPU/Directx9/GPU_DX9.cpp @@ -1568,12 +1568,70 @@ bool DIRECTX9_GPU::GetCurrentStencilbuffer(GPUDebugBuffer &buffer) { return framebufferManager_.GetCurrentStencilbuffer(buffer); } -bool DIRECTX9_GPU::GetCurrentTexture(GPUDebugBuffer &buffer) { +bool DIRECTX9_GPU::GetCurrentTexture(GPUDebugBuffer &buffer, int level) { if (!gstate.isTextureMapEnabled()) { return false; } - return false; + textureCache_.SetTexture(true); + int w = gstate.getTextureWidth(level); + int h = gstate.getTextureHeight(level); + + LPDIRECT3DBASETEXTURE9 baseTex; + LPDIRECT3DTEXTURE9 tex; + HRESULT hr; + + bool success; + hr = pD3Ddevice->GetTexture(0, &baseTex); + if (SUCCEEDED(hr)) { + hr = baseTex->QueryInterface(IID_IDirect3DTexture9, (void **)&tex); + if (SUCCEEDED(hr)) { + D3DSURFACE_DESC desc; + D3DLOCKED_RECT locked; + tex->GetLevelDesc(level, &desc); + RECT rect = {0, 0, desc.Width, desc.Height}; + hr = tex->LockRect(level, &locked, &rect, D3DLOCK_READONLY); + if (SUCCEEDED(hr)) { + GPUDebugBufferFormat fmt; + int pixelSize; + // TODO: These formats are wrong. + switch (desc.Format) { + case D3DFMT_A1R5G5B5: + fmt = GPU_DBG_FORMAT_5551; + pixelSize = 2; + break; + case D3DFMT_A4R4G4B4: + fmt = GPU_DBG_FORMAT_4444; + pixelSize = 2; + break; + case D3DFMT_R5G6B5: + fmt = GPU_DBG_FORMAT_565; + pixelSize = 2; + break; + case D3DFMT_A8R8G8B8: + fmt = GPU_DBG_FORMAT_8888; + pixelSize = 4; + break; + default: + fmt = GPU_DBG_FORMAT_INVALID; + break; + } + + if (fmt != GPU_DBG_FORMAT_INVALID) { + buffer.Allocate(locked.Pitch / pixelSize, desc.Height, fmt, gstate_c.flipTexture); + memcpy(buffer.GetData(), locked.pBits, locked.Pitch * desc.Height); + success = true; + } else { + success = false; + } + tex->UnlockRect(level); + } + tex->Release(); + } + baseTex->Release(); + } + + return success; } }; diff --git a/GPU/Directx9/GPU_DX9.h b/GPU/Directx9/GPU_DX9.h index 6a71974f60..ec7a542d11 100644 --- a/GPU/Directx9/GPU_DX9.h +++ b/GPU/Directx9/GPU_DX9.h @@ -76,7 +76,7 @@ public: bool GetCurrentFramebuffer(GPUDebugBuffer &buffer); bool GetCurrentDepthbuffer(GPUDebugBuffer &buffer); bool GetCurrentStencilbuffer(GPUDebugBuffer &buffer); - bool GetCurrentTexture(GPUDebugBuffer &buffer); + bool GetCurrentTexture(GPUDebugBuffer &buffer, int level); protected: virtual void FastRunLoop(DisplayList &list); virtual void ProcessEvent(GPUEvent ev); diff --git a/GPU/GLES/Framebuffer.cpp b/GPU/GLES/Framebuffer.cpp index 6f1f77242f..88b501350b 100644 --- a/GPU/GLES/Framebuffer.cpp +++ b/GPU/GLES/Framebuffer.cpp @@ -2505,7 +2505,6 @@ bool FramebufferManager::GetCurrentDepthbuffer(GPUDebugBuffer &buffer) { if (!vfb) { // If there's no vfb and we're drawing there, must be memory? - // TODO: Is the value 16-bit? It seems to be. buffer = GPUDebugBuffer(Memory::GetPointer(z_address | 0x04000000), z_stride, 512, GPU_DBG_FORMAT_16BIT); return true; } diff --git a/Windows/PPSSPP.vcxproj b/Windows/PPSSPP.vcxproj index 5327034679..26d57c9710 100644 --- a/Windows/PPSSPP.vcxproj +++ b/Windows/PPSSPP.vcxproj @@ -131,7 +131,7 @@ false - Winmm.lib;Ws2_32.lib;opengl32.lib;dsound.lib;glu32.lib;..\ffmpeg\Windows\x86\lib\avcodec.lib;..\ffmpeg\Windows\x86\lib\avformat.lib;..\ffmpeg\Windows\x86\lib\avutil.lib;..\ffmpeg\Windows\x86\lib\swresample.lib;..\ffmpeg\Windows\x86\lib\swscale.lib;comctl32.lib;d3d9.lib;%(AdditionalDependencies) + Winmm.lib;Ws2_32.lib;opengl32.lib;dsound.lib;glu32.lib;..\ffmpeg\Windows\x86\lib\avcodec.lib;..\ffmpeg\Windows\x86\lib\avformat.lib;..\ffmpeg\Windows\x86\lib\avutil.lib;..\ffmpeg\Windows\x86\lib\swresample.lib;..\ffmpeg\Windows\x86\lib\swscale.lib;comctl32.lib;d3d9.lib;dxguid.lib;%(AdditionalDependencies) true Windows MachineX86 @@ -165,7 +165,7 @@ false - Winmm.lib;Ws2_32.lib;opengl32.lib;dsound.lib;glu32.lib;..\ffmpeg\Windows\x86_64\lib\avcodec.lib;..\ffmpeg\Windows\x86_64\lib\avformat.lib;..\ffmpeg\Windows\x86_64\lib\avutil.lib;..\ffmpeg\Windows\x86_64\lib\swresample.lib;..\ffmpeg\Windows\x86_64\lib\swscale.lib;comctl32.lib;d3d9.lib;%(AdditionalDependencies) + Winmm.lib;Ws2_32.lib;opengl32.lib;dsound.lib;glu32.lib;..\ffmpeg\Windows\x86_64\lib\avcodec.lib;..\ffmpeg\Windows\x86_64\lib\avformat.lib;..\ffmpeg\Windows\x86_64\lib\avutil.lib;..\ffmpeg\Windows\x86_64\lib\swresample.lib;..\ffmpeg\Windows\x86_64\lib\swscale.lib;comctl32.lib;d3d9.lib;dxguid.lib;%(AdditionalDependencies) true $(OutDir)$(ProjectName).pdb Windows @@ -200,7 +200,7 @@ false - Winmm.lib;Ws2_32.lib;opengl32.lib;dsound.lib;glu32.lib;..\ffmpeg\Windows\x86\lib\avcodec.lib;..\ffmpeg\Windows\x86\lib\avformat.lib;..\ffmpeg\Windows\x86\lib\avutil.lib;..\ffmpeg\Windows\x86\lib\swresample.lib;..\ffmpeg\Windows\x86\lib\swscale.lib;comctl32.lib;d3d9.lib;%(AdditionalDependencies) + Winmm.lib;Ws2_32.lib;opengl32.lib;dsound.lib;glu32.lib;..\ffmpeg\Windows\x86\lib\avcodec.lib;..\ffmpeg\Windows\x86\lib\avformat.lib;..\ffmpeg\Windows\x86\lib\avutil.lib;..\ffmpeg\Windows\x86\lib\swresample.lib;..\ffmpeg\Windows\x86\lib\swscale.lib;comctl32.lib;d3d9.lib;dxguid.lib;%(AdditionalDependencies) $(OutDir)$(TargetName)$(TargetExt) %(AdditionalLibraryDirectories) true @@ -241,7 +241,7 @@ false - Winmm.lib;Ws2_32.lib;opengl32.lib;dsound.lib;glu32.lib;..\ffmpeg\Windows\x86_64\lib\avcodec.lib;..\ffmpeg\Windows\x86_64\lib\avformat.lib;..\ffmpeg\Windows\x86_64\lib\avutil.lib;..\ffmpeg\Windows\x86_64\lib\swresample.lib;..\ffmpeg\Windows\x86_64\lib\swscale.lib;comctl32.lib;d3d9.lib;%(AdditionalDependencies) + Winmm.lib;Ws2_32.lib;opengl32.lib;dsound.lib;glu32.lib;..\ffmpeg\Windows\x86_64\lib\avcodec.lib;..\ffmpeg\Windows\x86_64\lib\avformat.lib;..\ffmpeg\Windows\x86_64\lib\avutil.lib;..\ffmpeg\Windows\x86_64\lib\swresample.lib;..\ffmpeg\Windows\x86_64\lib\swscale.lib;comctl32.lib;d3d9.lib;dxguid.lib;%(AdditionalDependencies) %(AdditionalLibraryDirectories) true Windows diff --git a/headless/Headless.vcxproj b/headless/Headless.vcxproj index 28dfd7c75c..54ecd36246 100644 --- a/headless/Headless.vcxproj +++ b/headless/Headless.vcxproj @@ -104,7 +104,7 @@ Console true - Winmm.lib;Ws2_32.lib;opengl32.lib;dsound.lib;glu32.lib;..\ffmpeg\Windows\x86\lib\avcodec.lib;..\ffmpeg\Windows\x86\lib\avformat.lib;..\ffmpeg\Windows\x86\lib\avutil.lib;..\ffmpeg\Windows\x86\lib\swresample.lib;..\ffmpeg\Windows\x86\lib\swscale.lib;comctl32.lib;xinput.lib;d3d9.lib;d3dx9d.lib;%(AdditionalDependencies) + Winmm.lib;Ws2_32.lib;opengl32.lib;dsound.lib;glu32.lib;..\ffmpeg\Windows\x86\lib\avcodec.lib;..\ffmpeg\Windows\x86\lib\avformat.lib;..\ffmpeg\Windows\x86\lib\avutil.lib;..\ffmpeg\Windows\x86\lib\swresample.lib;..\ffmpeg\Windows\x86\lib\swscale.lib;comctl32.lib;xinput.lib;d3d9.lib;d3dx9d.lib;dxguid.lib;%(AdditionalDependencies) 0x00400000 false true @@ -128,7 +128,7 @@ Console true - Winmm.lib;Ws2_32.lib;opengl32.lib;dsound.lib;glu32.lib;..\ffmpeg\Windows\x86_64\lib\avcodec.lib;..\ffmpeg\Windows\x86_64\lib\avformat.lib;..\ffmpeg\Windows\x86_64\lib\avutil.lib;..\ffmpeg\Windows\x86_64\lib\swresample.lib;..\ffmpeg\Windows\x86_64\lib\swscale.lib;comctl32.lib;d3d9.lib;d3dx9d.lib;%(AdditionalDependencies) + Winmm.lib;Ws2_32.lib;opengl32.lib;dsound.lib;glu32.lib;..\ffmpeg\Windows\x86_64\lib\avcodec.lib;..\ffmpeg\Windows\x86_64\lib\avformat.lib;..\ffmpeg\Windows\x86_64\lib\avutil.lib;..\ffmpeg\Windows\x86_64\lib\swresample.lib;..\ffmpeg\Windows\x86_64\lib\swscale.lib;comctl32.lib;d3d9.lib;d3dx9d.lib;dxguid.lib;%(AdditionalDependencies) 0x00400000 false true @@ -156,7 +156,7 @@ true true true - Winmm.lib;Ws2_32.lib;opengl32.lib;dsound.lib;glu32.lib;..\ffmpeg\Windows\x86\lib\avcodec.lib;..\ffmpeg\Windows\x86\lib\avformat.lib;..\ffmpeg\Windows\x86\lib\avutil.lib;..\ffmpeg\Windows\x86\lib\swresample.lib;..\ffmpeg\Windows\x86\lib\swscale.lib;comctl32.lib;d3d9.lib;d3dx9.lib;%(AdditionalDependencies) + Winmm.lib;Ws2_32.lib;opengl32.lib;dsound.lib;glu32.lib;..\ffmpeg\Windows\x86\lib\avcodec.lib;..\ffmpeg\Windows\x86\lib\avformat.lib;..\ffmpeg\Windows\x86\lib\avutil.lib;..\ffmpeg\Windows\x86\lib\swresample.lib;..\ffmpeg\Windows\x86\lib\swscale.lib;comctl32.lib;d3d9.lib;d3dx9.lib;dxguid.lib;%(AdditionalDependencies) 0x00400000 false true @@ -185,7 +185,7 @@ true true true - Winmm.lib;Ws2_32.lib;opengl32.lib;dsound.lib;glu32.lib;..\ffmpeg\Windows\x86_64\lib\avcodec.lib;..\ffmpeg\Windows\x86_64\lib\avformat.lib;..\ffmpeg\Windows\x86_64\lib\avutil.lib;..\ffmpeg\Windows\x86_64\lib\swresample.lib;..\ffmpeg\Windows\x86_64\lib\swscale.lib;comctl32.lib;d3d9.lib;d3dx9.lib;%(AdditionalDependencies) + Winmm.lib;Ws2_32.lib;opengl32.lib;dsound.lib;glu32.lib;..\ffmpeg\Windows\x86_64\lib\avcodec.lib;..\ffmpeg\Windows\x86_64\lib\avformat.lib;..\ffmpeg\Windows\x86_64\lib\avutil.lib;..\ffmpeg\Windows\x86_64\lib\swresample.lib;..\ffmpeg\Windows\x86_64\lib\swscale.lib;comctl32.lib;d3d9.lib;d3dx9.lib;dxguid.lib;%(AdditionalDependencies) 0x00400000 false true