gltexture: Use the right context

When checking characteristics of the context
for downloading, we were using self->context,
even though we are using a possibly different
context for downloading.

Pass the right context along and use it.
This commit is contained in:
Matthias Clasen 2023-01-31 07:23:59 -05:00
parent cab5f2bd8d
commit 1cb621633c

View File

@ -72,11 +72,15 @@ gdk_gl_texture_dispose (GObject *object)
G_OBJECT_CLASS (gdk_gl_texture_parent_class)->dispose (object);
}
typedef void (* GLFunc) (GdkGLTexture *self,
gpointer data,
GdkGLContext *context);
typedef struct _InvokeData
{
GdkGLTexture *self;
volatile int spinlock;
GFunc func;
GLFunc func;
gpointer data;
} InvokeData;
@ -91,7 +95,7 @@ gdk_gl_texture_invoke_callback (gpointer data)
gdk_gl_context_make_current (context);
glBindTexture (GL_TEXTURE_2D, invoke->self->id);
invoke->func (invoke->self, invoke->data);
invoke->func (invoke->self, invoke->data, context);
g_atomic_int_set (&invoke->spinlock, 1);
@ -100,7 +104,7 @@ gdk_gl_texture_invoke_callback (gpointer data)
static void
gdk_gl_texture_run (GdkGLTexture *self,
GFunc func,
GLFunc func,
gpointer data)
{
InvokeData invoke = { self, 0, func, data };
@ -145,19 +149,19 @@ gdk_gl_texture_find_format (gboolean use_es,
}
static inline void
gdk_gl_texture_do_download (gpointer texture_,
gpointer download_)
gdk_gl_texture_do_download (GdkGLTexture *self,
gpointer download_,
GdkGLContext *context)
{
GdkTexture *texture = GDK_TEXTURE (self);
gsize expected_stride;
GdkGLTexture *self = texture_;
GdkTexture *texture = texture_;
Download *download = download_;
GLenum gl_internal_format, gl_format, gl_type;
expected_stride = texture->width * gdk_memory_format_bytes_per_pixel (download->format);
if (download->stride == expected_stride &&
!gdk_gl_context_get_use_es (self->context) &&
!gdk_gl_context_get_use_es (context) &&
gdk_memory_format_gl_format (download->format, TRUE, &gl_internal_format, &gl_format, &gl_type))
{
glGetTexImage (GL_TEXTURE_2D,
@ -175,11 +179,11 @@ gdk_gl_texture_do_download (gpointer texture_,
glGenFramebuffers (1, &fbo);
glBindFramebuffer (GL_FRAMEBUFFER, fbo);
glFramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, self->id, 0);
if (gdk_gl_context_check_version (self->context, 4, 3, 3, 1))
if (gdk_gl_context_check_version (context, 4, 3, 3, 1))
{
glGetFramebufferParameteriv (GL_FRAMEBUFFER, GL_IMPLEMENTATION_COLOR_READ_FORMAT, &gl_read_format);
glGetFramebufferParameteriv (GL_FRAMEBUFFER, GL_IMPLEMENTATION_COLOR_READ_TYPE, &gl_read_type);
if (!gdk_gl_texture_find_format (gdk_gl_context_get_use_es (self->context), gl_read_format, gl_read_type, &actual_format))
if (!gdk_gl_texture_find_format (gdk_gl_context_get_use_es (context), gl_read_format, gl_read_type, &actual_format))
actual_format = GDK_MEMORY_R8G8B8A8_PREMULTIPLIED; /* pray */
}
else
@ -193,7 +197,7 @@ gdk_gl_texture_do_download (gpointer texture_,
(download->stride == expected_stride))
{
glReadPixels (0, 0,
texture->width, texture->height,
texture->width, texture->height,
gl_read_format,
gl_read_type,
download->data);
@ -204,7 +208,7 @@ gdk_gl_texture_do_download (gpointer texture_,
guchar *pixels = g_malloc_n (texture->width * actual_bpp, texture->height);
glReadPixels (0, 0,
texture->width, texture->height,
texture->width, texture->height,
gl_read_format,
gl_read_type,
pixels);