[retro-gtk: 10/12] gl-display: Add load_texture() method
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [retro-gtk: 10/12] gl-display: Add load_texture() method
- Date: Sat, 18 Nov 2017 13:30:04 +0000 (UTC)
commit f2faf29228136ab0d1731f99c90e7fc03c048793
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 ++++++++++++++++++++++++-------------
retro-gtk/retro-pixdata.c | 31 ++++++++++++++++++++++++++++++-
2 files changed, 54 insertions(+), 14 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);
diff --git a/retro-gtk/retro-pixdata.c b/retro-gtk/retro-pixdata.c
index 87c2b06..b46c7fa 100644
--- a/retro-gtk/retro-pixdata.c
+++ b/retro-gtk/retro-pixdata.c
@@ -365,16 +365,45 @@ retro_pixdata_to_pixbuf (RetroPixdata *self)
gboolean
retro_pixdata_load_gl_texture (RetroPixdata *self)
{
+ GLenum format;
+ GLenum type;
+ gint pixel_size;
+
g_return_val_if_fail (self != NULL, FALSE);
+ switch (self->pixel_format) {
+ case RETRO_PIXEL_FORMAT_XRGB1555:
+ format = GL_BGRA;
+ type = GL_UNSIGNED_SHORT_5_5_5_1;
+ pixel_size = 2;
+
+ break;
+ case RETRO_PIXEL_FORMAT_XRGB8888:
+ format = GL_BGRA;
+ type = GL_UNSIGNED_BYTE;
+ pixel_size = 4;
+
+ break;
+ case RETRO_PIXEL_FORMAT_RGB565:
+ format = GL_RGB;
+ type = GL_UNSIGNED_SHORT_5_6_5;
+ pixel_size = 2;
+
+ break;
+ default:
+ return FALSE;
+ }
+
+ glPixelStorei (GL_UNPACK_ROW_LENGTH, self->rowstride / pixel_size);
glTexImage2D (GL_TEXTURE_2D,
0,
GL_RGB,
self->width,
self->height,
0,
- GL_BGRA, GL_UNSIGNED_BYTE,
+ format, type,
self->data);
+ glPixelStorei (GL_UNPACK_ROW_LENGTH, 0);
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]