[retro-gtk/wip/aplazas/gl-display] various fixes



commit d87c11af1d3e1314ab79c7a20bf64ef507eba121
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Tue Nov 14 21:30:57 2017 +0100

    various fixes

 retro-gtk/retro-gl-display-vertex.glsl |   17 +++++++----------
 retro-gtk/retro-gl-display.c           |   10 +++++-----
 retro-gtk/shaders/crt-simple.vs        |   19 ++++++++++++-------
 retro-gtk/shaders/scanline.fs          |    2 ++
 4 files changed, 26 insertions(+), 22 deletions(-)
---
diff --git a/retro-gtk/retro-gl-display-vertex.glsl b/retro-gtk/retro-gl-display-vertex.glsl
index 52caf7c..cfe4a83 100644
--- a/retro-gtk/retro-gl-display-vertex.glsl
+++ b/retro-gtk/retro-gl-display-vertex.glsl
@@ -1,7 +1,7 @@
 #version 150 core
 
 in vec2 position;
-in vec2 texture_coordinates;
+in vec2 texCoord;
 
 out Vertex {
   vec2 texCoord;
@@ -11,13 +11,10 @@ uniform float relative_aspect_ratio;
 
 void main ()
 {
-  vertexOut.texCoord = texture_coordinates;
-  if (relative_aspect_ratio > 1.0f)
-    gl_Position = vec4 (position.x / relative_aspect_ratio,
-                        position.y,
-                        0.0, 1.0);
-  else
-    gl_Position = vec4 (position.x,
-                        position.y * relative_aspect_ratio,
-                        0.0, 1.0);
+  vec2 aspect_ratio = (relative_aspect_ratio > 1.0f) ?
+    vec2 (1.0 / relative_aspect_ratio, 1.0) :
+    vec2 (1.0, relative_aspect_ratio);
+
+  vertexOut.texCoord = texCoord;
+  gl_Position = vec4 (position.xy * aspect_ratio, 0.0, 1.0);
 }
diff --git a/retro-gtk/retro-gl-display.c b/retro-gtk/retro-gl-display.c
index 29702b3..9f01a09 100644
--- a/retro-gtk/retro-gl-display.c
+++ b/retro-gtk/retro-gl-display.c
@@ -136,13 +136,13 @@ retro_gl_display_realize (RetroGLDisplay *self)
 
   vertex_shader =
     create_shader_from_resource (GL_VERTEX_SHADER,
-                                 "/org/gnome/Retro/retro-gl-display-vertex.glsl",
+                                 "/org/gnome/Retro/shaders/crt-simple.vs",
                                  0,
                                  NULL);
 
   fragment_shader =
     create_shader_from_resource (GL_FRAGMENT_SHADER,
-                                 "/org/gnome/Retro/shaders/shadertoy.fs",
+                                 "/org/gnome/Retro/shaders/crt-simple.fs",
                                  0,
                                  NULL);
 
@@ -158,7 +158,7 @@ retro_gl_display_realize (RetroGLDisplay *self)
                          sizeof (RetroVertex), offsetof (RetroVertex, position));
   glEnableVertexAttribArray (position_attrib);
 
-  GLint texture_coordinates_attrib = glGetAttribLocation (shader_program, "texture_coordinates");
+  GLint texture_coordinates_attrib = glGetAttribLocation (shader_program, "texCoord");
   glVertexAttribPointer (texture_coordinates_attrib, sizeof (((RetroVertex *) NULL)->texture_coordinates) / 
sizeof (float), GL_FLOAT, GL_FALSE,
                          sizeof (RetroVertex), offsetof (RetroVertex, texture_coordinates));
   glEnableVertexAttribArray (texture_coordinates_attrib);
@@ -238,8 +238,8 @@ retro_gl_display_render (RetroGLDisplay *self)
                 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_WRAP_S, GL_CLAMP_TO_BORDER);
+  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
   glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
   glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
 
diff --git a/retro-gtk/shaders/crt-simple.vs b/retro-gtk/shaders/crt-simple.vs
index e1f50d5..53957cd 100644
--- a/retro-gtk/shaders/crt-simple.vs
+++ b/retro-gtk/shaders/crt-simple.vs
@@ -1,6 +1,6 @@
 #version 150
 
-in vec2 position;
+in vec4 position;
 in vec2 texCoord;
 
 out Vertex {
@@ -10,18 +10,23 @@ out Vertex {
   float mod_factor;
 } vertexOut;
 
-        uniform vec4 targetSize;
-        uniform vec2 outputSize;
-        uniform vec4 sourceSize[];
+uniform float relative_aspect_ratio;
+uniform vec4 targetSize;
+uniform vec2 outputSize;
+uniform vec4 sourceSize[];
 
 void main() {
-  gl_Position = vec4 (position, 0.0, 1.0);
-  vertexOut.texCoord = texCoord;
+  vec2 aspect_ratio = (relative_aspect_ratio > 1.0f) ?
+    vec2 (1.0 / relative_aspect_ratio, 1.0) :
+    vec2 (1.0, relative_aspect_ratio);
 
+  vertexOut.texCoord = texCoord;
+  gl_Position = vec4 (position.xy * aspect_ratio, 0.0, 1.0);
+  // gl_Position = vec4 (position);
 
    // The size of one texel, in texture-coordinates.
    vertexOut.one = 1.0 / sourceSize[0].xy;
 
    // Resulting X pixel-coordinate of the pixel we're drawing.
-   vertexOut.mod_factor = texCoord.x * targetSize.x;
+   vertexOut.mod_factor = texCoord.x * targetSize.x * aspect_ratio.x;
 }
diff --git a/retro-gtk/shaders/scanline.fs b/retro-gtk/shaders/scanline.fs
index 42a9603..c6d97c2 100644
--- a/retro-gtk/shaders/scanline.fs
+++ b/retro-gtk/shaders/scanline.fs
@@ -4,6 +4,8 @@ uniform sampler2D source[];
 
 in Vertex {
   vec2 texCoord;
+  vec2 one;
+  float mod_factor;
 };
 
 out vec4 fragColor;


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