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 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].

  • ptr
    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!

GLContext Class

  • Designated initialiser from the underlying C data type

    Declaration

    Swift

    @inlinable
    init(_ p: UnsafeMutablePointer<GdkGLContext>)
  • Designated initialiser from a constant pointer to the underlying C data type

    Declaration

    Swift

    @inlinable
    init(_ p: UnsafePointer<GdkGLContext>)
  • Conditional initialiser from an optional pointer to the underlying C data type

    Declaration

    Swift

    @inlinable
    init!(_ maybePointer: UnsafeMutablePointer<GdkGLContext>?)
  • Conditional initialiser from an optional, non-mutable pointer to the underlying C data type

    Declaration

    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!