Class GLLoader

java.lang.Object
overrungl.opengl.GLLoader

public final class GLLoader extends Object
This class must be used before any OpenGL function is called. It has the following responsibilities:
  • Loads the OpenGL native library into the JVM process.
  • Creates instances of GLCapabilities classes. A GLCapabilities instance contains flags for functionality that is available in an OpenGL context. Internally, it also contains function pointers that are only valid in that specific OpenGL context.
  • Maintains thread-local state for GLCapabilities instances, corresponding to OpenGL contexts that are current in those threads.

GLCapabilities creation

Instances of GLCapabilities can be created with the load method. An OpenGL context must be current in the current thread before it is called. Calling this method is expensive, so the GLCapabilities instance should be associated with the OpenGL context and reused as necessary.

Thread-local state

Before a function for a given OpenGL context can be called, the corresponding GLCapabilities instance must be passed to the setCapabilities(overrungl.opengl.GLCapabilities) method. The user is also responsible for clearing the current GLCapabilities instance when the context is destroyed or made current in another thread.

Note that the load method implicitly calls setCapabilities(overrungl.opengl.GLCapabilities) with the newly created instance.

Since:
0.1.0
Author:
squid233
See Also:
  • Constructor Details

    • GLLoader

      public GLLoader()
  • Method Details

    • setCapabilities

      public static void setCapabilities(@Nullable @Nullable GLCapabilities caps)
      Sets the GLCapabilities of the OpenGL context that is current in the current thread.

      This GLCapabilities instance will be used by any OpenGL call in the current thread, until setCapabilities is called again with a different value.

    • getCapabilities

      public static GLCapabilities getCapabilities()
      Returns the GLCapabilities of the OpenGL context that is current in the current thread..
      Returns:
      the GLCapabilities of the OpenGL context that is current in the current thread
      Throws:
      IllegalStateException - if setCapabilities(overrungl.opengl.GLCapabilities) has never been called in the current thread or was last called with a null value
    • getExtCapabilities

      public static GLExtCaps getExtCapabilities()
      Returns the current GLExtCaps of the OpenGL context in the current thread.

      This is equivalent to the following code:

      
       getCapabilities().ext()
       
      Returns:
      the current GLExtCaps of the OpenGL context in the current thread
      Throws:
      IllegalStateException - if setCapabilities(overrungl.opengl.GLCapabilities) has never been called in the current thread or was last called with a null value
    • load

      @Nullable public static @Nullable GLCapabilities load(GLLoadFunc load)
      Loads OpenGL compatibility profile with the given load function.
      Parameters:
      load - the load function
      Returns:
      the OpenGL capabilities, or null if no OpenGL context found.
    • load

      @Nullable public static @Nullable GLCapabilities load(GLLoadFunc load, boolean forwardCompatible)
      Loads OpenGL with the given load function.
      Parameters:
      load - the load function
      forwardCompatible - If true, only loads core profile functions.
      Returns:
      the OpenGL capabilities, or null if no OpenGL context found.
    • check

      @NotNull @Contract(value="null -> fail; !null -> param1", pure=true) public static @NotNull MethodHandle check(@Nullable @Nullable MethodHandle handle) throws IllegalStateException
      Checks whether the given GL function is available in this context. This method raises an IllegalStateException rather than a NullPointerException.
      Parameters:
      handle - the method handle to be checked.
      Returns:
      handle
      Throws:
      IllegalStateException - if handle is null.
    • makeVersion

      public static int makeVersion(int major, int minor)
      Pack the version into an integer.
      Parameters:
      major - the major version
      minor - the minor version
      Returns:
      the packed version
    • versionMajor

      public static int versionMajor(int version)
      Returns the major version.
      Parameters:
      version - the packed version
      Returns:
      the major version
    • versionMinor

      public static int versionMinor(int version)
      Returns the minor version.
      Parameters:
      version - the packed version
      Returns:
      the minor version