diff --git a/src/render/direct3d/SDL_render_d3d.c b/src/render/direct3d/SDL_render_d3d.c index 67cddb387..285ddb761 100644 --- a/src/render/direct3d/SDL_render_d3d.c +++ b/src/render/direct3d/SDL_render_d3d.c @@ -1216,6 +1216,7 @@ D3D_RenderClear(SDL_Renderer * renderer) D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; DWORD color; HRESULT result; + int BackBufferWidth, BackBufferHeight; if (D3D_ActivateRenderer(renderer) < 0) { return -1; @@ -1223,10 +1224,18 @@ D3D_RenderClear(SDL_Renderer * renderer) color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b); + if (renderer->target) { + BackBufferWidth = renderer->target->w; + BackBufferHeight = renderer->target->h; + } else { + BackBufferWidth = data->pparams.BackBufferWidth; + BackBufferHeight = data->pparams.BackBufferHeight; + } + /* Don't reset the viewport if we don't have to! */ if (!renderer->viewport.x && !renderer->viewport.y && - renderer->viewport.w == data->pparams.BackBufferWidth && - renderer->viewport.h == data->pparams.BackBufferHeight) { + renderer->viewport.w == BackBufferWidth && + renderer->viewport.h == BackBufferHeight) { result = IDirect3DDevice9_Clear(data->device, 0, NULL, D3DCLEAR_TARGET, color, 0.0f, 0); } else { D3DVIEWPORT9 viewport; @@ -1234,8 +1243,8 @@ D3D_RenderClear(SDL_Renderer * renderer) /* Clear is defined to clear the entire render target */ viewport.X = 0; viewport.Y = 0; - viewport.Width = data->pparams.BackBufferWidth; - viewport.Height = data->pparams.BackBufferHeight; + viewport.Width = BackBufferWidth; + viewport.Height = BackBufferHeight; viewport.MinZ = 0.0f; viewport.MaxZ = 1.0f; IDirect3DDevice9_SetViewport(data->device, &viewport);