GLContext
open class GLContext : DrawContext, GLContextProtocol
The GLContext
type acts as a reference-counted owner of an underlying GdkGLContext
instance.
It provides the methods that can operate on this data type through GLContextProtocol
conformance.
Use GLContext
as a strong reference or owner of a GdkGLContext
instance.
GdkGLContext
is an object representing a platform-specific
OpenGL draw context.
GdkGLContext
s 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
].
-
Designated initialiser from the underlying `C` data type.
This creates an instance without performing an unbalanced retain i.e., ownership is transferred to the
GLContext
instance.Declaration
Swift
@inlinable public init(_ op: UnsafeMutablePointer<GdkGLContext>)
Parameters
op
pointer to the underlying object
-
Designated initialiser from a constant pointer to the underlying
C
data type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theGLContext
instance.Declaration
Swift
@inlinable public init(_ op: UnsafePointer<GdkGLContext>)
Parameters
op
pointer to the underlying object
-
Optional initialiser from a non-mutating
gpointer
to the underlyingC
data type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theGLContext
instance.Declaration
Swift
@inlinable override public init!(gpointer op: gpointer?)
Parameters
op
gpointer to the underlying object
-
Optional initialiser from a non-mutating
gconstpointer
to the underlyingC
data type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theGLContext
instance.Declaration
Swift
@inlinable override public init!(gconstpointer op: gconstpointer?)
Parameters
op
pointer to the underlying object
-
Optional initialiser from a constant pointer to the underlying
C
data type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theGLContext
instance.Declaration
Swift
@inlinable public init!(_ op: UnsafePointer<GdkGLContext>?)
Parameters
op
pointer to the underlying object
-
Optional initialiser from the underlying
C
data type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theGLContext
instance.Declaration
Swift
@inlinable public init!(_ op: UnsafeMutablePointer<GdkGLContext>?)
Parameters
op
pointer to the underlying object
-
Designated initialiser from the underlying
C
data type. Will retainGdkGLContext
. i.e., ownership is transferred to theGLContext
instance.Declaration
Swift
@inlinable public init(retaining op: UnsafeMutablePointer<GdkGLContext>)
Parameters
op
pointer to the underlying object
-
Reference intialiser for a related type that implements
GLContextProtocol
Will retainGdkGLContext
.Declaration
Swift
@inlinable public init<T>(gLContext other: T) where T : GLContextProtocol
Parameters
other
an instance of a related type that implements
GLContextProtocol
-
Unsafe typed initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
GLContextProtocol
.Declaration
Swift
@inlinable override public init<T>(cPointer p: UnsafeMutablePointer<T>)
Parameters
cPointer
pointer to the underlying object
-
Unsafe typed, retaining initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
GLContextProtocol
.Declaration
Swift
@inlinable override public init<T>(retainingCPointer cPointer: UnsafeMutablePointer<T>)
Parameters
cPointer
pointer to the underlying object
-
Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
GLContextProtocol
.Declaration
Swift
@inlinable override public init(raw p: UnsafeRawPointer)
Parameters
p
raw pointer to the underlying object
-
Unsafe untyped, retaining initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
GLContextProtocol
.Declaration
Swift
@inlinable override public init(retainingRaw 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 public required init(raw p: UnsafeMutableRawPointer)
Parameters
p
mutable raw pointer to the underlying object
-
Unsafe untyped, retaining initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
GLContextProtocol
.Declaration
Swift
@inlinable required public init(retainingRaw raw: UnsafeMutableRawPointer)
Parameters
raw
mutable raw pointer to the underlying object
-
Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
GLContextProtocol
.Declaration
Swift
@inlinable override public init(opaquePointer p: OpaquePointer)
Parameters
p
opaque pointer to the underlying object
-
Unsafe untyped, retaining initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
GLContextProtocol
.Declaration
Swift
@inlinable override public init(retainingOpaquePointer p: OpaquePointer)
Parameters
p
opaque pointer to the underlying object
-
Retrieves the current
GdkGLContext
.Declaration
Swift
@inlinable public static func getCurrent() -> GLContext!