Context Switching

Overview

This short tutorial will teach you the basics of context handling and switching for multithreaded applications.

Context Operations

Simply calling:

  Display.releaseContext();

will release the current context from this thread allowing another thread to make the context current to the other thread. Making the context current to this new thread is simple:

try {
  Display.makeCurrent();
} catch (LWJGLException e) { }

will cause the current thread to have ownership of the context, and thus GL calls can be made from that new thread.

Warning: Making GL calls when a context has been released but not yet owned causes a NPE to be thrown.

Usage examples

One simple example of using this mechanism is if the renderer of the game is on a different thread than what makes the display; releasing the context after display creation and making it current to the renderer thread before the rendering thread starts is just one usage pattern.

 
lwjgl/tutorials/changingcontexts.txt · Last modified: 2007/07/07 00:38 (external edit)
 
Recent changes RSS feed Creative Commons License Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki