[retro-gtk/wip/aplazas/gl-display: 22/22] fixes
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [retro-gtk/wip/aplazas/gl-display: 22/22] fixes
- Date: Thu, 9 Nov 2017 18:08:03 +0000 (UTC)
commit 7159ae42fa95c54a1dcaade3ca4ece5cadf28154
Author: Adrien Plazas <kekun plazas laposte net>
Date: Sun Nov 5 08:25:17 2017 +0100
fixes
meson.build | 2 +
retro-gtk/glarea-fragment.glsl | 8 +-
retro-gtk/glarea-resources.c | 2 +-
retro-gtk/glarea-vertex.glsl | 12 +--
retro-gtk/meson.build | 1 +
retro-gtk/retro-gl-display.c | 246 ++++++++++++++++++-------------------
retro-gtk/retro-gtk.gresource.xml | 2 +-
7 files changed, 131 insertions(+), 142 deletions(-)
---
diff --git a/meson.build b/meson.build
index 4640194..d0f936d 100644
--- a/meson.build
+++ b/meson.build
@@ -3,6 +3,7 @@ project('retro-gtk','c',
meson_version: '>= 0.43.0',
)
+cc = meson.get_compiler('c')
gnome = import('gnome')
prefix = get_option('prefix')
@@ -22,6 +23,7 @@ gmodule = dependency ('gmodule-2.0', version: glib_version)
gobject = dependency ('gobject-2.0', version: glib_version)
gtk = dependency ('gtk+-3.0', version: gtk_version)
libpulse_simple = dependency ('libpulse-simple')
+m = cc.find_library('m', required : false)
config_h = configuration_data()
config_h.set_quoted ('RETRO_PLUGIN_PATH', ':'.join ([libretrodir, libdir]))
diff --git a/retro-gtk/glarea-fragment.glsl b/retro-gtk/glarea-fragment.glsl
index c331ad2..3d29acb 100644
--- a/retro-gtk/glarea-fragment.glsl
+++ b/retro-gtk/glarea-fragment.glsl
@@ -1,9 +1,7 @@
-#version 130
+#version 400
-smooth in vec4 vertexColor;
-
-out vec4 outputColor;
+in vec3 vp;
void main() {
- outputColor = vertexColor;
+ gl_Position = vec4(vp, 1.0);
}
diff --git a/retro-gtk/glarea-resources.c b/retro-gtk/glarea-resources.c
index 268a486..0c66306 100644
--- a/retro-gtk/glarea-resources.c
+++ b/retro-gtk/glarea-resources.c
@@ -1,4 +1,4 @@
-#include <gio/gio.h>
+include <gio/gio.h>
#if defined (__ELF__) && ( __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 6))
# define SECTION __attribute__ ((section (".gresource.glarea"), aligned (8)))
diff --git a/retro-gtk/glarea-vertex.glsl b/retro-gtk/glarea-vertex.glsl
index 83dda48..79f57cb 100644
--- a/retro-gtk/glarea-vertex.glsl
+++ b/retro-gtk/glarea-vertex.glsl
@@ -1,13 +1,7 @@
-#version 130
+#version 400
-in vec3 position;
-in vec3 color;
-
-uniform mat4 mvp;
-
-smooth out vec4 vertexColor;
+out vec4 frag_colour;
void main() {
- gl_Position = mvp * vec4(position, 1.0);
- vertexColor = vec4(color, 1.0);
+ frag_colour = vec4(0.5, 0.0, 0.5, 1.0);
}
diff --git a/retro-gtk/meson.build b/retro-gtk/meson.build
index 9626675..1a2f733 100644
--- a/retro-gtk/meson.build
+++ b/retro-gtk/meson.build
@@ -96,6 +96,7 @@ retro_gtk_deps = [
gobject,
gtk,
libpulse_simple,
+ m,
]
retro_gtk_lib = shared_library(
diff --git a/retro-gtk/retro-gl-display.c b/retro-gtk/retro-gl-display.c
index 6d88299..a9ed576 100644
--- a/retro-gtk/retro-gl-display.c
+++ b/retro-gtk/retro-gl-display.c
@@ -3,6 +3,7 @@
#include "retro-gl-display.h"
#include <epoxy/gl.h>
+#include <math.h>
#include "retro-pixdata.h"
struct _RetroGLDisplay
@@ -172,44 +173,70 @@ static const struct vertex_info vertex_data[] = {
{ { 0.5f, -0.366f, 0.0f }, { 0.f, 1.f, 0.f } },
{ { -0.5f, -0.366f, 0.0f }, { 0.f, 0.f, 1.f } },
};
+float points[] = {
+ 0.0f, 0.5f, 0.0f,
+ 0.5f, -0.5f, 0.0f,
+ -0.5f, -0.5f, 0.0f
+};
static void
init_buffers (guint position_index,
guint color_index,
guint *vao_out)
{
- guint vao, buffer;
+ /* guint vao, buffer; */
/* we need to create a VAO to store the other buffers */
- glGenVertexArrays (1, &vao);
- glBindVertexArray (vao);
+ /* glGenVertexArrays (1, &vao); */
+ /* glBindVertexArray (vao); */
/* this is the VBO that holds the vertex data */
- glGenBuffers (1, &buffer);
- glBindBuffer (GL_ARRAY_BUFFER, buffer);
- glBufferData (GL_ARRAY_BUFFER, sizeof (vertex_data), vertex_data, GL_STATIC_DRAW);
+ /* glGenBuffers (1, &buffer); */
+ /* glBindBuffer (GL_ARRAY_BUFFER, buffer); */
+ /* glBufferData (GL_ARRAY_BUFFER, sizeof (vertex_data), vertex_data, GL_STATIC_DRAW); */
/* enable and set the position attribute */
- glEnableVertexAttribArray (position_index);
- glVertexAttribPointer (position_index, 3, GL_FLOAT, GL_FALSE,
- sizeof (struct vertex_info),
- (GLvoid *) (G_STRUCT_OFFSET (struct vertex_info, position)));
+ /* glEnableVertexAttribArray (position_index); */
+ /* glVertexAttribPointer (position_index, 3, GL_FLOAT, GL_FALSE, */
+ /* sizeof (struct vertex_info), */
+ /* (GLvoid *) (G_STRUCT_OFFSET (struct vertex_info, position))); */
/* enable and set the color attribute */
- glEnableVertexAttribArray (color_index);
- glVertexAttribPointer (color_index, 3, GL_FLOAT, GL_FALSE,
- sizeof (struct vertex_info),
- (GLvoid *) (G_STRUCT_OFFSET (struct vertex_info, color)));
+ /* glEnableVertexAttribArray (color_index); */
+ /* glVertexAttribPointer (color_index, 3, GL_FLOAT, GL_FALSE, */
+ /* sizeof (struct vertex_info), */
+ /* (GLvoid *) (G_STRUCT_OFFSET (struct vertex_info, color))); */
/* reset the state; we will re-enable the VAO when needed */
- glBindBuffer (GL_ARRAY_BUFFER, 0);
- glBindVertexArray (0);
+ /* glBindBuffer (GL_ARRAY_BUFFER, 0); */
+ /* glBindVertexArray (0); */
/* the VBO is referenced by the VAO */
- glDeleteBuffers (1, &buffer);
+ /* glDeleteBuffers (1, &buffer); */
+
+ /* if (vao_out != NULL) */
+ /* *vao_out = vao; */
+
+
+
+
+
+
+
+
+
- if (vao_out != NULL)
- *vao_out = vao;
+ /* GLuint vbo = 0; */
+ /* glGenBuffers(1, &vbo); */
+ /* glBindBuffer(GL_ARRAY_BUFFER, vbo); */
+ /* glBufferData(GL_ARRAY_BUFFER, 9 * sizeof(float), points, GL_STATIC_DRAW); */
+
+ /* GLuint vao = 0; */
+ /* glGenVertexArrays(1, &vao); */
+ /* glBindVertexArray(vao); */
+ /* glEnableVertexAttribArray(0); */
+ /* glBindBuffer(GL_ARRAY_BUFFER, vbo); */
+ /* glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL); */
}
static guint
@@ -263,57 +290,70 @@ init_shaders (guint *program_out,
guint position_location = 0;
guint color_location = 0;
- /* load the vertex shader */
- source = g_resources_lookup_data ("/io/bassi/glarea/glarea-vertex.glsl", 0, NULL);
+ load the vertex shader
+ source = g_resources_lookup_data ("/org/gnome/Retro/glarea-vertex.glsl", 0, NULL);
create_shader (GL_VERTEX_SHADER, g_bytes_get_data (source, NULL), error, &vertex);
g_bytes_unref (source);
if (vertex == 0)
goto out;
- /* load the fragment shader */
- source = g_resources_lookup_data ("/io/bassi/glarea/glarea-fragment.glsl", 0, NULL);
+ load the fragment shader
+ source = g_resources_lookup_data ("/org/gnome/Retro/glarea-fragment.glsl", 0, NULL);
create_shader (GL_FRAGMENT_SHADER, g_bytes_get_data (source, NULL), error, &fragment);
g_bytes_unref (source);
if (fragment == 0)
goto out;
+
+ /* GLuint vs = glCreateShader(GL_VERTEX_SHADER); */
+ /* glShaderSource(vs, 1, &vertex_shader, NULL); */
+ /* glCompileShader(vs); */
+ /* GLuint fs = glCreateShader(GL_FRAGMENT_SHADER); */
+ /* glShaderSource(fs, 1, &fragment_shader, NULL); */
+ /* glCompileShader(fs); */
+
+ /* GLuint shader_programme = glCreateProgram(); */
+ /* glAttachShader(shader_programme, fs); */
+ /* glAttachShader(shader_programme, vs); */
+ /* glLinkProgram(shader_programme); */
+
/* link the vertex and fragment shaders together */
- program = glCreateProgram ();
- glAttachShader (program, vertex);
- glAttachShader (program, fragment);
- glLinkProgram (program);
+ /* program = glCreateProgram (); */
+ /* glAttachShader (program, vertex); */
+ /* glAttachShader (program, fragment); */
+ /* glLinkProgram (program); */
- int status = 0;
- glGetProgramiv (program, GL_LINK_STATUS, &status);
- if (status == GL_FALSE)
- {
- int log_len = 0;
- glGetProgramiv (program, GL_INFO_LOG_LENGTH, &log_len);
+ /* int status = 0; */
+ /* glGetProgramiv (program, GL_LINK_STATUS, &status); */
+ /* if (status == GL_FALSE) */
+ /* { */
+ /* int log_len = 0; */
+ /* glGetProgramiv (program, GL_INFO_LOG_LENGTH, &log_len); */
- char *buffer = g_malloc (log_len + 1);
- glGetProgramInfoLog (program, log_len, NULL, buffer);
+ /* char *buffer = g_malloc (log_len + 1); */
+ /* glGetProgramInfoLog (program, log_len, NULL, buffer); */
- g_set_error (error, GLAREA_ERROR, GLAREA_ERROR_SHADER_LINK,
- "Linking failure in program: %s", buffer);
+ /* g_set_error (error, GLAREA_ERROR, GLAREA_ERROR_SHADER_LINK, */
+ /* "Linking failure in program: %s", buffer); */
- g_free (buffer);
+ /* g_free (buffer); */
- glDeleteProgram (program);
- program = 0;
+ /* glDeleteProgram (program); */
+ /* program = 0; */
- goto out;
- }
+ /* goto out; */
+ /* } */
/* get the location of the "mvp" uniform */
- mvp_location = glGetUniformLocation (program, "mvp");
+ /* mvp_location = glGetUniformLocation (program, "mvp"); */
/* get the location of the "position" and "color" attributes */
- position_location = glGetAttribLocation (program, "position");
- color_location = glGetAttribLocation (program, "color");
+ /* position_location = glGetAttribLocation (program, "position"); */
+ /* color_location = glGetAttribLocation (program, "color"); */
/* the individual shaders can be detached and destroyed */
- glDetachShader (program, vertex);
- glDetachShader (program, fragment);
+ /* glDetachShader (program, vertex); */
+ /* glDetachShader (program, fragment); */
out:
if (vertex != 0)
@@ -334,64 +374,65 @@ out:
}
static void
-gl_init (RetroGLDisplay *self)
+retro_gl_display_realize (RetroGLDisplay *self)
{
+ GError *error = NULL;
+
/* we need to ensure that the GdkGLContext is set before calling GL API */
gtk_gl_area_make_current (GTK_GL_AREA (self));
/* initialize the shaders and retrieve the program data */
- GError *error = NULL;
- if (!init_shaders (&self->program,
- &self->mvp_location,
- &self->position_index,
- &self->color_index,
- &error))
- {
- gtk_gl_area_set_error (GTK_GL_AREA (self), error);
- g_error_free (error);
- return;
- }
+ /* if (!init_shaders (&self->program, */
+ /* &self->mvp_location, */
+ /* &self->position_index, */
+ /* &self->color_index, */
+ /* &error)) { */
+ /* gtk_gl_area_set_error (GTK_GL_AREA (self), error); */
+ /* g_error_free (error); */
+
+ /* return; */
+ /* } */
/* initialize the vertex buffers */
init_buffers (self->position_index, self->color_index, &self->vao);
}
static void
-gl_fini (RetroGLDisplay *self)
+retro_gl_display_unrealize (RetroGLDisplay *self)
{
/* we need to ensure that the GdkGLContext is set before calling GL API */
gtk_gl_area_make_current (GTK_GL_AREA (self));
/* destroy all the resources we created */
- glDeleteVertexArrays (1, &self->vao);
- glDeleteProgram (self->program);
+ /* glDeleteVertexArrays (1, &self->vao); */
+ /* glDeleteProgram (self->program); */
}
-static void
-draw_triangle (RetroGLDisplay *self)
-{
- if (self->program == 0 || self->vao == 0)
- return;
+/* static void */
+/* draw_triangle (RetroGLDisplay *self) */
+/* { */
+/* if (self->program == 0 || self->vao == 0) */
+/* return; */
/* load our program */
- glUseProgram (self->program);
+/* glUseProgram (self->program); */
/* update the "mvp" matrix we use in the shader */
- glUniformMatrix4fv (self->mvp_location, 1, GL_FALSE, &(self->mvp[0]));
+/* glUniformMatrix4fv (self->mvp_location, 1, GL_FALSE, &(self->mvp[0])); */
/* use the buffers in the VAO */
- glBindVertexArray (self->vao);
+/* glBindVertexArray (self->vao); */
/* draw the three vertices as a triangle */
- glDrawArrays (GL_TRIANGLES, 0, 3);
+/* glDrawArrays (GL_TRIANGLES, 0, 3); */
/* we finished using the buffers and program */
- glBindVertexArray (0);
- glUseProgram (0);
-}
+/* glBindVertexArray (0); */
+/* glUseProgram (0); */
+/* } */
static gboolean
-gl_draw (RetroGLDisplay *self)
+retro_gl_display_render (RetroGLDisplay *self)
{
/* clear the viewport; the viewport is automatically resized when
* the GtkGLArea gets an allocation
@@ -400,7 +441,7 @@ gl_draw (RetroGLDisplay *self)
glClear (GL_COLOR_BUFFER_BIT);
/* draw our object */
- draw_triangle (self);
+ /* draw_triangle (self); */
/* flush the contents of the pipeline */
glFlush ();
@@ -409,53 +450,6 @@ gl_draw (RetroGLDisplay *self)
}
static void
-init_mvp (float *res)
-{
- /* initialize a matrix as an identity matrix */
- res[0] = 1.f; res[4] = 0.f; res[8] = 0.f; res[12] = 0.f;
- res[1] = 0.f; res[5] = 1.f; res[9] = 0.f; res[13] = 0.f;
- res[2] = 0.f; res[6] = 0.f; res[10] = 1.f; res[14] = 0.f;
- res[3] = 0.f; res[7] = 0.f; res[11] = 0.f; res[15] = 1.f;
-}
-
-static void
-compute_mvp (float *res,
- float phi,
- float theta,
- float psi)
-{
- float x = phi * (G_PI / 180.f);
- float y = theta * (G_PI / 180.f);
- float z = psi * (G_PI / 180.f);
- float c1 = cosf (x), s1 = sinf (x);
- float c2 = cosf (y), s2 = sinf (y);
- float c3 = cosf (z), s3 = sinf (z);
- float c3c2 = c3 * c2;
- float s3c1 = s3 * c1;
- float c3s2s1 = c3 * s2 * s1;
- float s3s1 = s3 * s1;
- float c3s2c1 = c3 * s2 * c1;
- float s3c2 = s3 * c2;
- float c3c1 = c3 * c1;
- float s3s2s1 = s3 * s2 * s1;
- float c3s1 = c3 * s1;
- float s3s2c1 = s3 * s2 * c1;
- float c2s1 = c2 * s1;
- float c2c1 = c2 * c1;
-
- /* apply all three Euler angles rotations using the three matrices:
- *
- * ⎡ c3 s3 0 ⎤ ⎡ c2 0 -s2 ⎤ ⎡ 1 0 0 ⎤
- * ⎢ -s3 c3 0 ⎥ ⎢ 0 1 0 ⎥ ⎢ 0 c1 s1 ⎥
- * ⎣ 0 0 1 ⎦ ⎣ s2 0 c2 ⎦ ⎣ 0 -s1 c1 ⎦
- */
- res[0] = c3c2; res[4] = s3c1 + c3s2s1; res[8] = s3s1 - c3s2c1; res[12] = 0.f;
- res[1] = -s3c2; res[5] = c3c1 - s3s2s1; res[9] = c3s1 + s3s2c1; res[13] = 0.f;
- res[2] = s2; res[6] = -c2s1; res[10] = c2c1; res[14] = 0.f;
- res[3] = 0.f; res[7] = 0.f; res[11] = 0.f; res[15] = 1.f;
-}
-
-static void
retro_gl_display_finalize (GObject *object)
{
RetroGLDisplay *self = (RetroGLDisplay *) object;
@@ -542,19 +536,19 @@ retro_gl_display_init (RetroGLDisplay *self)
{
g_signal_connect_object (G_OBJECT (self),
"realize",
- (GCallback) gl_init,
+ (GCallback) retro_gl_display_realize,
GTK_WIDGET (self),
0);
g_signal_connect_object (G_OBJECT (self),
"unrealize",
- (GCallback) gl_fini,
+ (GCallback) retro_gl_display_unrealize,
GTK_WIDGET (self),
0);
g_signal_connect_object (G_OBJECT (self),
"render",
- (GCallback) gl_draw,
+ (GCallback) retro_gl_display_render,
GTK_WIDGET (self),
0);
diff --git a/retro-gtk/retro-gtk.gresource.xml b/retro-gtk/retro-gtk.gresource.xml
index b5a23bc..0dfd47f 100644
--- a/retro-gtk/retro-gtk.gresource.xml
+++ b/retro-gtk/retro-gtk.gresource.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
- <gresource prefix="/io/bassi/glarea">
+ <gresource prefix="/org/gnome/Retro">
<file>glarea-fragment.glsl</file>
<file>glarea-vertex.glsl</file>
</gresource>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]