From de3d381cb64fbefebd63f80aecb651dbfc82c80a Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 17 Aug 2014 14:44:53 -0700 Subject: [PATCH] Fixed bug 2685 - SDL_RenderReadPixels() doesn't work with offscreen targets Andreas Falkenhahn SDL_RenderReadPixels() doesn't seem to work when trying to read pixels from a texture that has been created using SDL_TEXTUREACCESS_TARGET and has been selected as the render target using SDL_SetRenderTarget(). I am attaching a small program that demonstrates the issue. I get the following result here: READ PIXEL RETURN: 0 --- COLOR CHECK: ff000000 But it should be: READ PIXEL RETURN: 0 --- COLOR CHECK: ffff0000 Tested with SDL 2.0.3 on Windows 7. --- src/render/direct3d/SDL_render_d3d.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/render/direct3d/SDL_render_d3d.c b/src/render/direct3d/SDL_render_d3d.c index be88da3c8..d96522e71 100644 --- a/src/render/direct3d/SDL_render_d3d.c +++ b/src/render/direct3d/SDL_render_d3d.c @@ -1831,9 +1831,10 @@ D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, D3DLOCKED_RECT locked; HRESULT result; - result = IDirect3DDevice9_GetBackBuffer(data->device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backBuffer); - if (FAILED(result)) { - return D3D_SetError("GetBackBuffer()", result); + if (data->currentRenderTarget) { + backBuffer = data->currentRenderTarget; + } else { + backBuffer = data->defaultRenderTarget; } result = IDirect3DSurface9_GetDesc(backBuffer, &desc); @@ -1874,7 +1875,6 @@ D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, IDirect3DSurface9_UnlockRect(surface); IDirect3DSurface9_Release(surface); - IDirect3DSurface9_Release(backBuffer); return 0; }