GLContext

GdkGLContext is an object representing 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 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:

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

Constructors

this
this(GdkGLContext* gdkGLContext, bool ownedRef)

Sets our main struct and passes it to the parent class.

Members

Functions

getDebugEnabled
bool getDebugEnabled()

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

getDisplay
Display getDisplay()

Retrieves the display the @context is created for

getForwardCompatible
bool getForwardCompatible()

Retrieves whether the context is forward-compatible.

getGLContextStruct
GdkGLContext* getGLContextStruct(bool transferOwnership)

Get the main Gtk struct

getRequiredVersion
void getRequiredVersion(int major, int minor)

Retrieves required OpenGL version.

getSharedContext
GLContext getSharedContext()

Retrieves the GdkGLContext that this @context share data with.

getStruct
void* getStruct()

the main Gtk struct as a void*

getSurface
Surface getSurface()

Retrieves the surface used by the @context.

getUseEs
bool getUseEs()

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

getVersion
void getVersion(int major, int minor)

Retrieves the OpenGL version of the @context.

isLegacy
bool isLegacy()

Whether the GdkGLContext is in legacy mode or not.

makeCurrent
void makeCurrent()

Makes the @context the current one.

realize
bool realize()

Realizes the given GdkGLContext.

setDebugEnabled
void setDebugEnabled(bool enabled)

Sets whether the GdkGLContext should perform extra validations and runtime checking.

setForwardCompatible
void setForwardCompatible(bool compatible)

Sets whether the GdkGLContext should be forward-compatible.

setRequiredVersion
void setRequiredVersion(int major, int minor)

Sets the major and minor version of OpenGL to request.

setUseEs
void setUseEs(int useEs)

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

Static functions

clearCurrent
void clearCurrent()

Clears the current GdkGLContext.

getCurrent
GLContext getCurrent()

Retrieves the current GdkGLContext.

getType
GType getType()

Variables

gdkGLContext
GdkGLContext* gdkGLContext;

the main Gtk struct

Inherited Members

From DrawContext

gdkDrawContext
GdkDrawContext* gdkDrawContext;

the main Gtk struct

getDrawContextStruct
GdkDrawContext* getDrawContextStruct(bool transferOwnership)

Get the main Gtk struct

getStruct
void* getStruct()

the main Gtk struct as a void*

getType
GType getType()
beginFrame
void beginFrame(Region region)

Indicates that you are beginning the process of redrawing @region on the @context's surface.

endFrame
void endFrame()

Ends a drawing operation started with gdk_draw_context_begin_frame().

getDisplay
Display getDisplay()

Retrieves the GdkDisplay the @context is created for

getFrameRegion
Region getFrameRegion()

Retrieves the region that is currently being repainted.

getSurface
Surface getSurface()

Retrieves the surface that @context is bound to.

isInFrame
bool isInFrame()

Returns %TRUE if @context is in the process of drawing to its surface.

Meta