render: Only compile the shader that is being used

pull/15/head
Andri Yngvason 2020-02-11 21:55:05 +00:00
parent c274c81fa3
commit e5512114f8
3 changed files with 34 additions and 20 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -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);