gl renderer: Generate queries only on desktop GL

On desktop GL, GL 1.5 or GL_ARB_occlusion_query is required to get the
glGenQueries() etc. symbols.  This isn’t the case on GLES, where they
are provided by GL_EXT_occlusion_query_boolean, and more importantly
have never been made core.

This patch allows gtk4-demo to start when GDK_DEBUG=gl-gles is set, on
my Mali 400 MP running the Lima driver from Mesa.
This commit is contained in:
Emmanuel Gil Peyrot 2020-11-07 20:14:07 +00:00
parent 638987f359
commit 08193ecf1c

View File

@ -18,6 +18,7 @@ struct _GskGLProfiler
GLuint gl_queries[N_QUERIES];
GLuint active_query;
gboolean has_queries : 1;
gboolean has_timer : 1;
gboolean first_frame : 1;
};
@ -37,7 +38,8 @@ gsk_gl_profiler_finalize (GObject *gobject)
{
GskGLProfiler *self = GSK_GL_PROFILER (gobject);
glDeleteQueries (N_QUERIES, self->gl_queries);
if (self->has_queries)
glDeleteQueries (N_QUERIES, self->gl_queries);
g_clear_object (&self->gl_context);
@ -106,10 +108,14 @@ gsk_gl_profiler_class_init (GskGLProfilerClass *klass)
static void
gsk_gl_profiler_init (GskGLProfiler *self)
{
glGenQueries (N_QUERIES, self->gl_queries);
self->has_queries = epoxy_is_desktop_gl();
self->has_timer = epoxy_is_desktop_gl() && (epoxy_gl_version () >= 33 || epoxy_has_gl_extension ("GL_ARB_timer_query"));
if (!self->has_queries)
return;
glGenQueries (N_QUERIES, self->gl_queries);
self->first_frame = TRUE;
self->has_timer = epoxy_gl_version () >= 33 || epoxy_has_gl_extension ("GL_ARB_timer_query");
}
GskGLProfiler *
@ -127,7 +133,7 @@ gsk_gl_profiler_begin_gpu_region (GskGLProfiler *profiler)
g_return_if_fail (GSK_IS_GL_PROFILER (profiler));
if (!profiler->has_timer)
if (!profiler->has_timer || !profiler->has_queries)
return;
query_id = profiler->gl_queries[profiler->active_query];
@ -143,7 +149,7 @@ gsk_gl_profiler_end_gpu_region (GskGLProfiler *profiler)
g_return_val_if_fail (GSK_IS_GL_PROFILER (profiler), 0);
if (!profiler->has_timer)
if (!profiler->has_timer || !profiler->has_queries)
return 0;
glEndQuery (GL_TIME_ELAPSED);