mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-24 12:41:16 +00:00
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.
This commit is contained in:
parent
53312cf696
commit
2601c39cb2
@ -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`
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user