GLContextProtocol

public protocol GLContextProtocol : ObjectProtocol

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 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().

  • ptr

    Untyped pointer to the underlying GdkGLContext instance.

    Declaration

    Swift

    var ptr: UnsafeMutableRawPointer! { get }
  • gl_context_ptr Default implementation

    Typed pointer to the underlying GdkGLContext instance.

    Default Implementation

    Return the stored, untyped pointer as a typed pointer to the GdkGLContext instance.

    Declaration

    Swift

    var gl_context_ptr: UnsafeMutablePointer<GdkGLContext>! { get }
  • Required Initialiser for types conforming to GLContextProtocol

    Declaration

    Swift

    init(raw: UnsafeMutableRawPointer)

GLContext Class

  • Bind a GLContextPropertyName source 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 : ObjectProtocol

    Parameters

    source_property

    the source property to bind

    target

    the target object to bind to

    target_property

    the target property to bind to

    flags

    the flags to pass to the Binding

    transform_from

    ValueTransformer to use for forward transformation

    transform_to

    ValueTransformer to use for backwards transformation

    Return Value

    binding reference or nil in case of an error

  • get(property:) Extension method

    Get the value of a GLContext property

    Declaration

    Swift

    @inlinable
    func get(property: GLContextPropertyName) -> GLibObject.Value

    Parameters

    property

    the property to get the value for

    Return Value

    the value of the named property

  • set(property:value:) Extension method

    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

    property

    the property to get the value for

    Return Value

    the value of the named property

GLContext Class: GLContextProtocol extension (methods and fields)

  • getDebugEnabled() Extension method

    Retrieves the value set using gdk_gl_context_set_debug_enabled().

    Declaration

    Swift

    @inlinable
    func getDebugEnabled() -> Bool
  • getDisplay() Extension method

    Retrieves the GdkDisplay the context is created for

    Declaration

    Swift

    @inlinable
    func getDisplay() -> DisplayRef!
  • getForwardCompatible() Extension method

    Retrieves the value set using gdk_gl_context_set_forward_compatible().

    Declaration

    Swift

    @inlinable
    func getForwardCompatible() -> Bool
  • Retrieves the major and minor version requested by calling gdk_gl_context_set_required_version().

    Declaration

    Swift

    @inlinable
    func getRequiredVersion(major: UnsafeMutablePointer<gint>?, minor: UnsafeMutablePointer<gint>?)
  • getSharedContext() Extension method

    Retrieves the GdkGLContext that this context share data with.

    Declaration

    Swift

    @inlinable
    func getSharedContext() -> GLContextRef!
  • getUseEs() Extension method

    Checks whether the context is using an OpenGL or OpenGL ES profile.

    Declaration

    Swift

    @inlinable
    func getUseEs() -> Bool
  • getVersion(major:minor:) Extension method

    Retrieves the OpenGL version of the context.

    The context must be realized prior to calling this function.

    Declaration

    Swift

    @inlinable
    func getVersion(major: UnsafeMutablePointer<gint>!, minor: UnsafeMutablePointer<gint>!)
  • getWindow() Extension method

    Retrieves the GdkWindow used by the context.

    Declaration

    Swift

    @inlinable
    func getWindow() -> WindowRef!
  • makeCurrent() Extension method

    Makes the context the current one.

    Declaration

    Swift

    @inlinable
    func makeCurrent()
  • realize() Extension method

    Realizes 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 GdkGLContext should perform extra validations and run time checking. This is useful during development, but has additional overhead.

    The GdkGLContext must 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 GdkGLContext should be forward compatible.

    Forward compatibile 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.

    Declaration

    Swift

    @inlinable
    func setForward(compatible: Bool)
  • Sets the major and minor version of OpenGL to request.

    Setting major and minor to zero will use the default values.

    The GdkGLContext must 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 a OpenGL ES context instead of an OpenGL one, if the platform and windowing system allows it.

    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 gdk_gl_context_get_use_es() after calling gdk_gl_context_realize() to decide whether to use the OpenGL or OpenGL ES API, extensions, or shaders.

    Declaration

    Swift

    @inlinable
    func set(useEs: Int)
  • debugEnabled Extension method

    Retrieves the value set using gdk_gl_context_set_debug_enabled().

    Declaration

    Swift

    @inlinable
    var debugEnabled: Bool { get nonmutating set }
  • display Extension method

    The GdkDisplay used to create the GdkGLContext.

    Declaration

    Swift

    @inlinable
    var display: DisplayRef! { get }
  • forwardCompatible Extension method

    Retrieves the value set using gdk_gl_context_set_forward_compatible().

    Declaration

    Swift

    @inlinable
    var forwardCompatible: Bool { get nonmutating set }
  • isLegacy Extension method

    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.

    Declaration

    Swift

    @inlinable
    var isLegacy: Bool { get }
  • sharedContext Extension method

    Retrieves the GdkGLContext that this context share data with.

    Declaration

    Swift

    @inlinable
    var sharedContext: GLContextRef! { get }
  • useEs Extension method

    Checks whether the context is using an OpenGL or OpenGL ES profile.

    Declaration

    Swift

    @inlinable
    var useEs: Bool { get nonmutating set }
  • window Extension method

    The GdkWindow the gl context is bound to.

    Declaration

    Swift

    @inlinable
    var window: WindowRef! { get }