GLContextRef
public struct GLContextRef : GLContextProtocol, GWeakCapturing
The GLContextRef
type acts as a lightweight Swift reference to an underlying GdkGLContext
instance.
It exposes methods that can operate on this data type through GLContextProtocol
conformance.
Use GLContextRef
only as an unowned
reference to an existing GdkGLContext
instance.
GdkGLContext
is an object representing the platform-specific
OpenGL drawing context.
GdkGLContexts
are created for a GdkWindow
using
gdk_window_create_gl_context()
, and the context will match
the GdkVisual
of the window.
A GdkGLContext
is not tied to any particular normal framebuffer.
For instance, it cannot draw to the GdkWindow
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_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, 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
GdkWindow
, which you typically get during the realize call
of a widget.
A GdkGLContext
is not realized until either gdk_gl_context_make_current()
,
or until it is realized using gdk_gl_context_realize()
. 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 gdk_window_create_gl_context()
by calling gdk_gl_context_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 Language Example):
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
gdk_gl_context_get_current()
; you can also unset any GdkGLContext
that is currently set by calling gdk_gl_context_clear_current()
.
-
Untyped pointer to the underlying `GdkGLContext` instance.
For type-safe access, use the generated, typed pointer
gl_context_ptr
property instead.Declaration
Swift
public let ptr: UnsafeMutableRawPointer!
-
Designated initialiser from the underlying
C
data typeDeclaration
Swift
@inlinable init(_ p: UnsafeMutablePointer<GdkGLContext>)
-
Designated initialiser from a constant pointer to the underlying
C
data typeDeclaration
Swift
@inlinable init(_ p: UnsafePointer<GdkGLContext>)
-
Conditional initialiser from an optional pointer to the underlying
C
data typeDeclaration
Swift
@inlinable init!(_ maybePointer: UnsafeMutablePointer<GdkGLContext>?)
-
Conditional initialiser from an optional, non-mutable pointer to the underlying
C
data typeDeclaration
Swift
@inlinable init!(_ maybePointer: UnsafePointer<GdkGLContext>?)
-
Conditional initialiser from an optional
gpointer
Declaration
Swift
@inlinable init!(gpointer g: gpointer?)
-
Conditional initialiser from an optional, non-mutable
gconstpointer
Declaration
Swift
@inlinable init!(gconstpointer g: gconstpointer?)
-
Reference intialiser for a related type that implements
GLContextProtocol
Declaration
Swift
@inlinable init<T>(_ other: T) where T : GLContextProtocol
-
This factory is syntactic sugar for setting weak pointers wrapped in
GWeak<T>
Declaration
Swift
@inlinable static func unowned<T>(_ other: T) -> GLContextRef where T : GLContextProtocol
-
Unsafe typed initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
GLContextProtocol
.Declaration
Swift
@inlinable init<T>(cPointer: UnsafeMutablePointer<T>)
-
Unsafe typed initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
GLContextProtocol
.Declaration
Swift
@inlinable init<T>(constPointer: UnsafePointer<T>)
-
Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
GLContextProtocol
.Declaration
Swift
@inlinable init(mutating raw: UnsafeRawPointer)
-
Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
GLContextProtocol
.Declaration
Swift
@inlinable init(raw: UnsafeMutableRawPointer)
-
Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
GLContextProtocol
.Declaration
Swift
@inlinable init(opaquePointer: OpaquePointer)
-
Retrieves the current
GdkGLContext
.Declaration
Swift
@inlinable static func getCurrent() -> GLContextRef!