[retro-gtk/wip/aplazas/screen] pixdata: Add retro_pixdata_load_rectangle_as_gl_texture()



commit ef45e3d80875e620122426cc69bb37cbf560273f
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Sun Sep 9 12:46:59 2018 +0200

    pixdata: Add retro_pixdata_load_rectangle_as_gl_texture()
    
    This allows to load only a part of the video output of a core as an
    OpenGL texture.

 retro-gtk/retro-pixdata.c | 32 +++++++++++++++++++++++++++++---
 retro-gtk/retro-pixdata.h |  3 +++
 2 files changed, 32 insertions(+), 3 deletions(-)
---
diff --git a/retro-gtk/retro-pixdata.c b/retro-gtk/retro-pixdata.c
index b46c7fa..84b128c 100644
--- a/retro-gtk/retro-pixdata.c
+++ b/retro-gtk/retro-pixdata.c
@@ -364,12 +364,38 @@ retro_pixdata_to_pixbuf (RetroPixdata *self)
  */
 gboolean
 retro_pixdata_load_gl_texture (RetroPixdata *self)
+{
+  GdkRectangle rectangle;
+
+  rectangle.x = 0;
+  rectangle.y = 0;
+  rectangle.width = self->width;
+  rectangle.height = self->height;
+
+  return retro_pixdata_load_rectangle_as_gl_texture (self, &rectangle);
+}
+
+/**
+ * retro_pixdata_load_rectangle_as_gl_texture:
+ * @self: the #RetroPixdata
+ * @rectangle: the #GdkRectangle
+ *
+ * Loads an OpenGL texture from a rectangle in @self.
+ *
+ * Returns: whether the loading was successful
+ */
+gboolean
+retro_pixdata_load_rectangle_as_gl_texture (RetroPixdata *self,
+                                            GdkRectangle *rectangle)
 {
   GLenum format;
   GLenum type;
   gint pixel_size;
 
   g_return_val_if_fail (self != NULL, FALSE);
+  g_return_val_if_fail (rectangle != NULL, FALSE);
+  g_return_val_if_fail (rectangle->x + rectangle->width <= self->width, FALSE);
+  g_return_val_if_fail (rectangle->y + rectangle->height <= self->height, FALSE);
 
   switch (self->pixel_format) {
   case RETRO_PIXEL_FORMAT_XRGB1555:
@@ -398,11 +424,11 @@ retro_pixdata_load_gl_texture (RetroPixdata *self)
   glTexImage2D (GL_TEXTURE_2D,
                 0,
                 GL_RGB,
-                self->width,
-                self->height,
+                rectangle->width,
+                rectangle->height,
                 0,
                 format, type,
-                self->data);
+                self->data + rectangle->x * pixel_size + rectangle->y * self->rowstride);
   glPixelStorei (GL_UNPACK_ROW_LENGTH, 0);
 
   return TRUE;
diff --git a/retro-gtk/retro-pixdata.h b/retro-gtk/retro-pixdata.h
index 3b0b9a8..356f34f 100644
--- a/retro-gtk/retro-pixdata.h
+++ b/retro-gtk/retro-pixdata.h
@@ -7,6 +7,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>
 
@@ -25,6 +26,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_rectangle_as_gl_texture (RetroPixdata *self,
+                                                     GdkRectangle *rectangle);
 
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (RetroPixdata, retro_pixdata_free)
 


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