Gdk.GLContext

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

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

clear_current ()

class

get_current ()

get_debug_enabled ()

get_display ()

get_forward_compatible ()

get_required_version ()

get_shared_context ()

get_use_es ()

get_version ()

get_window ()

is_legacy ()

make_current ()

realize ()

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

Name

Type

Flags

Short Description

display

Gdk.Display

r/w/co

The GDK display used to create the GL context

shared-context

Gdk.GLContext

r/w/co

The GL context this context shares data with

window

Gdk.Window

r/w/co

The GDK window bound to the GL context

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Class Details

class Gdk.GLContext(**kwargs)
Bases:

GObject.Object

Abstract:

Yes

Gdk.GLContext is an object representing the platform-specific OpenGL drawing context.

Gdk.GLContexts are created for a Gdk.Window using Gdk.Window.create_gl_context(), and the context will match the Gdk.Visual of the window.

A Gdk.GLContext is not tied to any particular normal framebuffer. For instance, it cannot draw to the Gdk.Window 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 Gdk.GLContext is platform-specific, context creation can fail, returning None context.

A Gdk.GLContext 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 Gdk.GLContext instance you need a Gdk.Window, which you typically get during the realize call of a widget.

A Gdk.GLContext is not realized until either Gdk.GLContext.make_current(), or until it is realized using Gdk.GLContext.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.GLContext.realize(). If the realization fails you have the option to change the settings of the Gdk.GLContext and try again.

Using a Gdk.GLContext

You will need to make the Gdk.GLContext 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 Gdk.GLContext is the current one by using Gdk.GLContext.get_current(); you can also unset any Gdk.GLContext that is currently set by calling Gdk.GLContext.clear_current().

classmethod clear_current()[source]

Clears the current Gdk.GLContext.

Any OpenGL call after this function returns will be ignored until Gdk.GLContext.make_current() is called.

New in version 3.16.

classmethod get_current()[source]
Returns:

the current Gdk.GLContext, or None

Return type:

Gdk.GLContext or None

Retrieves the current Gdk.GLContext.

New in version 3.16.

get_debug_enabled()[source]
Returns:

True if debugging is enabled

Return type:

bool

Retrieves the value set using Gdk.GLContext.set_debug_enabled().

New in version 3.16.

get_display()[source]
Returns:

a Gdk.Display or None

Return type:

Gdk.Display or None

Retrieves the Gdk.Display the self is created for

New in version 3.16.

get_forward_compatible()[source]
Returns:

True if the context should be forward compatible

Return type:

bool

Retrieves the value set using Gdk.GLContext.set_forward_compatible().

New in version 3.16.

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 the major and minor version requested by calling Gdk.GLContext.set_required_version().

New in version 3.16.

get_shared_context()[source]
Returns:

a Gdk.GLContext or None

Return type:

Gdk.GLContext or None

Retrieves the Gdk.GLContext that this self share data with.

New in version 3.16.

get_use_es()[source]
Returns:

True if the Gdk.GLContext is using an OpenGL ES profile

Return type:

bool

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

New in version 3.22.

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.

New in version 3.16.

get_window()[source]
Returns:

a Gdk.Window or None

Return type:

Gdk.Window or None

Retrieves the Gdk.Window used by the self.

New in version 3.16.

is_legacy()[source]
Returns:

True if the GL context is in legacy mode

Return type:

bool

Whether the Gdk.GLContext is in legacy mode or not.

The Gdk.GLContext 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.

New in version 3.20.

make_current()[source]

Makes the self the current one.

New in version 3.16.

realize()[source]
Raises:

GLib.Error

Returns:

True if the context is realized

Return type:

bool

Realizes the given Gdk.GLContext.

It is safe to call this function on a realized Gdk.GLContext.

New in version 3.16.

set_debug_enabled(enabled)[source]
Parameters:

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

Sets whether the Gdk.GLContext should perform extra validations and run time checking. This is useful during development, but has additional overhead.

The Gdk.GLContext must not be realized or made current prior to calling this function.

New in version 3.16.

set_forward_compatible(compatible)[source]
Parameters:

compatible (bool) – whether the context should be forward compatible

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

New in version 3.16.

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.

The Gdk.GLContext must not be realized or made current prior to calling this function.

New in version 3.16.

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

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

New in version 3.22.

Property Details

Gdk.GLContext.props.display
Name:

display

Type:

Gdk.Display

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The Gdk.Display used to create the Gdk.GLContext.

New in version 3.16.

Gdk.GLContext.props.shared_context
Name:

shared-context

Type:

Gdk.GLContext

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The Gdk.GLContext that this context is sharing data with, or None

New in version 3.16.

Gdk.GLContext.props.window
Name:

window

Type:

Gdk.Window

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The Gdk.Window the gl context is bound to.

New in version 3.16.