mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-08 09:40:10 +00:00
gl: Turn has_foo flags into GdkGLFeatures
The goal is to have it mirror GdkVulkanFeatures, and in particular having an environment variable to turn individual flags off.
This commit is contained in:
parent
0fdb6a9243
commit
141769fb46
@ -125,7 +125,7 @@ gdk_cairo_draw_from_gl (cairo_t *cr,
|
||||
* the GL_UNPACK_ROW_LENGTH support
|
||||
*/
|
||||
if (gdk_gl_context_get_use_es (paint_context) &&
|
||||
!(version >= 300 || gdk_gl_context_has_unpack_subimage (paint_context)))
|
||||
!(version >= 300 || gdk_gl_context_has_feature (paint_context, GDK_GL_FEATURE_UNPACK_SUBIMAGE)))
|
||||
return;
|
||||
|
||||
/* TODO: avoid reading back non-required data due to dest clip */
|
||||
|
@ -112,13 +112,9 @@ struct _GdkGLContextPrivate
|
||||
|
||||
GdkGLMemoryFlags memory_flags[GDK_MEMORY_N_FORMATS];
|
||||
|
||||
guint has_khr_debug : 1;
|
||||
GdkGLFeatures features;
|
||||
guint use_khr_debug : 1;
|
||||
guint has_half_float : 1;
|
||||
guint has_sync : 1;
|
||||
guint has_unpack_subimage : 1;
|
||||
guint has_debug_output : 1;
|
||||
guint has_bgra : 1;
|
||||
guint extensions_checked : 1;
|
||||
guint debug_enabled : 1;
|
||||
guint forward_compatible : 1;
|
||||
@ -898,11 +894,12 @@ gdk_gl_context_label_object_printf (GdkGLContext *context,
|
||||
|
||||
|
||||
gboolean
|
||||
gdk_gl_context_has_unpack_subimage (GdkGLContext *context)
|
||||
gdk_gl_context_has_feature (GdkGLContext *self,
|
||||
GdkGLFeatures feature)
|
||||
{
|
||||
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
|
||||
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (self);
|
||||
|
||||
return priv->has_unpack_subimage;
|
||||
return (priv->features & feature) == feature;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -1692,34 +1689,39 @@ gdk_gl_context_check_extensions (GdkGLContext *context)
|
||||
|
||||
if (gdk_gl_context_get_use_es (context))
|
||||
{
|
||||
priv->has_unpack_subimage = gdk_gl_version_greater_equal (&priv->gl_version, &GDK_GL_VERSION_INIT (3, 0)) ||
|
||||
epoxy_has_gl_extension ("GL_EXT_unpack_subimage");
|
||||
priv->has_khr_debug = epoxy_has_gl_extension ("GL_KHR_debug");
|
||||
priv->has_bgra = epoxy_has_gl_extension ("GL_EXT_texture_format_BGRA8888");
|
||||
if (gdk_gl_version_greater_equal (&priv->gl_version, &GDK_GL_VERSION_INIT (3, 0)) ||
|
||||
epoxy_has_gl_extension ("GL_EXT_unpack_subimage"))
|
||||
priv->features |= GDK_GL_FEATURE_UNPACK_SUBIMAGE;
|
||||
if (epoxy_has_gl_extension ("GL_EXT_texture_format_BGRA8888"))
|
||||
priv->features |= GDK_GL_FEATURE_BGRA;
|
||||
}
|
||||
else
|
||||
{
|
||||
priv->has_unpack_subimage = TRUE;
|
||||
priv->has_khr_debug = epoxy_has_gl_extension ("GL_KHR_debug");
|
||||
priv->has_bgra = TRUE;
|
||||
priv->features |= GDK_GL_FEATURE_UNPACK_SUBIMAGE | GDK_GL_FEATURE_BGRA;
|
||||
|
||||
/* We asked for a core profile, but we didn't get one, so we're in legacy mode */
|
||||
if (!gdk_gl_version_greater_equal (&priv->gl_version, &GDK_GL_VERSION_INIT (3, 2)))
|
||||
priv->is_legacy = TRUE;
|
||||
}
|
||||
|
||||
if (priv->has_khr_debug && gl_debug)
|
||||
if (epoxy_has_gl_extension ("GL_KHR_debug"))
|
||||
{
|
||||
priv->use_khr_debug = TRUE;
|
||||
glGetIntegerv (GL_MAX_LABEL_LENGTH, &priv->max_debug_label_length);
|
||||
priv->features |= GDK_GL_FEATURE_DEBUG;
|
||||
if (gl_debug)
|
||||
{
|
||||
priv->use_khr_debug = TRUE;
|
||||
glGetIntegerv (GL_MAX_LABEL_LENGTH, &priv->max_debug_label_length);
|
||||
}
|
||||
}
|
||||
|
||||
priv->has_half_float = gdk_gl_context_check_version (context, "3.0", "3.0") ||
|
||||
epoxy_has_gl_extension ("GL_OES_vertex_half_float");
|
||||
if (gdk_gl_context_check_version (context, "3.0", "3.0") ||
|
||||
epoxy_has_gl_extension ("GL_OES_vertex_half_float"))
|
||||
priv->features |= GDK_GL_FEATURE_VERTEX_HALF_FLOAT;
|
||||
|
||||
priv->has_sync = gdk_gl_context_check_version (context, "3.2", "3.0") ||
|
||||
epoxy_has_gl_extension ("GL_ARB_sync") ||
|
||||
epoxy_has_gl_extension ("GL_APPLE_sync");
|
||||
if (gdk_gl_context_check_version (context, "3.2", "3.0") ||
|
||||
epoxy_has_gl_extension ("GL_ARB_sync") ||
|
||||
epoxy_has_gl_extension ("GL_APPLE_sync"))
|
||||
priv->features |= GDK_GL_FEATURE_SYNC;
|
||||
|
||||
gdk_gl_context_init_memory_flags (context);
|
||||
|
||||
@ -1729,23 +1731,12 @@ gdk_gl_context_check_extensions (GdkGLContext *context)
|
||||
GDK_DISPLAY_DEBUG (gdk_draw_context_get_display (GDK_DRAW_CONTEXT (context)), OPENGL,
|
||||
"%s version: %d.%d (%s)\n"
|
||||
"* GLSL version: %s\n"
|
||||
"* Max texture size: %d\n"
|
||||
"* Extensions checked:\n"
|
||||
" - GL_KHR_debug: %s\n"
|
||||
" - GL_EXT_unpack_subimage: %s\n"
|
||||
" - half float: %s\n"
|
||||
" - sync: %s\n"
|
||||
" - bgra: %s",
|
||||
"* Max texture size: %d\n",
|
||||
gdk_gl_context_get_use_es (context) ? "OpenGL ES" : "OpenGL",
|
||||
gdk_gl_version_get_major (&priv->gl_version), gdk_gl_version_get_minor (&priv->gl_version),
|
||||
priv->is_legacy ? "legacy" : "core",
|
||||
glGetString (GL_SHADING_LANGUAGE_VERSION),
|
||||
max_texture_size,
|
||||
priv->has_khr_debug ? "yes" : "no",
|
||||
priv->has_unpack_subimage ? "yes" : "no",
|
||||
priv->has_half_float ? "yes" : "no",
|
||||
priv->has_sync ? "yes" : "no",
|
||||
priv->has_bgra ? "yes" : "no");
|
||||
max_texture_size);
|
||||
}
|
||||
|
||||
priv->extensions_checked = TRUE;
|
||||
@ -2015,30 +2006,6 @@ gdk_gl_context_get_format_flags (GdkGLContext *self,
|
||||
return priv->memory_flags[format];
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gdk_gl_context_has_vertex_half_float (GdkGLContext *self)
|
||||
{
|
||||
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (self);
|
||||
|
||||
return priv->has_half_float;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gdk_gl_context_has_sync (GdkGLContext *self)
|
||||
{
|
||||
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (self);
|
||||
|
||||
return priv->has_sync;
|
||||
}
|
||||
|
||||
/* Return if glGenVertexArrays, glBindVertexArray and glDeleteVertexArrays
|
||||
* can be used
|
||||
*/
|
||||
|
@ -27,6 +27,14 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef enum {
|
||||
GDK_GL_FEATURE_DEBUG = 1 << 0,
|
||||
GDK_GL_FEATURE_UNPACK_SUBIMAGE = 1 << 1,
|
||||
GDK_GL_FEATURE_VERTEX_HALF_FLOAT = 1 << 2,
|
||||
GDK_GL_FEATURE_SYNC = 1 << 3,
|
||||
GDK_GL_FEATURE_BGRA = 1 << 4,
|
||||
} GdkGLFeatures;
|
||||
|
||||
typedef enum {
|
||||
GDK_GL_NONE = 0,
|
||||
GDK_GL_EGL,
|
||||
@ -142,7 +150,6 @@ void gdk_gl_context_get_matching_version (GdkGLContext
|
||||
gboolean legacy,
|
||||
GdkGLVersion *out_version);
|
||||
|
||||
gboolean gdk_gl_context_has_unpack_subimage (GdkGLContext *context);
|
||||
void gdk_gl_context_push_debug_group (GdkGLContext *context,
|
||||
const char *message);
|
||||
void gdk_gl_context_push_debug_group_printf (GdkGLContext *context,
|
||||
@ -163,14 +170,11 @@ const char * gdk_gl_context_get_glsl_version_string (GdkGLContext
|
||||
|
||||
GdkGLMemoryFlags gdk_gl_context_get_format_flags (GdkGLContext *self,
|
||||
GdkMemoryFormat format) G_GNUC_PURE;
|
||||
gboolean gdk_gl_context_has_debug (GdkGLContext *self) G_GNUC_PURE;
|
||||
gboolean gdk_gl_context_has_feature (GdkGLContext *self,
|
||||
GdkGLFeatures feature) G_GNUC_PURE;
|
||||
|
||||
gboolean gdk_gl_context_use_es_bgra (GdkGLContext *context);
|
||||
|
||||
gboolean gdk_gl_context_has_vertex_half_float (GdkGLContext *self) G_GNUC_PURE;
|
||||
|
||||
gboolean gdk_gl_context_has_sync (GdkGLContext *self) G_GNUC_PURE;
|
||||
|
||||
gboolean gdk_gl_context_has_vertex_arrays (GdkGLContext *self) G_GNUC_PURE;
|
||||
|
||||
double gdk_gl_context_get_scale (GdkGLContext *self);
|
||||
|
@ -494,7 +494,7 @@ gdk_gl_texture_new_from_builder (GdkGLTextureBuilder *builder,
|
||||
self->id = gdk_gl_texture_builder_get_id (builder);
|
||||
GDK_TEXTURE (self)->format = gdk_gl_texture_builder_get_format (builder);
|
||||
self->has_mipmap = gdk_gl_texture_builder_get_has_mipmap (builder);
|
||||
if (gdk_gl_context_has_sync (self->context))
|
||||
if (gdk_gl_context_has_feature (self->context, GDK_GL_FEATURE_SYNC))
|
||||
self->sync = gdk_gl_texture_builder_get_sync (builder);
|
||||
self->destroy = destroy;
|
||||
self->data = data;
|
||||
|
@ -1622,7 +1622,7 @@ gsk_gl_command_queue_do_upload_texture_chunk (GskGLCommandQueue *self,
|
||||
{
|
||||
glTexSubImage2D (GL_TEXTURE_2D, 0, x, y, width, height, gl_format, gl_type, data);
|
||||
}
|
||||
else if (stride % bpp == 0 && gdk_gl_context_has_unpack_subimage (self->context))
|
||||
else if (stride % bpp == 0 && gdk_gl_context_has_feature (self->context, GDK_GL_FEATURE_UNPACK_SUBIMAGE))
|
||||
{
|
||||
glPixelStorei (GL_UNPACK_ROW_LENGTH, stride / bpp);
|
||||
|
||||
|
@ -1835,7 +1835,7 @@ gsk_gl_driver_create_gdk_texture (GskGLDriver *self,
|
||||
state = g_new0 (GskGLTextureState, 1);
|
||||
state->texture_id = texture_id;
|
||||
state->context = g_object_ref (self->command_queue->context);
|
||||
if (gdk_gl_context_has_sync (self->command_queue->context))
|
||||
if (gdk_gl_context_has_feature (self->command_queue->context, GDK_GL_FEATURE_SYNC))
|
||||
state->sync = glFenceSync (GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
|
||||
|
||||
g_hash_table_steal (self->textures, GUINT_TO_POINTER (texture_id));
|
||||
|
@ -194,7 +194,7 @@ gsk_gl_renderer_realize (GskRenderer *renderer,
|
||||
{
|
||||
gdk_gl_context_make_current (context);
|
||||
|
||||
if (!gdk_gl_context_has_vertex_half_float (context))
|
||||
if (!gdk_gl_context_has_feature (context, GDK_GL_FEATURE_VERTEX_HALF_FLOAT))
|
||||
{
|
||||
int major, minor;
|
||||
|
||||
|
@ -1235,7 +1235,7 @@ gsk_gl_render_job_visit_as_fallback (GskGLRenderJob *job,
|
||||
texture = gdk_texture_new_for_surface (surface);
|
||||
texture_id = gsk_gl_driver_load_texture (job->driver, texture, FALSE);
|
||||
|
||||
if (gdk_gl_context_has_debug (job->command_queue->context))
|
||||
if (gdk_gl_context_has_feature (job->command_queue->context, GDK_GL_FEATURE_DEBUG))
|
||||
gdk_gl_context_label_object_printf (job->command_queue->context, GL_TEXTURE, texture_id,
|
||||
"Fallback %s %d",
|
||||
g_type_name_from_instance ((GTypeInstance *) node),
|
||||
@ -2532,7 +2532,7 @@ gsk_gl_render_job_visit_blurred_outset_shadow_node (GskGLRenderJob *job,
|
||||
get_target_format (job, node),
|
||||
&render_target);
|
||||
|
||||
if (gdk_gl_context_has_debug (context))
|
||||
if (gdk_gl_context_has_feature (context, GDK_GL_FEATURE_DEBUG))
|
||||
{
|
||||
gdk_gl_context_label_object_printf (context,
|
||||
GL_TEXTURE,
|
||||
@ -4382,7 +4382,7 @@ gsk_gl_render_job_visit_node_with_offscreen (GskGLRenderJob *job,
|
||||
&render_target))
|
||||
g_assert_not_reached ();
|
||||
|
||||
if (gdk_gl_context_has_debug (job->command_queue->context))
|
||||
if (gdk_gl_context_has_feature (job->command_queue->context, GDK_GL_FEATURE_DEBUG))
|
||||
{
|
||||
gdk_gl_context_label_object_printf (job->command_queue->context,
|
||||
GL_TEXTURE,
|
||||
|
@ -272,7 +272,7 @@ gsk_gpu_download_op_gl_command (GskGpuOp *op,
|
||||
data->context = g_object_ref (context);
|
||||
data->texture_id = gsk_gl_image_steal_texture (GSK_GL_IMAGE (self->image));
|
||||
|
||||
if (gdk_gl_context_has_sync (context))
|
||||
if (gdk_gl_context_has_feature (context, GDK_GL_FEATURE_SYNC))
|
||||
data->sync = glFenceSync (GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
|
||||
|
||||
builder = gdk_gl_texture_builder_new ();
|
||||
|
@ -52,7 +52,7 @@ gsk_gpu_upload_op_gl_command_with_area (GskGpuOp *op,
|
||||
{
|
||||
glTexSubImage2D (GL_TEXTURE_2D, 0, area->x, area->y, area->width, area->height, gl_format, gl_type, data);
|
||||
}
|
||||
else if (stride % bpp == 0 && gdk_gl_context_has_unpack_subimage (context))
|
||||
else if (stride % bpp == 0 && gdk_gl_context_has_feature (context, GDK_GL_FEATURE_UNPACK_SUBIMAGE))
|
||||
{
|
||||
glPixelStorei (GL_UNPACK_ROW_LENGTH, stride / bpp);
|
||||
|
||||
|
@ -776,7 +776,7 @@ gtk_gl_area_snapshot (GtkWidget *widget,
|
||||
priv->texture = NULL;
|
||||
priv->textures = g_list_prepend (priv->textures, texture);
|
||||
|
||||
if (gdk_gl_context_has_sync (priv->context))
|
||||
if (gdk_gl_context_has_feature (priv->context, GDK_GL_FEATURE_SYNC))
|
||||
sync = glFenceSync (GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
|
||||
|
||||
gdk_gl_texture_builder_set_sync (texture->builder, sync);
|
||||
|
@ -179,7 +179,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
|
||||
id = make_gl_texture (context, surface);
|
||||
|
||||
if (gdk_gl_context_has_sync (context))
|
||||
if (gdk_gl_context_has_feature (context, GDK_GL_FEATURE_SYNC))
|
||||
sync = glFenceSync (GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
|
||||
else
|
||||
sync = NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user