[retro-gtk/wip/aplazas/gl-display] add CRT video filter type
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [retro-gtk/wip/aplazas/gl-display] add CRT video filter type
- Date: Wed, 15 Nov 2017 14:15:30 +0000 (UTC)
commit 5ef15b35486180e36bf1edaa6010bf2442405418
Author: Adrien Plazas <kekun plazas laposte net>
Date: Wed Nov 15 15:14:52 2017 +0100
add CRT video filter type
retro-gtk/retro-gl-display.c | 80 ++++++++++++++++++++++++---------------
retro-gtk/retro-video-filter.c | 1 +
retro-gtk/retro-video-filter.h | 2 +
3 files changed, 52 insertions(+), 31 deletions(-)
---
diff --git a/retro-gtk/retro-gl-display.c b/retro-gtk/retro-gl-display.c
index 19ddcee..a03b88e 100644
--- a/retro-gtk/retro-gl-display.c
+++ b/retro-gtk/retro-gl-display.c
@@ -93,12 +93,58 @@ static GLuint elements[] = {
};
static void
+prepare_shader_program (RetroGLDisplay *self)
+{
+ const gchar *uri;
+ GLuint program;
+ GLint attrib;
+
+ if (self->glsl_filter != NULL)
+ return;
+
+ switch (self->filter) {
+ case RETRO_VIDEO_FILTER_SHARP:
+ uri = "resource:///org/gnome/Retro/glsl-filters/sharp.filter";
+
+ break;
+ case RETRO_VIDEO_FILTER_SMOOTH:
+ default:
+ uri = "resource:///org/gnome/Retro/glsl-filters/bicubic.filter";
+
+ break;
+ case RETRO_VIDEO_FILTER_CRT:
+ default:
+ uri = "resource:///org/gnome/Retro/glsl-filters/crt-simple.filter";
+
+ break;
+ }
+
+ self->glsl_filter = retro_glsl_filter_new (uri, NULL);
+ program = retro_glsl_filter_create_program (self->glsl_filter);
+
+ glUseProgram (program);
+ attrib = glGetAttribLocation (program, "position");
+ glVertexAttribPointer (attrib, sizeof (((RetroVertex *) NULL)->position) / sizeof (float), GL_FLOAT,
GL_FALSE,
+ sizeof (RetroVertex), offsetof (RetroVertex, position));
+ glEnableVertexAttribArray (attrib);
+
+ attrib = glGetAttribLocation (program, "texCoord");
+ glVertexAttribPointer (attrib, sizeof (((RetroVertex *) NULL)->texture_coordinates) / sizeof (float),
GL_FLOAT, GL_FALSE,
+ sizeof (RetroVertex), offsetof (RetroVertex, texture_coordinates));
+ glEnableVertexAttribArray (attrib);
+
+ glGenTextures (1, &self->texture);
+ glBindTexture (GL_TEXTURE_2D, self->texture);
+
+ self->shader_program = program;
+}
+
+static void
retro_gl_display_realize (RetroGLDisplay *self)
{
GLuint vertex_buffer_object;
GLuint vertex_array_object;
GLuint element_buffer_object;
- GLuint program;
gtk_gl_area_make_current (GTK_GL_AREA (self));
@@ -113,24 +159,7 @@ retro_gl_display_realize (RetroGLDisplay *self)
glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, element_buffer_object);
glBufferData (GL_ELEMENT_ARRAY_BUFFER, sizeof (elements), elements, GL_STATIC_DRAW);
- self->glsl_filter = retro_glsl_filter_new ("resource:///org/gnome/Retro/glsl-filters/crt-simple.filter",
NULL);
- program = retro_glsl_filter_create_program (self->glsl_filter);
-
- glUseProgram (program);
- GLint position_attrib = glGetAttribLocation (program, "position");
- glVertexAttribPointer (position_attrib, sizeof (((RetroVertex *) NULL)->position) / sizeof (float),
GL_FLOAT, GL_FALSE,
- sizeof (RetroVertex), offsetof (RetroVertex, position));
- glEnableVertexAttribArray (position_attrib);
-
- GLint texture_coordinates_attrib = glGetAttribLocation (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);
-
- glGenTextures (1, &self->texture);
- glBindTexture (GL_TEXTURE_2D, self->texture);
-
- self->shader_program = program;
+ prepare_shader_program (self);
}
static void
@@ -166,7 +195,6 @@ retro_gl_display_render (RetroGLDisplay *self)
gdouble h = 0.0;
gdouble x = 0.0;
gdouble y = 0.0;
- GLenum filter;
GLint relative_aspect_ratio;
GLfloat source_width, source_height;
GLfloat target_width, target_height;
@@ -176,17 +204,7 @@ retro_gl_display_render (RetroGLDisplay *self)
retro_gl_display_get_video_box (self, &w, &h, &x, &y);
- switch (self->filter) {
- case RETRO_VIDEO_FILTER_SHARP:
- filter = GL_NEAREST;
-
- break;
- default:
- case RETRO_VIDEO_FILTER_SMOOTH:
- filter = GL_LINEAR;
-
- break;
- }
+ prepare_shader_program (self);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
diff --git a/retro-gtk/retro-video-filter.c b/retro-gtk/retro-video-filter.c
index cbff527..70e9c9c 100644
--- a/retro-gtk/retro-video-filter.c
+++ b/retro-gtk/retro-video-filter.c
@@ -41,6 +41,7 @@ retro_video_filter_get_type (void)
static const GEnumValue values[] = {
{ RETRO_VIDEO_FILTER_SMOOTH, "RETRO_VIDEO_FILTER_SMOOTH", "smooth" },
{ RETRO_VIDEO_FILTER_SHARP, "RETRO_VIDEO_FILTER_SHARP", "sharp" },
+ { RETRO_VIDEO_FILTER_CRT, "RETRO_VIDEO_FILTER_CRT", "crt" },
{ 0, NULL, NULL },
};
GType type;
diff --git a/retro-gtk/retro-video-filter.h b/retro-gtk/retro-video-filter.h
index 7eb6f53..0926278 100644
--- a/retro-gtk/retro-video-filter.h
+++ b/retro-gtk/retro-video-filter.h
@@ -19,6 +19,7 @@ GType retro_video_filter_get_type (void) G_GNUC_CONST;
* RetroVideoFilter:
* @RETRO_VIDEO_FILTER_SMOOTH: a smooth but blurry video filer
* @RETRO_VIDEO_FILTER_SHARP: a sharp video filter showing every pixel
+ * @RETRO_VIDEO_FILTER_CRT: a video filter mimicking CRT screens
*
* Represents the filters that can be applied to the video output.
*/
@@ -26,6 +27,7 @@ typedef enum
{
RETRO_VIDEO_FILTER_SMOOTH,
RETRO_VIDEO_FILTER_SHARP,
+ RETRO_VIDEO_FILTER_CRT,
} RetroVideoFilter;
RetroVideoFilter retro_video_filter_from_string (const gchar *filter);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]