Merge branch 'wip/otte/gles' into 'main'

Fix GLES

Closes #4571

See merge request GNOME/gtk!4285
This commit is contained in:
Benjamin Otte 2021-12-25 15:34:01 +00:00
commit 7118127139
5 changed files with 56 additions and 19 deletions

View File

@ -580,8 +580,8 @@ gdk_gl_context_real_begin_frame (GdkDrawContext *draw_context,
glViewport (0, 0, ww, wh);
#ifdef HAVE_EGL
if (priv->egl_context)
glDrawBuffers (1, (GLenum[1]) { GL_BACK_LEFT });
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 });
#endif
}
@ -1003,16 +1003,33 @@ gdk_gl_context_set_required_version (GdkGLContext *context,
}
gboolean
gdk_gl_context_check_version (GdkGLContext *context,
int required_major,
int required_minor)
gdk_gl_context_check_version (GdkGLContext *self,
int required_gl_major,
int required_gl_minor,
int required_gles_major,
int required_gles_minor)
{
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (self);
g_return_val_if_fail (GDK_IS_GL_CONTEXT (context), FALSE);
g_return_val_if_fail (required_minor < 10, FALSE);
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);
return priv->gl_version >= required_major * 10 + required_minor;
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);
}
}
/**
@ -1329,6 +1346,7 @@ gl_debug_message_callback (GLenum source,
const char *message_source;
const char *message_type;
const char *message_severity;
GLogLevelFlags log_level;
if (severity == GL_DEBUG_SEVERITY_NOTIFICATION)
return;
@ -1390,22 +1408,31 @@ gl_debug_message_callback (GLenum source,
{
case GL_DEBUG_SEVERITY_HIGH:
message_severity = "High";
log_level = G_LOG_LEVEL_CRITICAL;
break;
case GL_DEBUG_SEVERITY_MEDIUM:
message_severity = "Medium";
log_level = G_LOG_LEVEL_WARNING;
break;
case GL_DEBUG_SEVERITY_LOW:
message_severity = "Low";
log_level = G_LOG_LEVEL_MESSAGE;
break;
case GL_DEBUG_SEVERITY_NOTIFICATION:
message_severity = "Notification";
log_level = G_LOG_LEVEL_INFO;
break;
default:
message_severity = "Unknown";
log_level = G_LOG_LEVEL_MESSAGE;
}
g_warning ("OPENGL:\n Source: %s\n Type: %s\n Severity: %s\n Message: %s",
message_source, message_type, message_severity, message);
/* 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);
}
/**

View File

@ -111,8 +111,10 @@ void gdk_gl_context_set_is_legacy (GdkGLContext
gboolean is_legacy);
gboolean gdk_gl_context_check_version (GdkGLContext *context,
int required_major,
int required_minor);
int required_gl_major,
int required_gl_minor,
int required_gles_major,
int required_gles_minor);
gboolean gdk_gl_context_has_unpack_subimage (GdkGLContext *context);
void gdk_gl_context_push_debug_group (GdkGLContext *context,

View File

@ -21,6 +21,7 @@
#include "gdkgltextureprivate.h"
#include "gdkdisplayprivate.h"
#include "gdkglcontextprivate.h"
#include "gdkmemoryformatprivate.h"
#include "gdkmemorytextureprivate.h"
#include "gdktextureprivate.h"
@ -305,9 +306,11 @@ gdk_gl_texture_determine_format (GdkGLTexture *self)
GLint active_texture;
GLint internal_format;
if (self->context != gdk_gl_context_get_current ())
/* Abort if somebody else is GL-ing here... */
if (self->context != gdk_gl_context_get_current () ||
/* ... or glGetTexLevelParameter() isn't supported */
!gdk_gl_context_check_version (self->context, 0, 0, 3, 1))
{
/* Somebody else is GL-ing here, abort! */
texture->format = GDK_MEMORY_DEFAULT;
return;
}

View File

@ -1396,7 +1396,7 @@ gsk_gl_command_queue_do_upload_texture (GskGLCommandQueue *self,
glTexImage2D (GL_TEXTURE_2D, 0, gl_internalformat, width, height, 0, gl_format, gl_type, data);
}
else if (stride % bpp == 0 &&
(!use_es || gdk_gl_context_check_version (context, 3, 0) || gdk_gl_context_has_unpack_subimage (context)))
(gdk_gl_context_check_version (context, 0, 0, 3, 0) || gdk_gl_context_has_unpack_subimage (context)))
{
glPixelStorei (GL_UNPACK_ROW_LENGTH, stride / bpp);

View File

@ -4117,14 +4117,19 @@ gsk_gl_render_job_set_debug_fallback (GskGLRenderJob *job,
}
static int
get_framebuffer_format (guint framebuffer)
get_framebuffer_format (GdkGLContext *context,
guint framebuffer)
{
int size;
if (!gdk_gl_context_check_version (context, 0, 0, 3, 0))
return GL_RGBA8;
glBindFramebuffer (GL_FRAMEBUFFER, framebuffer);
glGetFramebufferAttachmentParameteriv (GL_FRAMEBUFFER,
framebuffer ? GL_COLOR_ATTACHMENT0
: GL_BACK_LEFT,
: gdk_gl_context_get_use_es (context) ? GL_BACK
: GL_BACK_LEFT,
GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE, &size);
if (size > 16)
@ -4161,7 +4166,7 @@ gsk_gl_render_job_new (GskGLDriver *driver,
job->scale_x = scale_factor;
job->scale_y = scale_factor;
job->viewport = *viewport;
job->target_format = get_framebuffer_format (framebuffer);
job->target_format = get_framebuffer_format (job->command_queue->context, framebuffer);
gsk_gl_render_job_set_alpha (job, 1.0f);
gsk_gl_render_job_set_projection_from_rect (job, viewport, NULL);