Class GLContext
- All Implemented Interfaces:
Proxy
- Direct Known Subclasses:
GLContext.GLContextImpl
GdkGLContext
is an object representing a platform-specific
OpenGL draw context.
GdkGLContext
s are created for a surface using
Surface.createGlContext()
, and the context will match
the characteristics of the surface.
A GdkGLContext
is not tied to any particular normal framebuffer.
For instance, it cannot draw to the surface back buffer. The GDK
repaint system is in full control of the painting to that. Instead,
you can create render buffers or textures and use Gdk.cairoDrawFromGl(org.freedesktop.cairo.Context, org.gnome.gdk.Surface, int, int, int, int, int, int, int)
in the draw function of your widget to draw them. Then GDK will handle
the integration of your rendering with that of other widgets.
Support for GdkGLContext
is platform-specific and context creation
can fail, returning null
context.
A GdkGLContext
has to be made "current" in order to start using
it, otherwise any OpenGL call will be ignored.
Creating a new OpenGL context
In order to create a new GdkGLContext
instance you need a GdkSurface
,
which you typically get during the realize call of a widget.
A GdkGLContext
is not realized until either makeCurrent()
or realize()
is called. It is possible to specify
details of the GL context like the OpenGL version to be used, or whether
the GL context should have extra state validation enabled after calling
Surface.createGlContext()
by calling realize()
.
If the realization fails you have the option to change the settings of
the GdkGLContext
and try again.
Using a GdkGLContext
You will need to make the GdkGLContext
the current context before issuing
OpenGL calls; the system sends OpenGL commands to whichever context is current.
It is possible to have multiple contexts, so you always need to ensure that
the one which you want to draw with is the current one before issuing commands:
gdk_gl_context_make_current (context);
You can now perform your drawing using OpenGL commands.
You can check which GdkGLContext
is the current one by using
getCurrent()
; you can also unset any GdkGLContext
that is currently set by calling clearCurrent()
.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
GLContext.Builder<B extends GLContext.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static class
The GLContextImpl type represents a native instance of the abstract GLContext class.Nested classes/interfaces inherited from class org.gnome.gdk.DrawContext
DrawContext.DrawContextImpl
Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
-
Constructor Summary
ConstructorDescriptionGLContext
(MemorySegment address) Create a GLContext proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected GLContext
asParent()
Returns this instance as if it were its parent type.static GLContext.Builder
<? extends GLContext.Builder> builder()
AGLContext.Builder
object constructs aGLContext
with the specified properties.static void
Clears the currentGdkGLContext
.Gets the allowed APIs set via gdk_gl_context_set_allowed_apis().getApi()
Gets the API currently in use.static GLContext
Retrieves the currentGdkGLContext
.boolean
Retrieves whether the context is doing extra validations and runtime checking.Retrieves the display the this GLContext is created forboolean
Retrieves whether the context is forward-compatible.void
getRequiredVersion
(@Nullable Out<Integer> major, @Nullable Out<Integer> minor) Retrieves required OpenGL version set as a requirement for the this GLContext realization.Deprecated.Retrieves the surface used by the this GLContext.static Type
getType()
Get the GType of the GLContext classboolean
getUseEs()
Checks whether the this GLContext is using an OpenGL or OpenGL ES profile.void
getVersion
(Out<Integer> major, Out<Integer> minor) Retrieves the OpenGL version of the this GLContext.boolean
isLegacy()
Whether theGdkGLContext
is in legacy mode or not.boolean
Checks if the two GL contexts can share resources.void
Makes the this GLContext the current one.boolean
realize()
Realizes the givenGdkGLContext
.void
setAllowedApis
(Set<GLAPI> apis) Sets the allowed APIs.void
setAllowedApis
(GLAPI... apis) Sets the allowed APIs.void
setDebugEnabled
(boolean enabled) Sets whether theGdkGLContext
should perform extra validations and runtime checking.void
setForwardCompatible
(boolean compatible) Sets whether theGdkGLContext
should be forward-compatible.void
setRequiredVersion
(int major, int minor) Sets the major and minor version of OpenGL to request.void
setUseEs
(int useEs) Requests that GDK create an OpenGL ES context instead of an OpenGL one.Methods inherited from class org.gnome.gdk.DrawContext
beginFrame, endFrame, getFrameRegion, isInFrame
Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getMemoryLayout, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newInstance, newInstance, newv, notify_, notify_, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
GLContext
Create a GLContext proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()
doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName()
. This will call the native function pointer of this virtual method in the typeclass of the parent type.- Overrides:
asParent
in classDrawContext
-
clearCurrent
public static void clearCurrent()Clears the currentGdkGLContext
.Any OpenGL call after this function returns will be ignored until
makeCurrent()
is called. -
getCurrent
Retrieves the currentGdkGLContext
.- Returns:
- the current
GdkGLContext
-
getAllowedApis
-
getApi
-
getDebugEnabled
public boolean getDebugEnabled()Retrieves whether the context is doing extra validations and runtime checking.- Returns:
true
if debugging is enabled
-
getDisplay
Retrieves the display the this GLContext is created for- Overrides:
getDisplay
in classDrawContext
- Returns:
- a
GdkDisplay
-
getForwardCompatible
public boolean getForwardCompatible()Retrieves whether the context is forward-compatible.- Returns:
true
if the context should be forward-compatible
-
getRequiredVersion
public void getRequiredVersion(@Nullable @Nullable Out<Integer> major, @Nullable @Nullable Out<Integer> minor) Retrieves required OpenGL version set as a requirement for the this GLContext realization. It will not change even if a greater OpenGL version is supported and used after the this GLContext is realized. SeegetVersion(io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>)
for the real version in use.- Parameters:
major
- return location for the major version to requestminor
- return location for the minor version to request
-
getSurface
Retrieves the surface used by the this GLContext.- Overrides:
getSurface
in classDrawContext
- Returns:
- a
GdkSurface
-
getUseEs
public boolean getUseEs()Checks whether the this GLContext is using an OpenGL or OpenGL ES profile.- Returns:
true
if theGdkGLContext
is using an OpenGL ES profile;false
if other profile is in use of if the this GLContext has not yet been realized.
-
getVersion
-
isLegacy
public boolean isLegacy()Whether theGdkGLContext
is in legacy mode or not.The
GdkGLContext
must be realized before calling this function.When realizing a GL context, GDK will try to use the OpenGL 3.2 core profile; this profile removes all the OpenGL API that was deprecated prior to the 3.2 version of the specification. If the realization is successful, this function will return
false
.If the underlying OpenGL implementation does not support core profiles, GDK will fall back to a pre-3.2 compatibility profile, and this function will return
true
.You can use the value returned by this function to decide which kind of OpenGL API to use, or whether to do extension discovery, or what kind of shader programs to load.
- Returns:
true
if the GL context is in legacy mode
-
makeCurrent
public void makeCurrent()Makes the this GLContext the current one. -
realize
Realizes the givenGdkGLContext
.It is safe to call this function on a realized
GdkGLContext
.- Returns:
true
if the context is realized- Throws:
GErrorException
- seeGError
-
setAllowedApis
Sets the allowed APIs. When gdk_gl_context_realize() is called, only the allowed APIs will be tried. If you set this to 0, realizing will always fail.If you set it on a realized context, the property will not have any effect. It is only relevant during gdk_gl_context_realize().
By default, all APIs are allowed.
- Parameters:
apis
- the allowed APIs
-
setAllowedApis
Sets the allowed APIs. When gdk_gl_context_realize() is called, only the allowed APIs will be tried. If you set this to 0, realizing will always fail.If you set it on a realized context, the property will not have any effect. It is only relevant during gdk_gl_context_realize().
By default, all APIs are allowed.
- Parameters:
apis
- the allowed APIs
-
setDebugEnabled
public void setDebugEnabled(boolean enabled) Sets whether theGdkGLContext
should perform extra validations and runtime checking.This is useful during development, but has additional overhead.
The
GdkGLContext
must not be realized or made current prior to calling this function.- Parameters:
enabled
- whether to enable debugging in the context
-
setForwardCompatible
public void setForwardCompatible(boolean compatible) Sets whether theGdkGLContext
should be forward-compatible.Forward-compatible contexts must not support OpenGL functionality that has been marked as deprecated in the requested version; non-forward compatible contexts, on the other hand, must support both deprecated and non deprecated functionality.
The
GdkGLContext
must not be realized or made current prior to calling this function.- Parameters:
compatible
- whether the context should be forward-compatible
-
setRequiredVersion
public void setRequiredVersion(int major, int minor) Sets the major and minor version of OpenGL to request.Setting
major
andminor
to zero will use the default values.Setting
major
andminor
lower than the minimum versions required by GTK will result in the context choosing the minimum version.The this GLContext must not be realized or made current prior to calling this function.
- Parameters:
major
- the major version to requestminor
- the minor version to request
-
setUseEs
public void setUseEs(int useEs) Requests that GDK create an OpenGL ES context instead of an OpenGL one.Not all platforms support OpenGL ES.
The this GLContext must not have been realized.
By default, GDK will attempt to automatically detect whether the underlying GL implementation is OpenGL or OpenGL ES once the this GLContext is realized.
You should check the return value of
getUseEs()
after callingrealize()
to decide whether to use the OpenGL or OpenGL ES API, extensions, or shaders.- Parameters:
useEs
- whether the context should use OpenGL ES instead of OpenGL, or -1 to allow auto-detection
-
builder
AGLContext.Builder
object constructs aGLContext
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withGLContext.Builder.build()
.
-
isShared(org.gnome.gdk.GLContext)
to check if contexts can be shared.