Class: Gdk::GLContext

Inherits:
Object
  • Object
show all
Defined in:
(unknown)

Overview

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

Gdk::GLContexts are created for a #GdkWindow 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 nil 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_gl_context_make_current(), or until it is realized using gdk_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 gdk_window_create_gl_context() by calling gdk_gl_context_realize(). If the realization fails you have the option to change the settings of the Gdk::GLContext and try again.

## Using a GdkGLContext ##

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_gl_context_get_current(); you can also unset any Gdk::GLContext that is currently set by calling gdk_gl_context_clear_current().

Instance Method Summary collapse

Instance Method Details

#debug_enabledTrueClass

Retrieves the value set using gdk_gl_context_set_debug_enabled().

Returns:

  • (TrueClass)

    true if debugging is enabled

#debug_enabled=(enabled) ⇒ nil

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.

Parameters:

  • enabled (TrueClass)

    whether to enable debugging in the context

Returns:

  • (nil)

#displayGdk::Display

The Gdk::Display used to create the #GdkGLContext.

Returns:

#display=(display) ⇒ Gdk::Display

The Gdk::Display used to create the #GdkGLContext.

Parameters:

Returns:

#forward_compatibleTrueClass

Retrieves the value set using gdk_gl_context_set_forward_compatible().

Returns:

  • (TrueClass)

    true if the context should be forward compatible

#forward_compatible=(compatible) ⇒ nil

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.

Parameters:

  • compatible (TrueClass)

    whether the context should be forward compatible

Returns:

  • (nil)

#get_required_version(major, minor) ⇒ nil

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

Parameters:

  • major (Integer)

    return location for the major version to request

  • minor (Integer)

    return location for the minor version to request

Returns:

  • (nil)

#get_version(major, minor) ⇒ nil

Retrieves the OpenGL version of the context.

The context must be realized prior to calling this function.

Parameters:

  • major (Integer)

    return location for the major version

  • minor (Integer)

    return location for the minor version

Returns:

  • (nil)

#is_legacyTrueClass

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.

Returns:

  • (TrueClass)

    true if the GL context is in legacy mode

#make_currentnil

Makes the context the current one.

Returns:

  • (nil)

#realizeTrueClass

Realizes the given Gdk::GLContext.

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

Returns:

  • (TrueClass)

    true if the context is realized

#set_required_version(major, minor) ⇒ nil

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.

Parameters:

  • major (Integer)

    the major version to request

  • minor (Integer)

    the minor version to request

Returns:

  • (nil)

#shared_contextGdk::GLContext

The Gdk::GLContext that this context is sharing data with, or nil

Returns:

#shared_context=(shared_context) ⇒ Gdk::GLContext

The Gdk::GLContext that this context is sharing data with, or nil

Parameters:

Returns:

#use_esTrueClass

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

Returns:

  • (TrueClass)

    true if the Gdk::GLContext is using an OpenGL ES profile

#use_es=(use_es) ⇒ nil

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

Parameters:

  • use_es (Integer)

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

Returns:

  • (nil)

#windowGdk::Window

The Gdk::Window the gl context is bound to.

Returns:

#window=(window) ⇒ Gdk::Window

The Gdk::Window the gl context is bound to.

Parameters:

Returns: