Class GLContext

java.lang.Object
org.lwjgl.opengl.GLContext

public final class GLContext extends Object

Manages GL contexts. Before any rendering is done by a LWJGL system, a call should be made to GLContext.useContext() with a context. This will ensure that GLContext has an accurate reflection of the current context's capabilities and function pointers.

This class is thread-safe in the sense that multiple threads can safely call all public methods. The class is also thread-aware in the sense that it tracks a per-thread current context (including capabilities and function pointers). That way, multiple threads can have multiple contexts current and render to them concurrently.

Version:
$Revision$ $Id$
Author:
elias_naur invalid input: '<'elias_naur@users.sourceforge.net>
  • Constructor Details

    • GLContext

      public GLContext()
  • Method Details

    • getCapabilities

      public static ContextCapabilities getCapabilities()
      Get the current capabilities instance. It contains the flags used to test for support of a particular extension.
      Returns:
      The current capabilities instance.
    • useContext

      public static void useContext(Object context) throws LWJGLException
      Makes a GL context the current LWJGL context by loading GL function pointers. The context must be current before a call to this method! Instead it simply ensures that the current context is reflected accurately by GLContext's extension caps and function pointers. Use useContext(null) when no context is active.

      If the context is the same as last time, then this is a no-op.

      If the context has not been encountered before it will be fully initialized from scratch. Otherwise a cached set of caps and function pointers will be used.

      The reference to the context is held in a weak reference; therefore if no strong reference exists to the GL context it will automatically be forgotten by the VM at an indeterminate point in the future, freeing up a little RAM.

      Parameters:
      context - The context object, which uniquely identifies a GL context. If context is null, the native stubs are unloaded.
      Throws:
      LWJGLException - if context non-null, and the gl library can't be loaded or the basic GL11 functions can't be loaded
    • useContext

      public static void useContext(Object context, boolean forwardCompatible) throws LWJGLException
      Makes a GL context the current LWJGL context by loading GL function pointers. The context must be current before a call to this method! Instead it simply ensures that the current context is reflected accurately by GLContext's extension caps and function pointers. Use useContext(null) when no context is active.

      If the context is the same as last time, then this is a no-op.

      If the context has not been encountered before it will be fully initialized from scratch. Otherwise a cached set of caps and function pointers will be used.

      The reference to the context is held in a weak reference; therefore if no strong reference exists to the GL context it will automatically be forgotten by the VM at an indeterminate point in the future, freeing up a little RAM.

      If forwardCompatible is true, function pointers of deprecated GL11-GL21 functionality will not be loaded. Calling a deprecated function using the specified context will result in an IllegalStateException.

      Parameters:
      context - The context object, which uniquely identifies a GL context. If context is null, the native stubs are unloaded.
      forwardCompatible - If the context is a forward compatible context (does not expose deprecated functionality, see XGL_ARB_create_context)
      Throws:
      LWJGLException - if context non-null, and the gl library can't be loaded or the basic GL11 functions can't be loaded
    • loadOpenGLLibrary

      public static void loadOpenGLLibrary() throws LWJGLException
      If the OpenGL reference count is 0, the library is loaded. The reference count is then incremented.
      Throws:
      LWJGLException
    • unloadOpenGLLibrary

      public static void unloadOpenGLLibrary()
      The OpenGL library reference count is decremented, and if it reaches 0, the library is unloaded.