Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Don't reset the viewport unless you have to.

  • Loading branch information
slouken committed Feb 15, 2011
1 parent a718ad0 commit 1d354b40ea06360cc667117d4eea18680fee5f53
Showing with 28 additions and 20 deletions.
  1. +28 −20 src/render/direct3d/SDL_render_d3d.c
@@ -704,35 +704,43 @@ static int
D3D_RenderClear(SDL_Renderer * renderer)
{
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
D3DVIEWPORT9 viewport;
DWORD color;
HRESULT result;

if (D3D_ActivateRenderer(renderer) < 0) {
return -1;
}

/* 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.MinZ = 0.0f;
viewport.MaxZ = 1.0f;
IDirect3DDevice9_SetViewport(data->device, &viewport);

color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b);

result = IDirect3DDevice9_Clear(data->device, 0, NULL, D3DCLEAR_TARGET, color, 0.0f, 0);

/* Reset the viewport */
viewport.X = renderer->viewport.x;
viewport.Y = renderer->viewport.y;
viewport.Width = renderer->viewport.w;
viewport.Height = renderer->viewport.h;
viewport.MinZ = 0.0f;
viewport.MaxZ = 1.0f;
IDirect3DDevice9_SetViewport(data->device, &viewport);
/* 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) {
result = IDirect3DDevice9_Clear(data->device, 0, NULL, D3DCLEAR_TARGET, color, 0.0f, 0);
} else {
D3DVIEWPORT9 viewport;

/* 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.MinZ = 0.0f;
viewport.MaxZ = 1.0f;
IDirect3DDevice9_SetViewport(data->device, &viewport);

result = IDirect3DDevice9_Clear(data->device, 0, NULL, D3DCLEAR_TARGET, color, 0.0f, 0);

/* Reset the viewport */
viewport.X = renderer->viewport.x;
viewport.Y = renderer->viewport.y;
viewport.Width = renderer->viewport.w;
viewport.Height = renderer->viewport.h;
viewport.MinZ = 0.0f;
viewport.MaxZ = 1.0f;
IDirect3DDevice9_SetViewport(data->device, &viewport);
}

if (FAILED(result)) {
D3D_SetError("Clear()", result);

0 comments on commit 1d354b4

Please sign in to comment.