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.
This commit is contained in:
Sam Lantinga 2013-10-19 01:29:23 -07:00
parent b4a00144fb
commit e343273abb
1 changed files with 13 additions and 4 deletions

View File

@ -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);