Skip to content

Commit

Permalink
Fixed bug 2685 - SDL_RenderReadPixels() doesn't work with offscreen t…
Browse files Browse the repository at this point in the history
…argets

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.
  • Loading branch information
slouken committed Aug 17, 2014
1 parent 2e3c778 commit de3d381
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/render/direct3d/SDL_render_d3d.c
Expand Up @@ -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);
Expand Down Expand Up @@ -1874,7 +1875,6 @@ D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
IDirect3DSurface9_UnlockRect(surface);

IDirect3DSurface9_Release(surface);
IDirect3DSurface9_Release(backBuffer);

return 0;
}
Expand Down

0 comments on commit de3d381

Please sign in to comment.