[retro-gtk/wip/aplazas/gl-errors] simplify shader management
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [retro-gtk/wip/aplazas/gl-errors] simplify shader management
- Date: Thu, 16 Nov 2017 11:27:25 +0000 (UTC)
commit 56fc9173d8fd137c0bdd2eba809a0a95d4815f85
Author: Adrien Plazas <kekun plazas laposte net>
Date: Thu Nov 16 12:26:44 2017 +0100
simplify shader management
retro-gtk/retro-glsl-filter.c | 42 ++++++++++++++++------------------------
1 files changed, 17 insertions(+), 25 deletions(-)
---
diff --git a/retro-gtk/retro-glsl-filter.c b/retro-gtk/retro-glsl-filter.c
index 6e59fc8..7c534c7 100644
--- a/retro-gtk/retro-glsl-filter.c
+++ b/retro-gtk/retro-glsl-filter.c
@@ -9,8 +9,6 @@ struct _RetroGLSLFilter
GBytes *fragment;
GLenum wrap;
GLenum filter;
- GLuint vertex_shader;
- GLuint fragment_shader;
GLuint program;
};
@@ -225,9 +223,8 @@ retro_glsl_filter_finalize (GObject *object)
g_bytes_unref (self->vertex);
if (self->fragment != NULL)
g_bytes_unref (self->fragment);
- glDeleteShader (self->vertex_shader);
- glDeleteShader (self->fragment_shader);
glDeleteProgram (self->program);
+ self->program = 0;
G_OBJECT_CLASS (retro_glsl_filter_parent_class)->finalize (object);
}
@@ -302,38 +299,33 @@ retro_glsl_filter_prepare_program (RetroGLSLFilter *self,
gint status;
gint log_length;
gchar *buffer;
+ GLuint vertex_shader;
+ GLuint fragment_shader;
GError *inner_error = NULL;
g_return_if_fail (RETRO_IS_GLSL_FILTER (self));
+ g_return_if_fail (self->program == 0);
- self->vertex_shader = create_shader (self->vertex,
- GL_VERTEX_SHADER,
- &inner_error);
+ vertex_shader = create_shader (self->vertex, GL_VERTEX_SHADER, &inner_error);
if (G_UNLIKELY (inner_error != NULL)) {
g_propagate_error (error, inner_error);
- self->vertex_shader = 0;
- self->fragment_shader = 0;
self->program = 0;
return;
}
- self->fragment_shader = create_shader (self->fragment,
- GL_FRAGMENT_SHADER,
- &inner_error);
+ fragment_shader = create_shader (self->fragment, GL_FRAGMENT_SHADER, &inner_error);
if (G_UNLIKELY (inner_error != NULL)) {
g_propagate_error (error, inner_error);
- glDeleteShader (self->vertex_shader);
- self->vertex_shader = 0;
- self->fragment_shader = 0;
+ glDeleteShader (vertex_shader);
self->program = 0;
return;
}
self->program = glCreateProgram();
- glAttachShader (self->program, self->vertex_shader);
- glAttachShader (self->program, self->fragment_shader);
+ glAttachShader (self->program, vertex_shader);
+ glAttachShader (self->program, fragment_shader);
glLinkProgram (self->program);
status = 0;
@@ -348,26 +340,23 @@ retro_glsl_filter_prepare_program (RetroGLSLFilter *self,
"Linking failure in program: %s", buffer);
g_free (buffer);
- glDeleteShader (self->vertex_shader);
- glDeleteShader (self->fragment_shader);
+ glDeleteShader (vertex_shader);
+ glDeleteShader (fragment_shader);
glDeleteProgram (self->program);
- self->vertex_shader = 0;
- self->fragment_shader = 0;
self->program = 0;
return;
}
- glDetachShader (self->program, self->vertex_shader);
- glDetachShader (self->program, self->fragment_shader);
- self->vertex_shader = 0;
- self->fragment_shader = 0;
+ glDetachShader (self->program, vertex_shader);
+ glDetachShader (self->program, fragment_shader);
}
void
retro_glsl_filter_use_program (RetroGLSLFilter *self)
{
g_return_if_fail (RETRO_IS_GLSL_FILTER (self));
+ g_return_if_fail (self->program != 0);
glUseProgram (self->program);
}
@@ -384,6 +373,7 @@ retro_glsl_filter_set_attribute_pointer (RetroGLSLFilter *self,
GLint location;
g_return_if_fail (RETRO_IS_GLSL_FILTER (self));
+ g_return_if_fail (self->program != 0);
location = glGetAttribLocation (self->program, name);
glVertexAttribPointer (location, size, type, normalized, stride, pointer);
@@ -399,6 +389,7 @@ retro_glsl_filter_set_uniform_1f (RetroGLSLFilter *self,
GLint location;
g_return_if_fail (RETRO_IS_GLSL_FILTER (self));
+ g_return_if_fail (self->program != 0);
location = glGetUniformLocation (self->program, name);
glUniform1f (location, v0);
@@ -415,6 +406,7 @@ retro_glsl_filter_set_uniform_4f (RetroGLSLFilter *self,
GLint location;
g_return_if_fail (RETRO_IS_GLSL_FILTER (self));
+ g_return_if_fail (self->program != 0);
location = glGetUniformLocation (self->program, name);
glUniform4f (location, v0, v1, v2, v3);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]