We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2162

Summary: SDL_RenderClear not clearing entire render target
Product: SDL Reporter: Kevin Wells <DarkOppressor>
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: 2.0.0   
Hardware: x86_64   
OS: Windows 7   
URL: http://www.youtube.com/watch?v=v7Np5S3Bgj0
Attachments: DxDiag with relevant system information

Description Kevin Wells 2013-10-18 21:28:10 UTC
Created attachment 1374 [details]
DxDiag with relevant system information

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.

Build Date and Hardware:
Stable 2.0.0 on Windows 7 Professional 64-bit (see attached DxDiag for details)

Additional Information:
The size of the window is 1280x720. The size of the texture is 1024x1024. If you create the texture with a size of 1280x720 instead, SDL_RenderClear clears the entire texture.

Using 'SDL_RenderFillRect(main_window.renderer,NULL)' instead of SDL_RenderClear DOES fill the entire texture with color.

I tried a variety of tweaks (playing with different SDL_HINT_'s, texture and renderer settings, etc.) and could not find any way to prevent the problem from happening until I tried 'SDL_SetHint(SDL_HINT_RENDER_DRIVER,"opengl")' which pointed me to the direct3d render driver being the (a part of the?) culprit.
Comment 1 Kevin Wells 2013-10-18 21:31:07 UTC
See the URL for a video showing the bug in action.

The game is a 2D top-down affair, and the animated texture I'm making is falling raindrops. The game world is divided into "chunks" of 1024x1024 pixels, and weather occurs at this resolution, so my 1024x1024 rain texture is rendered over any chunk in which it is raining. As you can see, the bottom section of the texture quickly fills with raindrop color and is never cleared.
Comment 2 Sam Lantinga 2013-10-19 08:30:47 UTC
Okay, I'm not on a windows machine, so I can't test it, but I think this will fix the issue:
http://hg.libsdl.org/SDL/rev/2f2f0b3b4702

Can you try it out and see?

Thanks!
Comment 3 Kevin Wells 2013-10-19 21:21:39 UTC
I would love to, but I don't know how to build SDL from source on Windows. I've been using the pre-built dev binaries built with MinGW. Does anyone build those periodically, do you know? If not, I will try to figure it out.
Comment 4 Sam Lantinga 2013-10-21 09:43:54 UTC
How about this?
http://www.libsdl.org/tmp/release/SDL2-devel-2.0.1-mingw.tar.gz
Comment 5 Kevin Wells 2013-10-22 03:56:07 UTC
Thanks! Yes, that seems to have fixed the problem. The full texture is now being cleared as expected using the direct3d render driver.
Comment 6 Sam Lantinga 2013-10-22 04:11:03 UTC
Great, thanks!