summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2021-09-12 00:14:19 +0200
committerBenjamin Otte <otte@redhat.com>2021-09-12 05:22:21 +0200
commitc349ed956269129841a881343cd1d5841d4daa2c (patch)
tree624bed6b35510ed7d1328455ca390391e4d7535f
parent74ce69a8a1187c9f4b65a0f8d38363f0d83b7574 (diff)
downloadgtk+-c349ed956269129841a881343cd1d5841d4daa2c.tar.gz
gltexture: Implement download() via glGetTexImage()
1. The download via gdk_cairo_draw_from_gl() was broken sometimes 2. We get easy conversion on fallback by chaining up and using download_texture(). 3. One more place where Cairo is no longer necessary.
-rw-r--r--gdk/gdkgltexture.c42
1 files changed, 23 insertions, 19 deletions
diff --git a/gdk/gdkgltexture.c b/gdk/gdkgltexture.c
index ef95c4604b..bd69809061 100644
--- a/gdk/gdkgltexture.c
+++ b/gdk/gdkgltexture.c
@@ -20,7 +20,6 @@
#include "gdkgltextureprivate.h"
-#include "gdkcairo.h"
#include "gdkmemorytextureprivate.h"
#include "gdktextureprivate.h"
@@ -145,10 +144,7 @@ gdk_gl_texture_download (GdkTexture *texture,
gsize stride)
{
GdkGLTexture *self = GDK_GL_TEXTURE (texture);
- GdkSurface *gl_surface;
- cairo_surface_t *surface;
- cairo_t *cr;
- int width, height;
+ GLint active_texture;
if (self->saved)
{
@@ -156,23 +152,31 @@ gdk_gl_texture_download (GdkTexture *texture,
return;
}
- width = gdk_texture_get_width (texture);
- height = gdk_texture_get_width (texture);
- surface = cairo_image_surface_create_for_data (data,
- CAIRO_FORMAT_ARGB32,
- width, height,
- stride);
+ if (gdk_gl_context_get_use_es (self->context) ||
+ stride != texture->width * 4)
+ {
+ GDK_TEXTURE_CLASS (gdk_gl_texture_parent_class)->download (texture, data, stride);
+ return;
+ }
- cr = cairo_create (surface);
+ gdk_gl_context_make_current (self->context);
- gl_surface = gdk_gl_context_get_surface (self->context);
- gdk_cairo_draw_from_gl (cr, gl_surface, self->id, GL_TEXTURE, 1,
- 0, 0,
- width, height);
+ glGetIntegerv (GL_TEXTURE_BINDING_2D, &active_texture);
+ glBindTexture (GL_TEXTURE_2D, self->id);
- cairo_destroy (cr);
- cairo_surface_finish (surface);
- cairo_surface_destroy (surface);
+ glGetTexImage (GL_TEXTURE_2D,
+ 0,
+ GL_BGRA,
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+ GL_UNSIGNED_INT_8_8_8_8_REV,
+#elif G_BYTE_ORDER == G_BIG_ENDIAN
+ GL_UNSIGNED_BYTE,
+#else
+#error "Unknown byte order for gdk_gl_texture_download()"
+#endif
+ data);
+
+ glBindTexture (GL_TEXTURE_2D, active_texture);
}
static void