[]Struct gdk::GLContext

pub struct GLContext(_, _);

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

GdkGLContexts are created for a Window using WindowExt::create_gl_context, and the context will match the Visual of the window.

A GLContext is not tied to any particular normal framebuffer. For instance, it cannot draw to the 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 GLContext is platform-specific, context creation can fail, returning None context.

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

A GLContext is not realized until either GLContext::make_current, or until it is realized using GLContext::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 WindowExt::create_gl_context by calling GLContext::realize. If the realization fails you have the option to change the settings of the GLContext and try again.

Using a GLContext

You will need to make the 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 GLContext is the current one by using GLContext::get_current; you can also unset any GLContext that is currently set by calling GLContext::clear_current.

Feature: v3_16

Implementations

impl GLContext[src]

pub fn get_debug_enabled(&self) -> bool[src]

Retrieves the value set using GLContext::set_debug_enabled.

Feature: v3_16

Returns

true if debugging is enabled

pub fn get_display(&self) -> Option<Display>[src]

Retrieves the Display the self is created for

Feature: v3_16

Returns

a Display or None

pub fn get_forward_compatible(&self) -> bool[src]

Retrieves the value set using GLContext::set_forward_compatible.

Feature: v3_16

Returns

true if the context should be forward compatible

pub fn get_required_version(&self) -> (i32, i32)[src]

Retrieves the major and minor version requested by calling GLContext::set_required_version.

Feature: v3_16

major

return location for the major version to request

minor

return location for the minor version to request

pub fn get_shared_context(&self) -> Option<GLContext>[src]

Retrieves the GLContext that this self share data with.

Feature: v3_16

Returns

a GLContext or None

pub fn get_use_es(&self) -> bool[src]

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

Feature: v3_22

Returns

true if the GLContext is using an OpenGL ES profile

pub fn get_version(&self) -> (i32, i32)[src]

Retrieves the OpenGL version of the self.

The self must be realized prior to calling this function.

Feature: v3_16

major

return location for the major version

minor

return location for the minor version

pub fn get_window(&self) -> Option<Window>[src]

Retrieves the Window used by the self.

Feature: v3_16

Returns

a Window or None

pub fn is_legacy(&self) -> bool[src]

Whether the GLContext is in legacy mode or not.

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

Feature: v3_20

Returns

true if the GL context is in legacy mode

pub fn make_current(&self)[src]

Makes the self the current one.

Feature: v3_16

pub fn realize(&self) -> Result<(), Error>[src]

Realizes the given GLContext.

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

Feature: v3_16

Returns

true if the context is realized

pub fn set_debug_enabled(&self, enabled: bool)[src]

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

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

Feature: v3_16

enabled

whether to enable debugging in the context

pub fn set_forward_compatible(&self, compatible: bool)[src]

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

Feature: v3_16

compatible

whether the context should be forward compatible

pub fn set_required_version(&self, major: i32, minor: i32)[src]

Sets the major and minor version of OpenGL to request.

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

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

Feature: v3_16

major

the major version to request

minor

the minor version to request

pub fn set_use_es(&self, use_es: i32)[src]

Requests that GDK create a OpenGL ES context instead of an OpenGL one, if the platform and windowing system allows it.

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.

Feature: v3_22

use_es

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

pub fn clear_current()[src]

Clears the current GLContext.

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

Feature: v3_16

pub fn get_current() -> Option<GLContext>[src]

Retrieves the current GLContext.

Feature: v3_16

Returns

the current GLContext, or None

Trait Implementations

impl Clone for GLContext

impl Debug for GLContext

impl Display for GLContext[src]

impl Eq for GLContext

impl Hash for GLContext

impl Ord for GLContext

impl<T: ObjectType> PartialEq<T> for GLContext

impl<T: ObjectType> PartialOrd<T> for GLContext

impl StaticType for GLContext

Auto Trait Implementations

impl RefUnwindSafe for GLContext

impl !Send for GLContext

impl !Sync for GLContext

impl Unpin for GLContext

impl UnwindSafe for GLContext

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<Super, Sub> CanDowncast<Sub> for Super where
    Sub: IsA<Super>,
    Super: IsA<Super>, 

impl<T> Cast for T where
    T: ObjectType, 

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ObjectExt for T where
    T: ObjectType, 

impl<'a, T> ToGlibContainerFromSlice<'a, *const GList> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<List>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<'a, T> ToGlibContainerFromSlice<'a, *const GPtrArray> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<PtrArray>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<'a, T> ToGlibContainerFromSlice<'a, *mut GArray> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<Array>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<'a, T> ToGlibContainerFromSlice<'a, *mut GList> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<List>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<'a, T> ToGlibContainerFromSlice<'a, *mut GPtrArray> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<PtrArray>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToSendValue for T where
    T: ToValue + SetValue + Send + ?Sized

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T> ToValue for T where
    T: SetValue + ?Sized

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.