Design.ContextLost - lidavidm/jsglet GitHub Wiki

Uses

Needs and Considerations

  • When context is restored, bring back OpenGL state
  • Need a way of recording what state was changed
  • Need a way to determine what resources to recreate
  • Let application override/augment this functionality (e.g. to display a pause screen)

Implementation

  • Each object that has OpenGL state/resources needs to register a context restored handler (in jsglet.common?)

    • This handler should restore/recreate OpenGL objects

    • Problem: object may depend on external resources such as images that may also need to be reloaded

      • Integrate with resource system?
  • Keep a stack of OpenGL state changes (similar to Pyglet's Group, but for permanent, global state changes)

    • Let applications push functions onto stack
    • On context restore, call each function
    • Have a 'push-and-call' method to make it convenient