class Gdk::GLContext
- Gdk::GLContext
- Gdk::DrawContext
- GObject::Object
- Reference
- Object
Overview
Gdk::GLContext
is an object representing a platform-specific
OpenGL draw context.
Gdk::GLContext
s are created for a surface using
Gdk::Surface#create_gl_context
, and the context will match
the characteristics of the surface.
A Gdk::GLContext
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 Gdk::GLContext
is platform-specific and 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::Surface
,
which you typically get during the realize call of a widget.
A Gdk::GLContext
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 Gdk::GLContext
and try again.
Using a Gdk::GLContext
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:
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 Gdk::GLContext
is the current one by using
Gdk::GLContext#current
; you can also unset any Gdk::GLContext
that is currently set by calling Gdk::GLContext#clear_current
.
Defined in:
lib/gi-crystal/src/auto/gdk-4.0/gl_context.crConstructors
-
.new
Initialize a new
GLContext
. - .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 Summary
-
.clear_current : Nil
Clears the current
Gdk::GLContext
. -
.current : Gdk::GLContext?
Retrieves the current
Gdk::GLContext
. -
.g_type : UInt64
Returns the type id (GType) registered in GLib type system.
Instance Method Summary
-
#allowed_apis : Gdk::GLAPI
Gets the allowed APIs set via gdk_gl_context_set_allowed_apis().
-
#allowed_apis=(apis : Gdk::GLAPI) : Nil
Sets the allowed APIs.
-
#api : Gdk::GLAPI
Gets the API currently in use.
-
#debug_enabled : Bool
Retrieves whether the context is doing extra validations and runtime checking.
-
#debug_enabled=(enabled : Bool) : Nil
Sets whether the
Gdk::GLContext
should perform extra validations and runtime checking. -
#display : Gdk::Display?
Retrieves the display the @context is created for
-
#forward_compatible : Bool
Retrieves whether the context is forward-compatible.
-
#forward_compatible=(compatible : Bool) : Nil
Sets whether the
Gdk::GLContext
should be forward-compatible. -
#is_legacy : Bool
Whether the
Gdk::GLContext
is in legacy mode or not. -
#is_shared(other : Gdk::GLContext) : Bool
Checks if the two GL contexts can share resources.
-
#make_current : Nil
Makes the @context the current one.
-
#realize : Bool
Realizes the given
Gdk::GLContext
. -
#required_version(major : Int32?, minor : Int32?) : Nil
Retrieves required OpenGL version set as a requirement for the @context realization.
-
#set_required_version(major : Int32, minor : Int32) : Nil
Sets the major and minor version of OpenGL to request.
-
#shared_context : Gdk::GLContext?
Used to retrieves the
Gdk::GLContext
that this @context share data with. - #shared_context=(value : Gdk::GLContext?) : Gdk::GLContext?
-
#surface : Gdk::Surface?
Retrieves the surface used by the @context.
-
#use_es : Bool
Checks whether the @context is using an OpenGL or OpenGL ES profile.
-
#use_es=(use_es : Int32) : Nil
Requests that GDK create an OpenGL ES context instead of an OpenGL one.
-
#version(major : Int32, minor : Int32) : Nil
Retrieves the OpenGL version of the @context.
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
newnew(*, 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 : UInt32
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(pointer : Pointer(Void), transfer : GICrystal::Transfer)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
Class Method Detail
Clears the current Gdk::GLContext
.
Any OpenGL call after this function returns will be ignored
until Gdk::GLContext#make_current
is called.
Instance Method Detail
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.
Gets the API currently in use.
If the renderer has not been realized yet, 0 is returned.
Retrieves whether the context is doing extra validations and runtime checking.
Sets whether the Gdk::GLContext
should perform extra validations and
runtime 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.
Retrieves whether the context is forward-compatible.
Sets whether the Gdk::GLContext
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 Gdk::GLContext
must not be realized or made current prior to calling
this function.
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.
Retrieves required OpenGL version set as a requirement for the @context
realization. It will not change even if a greater OpenGL version is supported
and used after the @context is realized. See
Gdk::GLContext#version
for the real version in use.
See Gdk::GLContext#required_version=
.
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 @context must not be realized or made current prior to calling this function.
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.