[retro-gtk/wip/aplazas/gl-display] Display the video output
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [retro-gtk/wip/aplazas/gl-display] Display the video output
- Date: Fri, 10 Nov 2017 13:17:32 +0000 (UTC)
commit 8879edcfc2beea9965aa0786131f48934d3f2e76
Author: Adrien Plazas <kekun plazas laposte net>
Date: Fri Nov 10 14:11:37 2017 +0100
Display the video output
Colors are broken and the video is flipped vertically.
retro-gtk/retro-gl-display.c | 72 ++++++++++++++++++++++++++++++++++++-----
1 files changed, 63 insertions(+), 9 deletions(-)
---
diff --git a/retro-gtk/retro-gl-display.c b/retro-gtk/retro-gl-display.c
index db48b4b..22cbfa3 100644
--- a/retro-gtk/retro-gl-display.c
+++ b/retro-gtk/retro-gl-display.c
@@ -17,6 +17,7 @@ struct _RetroGLDisplay
GLuint vertex_array_object;
GLuint shader_program;
+ GLuint readFboId;
};
G_DEFINE_TYPE (RetroGLDisplay, retro_gl_display, GTK_TYPE_GL_AREA)
@@ -83,10 +84,8 @@ retro_gl_display_get_video_box (RetroGLDisplay *self,
float points[] = {
-0.5f, 0.5f, 0.0f,
0.5f, 0.5f, 0.0f,
- -0.5f, -0.5f, 0.0f,
- 0.5f, 0.5f, 0.0f,
- -0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f,
+ -0.5f, -0.5f, 0.0f,
};
static void
@@ -105,7 +104,7 @@ retro_gl_display_realize (RetroGLDisplay *self)
// Prepare the vertex buffer
glGenBuffers (1, &vertex_buffer_object);
glBindBuffer (GL_ARRAY_BUFFER, vertex_buffer_object);
- glBufferData (GL_ARRAY_BUFFER, 18 * sizeof (float), points, GL_STATIC_DRAW);
+ glBufferData (GL_ARRAY_BUFFER, 12 * sizeof (float), points, GL_STATIC_DRAW);
// Prepare the vertex array
glGenVertexArrays (1, &vertex_array_object);
@@ -136,6 +135,23 @@ retro_gl_display_realize (RetroGLDisplay *self)
glAttachShader (shader_program, fragment_shader);
glLinkProgram (shader_program);
+ /* GLuint tex = 0; */
+ /* glGenTextures (1, &tex); */
+ /* glBindTexture (GL_TEXTURE_2D, tex); */
+
+ /* // Black/white checkerboard */
+ /* float pixels[] = { */
+ /* 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, */
+ /* 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f */
+ /* }; */
+ /* glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 2, 2, 0, GL_RGB, GL_FLOAT, pixels); */
+
+ /* glGenFramebuffers(1, &self->readFboId); */
+ /* glBindFramebuffer(GL_READ_FRAMEBUFFER, self->readFboId); */
+ /* glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, */
+ /* GL_TEXTURE_2D, tex, 0); */
+ /* glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); */
+
self->vertex_array_object = vertex_array_object;
self->shader_program = shader_program;
}
@@ -152,10 +168,28 @@ retro_gl_display_unrealize (RetroGLDisplay *self)
static gboolean
retro_gl_display_render (RetroGLDisplay *self)
{
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glUseProgram(self->shader_program);
- glBindVertexArray(self->vertex_array_object);
- glDrawArrays(GL_TRIANGLES, 0, 6);
+ gdouble w = 0.0;
+ gdouble h = 0.0;
+ gdouble x = 0.0;
+ gdouble y = 0.0;
+
+ g_return_val_if_fail (self != NULL, FALSE);
+
+ retro_gl_display_get_video_box (self, &w, &h, &x, &y);
+
+ glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glUseProgram (self->shader_program);
+ glBindVertexArray (self->vertex_array_object);
+ glDrawArrays (GL_TRIANGLE_FAN, 0, 4);
+
+ glBindFramebuffer (GL_READ_FRAMEBUFFER, self->readFboId);
+ glBlitFramebuffer (0, 0,
+ gdk_pixbuf_get_width (self->pixbuf),
+ gdk_pixbuf_get_height (self->pixbuf),
+ (GLint) x, (GLint) y, (GLint) (x + w), (GLint) (y + h),
+ GL_COLOR_BUFFER_BIT,
+ GL_LINEAR);
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
return FALSE;
}
@@ -360,9 +394,29 @@ retro_gl_display_set_pixbuf (RetroGLDisplay *self,
g_clear_object (&self->pixbuf);
- if (pixbuf != NULL)
+ if (pixbuf != NULL) {
self->pixbuf = g_object_ref (pixbuf);
+ GLuint tex = 0;
+ glGenTextures (1, &tex);
+ glBindTexture (GL_TEXTURE_2D, tex);
+
+ glTexImage2D (GL_TEXTURE_2D,
+ 0,
+ GL_RGB,
+ gdk_pixbuf_get_width (self->pixbuf),
+ gdk_pixbuf_get_height (self->pixbuf),
+ 0,
+ GL_RGBA, GL_UNSIGNED_INT_8_8_8_8,
+ gdk_pixbuf_get_pixels (self->pixbuf));
+
+ glGenFramebuffers(1, &self->readFboId);
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, self->readFboId);
+ glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+ GL_TEXTURE_2D, tex, 0);
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
+ }
+
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_PIXBUF]);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]