CdkGLContext

CdkGLContext — OpenGL context

Functions

Properties

CdkDisplay * display Read / Write / Construct Only
CdkGLContext * shared-context Read / Write / Construct Only
CdkWindow * window Read / Write / Construct Only

Types and Values

Object Hierarchy

    GObject
    ╰── CdkGLContext

Includes

#include <cdk/cdkwayland.h>

Description

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

CdkGLContexts are created for a CdkWindow using cdk_window_create_gl_context(), and the context will match the CdkVisual of the window.

A CdkGLContext is not tied to any particular normal framebuffer. For instance, it cannot draw to the CdkWindow back buffer. The CDK repaint system is in full control of the painting to that. Instead, you can create render buffers or textures and use cdk_cairo_draw_from_gl() in the draw function of your widget to draw them. Then CDK will handle the integration of your rendering with that of other widgets.

Support for CdkGLContext is platform-specific, context creation can fail, returning NULL context.

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

A CdkGLContext is not realized until either cdk_gl_context_make_current(), or until it is realized using cdk_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 cdk_window_create_gl_context() by calling cdk_gl_context_realize(). If the realization fails you have the option to change the settings of the CdkGLContext and try again.

Using a CdkGLContext

You will need to make the CdkGLContext 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:

1
cdk_gl_context_make_current (context);

You can now perform your drawing using OpenGL commands.

You can check which CdkGLContext is the current one by using cdk_gl_context_get_current(); you can also unset any CdkGLContext that is currently set by calling cdk_gl_context_clear_current().

Functions

cdk_gl_context_get_display ()

CdkDisplay *
cdk_gl_context_get_display (CdkGLContext *context);

Retrieves the CdkDisplay the context is created for

Parameters

context

a CdkGLContext

 

Returns

a CdkDisplay or NULL.

[nullable][transfer none]

Since: 3.16


cdk_gl_context_get_window ()

CdkWindow *
cdk_gl_context_get_window (CdkGLContext *context);

Retrieves the CdkWindow used by the context .

Parameters

context

a CdkGLContext

 

Returns

a CdkWindow or NULL.

[nullable][transfer none]

Since: 3.16


cdk_gl_context_get_shared_context ()

CdkGLContext *
cdk_gl_context_get_shared_context (CdkGLContext *context);

Retrieves the CdkGLContext that this context share data with.

Parameters

context

a CdkGLContext

 

Returns

a CdkGLContext or NULL.

[nullable][transfer none]

Since: 3.16


cdk_gl_context_get_version ()

void
cdk_gl_context_get_version (CdkGLContext *context,
                            int *major,
                            int *minor);

Retrieves the OpenGL version of the context .

The context must be realized prior to calling this function.

Parameters

context

a CdkGLContext

 

major

return location for the major version.

[out]

minor

return location for the minor version.

[out]

Since: 3.16


cdk_gl_context_set_required_version ()

void
cdk_gl_context_set_required_version (CdkGLContext *context,
                                     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.

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

Parameters

context

a CdkGLContext

 

major

the major version to request

 

minor

the minor version to request

 

Since: 3.16


cdk_gl_context_get_required_version ()

void
cdk_gl_context_get_required_version (CdkGLContext *context,
                                     int *major,
                                     int *minor);

Retrieves the major and minor version requested by calling cdk_gl_context_set_required_version().

Parameters

context

a CdkGLContext

 

major

return location for the major version to request.

[out][nullable]

minor

return location for the minor version to request.

[out][nullable]

Since: 3.16


cdk_gl_context_set_debug_enabled ()

void
cdk_gl_context_set_debug_enabled (CdkGLContext *context,
                                  gboolean enabled);

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

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

Parameters

context

a CdkGLContext

 

enabled

whether to enable debugging in the context

 

Since: 3.16


cdk_gl_context_get_debug_enabled ()

gboolean
cdk_gl_context_get_debug_enabled (CdkGLContext *context);

Retrieves the value set using cdk_gl_context_set_debug_enabled().

Parameters

context

a CdkGLContext

 

Returns

TRUE if debugging is enabled

Since: 3.16


cdk_gl_context_set_forward_compatible ()

void
cdk_gl_context_set_forward_compatible (CdkGLContext *context,
                                       gboolean compatible);

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

Parameters

context

a CdkGLContext

 

compatible

whether the context should be forward compatible

 

Since: 3.16


cdk_gl_context_get_forward_compatible ()

gboolean
cdk_gl_context_get_forward_compatible (CdkGLContext *context);

Retrieves the value set using cdk_gl_context_set_forward_compatible().

Parameters

context

a CdkGLContext

 

Returns

TRUE if the context should be forward compatible

Since: 3.16


cdk_gl_context_set_use_es ()

void
cdk_gl_context_set_use_es (CdkGLContext *context,
                           int use_es);

Requests that CDK 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, CDK 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 cdk_gl_context_get_use_es() after calling cdk_gl_context_realize() to decide whether to use the OpenGL or OpenGL ES API, extensions, or shaders.

Parameters

context

a CdkGLContext:

 

use_es

whether the context should use OpenGL ES instead of OpenGL, or -1 to allow auto-detection

 

Since: 3.22


cdk_gl_context_get_use_es ()

gboolean
cdk_gl_context_get_use_es (CdkGLContext *context);

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

Parameters

context

a CdkGLContext

 

Returns

TRUE if the CdkGLContext is using an OpenGL ES profile

Since: 3.22


cdk_gl_context_is_legacy ()

gboolean
cdk_gl_context_is_legacy (CdkGLContext *context);

Whether the CdkGLContext is in legacy mode or not.

The CdkGLContext must be realized before calling this function.

When realizing a GL context, CDK 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, CDK 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.

Parameters

context

a CdkGLContext

 

Returns

TRUE if the GL context is in legacy mode

Since: 3.20


cdk_gl_context_realize ()

gboolean
cdk_gl_context_realize (CdkGLContext *context,
                        GError **error);

Realizes the given CdkGLContext.

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

Parameters

context

a CdkGLContext

 

error

return location for a GError

 

Returns

TRUE if the context is realized

Since: 3.16


cdk_gl_context_make_current ()

void
cdk_gl_context_make_current (CdkGLContext *context);

Makes the context the current one.

Parameters

context

a CdkGLContext

 

Since: 3.16


cdk_gl_context_get_current ()

CdkGLContext *
cdk_gl_context_get_current (void);

Retrieves the current CdkGLContext.

Returns

the current CdkGLContext, or NULL.

[nullable][transfer none]

Since: 3.16


cdk_gl_context_clear_current ()

void
cdk_gl_context_clear_current (void);

Clears the current CdkGLContext.

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

Since: 3.16

Types and Values

CdkGLContext

typedef struct _CdkGLContext CdkGLContext;

enum CdkGLError

Error enumeration for CdkGLContext.

Members

CDK_GL_ERROR_NOT_AVAILABLE

OpenGL support is not available

 

CDK_GL_ERROR_UNSUPPORTED_FORMAT

The requested visual format is not supported

 

CDK_GL_ERROR_UNSUPPORTED_PROFILE

The requested profile is not supported

 

Since: 3.16

Property Details

The “display” property

  “display”                  CdkDisplay *

The CdkDisplay used to create the CdkGLContext.

Owner: CdkGLContext

Flags: Read / Write / Construct Only

Since: 3.16


The “shared-context” property

  “shared-context”           CdkGLContext *

The CdkGLContext that this context is sharing data with, or NULL

Owner: CdkGLContext

Flags: Read / Write / Construct Only

Since: 3.16


The “window” property

  “window”                   CdkWindow *

The CdkWindow the gl context is bound to.

Owner: CdkGLContext

Flags: Read / Write / Construct Only

Since: 3.16