diff --git a/include/render.h b/include/render.h index 2f13790..6ee5e0a 100644 --- a/include/render.h +++ b/include/render.h @@ -21,19 +21,24 @@ struct dmabuf_frame; +enum renderer_input_type { + RENDERER_INPUT_FB, + RENDERER_INPUT_DMABUF, +}; + struct renderer { EGLDisplay display; EGLSurface surface; EGLContext context; - GLuint dmabuf_shader_program; - GLuint texture_shader_program; + GLuint shader_program; uint32_t width; uint32_t height; GLint read_format; GLint read_type; }; -int renderer_init(struct renderer* self, uint32_t width, uint32_t height); +int renderer_init(struct renderer* self, uint32_t width, uint32_t height, + enum renderer_input_type input_type); void renderer_destroy(struct renderer* self); int render_dmabuf_frame(struct renderer* self, struct dmabuf_frame* frame); diff --git a/src/main.c b/src/main.c index 06ce7aa..33fb55a 100644 --- a/src/main.c +++ b/src/main.c @@ -765,8 +765,12 @@ int main(int argc, char* argv[]) pointer_init(&self.pointer_backend); + enum renderer_input_type renderer_input_type = + fcbackend == FRAME_CAPTURE_BACKEND_DMABUF ? + RENDERER_INPUT_DMABUF : RENDERER_INPUT_FB; if (renderer_init(&self.renderer, self.selected_output->width, - self.selected_output->height) < 0) { + self.selected_output->height, + renderer_input_type) < 0) { log_error("Failed to initialise renderer\n"); goto failure; } diff --git a/src/render.c b/src/render.c index 0a6e1e7..4183d56 100644 --- a/src/render.c +++ b/src/render.c @@ -324,8 +324,7 @@ void gl_render(void) void renderer_destroy(struct renderer* self) { - glDeleteProgram(self->dmabuf_shader_program); - glDeleteProgram(self->texture_shader_program); + glDeleteProgram(self->shader_program); eglMakeCurrent(self->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglDestroySurface(self->display, self->surface); @@ -333,7 +332,8 @@ void renderer_destroy(struct renderer* self) eglTerminate(self->display); } -int renderer_init(struct renderer* self, uint32_t width, uint32_t height) +int renderer_init(struct renderer* self, uint32_t width, uint32_t height, + enum renderer_input_type input_type) { if (!eglBindAPI(EGL_OPENGL_ES_API)) return -1; @@ -396,15 +396,20 @@ int renderer_init(struct renderer* self, uint32_t width, uint32_t height) if (gl_load_late_extensions() < 0) goto late_extension_failure; - if (gl_compile_shader_program(&self->dmabuf_shader_program, - "dmabuf-vertex.glsl", - "dmabuf-fragment.glsl") < 0) - goto shader_failure; - - if (gl_compile_shader_program(&self->texture_shader_program, - "texture-vertex.glsl", - "texture-fragment.glsl") < 0) - goto shader_failure; + switch (input_type) { + case RENDERER_INPUT_DMABUF: + 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, + "texture-vertex.glsl", + "texture-fragment.glsl") < 0) + goto shader_failure; + break; + } self->width = width; self->height = height; @@ -479,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->dmabuf_shader_program); - glUniform1i(glGetUniformLocation(self->dmabuf_shader_program, "u_tex"), 0); + glUseProgram(self->shader_program); + glUniform1i(glGetUniformLocation(self->shader_program, "u_tex"), 0); gl_render(); glBindTexture(GL_TEXTURE_2D, 0); @@ -508,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->texture_shader_program); - glUniform1i(glGetUniformLocation(self->texture_shader_program, "u_tex"), 0); + glUseProgram(self->shader_program); + glUniform1i(glGetUniformLocation(self->shader_program, "u_tex"), 0); gl_render(); glBindTexture(GL_TEXTURE_2D, 0);