2014-10-09 08:45:44 +00:00
|
|
|
|
/* GDK - The GIMP Drawing Kit
|
|
|
|
|
*
|
|
|
|
|
* gdkglcontext.c: GL context abstraction
|
2022-05-06 14:40:13 +00:00
|
|
|
|
*
|
2014-10-09 08:45:44 +00:00
|
|
|
|
* Copyright © 2014 Emmanuele Bassi
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Library General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* GdkGLContext:
|
2014-10-09 08:45:44 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* `GdkGLContext` is an object representing a platform-specific
|
2017-12-26 19:10:54 +00:00
|
|
|
|
* OpenGL draw context.
|
2014-10-09 08:45:44 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* `GdkGLContext`s are created for a surface using
|
|
|
|
|
* [method@Gdk.Surface.create_gl_context], and the context will match
|
2021-10-17 20:05:35 +00:00
|
|
|
|
* the characteristics of the surface.
|
2014-10-09 14:09:05 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* A `GdkGLContext` is not tied to any particular normal framebuffer.
|
|
|
|
|
* For instance, it cannot draw to the surface back buffer. The GDK
|
2014-10-12 03:35:52 +00:00
|
|
|
|
* repaint system is in full control of the painting to that. Instead,
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* you can create render buffers or textures and use [func@cairo_draw_from_gl]
|
2014-10-12 03:35:52 +00:00
|
|
|
|
* in the draw function of your widget to draw them. Then GDK will handle
|
|
|
|
|
* the integration of your rendering with that of other widgets.
|
2014-10-09 08:45:44 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* Support for `GdkGLContext` is platform-specific and context creation
|
2014-10-12 03:17:34 +00:00
|
|
|
|
* can fail, returning %NULL context.
|
2014-10-09 08:45:44 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* A `GdkGLContext` has to be made "current" in order to start using
|
2014-10-09 08:45:44 +00:00
|
|
|
|
* it, otherwise any OpenGL call will be ignored.
|
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* ## Creating a new OpenGL context
|
2014-10-09 08:45:44 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* In order to create a new `GdkGLContext` instance you need a `GdkSurface`,
|
|
|
|
|
* which you typically get during the realize call of a widget.
|
2014-10-09 08:45:44 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* A `GdkGLContext` is not realized until either [method@Gdk.GLContext.make_current]
|
|
|
|
|
* or [method@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
|
|
|
|
|
* [method@Gdk.Surface.create_gl_context] by calling [method@Gdk.GLContext.realize].
|
|
|
|
|
* If the realization fails you have the option to change the settings of
|
|
|
|
|
* the `GdkGLContext` and try again.
|
2015-02-09 16:09:25 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* ## Using a GdkGLContext
|
2014-10-09 08:45:44 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* 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:
|
2014-10-09 08:45:44 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* ```c
|
|
|
|
|
* gdk_gl_context_make_current (context);
|
|
|
|
|
* ```
|
2014-10-09 08:45:44 +00:00
|
|
|
|
*
|
|
|
|
|
* You can now perform your drawing using OpenGL commands.
|
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* You can check which `GdkGLContext` is the current one by using
|
|
|
|
|
* [func@Gdk.GLContext.get_current]; you can also unset any `GdkGLContext`
|
|
|
|
|
* that is currently set by calling [func@Gdk.GLContext.clear_current].
|
2017-12-26 19:39:24 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2014-10-09 08:45:44 +00:00
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#include "gdkglcontextprivate.h"
|
2021-09-23 23:47:03 +00:00
|
|
|
|
|
|
|
|
|
#include "gdkdebug.h"
|
2014-10-09 08:45:44 +00:00
|
|
|
|
#include "gdkdisplayprivate.h"
|
|
|
|
|
#include "gdkintl.h"
|
2021-09-22 00:01:41 +00:00
|
|
|
|
#include "gdkmemoryformatprivate.h"
|
2021-09-23 23:47:03 +00:00
|
|
|
|
#include "gdkmemorytextureprivate.h"
|
2021-10-05 22:34:10 +00:00
|
|
|
|
#include "gdkprofilerprivate.h"
|
2021-09-23 23:47:03 +00:00
|
|
|
|
|
2014-11-07 14:27:56 +00:00
|
|
|
|
#include "gdk-private.h"
|
2014-10-09 08:45:44 +00:00
|
|
|
|
|
2018-07-31 10:18:59 +00:00
|
|
|
|
#ifdef GDK_WINDOWING_WIN32
|
|
|
|
|
# include "gdk/win32/gdkwin32.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-10-27 20:12:40 +00:00
|
|
|
|
#include <epoxy/gl.h>
|
2021-10-05 22:34:10 +00:00
|
|
|
|
#ifdef HAVE_EGL
|
|
|
|
|
#include <epoxy/egl.h>
|
|
|
|
|
#endif
|
2014-10-27 20:12:40 +00:00
|
|
|
|
|
2021-10-07 15:59:17 +00:00
|
|
|
|
#define DEFAULT_ALLOWED_APIS GDK_GL_API_GL | GDK_GL_API_GLES
|
|
|
|
|
|
2014-10-09 08:45:44 +00:00
|
|
|
|
typedef struct {
|
2015-01-28 09:34:16 +00:00
|
|
|
|
int major;
|
|
|
|
|
int minor;
|
2015-02-12 14:28:22 +00:00
|
|
|
|
int gl_version;
|
2015-01-28 09:34:16 +00:00
|
|
|
|
|
2019-04-24 11:25:46 +00:00
|
|
|
|
guint has_khr_debug : 1;
|
2019-04-24 13:23:32 +00:00
|
|
|
|
guint use_khr_debug : 1;
|
2016-04-22 16:27:04 +00:00
|
|
|
|
guint has_unpack_subimage : 1;
|
2018-03-25 13:28:40 +00:00
|
|
|
|
guint has_debug_output : 1;
|
GL: Split GL context creation in two phases
One of the major requests by OpenGL users has been the ability to
specify settings when creating a GL context, like the version to use
or whether the debug support should be enabled.
We have a couple of requirements in terms of API:
• avoid, if at all possible, the "C arrays of integers with
attribute, value pairs", which are hard to write and hard
to bind in non-C languages.
• allow failing in a recoverable way.
• do not make the GL context creation API a mess of arguments.
Looking at prior art, it seems that a common pattern is to split the
construction phase in two:
• a first phase that creates a GL context wrapper object and
does preliminary checks on the environment.
• a second phase that creates the backend-specific GL object.
We adopted a similar pattern:
• gdk_window_create_gl_context() creates a GdkGLContext
• gdk_gl_context_realize() creates the underlying resources
Calling gdk_gl_context_make_current() also realizes the context, so
simple GL users do not need to care. Advanced users will want to
call gdk_window_create_gl_context(), set up the optional requirements,
and then call gdk_gl_context_realize(). If either of these two steps
fails, it's possible to recover by changing the requirements, or simply
creating a new GdkGLContext instance.
https://bugzilla.gnome.org/show_bug.cgi?id=741946
2015-01-27 21:23:23 +00:00
|
|
|
|
guint extensions_checked : 1;
|
2015-01-28 09:34:16 +00:00
|
|
|
|
guint debug_enabled : 1;
|
|
|
|
|
guint forward_compatible : 1;
|
2015-10-06 17:54:58 +00:00
|
|
|
|
guint is_legacy : 1;
|
2016-10-19 12:43:17 +00:00
|
|
|
|
|
2021-10-07 15:59:17 +00:00
|
|
|
|
GdkGLAPI allowed_apis;
|
2021-10-07 20:10:39 +00:00
|
|
|
|
GdkGLAPI api;
|
2014-10-27 20:12:40 +00:00
|
|
|
|
|
2019-04-27 07:49:41 +00:00
|
|
|
|
int max_debug_label_length;
|
2021-10-05 22:34:10 +00:00
|
|
|
|
|
|
|
|
|
#ifdef HAVE_EGL
|
|
|
|
|
EGLContext egl_context;
|
2022-03-03 06:59:23 +00:00
|
|
|
|
EGLBoolean (*eglSwapBuffersWithDamage) (EGLDisplay, EGLSurface, const EGLint *, EGLint);
|
2021-10-05 22:34:10 +00:00
|
|
|
|
#endif
|
2014-10-09 08:45:44 +00:00
|
|
|
|
} GdkGLContextPrivate;
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
PROP_0,
|
|
|
|
|
|
2021-10-07 15:59:17 +00:00
|
|
|
|
PROP_ALLOWED_APIS,
|
2021-10-07 21:03:45 +00:00
|
|
|
|
PROP_API,
|
2014-10-30 11:04:23 +00:00
|
|
|
|
PROP_SHARED_CONTEXT,
|
2014-10-09 08:45:44 +00:00
|
|
|
|
|
|
|
|
|
LAST_PROP
|
|
|
|
|
};
|
|
|
|
|
|
2021-10-07 15:59:17 +00:00
|
|
|
|
static GParamSpec *properties[LAST_PROP] = { NULL, };
|
2014-10-09 08:45:44 +00:00
|
|
|
|
|
|
|
|
|
G_DEFINE_QUARK (gdk-gl-error-quark, gdk_gl_error)
|
|
|
|
|
|
2016-11-28 16:36:37 +00:00
|
|
|
|
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GdkGLContext, gdk_gl_context, GDK_TYPE_DRAW_CONTEXT)
|
2014-10-09 08:45:44 +00:00
|
|
|
|
|
2021-07-06 02:47:15 +00:00
|
|
|
|
typedef struct _MaskedContext MaskedContext;
|
|
|
|
|
|
|
|
|
|
static inline MaskedContext *
|
2021-07-07 02:40:34 +00:00
|
|
|
|
mask_context (GdkGLContext *context,
|
|
|
|
|
gboolean surfaceless)
|
2021-07-06 02:47:15 +00:00
|
|
|
|
{
|
2021-07-07 02:40:34 +00:00
|
|
|
|
return (MaskedContext *) GSIZE_TO_POINTER (GPOINTER_TO_SIZE (context) | (surfaceless ? 1 : 0));
|
2021-07-06 02:47:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline GdkGLContext *
|
|
|
|
|
unmask_context (MaskedContext *mask)
|
|
|
|
|
{
|
|
|
|
|
return GDK_GL_CONTEXT (GSIZE_TO_POINTER (GPOINTER_TO_SIZE (mask) & ~(gsize) 1));
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-22 18:49:13 +00:00
|
|
|
|
static inline gboolean
|
|
|
|
|
mask_is_surfaceless (MaskedContext *mask)
|
|
|
|
|
{
|
|
|
|
|
return GPOINTER_TO_SIZE (mask) & (gsize) 1;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-06 02:47:15 +00:00
|
|
|
|
static void
|
|
|
|
|
unref_unmasked (gpointer data)
|
|
|
|
|
{
|
|
|
|
|
g_object_unref (unmask_context (data));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GPrivate thread_current_context = G_PRIVATE_INIT (unref_unmasked);
|
2014-10-30 10:46:09 +00:00
|
|
|
|
|
2018-04-08 22:58:31 +00:00
|
|
|
|
static void
|
|
|
|
|
gdk_gl_context_clear_old_updated_area (GdkGLContext *context)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
|
{
|
|
|
|
|
g_clear_pointer (&context->old_updated_area[i], cairo_region_destroy);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-09 08:45:44 +00:00
|
|
|
|
static void
|
|
|
|
|
gdk_gl_context_dispose (GObject *gobject)
|
|
|
|
|
{
|
|
|
|
|
GdkGLContext *context = GDK_GL_CONTEXT (gobject);
|
2021-10-05 22:34:10 +00:00
|
|
|
|
#ifdef HAVE_EGL
|
|
|
|
|
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
|
|
|
|
|
|
|
|
|
|
if (priv->egl_context != NULL)
|
|
|
|
|
{
|
2022-01-06 18:23:29 +00:00
|
|
|
|
GdkDisplay *display = gdk_draw_context_get_display (GDK_DRAW_CONTEXT (context));
|
2021-10-05 22:34:10 +00:00
|
|
|
|
EGLDisplay *egl_display = gdk_display_get_egl_display (display);
|
|
|
|
|
|
|
|
|
|
if (eglGetCurrentContext () == priv->egl_context)
|
|
|
|
|
eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
|
|
|
|
|
|
|
|
|
GDK_DISPLAY_NOTE (display, OPENGL, g_message ("Destroying EGL context"));
|
|
|
|
|
|
|
|
|
|
eglDestroyContext (egl_display, priv->egl_context);
|
|
|
|
|
priv->egl_context = NULL;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2014-10-09 08:45:44 +00:00
|
|
|
|
|
2018-04-08 22:58:31 +00:00
|
|
|
|
gdk_gl_context_clear_old_updated_area (context);
|
|
|
|
|
|
2014-10-09 08:45:44 +00:00
|
|
|
|
G_OBJECT_CLASS (gdk_gl_context_parent_class)->dispose (gobject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2021-10-07 15:59:17 +00:00
|
|
|
|
gdk_gl_context_set_property (GObject *object,
|
2014-10-09 08:45:44 +00:00
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
2021-10-07 15:59:17 +00:00
|
|
|
|
GdkGLContext *self = GDK_GL_CONTEXT (object);
|
|
|
|
|
|
2014-10-09 08:45:44 +00:00
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
2021-10-07 15:59:17 +00:00
|
|
|
|
case PROP_ALLOWED_APIS:
|
|
|
|
|
gdk_gl_context_set_allowed_apis (self, g_value_get_flags (value));
|
|
|
|
|
break;
|
|
|
|
|
|
2014-10-30 11:04:23 +00:00
|
|
|
|
case PROP_SHARED_CONTEXT:
|
2021-07-10 01:24:00 +00:00
|
|
|
|
g_assert (g_value_get_object (value) == NULL);
|
2014-10-30 11:04:23 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2014-10-09 08:45:44 +00:00
|
|
|
|
default:
|
2021-10-07 15:59:17 +00:00
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2014-10-09 08:45:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2021-10-07 15:59:17 +00:00
|
|
|
|
gdk_gl_context_get_property (GObject *object,
|
2014-10-09 08:45:44 +00:00
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
2021-10-07 15:59:17 +00:00
|
|
|
|
GdkGLContext *self = GDK_GL_CONTEXT (object);
|
|
|
|
|
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (self);
|
|
|
|
|
|
2014-10-09 08:45:44 +00:00
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
2021-10-07 15:59:17 +00:00
|
|
|
|
case PROP_ALLOWED_APIS:
|
|
|
|
|
g_value_set_flags (value, priv->allowed_apis);
|
|
|
|
|
break;
|
|
|
|
|
|
2021-10-07 21:03:45 +00:00
|
|
|
|
case PROP_API:
|
|
|
|
|
g_value_set_flags (value, priv->api);
|
|
|
|
|
break;
|
|
|
|
|
|
2014-10-30 11:04:23 +00:00
|
|
|
|
case PROP_SHARED_CONTEXT:
|
2021-07-10 01:24:00 +00:00
|
|
|
|
g_value_set_object (value, NULL);
|
2014-10-30 11:04:23 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2014-10-09 08:45:44 +00:00
|
|
|
|
default:
|
2021-10-07 15:59:17 +00:00
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2014-10-09 08:45:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-05 22:34:10 +00:00
|
|
|
|
#define N_EGL_ATTRS 16
|
|
|
|
|
|
2021-10-07 20:10:39 +00:00
|
|
|
|
static GdkGLAPI
|
2022-05-06 14:40:13 +00:00
|
|
|
|
gdk_gl_context_realize_egl (GdkGLContext *context,
|
|
|
|
|
GError **error)
|
2016-05-23 07:31:47 +00:00
|
|
|
|
{
|
2021-10-05 22:34:10 +00:00
|
|
|
|
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
|
|
|
|
|
GdkDisplay *display = gdk_gl_context_get_display (context);
|
|
|
|
|
EGLDisplay egl_display = gdk_display_get_egl_display (display);
|
|
|
|
|
|
2022-05-06 14:40:13 +00:00
|
|
|
|
EGLConfig egl_config;
|
|
|
|
|
GdkGLContext *share = gdk_display_get_gl_context (display);
|
|
|
|
|
GdkGLContextPrivate *share_priv = gdk_gl_context_get_instance_private (share);
|
|
|
|
|
EGLContext ctx;
|
|
|
|
|
EGLint context_attribs[N_EGL_ATTRS];
|
|
|
|
|
int major, minor, flags;
|
|
|
|
|
gboolean debug_bit, forward_bit, legacy_bit;
|
|
|
|
|
GdkGLAPI api;
|
|
|
|
|
int i = 0;
|
|
|
|
|
G_GNUC_UNUSED gint64 start_time = GDK_PROFILER_CURRENT_TIME;
|
|
|
|
|
|
|
|
|
|
if (share != NULL)
|
|
|
|
|
gdk_gl_context_get_required_version (share, &major, &minor);
|
|
|
|
|
else
|
|
|
|
|
gdk_gl_context_get_required_version (context, &major, &minor);
|
2022-01-17 09:27:10 +00:00
|
|
|
|
|
2022-05-06 14:40:13 +00:00
|
|
|
|
debug_bit = gdk_gl_context_get_debug_enabled (context);
|
|
|
|
|
forward_bit = gdk_gl_context_get_forward_compatible (context);
|
|
|
|
|
legacy_bit = GDK_DISPLAY_DEBUG_CHECK (display, GL_LEGACY) ||
|
|
|
|
|
(share != NULL && gdk_gl_context_is_legacy (share));
|
2021-10-05 22:34:10 +00:00
|
|
|
|
|
2022-05-06 14:40:13 +00:00
|
|
|
|
if (display->have_egl_no_config_context)
|
|
|
|
|
egl_config = NULL;
|
|
|
|
|
else
|
|
|
|
|
egl_config = gdk_display_get_egl_config (display);
|
2021-10-06 00:41:31 +00:00
|
|
|
|
|
2022-05-06 14:40:13 +00:00
|
|
|
|
flags = 0;
|
2021-10-05 22:34:10 +00:00
|
|
|
|
|
2022-05-06 14:40:13 +00:00
|
|
|
|
if (debug_bit)
|
|
|
|
|
flags |= EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR;
|
|
|
|
|
if (forward_bit)
|
|
|
|
|
flags |= EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR;
|
2021-10-05 22:34:10 +00:00
|
|
|
|
|
2022-05-06 14:40:13 +00:00
|
|
|
|
if (gdk_gl_context_is_api_allowed (context, GDK_GL_API_GL, NULL) &&
|
|
|
|
|
eglBindAPI (EGL_OPENGL_API))
|
|
|
|
|
{
|
|
|
|
|
/* We want a core profile, unless in legacy mode */
|
|
|
|
|
context_attribs[i++] = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR;
|
|
|
|
|
context_attribs[i++] = legacy_bit
|
|
|
|
|
? EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR
|
|
|
|
|
: EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR;
|
|
|
|
|
|
|
|
|
|
/* Specify the version */
|
|
|
|
|
context_attribs[i++] = EGL_CONTEXT_MAJOR_VERSION_KHR;
|
|
|
|
|
context_attribs[i++] = legacy_bit ? 3 : major;
|
|
|
|
|
context_attribs[i++] = EGL_CONTEXT_MINOR_VERSION_KHR;
|
|
|
|
|
context_attribs[i++] = legacy_bit ? 0 : minor;
|
|
|
|
|
api = GDK_GL_API_GL;
|
|
|
|
|
}
|
|
|
|
|
else if (gdk_gl_context_is_api_allowed (context, GDK_GL_API_GLES, NULL) &&
|
|
|
|
|
eglBindAPI (EGL_OPENGL_ES_API))
|
|
|
|
|
{
|
|
|
|
|
context_attribs[i++] = EGL_CONTEXT_CLIENT_VERSION;
|
|
|
|
|
if (major == 3)
|
|
|
|
|
context_attribs[i++] = 3;
|
2021-10-06 00:36:59 +00:00
|
|
|
|
else
|
2022-05-06 14:40:13 +00:00
|
|
|
|
context_attribs[i++] = 2;
|
|
|
|
|
api = GDK_GL_API_GLES;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
g_set_error_literal (error, GDK_GL_ERROR, GDK_GL_ERROR_NOT_AVAILABLE,
|
|
|
|
|
_("The EGL implementation does not support any allowed APIs"));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2021-10-05 22:34:10 +00:00
|
|
|
|
|
2022-05-06 14:40:13 +00:00
|
|
|
|
/* Specify the flags */
|
|
|
|
|
context_attribs[i++] = EGL_CONTEXT_FLAGS_KHR;
|
|
|
|
|
context_attribs[i++] = flags;
|
|
|
|
|
|
|
|
|
|
context_attribs[i++] = EGL_NONE;
|
|
|
|
|
g_assert (i < N_EGL_ATTRS);
|
|
|
|
|
|
|
|
|
|
GDK_DISPLAY_NOTE (display, OPENGL,
|
|
|
|
|
g_message ("Creating EGL context version %d.%d (debug:%s, forward:%s, legacy:%s, es:%s)",
|
|
|
|
|
major, minor,
|
|
|
|
|
debug_bit ? "yes" : "no",
|
|
|
|
|
forward_bit ? "yes" : "no",
|
|
|
|
|
legacy_bit ? "yes" : "no",
|
|
|
|
|
api == GDK_GL_API_GLES ? "yes" : "no"));
|
|
|
|
|
|
|
|
|
|
ctx = eglCreateContext (egl_display,
|
|
|
|
|
egl_config,
|
|
|
|
|
share != NULL ? share_priv->egl_context
|
|
|
|
|
: EGL_NO_CONTEXT,
|
|
|
|
|
context_attribs);
|
|
|
|
|
|
|
|
|
|
/* If context creation failed without the ES bit, let's try again with it */
|
|
|
|
|
if (ctx == NULL && gdk_gl_context_is_api_allowed (context, GDK_GL_API_GLES, NULL) && eglBindAPI (EGL_OPENGL_ES_API))
|
|
|
|
|
{
|
|
|
|
|
i = 0;
|
|
|
|
|
context_attribs[i++] = EGL_CONTEXT_MAJOR_VERSION;
|
|
|
|
|
context_attribs[i++] = 2;
|
|
|
|
|
context_attribs[i++] = EGL_CONTEXT_MINOR_VERSION;
|
|
|
|
|
context_attribs[i++] = 0;
|
2021-10-05 22:34:10 +00:00
|
|
|
|
context_attribs[i++] = EGL_CONTEXT_FLAGS_KHR;
|
2022-05-06 14:40:13 +00:00
|
|
|
|
context_attribs[i++] = flags & ~EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR;
|
2021-10-05 22:34:10 +00:00
|
|
|
|
context_attribs[i++] = EGL_NONE;
|
|
|
|
|
g_assert (i < N_EGL_ATTRS);
|
|
|
|
|
|
2022-05-06 14:40:13 +00:00
|
|
|
|
legacy_bit = FALSE;
|
|
|
|
|
api = GDK_GL_API_GLES;
|
|
|
|
|
|
2021-10-05 22:34:10 +00:00
|
|
|
|
GDK_DISPLAY_NOTE (display, OPENGL,
|
2022-05-06 14:40:13 +00:00
|
|
|
|
g_message ("eglCreateContext failed, switching to OpenGL ES"));
|
|
|
|
|
ctx = eglCreateContext (egl_display,
|
|
|
|
|
egl_config,
|
|
|
|
|
share != NULL ? share_priv->egl_context
|
|
|
|
|
: EGL_NO_CONTEXT,
|
|
|
|
|
context_attribs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If context creation failed without the legacy bit, let's try again with it */
|
|
|
|
|
if (ctx == NULL && gdk_gl_context_is_api_allowed (context, GDK_GL_API_GL, NULL) && eglBindAPI (EGL_OPENGL_API))
|
|
|
|
|
{
|
|
|
|
|
i = 0;
|
|
|
|
|
context_attribs[i++] = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR;
|
|
|
|
|
context_attribs[i++] = EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR;
|
|
|
|
|
context_attribs[i++] = EGL_CONTEXT_MAJOR_VERSION;
|
|
|
|
|
context_attribs[i++] = 3;
|
|
|
|
|
context_attribs[i++] = EGL_CONTEXT_MINOR_VERSION;
|
|
|
|
|
context_attribs[i++] = 0;
|
|
|
|
|
context_attribs[i++] = EGL_CONTEXT_FLAGS_KHR;
|
|
|
|
|
context_attribs[i++] = flags & ~EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR;
|
|
|
|
|
context_attribs[i++] = EGL_NONE;
|
|
|
|
|
g_assert (i < N_EGL_ATTRS);
|
2021-10-05 22:34:10 +00:00
|
|
|
|
|
2022-05-06 14:40:13 +00:00
|
|
|
|
legacy_bit = TRUE;
|
|
|
|
|
api = GDK_GL_API_GL;
|
|
|
|
|
|
|
|
|
|
GDK_DISPLAY_NOTE (display, OPENGL,
|
|
|
|
|
g_message ("eglCreateContext failed, switching to legacy"));
|
2021-10-05 22:34:10 +00:00
|
|
|
|
ctx = eglCreateContext (egl_display,
|
|
|
|
|
egl_config,
|
|
|
|
|
share != NULL ? share_priv->egl_context
|
2022-05-06 14:40:13 +00:00
|
|
|
|
: EGL_NO_CONTEXT,
|
2021-10-05 22:34:10 +00:00
|
|
|
|
context_attribs);
|
2022-05-06 14:40:13 +00:00
|
|
|
|
}
|
2021-10-05 22:34:10 +00:00
|
|
|
|
|
2022-05-06 14:40:13 +00:00
|
|
|
|
if (ctx == NULL)
|
|
|
|
|
{
|
|
|
|
|
g_set_error_literal (error, GDK_GL_ERROR,
|
|
|
|
|
GDK_GL_ERROR_NOT_AVAILABLE,
|
|
|
|
|
_("Unable to create a GL context"));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2021-10-05 22:34:10 +00:00
|
|
|
|
|
2022-05-06 14:40:13 +00:00
|
|
|
|
GDK_DISPLAY_NOTE (display, OPENGL, g_message ("Created EGL context[%p]", ctx));
|
2021-10-05 22:34:10 +00:00
|
|
|
|
|
2022-05-06 14:40:13 +00:00
|
|
|
|
priv->egl_context = ctx;
|
2021-10-05 22:34:10 +00:00
|
|
|
|
|
2022-05-06 14:40:13 +00:00
|
|
|
|
gdk_gl_context_set_is_legacy (context, legacy_bit);
|
2021-10-05 22:34:10 +00:00
|
|
|
|
|
2022-05-06 14:40:13 +00:00
|
|
|
|
if (epoxy_has_egl_extension (egl_display, "EGL_KHR_swap_buffers_with_damage"))
|
|
|
|
|
priv->eglSwapBuffersWithDamage = (gpointer)epoxy_eglGetProcAddress ("eglSwapBuffersWithDamageKHR");
|
|
|
|
|
else if (epoxy_has_egl_extension (egl_display, "EGL_EXT_swap_buffers_with_damage"))
|
|
|
|
|
priv->eglSwapBuffersWithDamage = (gpointer)epoxy_eglGetProcAddress ("eglSwapBuffersWithDamageEXT");
|
2021-10-05 22:34:10 +00:00
|
|
|
|
|
2022-05-06 14:40:13 +00:00
|
|
|
|
gdk_profiler_end_mark (start_time, "realize GdkWaylandGLContext", NULL);
|
2021-10-05 22:34:10 +00:00
|
|
|
|
|
2022-05-06 14:40:13 +00:00
|
|
|
|
return api;
|
|
|
|
|
}
|
2022-03-03 06:59:23 +00:00
|
|
|
|
|
2022-05-06 14:40:13 +00:00
|
|
|
|
static GdkGLAPI
|
|
|
|
|
gdk_gl_context_default_realize (GdkGLContext *context,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
#ifdef HAVE_EGL
|
|
|
|
|
GdkDisplay *display = gdk_gl_context_get_display (context);
|
2021-10-05 22:34:10 +00:00
|
|
|
|
|
2022-05-06 14:40:13 +00:00
|
|
|
|
if (gdk_display_get_egl_display (display))
|
|
|
|
|
return gdk_gl_context_realize_egl (context, error);
|
2021-10-05 22:34:10 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2016-05-23 07:31:47 +00:00
|
|
|
|
g_set_error_literal (error, GDK_GL_ERROR, GDK_GL_ERROR_NOT_AVAILABLE,
|
2021-10-06 00:36:59 +00:00
|
|
|
|
_("The current backend does not support OpenGL"));
|
2021-10-07 20:10:39 +00:00
|
|
|
|
return 0;
|
2016-05-23 07:31:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-05 22:34:10 +00:00
|
|
|
|
#undef N_EGL_ATTRS
|
|
|
|
|
|
2016-12-04 15:33:13 +00:00
|
|
|
|
static cairo_region_t *
|
|
|
|
|
gdk_gl_context_real_get_damage (GdkGLContext *context)
|
|
|
|
|
{
|
2018-03-20 14:14:10 +00:00
|
|
|
|
GdkSurface *surface = gdk_draw_context_get_surface (GDK_DRAW_CONTEXT (context));
|
2021-10-05 22:34:10 +00:00
|
|
|
|
#ifdef HAVE_EGL
|
|
|
|
|
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
|
|
|
|
|
GdkDisplay *display = gdk_draw_context_get_display (GDK_DRAW_CONTEXT (context));
|
|
|
|
|
|
|
|
|
|
if (priv->egl_context && display->have_egl_buffer_age)
|
|
|
|
|
{
|
|
|
|
|
EGLSurface egl_surface;
|
|
|
|
|
int buffer_age = 0;
|
|
|
|
|
egl_surface = gdk_surface_get_egl_surface (surface);
|
|
|
|
|
gdk_gl_context_make_current (context);
|
|
|
|
|
eglQuerySurface (gdk_display_get_egl_display (display), egl_surface,
|
|
|
|
|
EGL_BUFFER_AGE_EXT, &buffer_age);
|
|
|
|
|
|
|
|
|
|
switch (buffer_age)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
return cairo_region_create ();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
if (context->old_updated_area[0])
|
|
|
|
|
return cairo_region_copy (context->old_updated_area[0]);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
if (context->old_updated_area[0] &&
|
|
|
|
|
context->old_updated_area[1])
|
|
|
|
|
{
|
|
|
|
|
cairo_region_t *damage = cairo_region_copy (context->old_updated_area[0]);
|
|
|
|
|
cairo_region_union (damage, context->old_updated_area[1]);
|
|
|
|
|
return damage;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2016-12-04 15:33:13 +00:00
|
|
|
|
|
|
|
|
|
return cairo_region_create_rectangle (&(GdkRectangle) {
|
|
|
|
|
0, 0,
|
2018-03-20 14:14:10 +00:00
|
|
|
|
gdk_surface_get_width (surface),
|
|
|
|
|
gdk_surface_get_height (surface)
|
2016-12-04 15:33:13 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-30 02:52:35 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
gdk_gl_context_real_is_shared (GdkGLContext *self,
|
|
|
|
|
GdkGLContext *other)
|
|
|
|
|
{
|
|
|
|
|
if (gdk_draw_context_get_display (GDK_DRAW_CONTEXT (self)) != gdk_draw_context_get_display (GDK_DRAW_CONTEXT (other)))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
/* XXX: Should we check es or legacy here? */
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-05 22:34:10 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
gdk_gl_context_real_clear_current (GdkGLContext *context)
|
|
|
|
|
{
|
|
|
|
|
GdkDisplay *display = gdk_gl_context_get_display (context);
|
|
|
|
|
#ifdef HAVE_EGL
|
|
|
|
|
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
|
|
|
|
|
|
|
|
|
|
if (priv->egl_context == NULL)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
return eglMakeCurrent (gdk_display_get_egl_display (display),
|
|
|
|
|
EGL_NO_SURFACE,
|
|
|
|
|
EGL_NO_SURFACE,
|
|
|
|
|
EGL_NO_CONTEXT);
|
|
|
|
|
#else
|
|
|
|
|
return FALSE;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
gdk_gl_context_real_make_current (GdkGLContext *context,
|
|
|
|
|
gboolean surfaceless)
|
|
|
|
|
{
|
|
|
|
|
#ifdef HAVE_EGL
|
|
|
|
|
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
|
|
|
|
|
GdkDisplay *display = gdk_gl_context_get_display (context);
|
|
|
|
|
EGLSurface egl_surface;
|
|
|
|
|
|
|
|
|
|
if (priv->egl_context == NULL)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (!surfaceless)
|
|
|
|
|
egl_surface = gdk_surface_get_egl_surface (gdk_gl_context_get_surface (context));
|
|
|
|
|
else
|
|
|
|
|
egl_surface = EGL_NO_SURFACE;
|
|
|
|
|
|
|
|
|
|
return eglMakeCurrent (gdk_display_get_egl_display (display),
|
|
|
|
|
egl_surface,
|
|
|
|
|
egl_surface,
|
|
|
|
|
priv->egl_context);
|
|
|
|
|
#else
|
|
|
|
|
return FALSE;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-01 00:38:20 +00:00
|
|
|
|
static void
|
|
|
|
|
gdk_gl_context_real_begin_frame (GdkDrawContext *draw_context,
|
2021-10-06 16:25:30 +00:00
|
|
|
|
gboolean prefers_high_depth,
|
2016-12-01 00:38:20 +00:00
|
|
|
|
cairo_region_t *region)
|
|
|
|
|
{
|
|
|
|
|
GdkGLContext *context = GDK_GL_CONTEXT (draw_context);
|
2021-10-06 01:33:24 +00:00
|
|
|
|
G_GNUC_UNUSED GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
|
2018-03-20 14:14:10 +00:00
|
|
|
|
GdkSurface *surface;
|
2016-12-04 15:33:13 +00:00
|
|
|
|
cairo_region_t *damage;
|
2016-12-01 00:38:20 +00:00
|
|
|
|
int ww, wh;
|
|
|
|
|
|
2021-10-06 01:33:24 +00:00
|
|
|
|
surface = gdk_draw_context_get_surface (draw_context);
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_EGL
|
|
|
|
|
if (priv->egl_context)
|
2021-10-06 16:25:30 +00:00
|
|
|
|
gdk_surface_ensure_egl_surface (surface, prefers_high_depth);
|
2021-10-06 01:33:24 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2018-04-20 15:04:36 +00:00
|
|
|
|
damage = GDK_GL_CONTEXT_GET_CLASS (context)->get_damage (context);
|
2019-05-18 14:54:27 +00:00
|
|
|
|
|
|
|
|
|
if (context->old_updated_area[1])
|
|
|
|
|
cairo_region_destroy (context->old_updated_area[1]);
|
|
|
|
|
context->old_updated_area[1] = context->old_updated_area[0];
|
|
|
|
|
context->old_updated_area[0] = cairo_region_copy (region);
|
|
|
|
|
|
2016-12-04 15:33:13 +00:00
|
|
|
|
cairo_region_union (region, damage);
|
|
|
|
|
cairo_region_destroy (damage);
|
|
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
|
ww = gdk_surface_get_width (surface) * gdk_surface_get_scale_factor (surface);
|
|
|
|
|
wh = gdk_surface_get_height (surface) * gdk_surface_get_scale_factor (surface);
|
2016-12-01 00:38:20 +00:00
|
|
|
|
|
|
|
|
|
gdk_gl_context_make_current (context);
|
|
|
|
|
|
|
|
|
|
/* Initial setup */
|
|
|
|
|
glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
|
|
|
|
|
glDisable (GL_DEPTH_TEST);
|
|
|
|
|
glDisable (GL_BLEND);
|
|
|
|
|
glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
|
|
|
|
|
glViewport (0, 0, ww, wh);
|
2021-11-03 18:49:57 +00:00
|
|
|
|
|
|
|
|
|
#ifdef HAVE_EGL
|
2021-12-25 13:43:33 +00:00
|
|
|
|
if (priv->egl_context && gdk_gl_context_check_version (context, 0, 0, 3, 0))
|
|
|
|
|
glDrawBuffers (1, (GLenum[1]) { gdk_gl_context_get_use_es (context) ? GL_BACK : GL_BACK_LEFT });
|
2021-11-03 18:49:57 +00:00
|
|
|
|
#endif
|
2016-12-01 00:38:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gdk_gl_context_real_end_frame (GdkDrawContext *draw_context,
|
2018-04-23 21:26:14 +00:00
|
|
|
|
cairo_region_t *painted)
|
2016-12-01 00:38:20 +00:00
|
|
|
|
{
|
2021-10-05 22:34:10 +00:00
|
|
|
|
#ifdef HAVE_EGL
|
|
|
|
|
GdkGLContext *context = GDK_GL_CONTEXT (draw_context);
|
|
|
|
|
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
|
|
|
|
|
GdkSurface *surface = gdk_gl_context_get_surface (context);
|
|
|
|
|
GdkDisplay *display = gdk_surface_get_display (surface);
|
|
|
|
|
EGLSurface egl_surface;
|
|
|
|
|
|
|
|
|
|
if (priv->egl_context == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
gdk_gl_context_make_current (context);
|
|
|
|
|
|
|
|
|
|
egl_surface = gdk_surface_get_egl_surface (surface);
|
|
|
|
|
|
|
|
|
|
gdk_profiler_add_mark (GDK_PROFILER_CURRENT_TIME, 0, "EGL", "swap buffers");
|
|
|
|
|
|
2022-03-03 06:59:23 +00:00
|
|
|
|
if (priv->eglSwapBuffersWithDamage)
|
2021-10-05 22:34:10 +00:00
|
|
|
|
{
|
|
|
|
|
EGLint stack_rects[4 * 4]; /* 4 rects */
|
|
|
|
|
EGLint *heap_rects = NULL;
|
|
|
|
|
int i, j, n_rects = cairo_region_num_rectangles (painted);
|
|
|
|
|
int surface_height = gdk_surface_get_height (surface);
|
|
|
|
|
int scale = gdk_surface_get_scale_factor (surface);
|
|
|
|
|
EGLint *rects;
|
|
|
|
|
|
|
|
|
|
if (n_rects < G_N_ELEMENTS (stack_rects) / 4)
|
|
|
|
|
rects = (EGLint *)&stack_rects;
|
|
|
|
|
else
|
|
|
|
|
heap_rects = rects = g_new (EGLint, n_rects * 4);
|
|
|
|
|
|
|
|
|
|
for (i = 0, j = 0; i < n_rects; i++)
|
|
|
|
|
{
|
|
|
|
|
cairo_rectangle_int_t rect;
|
|
|
|
|
|
|
|
|
|
cairo_region_get_rectangle (painted, i, &rect);
|
|
|
|
|
rects[j++] = rect.x * scale;
|
|
|
|
|
rects[j++] = (surface_height - rect.height - rect.y) * scale;
|
|
|
|
|
rects[j++] = rect.width * scale;
|
|
|
|
|
rects[j++] = rect.height * scale;
|
|
|
|
|
}
|
2022-03-03 06:59:23 +00:00
|
|
|
|
priv->eglSwapBuffersWithDamage (gdk_display_get_egl_display (display), egl_surface, rects, n_rects);
|
2021-10-05 22:34:10 +00:00
|
|
|
|
g_free (heap_rects);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
eglSwapBuffers (gdk_display_get_egl_display (display), egl_surface);
|
|
|
|
|
#endif
|
2018-04-08 22:58:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gdk_gl_context_surface_resized (GdkDrawContext *draw_context)
|
|
|
|
|
{
|
|
|
|
|
GdkGLContext *context = GDK_GL_CONTEXT (draw_context);
|
|
|
|
|
|
|
|
|
|
gdk_gl_context_clear_old_updated_area (context);
|
2016-12-01 00:38:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-11 05:51:15 +00:00
|
|
|
|
static guint
|
|
|
|
|
gdk_gl_context_real_get_default_framebuffer (GdkGLContext *self)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-09 08:45:44 +00:00
|
|
|
|
static void
|
|
|
|
|
gdk_gl_context_class_init (GdkGLContextClass *klass)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
2016-12-01 00:38:20 +00:00
|
|
|
|
GdkDrawContextClass *draw_context_class = GDK_DRAW_CONTEXT_CLASS (klass);
|
2014-10-09 08:45:44 +00:00
|
|
|
|
|
2022-05-06 14:40:13 +00:00
|
|
|
|
klass->realize = gdk_gl_context_default_realize;
|
2016-12-04 15:33:13 +00:00
|
|
|
|
klass->get_damage = gdk_gl_context_real_get_damage;
|
2021-06-30 02:52:35 +00:00
|
|
|
|
klass->is_shared = gdk_gl_context_real_is_shared;
|
2021-10-05 22:34:10 +00:00
|
|
|
|
klass->make_current = gdk_gl_context_real_make_current;
|
|
|
|
|
klass->clear_current = gdk_gl_context_real_clear_current;
|
2022-02-11 05:51:15 +00:00
|
|
|
|
klass->get_default_framebuffer = gdk_gl_context_real_get_default_framebuffer;
|
2016-05-23 07:31:47 +00:00
|
|
|
|
|
2016-12-01 00:38:20 +00:00
|
|
|
|
draw_context_class->begin_frame = gdk_gl_context_real_begin_frame;
|
|
|
|
|
draw_context_class->end_frame = gdk_gl_context_real_end_frame;
|
2018-04-08 22:58:31 +00:00
|
|
|
|
draw_context_class->surface_resized = gdk_gl_context_surface_resized;
|
2016-12-01 00:38:20 +00:00
|
|
|
|
|
2014-10-30 11:04:23 +00:00
|
|
|
|
/**
|
2021-02-25 01:04:17 +00:00
|
|
|
|
* GdkGLContext:shared-context: (attributes org.gtk.Property.get=gdk_gl_context_get_shared_context)
|
2014-10-30 11:04:23 +00:00
|
|
|
|
*
|
2021-07-10 01:24:00 +00:00
|
|
|
|
* Always %NULL
|
|
|
|
|
*
|
|
|
|
|
* As many contexts can share data now and no single shared context exists
|
|
|
|
|
* anymore, this function has been deprecated and now always returns %NULL.
|
|
|
|
|
*
|
|
|
|
|
* Deprecated: 4.4: Use [method@Gdk.GLContext.is_shared] to check if contexts
|
|
|
|
|
* can be shared.
|
2014-10-30 11:04:23 +00:00
|
|
|
|
*/
|
2021-10-07 15:59:17 +00:00
|
|
|
|
properties[PROP_SHARED_CONTEXT] =
|
2014-10-30 11:04:23 +00:00
|
|
|
|
g_param_spec_object ("shared-context",
|
|
|
|
|
P_("Shared context"),
|
2015-07-16 16:22:07 +00:00
|
|
|
|
P_("The GL context this context shares data with"),
|
2014-10-30 11:04:23 +00:00
|
|
|
|
GDK_TYPE_GL_CONTEXT,
|
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
2021-07-10 01:24:00 +00:00
|
|
|
|
G_PARAM_STATIC_STRINGS |
|
|
|
|
|
G_PARAM_DEPRECATED);
|
2014-10-30 11:04:23 +00:00
|
|
|
|
|
2021-10-07 15:59:17 +00:00
|
|
|
|
/**
|
|
|
|
|
* GdkGLContext:allowed-apis: (attributes org.gtk.Property.get=gdk_gl_context_get_allowed_apis org.gtk.Property.gdk_gl_context_set_allowed_apis)
|
|
|
|
|
*
|
|
|
|
|
* The allowed APIs.
|
|
|
|
|
*
|
|
|
|
|
* Since: 4.6
|
|
|
|
|
*/
|
|
|
|
|
properties[PROP_ALLOWED_APIS] =
|
|
|
|
|
g_param_spec_flags ("allowed-apis",
|
|
|
|
|
P_("Allowed APIs"),
|
|
|
|
|
P_("The list of allowed APIs for this context"),
|
|
|
|
|
GDK_TYPE_GL_API,
|
|
|
|
|
DEFAULT_ALLOWED_APIS,
|
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS |
|
|
|
|
|
G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
|
2021-10-07 21:03:45 +00:00
|
|
|
|
/**
|
|
|
|
|
* GdkGLContext:api: (attributes org.gtk.Property.get=gdk_gl_context_get_api)
|
|
|
|
|
*
|
|
|
|
|
* The API currently in use.
|
|
|
|
|
*
|
|
|
|
|
* Since: 4.6
|
|
|
|
|
*/
|
|
|
|
|
properties[PROP_API] =
|
|
|
|
|
g_param_spec_flags ("api",
|
|
|
|
|
P_("API"),
|
|
|
|
|
P_("The API currently in use"),
|
|
|
|
|
GDK_TYPE_GL_API,
|
|
|
|
|
0,
|
|
|
|
|
G_PARAM_READABLE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS |
|
|
|
|
|
G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
|
2014-10-09 08:45:44 +00:00
|
|
|
|
gobject_class->set_property = gdk_gl_context_set_property;
|
|
|
|
|
gobject_class->get_property = gdk_gl_context_get_property;
|
|
|
|
|
gobject_class->dispose = gdk_gl_context_dispose;
|
|
|
|
|
|
2021-10-07 15:59:17 +00:00
|
|
|
|
g_object_class_install_properties (gobject_class, LAST_PROP, properties);
|
2014-10-09 08:45:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gdk_gl_context_init (GdkGLContext *self)
|
|
|
|
|
{
|
2016-10-19 12:43:17 +00:00
|
|
|
|
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (self);
|
|
|
|
|
|
2021-10-07 15:59:17 +00:00
|
|
|
|
priv->allowed_apis = DEFAULT_ALLOWED_APIS;
|
2014-10-09 08:45:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-09 00:50:32 +00:00
|
|
|
|
/* Must have called gdk_display_prepare_gl() before */
|
|
|
|
|
GdkGLContext *
|
2021-10-20 18:03:00 +00:00
|
|
|
|
gdk_gl_context_new (GdkDisplay *display,
|
|
|
|
|
GdkSurface *surface)
|
2021-07-09 00:50:32 +00:00
|
|
|
|
{
|
2021-10-20 18:03:00 +00:00
|
|
|
|
GdkGLContext *shared;
|
|
|
|
|
|
|
|
|
|
g_assert (surface == NULL || display == gdk_surface_get_display (surface));
|
2021-07-09 00:50:32 +00:00
|
|
|
|
|
|
|
|
|
/* assert gdk_display_prepare_gl() had been called */
|
2021-10-20 18:03:00 +00:00
|
|
|
|
shared = gdk_display_get_gl_context (display);
|
2021-07-09 00:50:32 +00:00
|
|
|
|
g_assert (shared);
|
|
|
|
|
|
|
|
|
|
return g_object_new (G_OBJECT_TYPE (shared),
|
2021-10-20 18:03:00 +00:00
|
|
|
|
"display", display,
|
2021-07-09 00:50:32 +00:00
|
|
|
|
"surface", surface,
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-24 11:25:46 +00:00
|
|
|
|
void
|
|
|
|
|
gdk_gl_context_push_debug_group (GdkGLContext *context,
|
|
|
|
|
const char *message)
|
|
|
|
|
{
|
|
|
|
|
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
|
|
|
|
|
|
2019-04-24 13:23:32 +00:00
|
|
|
|
if (priv->use_khr_debug)
|
2019-04-24 11:25:46 +00:00
|
|
|
|
glPushDebugGroupKHR (GL_DEBUG_SOURCE_APPLICATION, 0, -1, message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gdk_gl_context_push_debug_group_printf (GdkGLContext *context,
|
|
|
|
|
const char *format,
|
|
|
|
|
...)
|
|
|
|
|
{
|
|
|
|
|
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *message;
|
2019-04-24 11:25:46 +00:00
|
|
|
|
va_list args;
|
|
|
|
|
|
2019-04-24 13:23:32 +00:00
|
|
|
|
if (priv->use_khr_debug)
|
2019-04-24 11:25:46 +00:00
|
|
|
|
{
|
2019-04-27 07:49:41 +00:00
|
|
|
|
int msg_len;
|
|
|
|
|
|
2019-04-24 11:25:46 +00:00
|
|
|
|
va_start (args, format);
|
|
|
|
|
message = g_strdup_vprintf (format, args);
|
|
|
|
|
va_end (args);
|
|
|
|
|
|
2019-04-27 07:49:41 +00:00
|
|
|
|
msg_len = MIN (priv->max_debug_label_length, strlen (message) - 1);
|
|
|
|
|
glPushDebugGroupKHR (GL_DEBUG_SOURCE_APPLICATION, 0, msg_len, message);
|
2019-04-24 11:25:46 +00:00
|
|
|
|
g_free (message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gdk_gl_context_pop_debug_group (GdkGLContext *context)
|
|
|
|
|
{
|
|
|
|
|
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
|
|
|
|
|
|
2019-04-24 13:23:32 +00:00
|
|
|
|
if (priv->use_khr_debug)
|
2019-04-24 11:25:46 +00:00
|
|
|
|
glPopDebugGroupKHR ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gdk_gl_context_label_object (GdkGLContext *context,
|
|
|
|
|
guint identifier,
|
|
|
|
|
guint name,
|
|
|
|
|
const char *label)
|
|
|
|
|
{
|
|
|
|
|
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
|
|
|
|
|
|
2019-04-24 13:23:32 +00:00
|
|
|
|
if (priv->use_khr_debug)
|
2019-04-24 11:25:46 +00:00
|
|
|
|
glObjectLabel (identifier, name, -1, label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gdk_gl_context_label_object_printf (GdkGLContext *context,
|
|
|
|
|
guint identifier,
|
|
|
|
|
guint name,
|
|
|
|
|
const char *format,
|
|
|
|
|
...)
|
|
|
|
|
{
|
|
|
|
|
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *message;
|
2019-04-24 11:25:46 +00:00
|
|
|
|
va_list args;
|
|
|
|
|
|
2019-04-24 13:23:32 +00:00
|
|
|
|
if (priv->use_khr_debug)
|
2019-04-24 11:25:46 +00:00
|
|
|
|
{
|
2019-04-27 07:49:41 +00:00
|
|
|
|
int msg_len;
|
|
|
|
|
|
2019-04-24 11:25:46 +00:00
|
|
|
|
va_start (args, format);
|
|
|
|
|
message = g_strdup_vprintf (format, args);
|
|
|
|
|
va_end (args);
|
|
|
|
|
|
2019-04-27 07:49:41 +00:00
|
|
|
|
msg_len = MIN (priv->max_debug_label_length, strlen (message) - 1);
|
|
|
|
|
|
|
|
|
|
glObjectLabel (identifier, name, msg_len, message);
|
2019-04-24 11:25:46 +00:00
|
|
|
|
g_free (message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-04-22 16:27:04 +00:00
|
|
|
|
gboolean
|
|
|
|
|
gdk_gl_context_has_unpack_subimage (GdkGLContext *context)
|
|
|
|
|
{
|
|
|
|
|
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
|
|
|
|
|
|
|
|
|
|
return priv->has_unpack_subimage;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-07 20:10:39 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
gdk_gl_context_is_realized (GdkGLContext *context)
|
|
|
|
|
{
|
|
|
|
|
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
|
|
|
|
|
|
|
|
|
|
return priv->api != 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-28 09:34:16 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_gl_context_set_debug_enabled:
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* @context: a `GdkGLContext`
|
2015-01-28 09:34:16 +00:00
|
|
|
|
* @enabled: whether to enable debugging in the context
|
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* Sets whether the `GdkGLContext` should perform extra validations and
|
|
|
|
|
* runtime checking.
|
2015-01-28 09:34:16 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* This is useful during development, but has additional overhead.
|
|
|
|
|
*
|
|
|
|
|
* The `GdkGLContext` must not be realized or made current prior to
|
2015-02-09 16:09:25 +00:00
|
|
|
|
* calling this function.
|
2015-01-28 09:34:16 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gdk_gl_context_set_debug_enabled (GdkGLContext *context,
|
|
|
|
|
gboolean enabled)
|
|
|
|
|
{
|
|
|
|
|
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GDK_IS_GL_CONTEXT (context));
|
2021-10-16 13:47:05 +00:00
|
|
|
|
g_return_if_fail (!gdk_gl_context_is_realized (context));
|
2015-01-28 09:34:16 +00:00
|
|
|
|
|
|
|
|
|
enabled = !!enabled;
|
|
|
|
|
|
|
|
|
|
priv->debug_enabled = enabled;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-28 14:37:26 +00:00
|
|
|
|
/**
|
2015-01-28 09:34:16 +00:00
|
|
|
|
* gdk_gl_context_get_debug_enabled:
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* @context: a `GdkGLContext`
|
|
|
|
|
*
|
|
|
|
|
* Retrieves whether the context is doing extra validations and runtime checking.
|
2015-01-28 09:34:16 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* See [method@Gdk.GLContext.set_debug_enabled].
|
2015-01-28 09:34:16 +00:00
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if debugging is enabled
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gdk_gl_context_get_debug_enabled (GdkGLContext *context)
|
|
|
|
|
{
|
|
|
|
|
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
|
|
|
|
|
|
2015-01-28 14:37:26 +00:00
|
|
|
|
g_return_val_if_fail (GDK_IS_GL_CONTEXT (context), FALSE);
|
|
|
|
|
|
2015-01-28 09:34:16 +00:00
|
|
|
|
return priv->debug_enabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gdk_gl_context_set_forward_compatible:
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* @context: a `GdkGLContext`
|
|
|
|
|
* @compatible: whether the context should be forward-compatible
|
2015-01-28 09:34:16 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* Sets whether the `GdkGLContext` should be forward-compatible.
|
2015-01-28 09:34:16 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* Forward-compatible contexts must not support OpenGL functionality that
|
2015-01-28 09:34:16 +00:00
|
|
|
|
* 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.
|
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* The `GdkGLContext` must not be realized or made current prior to calling
|
2015-02-09 16:09:25 +00:00
|
|
|
|
* this function.
|
2015-01-28 09:34:16 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gdk_gl_context_set_forward_compatible (GdkGLContext *context,
|
|
|
|
|
gboolean compatible)
|
|
|
|
|
{
|
|
|
|
|
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
|
|
|
|
|
|
2015-02-09 16:08:43 +00:00
|
|
|
|
g_return_if_fail (GDK_IS_GL_CONTEXT (context));
|
2021-10-16 13:47:05 +00:00
|
|
|
|
g_return_if_fail (!gdk_gl_context_is_realized (context));
|
2015-02-09 16:08:43 +00:00
|
|
|
|
|
2015-01-28 09:34:16 +00:00
|
|
|
|
compatible = !!compatible;
|
|
|
|
|
|
|
|
|
|
priv->forward_compatible = compatible;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-28 14:37:26 +00:00
|
|
|
|
/**
|
2015-01-28 09:34:16 +00:00
|
|
|
|
* gdk_gl_context_get_forward_compatible:
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* @context: a `GdkGLContext`
|
|
|
|
|
*
|
|
|
|
|
* Retrieves whether the context is forward-compatible.
|
2015-01-28 09:34:16 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* See [method@Gdk.GLContext.set_forward_compatible].
|
2015-01-28 09:34:16 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* Returns: %TRUE if the context should be forward-compatible
|
2015-01-28 09:34:16 +00:00
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gdk_gl_context_get_forward_compatible (GdkGLContext *context)
|
|
|
|
|
{
|
|
|
|
|
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
|
|
|
|
|
|
2015-01-28 14:37:26 +00:00
|
|
|
|
g_return_val_if_fail (GDK_IS_GL_CONTEXT (context), FALSE);
|
|
|
|
|
|
2015-01-28 09:34:16 +00:00
|
|
|
|
return priv->forward_compatible;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gdk_gl_context_set_required_version:
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* @context: a `GdkGLContext`
|
2015-01-28 09:34:16 +00:00
|
|
|
|
* @major: the major version to request
|
|
|
|
|
* @minor: the minor version to request
|
|
|
|
|
*
|
|
|
|
|
* Sets the major and minor version of OpenGL to request.
|
|
|
|
|
*
|
|
|
|
|
* Setting @major and @minor to zero will use the default values.
|
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* The `GdkGLContext` must not be realized or made current prior to calling
|
2015-02-09 16:09:25 +00:00
|
|
|
|
* this function.
|
2015-01-28 09:34:16 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gdk_gl_context_set_required_version (GdkGLContext *context,
|
|
|
|
|
int major,
|
|
|
|
|
int minor)
|
|
|
|
|
{
|
|
|
|
|
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
|
2020-01-29 11:00:48 +00:00
|
|
|
|
gboolean force_gles = FALSE;
|
2016-04-18 09:10:30 +00:00
|
|
|
|
int version, min_ver;
|
2020-01-29 11:00:48 +00:00
|
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
|
GdkDisplay *display;
|
|
|
|
|
#endif
|
2015-01-28 09:34:16 +00:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (GDK_IS_GL_CONTEXT (context));
|
2021-10-17 16:46:01 +00:00
|
|
|
|
g_return_if_fail (!gdk_gl_context_is_realized (context));
|
2015-01-28 09:34:16 +00:00
|
|
|
|
|
2015-02-10 10:16:53 +00:00
|
|
|
|
/* this will take care of the default */
|
|
|
|
|
if (major == 0 && minor == 0)
|
|
|
|
|
{
|
|
|
|
|
priv->major = 0;
|
|
|
|
|
priv->minor = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-11 04:35:01 +00:00
|
|
|
|
version = (major * 100) + minor;
|
2016-04-18 09:10:30 +00:00
|
|
|
|
|
2020-01-29 11:00:48 +00:00
|
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
|
display = gdk_draw_context_get_display (GDK_DRAW_CONTEXT (context));
|
|
|
|
|
force_gles = GDK_DISPLAY_DEBUG_CHECK (display, GL_GLES);
|
|
|
|
|
#endif
|
|
|
|
|
/* Enforce a minimum context version number of 3.2 for desktop GL,
|
|
|
|
|
* and 2.0 for GLES
|
|
|
|
|
*/
|
2021-10-07 20:10:39 +00:00
|
|
|
|
if (gdk_gl_context_get_use_es (context) || force_gles)
|
2016-04-18 09:10:30 +00:00
|
|
|
|
min_ver = 200;
|
2016-04-22 16:27:04 +00:00
|
|
|
|
else
|
|
|
|
|
min_ver = 302;
|
2016-04-18 09:10:30 +00:00
|
|
|
|
|
|
|
|
|
if (version < min_ver)
|
2015-02-11 04:35:01 +00:00
|
|
|
|
{
|
|
|
|
|
g_warning ("gdk_gl_context_set_required_version - GL context versions less than 3.2 are not supported.");
|
2016-04-18 09:10:30 +00:00
|
|
|
|
version = min_ver;
|
2015-02-11 04:35:01 +00:00
|
|
|
|
}
|
|
|
|
|
priv->major = version / 100;
|
|
|
|
|
priv->minor = version % 100;
|
2015-01-28 09:34:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-12 13:04:43 +00:00
|
|
|
|
gboolean
|
2021-12-25 13:14:52 +00:00
|
|
|
|
gdk_gl_context_check_version (GdkGLContext *self,
|
|
|
|
|
int required_gl_major,
|
|
|
|
|
int required_gl_minor,
|
|
|
|
|
int required_gles_major,
|
|
|
|
|
int required_gles_minor)
|
2021-10-12 13:04:43 +00:00
|
|
|
|
{
|
2021-12-25 13:14:52 +00:00
|
|
|
|
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (self);
|
2021-10-12 13:04:43 +00:00
|
|
|
|
|
2021-12-25 13:14:52 +00:00
|
|
|
|
g_return_val_if_fail (GDK_IS_GL_CONTEXT (self), FALSE);
|
|
|
|
|
g_return_val_if_fail (required_gl_minor < 10, FALSE);
|
|
|
|
|
g_return_val_if_fail (required_gles_minor < 10, FALSE);
|
2021-10-12 13:04:43 +00:00
|
|
|
|
|
2021-12-25 13:14:52 +00:00
|
|
|
|
if (!gdk_gl_context_is_realized (self))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
switch (priv->api)
|
|
|
|
|
{
|
|
|
|
|
case GDK_GL_API_GL:
|
|
|
|
|
return priv->gl_version >= required_gl_major * 10 + required_gl_minor;
|
|
|
|
|
|
|
|
|
|
case GDK_GL_API_GLES:
|
|
|
|
|
return priv->gl_version >= required_gles_major * 10 + required_gles_minor;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
g_return_val_if_reached (FALSE);
|
|
|
|
|
|
|
|
|
|
}
|
2021-10-12 13:04:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-28 14:37:26 +00:00
|
|
|
|
/**
|
2015-01-28 09:34:16 +00:00
|
|
|
|
* gdk_gl_context_get_required_version:
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* @context: a `GdkGLContext`
|
2015-01-28 09:34:16 +00:00
|
|
|
|
* @major: (out) (nullable): return location for the major version to request
|
|
|
|
|
* @minor: (out) (nullable): return location for the minor version to request
|
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* Retrieves required OpenGL version.
|
|
|
|
|
*
|
|
|
|
|
* See [method@Gdk.GLContext.set_required_version].
|
2015-01-28 09:34:16 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gdk_gl_context_get_required_version (GdkGLContext *context,
|
|
|
|
|
int *major,
|
|
|
|
|
int *minor)
|
|
|
|
|
{
|
|
|
|
|
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
|
2020-01-29 11:00:48 +00:00
|
|
|
|
gboolean force_gles = FALSE;
|
|
|
|
|
GdkDisplay *display;
|
2016-04-18 09:10:30 +00:00
|
|
|
|
int default_major, default_minor;
|
2015-02-09 16:10:22 +00:00
|
|
|
|
int maj, min;
|
2015-01-28 09:34:16 +00:00
|
|
|
|
|
2015-02-09 16:10:22 +00:00
|
|
|
|
g_return_if_fail (GDK_IS_GL_CONTEXT (context));
|
|
|
|
|
|
2020-01-29 11:00:48 +00:00
|
|
|
|
display = gdk_draw_context_get_display (GDK_DRAW_CONTEXT (context));
|
2022-01-18 16:16:11 +00:00
|
|
|
|
|
|
|
|
|
#ifdef G_ENABLE_DEBUG
|
2020-01-29 11:00:48 +00:00
|
|
|
|
force_gles = GDK_DISPLAY_DEBUG_CHECK (display, GL_GLES);
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-01-18 16:16:11 +00:00
|
|
|
|
/* libANGLE on Windows at least requires GLES 3.0+ */
|
|
|
|
|
if (display->have_egl_win32_libangle)
|
|
|
|
|
force_gles = TRUE;
|
|
|
|
|
|
2020-01-29 11:00:48 +00:00
|
|
|
|
/* Default fallback values for uninitialised contexts; we
|
|
|
|
|
* enforce a context version number of 3.2 for desktop GL,
|
|
|
|
|
* and 2.0 for GLES
|
|
|
|
|
*/
|
2021-10-07 20:10:39 +00:00
|
|
|
|
if (gdk_gl_context_get_use_es (context) || force_gles)
|
2016-04-18 09:10:30 +00:00
|
|
|
|
{
|
2022-01-18 16:16:11 +00:00
|
|
|
|
default_major = display->have_egl_win32_libangle ? 3 : 2;
|
2016-04-22 16:27:04 +00:00
|
|
|
|
default_minor = 0;
|
2016-04-18 09:10:30 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-04-22 16:27:04 +00:00
|
|
|
|
default_major = 3;
|
|
|
|
|
default_minor = 2;
|
2016-04-18 09:10:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-09 16:10:22 +00:00
|
|
|
|
if (priv->major > 0)
|
|
|
|
|
maj = priv->major;
|
2015-01-28 09:34:16 +00:00
|
|
|
|
else
|
2016-04-18 09:10:30 +00:00
|
|
|
|
maj = default_major;
|
2015-01-28 09:34:16 +00:00
|
|
|
|
|
2015-02-09 16:10:22 +00:00
|
|
|
|
if (priv->minor > 0)
|
|
|
|
|
min = priv->minor;
|
2015-01-28 09:34:16 +00:00
|
|
|
|
else
|
2016-04-18 09:10:30 +00:00
|
|
|
|
min = default_minor;
|
2015-02-09 16:10:22 +00:00
|
|
|
|
|
|
|
|
|
if (major != NULL)
|
|
|
|
|
*major = maj;
|
|
|
|
|
if (minor != NULL)
|
|
|
|
|
*minor = min;
|
2015-01-28 09:34:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-06 17:54:58 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_gl_context_is_legacy:
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* @context: a `GdkGLContext`
|
2015-10-06 17:54:58 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* Whether the `GdkGLContext` is in legacy mode or not.
|
2015-10-06 17:54:58 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* The `GdkGLContext` must be realized before calling this function.
|
2015-10-07 07:50:23 +00:00
|
|
|
|
*
|
|
|
|
|
* 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.
|
2015-10-06 17:54:58 +00:00
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if the GL context is in legacy mode
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gdk_gl_context_is_legacy (GdkGLContext *context)
|
|
|
|
|
{
|
|
|
|
|
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GDK_IS_GL_CONTEXT (context), FALSE);
|
2021-10-07 20:10:39 +00:00
|
|
|
|
g_return_val_if_fail (gdk_gl_context_is_realized (context), FALSE);
|
2015-10-06 17:54:58 +00:00
|
|
|
|
|
|
|
|
|
return priv->is_legacy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gdk_gl_context_set_is_legacy (GdkGLContext *context,
|
|
|
|
|
gboolean is_legacy)
|
|
|
|
|
{
|
|
|
|
|
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
|
|
|
|
|
|
|
|
|
|
priv->is_legacy = !!is_legacy;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-30 02:52:35 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_gl_context_is_shared:
|
|
|
|
|
* @self: a `GdkGLContext`
|
|
|
|
|
* @other: the `GdkGLContext` that should be compatible with @self
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if the two GL contexts are compatible.
|
2021-07-27 17:01:31 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 4.4
|
2021-06-30 02:52:35 +00:00
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gdk_gl_context_is_shared (GdkGLContext *self,
|
|
|
|
|
GdkGLContext *other)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GDK_IS_GL_CONTEXT (self), FALSE);
|
|
|
|
|
g_return_val_if_fail (GDK_IS_GL_CONTEXT (other), FALSE);
|
|
|
|
|
|
2021-10-07 20:10:39 +00:00
|
|
|
|
if (!gdk_gl_context_is_realized (self) ||
|
|
|
|
|
!gdk_gl_context_is_realized (other))
|
2021-06-30 02:52:35 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
return GDK_GL_CONTEXT_GET_CLASS (self)->is_shared (self, other);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-07 15:59:17 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_gl_context_set_allowed_apis: (attributes org.gtk.Method.set_property=allowed-apis)
|
|
|
|
|
* @self: a GL context
|
|
|
|
|
* @apis: the allowed APIs
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
* Since: 4.6
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
gdk_gl_context_set_allowed_apis (GdkGLContext *self,
|
|
|
|
|
GdkGLAPI apis)
|
|
|
|
|
{
|
|
|
|
|
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (self);
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GDK_IS_GL_CONTEXT (self));
|
|
|
|
|
|
|
|
|
|
if (priv->allowed_apis == apis)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
priv->allowed_apis = apis;
|
|
|
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ALLOWED_APIS]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gdk_gl_context_get_allowed_apis: (attributes org.gtk.Method.get_property=allowed-apis)
|
|
|
|
|
* @self: a GL context
|
|
|
|
|
*
|
|
|
|
|
* Gets the allowed APIs set via gdk_gl_context_set_allowed_apis().
|
|
|
|
|
*
|
|
|
|
|
* Returns: the allowed APIs
|
|
|
|
|
*
|
|
|
|
|
* Since: 4.6
|
|
|
|
|
**/
|
|
|
|
|
GdkGLAPI
|
|
|
|
|
gdk_gl_context_get_allowed_apis (GdkGLContext *self)
|
|
|
|
|
{
|
|
|
|
|
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (self);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GDK_IS_GL_CONTEXT (self), 0);
|
|
|
|
|
|
|
|
|
|
return priv->allowed_apis;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-07 21:03:45 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_gl_context_get_api: (attributes org.gtk.Method.get_property=api)
|
|
|
|
|
* @self: a GL context
|
|
|
|
|
*
|
|
|
|
|
* Gets the API currently in use.
|
|
|
|
|
*
|
|
|
|
|
* If the renderer has not been realized yet, 0 is returned.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the currently used API
|
|
|
|
|
*
|
|
|
|
|
* Since: 4.6
|
|
|
|
|
**/
|
|
|
|
|
GdkGLAPI
|
|
|
|
|
gdk_gl_context_get_api (GdkGLContext *self)
|
|
|
|
|
{
|
|
|
|
|
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (self);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GDK_IS_GL_CONTEXT (self), 0);
|
|
|
|
|
|
|
|
|
|
return priv->api;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-07 20:10:39 +00:00
|
|
|
|
gboolean
|
|
|
|
|
gdk_gl_context_is_api_allowed (GdkGLContext *self,
|
|
|
|
|
GdkGLAPI api,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (self);
|
|
|
|
|
|
|
|
|
|
if (GDK_DISPLAY_DEBUG_CHECK (gdk_gl_context_get_display (self), GL_GLES))
|
|
|
|
|
{
|
|
|
|
|
if (!(api & GDK_GL_API_GLES))
|
|
|
|
|
{
|
|
|
|
|
g_set_error_literal (error, GDK_GL_ERROR, GDK_GL_ERROR_NOT_AVAILABLE,
|
|
|
|
|
_("Anything but OpenGL ES disabled via GDK_DEBUG"));
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (priv->allowed_apis & api)
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
g_set_error (error, GDK_GL_ERROR, GDK_GL_ERROR_NOT_AVAILABLE,
|
|
|
|
|
_("Application does not support %s API"),
|
|
|
|
|
api == GDK_GL_API_GL ? "OpenGL" : "OpenGL ES");
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-22 16:27:04 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_gl_context_set_use_es:
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* @context: a `GdkGLContext`
|
2016-10-19 12:43:17 +00:00
|
|
|
|
* @use_es: whether the context should use OpenGL ES instead of OpenGL,
|
|
|
|
|
* or -1 to allow auto-detection
|
2016-04-22 16:27:04 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* Requests that GDK create an OpenGL ES context instead of an OpenGL one.
|
|
|
|
|
*
|
|
|
|
|
* Not all platforms support OpenGL ES.
|
2016-04-22 16:27:04 +00:00
|
|
|
|
*
|
|
|
|
|
* The @context must not have been realized.
|
|
|
|
|
*
|
2016-10-19 12:43:17 +00:00
|
|
|
|
* By default, GDK will attempt to automatically detect whether the
|
|
|
|
|
* underlying GL implementation is OpenGL or OpenGL ES once the @context
|
|
|
|
|
* is realized.
|
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* You should check the return value of [method@Gdk.GLContext.get_use_es]
|
|
|
|
|
* after calling [method@Gdk.GLContext.realize] to decide whether to use
|
|
|
|
|
* the OpenGL or OpenGL ES API, extensions, or shaders.
|
2016-04-22 16:27:04 +00:00
|
|
|
|
*/
|
2016-04-18 09:10:30 +00:00
|
|
|
|
void
|
|
|
|
|
gdk_gl_context_set_use_es (GdkGLContext *context,
|
2016-10-19 12:43:17 +00:00
|
|
|
|
int use_es)
|
2016-04-18 09:10:30 +00:00
|
|
|
|
{
|
2016-04-22 16:27:04 +00:00
|
|
|
|
g_return_if_fail (GDK_IS_GL_CONTEXT (context));
|
2021-10-16 13:47:05 +00:00
|
|
|
|
g_return_if_fail (!gdk_gl_context_is_realized (context));
|
2016-04-22 16:27:04 +00:00
|
|
|
|
|
2021-10-07 16:13:36 +00:00
|
|
|
|
switch (use_es)
|
|
|
|
|
{
|
|
|
|
|
case -1:
|
|
|
|
|
gdk_gl_context_set_allowed_apis (context, DEFAULT_ALLOWED_APIS);
|
|
|
|
|
break;
|
|
|
|
|
case 0:
|
|
|
|
|
gdk_gl_context_set_allowed_apis (context, GDK_GL_API_GL);
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
gdk_gl_context_set_allowed_apis (context, GDK_GL_API_GLES);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
/* Just ignore the call */
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-04-18 09:10:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-22 16:27:04 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_gl_context_get_use_es:
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* @context: a `GdkGLContext`
|
2016-04-22 16:27:04 +00:00
|
|
|
|
*
|
|
|
|
|
* Checks whether the @context is using an OpenGL or OpenGL ES profile.
|
|
|
|
|
*
|
2022-05-30 18:47:40 +00:00
|
|
|
|
* Returns: %TRUE if the `GdkGLContext` is using an OpenGL ES profile;
|
|
|
|
|
* %FALSE if other profile is in use of if the @context has not yet
|
|
|
|
|
* been realized.
|
2016-04-22 16:27:04 +00:00
|
|
|
|
*/
|
2016-04-18 09:10:30 +00:00
|
|
|
|
gboolean
|
|
|
|
|
gdk_gl_context_get_use_es (GdkGLContext *context)
|
|
|
|
|
{
|
|
|
|
|
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
|
|
|
|
|
|
2016-04-22 16:27:04 +00:00
|
|
|
|
g_return_val_if_fail (GDK_IS_GL_CONTEXT (context), FALSE);
|
|
|
|
|
|
2021-10-07 20:10:39 +00:00
|
|
|
|
return priv->api == GDK_GL_API_GLES;
|
2016-04-18 09:10:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-18 21:14:22 +00:00
|
|
|
|
static void APIENTRY
|
2018-03-25 13:28:40 +00:00
|
|
|
|
gl_debug_message_callback (GLenum source,
|
|
|
|
|
GLenum type,
|
|
|
|
|
GLuint id,
|
|
|
|
|
GLenum severity,
|
|
|
|
|
GLsizei length,
|
|
|
|
|
const GLchar *message,
|
|
|
|
|
const void *user_data)
|
|
|
|
|
{
|
|
|
|
|
const char *message_source;
|
|
|
|
|
const char *message_type;
|
|
|
|
|
const char *message_severity;
|
2021-12-25 13:41:20 +00:00
|
|
|
|
GLogLevelFlags log_level;
|
2018-03-25 13:28:40 +00:00
|
|
|
|
|
|
|
|
|
if (severity == GL_DEBUG_SEVERITY_NOTIFICATION)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
switch (source)
|
|
|
|
|
{
|
|
|
|
|
case GL_DEBUG_SOURCE_API:
|
|
|
|
|
message_source = "API";
|
|
|
|
|
break;
|
|
|
|
|
case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
|
|
|
|
|
message_source = "Window System";
|
|
|
|
|
break;
|
|
|
|
|
case GL_DEBUG_SOURCE_SHADER_COMPILER:
|
|
|
|
|
message_source = "Shader Compiler";
|
|
|
|
|
break;
|
|
|
|
|
case GL_DEBUG_SOURCE_THIRD_PARTY:
|
|
|
|
|
message_source = "Third Party";
|
|
|
|
|
break;
|
|
|
|
|
case GL_DEBUG_SOURCE_APPLICATION:
|
|
|
|
|
message_source = "Application";
|
|
|
|
|
break;
|
|
|
|
|
case GL_DEBUG_SOURCE_OTHER:
|
|
|
|
|
default:
|
|
|
|
|
message_source = "Other";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case GL_DEBUG_TYPE_ERROR:
|
|
|
|
|
message_type = "Error";
|
|
|
|
|
break;
|
|
|
|
|
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
|
|
|
|
|
message_type = "Deprecated Behavior";
|
|
|
|
|
break;
|
|
|
|
|
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
|
|
|
|
|
message_type = "Undefined Behavior";
|
|
|
|
|
break;
|
|
|
|
|
case GL_DEBUG_TYPE_PORTABILITY:
|
|
|
|
|
message_type = "Portability";
|
|
|
|
|
break;
|
|
|
|
|
case GL_DEBUG_TYPE_PERFORMANCE:
|
|
|
|
|
message_type = "Performance";
|
|
|
|
|
break;
|
|
|
|
|
case GL_DEBUG_TYPE_MARKER:
|
|
|
|
|
message_type = "Marker";
|
|
|
|
|
break;
|
|
|
|
|
case GL_DEBUG_TYPE_PUSH_GROUP:
|
|
|
|
|
message_type = "Push Group";
|
|
|
|
|
break;
|
|
|
|
|
case GL_DEBUG_TYPE_POP_GROUP:
|
|
|
|
|
message_type = "Pop Group";
|
|
|
|
|
break;
|
|
|
|
|
case GL_DEBUG_TYPE_OTHER:
|
|
|
|
|
default:
|
|
|
|
|
message_type = "Other";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (severity)
|
|
|
|
|
{
|
|
|
|
|
case GL_DEBUG_SEVERITY_HIGH:
|
|
|
|
|
message_severity = "High";
|
2021-12-25 13:41:20 +00:00
|
|
|
|
log_level = G_LOG_LEVEL_CRITICAL;
|
2018-03-25 13:28:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case GL_DEBUG_SEVERITY_MEDIUM:
|
|
|
|
|
message_severity = "Medium";
|
2021-12-25 13:41:20 +00:00
|
|
|
|
log_level = G_LOG_LEVEL_WARNING;
|
2018-03-25 13:28:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case GL_DEBUG_SEVERITY_LOW:
|
|
|
|
|
message_severity = "Low";
|
2021-12-25 13:41:20 +00:00
|
|
|
|
log_level = G_LOG_LEVEL_MESSAGE;
|
2018-03-25 13:28:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case GL_DEBUG_SEVERITY_NOTIFICATION:
|
|
|
|
|
message_severity = "Notification";
|
2021-12-25 13:41:20 +00:00
|
|
|
|
log_level = G_LOG_LEVEL_INFO;
|
2018-03-25 13:28:40 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
message_severity = "Unknown";
|
2021-12-25 13:41:20 +00:00
|
|
|
|
log_level = G_LOG_LEVEL_MESSAGE;
|
2018-03-25 13:28:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-25 13:41:20 +00:00
|
|
|
|
/* There's no higher level function taking a log level argument... */
|
|
|
|
|
g_log_structured_standard (G_LOG_DOMAIN, log_level,
|
|
|
|
|
__FILE__, G_STRINGIFY (__LINE__),
|
|
|
|
|
G_STRFUNC,
|
|
|
|
|
"OPENGL:\n Source: %s\n Type: %s\n Severity: %s\n Message: %s",
|
|
|
|
|
message_source, message_type, message_severity, message);
|
2018-03-25 13:28:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
GL: Split GL context creation in two phases
One of the major requests by OpenGL users has been the ability to
specify settings when creating a GL context, like the version to use
or whether the debug support should be enabled.
We have a couple of requirements in terms of API:
• avoid, if at all possible, the "C arrays of integers with
attribute, value pairs", which are hard to write and hard
to bind in non-C languages.
• allow failing in a recoverable way.
• do not make the GL context creation API a mess of arguments.
Looking at prior art, it seems that a common pattern is to split the
construction phase in two:
• a first phase that creates a GL context wrapper object and
does preliminary checks on the environment.
• a second phase that creates the backend-specific GL object.
We adopted a similar pattern:
• gdk_window_create_gl_context() creates a GdkGLContext
• gdk_gl_context_realize() creates the underlying resources
Calling gdk_gl_context_make_current() also realizes the context, so
simple GL users do not need to care. Advanced users will want to
call gdk_window_create_gl_context(), set up the optional requirements,
and then call gdk_gl_context_realize(). If either of these two steps
fails, it's possible to recover by changing the requirements, or simply
creating a new GdkGLContext instance.
https://bugzilla.gnome.org/show_bug.cgi?id=741946
2015-01-27 21:23:23 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_gl_context_realize:
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* @context: a `GdkGLContext`
|
|
|
|
|
* @error: return location for a `GError`
|
GL: Split GL context creation in two phases
One of the major requests by OpenGL users has been the ability to
specify settings when creating a GL context, like the version to use
or whether the debug support should be enabled.
We have a couple of requirements in terms of API:
• avoid, if at all possible, the "C arrays of integers with
attribute, value pairs", which are hard to write and hard
to bind in non-C languages.
• allow failing in a recoverable way.
• do not make the GL context creation API a mess of arguments.
Looking at prior art, it seems that a common pattern is to split the
construction phase in two:
• a first phase that creates a GL context wrapper object and
does preliminary checks on the environment.
• a second phase that creates the backend-specific GL object.
We adopted a similar pattern:
• gdk_window_create_gl_context() creates a GdkGLContext
• gdk_gl_context_realize() creates the underlying resources
Calling gdk_gl_context_make_current() also realizes the context, so
simple GL users do not need to care. Advanced users will want to
call gdk_window_create_gl_context(), set up the optional requirements,
and then call gdk_gl_context_realize(). If either of these two steps
fails, it's possible to recover by changing the requirements, or simply
creating a new GdkGLContext instance.
https://bugzilla.gnome.org/show_bug.cgi?id=741946
2015-01-27 21:23:23 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* Realizes the given `GdkGLContext`.
|
GL: Split GL context creation in two phases
One of the major requests by OpenGL users has been the ability to
specify settings when creating a GL context, like the version to use
or whether the debug support should be enabled.
We have a couple of requirements in terms of API:
• avoid, if at all possible, the "C arrays of integers with
attribute, value pairs", which are hard to write and hard
to bind in non-C languages.
• allow failing in a recoverable way.
• do not make the GL context creation API a mess of arguments.
Looking at prior art, it seems that a common pattern is to split the
construction phase in two:
• a first phase that creates a GL context wrapper object and
does preliminary checks on the environment.
• a second phase that creates the backend-specific GL object.
We adopted a similar pattern:
• gdk_window_create_gl_context() creates a GdkGLContext
• gdk_gl_context_realize() creates the underlying resources
Calling gdk_gl_context_make_current() also realizes the context, so
simple GL users do not need to care. Advanced users will want to
call gdk_window_create_gl_context(), set up the optional requirements,
and then call gdk_gl_context_realize(). If either of these two steps
fails, it's possible to recover by changing the requirements, or simply
creating a new GdkGLContext instance.
https://bugzilla.gnome.org/show_bug.cgi?id=741946
2015-01-27 21:23:23 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* It is safe to call this function on a realized `GdkGLContext`.
|
GL: Split GL context creation in two phases
One of the major requests by OpenGL users has been the ability to
specify settings when creating a GL context, like the version to use
or whether the debug support should be enabled.
We have a couple of requirements in terms of API:
• avoid, if at all possible, the "C arrays of integers with
attribute, value pairs", which are hard to write and hard
to bind in non-C languages.
• allow failing in a recoverable way.
• do not make the GL context creation API a mess of arguments.
Looking at prior art, it seems that a common pattern is to split the
construction phase in two:
• a first phase that creates a GL context wrapper object and
does preliminary checks on the environment.
• a second phase that creates the backend-specific GL object.
We adopted a similar pattern:
• gdk_window_create_gl_context() creates a GdkGLContext
• gdk_gl_context_realize() creates the underlying resources
Calling gdk_gl_context_make_current() also realizes the context, so
simple GL users do not need to care. Advanced users will want to
call gdk_window_create_gl_context(), set up the optional requirements,
and then call gdk_gl_context_realize(). If either of these two steps
fails, it's possible to recover by changing the requirements, or simply
creating a new GdkGLContext instance.
https://bugzilla.gnome.org/show_bug.cgi?id=741946
2015-01-27 21:23:23 +00:00
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if the context is realized
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gdk_gl_context_realize (GdkGLContext *context,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GDK_IS_GL_CONTEXT (context), FALSE);
|
|
|
|
|
|
2021-10-07 20:10:39 +00:00
|
|
|
|
if (priv->api)
|
2015-02-09 16:10:22 +00:00
|
|
|
|
return TRUE;
|
GL: Split GL context creation in two phases
One of the major requests by OpenGL users has been the ability to
specify settings when creating a GL context, like the version to use
or whether the debug support should be enabled.
We have a couple of requirements in terms of API:
• avoid, if at all possible, the "C arrays of integers with
attribute, value pairs", which are hard to write and hard
to bind in non-C languages.
• allow failing in a recoverable way.
• do not make the GL context creation API a mess of arguments.
Looking at prior art, it seems that a common pattern is to split the
construction phase in two:
• a first phase that creates a GL context wrapper object and
does preliminary checks on the environment.
• a second phase that creates the backend-specific GL object.
We adopted a similar pattern:
• gdk_window_create_gl_context() creates a GdkGLContext
• gdk_gl_context_realize() creates the underlying resources
Calling gdk_gl_context_make_current() also realizes the context, so
simple GL users do not need to care. Advanced users will want to
call gdk_window_create_gl_context(), set up the optional requirements,
and then call gdk_gl_context_realize(). If either of these two steps
fails, it's possible to recover by changing the requirements, or simply
creating a new GdkGLContext instance.
https://bugzilla.gnome.org/show_bug.cgi?id=741946
2015-01-27 21:23:23 +00:00
|
|
|
|
|
2021-10-07 20:10:39 +00:00
|
|
|
|
priv->api = GDK_GL_CONTEXT_GET_CLASS (context)->realize (context, error);
|
GL: Split GL context creation in two phases
One of the major requests by OpenGL users has been the ability to
specify settings when creating a GL context, like the version to use
or whether the debug support should be enabled.
We have a couple of requirements in terms of API:
• avoid, if at all possible, the "C arrays of integers with
attribute, value pairs", which are hard to write and hard
to bind in non-C languages.
• allow failing in a recoverable way.
• do not make the GL context creation API a mess of arguments.
Looking at prior art, it seems that a common pattern is to split the
construction phase in two:
• a first phase that creates a GL context wrapper object and
does preliminary checks on the environment.
• a second phase that creates the backend-specific GL object.
We adopted a similar pattern:
• gdk_window_create_gl_context() creates a GdkGLContext
• gdk_gl_context_realize() creates the underlying resources
Calling gdk_gl_context_make_current() also realizes the context, so
simple GL users do not need to care. Advanced users will want to
call gdk_window_create_gl_context(), set up the optional requirements,
and then call gdk_gl_context_realize(). If either of these two steps
fails, it's possible to recover by changing the requirements, or simply
creating a new GdkGLContext instance.
https://bugzilla.gnome.org/show_bug.cgi?id=741946
2015-01-27 21:23:23 +00:00
|
|
|
|
|
2021-10-07 21:03:45 +00:00
|
|
|
|
if (priv->api)
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (context), properties[PROP_API]);
|
|
|
|
|
|
2021-10-07 20:10:39 +00:00
|
|
|
|
return priv->api;
|
GL: Split GL context creation in two phases
One of the major requests by OpenGL users has been the ability to
specify settings when creating a GL context, like the version to use
or whether the debug support should be enabled.
We have a couple of requirements in terms of API:
• avoid, if at all possible, the "C arrays of integers with
attribute, value pairs", which are hard to write and hard
to bind in non-C languages.
• allow failing in a recoverable way.
• do not make the GL context creation API a mess of arguments.
Looking at prior art, it seems that a common pattern is to split the
construction phase in two:
• a first phase that creates a GL context wrapper object and
does preliminary checks on the environment.
• a second phase that creates the backend-specific GL object.
We adopted a similar pattern:
• gdk_window_create_gl_context() creates a GdkGLContext
• gdk_gl_context_realize() creates the underlying resources
Calling gdk_gl_context_make_current() also realizes the context, so
simple GL users do not need to care. Advanced users will want to
call gdk_window_create_gl_context(), set up the optional requirements,
and then call gdk_gl_context_realize(). If either of these two steps
fails, it's possible to recover by changing the requirements, or simply
creating a new GdkGLContext instance.
https://bugzilla.gnome.org/show_bug.cgi?id=741946
2015-01-27 21:23:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-27 20:12:40 +00:00
|
|
|
|
static void
|
GL: Split GL context creation in two phases
One of the major requests by OpenGL users has been the ability to
specify settings when creating a GL context, like the version to use
or whether the debug support should be enabled.
We have a couple of requirements in terms of API:
• avoid, if at all possible, the "C arrays of integers with
attribute, value pairs", which are hard to write and hard
to bind in non-C languages.
• allow failing in a recoverable way.
• do not make the GL context creation API a mess of arguments.
Looking at prior art, it seems that a common pattern is to split the
construction phase in two:
• a first phase that creates a GL context wrapper object and
does preliminary checks on the environment.
• a second phase that creates the backend-specific GL object.
We adopted a similar pattern:
• gdk_window_create_gl_context() creates a GdkGLContext
• gdk_gl_context_realize() creates the underlying resources
Calling gdk_gl_context_make_current() also realizes the context, so
simple GL users do not need to care. Advanced users will want to
call gdk_window_create_gl_context(), set up the optional requirements,
and then call gdk_gl_context_realize(). If either of these two steps
fails, it's possible to recover by changing the requirements, or simply
creating a new GdkGLContext instance.
https://bugzilla.gnome.org/show_bug.cgi?id=741946
2015-01-27 21:23:23 +00:00
|
|
|
|
gdk_gl_context_check_extensions (GdkGLContext *context)
|
2014-10-27 20:12:40 +00:00
|
|
|
|
{
|
|
|
|
|
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
|
2020-01-29 11:00:48 +00:00
|
|
|
|
gboolean gl_debug = FALSE;
|
|
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
|
GdkDisplay *display;
|
|
|
|
|
#endif
|
2014-10-27 20:12:40 +00:00
|
|
|
|
|
2021-10-07 20:10:39 +00:00
|
|
|
|
if (!gdk_gl_context_is_realized (context))
|
GL: Split GL context creation in two phases
One of the major requests by OpenGL users has been the ability to
specify settings when creating a GL context, like the version to use
or whether the debug support should be enabled.
We have a couple of requirements in terms of API:
• avoid, if at all possible, the "C arrays of integers with
attribute, value pairs", which are hard to write and hard
to bind in non-C languages.
• allow failing in a recoverable way.
• do not make the GL context creation API a mess of arguments.
Looking at prior art, it seems that a common pattern is to split the
construction phase in two:
• a first phase that creates a GL context wrapper object and
does preliminary checks on the environment.
• a second phase that creates the backend-specific GL object.
We adopted a similar pattern:
• gdk_window_create_gl_context() creates a GdkGLContext
• gdk_gl_context_realize() creates the underlying resources
Calling gdk_gl_context_make_current() also realizes the context, so
simple GL users do not need to care. Advanced users will want to
call gdk_window_create_gl_context(), set up the optional requirements,
and then call gdk_gl_context_realize(). If either of these two steps
fails, it's possible to recover by changing the requirements, or simply
creating a new GdkGLContext instance.
https://bugzilla.gnome.org/show_bug.cgi?id=741946
2015-01-27 21:23:23 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (priv->extensions_checked)
|
|
|
|
|
return;
|
|
|
|
|
|
2015-02-12 14:28:22 +00:00
|
|
|
|
priv->gl_version = epoxy_gl_version ();
|
|
|
|
|
|
2019-12-17 08:06:15 +00:00
|
|
|
|
priv->has_debug_output = epoxy_has_gl_extension ("GL_ARB_debug_output") ||
|
|
|
|
|
epoxy_has_gl_extension ("GL_KHR_debug");
|
2018-03-25 13:28:40 +00:00
|
|
|
|
|
2020-10-05 18:08:55 +00:00
|
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
|
display = gdk_draw_context_get_display (GDK_DRAW_CONTEXT (context));
|
|
|
|
|
gl_debug = GDK_DISPLAY_DEBUG_CHECK (display, GL_DEBUG);
|
2020-10-06 13:25:47 +00:00
|
|
|
|
#endif
|
2020-10-05 18:08:55 +00:00
|
|
|
|
|
2020-10-06 13:25:47 +00:00
|
|
|
|
if (priv->has_debug_output
|
|
|
|
|
#ifndef G_ENABLE_CONSISTENCY_CHECKS
|
|
|
|
|
&& gl_debug
|
|
|
|
|
#endif
|
|
|
|
|
)
|
2018-03-25 13:28:40 +00:00
|
|
|
|
{
|
|
|
|
|
gdk_gl_context_make_current (context);
|
|
|
|
|
glEnable (GL_DEBUG_OUTPUT);
|
|
|
|
|
glEnable (GL_DEBUG_OUTPUT_SYNCHRONOUS);
|
|
|
|
|
glDebugMessageCallback (gl_debug_message_callback, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-07 20:10:39 +00:00
|
|
|
|
if (gdk_gl_context_get_use_es (context))
|
2016-04-22 16:27:04 +00:00
|
|
|
|
{
|
|
|
|
|
priv->has_unpack_subimage = epoxy_has_gl_extension ("GL_EXT_unpack_subimage");
|
2019-04-24 11:25:46 +00:00
|
|
|
|
priv->has_khr_debug = epoxy_has_gl_extension ("GL_KHR_debug");
|
2016-04-22 16:27:04 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
priv->has_unpack_subimage = TRUE;
|
2019-04-24 11:25:46 +00:00
|
|
|
|
priv->has_khr_debug = epoxy_has_gl_extension ("GL_KHR_debug");
|
2016-10-21 20:21:39 +00:00
|
|
|
|
|
|
|
|
|
/* We asked for a core profile, but we didn't get one, so we're in legacy mode */
|
|
|
|
|
if (priv->gl_version < 32)
|
|
|
|
|
priv->is_legacy = TRUE;
|
2016-04-22 16:27:04 +00:00
|
|
|
|
}
|
2014-11-06 11:13:08 +00:00
|
|
|
|
|
2020-01-29 11:00:48 +00:00
|
|
|
|
if (priv->has_khr_debug && gl_debug)
|
2019-04-27 07:49:41 +00:00
|
|
|
|
{
|
|
|
|
|
priv->use_khr_debug = TRUE;
|
|
|
|
|
glGetIntegerv (GL_MAX_LABEL_LENGTH, &priv->max_debug_label_length);
|
|
|
|
|
}
|
2014-10-27 20:12:40 +00:00
|
|
|
|
|
2020-02-04 21:54:19 +00:00
|
|
|
|
GDK_DISPLAY_NOTE (gdk_draw_context_get_display (GDK_DRAW_CONTEXT (context)), OPENGL,
|
2018-01-12 00:48:27 +00:00
|
|
|
|
g_message ("%s version: %d.%d (%s)\n"
|
2016-10-21 20:21:39 +00:00
|
|
|
|
"* GLSL version: %s\n"
|
2016-04-22 16:27:04 +00:00
|
|
|
|
"* Extensions checked:\n"
|
2019-04-24 11:25:46 +00:00
|
|
|
|
" - GL_KHR_debug: %s\n"
|
2021-10-05 23:32:22 +00:00
|
|
|
|
" - GL_EXT_unpack_subimage: %s",
|
2021-10-07 20:10:39 +00:00
|
|
|
|
gdk_gl_context_get_use_es (context) ? "OpenGL ES" : "OpenGL",
|
2016-02-28 20:39:05 +00:00
|
|
|
|
priv->gl_version / 10, priv->gl_version % 10,
|
2016-10-21 20:21:39 +00:00
|
|
|
|
priv->is_legacy ? "legacy" : "core",
|
|
|
|
|
glGetString (GL_SHADING_LANGUAGE_VERSION),
|
2019-04-24 11:25:46 +00:00
|
|
|
|
priv->has_khr_debug ? "yes" : "no",
|
2021-10-05 23:32:22 +00:00
|
|
|
|
priv->has_unpack_subimage ? "yes" : "no"));
|
2015-02-05 16:23:04 +00:00
|
|
|
|
|
GL: Split GL context creation in two phases
One of the major requests by OpenGL users has been the ability to
specify settings when creating a GL context, like the version to use
or whether the debug support should be enabled.
We have a couple of requirements in terms of API:
• avoid, if at all possible, the "C arrays of integers with
attribute, value pairs", which are hard to write and hard
to bind in non-C languages.
• allow failing in a recoverable way.
• do not make the GL context creation API a mess of arguments.
Looking at prior art, it seems that a common pattern is to split the
construction phase in two:
• a first phase that creates a GL context wrapper object and
does preliminary checks on the environment.
• a second phase that creates the backend-specific GL object.
We adopted a similar pattern:
• gdk_window_create_gl_context() creates a GdkGLContext
• gdk_gl_context_realize() creates the underlying resources
Calling gdk_gl_context_make_current() also realizes the context, so
simple GL users do not need to care. Advanced users will want to
call gdk_window_create_gl_context(), set up the optional requirements,
and then call gdk_gl_context_realize(). If either of these two steps
fails, it's possible to recover by changing the requirements, or simply
creating a new GdkGLContext instance.
https://bugzilla.gnome.org/show_bug.cgi?id=741946
2015-01-27 21:23:23 +00:00
|
|
|
|
priv->extensions_checked = TRUE;
|
2014-10-27 20:12:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-09 08:45:44 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_gl_context_make_current:
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* @context: a `GdkGLContext`
|
2014-10-09 08:45:44 +00:00
|
|
|
|
*
|
|
|
|
|
* Makes the @context the current one.
|
|
|
|
|
*/
|
2014-10-09 15:24:21 +00:00
|
|
|
|
void
|
2014-10-09 08:45:44 +00:00
|
|
|
|
gdk_gl_context_make_current (GdkGLContext *context)
|
|
|
|
|
{
|
2021-07-06 02:47:15 +00:00
|
|
|
|
MaskedContext *current, *masked_context;
|
2021-07-07 02:40:34 +00:00
|
|
|
|
gboolean surfaceless;
|
2014-10-09 08:45:44 +00:00
|
|
|
|
|
2014-10-09 15:24:21 +00:00
|
|
|
|
g_return_if_fail (GDK_IS_GL_CONTEXT (context));
|
2014-10-09 08:45:44 +00:00
|
|
|
|
|
2021-07-07 02:40:34 +00:00
|
|
|
|
surfaceless = !gdk_draw_context_is_in_frame (GDK_DRAW_CONTEXT (context));
|
|
|
|
|
masked_context = mask_context (context, surfaceless);
|
2021-07-06 02:47:15 +00:00
|
|
|
|
|
2014-10-30 10:46:09 +00:00
|
|
|
|
current = g_private_get (&thread_current_context);
|
2021-07-06 02:47:15 +00:00
|
|
|
|
if (current == masked_context)
|
2014-10-30 10:46:09 +00:00
|
|
|
|
return;
|
2014-10-27 20:12:40 +00:00
|
|
|
|
|
GL: Split GL context creation in two phases
One of the major requests by OpenGL users has been the ability to
specify settings when creating a GL context, like the version to use
or whether the debug support should be enabled.
We have a couple of requirements in terms of API:
• avoid, if at all possible, the "C arrays of integers with
attribute, value pairs", which are hard to write and hard
to bind in non-C languages.
• allow failing in a recoverable way.
• do not make the GL context creation API a mess of arguments.
Looking at prior art, it seems that a common pattern is to split the
construction phase in two:
• a first phase that creates a GL context wrapper object and
does preliminary checks on the environment.
• a second phase that creates the backend-specific GL object.
We adopted a similar pattern:
• gdk_window_create_gl_context() creates a GdkGLContext
• gdk_gl_context_realize() creates the underlying resources
Calling gdk_gl_context_make_current() also realizes the context, so
simple GL users do not need to care. Advanced users will want to
call gdk_window_create_gl_context(), set up the optional requirements,
and then call gdk_gl_context_realize(). If either of these two steps
fails, it's possible to recover by changing the requirements, or simply
creating a new GdkGLContext instance.
https://bugzilla.gnome.org/show_bug.cgi?id=741946
2015-01-27 21:23:23 +00:00
|
|
|
|
/* we need to realize the GdkGLContext if it wasn't explicitly realized */
|
2021-10-07 20:10:39 +00:00
|
|
|
|
if (!gdk_gl_context_is_realized (context))
|
GL: Split GL context creation in two phases
One of the major requests by OpenGL users has been the ability to
specify settings when creating a GL context, like the version to use
or whether the debug support should be enabled.
We have a couple of requirements in terms of API:
• avoid, if at all possible, the "C arrays of integers with
attribute, value pairs", which are hard to write and hard
to bind in non-C languages.
• allow failing in a recoverable way.
• do not make the GL context creation API a mess of arguments.
Looking at prior art, it seems that a common pattern is to split the
construction phase in two:
• a first phase that creates a GL context wrapper object and
does preliminary checks on the environment.
• a second phase that creates the backend-specific GL object.
We adopted a similar pattern:
• gdk_window_create_gl_context() creates a GdkGLContext
• gdk_gl_context_realize() creates the underlying resources
Calling gdk_gl_context_make_current() also realizes the context, so
simple GL users do not need to care. Advanced users will want to
call gdk_window_create_gl_context(), set up the optional requirements,
and then call gdk_gl_context_realize(). If either of these two steps
fails, it's possible to recover by changing the requirements, or simply
creating a new GdkGLContext instance.
https://bugzilla.gnome.org/show_bug.cgi?id=741946
2015-01-27 21:23:23 +00:00
|
|
|
|
{
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
|
|
gdk_gl_context_realize (context, &error);
|
|
|
|
|
if (error != NULL)
|
|
|
|
|
{
|
|
|
|
|
g_critical ("Could not realize the GL context: %s", error->message);
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-07 02:40:34 +00:00
|
|
|
|
if (!GDK_GL_CONTEXT_GET_CLASS (context)->make_current (context, surfaceless))
|
2014-10-30 10:46:09 +00:00
|
|
|
|
{
|
2021-07-07 02:40:34 +00:00
|
|
|
|
g_warning ("gdk_gl_context_make_current() failed");
|
|
|
|
|
return;
|
2014-10-30 10:46:09 +00:00
|
|
|
|
}
|
2021-07-07 02:40:34 +00:00
|
|
|
|
|
|
|
|
|
g_object_ref (context);
|
|
|
|
|
g_private_replace (&thread_current_context, masked_context);
|
|
|
|
|
gdk_gl_context_check_extensions (context);
|
2014-10-09 08:45:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-03 12:20:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_gl_context_get_display:
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* @context: a `GdkGLContext`
|
2014-11-03 12:20:55 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* Retrieves the display the @context is created for
|
2014-11-03 12:20:55 +00:00
|
|
|
|
*
|
2021-05-21 00:45:06 +00:00
|
|
|
|
* Returns: (nullable) (transfer none): a `GdkDisplay`
|
2014-11-03 12:20:55 +00:00
|
|
|
|
*/
|
|
|
|
|
GdkDisplay *
|
|
|
|
|
gdk_gl_context_get_display (GdkGLContext *context)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GDK_IS_GL_CONTEXT (context), NULL);
|
|
|
|
|
|
2016-11-28 16:36:37 +00:00
|
|
|
|
return gdk_draw_context_get_display (GDK_DRAW_CONTEXT (context));
|
2014-11-03 12:20:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-09 08:45:44 +00:00
|
|
|
|
/**
|
2018-03-20 11:05:26 +00:00
|
|
|
|
* gdk_gl_context_get_surface:
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* @context: a `GdkGLContext`
|
2014-10-09 08:45:44 +00:00
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* Retrieves the surface used by the @context.
|
2014-10-09 08:45:44 +00:00
|
|
|
|
*
|
2021-05-21 00:45:06 +00:00
|
|
|
|
* Returns: (nullable) (transfer none): a `GdkSurface`
|
2014-10-09 08:45:44 +00:00
|
|
|
|
*/
|
2018-03-20 10:40:08 +00:00
|
|
|
|
GdkSurface *
|
2018-03-20 11:05:26 +00:00
|
|
|
|
gdk_gl_context_get_surface (GdkGLContext *context)
|
2014-10-09 08:45:44 +00:00
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GDK_IS_GL_CONTEXT (context), NULL);
|
|
|
|
|
|
2018-03-20 11:05:26 +00:00
|
|
|
|
return gdk_draw_context_get_surface (GDK_DRAW_CONTEXT (context));
|
2014-10-09 08:45:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-30 11:04:23 +00:00
|
|
|
|
/**
|
2021-02-25 01:04:17 +00:00
|
|
|
|
* gdk_gl_context_get_shared_context: (attributes org.gtk.Method.get_property=shared-context)
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* @context: a `GdkGLContext`
|
2014-10-30 11:04:23 +00:00
|
|
|
|
*
|
2021-07-10 01:24:00 +00:00
|
|
|
|
* 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.
|
2014-10-30 11:04:23 +00:00
|
|
|
|
*
|
2021-07-10 01:24:00 +00:00
|
|
|
|
* Returns: (nullable) (transfer none): %NULL
|
|
|
|
|
*
|
|
|
|
|
* Deprecated: 4.4: Use [method@Gdk.GLContext.is_shared] to check if contexts
|
|
|
|
|
* can be shared.
|
2014-10-30 11:04:23 +00:00
|
|
|
|
*/
|
|
|
|
|
GdkGLContext *
|
|
|
|
|
gdk_gl_context_get_shared_context (GdkGLContext *context)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GDK_IS_GL_CONTEXT (context), NULL);
|
|
|
|
|
|
2021-07-10 01:24:00 +00:00
|
|
|
|
return NULL;
|
2014-10-30 11:04:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-12 14:28:22 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_gl_context_get_version:
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* @context: a `GdkGLContext`
|
2015-02-12 14:28:22 +00:00
|
|
|
|
* @major: (out): return location for the major version
|
|
|
|
|
* @minor: (out): return location for the minor version
|
|
|
|
|
*
|
|
|
|
|
* Retrieves the OpenGL version of the @context.
|
|
|
|
|
*
|
|
|
|
|
* The @context must be realized prior to calling this function.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gdk_gl_context_get_version (GdkGLContext *context,
|
|
|
|
|
int *major,
|
|
|
|
|
int *minor)
|
|
|
|
|
{
|
|
|
|
|
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GDK_IS_GL_CONTEXT (context));
|
2021-10-07 20:10:39 +00:00
|
|
|
|
g_return_if_fail (gdk_gl_context_is_realized (context));
|
2015-02-12 14:28:22 +00:00
|
|
|
|
|
|
|
|
|
if (major != NULL)
|
|
|
|
|
*major = priv->gl_version / 10;
|
|
|
|
|
if (minor != NULL)
|
|
|
|
|
*minor = priv->gl_version % 10;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-09 08:45:44 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_gl_context_clear_current:
|
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* Clears the current `GdkGLContext`.
|
2014-10-09 08:45:44 +00:00
|
|
|
|
*
|
|
|
|
|
* Any OpenGL call after this function returns will be ignored
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* until [method@Gdk.GLContext.make_current] is called.
|
2014-10-09 08:45:44 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gdk_gl_context_clear_current (void)
|
|
|
|
|
{
|
2021-07-06 02:47:15 +00:00
|
|
|
|
MaskedContext *current;
|
2014-10-09 08:45:44 +00:00
|
|
|
|
|
2014-10-30 10:46:09 +00:00
|
|
|
|
current = g_private_get (&thread_current_context);
|
|
|
|
|
if (current != NULL)
|
|
|
|
|
{
|
2021-07-07 02:40:34 +00:00
|
|
|
|
GdkGLContext *context = unmask_context (current);
|
|
|
|
|
|
|
|
|
|
if (GDK_GL_CONTEXT_GET_CLASS (context)->clear_current (context))
|
2014-10-30 10:46:09 +00:00
|
|
|
|
g_private_replace (&thread_current_context, NULL);
|
|
|
|
|
}
|
2014-10-09 08:45:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-22 18:49:13 +00:00
|
|
|
|
/*<private>
|
|
|
|
|
* gdk_gl_context_clear_current_if_surface:
|
|
|
|
|
* @surface: surface to clear for
|
|
|
|
|
*
|
|
|
|
|
* Does a gdk_gl_context_clear_current() if the current context is attached
|
|
|
|
|
* to @surface, leaves the current context alone otherwise.
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
gdk_gl_context_clear_current_if_surface (GdkSurface *surface)
|
|
|
|
|
{
|
|
|
|
|
MaskedContext *current;
|
|
|
|
|
|
|
|
|
|
current = g_private_get (&thread_current_context);
|
|
|
|
|
if (current != NULL && !mask_is_surfaceless (current))
|
|
|
|
|
{
|
|
|
|
|
GdkGLContext *context = unmask_context (current);
|
|
|
|
|
|
|
|
|
|
if (gdk_gl_context_get_surface (context) != surface)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (GDK_GL_CONTEXT_GET_CLASS (context)->clear_current (context))
|
|
|
|
|
g_private_replace (&thread_current_context, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-09 08:45:44 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_gl_context_get_current:
|
|
|
|
|
*
|
2021-02-21 05:13:57 +00:00
|
|
|
|
* Retrieves the current `GdkGLContext`.
|
2014-10-09 08:45:44 +00:00
|
|
|
|
*
|
2021-05-21 00:45:06 +00:00
|
|
|
|
* Returns: (nullable) (transfer none): the current `GdkGLContext`
|
2014-10-09 08:45:44 +00:00
|
|
|
|
*/
|
|
|
|
|
GdkGLContext *
|
|
|
|
|
gdk_gl_context_get_current (void)
|
|
|
|
|
{
|
2021-07-06 02:47:15 +00:00
|
|
|
|
MaskedContext *current;
|
2014-10-30 10:46:09 +00:00
|
|
|
|
|
|
|
|
|
current = g_private_get (&thread_current_context);
|
2014-10-09 08:45:44 +00:00
|
|
|
|
|
2021-07-06 02:47:15 +00:00
|
|
|
|
return unmask_context (current);
|
2014-10-09 08:45:44 +00:00
|
|
|
|
}
|
2020-07-24 16:54:23 +00:00
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
|
gdk_gl_context_has_debug (GdkGLContext *self)
|
|
|
|
|
{
|
|
|
|
|
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (self);
|
|
|
|
|
|
|
|
|
|
return priv->debug_enabled || priv->use_khr_debug;
|
|
|
|
|
}
|
2018-07-31 10:18:59 +00:00
|
|
|
|
|
|
|
|
|
/* This is currently private! */
|
|
|
|
|
/* When using GL/ES, don't flip the 'R' and 'B' bits on Windows/ANGLE for glReadPixels() */
|
|
|
|
|
gboolean
|
|
|
|
|
gdk_gl_context_use_es_bgra (GdkGLContext *context)
|
|
|
|
|
{
|
|
|
|
|
if (!gdk_gl_context_get_use_es (context))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
#ifdef GDK_WINDOWING_WIN32
|
|
|
|
|
if (GDK_WIN32_IS_GL_CONTEXT (context))
|
|
|
|
|
return TRUE;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2021-09-23 23:47:03 +00:00
|
|
|
|
|
|
|
|
|
static GdkGLBackend the_gl_backend_type = GDK_GL_NONE;
|
|
|
|
|
|
|
|
|
|
static const char *gl_backend_names[] = {
|
|
|
|
|
[GDK_GL_NONE] = "No GL (You should never read this)",
|
|
|
|
|
[GDK_GL_EGL] = "EGL",
|
|
|
|
|
[GDK_GL_GLX] = "X11 GLX",
|
|
|
|
|
[GDK_GL_WGL] = "Windows WGL",
|
|
|
|
|
[GDK_GL_CGL] = "Apple CGL"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*<private>
|
|
|
|
|
* gdk_gl_backend_can_be_used:
|
|
|
|
|
* @backend_type: Type of backend to check
|
|
|
|
|
* @error: Return location for an error
|
|
|
|
|
*
|
|
|
|
|
* Checks if this backend type can be used. When multiple displays
|
|
|
|
|
* are opened that use different GL backends, conflicts can arise,
|
|
|
|
|
* so this function checks that all displays use compatible GL
|
|
|
|
|
* backends.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if the backend can still be used
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gdk_gl_backend_can_be_used (GdkGLBackend backend_type,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
2022-05-06 14:40:13 +00:00
|
|
|
|
if (the_gl_backend_type == GDK_GL_NONE ||
|
2021-09-23 23:47:03 +00:00
|
|
|
|
the_gl_backend_type == backend_type)
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
g_set_error (error, GDK_GL_ERROR, GDK_GL_ERROR_NOT_AVAILABLE,
|
|
|
|
|
/* translators: This is about OpenGL backend names, like
|
|
|
|
|
* "Trying to use X11 GLX, but EGL is already in use" */
|
|
|
|
|
_("Trying to use %s, but %s is already in use"),
|
|
|
|
|
gl_backend_names[backend_type],
|
|
|
|
|
gl_backend_names[the_gl_backend_type]);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*<private>
|
|
|
|
|
* gdk_gl_backend_use:
|
|
|
|
|
* @backend_type: Type of backend
|
|
|
|
|
*
|
|
|
|
|
* Ensures that the backend in use is the given one. If another backend
|
|
|
|
|
* is already in use, this function will abort the program. It should
|
|
|
|
|
* have previously checked via gdk_gl_backend_can_be_used().
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
gdk_gl_backend_use (GdkGLBackend backend_type)
|
|
|
|
|
{
|
|
|
|
|
/* Check that the context class is properly initializing its backend type */
|
|
|
|
|
g_assert (backend_type != GDK_GL_NONE);
|
|
|
|
|
|
|
|
|
|
if (the_gl_backend_type == GDK_GL_NONE)
|
|
|
|
|
{
|
|
|
|
|
the_gl_backend_type = backend_type;
|
|
|
|
|
/* This is important!!!11eleven
|
|
|
|
|
* (But really: How do I print a message in 2 categories?) */
|
|
|
|
|
GDK_NOTE (OPENGL, g_print ("Using OpenGL backend %s\n", gl_backend_names[the_gl_backend_type]));
|
|
|
|
|
GDK_NOTE (MISC, g_message ("Using Opengl backend %s", gl_backend_names[the_gl_backend_type]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_assert (the_gl_backend_type == backend_type);
|
|
|
|
|
}
|