#[repr(transparent)]pub struct GLContext { /* private fields */ }
Expand description
GLContext
is an object representing the platform-specific
OpenGL drawing context.
GdkGLContexts
are created for a Window
using
Window::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 make_current()
,
or until it is realized using 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 Window::create_gl_context()
by calling realize()
.
If the realization fails you have the option to change the settings of the
GLContext
and try again.
Using a GdkGLContext
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:
⚠️ 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 GLContext
is the current one by using
current()
; you can also unset any GLContext
that is currently set by calling clear_current()
.
This is an Abstract Base Class, you cannot instantiate it.
Implementations
sourceimpl GLContext
impl GLContext
sourcepub fn is_debug_enabled(&self) -> bool
pub fn is_debug_enabled(&self) -> bool
sourcepub fn is_forward_compatible(&self) -> bool
pub fn is_forward_compatible(&self) -> bool
Retrieves the value set using set_forward_compatible()
.
Returns
true
if the context should be forward compatible
sourcepub fn required_version(&self) -> (i32, i32)
pub fn required_version(&self) -> (i32, i32)
Retrieves the major and minor version requested by calling
set_required_version()
.
Returns
major
return location for the major version to request
minor
return location for the minor version to request
sourcepub fn is_legacy(&self) -> bool
pub fn is_legacy(&self) -> bool
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.
Returns
true
if the GL context is in legacy mode
sourcepub fn make_current(&self)
pub fn make_current(&self)
Makes the self
the current one.
sourcepub fn set_debug_enabled(&self, enabled: bool)
pub fn set_debug_enabled(&self, enabled: bool)
sourcepub fn set_forward_compatible(&self, compatible: bool)
pub fn set_forward_compatible(&self, compatible: bool)
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.
compatible
whether the context should be forward compatible
sourcepub fn set_required_version(&self, major: i32, minor: i32)
pub fn set_required_version(&self, major: i32, minor: i32)
sourcepub fn set_use_es(&self, use_es: i32)
pub fn set_use_es(&self, use_es: i32)
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 uses_es()
after
calling realize()
to decide whether to use the OpenGL or
OpenGL ES API, extensions, or shaders.
use_es
whether the context should use OpenGL ES instead of OpenGL, or -1 to allow auto-detection
sourcepub fn clear_current()
pub fn clear_current()
Clears the current GLContext
.
Any OpenGL call after this function returns will be ignored
until make_current()
is called.
Trait Implementations
sourceimpl Ord for GLContext
impl Ord for GLContext
1.21.0 · sourceconst fn max(self, other: Self) -> Self
const fn max(self, other: Self) -> Self
1.21.0 · sourceconst fn min(self, other: Self) -> Self
const fn min(self, other: Self) -> Self
1.50.0 · sourceconst fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
const fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
sourceimpl ParentClassIs for GLContext
impl ParentClassIs for GLContext
sourceimpl<OT: ObjectType> PartialOrd<OT> for GLContext
impl<OT: ObjectType> PartialOrd<OT> for GLContext
sourcefn partial_cmp(&self, other: &OT) -> Option<Ordering>
fn partial_cmp(&self, other: &OT) -> Option<Ordering>
1.0.0 · sourceconst fn le(&self, other: &Rhs) -> bool
const fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresourceimpl StaticType for GLContext
impl StaticType for GLContext
sourcefn static_type() -> Type
fn static_type() -> Type
Self
.impl Eq 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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<T> Cast for Twhere
T: ObjectType,
impl<T> Cast for Twhere
T: ObjectType,
sourcefn upcast<T>(self) -> Twhere
T: ObjectType,
Self: IsA<T>,
fn upcast<T>(self) -> Twhere
T: ObjectType,
Self: IsA<T>,
T
. Read moresourcefn upcast_ref<T>(&self) -> &Twhere
T: ObjectType,
Self: IsA<T>,
fn upcast_ref<T>(&self) -> &Twhere
T: ObjectType,
Self: IsA<T>,
T
. Read moresourcefn downcast<T>(self) -> Result<T, Self>where
T: ObjectType,
Self: CanDowncast<T>,
fn downcast<T>(self) -> Result<T, Self>where
T: ObjectType,
Self: CanDowncast<T>,
T
. Read moresourcefn downcast_ref<T>(&self) -> Option<&T>where
T: ObjectType,
Self: CanDowncast<T>,
fn downcast_ref<T>(&self) -> Option<&T>where
T: ObjectType,
Self: CanDowncast<T>,
T
. Read moresourcefn dynamic_cast<T>(self) -> Result<T, Self>where
T: ObjectType,
fn dynamic_cast<T>(self) -> Result<T, Self>where
T: ObjectType,
T
. This handles upcasting, downcasting
and casting between interface and interface implementors. All checks are performed at
runtime, while downcast
and upcast
will do many checks at compile-time already. Read moresourcefn dynamic_cast_ref<T>(&self) -> Option<&T>where
T: ObjectType,
fn dynamic_cast_ref<T>(&self) -> Option<&T>where
T: ObjectType,
T
. This handles upcasting, downcasting
and casting between interface and interface implementors. All checks are performed at
runtime, while downcast
and upcast
will do many checks at compile-time already. Read moresourceunsafe fn unsafe_cast<T>(self) -> Twhere
T: ObjectType,
unsafe fn unsafe_cast<T>(self) -> Twhere
T: ObjectType,
T
unconditionally. Read moresourceunsafe fn unsafe_cast_ref<T>(&self) -> &Twhere
T: ObjectType,
unsafe fn unsafe_cast_ref<T>(&self) -> &Twhere
T: ObjectType,
&T
unconditionally. Read moresourceimpl<U> IsSubclassableExt for Uwhere
U: IsClass + ParentClassIs,
impl<U> IsSubclassableExt for Uwhere
U: IsClass + ParentClassIs,
fn parent_class_init<T>(class: &mut Class<U>)where
T: ObjectSubclass,
<U as ParentClassIs>::Parent: IsSubclassable<T>,
fn parent_instance_init<T>(instance: &mut InitializingObject<T>)where
T: ObjectSubclass,
<U as ParentClassIs>::Parent: IsSubclassable<T>,
sourceimpl<T> ObjectExt for Twhere
T: ObjectType,
impl<T> ObjectExt for Twhere
T: ObjectType,
sourcefn is<U>(&self) -> boolwhere
U: StaticType,
fn is<U>(&self) -> boolwhere
U: StaticType,
true
if the object is an instance of (can be cast to) T
.sourcefn object_class(&self) -> &Class<Object>
fn object_class(&self) -> &Class<Object>
ObjectClass
of the object. Read moresourcefn class_of<U>(&self) -> Option<&Class<U>>where
U: IsClass,
fn class_of<U>(&self) -> Option<&Class<U>>where
U: IsClass,
T
. Read moresourcefn interface<U>(&self) -> Option<InterfaceRef<'_, U>>where
U: IsInterface,
fn interface<U>(&self) -> Option<InterfaceRef<'_, U>>where
U: IsInterface,
T
of the object. Read moresourcefn set_property<V>(&self, property_name: &str, value: V)where
V: ToValue,
fn set_property<V>(&self, property_name: &str, value: V)where
V: ToValue,
sourcefn set_property_from_value(&self, property_name: &str, value: &Value)
fn set_property_from_value(&self, property_name: &str, value: &Value)
sourcefn set_properties(&self, property_values: &[(&str, &dyn ToValue)])
fn set_properties(&self, property_values: &[(&str, &dyn ToValue)])
sourcefn set_properties_from_value(&self, property_values: &[(&str, Value)])
fn set_properties_from_value(&self, property_values: &[(&str, Value)])
sourcefn property<V>(&self, property_name: &str) -> Vwhere
V: 'static + for<'b> FromValue<'b>,
fn property<V>(&self, property_name: &str) -> Vwhere
V: 'static + for<'b> FromValue<'b>,
property_name
of the object and cast it to the type V. Read moresourcefn property_value(&self, property_name: &str) -> Value
fn property_value(&self, property_name: &str) -> Value
property_name
of the object. Read moresourcefn property_type(&self, property_name: &str) -> Option<Type>
fn property_type(&self, property_name: &str) -> Option<Type>
property_name
of this object. Read moresourcefn find_property(&self, property_name: &str) -> Option<ParamSpec>
fn find_property(&self, property_name: &str) -> Option<ParamSpec>
ParamSpec
of the property property_name
of this object.sourcefn list_properties(&self) -> PtrSlice<ParamSpec>
fn list_properties(&self) -> PtrSlice<ParamSpec>
ParamSpec
of the properties of this object.sourcefn freeze_notify(&self) -> PropertyNotificationFreezeGuard
fn freeze_notify(&self) -> PropertyNotificationFreezeGuard
sourceunsafe fn set_qdata<QD>(&self, key: Quark, value: QD)where
QD: 'static,
unsafe fn set_qdata<QD>(&self, key: Quark, value: QD)where
QD: 'static,
key
. Read moresourceunsafe fn qdata<QD>(&self, key: Quark) -> Option<NonNull<QD>>where
QD: 'static,
unsafe fn qdata<QD>(&self, key: Quark) -> Option<NonNull<QD>>where
QD: 'static,
key
. Read moresourceunsafe fn steal_qdata<QD>(&self, key: Quark) -> Option<QD>where
QD: 'static,
unsafe fn steal_qdata<QD>(&self, key: Quark) -> Option<QD>where
QD: 'static,
key
. Read moresourceunsafe fn set_data<QD>(&self, key: &str, value: QD)where
QD: 'static,
unsafe fn set_data<QD>(&self, key: &str, value: QD)where
QD: 'static,
key
. Read moresourceunsafe fn data<QD>(&self, key: &str) -> Option<NonNull<QD>>where
QD: 'static,
unsafe fn data<QD>(&self, key: &str) -> Option<NonNull<QD>>where
QD: 'static,
key
. Read moresourceunsafe fn steal_data<QD>(&self, key: &str) -> Option<QD>where
QD: 'static,
unsafe fn steal_data<QD>(&self, key: &str) -> Option<QD>where
QD: 'static,
key
. Read moresourcefn block_signal(&self, handler_id: &SignalHandlerId)
fn block_signal(&self, handler_id: &SignalHandlerId)
sourcefn unblock_signal(&self, handler_id: &SignalHandlerId)
fn unblock_signal(&self, handler_id: &SignalHandlerId)
sourcefn stop_signal_emission(&self, signal_id: SignalId, detail: Option<Quark>)
fn stop_signal_emission(&self, signal_id: SignalId, detail: Option<Quark>)
sourcefn stop_signal_emission_by_name(&self, signal_name: &str)
fn stop_signal_emission_by_name(&self, signal_name: &str)
sourcefn connect<F>(
&self,
signal_name: &str,
after: bool,
callback: F
) -> SignalHandlerIdwhere
F: 'static + Fn(&[Value]) -> Option<Value> + Send + Sync,
fn connect<F>(
&self,
signal_name: &str,
after: bool,
callback: F
) -> SignalHandlerIdwhere
F: 'static + Fn(&[Value]) -> Option<Value> + Send + Sync,
signal_name
on this object. Read moresourcefn connect_id<F>(
&self,
signal_id: SignalId,
details: Option<Quark>,
after: bool,
callback: F
) -> SignalHandlerIdwhere
F: 'static + Fn(&[Value]) -> Option<Value> + Send + Sync,
fn connect_id<F>(
&self,
signal_id: SignalId,
details: Option<Quark>,
after: bool,
callback: F
) -> SignalHandlerIdwhere
F: 'static + Fn(&[Value]) -> Option<Value> + Send + Sync,
signal_id
on this object. Read moresourcefn connect_local<F>(
&self,
signal_name: &str,
after: bool,
callback: F
) -> SignalHandlerIdwhere
F: 'static + Fn(&[Value]) -> Option<Value>,
fn connect_local<F>(
&self,
signal_name: &str,
after: bool,
callback: F
) -> SignalHandlerIdwhere
F: 'static + Fn(&[Value]) -> Option<Value>,
signal_name
on this object. Read moresourcefn connect_local_id<F>(
&self,
signal_id: SignalId,
details: Option<Quark>,
after: bool,
callback: F
) -> SignalHandlerIdwhere
F: 'static + Fn(&[Value]) -> Option<Value>,
fn connect_local_id<F>(
&self,
signal_id: SignalId,
details: Option<Quark>,
after: bool,
callback: F
) -> SignalHandlerIdwhere
F: 'static + Fn(&[Value]) -> Option<Value>,
signal_id
on this object. Read moresourceunsafe fn connect_unsafe<F>(
&self,
signal_name: &str,
after: bool,
callback: F
) -> SignalHandlerIdwhere
F: Fn(&[Value]) -> Option<Value>,
unsafe fn connect_unsafe<F>(
&self,
signal_name: &str,
after: bool,
callback: F
) -> SignalHandlerIdwhere
F: Fn(&[Value]) -> Option<Value>,
signal_name
on this object. Read moresourceunsafe fn connect_unsafe_id<F>(
&self,
signal_id: SignalId,
details: Option<Quark>,
after: bool,
callback: F
) -> SignalHandlerIdwhere
F: Fn(&[Value]) -> Option<Value>,
unsafe fn connect_unsafe_id<F>(
&self,
signal_id: SignalId,
details: Option<Quark>,
after: bool,
callback: F
) -> SignalHandlerIdwhere
F: Fn(&[Value]) -> Option<Value>,
signal_id
on this object. Read moresourcefn connect_closure(
&self,
signal_name: &str,
after: bool,
closure: RustClosure
) -> SignalHandlerId
fn connect_closure(
&self,
signal_name: &str,
after: bool,
closure: RustClosure
) -> SignalHandlerId
signal_name
on this object. Read moresourcefn connect_closure_id(
&self,
signal_id: SignalId,
details: Option<Quark>,
after: bool,
closure: RustClosure
) -> SignalHandlerId
fn connect_closure_id(
&self,
signal_id: SignalId,
details: Option<Quark>,
after: bool,
closure: RustClosure
) -> SignalHandlerId
signal_id
on this object. Read moresourcefn watch_closure(&self, closure: &impl AsRef<Closure>)
fn watch_closure(&self, closure: &impl AsRef<Closure>)
closure
to the lifetime of the object. When
the object’s reference count drops to zero, the closure will be
invalidated. An invalidated closure will ignore any calls to
invoke_with_values
, or
invoke
when using Rust closures. Read moresourcefn emit<R>(&self, signal_id: SignalId, args: &[&dyn ToValue]) -> Rwhere
R: TryFromClosureReturnValue,
fn emit<R>(&self, signal_id: SignalId, args: &[&dyn ToValue]) -> Rwhere
R: TryFromClosureReturnValue,
sourcefn emit_with_values(&self, signal_id: SignalId, args: &[Value]) -> Option<Value>
fn emit_with_values(&self, signal_id: SignalId, args: &[Value]) -> Option<Value>
Self::emit
but takes Value
for the arguments.sourcefn emit_by_name<R>(&self, signal_name: &str, args: &[&dyn ToValue]) -> Rwhere
R: TryFromClosureReturnValue,
fn emit_by_name<R>(&self, signal_name: &str, args: &[&dyn ToValue]) -> Rwhere
R: TryFromClosureReturnValue,
sourcefn emit_by_name_with_values(
&self,
signal_name: &str,
args: &[Value]
) -> Option<Value>
fn emit_by_name_with_values(
&self,
signal_name: &str,
args: &[Value]
) -> Option<Value>
sourcefn emit_by_name_with_details<R>(
&self,
signal_name: &str,
details: Quark,
args: &[&dyn ToValue]
) -> Rwhere
R: TryFromClosureReturnValue,
fn emit_by_name_with_details<R>(
&self,
signal_name: &str,
details: Quark,
args: &[&dyn ToValue]
) -> Rwhere
R: TryFromClosureReturnValue,
sourcefn emit_by_name_with_details_and_values(
&self,
signal_name: &str,
details: Quark,
args: &[Value]
) -> Option<Value>
fn emit_by_name_with_details_and_values(
&self,
signal_name: &str,
details: Quark,
args: &[Value]
) -> Option<Value>
sourcefn emit_with_details<R>(
&self,
signal_id: SignalId,
details: Quark,
args: &[&dyn ToValue]
) -> Rwhere
R: TryFromClosureReturnValue,
fn emit_with_details<R>(
&self,
signal_id: SignalId,
details: Quark,
args: &[&dyn ToValue]
) -> Rwhere
R: TryFromClosureReturnValue,
sourcefn emit_with_details_and_values(
&self,
signal_id: SignalId,
details: Quark,
args: &[Value]
) -> Option<Value>
fn emit_with_details_and_values(
&self,
signal_id: SignalId,
details: Quark,
args: &[Value]
) -> Option<Value>
sourcefn disconnect(&self, handler_id: SignalHandlerId)
fn disconnect(&self, handler_id: SignalHandlerId)
sourcefn connect_notify<F>(&self, name: Option<&str>, f: F) -> SignalHandlerIdwhere
F: 'static + Fn(&T, &ParamSpec) + Send + Sync,
fn connect_notify<F>(&self, name: Option<&str>, f: F) -> SignalHandlerIdwhere
F: 'static + Fn(&T, &ParamSpec) + Send + Sync,
notify
signal of the object. Read moresourcefn connect_notify_local<F>(&self, name: Option<&str>, f: F) -> SignalHandlerIdwhere
F: 'static + Fn(&T, &ParamSpec),
fn connect_notify_local<F>(&self, name: Option<&str>, f: F) -> SignalHandlerIdwhere
F: 'static + Fn(&T, &ParamSpec),
notify
signal of the object. Read moresourceunsafe fn connect_notify_unsafe<F>(
&self,
name: Option<&str>,
f: F
) -> SignalHandlerIdwhere
F: Fn(&T, &ParamSpec),
unsafe fn connect_notify_unsafe<F>(
&self,
name: Option<&str>,
f: F
) -> SignalHandlerIdwhere
F: Fn(&T, &ParamSpec),
notify
signal of the object. Read more