Context switching / Texture reloading

Hi everyone,

I’ve been thinking about how to best handle the issue of texture
reloading across platforms, when/if the graphic context changes. My
interest is motivated by the fact that I’ve seen this happen in
Android after leaving the app and coming back to it, and I’ve done
some research to see if this can happen in other platforms as well…

It looks like in desktop system this is not a problem… in Direct3D
9, textures are automatically managed:
Desktop OpenGL does the same (at least from what I’ve read online), it
keeps copies of the textures in system memory.

The problem then can arise in GL ES platforms. I’m not sure if iOS
devices have this issue and if it’s been handled somehow already, can
anyone let me know how/if it’s handled?

So, going back to Android, I’d like to know if this is something SDL
should be concerned with…alternatives to the problem seem to be (in
order of preference):

  • Changing to use GLSurfaceView instead of
    SurfaceView (according to this thread
    it provides context preservation on hardware that supports it, the
    issue would remain in hardware that doesn’t! and potentially in other
    platforms that suffer from the same ES context switching)
  • Sending a message when the context changes (which is kinda what we
    are doing now, as the activity sends SDL_WINDOWEVENT_MINIMIZED and
    SDL_WINDOWEVENT_RESTORED when pause/restore happens)
  • Adding a SDL_CheckTexture function that would return true in every
    backend except GL ES, and in GL ES would check the texture’s renderer
    context vs the current context, or something along those lines…
  • A combination of the above or something else entirely

I think the solution will depend on what the iOS backend does or can
potentially do. Ideally if we can wrap this issues inside the
SDLActivity, and only fire a SDL_CONTEXT_CHANGED sort of event when
the hardware can’t handle context switching, that would be best IMO.

Thanks for any feedback!–

Hi myself, replying to my own message… It appears that out of all the supported platforms this is only an issue for Android, so I’ll look into a solution for this platform only!------------------------
Gabriel Jacobo