[retro-gtk/wip/aplazas/gl-display: 7/10] gl-display: Use shaders
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [retro-gtk/wip/aplazas/gl-display: 7/10] gl-display: Use shaders
- Date: Mon, 13 Nov 2017 14:11:45 +0000 (UTC)
commit ab57ff0df7f6118d44f449d08061601a2cda48b8
Author: Adrien Plazas <kekun plazas laposte net>
Date: Sun Oct 15 09:36:05 2017 +0200
gl-display: Use shaders
retro-gtk/retro-gl-display.c | 33 +++++++++++++++++++++++++++++++++
1 files changed, 33 insertions(+), 0 deletions(-)
---
diff --git a/retro-gtk/retro-gl-display.c b/retro-gtk/retro-gl-display.c
index 133bca4..ebbcf0b 100644
--- a/retro-gtk/retro-gl-display.c
+++ b/retro-gtk/retro-gl-display.c
@@ -14,6 +14,7 @@ struct _RetroGLDisplay
gfloat aspect_ratio;
gulong on_video_output_id;
+ GLuint shader_program;
GLuint framebuffer;
};
@@ -71,7 +72,37 @@ retro_gl_display_get_video_box (RetroGLDisplay *self,
static void
retro_gl_display_realize (RetroGLDisplay *self)
{
+ GLuint vertex_shader;
+ GLuint fragment_shader;
+ GLuint shader_program;
+ GBytes *shader_source_bytes;
+ const gchar *shader_source;
+
gtk_gl_area_make_current (GTK_GL_AREA (self));
+
+ // Prepare the vertex shader
+ shader_source_bytes = g_resources_lookup_data ("/org/gnome/Retro/retro-gl-display-vertex.glsl", 0, NULL);
+ shader_source = g_bytes_get_data (shader_source_bytes, NULL);
+ vertex_shader = glCreateShader (GL_VERTEX_SHADER);
+ glShaderSource (vertex_shader, 1, &shader_source, NULL);
+ glCompileShader (vertex_shader);
+ g_bytes_unref (shader_source_bytes);
+
+ // Prepare the fragment shader
+ shader_source_bytes = g_resources_lookup_data ("/org/gnome/Retro/retro-gl-display-fragment.glsl", 0, NULL);
+ shader_source = g_bytes_get_data (shader_source_bytes, NULL);
+ fragment_shader = glCreateShader (GL_FRAGMENT_SHADER);
+ glShaderSource (fragment_shader, 1, &shader_source, NULL);
+ glCompileShader (fragment_shader);
+ g_bytes_unref (shader_source_bytes);
+
+ // Prepare the shader program
+ shader_program = glCreateProgram();
+ glAttachShader (shader_program, vertex_shader);
+ glAttachShader (shader_program, fragment_shader);
+ glLinkProgram (shader_program);
+
+ self->shader_program = shader_program;
}
static void
@@ -80,6 +111,7 @@ retro_gl_display_unrealize (RetroGLDisplay *self)
gtk_gl_area_make_current (GTK_GL_AREA (self));
glDeleteFramebuffers (1, &self->framebuffer);
+ glDeleteProgram (self->shader_program);
}
static gboolean
@@ -108,6 +140,7 @@ retro_gl_display_render (RetroGLDisplay *self)
}
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glUseProgram (self->shader_program);
glBindFramebuffer (GL_READ_FRAMEBUFFER, self->framebuffer);
glBlitFramebuffer (0, 0,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]