Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create functions to save/restore render state #367

Closed
SDLBugzilla opened this issue Feb 10, 2021 · 3 comments · Fixed by #8616
Closed

Create functions to save/restore render state #367

SDLBugzilla opened this issue Feb 10, 2021 · 3 comments · Fixed by #8616
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

Reported in version: HG 2.1
Reported for operating system, platform: All, All

Comments on the original bug report:

On 2011-02-20 12:22:19 +0000, Sam Lantinga wrote:

It should be possible to use SDL rendering with native OpenGL or Direct3D.

This task is to create functions to save and restore render state so 2D rendering can be mixed with 3D rendering. e.g.

while (true) {
3D rendering...
SDL_RenderSaveState()
2D rendering...
SDL_RenderRestoreState()
3D present
}

We'll also need some test programs for this using the various native 3D APIs.

On 2013-05-21 09:34:48 +0000, Gabriel Jacobo wrote:

I've done a bit of this here: http://mdqinc.com/blog/2013/01/integrating-librocket-with-sdl-2/ where I do the "resetting" to a known state by drawing a point outside of the screen. I ended up building SDL_RenderGeometry out of that code to be able to integrate with SDL's shader management (there's another wishlist item!), but the idea still holds...

Basically I think a solution could be implemented with a SDL_RenderResetState function which can be called before the 2D functions, something like...

app specific 3D rendering setup...
3D rendering
SDL_RenderResetState()
2D rendering (using SDL_Render* functions)
2D/3D present

On 2013-05-21 23:57:56 +0000, Sam Lantinga wrote:

That seems like a decent approach to me. :)

@SDLBugzilla SDLBugzilla added the enhancement New feature or request label Feb 10, 2021
@1bsyl
Copy link
Contributor

1bsyl commented Jan 31, 2022

@slouken @icculus : with the batching SDL_Render, I wonder whether saving render state could be easily implemented:
SDL_RenderSaveState(): just do SDL_RendererFlush()
SDL_RenderRestoreState(): mark all internal variable '*_dirty' to '1'

@slouken slouken added this to the 3.0 milestone Sep 27, 2022
@icculus
Copy link
Collaborator

icculus commented Nov 4, 2023

Let's just add a function to say "I have invalidated the state" so it doesn't sound like they can save specific states off. Then this is simple enough we could probably even add it into SDL2.

@icculus
Copy link
Collaborator

icculus commented Nov 4, 2023

Actually, we can probably just make an explicit Flush make all state dirty, since you would only call this before using GL/D3D directly. Implicit flushes (changing render targets, presenting, etc) won't dirty all the state.

icculus added a commit to icculus/SDL that referenced this issue Nov 26, 2023
This uses the same `SDL_VerbNoun` format as the rest of SDL3, and also
adds stronger effort to invalidate cached state in the backend, so cooperation
improves with apps that are using lowlevel rendering APIs directly.

Fixes libsdl-org#367.
icculus added a commit to icculus/SDL that referenced this issue Nov 29, 2023
This uses the same `SDL_VerbNoun` format as the rest of SDL3, and also
adds stronger effort to invalidate cached state in the backend, so cooperation
improves with apps that are using lowlevel rendering APIs directly.

Fixes libsdl-org#367.
icculus added a commit that referenced this issue Nov 29, 2023
This uses the same `SDL_VerbNoun` format as the rest of SDL3, and also
adds stronger effort to invalidate cached state in the backend, so cooperation
improves with apps that are using lowlevel rendering APIs directly.

Fixes #367.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants