Class GL
- Loads the OpenGL native library into the JVM process.
- Creates instances of
GLCapabilities
classes. AGLCapabilities
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.
Library lifecycle
The OpenGL library is loaded automatically when this class is initialized. Set the Configuration.OPENGL_EXPLICIT_INIT
option to override this
behavior. Manual loading/unloading can be achieved with the create()
and destroy()
functions. The name of the library loaded can be overridden
with the Configuration.OPENGL_LIBRARY_NAME
option. The maximum OpenGL version loaded can be set with the Configuration.OPENGL_MAXVERSION
option. This can be useful to ensure that no functionality above a specific version is used during development.
GLCapabilities creation
Instances of GLCapabilities
can be created with the createCapabilities()
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(org.lwjgl.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 createCapabilities()
method implicitly calls setCapabilities(org.lwjgl.opengl.GLCapabilities)
with the newly created instance.
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
create()
Loads the OpenGL native library, using the default library name.static void
Loads the OpenGL native library, using the specified library name.static void
create
(FunctionProvider functionProvider) Initializes OpenGL with the specifiedFunctionProvider
.static GLCapabilities
Creates a newGLCapabilities
instance for the OpenGL context that is current in the current thread.static GLCapabilities
createCapabilities
(boolean forwardCompatible) Creates a newGLCapabilities
instance for the OpenGL context that is current in the current thread.static GLCapabilities
createCapabilities
(boolean forwardCompatible, IntFunction<PointerBuffer> bufferFactory) Creates a newGLCapabilities
instance for the OpenGL context that is current in the current thread.static GLCapabilities
createCapabilities
(IntFunction<PointerBuffer> bufferFactory) Creates a newGLCapabilities
instance for the OpenGL context that is current in the current thread.static GLXCapabilities
createCapabilitiesGLX
(long display) Creates aGLXCapabilities
instance for the default screen of the specified X connection.static GLXCapabilities
createCapabilitiesGLX
(long display, int screen) Creates aGLXCapabilities
instance for the specified screen of the specified X connection.static WGLCapabilities
Creates aWGLCapabilities
instance for the context that is current in the current thread.static void
destroy()
Unloads the OpenGL native library.static GLCapabilities
Returns theGLCapabilities
of the OpenGL context that is current in the current thread.static GLXCapabilities
Returns the GLX capabilities.static WGLCapabilities
Returns the WGL capabilities.static FunctionProvider
Returns theFunctionProvider
for the OpenGL native library.static void
Sets theGLCapabilities
of the OpenGL context that is current in the current thread.
-
Method Details
-
create
public static void create()Loads the OpenGL native library, using the default library name. -
create
Loads the OpenGL native library, using the specified library name.- Parameters:
libName
- the native library name
-
create
Initializes OpenGL with the specifiedFunctionProvider
. This method can be used to implement custom OpenGL library loading.- Parameters:
functionProvider
- the provider of OpenGL function addresses
-
destroy
public static void destroy()Unloads the OpenGL native library. -
getFunctionProvider
Returns theFunctionProvider
for the OpenGL native library. -
setCapabilities
Sets theGLCapabilities
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, untilsetCapabilities
is called again with a different value. -
getCapabilities
Returns theGLCapabilities
of the OpenGL context that is current in the current thread.- Throws:
IllegalStateException
- ifsetCapabilities(org.lwjgl.opengl.GLCapabilities)
has never been called in the current thread or was last called with anull
value
-
getCapabilitiesWGL
Returns the WGL capabilities.This method may only be used on Windows.
-
getCapabilitiesGLX
Returns the GLX capabilities.This method may only be used on Linux.
-
createCapabilities
Creates a newGLCapabilities
instance for the OpenGL context that is current in the current thread.Depending on the current context, the instance returned may or may not contain the deprecated functionality removed since OpenGL version 3.1.
This method calls
setCapabilities(GLCapabilities)
with the new instance before returning.- Returns:
- the GLCapabilities instance
-
createCapabilities
Creates a newGLCapabilities
instance for the OpenGL context that is current in the current thread.Depending on the current context, the instance returned may or may not contain the deprecated functionality removed since OpenGL version 3.1.
This method calls
setCapabilities(GLCapabilities)
with the new instance before returning.- Parameters:
bufferFactory
- a function that allocates aPointerBuffer
given a size. The buffer must be filled with zeroes. Ifnull
, LWJGL will allocate a GC-managed buffer internally.- Returns:
- the GLCapabilities instance
-
createCapabilities
Creates a newGLCapabilities
instance for the OpenGL context that is current in the current thread.Depending on the current context, the instance returned may or may not contain the deprecated functionality removed since OpenGL version 3.1. The
forwardCompatible
flag will force LWJGL to not load the deprecated functions, even if the current context exposes them.This method calls
setCapabilities(GLCapabilities)
with the new instance before returning.- Parameters:
forwardCompatible
- if true, LWJGL will create forward compatible capabilities- Returns:
- the GLCapabilities instance
-
createCapabilities
public static GLCapabilities createCapabilities(boolean forwardCompatible, @Nullable IntFunction<PointerBuffer> bufferFactory) Creates a newGLCapabilities
instance for the OpenGL context that is current in the current thread.Depending on the current context, the instance returned may or may not contain the deprecated functionality removed since OpenGL version 3.1. The
forwardCompatible
flag will force LWJGL to not load the deprecated functions, even if the current context exposes them.This method calls
setCapabilities(GLCapabilities)
with the new instance before returning.- Parameters:
forwardCompatible
- if true, LWJGL will create forward compatible capabilitiesbufferFactory
- a function that allocates aPointerBuffer
given a size. Ifnull
, LWJGL will allocate a GC-managed buffer internally.- Returns:
- the GLCapabilities instance
-
createCapabilitiesWGL
Creates aWGLCapabilities
instance for the context that is current in the current thread.This method may only be used on Windows.
-
createCapabilitiesGLX
Creates aGLXCapabilities
instance for the default screen of the specified X connection.This method may only be used on Linux.
- Parameters:
display
- the X connection handle (DISPLAY
)
-
createCapabilitiesGLX
Creates aGLXCapabilities
instance for the specified screen of the specified X connection.This method may only be used on Linux.
- Parameters:
display
- the X connection handle (DISPLAY
)screen
- the screen index
-