[gtk/wip/otte/display-gl: 2/6] API: Add gdk_display_create_gl_context()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/display-gl: 2/6] API: Add gdk_display_create_gl_context()
- Date: Wed, 20 Oct 2021 18:44:21 +0000 (UTC)
commit 2601c39cb2cd985f316fb03439a3a30325c3ea64
Author: Benjamin Otte <otte redhat com>
Date: Wed Oct 20 20:03:00 2021 +0200
API: Add gdk_display_create_gl_context()
This is an alternative to gdk_surface_create_gl_context() when the
context is meant to only draw to textures.
This is useful in the testsuite or in GStreamer or with GLArea,
basically whenever we want to do GL stuff but don't need to actually
draw anything on screen.
A bunch of code will need to be updated to deal with context->surface
being NULL.
gdk/gdkdisplay.c | 32 ++++++++++++++++++++++++++++++++
gdk/gdkdisplay.h | 3 +++
gdk/gdkglcontext.c | 10 +++++++---
gdk/gdkglcontextprivate.h | 3 ++-
gdk/gdksurface.c | 2 +-
5 files changed, 45 insertions(+), 5 deletions(-)
---
diff --git a/gdk/gdkdisplay.c b/gdk/gdkdisplay.c
index 075342a26b..d5defbeb82 100644
--- a/gdk/gdkdisplay.c
+++ b/gdk/gdkdisplay.c
@@ -1325,6 +1325,38 @@ gdk_display_prepare_gl (GdkDisplay *self,
}
}
+/**
+ * gdk_display_create_gl_context:
+ * @self: a `GdkDisplay`
+ * @error: return location for an error
+ *
+ * Creates a new `GdkGLContext` for the `GdkDisplay`.
+ *
+ * The context is disconnected from any particular surface or surface
+ * and cannot be used to draw to any surface. It can only be used to
+ * draw to non-surface framebuffers like textures.
+ *
+ * If the creation of the `GdkGLContext` failed, @error will be set.
+ * Before using the returned `GdkGLContext`, you will need to
+ * call [method@Gdk.GLContext.make_current] or [method@Gdk.GLContext.realize].
+ *
+ * Returns: (transfer full) (nullable): the newly created `GdkGLContext`
+ *
+ * Since: 4.6
+ */
+GdkGLContext *
+gdk_display_create_gl_context (GdkDisplay *self,
+ GError **error)
+{
+ g_return_val_if_fail (GDK_IS_DISPLAY (self), NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+ if (!gdk_display_prepare_gl (self, error))
+ return NULL;
+
+ return gdk_gl_context_new (self, NULL);
+}
+
/*< private >
* gdk_display_get_gl_context:
* @self: the `GdkDisplay`
diff --git a/gdk/gdkdisplay.h b/gdk/gdkdisplay.h
index 9fabac6b50..52aa502247 100644
--- a/gdk/gdkdisplay.h
+++ b/gdk/gdkdisplay.h
@@ -71,6 +71,9 @@ gboolean gdk_display_supports_input_shapes (GdkDisplay *display);
GDK_AVAILABLE_IN_4_4
gboolean gdk_display_prepare_gl (GdkDisplay *self,
GError **error);
+GDK_AVAILABLE_IN_4_6
+GdkGLContext *gdk_display_create_gl_context(GdkDisplay *self,
+ GError **error);
GDK_AVAILABLE_IN_ALL
GdkDisplay *gdk_display_get_default (void);
diff --git a/gdk/gdkglcontext.c b/gdk/gdkglcontext.c
index 812a3cd9d8..422e0a189e 100644
--- a/gdk/gdkglcontext.c
+++ b/gdk/gdkglcontext.c
@@ -722,15 +722,19 @@ gdk_gl_context_init (GdkGLContext *self)
/* Must have called gdk_display_prepare_gl() before */
GdkGLContext *
-gdk_gl_context_new_for_surface (GdkSurface *surface)
+gdk_gl_context_new (GdkDisplay *display,
+ GdkSurface *surface)
{
- GdkDisplay *display = gdk_surface_get_display (surface);
- GdkGLContext *shared = gdk_display_get_gl_context (display);
+ GdkGLContext *shared;
+
+ g_assert (surface == NULL || display == gdk_surface_get_display (surface));
/* assert gdk_display_prepare_gl() had been called */
+ shared = gdk_display_get_gl_context (display);
g_assert (shared);
return g_object_new (G_OBJECT_TYPE (shared),
+ "display", display,
"surface", surface,
NULL);
}
diff --git a/gdk/gdkglcontextprivate.h b/gdk/gdkglcontextprivate.h
index 56fe04f903..e07420f1c1 100644
--- a/gdk/gdkglcontextprivate.h
+++ b/gdk/gdkglcontextprivate.h
@@ -99,7 +99,8 @@ gboolean gdk_gl_backend_can_be_used (GdkGLBackend
GError **error);
void gdk_gl_backend_use (GdkGLBackend backend_type);
-GdkGLContext * gdk_gl_context_new_for_surface (GdkSurface *surface);
+GdkGLContext * gdk_gl_context_new (GdkDisplay *display,
+ GdkSurface *surface);
gboolean gdk_gl_context_is_api_allowed (GdkGLContext *self,
GdkGLAPI api,
diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c
index 9430a4a111..5b0c947ed3 100644
--- a/gdk/gdksurface.c
+++ b/gdk/gdksurface.c
@@ -1183,7 +1183,7 @@ gdk_surface_create_gl_context (GdkSurface *surface,
if (!gdk_display_prepare_gl (surface->display, error))
return NULL;
- return gdk_gl_context_new_for_surface (surface);
+ return gdk_gl_context_new (surface->display, surface);
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]