Package ch.bailu.gtk.gdk
Class GLContext
java.lang.Object
ch.bailu.gtk.type.Type
ch.bailu.gtk.type.Pointer
ch.bailu.gtk.gobject.Object
ch.bailu.gtk.gdk.DrawContext
ch.bailu.gtk.gdk.GLContext
- All Implemented Interfaces:
PointerInterface
`GdkGLContext` is an object representing a platform-specific
OpenGL draw context.
`GdkGLContext`s are created for a surface using
[method@Gdk.Surface.create_gl_context], 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 [func@cairo_draw_from_gl]
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 [method@Gdk.GLContext.make_current]
or [method@Gdk.GLContext.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
[method@Gdk.Surface.create_gl_context] by calling [method@Gdk.GLContext.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:
```c
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
[func@Gdk.GLContext.get_current]; you can also unset any `GdkGLContext`
that is currently set by calling [func@Gdk.GLContext.clear_current].
OpenGL draw context.
`GdkGLContext`s are created for a surface using
[method@Gdk.Surface.create_gl_context], 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 [func@cairo_draw_from_gl]
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 [method@Gdk.GLContext.make_current]
or [method@Gdk.GLContext.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
[method@Gdk.Surface.create_gl_context] by calling [method@Gdk.GLContext.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:
```c
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
[func@Gdk.GLContext.get_current]; you can also unset any `GdkGLContext`
that is currently set by calling [func@Gdk.GLContext.clear_current].
-
Nested Class Summary
Nested classes/interfaces inherited from class ch.bailu.gtk.gobject.Object
Object.OnBindingTransformFunc, Object.OnDestroyNotify, Object.OnDuplicateFunc, Object.OnNotify, Object.OnToggleNotify, Object.OnWeakNotify
-
Field Summary
Fields inherited from class ch.bailu.gtk.gobject.Object
SIGNAL_ON_NOTIFY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Clears the current `GdkGLContext`.int
Gets the allowed APIs set via gdk_gl_context_set_allowed_apis().int
getApi()
Gets the API currently in use.static ClassHandler
static GLContext
Retrieves the current `GdkGLContext`.boolean
Retrieves whether the context is doing extra validations and runtime checking.Retrieves the display the @context is created forboolean
Retrieves whether the context is forward-compatible.static int
static long
static TypeSystem.TypeSize
void
getRequiredVersion
(Int major, Int minor) Retrieves required OpenGL version set as a requirement for the @context
realization.Retrieves the surface used by the @context.static long
static TypeSystem.TypeSize
boolean
getUseEs()
Checks whether the @context is using an OpenGL or OpenGL ES profile.void
getVersion
(Int major, Int minor) Retrieves the OpenGL version of the @context.boolean
isLegacy()
Whether the `GdkGLContext` is in legacy mode or not.boolean
Checks if the two GL contexts can share resources.void
Makes the @context the current one.boolean
realize()
Realizes the given `GdkGLContext`.void
setAllowedApis
(int apis) Sets the allowed APIs.void
setDebugEnabled
(boolean enabled) Sets whether the `GdkGLContext` should perform extra validations and
runtime checking.void
setForwardCompatible
(boolean compatible) Sets whether the `GdkGLContext` should be forward-compatible.void
setRequiredVersion
(int major, int minor) Sets the major and minor version of OpenGL to request.void
setUseEs
(int use_es) Requests that GDK create an OpenGL ES context instead of an OpenGL one.Methods inherited from class ch.bailu.gtk.gdk.DrawContext
beginFrame, endFrame, getFrameRegion, isInFrame
Methods inherited from class ch.bailu.gtk.gobject.Object
addToggleRef, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, disconnect, disconnect, dupData, dupData, dupQdata, forceFloating, freezeNotify, get, get, getData, getData, getProperty, getProperty, getQdata, interfaceFindProperty, interfaceInstallProperty, isFloating, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, replaceData, replaceData, replaceQdata, runDispose, set, set, setData, setData, setDataFull, setDataFull, setProperty, setProperty, setQdata, setQdataFull, stealData, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref
Methods inherited from class ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Methods inherited from class ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Constructor Details
-
GLContext
-
-
Method Details
-
getClassHandler
-
getAllowedApis
public int getAllowedApis()Gets the allowed APIs set via gdk_gl_context_set_allowed_apis().- Returns:
- the allowed APIs
-
getApi
public int getApi()Gets the API currently in use.
If the renderer has not been realized yet, 0 is returned.- Returns:
- the currently used API
-
getDebugEnabled
public boolean getDebugEnabled()Retrieves whether the context is doing extra validations and runtime checking.
See [method@Gdk.GLContext.set_debug_enabled].- Returns:
- %TRUE if debugging is enabled
-
getDisplay
Retrieves the display the @context is created for- Overrides:
getDisplay
in classDrawContext
- Returns:
- a `GdkDisplay`
-
getForwardCompatible
public boolean getForwardCompatible()Retrieves whether the context is forward-compatible.
See [method@Gdk.GLContext.set_forward_compatible].- Returns:
- %TRUE if the context should be forward-compatible
-
getRequiredVersion
Retrieves required OpenGL version set as a requirement for the @context
realization. It will not change even if a greater OpenGL version is supported
and used after the @context is realized. See
[method@Gdk.GLContext.get_version] for the real version in use.
See [method@Gdk.GLContext.set_required_version].- 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 @context.- Overrides:
getSurface
in classDrawContext
- Returns:
- a `GdkSurface`
-
getUseEs
public boolean getUseEs()Checks whether the @context is using an OpenGL or OpenGL ES profile.- Returns:
- %TRUE if the `GdkGLContext` is using an OpenGL ES profile; %FALSE if other profile is in use of if the @context has not yet been realized.
-
getVersion
Retrieves the OpenGL version of the @context.
The @context must be realized prior to calling this function.
If the @context has never been made current, the version cannot
be known and it will return 0 for both @major and @minor.- Parameters:
major
- return location for the major versionminor
- return location for the minor version
-
isLegacy
public boolean isLegacy()Whether the `GdkGLContext` 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 @context the current one. -
realize
Realizes the given `GdkGLContext`.
It is safe to call this function on a realized `GdkGLContext`.- Returns:
- %TRUE if the context is realized
- Throws:
AllocationError
-
setAllowedApis
public void setAllowedApis(int apis) 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 the `GdkGLContext` 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 the `GdkGLContext` 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 and @minor to zero will use the default values.
Setting @major and @minor lower than the minimum versions required
by GTK will result in the context choosing the minimum version.
The @context 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 use_es) Requests that GDK create an OpenGL ES context instead of an OpenGL one.
Not all platforms support OpenGL ES.
The @context 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 @context
is realized.
You should check the return value of [method@Gdk.GLContext.get_use_es]
after calling [method@Gdk.GLContext.realize] to decide whether to use
the OpenGL or OpenGL ES API, extensions, or shaders.- Parameters:
use_es
- whether the context should use OpenGL ES instead of OpenGL, or -1 to allow auto-detection
-
clearCurrent
public static void clearCurrent()Clears the current `GdkGLContext`.
Any OpenGL call after this function returns will be ignored
until [method@Gdk.GLContext.make_current] is called. -
getCurrent
Retrieves the current `GdkGLContext`.- Returns:
- the current `GdkGLContext`
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-