Skip to content
Permalink
Browse files

Fixed bug 2162 - SDL_RenderClear not clearing entire render target

Kevin Wells

Overview:
SDL_RenderClear is only clearing part of a texture when it is the render target and a different size than the screen.

Steps to Reproduce:
1) This only occurs with the render driver set to direct3d, so: SDL_SetHint(SDL_HINT_RENDER_DRIVER,"direct3d")
Also, my window was 1280x720.

2) Create a texture for a render target with a resolution of 1024x1024:
texture=SDL_CreateTexture(main_window.renderer,SDL_PIXELFORMAT_RGBA8888,SDL_TEXTUREACCESS_TARGET,1024,1024);
SDL_SetTextureBlendMode(texture,SDL_BLENDMODE_BLEND);

3) Target the texture for rendering: SDL_SetRenderTarget(main_window.renderer,texture);

4) Set the draw color to whatever you want (problem occurs with both 0,0,0,0 and 0,0,0,255 among others) and then clear the render target:
SDL_SetRenderDrawColor(main_window.renderer,0,0,0,0);
SDL_RenderClear(main_window.renderer);

Actual Results:
Only about the top 3/4s of the texture gets cleared on calling SDL_RenderClear. The bottom 1/4 or so does not clear.

Expected Results:
Entire render target should be cleared.
  • Loading branch information
slouken committed Oct 19, 2013
1 parent b4a0014 commit e343273abb68ea9c27ac71127baa8499ab125c27
Showing with 13 additions and 4 deletions.
  1. +13 −4 src/render/direct3d/SDL_render_d3d.c
@@ -1216,26 +1216,35 @@ 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;
}

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;

/* 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);

0 comments on commit e343273

Please sign in to comment.