Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

class: GLContext

[41:7] extends: object

Represents a platform-specific OpenGL draw context. GdkGLContexts are created for a surface using [method@Gdk.Surface.create_gl_context], and the context will match 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 [func@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 and context creation can fail, returning %NULL 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 [method@Gdk.GLContext.make_current] or [method@Gdk.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 [method@Gdk.Surface.create_gl_context] by calling [method@Gdk.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: c 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 [func@Gdk.GLContext.get_current]; you can also unset any GdkGLContext that is currently set by calling [func@Gdk.GLContext.clear_current].

Members

  • handleObj
  • lib
  • retainedCallbacks
  • signalHandlerNames
  • signalSetterHandlers

Methods

  • GLContext (Handle = null)

    Creates a new GLContext by wrapping a native handle or another wrapper.

    • @p Handle is the native handle or another wrapper whose handle to adopt.
  • toNativeHandle (Source)

    Normalizes a constructor argument into a raw pointer carrier. Accepts a raw NativeHandle, a raw NativeBuffer returned from fn.call(...), another generated wrapper exposing handle(), or null. Returns null when the argument carries no pointer.

    • @p Source is the raw handle, raw buffer, wrapper, or null.
    • @r A raw pointer carrier or null when no pointer is present.
  • getLib ()

    Returns the opened native library for this generated wrapper.

    • @r The opened native library.
  • handle ()

    Returns the wrapped NativeHandle.

    • @r The wrapped NativeHandle.
  • isNull ()

    Returns true when the wrapped handle is null.

    • @r A bool.
  • describe ()

    Returns a small string for debugging generated wrappers.

    • @r A string.
  • asDrawContext ()

    Wraps this handle as DrawContext.

    • @r A DrawContext object.
  • getProperty (string Name)

    Reads one generated property by name.

  • setProperty (string Name, Value)

    Writes one generated property by name.

  • setAllowedapis (string Value)

    The allowed APIs.

    • @p Value is the new property value.
    • @r None.
  • get_allowed_apis ()

    Gets the allowed APIs set via gdk_gl_context_set_allowed_apis().

  • get_api ()

    Gets the API currently in use. If the renderer has not been realized yet, 0 is returned.

  • get_debug_enabled ()

    Retrieves whether the context is doing extra validations and runtime checking. See [method@Gdk.GLContext.set_debug_enabled].

  • get_display ()

    Retrieves the display the @context is created for

  • get_forward_compatible ()

    Retrieves whether the context is forward-compatible. See [method@Gdk.GLContext.set_forward_compatible].

  • get_shared_context ()

    Used to retrieves the GdkGLContext that this @context share data with. As many contexts can share data now and no single shared context exists anymore, this function has been deprecated and now always returns %NULL.

  • get_surface ()

    Retrieves the surface used by the @context.

  • get_use_es ()

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

  • is_legacy ()

    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.

  • is_shared (object other)

    Checks if the two GL contexts can share resources. When they can, the texture IDs from @other can be used in @self. This is particularly useful when passing GdkGLTexture objects between different contexts. Contexts created for the same display with the same properties will always be compatible, even if they are created for different surfaces. For other contexts it depends on the GL backend. Both contexts must be realized for this check to succeed. If either one is not, this function will return %FALSE.

    • @p other is the GdkGLContext that should be compatible with @self.
  • make_current ()

    Makes the @context the current one.

    • @r None.
  • realize ()

    Realizes the given GdkGLContext. It is safe to call this function on a realized GdkGLContext.

  • set_allowed_apis (string apis)

    Sets the allowed APIs. When gdk_gl_context_realize() is called, only the allowed APIs will be tried. If you set this to 0, realizing will always fail. If you set it on a realized context, the property will not have any effect. It is only relevant during gdk_gl_context_realize(). By default, all APIs are allowed.

    • @p apis is the allowed APIs.
    • @r None.
  • set_debug_enabled (bool enabled)

    Sets whether the GdkGLContext should perform extra validations and runtime checking. This is useful during development, but has additional overhead. The GdkGLContext must not be realized or made current prior to calling this function.

    • @p enabled is whether to enable debugging in the context.
    • @r None.
  • set_forward_compatible (bool compatible)

    Sets whether the GdkGLContext should 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 GdkGLContext must not be realized or made current prior to calling this function.

    • @p compatible is whether the context should be forward-compatible.
    • @r None.
  • set_required_version (int major, int minor)

    Sets the major and minor version of OpenGL to request. Setting @major and

    • @minor to zero will use the default values. Setting @major and @minor lower than the minimum versions required by GTK will result in the context choosing the minimum version. The @context must not be realized or made current prior to calling this function.
    • @p major is the major version to request.
    • @p minor is the minor version to request.
    • @r None.
  • set_use_es (int use_es)

    Requests that GDK create an OpenGL ES context instead of an OpenGL one. Not all platforms support OpenGL ES. 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 [method@Gdk.GLContext.get_use_es] after calling [method@Gdk.GLContext.realize] to decide whether to use the OpenGL or OpenGL ES API, extensions, or shaders.

    • @p use_es is whether the context should use OpenGL ES instead of OpenGL, or -1 to allow auto-detection.
    • @r None.

class: GLContextMeta

[371:14] static extends: object

Generated metadata helpers for GLContext class surfaces.

Methods

  • properties ()

    Returns property metadata for GLContext.

    • @r A list.