1.25 <GdkGLContext>

Class: <GdkGLContext>

It derives from <GdkDrawContext>.

Represents a platform-specific OpenGL draw context.

<GdkGLContext>s are created for a surface using 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 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 #f 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 glcontext:make-current or 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 surface:create-gl-context by calling 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 glcontext:get-current; you can also unset any <GdkGLContext> that is currently set by calling glcontext:clear-current.

Properties

Property: glcontext:allowed-apis self

The allowed APIs.

Its value is a <GdkGLAPI> (or, to set it, a list of its symbols, or one of them).

Set it with (set! (glcontext:allowed-apis self) value).

Property: glcontext:api self

The API currently in use.

Its value is a <GdkGLAPI>.

It is read only.

Property: glcontext:shared-context self

Always #f

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

Its value is a <GdkGLContext>, or #f.

It can only be set when the object is made, with #:shared-context.

Procedures

Procedure: glcontext:clear-current

Clears the current <GdkGLContext>.

Any OpenGL call after this function returns will be ignored until glcontext:make-current is called.

Method: glcontext:get-allowed-apis self ⇒ %return
Method: get-allowed-apis self ⇒ %return

Gets the allowed APIs set via glcontext:set-allowed-apis.

self

Passed: a <GdkGLContext>.

a GL context

%return

Returned: a <GdkGLAPI>.

the allowed APIs

Method: glcontext:get-api self ⇒ %return
Method: get-api self ⇒ %return

Gets the API currently in use.

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

self

Passed: a <GdkGLContext>.

a GL context

%return

Returned: a <GdkGLAPI>.

the currently used API

Procedure: glcontext:get-current ⇒ %return

Retrieves the current <GdkGLContext>.

%return

Returned: a <GdkGLContext>, or #f.

the current <GdkGLContext>

Method: glcontext:get-debug-enabled? self ⇒ %return
Method: get-debug-enabled? self ⇒ %return

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

See glcontext:set-debug-enabled.

self

Passed: a <GdkGLContext>.

a <GdkGLContext>

%return

Returned: a boolean.

#t if debugging is enabled

Method: glcontext:get-display self ⇒ %return
Method: get-display self ⇒ %return

Retrieves the display the self is created for

self

Passed: a <GdkGLContext>.

a <GdkGLContext>

%return

Returned: a <GdkDisplay>, or #f.

a <GdkDisplay>

Method: glcontext:get-forward-compatible? self ⇒ %return
Method: get-forward-compatible? self ⇒ %return

Retrieves whether the context is forward-compatible.

See glcontext:set-forward-compatible.

self

Passed: a <GdkGLContext>.

a <GdkGLContext>

%return

Returned: a boolean.

#t if the context should be forward-compatible

Method: glcontext:get-required-version self ⇒ major minor
Method: get-required-version self ⇒ major minor

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 glcontext:get-version for the real version in use.

See glcontext:set-required-version.

self

Passed: a <GdkGLContext>.

a <GdkGLContext>

major

Returned: a 32-bit integer.

return location for the major version to request

minor

Returned: a 32-bit integer.

return location for the minor version to request

Method: glcontext:get-shared-context self ⇒ %return
Method: get-shared-context self ⇒ %return

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 #f.

self

Passed: a <GdkGLContext>.

a <GdkGLContext>

%return

Returned: a <GdkGLContext>, or #f.

#f

Method: glcontext:get-surface self ⇒ %return
Method: get-surface self ⇒ %return

Retrieves the surface used by the self.

self

Passed: a <GdkGLContext>.

a <GdkGLContext>

%return

Returned: a <GdkSurface>, or #f.

a <GdkSurface>

Method: glcontext:get-use-es? self ⇒ %return
Method: get-use-es? self ⇒ %return

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

self

Passed: a <GdkGLContext>.

a <GdkGLContext>

%return

Returned: a boolean.

#t if the <GdkGLContext> is using an OpenGL ES profile; #f if other profile is in use of if the self has not yet been realized.

Method: glcontext:get-version self ⇒ major minor
Method: get-version self ⇒ major minor

Retrieves the OpenGL version of the self.

The self must be realized prior to calling this function.

self

Passed: a <GdkGLContext>.

a <GdkGLContext>

major

Returned: a 32-bit integer.

return location for the major version

minor

Returned: a 32-bit integer.

return location for the minor version

Method: glcontext:is-legacy? self ⇒ %return
Method: is-legacy? self ⇒ %return

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 #f.

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 #t.

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.

self

Passed: a <GdkGLContext>.

a <GdkGLContext>

%return

Returned: a boolean.

#t if the GL context is in legacy mode

Method: glcontext:is-shared? self other ⇒ %return
Method: is-shared? self other ⇒ %return

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 #f.

self

Passed: a <GdkGLContext>.

a <GdkGLContext>

other

Passed: a <GdkGLContext>.

the <GdkGLContext> that should be compatible with self

%return

Returned: a boolean.

#t if the two GL contexts are compatible.

Method: glcontext:make-current self
Method: make-current self

Makes the self the current one.

self

Passed: a <GdkGLContext>.

a <GdkGLContext>

Method: glcontext:realize? self ⇒ %return
Method: realize? self ⇒ %return

Realizes the given <GdkGLContext>.

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

self

Passed: a <GdkGLContext>.

a <GdkGLContext>

%return

Returned: a boolean.

#t if the context is realized

Method: glcontext:set-allowed-apis self apis
Method: set-allowed-apis self apis

Sets the allowed APIs. When 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 glcontext:realize?.

By default, all APIs are allowed.

self

Passed: a <GdkGLContext>.

a GL context

apis

Passed: a <GdkGLAPI>, or a list of its symbols, or one of them.

the allowed APIs

Method: glcontext:set-debug-enabled self enabled
Method: set-debug-enabled self 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.

self

Passed: a <GdkGLContext>.

a <GdkGLContext>

enabled

Passed: a boolean.

whether to enable debugging in the context

Method: glcontext:set-forward-compatible self compatible
Method: set-forward-compatible self 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.

self

Passed: a <GdkGLContext>.

a <GdkGLContext>

compatible

Passed: a boolean.

whether the context should be forward-compatible

Method: glcontext:set-required-version self major minor
Method: set-required-version self major 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 self must not be realized or made current prior to calling this function.

self

Passed: a <GdkGLContext>.

a <GdkGLContext>

major

Passed: a 32-bit integer.

the major version to request

minor

Passed: a 32-bit integer.

the minor version to request

Method: glcontext:set-use-es self use-es
Method: set-use-es self use-es

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 glcontext:get-use-es? after calling glcontext:realize? to decide whether to use the OpenGL or OpenGL ES API, extensions, or shaders.

self

Passed: a <GdkGLContext>.

a <GdkGLContext>

use-es

Passed: a 32-bit integer.

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