class Gdk::GLContext

Overview

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

GdkGLContexts are created for a surface using 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 #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 Gdk::GLContext#make_current or 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 Gdk::Surface#create_gl_context by calling 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:

WARNING ⚠️ The following code is in 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 Gdk::GLContext#current; you can also unset any GdkGLContext that is currently set by calling Gdk::GLContext#clear_current.

Defined in:

auto/gdk-4.0/gl_context.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from class Gdk::DrawContext

begin_frame(region : Cairo::Region) : Nil begin_frame, display : Gdk::Display? display, display=(value : Gdk::Display?) : Gdk::Display? display=, end_frame : Nil end_frame, frame_region : Cairo::Region? frame_region, is_in_frame : Bool is_in_frame, surface : Gdk::Surface? surface, surface=(value : Gdk::Surface?) : Gdk::Surface? surface=

Constructor methods inherited from class Gdk::DrawContext

new
new(*, display : Gdk::Display? = nil, surface : Gdk::Surface? = nil)
new

Class methods inherited from class Gdk::DrawContext

g_type : UInt64 g_type

Instance methods inherited from class GObject::Object

bind_property(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags) : GObject::Binding bind_property, bind_property_full(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags, transform_to : GObject::Closure, transform_from : GObject::Closure) : GObject::Binding bind_property_full, data(key : String) : Pointer(Void)? data, finalize finalize, freeze_notify : Nil freeze_notify, getv(names : Enumerable(String), values : Enumerable(_)) : Nil getv, notify(property_name : String) : Nil notify, notify_by_pspec(pspec : GObject::ParamSpec) : Nil notify_by_pspec, notify_signal notify_signal, property(property_name : String, value : _) : Nil property, qdata(quark : UInt32) : Pointer(Void)? qdata, ref_count ref_count, run_dispose : Nil run_dispose, set_data(key : String, data : Pointer(Void)?) : Nil set_data, set_property(property_name : String, value : _) : Nil set_property, steal_data(key : String) : Pointer(Void)? steal_data, steal_qdata(quark : UInt32) : Pointer(Void)? steal_qdata, thaw_notify : Nil thaw_notify, to_unsafe : Pointer(Void) to_unsafe, watch_closure(closure : GObject::Closure) : Nil watch_closure

Constructor methods inherited from class GObject::Object

cast(obj : GObject::Object) : self cast, cast?(obj : GObject::Object) : self? cast?, new new, newv(object_type : UInt64, parameters : Enumerable(GObject::Parameter)) : self newv

Class methods inherited from class GObject::Object

compat_control(what : UInt64, data : Pointer(Void)?) : UInt64 compat_control, g_type : UInt64 g_type, interface_find_property(g_iface : GObject::TypeInterface, property_name : String) : GObject::ParamSpec interface_find_property, interface_list_properties(g_iface : GObject::TypeInterface) : Enumerable(GObject::ParamSpec) interface_list_properties

Constructor Detail

def self.new #

Initialize a new GLContext.


def self.new(*, allowed_apis : Gdk::GLAPI? = nil, api : Gdk::GLAPI? = nil, display : Gdk::Display? = nil, shared_context : Gdk::GLContext? = nil, surface : Gdk::Surface? = nil) #

Class Method Detail

def self.clear_current : Nil #

Clears the current GdkGLContext.

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


def self.current : Gdk::GLContext? #

Retrieves the current GdkGLContext.


def self.g_type : UInt64 #

Returns the type id (GType) registered in GLib type system.


Instance Method Detail

def allowed_apis : Gdk::GLAPI #

Gets the allowed APIs set via gdk_gl_context_set_allowed_apis().


def allowed_apis=(apis : Gdk::GLAPI) : Nil #

Sets the allowed APIs. When gdk_gl_context_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_gl_context_realize().

By default, all APIs are allowed.


def api : Gdk::GLAPI #

Gets the API currently in use.

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


def debug_enabled : Bool #

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

See Gdk::GLContext#debug_enabled=.


def debug_enabled=(enabled : Bool) : Nil #

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.


def display : Gdk::Display? #

Retrieves the display the @context is created for


def forward_compatible : Bool #

Retrieves whether the context is forward-compatible.

See Gdk::GLContext#forward_compatible=.


def forward_compatible=(compatible : Bool) : Nil #

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.


def is_legacy : 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.


def is_shared(other : Gdk::GLContext) : 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.


def make_current : Nil #

Makes the @context the current one.


def realize : Bool #

Realizes the given GdkGLContext.

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


def required_version(major : Int32?, minor : Int32?) : Nil #

Retrieves required OpenGL version.

See Gdk::GLContext#required_version=.


def set_required_version(major : Int32, minor : Int32) : Nil #

Sets the major and minor version of OpenGL to request.

Setting @major and @minor to zero will use the default values.

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


def shared_context : Gdk::GLContext? #

Used to retrieves the GdkGLContext that this @context 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 %NULL.


def shared_context=(value : Gdk::GLContext?) : Gdk::GLContext? #

def surface : Gdk::Surface? #

Retrieves the surface used by the @context.


def use_es : Bool #

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


def use_es=(use_es : Int32) : Nil #

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

Not all platforms support OpenGL ES.

The @context 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 @context is realized.

You should check the return value of Gdk::GLContext#use_es after calling Gdk::GLContext#realize to decide whether to use the OpenGL or OpenGL ES API, extensions, or shaders.


def version(major : Int32, minor : Int32) : Nil #

Retrieves the OpenGL version of the @context.

The @context must be realized prior to calling this function.