GLContextProtocol
public protocol GLContextProtocol : DrawContextProtocol
The GLContextProtocol protocol exposes the methods and properties of an underlying GdkGLContext instance.
The default implementation of these can be found in the protocol extension below.
For a concrete class that implements these methods and properties, see GLContext.
Alternatively, use GLContextRef as a lighweight, unowned reference if you already have an instance you just want to use.
GdkGLContext is an object representing a platform-specific
OpenGL draw context.
GdkGLContexts are created for a surface using
[methodGdk.Surface.create_gl_context], and the context will match
the 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 [funccairo_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 nil 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 [methodGdk.GLContext.make_current]
or [methodGdk.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
[methodGdk.Surface.create_gl_context] by calling [methodGdk.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:
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
[funcGdk.GLContext.get_current]; you can also unset any GdkGLContext
that is currently set by calling [funcGdk.GLContext.clear_current].
-
Untyped pointer to the underlying
GdkGLContextinstance.Declaration
Swift
var ptr: UnsafeMutableRawPointer! { get } -
gl_context_ptrDefault implementationTyped pointer to the underlying
GdkGLContextinstance.Default Implementation
Return the stored, untyped pointer as a typed pointer to the
GdkGLContextinstance.Declaration
Swift
var gl_context_ptr: UnsafeMutablePointer<GdkGLContext>! { get } -
Required Initialiser for types conforming to
GLContextProtocolDeclaration
Swift
init(raw: UnsafeMutableRawPointer)
-
bind(property:Extension methodto: _: flags: transformFrom: transformTo: ) Bind a
GLContextPropertyNamesource property to a given target object.Declaration
Swift
@discardableResult @inlinable func bind<Q, T>(property source_property: GLContextPropertyName, to target: T, _ target_property: Q, flags f: BindingFlags = .default, transformFrom transform_from: @escaping GLibObject.ValueTransformer = { $0.transform(destValue: $1) }, transformTo transform_to: @escaping GLibObject.ValueTransformer = { $0.transform(destValue: $1) }) -> BindingRef! where Q : PropertyNameProtocol, T : ObjectProtocolParameters
source_propertythe source property to bind
targetthe target object to bind to
target_propertythe target property to bind to
flagsthe flags to pass to the
Bindingtransform_fromValueTransformerto use for forward transformationtransform_toValueTransformerto use for backwards transformationReturn Value
binding reference or
nilin case of an error -
get(property:Extension method) Get the value of a GLContext property
Declaration
Swift
@inlinable func get(property: GLContextPropertyName) -> GLibObject.ValueParameters
propertythe property to get the value for
Return Value
the value of the named property
-
set(property:Extension methodvalue: ) Set the value of a GLContext property. Note that this will only have an effect on properties that are writable and not construct-only!
Declaration
Swift
@inlinable func set(property: GLContextPropertyName, value v: GLibObject.Value)Parameters
propertythe property to get the value for
Return Value
the value of the named property
-
getDebugEnabled()Extension methodRetrieves whether the context is doing extra validations and runtime checking.
See [method
Gdk.GLContext.set_debug_enabled].Declaration
Swift
@inlinable func getDebugEnabled() -> Bool -
getDisplay()Extension methodRetrieves the display the
contextis created forDeclaration
Swift
@inlinable func getDisplay() -> DisplayRef! -
getForwardCompatible()Extension methodRetrieves whether the context is forward-compatible.
See [method
Gdk.GLContext.set_forward_compatible].Declaration
Swift
@inlinable func getForwardCompatible() -> Bool -
getRequiredVersion(major:Extension methodminor: ) Retrieves required OpenGL version.
See [method
Gdk.GLContext.set_required_version].Declaration
Swift
@inlinable func getRequiredVersion(major: UnsafeMutablePointer<gint>?, minor: UnsafeMutablePointer<gint>?) -
getSharedContext()Extension methodRetrieves the
GdkGLContextthat thiscontextshare data with.Declaration
Swift
@inlinable func getSharedContext() -> GLContextRef! -
getSurface()Extension methodRetrieves the surface used by the
context.Declaration
Swift
@inlinable func getSurface() -> SurfaceRef! -
getUseEs()Extension methodChecks whether the
contextis using an OpenGL or OpenGL ES profile.Declaration
Swift
@inlinable func getUseEs() -> Bool -
getVersion(major:Extension methodminor: ) Retrieves the OpenGL version of the
context.The
contextmust be realized prior to calling this function.Declaration
Swift
@inlinable func getVersion(major: UnsafeMutablePointer<gint>!, minor: UnsafeMutablePointer<gint>!) -
makeCurrent()Extension methodMakes the
contextthe current one.Declaration
Swift
@inlinable func makeCurrent() -
realize()Extension methodRealizes the given
GdkGLContext.It is safe to call this function on a realized
GdkGLContext.Declaration
Swift
@inlinable func realize() throws -> Bool -
setDebug(enabled:Extension method) Sets whether the
GdkGLContextshould perform extra validations and runtime checking.This is useful during development, but has additional overhead.
The
GdkGLContextmust not be realized or made current prior to calling this function.Declaration
Swift
@inlinable func setDebug(enabled: Bool) -
setForward(compatible:Extension method) Sets whether the
GdkGLContextshould 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
GdkGLContextmust not be realized or made current prior to calling this function.Declaration
Swift
@inlinable func setForward(compatible: Bool) -
setRequiredVersion(major:Extension methodminor: ) Sets the major and minor version of OpenGL to request.
Setting
majorandminorto zero will use the default values.The
GdkGLContextmust not be realized or made current prior to calling this function.Declaration
Swift
@inlinable func setRequiredVersion(major: Int, minor: Int) -
set(useEs:Extension method) Requests that GDK create an OpenGL ES context instead of an OpenGL one.
Not all platforms support OpenGL ES.
The
contextmust not have been realized.By default, GDK will attempt to automatically detect whether the underlying GL implementation is OpenGL or OpenGL ES once the
contextis realized.You should check the return value of [method
Gdk.GLContext.get_use_es] after calling [methodGdk.GLContext.realize] to decide whether to use the OpenGL or OpenGL ES API, extensions, or shaders.Declaration
Swift
@inlinable func set(useEs: Int) -
debugEnabledExtension methodRetrieves whether the context is doing extra validations and runtime checking.
See [method
Gdk.GLContext.set_debug_enabled].Declaration
Swift
@inlinable var debugEnabled: Bool { get nonmutating set } -
displayExtension methodRetrieves the display the
contextis created forDeclaration
Swift
@inlinable var display: DisplayRef! { get } -
forwardCompatibleExtension methodRetrieves whether the context is forward-compatible.
See [method
Gdk.GLContext.set_forward_compatible].Declaration
Swift
@inlinable var forwardCompatible: Bool { get nonmutating set } -
isLegacyExtension methodWhether the
GdkGLContextis in legacy mode or not.The
GdkGLContextmust 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.
Declaration
Swift
@inlinable var isLegacy: Bool { get } -
sharedContextExtension methodRetrieves the
GdkGLContextthat thiscontextshare data with.Declaration
Swift
@inlinable var sharedContext: GLContextRef! { get } -
surfaceExtension methodRetrieves the surface used by the
context.Declaration
Swift
@inlinable var surface: SurfaceRef! { get } -
useEsExtension methodChecks whether the
contextis using an OpenGL or OpenGL ES profile.Declaration
Swift
@inlinable var useEs: Bool { get nonmutating set }
View on GitHub
Install in Dash
GLContextProtocol Protocol Reference