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 3345 - SDL_RenderClear inconsistency with ClipRect
Summary: SDL_RenderClear inconsistency with ClipRect
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: render (show other bugs)
Version: HG 2.0
Hardware: All All
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-05-26 16:00 UTC by Simon Hug
Modified: 2016-10-01 18:46 UTC (History)
0 users

See Also:


Attachments
Test case for SDL_RenderClear and ClipRect. (3.48 KB, text/x-csrc)
2016-05-26 16:00 UTC, Simon Hug
Details
Patch that disables the scissor test for various renderers when they clear the render target. (3.08 KB, patch)
2016-06-16 11:37 UTC, Simon Hug
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Hug 2016-05-26 16:00:37 UTC
Created attachment 2465 [details]
Test case for SDL_RenderClear and ClipRect.

The description of the SDL_RenderClear function in the SDL_render.h header says the following:

"This function clears the entire rendering target, ignoring the viewport."

The word "entire" implies that the clipping rectangle set with SDL_RenderSetClipRect also gets ignored. This is left somewhat ambiguous if only the viewport is mentioned. Minor thing, but let's see what the implementations actually do.

The software renderer ignores the clipping rectangle when clearing. It even has a comment on this: /* By definition the clear ignores the clip rect */

Most other render drivers (opengl, opengles, opengles2, direct3d, and psp [I assume. Can't test it.]) use the scissor test for the ClipRect and don't disable it when clearing. Clearing will only happen within the clipping rectangle for these drivers.

An exception is direct3d11 which uses a clear function that ignores the scissor test.

Attached is a test case that shows a green window when the ClipRect is ignored or a green square on a blue background when ClipRect affects the clearing. The lower half of the window is a target texture or red if unsupported.
Comment 1 Simon Hug 2016-06-16 11:37:29 UTC
Created attachment 2497 [details]
Patch that disables the scissor test for various renderers when they clear the render target.

The attached patch changes the code around the clear operation of the opengl, opengles, opengles2, and direct3d renderers to disable and re-enable the scissor test if clipping is active. It also resolves the ambiguity in the comment of SDL_RenderClear in the SDL_render.h header by clearly stating that the clear rectangle gets ignored.
Comment 2 Sam Lantinga 2016-10-01 18:46:52 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/d78b187845d6