From 6b3b448405f0f42bc5e9c7f77b3b357d2959c9b4 Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Thu, 5 Mar 2020 18:14:50 +0000 Subject: [PATCH] render: Move shader_program into shader struct --- include/render.h | 7 ++++++- src/render.c | 14 +++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/include/render.h b/include/render.h index 6ee5e0a..84a246c 100644 --- a/include/render.h +++ b/include/render.h @@ -30,11 +30,16 @@ struct renderer { EGLDisplay display; EGLSurface surface; EGLContext context; - GLuint shader_program; + uint32_t width; uint32_t height; + GLint read_format; GLint read_type; + + struct { + GLuint program; + } shader; }; int renderer_init(struct renderer* self, uint32_t width, uint32_t height, diff --git a/src/render.c b/src/render.c index 556bbac..e29e9f5 100644 --- a/src/render.c +++ b/src/render.c @@ -324,7 +324,7 @@ void gl_render(void) void renderer_destroy(struct renderer* self) { - glDeleteProgram(self->shader_program); + glDeleteProgram(self->shader.program); eglMakeCurrent(self->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglDestroySurface(self->display, self->surface); @@ -398,13 +398,13 @@ int renderer_init(struct renderer* self, uint32_t width, uint32_t height, switch (input_type) { case RENDERER_INPUT_DMABUF: - if (gl_compile_shader_program(&self->shader_program, + if (gl_compile_shader_program(&self->shader.program, "dmabuf-vertex.glsl", "dmabuf-fragment.glsl") < 0) goto shader_failure; break; case RENDERER_INPUT_FB: - if (gl_compile_shader_program(&self->shader_program, + if (gl_compile_shader_program(&self->shader.program, "texture-vertex.glsl", "texture-fragment.glsl") < 0) goto shader_failure; @@ -484,8 +484,8 @@ int render_dmabuf_frame(struct renderer* self, struct dmabuf_frame* frame) glBindTexture(GL_TEXTURE_EXTERNAL_OES, tex); glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, image); - glUseProgram(self->shader_program); - glUniform1i(glGetUniformLocation(self->shader_program, "u_tex"), 0); + glUseProgram(self->shader.program); + glUniform1i(glGetUniformLocation(self->shader.program, "u_tex"), 0); gl_render(); glBindTexture(GL_TEXTURE_2D, 0); @@ -513,8 +513,8 @@ int render_framebuffer(struct renderer* self, const void* addr, uint32_t format, glGenerateMipmap(GL_TEXTURE_2D); glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, 0); - glUseProgram(self->shader_program); - glUniform1i(glGetUniformLocation(self->shader_program, "u_tex"), 0); + glUseProgram(self->shader.program); + glUniform1i(glGetUniformLocation(self->shader.program, "u_tex"), 0); gl_render(); glBindTexture(GL_TEXTURE_2D, 0);