Skip to content

Commit

Permalink
Presenting while drawing to a render target should fail.
Browse files Browse the repository at this point in the history
People are adding present calls while rendering to render targets, not understanding that this doesn't make sense, and wondering why they get flicker on some systems. If there are programs that relied on the previous behavior we can add a hint to control this.

Fixes #12432
  • Loading branch information
slouken committed Mar 4, 2025
1 parent debbe1c commit 5d20bbf
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
3 changes: 1 addition & 2 deletions include/SDL3/SDL_render.h
Original file line number Diff line number Diff line change
Expand Up @@ -2385,8 +2385,7 @@ extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_RenderReadPixels(SDL_Renderer *ren
* should not be done; you are only required to change back the rendering
* target to default via `SDL_SetRenderTarget(renderer, NULL)` afterwards, as
* textures by themselves do not have a concept of backbuffers. Calling
* SDL_RenderPresent while rendering to a texture will still update the screen
* with any current drawing that has been done _to the window itself_.
* SDL_RenderPresent while rendering to a texture will fail.
*
* \param renderer the rendering context.
* \returns true on success or false on failure; call SDL_GetError() for more
Expand Down
9 changes: 2 additions & 7 deletions src/render/SDL_render.c
Original file line number Diff line number Diff line change
Expand Up @@ -5276,9 +5276,8 @@ bool SDL_RenderPresent(SDL_Renderer *renderer)

CHECK_RENDERER_MAGIC(renderer, false);

SDL_Texture *target = renderer->target;
if (target) {
SDL_SetRenderTarget(renderer, NULL);
if (renderer->target) {
return SDL_SetError("You can't present on a render target");
}

SDL_RenderLogicalPresentation(renderer);
Expand All @@ -5299,10 +5298,6 @@ bool SDL_RenderPresent(SDL_Renderer *renderer)
presented = false;
}

if (target) {
SDL_SetRenderTarget(renderer, target);
}

if (renderer->simulate_vsync ||
(!presented && renderer->wanted_vsync)) {
SDL_SimulateRenderVSync(renderer);
Expand Down

0 comments on commit 5d20bbf

Please sign in to comment.