[retro-gtk/retro-screen: 1/2] pixdata: Add retro_pixdata_load_gl_texture_full()



commit 0ab30ea35bc54f109c68e404e9f328a1ab01ddba
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Thu Jan 30 21:18:48 2020 +0100

    pixdata: Add retro_pixdata_load_gl_texture_full()

 retro-gtk/retro-pixdata.c | 26 +++++++++++++++++++++++---
 retro-gtk/retro-pixdata.h |  3 +++
 2 files changed, 26 insertions(+), 3 deletions(-)
---
diff --git a/retro-gtk/retro-pixdata.c b/retro-gtk/retro-pixdata.c
index b2208d8..6455c94 100644
--- a/retro-gtk/retro-pixdata.c
+++ b/retro-gtk/retro-pixdata.c
@@ -367,6 +367,26 @@ retro_pixdata_to_pixbuf (RetroPixdata *self)
  */
 gboolean
 retro_pixdata_load_gl_texture (RetroPixdata *self)
+{
+  GdkRectangle view = { 0, 0, self->width, self->height };
+
+  g_return_val_if_fail (self != NULL, FALSE);
+
+  return retro_pixdata_load_gl_texture_full (self, &view);
+}
+
+/**
+ * retro_pixdata_load_gl_texture_full:
+ * @self: the #RetroPixdata
+ * @view: a view in the pixbuf
+ *
+ * Loads an OpenGL texture from a view in @self.
+ *
+ * Returns: whether the loading was successful
+ */
+gboolean
+retro_pixdata_load_gl_texture_full (RetroPixdata       *self,
+                                    const GdkRectangle *view)
 {
   GLenum format;
   GLenum type;
@@ -401,11 +421,11 @@ retro_pixdata_load_gl_texture (RetroPixdata *self)
   glTexImage2D (GL_TEXTURE_2D,
                 0,
                 GL_RGB,
-                self->width,
-                self->height,
+                view->width,
+                view->height,
                 0,
                 format, type,
-                self->data);
+                self->data + view->y * self->rowstride + view->x * pixel_size);
   glPixelStorei (GL_UNPACK_ROW_LENGTH, 0);
 
   return TRUE;
diff --git a/retro-gtk/retro-pixdata.h b/retro-gtk/retro-pixdata.h
index d9e4c3b..90d173c 100644
--- a/retro-gtk/retro-pixdata.h
+++ b/retro-gtk/retro-pixdata.h
@@ -6,6 +6,7 @@
 # error "Only <retro-gtk.h> can be included directly."
 #endif
 
+#include <gdk/gdk.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include <glib-object.h>
 
@@ -24,6 +25,8 @@ gint retro_pixdata_get_height (RetroPixdata *self);
 gfloat retro_pixdata_get_aspect_ratio (RetroPixdata *self);
 GdkPixbuf *retro_pixdata_to_pixbuf (RetroPixdata *self);
 gboolean retro_pixdata_load_gl_texture (RetroPixdata *self);
+gboolean retro_pixdata_load_gl_texture_full (RetroPixdata       *self,
+                                             const GdkRectangle *view);
 
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (RetroPixdata, retro_pixdata_free)
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]