[retro-gtk/wip/aplazas/gl-display] draw the texture but geometry is wrong
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [retro-gtk/wip/aplazas/gl-display] draw the texture but geometry is wrong
- Date: Mon, 13 Nov 2017 19:37:12 +0000 (UTC)
commit 7a60230f3ad0465b68f4b9e31837a4fb76c03583
Author: Adrien Plazas <kekun plazas laposte net>
Date: Mon Nov 13 20:20:35 2017 +0100
draw the texture but geometry is wrong
retro-gtk/retro-gl-display.c | 85 ++++++++++++++++-------------------------
1 files changed, 33 insertions(+), 52 deletions(-)
---
diff --git a/retro-gtk/retro-gl-display.c b/retro-gtk/retro-gl-display.c
index a54f6d8..e307814 100644
--- a/retro-gtk/retro-gl-display.c
+++ b/retro-gtk/retro-gl-display.c
@@ -15,7 +15,7 @@ struct _RetroGLDisplay
gulong on_video_output_id;
GLuint shader_program;
- GLuint framebuffer;
+ GLuint texture;
};
G_DEFINE_TYPE (RetroGLDisplay, retro_gl_display, GTK_TYPE_GL_AREA)
@@ -78,20 +78,11 @@ typedef struct {
} texture_coordinates;
} RetroVertex;
-/* float vertices[] = { */
-/* // Position Texcoords */
-/* -0.5f, 0.5f, 0.0f, 0.0f, // Top-left */
-/* 0.5f, 0.5f, 1.0f, 0.0f, // Top-right */
-/* 0.5f, -0.5f, 1.0f, 1.0f, // Bottom-right */
-/* -0.5f, -0.5f, 0.0f, 1.0f, // Bottom-left */
-/* }; */
-
float vertices[] = {
-// Position Texcoords
- -0.5f, 0.5f, 0.0f, 0.0f, // Top-left
- 0.5f, 0.5f, 1.0f, 0.0f, // Top-right
- 0.5f, -0.5f, 1.0f, 1.0f, // Bottom-right
- -0.5f, -0.5f, 0.0f, 1.0f, // Bottom-left
+ -1.0f, 1.0f, 0.0f, 0.0f, // Top-left
+ 1.0f, 1.0f, 1.0f, 0.0f, // Top-right
+ 1.0f, -1.0f, 1.0f, 1.0f, // Bottom-right
+ -1.0f, -1.0f, 0.0f, 1.0f, // Bottom-left
};
GLuint elements[] = {
@@ -157,6 +148,9 @@ retro_gl_display_realize (RetroGLDisplay *self)
sizeof (RetroVertex), offsetof (RetroVertex, texture_coordinates));
glEnableVertexAttribArray (texture_coordinates_attrib);
+ glGenTextures (1, &self->texture);
+ glBindTexture (GL_TEXTURE_2D, self->texture);
+
self->shader_program = shader_program;
}
@@ -165,8 +159,10 @@ retro_gl_display_unrealize (RetroGLDisplay *self)
{
gtk_gl_area_make_current (GTK_GL_AREA (self));
- glDeleteFramebuffers (1, &self->framebuffer);
+ glDeleteTextures (1, &self->texture);
+ self->texture = 0;
glDeleteProgram (self->shader_program);
+ self->shader_program = 0;
}
static gboolean
@@ -195,17 +191,23 @@ retro_gl_display_render (RetroGLDisplay *self)
}
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- GLint rect = glGetUniformLocation (self->shader_program, "rect");
- glUniform4f (rect, x, y, w, h);
-
- glBindFramebuffer (GL_READ_FRAMEBUFFER, self->framebuffer);
- glBlitFramebuffer (0, 0,
- gdk_pixbuf_get_width (self->pixbuf),
- gdk_pixbuf_get_height (self->pixbuf),
- (GLint) x, (GLint) (y + h), (GLint) (x + w), (GLint) y,
- GL_COLOR_BUFFER_BIT,
- filter);
- glBindFramebuffer (GL_READ_FRAMEBUFFER, 0);
+
+ if (self->pixbuf == NULL)
+ return FALSE;
+
+ glTexImage2D (GL_TEXTURE_2D,
+ 0,
+ GL_RGB,
+ gdk_pixbuf_get_width (self->pixbuf),
+ gdk_pixbuf_get_height (self->pixbuf),
+ 0,
+ GL_RGBA, GL_UNSIGNED_BYTE,
+ gdk_pixbuf_get_pixels (self->pixbuf));
+
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
glDrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
@@ -217,6 +219,10 @@ retro_gl_display_finalize (GObject *object)
{
RetroGLDisplay *self = (RetroGLDisplay *) object;
+ glDeleteTextures (1, &self->texture);
+ self->texture = 0;
+ glDeleteProgram (self->shader_program);
+ self->shader_program = 0;
if (self->core != NULL)
g_object_unref (self->core);
if (self->pixbuf != NULL)
@@ -412,34 +418,9 @@ 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_BYTE,
- gdk_pixbuf_get_pixels (self->pixbuf));
-
- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
- glGenFramebuffers (1, &self->framebuffer);
- glBindFramebuffer (GL_READ_FRAMEBUFFER, self->framebuffer);
- 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]