Fixed bug 3345 - SDL_RenderClear inconsistency with ClipRect

Simon Hug

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.
This commit is contained in:
Sam Lantinga 2016-10-01 11:46:32 -07:00
parent 89c868f4f8
commit 77305d47c2
5 changed files with 34 additions and 1 deletions

View File

@ -682,7 +682,8 @@ extern DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(SDL_Renderer * renderer,
/**
* \brief Clear the current rendering target with the drawing color
*
* This function clears the entire rendering target, ignoring the viewport.
* This function clears the entire rendering target, ignoring the viewport and
* the clip rectangle.
*
* \return 0 on success, or -1 on error
*/

View File

@ -1311,6 +1311,10 @@ D3D_RenderClear(SDL_Renderer * renderer)
BackBufferHeight = data->pparams.BackBufferHeight;
}
if (renderer->clipping_enabled) {
IDirect3DDevice9_SetRenderState(data->device, D3DRS_SCISSORTESTENABLE, FALSE);
}
/* Don't reset the viewport if we don't have to! */
if (!renderer->viewport.x && !renderer->viewport.y &&
renderer->viewport.w == BackBufferWidth &&
@ -1340,6 +1344,10 @@ D3D_RenderClear(SDL_Renderer * renderer)
IDirect3DDevice9_SetViewport(data->device, &viewport);
}
if (renderer->clipping_enabled) {
IDirect3DDevice9_SetRenderState(data->device, D3DRS_SCISSORTESTENABLE, TRUE);
}
if (FAILED(result)) {
return D3D_SetError("Clear()", result);
}

View File

@ -1146,8 +1146,16 @@ GL_RenderClear(SDL_Renderer * renderer)
(GLfloat) renderer->b * inv255f,
(GLfloat) renderer->a * inv255f);
if (renderer->clipping_enabled) {
data->glDisable(GL_SCISSOR_TEST);
}
data->glClear(GL_COLOR_BUFFER_BIT);
if (renderer->clipping_enabled) {
data->glEnable(GL_SCISSOR_TEST);
}
return 0;
}

View File

@ -816,8 +816,16 @@ GLES_RenderClear(SDL_Renderer * renderer)
(GLfloat) renderer->b * inv255f,
(GLfloat) renderer->a * inv255f);
if (renderer->clipping_enabled) {
data->glDisable(GL_SCISSOR_TEST);
}
data->glClear(GL_COLOR_BUFFER_BIT);
if (renderer->clipping_enabled) {
data->glEnable(GL_SCISSOR_TEST);
}
return 0;
}

View File

@ -1327,8 +1327,16 @@ GLES2_RenderClear(SDL_Renderer * renderer)
data->clear_a = renderer->a;
}
if (renderer->clipping_enabled) {
data->glDisable(GL_SCISSOR_TEST);
}
data->glClear(GL_COLOR_BUFFER_BIT);
if (renderer->clipping_enabled) {
data->glEnable(GL_SCISSOR_TEST);
}
return 0;
}