Gdk.GLContext

g GObject.Object GObject.Object Gdk.DrawContext Gdk.DrawContext GObject.Object->Gdk.DrawContext Gdk.GLContext Gdk.GLContext Gdk.DrawContext->Gdk.GLContext

Subclasses:

None

Methods

Inherited:

Gdk.DrawContext (6), GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

clear_current ()

class

get_current ()

get_allowed_apis ()

get_api ()

get_debug_enabled ()

get_display ()

get_forward_compatible ()

get_required_version ()

get_shared_context ()

get_surface ()

get_use_es ()

get_version ()

is_legacy ()

is_shared (other)

make_current ()

realize ()

set_allowed_apis (apis)

set_debug_enabled (enabled)

set_forward_compatible (compatible)

set_required_version (major, minor)

set_use_es (use_es)

Virtual Methods

Inherited:

GObject.Object (7)

Properties

Inherited:

Gdk.DrawContext (2)

Name

Type

Flags

Short Description

allowed-apis

Gdk.GLAPI

r/w/en

api

Gdk.GLAPI

r/en

shared-context

Gdk.GLContext

d/r/w/co

deprecated

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Class Details

class Gdk.GLContext(**kwargs)
Bases:

Gdk.DrawContext

Abstract:

Yes

GdkGLContext is an object representing a platform-specific OpenGL draw context.

``GdkGLContext``s 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 None 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 Gdk.GLContext

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

classmethod clear_current()[source]

Clears the current GdkGLContext.

Any OpenGL call after this function returns will be ignored until [method`Gdk`.GLContext.make_current] is called.

classmethod get_current()[source]
Returns:

the current GdkGLContext

Return type:

Gdk.GLContext or None

Retrieves the current GdkGLContext.

get_allowed_apis()[source]
Returns:

the allowed APIs

Return type:

Gdk.GLAPI

Gets the allowed APIs set via Gdk.GLContext.set_allowed_apis().

New in version 4.6.

get_api()[source]
Returns:

the currently used API

Return type:

Gdk.GLAPI

Gets the API currently in use.

If the renderer has not been realized yet, 0 is returned.

New in version 4.6.

get_debug_enabled()[source]
Returns:

True if debugging is enabled

Return type:

bool

Retrieves whether the context is doing extra validations and runtime checking.

See [method`Gdk`.GLContext.set_debug_enabled].

get_display()[source]
Returns:

a GdkDisplay

Return type:

Gdk.Display or None

Retrieves the display the self is created for

get_forward_compatible()[source]
Returns:

True if the context should be forward-compatible

Return type:

bool

Retrieves whether the context is forward-compatible.

See [method`Gdk`.GLContext.set_forward_compatible].

get_required_version()[source]
Returns:

major:

return location for the major version to request

minor:

return location for the minor version to request

Return type:

(major: int, minor: int)

Retrieves required OpenGL version set as a requirement for the self realization. It will not change even if a greater OpenGL version is supported and used after the self is realized. See [method`Gdk`.GLContext.get_version] for the real version in use.

See [method`Gdk`.GLContext.set_required_version].

get_shared_context()[source]
Returns:

None

Return type:

Gdk.GLContext or None

Used to retrieves the GdkGLContext that this self 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 None.

Deprecated since version 4.4: Use [method`Gdk`.GLContext.is_shared] to check if contexts can be shared.

get_surface()[source]
Returns:

a GdkSurface

Return type:

Gdk.Surface or None

Retrieves the surface used by the self.

get_use_es()[source]
Returns:

True if the GdkGLContext is using an OpenGL ES profile; False if other profile is in use of if the self has not yet been realized.

Return type:

bool

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

get_version()[source]
Returns:

major:

return location for the major version

minor:

return location for the minor version

Return type:

(major: int, minor: int)

Retrieves the OpenGL version of the self.

The self must be realized prior to calling this function.

is_legacy()[source]
Returns:

True if the GL context is in legacy mode

Return type:

bool

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(other)[source]
Parameters:

other (Gdk.GLContext) – the GdkGLContext that should be compatible with self

Returns:

True if the two GL contexts are compatible.

Return type:

bool

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.

New in version 4.4.

make_current()[source]

Makes the self the current one.

realize()[source]
Raises:

GLib.Error

Returns:

True if the context is realized

Return type:

bool

Realizes the given GdkGLContext.

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

set_allowed_apis(apis)[source]
Parameters:

apis (Gdk.GLAPI) – the allowed APIs

Sets the allowed APIs. When Gdk.GLContext.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.GLContext.realize().

By default, all APIs are allowed.

New in version 4.6.

set_debug_enabled(enabled)[source]
Parameters:

enabled (bool) – whether to enable debugging in the context

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.

set_forward_compatible(compatible)[source]
Parameters:

compatible (bool) – whether the context should be forward-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.

set_required_version(major, minor)[source]
Parameters:
  • major (int) – the major version to request

  • minor (int) – the minor version to request

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 self must not be realized or made current prior to calling this function.

set_use_es(use_es)[source]
Parameters:

use_es (int) – whether the context should use OpenGL ES instead of OpenGL, or -1 to allow auto-detection

Requests that GDK create an OpenGL ES context instead of an OpenGL one.

Not all platforms support OpenGL ES.

The self 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 self 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.

Property Details

Gdk.GLContext.props.allowed_apis
Name:

allowed-apis

Type:

Gdk.GLAPI

Default Value:

Gdk.GLAPI.GL | Gdk.GLAPI.GLES

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The allowed APIs.

New in version 4.6.

Gdk.GLContext.props.api
Name:

api

Type:

Gdk.GLAPI

Default Value:

0

Flags:

READABLE, EXPLICIT_NOTIFY

The API currently in use.

New in version 4.6.

Gdk.GLContext.props.shared_context
Name:

shared-context

Type:

Gdk.GLContext

Default Value:

None

Flags:

DEPRECATED, READABLE, WRITABLE, CONSTRUCT_ONLY

Always None

As many contexts can share data now and no single shared context exists anymore, this function has been deprecated and now always returns None.

Deprecated since version 4.4: Use [method`Gdk`.GLContext.is_shared] to check if contexts can be shared.