[retro-gtk/wip/aplazas/gl-display: 9/12] gl-display: Add load_texture() method



commit 388351e9a3ae8e24b215d2a1e4e2a0c408a22925
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Sat Nov 18 10:17:12 2017 +0100

    gl-display: Add load_texture() method
    
    This helps decoupling loading the texture from the rendering method.

 retro-gtk/retro-gl-display.c |   37 ++++++++++++++++++++++++-------------
 1 files changed, 24 insertions(+), 13 deletions(-)
---
diff --git a/retro-gtk/retro-gl-display.c b/retro-gtk/retro-gl-display.c
index c6bfc19..39061f9 100644
--- a/retro-gtk/retro-gl-display.c
+++ b/retro-gtk/retro-gl-display.c
@@ -91,6 +91,29 @@ retro_gl_display_get_video_box (RetroGLDisplay *self,
   *y = (h - *height) / 2;
 }
 
+static gboolean
+retro_gl_display_load_texture (RetroGLDisplay *self,
+                               gint           *texture_width,
+                               gint           *texture_height)
+{
+  if (retro_gl_display_get_pixbuf (self) == NULL)
+    return FALSE;
+
+  *texture_width = gdk_pixbuf_get_width (self->pixbuf),
+  *texture_height = gdk_pixbuf_get_height (self->pixbuf),
+
+  glTexImage2D (GL_TEXTURE_2D,
+                0,
+                GL_RGB,
+                *texture_width,
+                *texture_height,
+                0,
+                GL_RGBA, GL_UNSIGNED_BYTE,
+                gdk_pixbuf_get_pixels (self->pixbuf));
+
+  return TRUE;
+}
+
 static void
 retro_gl_display_blit_texture (RetroGLDisplay *self,
                                GLenum          filter,
@@ -262,21 +285,9 @@ retro_gl_display_render (RetroGLDisplay *self)
     RETRO_VIDEO_FILTER_SMOOTH :
     self->filter;
 
-  if (self->pixbuf == NULL)
+  if (!retro_gl_display_load_texture (self, &texture_width, &texture_height))
     return FALSE;
 
-  texture_width = gdk_pixbuf_get_width (self->pixbuf);
-  texture_height = gdk_pixbuf_get_height (self->pixbuf);
-
-  glTexImage2D (GL_TEXTURE_2D,
-                0,
-                GL_RGB,
-                texture_width,
-                texture_height,
-                0,
-                GL_RGBA, GL_UNSIGNED_BYTE,
-                gdk_pixbuf_get_pixels (self->pixbuf));
-
   if (filter == RETRO_VIDEO_FILTER_SMOOTH) {
     retro_gl_display_blit_texture (self, GL_LINEAR, texture_width, texture_height);
 


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