wiiu/render: Fix clip rect state

This commit is contained in:
GaryOderNichts 2023-04-16 16:04:03 +02:00 committed by Dave Murphy
parent 746622ced7
commit 97bedb9f40
No known key found for this signature in database
GPG Key ID: F7FD5492264BB9D0
3 changed files with 12 additions and 15 deletions

View File

@ -194,8 +194,6 @@ int WIIU_SDL_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
/* Wait for the texture rendering to finish */
WIIU_TextureCheckWaitRendering(data, tdata);
data->drawState.viewportDirty = SDL_TRUE;
/* Update context state */
GX2SetColorBuffer(&tdata->cbuf, GX2_RENDER_TARGET_0);

View File

@ -78,7 +78,6 @@ struct WIIU_DrawState
int drawableWidth, drawableHeight;
float projectionMatrix[4][4];
SDL_bool cliprectEnabledDirty;
SDL_bool cliprectEnabled;
SDL_bool cliprectDirty;
SDL_Rect cliprect;

View File

@ -286,24 +286,19 @@ static int WIIU_SDL_SetDrawState(WIIU_RenderData * data, const SDL_RenderCommand
data->drawState.viewportDirty = SDL_FALSE;
}
if (data->drawState.cliprectEnabledDirty || data->drawState.cliprectDirty) {
if (data->drawState.cliprectDirty) {
SDL_Rect scissor;
const SDL_Rect *viewport = &data->drawState.viewport;
const SDL_Rect *rect = &data->drawState.cliprect;
if (data->drawState.cliprectEnabled) {
// make sure scissor is never larger than the colorbuffer to prevent memory corruption
scissor.x = SDL_clamp(rect->x, 0, viewport->w);
scissor.y = SDL_clamp(rect->y, 0, viewport->h);
scissor.w = SDL_clamp(rect->w, 0, viewport->w);
scissor.h = SDL_clamp(rect->h, 0, viewport->h);
} else {
scissor = *viewport;
}
// make sure scissor is never larger than the colorbuffer to prevent memory corruption
scissor.x = SDL_clamp(rect->x, 0, viewport->w);
scissor.y = SDL_clamp(rect->y, 0, viewport->h);
scissor.w = SDL_clamp(rect->w, 0, viewport->w);
scissor.h = SDL_clamp(rect->h, 0, viewport->h);
GX2SetScissor(scissor.x, scissor.y, scissor.w, scissor.h);
data->drawState.cliprectEnabledDirty = SDL_FALSE;
data->drawState.cliprectDirty = SDL_FALSE;
}
@ -394,7 +389,12 @@ int WIIU_SDL_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, vo
const SDL_Rect *rect = &cmd->data.cliprect.rect;
if (data->drawState.cliprectEnabled != cmd->data.cliprect.enabled) {
data->drawState.cliprectEnabled = cmd->data.cliprect.enabled;
data->drawState.cliprectEnabledDirty = SDL_TRUE;
data->drawState.cliprectDirty = SDL_TRUE;
}
if (!data->drawState.cliprectEnabled) {
/* If the clip rect is disabled, then the scissor rect should be the whole viewport */
rect = &data->drawState.viewport;
}
if (SDL_memcmp(&data->drawState.cliprect, rect, sizeof (SDL_Rect)) != 0) {