Skip to content

Commit

Permalink
Fixed bug 3345 - SDL_RenderClear inconsistency with ClipRect
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
slouken committed Oct 1, 2016
1 parent 89c868f commit 77305d4
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion include/SDL_render.h
Expand Up @@ -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
*/
Expand Down
8 changes: 8 additions & 0 deletions src/render/direct3d/SDL_render_d3d.c
Expand Up @@ -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 &&
Expand Down Expand Up @@ -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);
}
Expand Down
8 changes: 8 additions & 0 deletions src/render/opengl/SDL_render_gl.c
Expand Up @@ -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;
}

Expand Down
8 changes: 8 additions & 0 deletions src/render/opengles/SDL_render_gles.c
Expand Up @@ -815,9 +815,17 @@ GLES_RenderClear(SDL_Renderer * renderer)
(GLfloat) renderer->g * inv255f,
(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;
}

Expand Down
8 changes: 8 additions & 0 deletions src/render/opengles2/SDL_render_gles2.c
Expand Up @@ -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;
}

Expand Down

0 comments on commit 77305d4

Please sign in to comment.