render: Only compile the shader that is being used
parent
c274c81fa3
commit
e5512114f8
|
@ -21,19 +21,24 @@
|
||||||
|
|
||||||
struct dmabuf_frame;
|
struct dmabuf_frame;
|
||||||
|
|
||||||
|
enum renderer_input_type {
|
||||||
|
RENDERER_INPUT_FB,
|
||||||
|
RENDERER_INPUT_DMABUF,
|
||||||
|
};
|
||||||
|
|
||||||
struct renderer {
|
struct renderer {
|
||||||
EGLDisplay display;
|
EGLDisplay display;
|
||||||
EGLSurface surface;
|
EGLSurface surface;
|
||||||
EGLContext context;
|
EGLContext context;
|
||||||
GLuint dmabuf_shader_program;
|
GLuint shader_program;
|
||||||
GLuint texture_shader_program;
|
|
||||||
uint32_t width;
|
uint32_t width;
|
||||||
uint32_t height;
|
uint32_t height;
|
||||||
GLint read_format;
|
GLint read_format;
|
||||||
GLint read_type;
|
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);
|
void renderer_destroy(struct renderer* self);
|
||||||
|
|
||||||
int render_dmabuf_frame(struct renderer* self, struct dmabuf_frame* frame);
|
int render_dmabuf_frame(struct renderer* self, struct dmabuf_frame* frame);
|
||||||
|
|
|
@ -765,8 +765,12 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
pointer_init(&self.pointer_backend);
|
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,
|
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");
|
log_error("Failed to initialise renderer\n");
|
||||||
goto failure;
|
goto failure;
|
||||||
}
|
}
|
||||||
|
|
37
src/render.c
37
src/render.c
|
@ -324,8 +324,7 @@ void gl_render(void)
|
||||||
|
|
||||||
void renderer_destroy(struct renderer* self)
|
void renderer_destroy(struct renderer* self)
|
||||||
{
|
{
|
||||||
glDeleteProgram(self->dmabuf_shader_program);
|
glDeleteProgram(self->shader_program);
|
||||||
glDeleteProgram(self->texture_shader_program);
|
|
||||||
eglMakeCurrent(self->display, EGL_NO_SURFACE, EGL_NO_SURFACE,
|
eglMakeCurrent(self->display, EGL_NO_SURFACE, EGL_NO_SURFACE,
|
||||||
EGL_NO_CONTEXT);
|
EGL_NO_CONTEXT);
|
||||||
eglDestroySurface(self->display, self->surface);
|
eglDestroySurface(self->display, self->surface);
|
||||||
|
@ -333,7 +332,8 @@ void renderer_destroy(struct renderer* self)
|
||||||
eglTerminate(self->display);
|
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))
|
if (!eglBindAPI(EGL_OPENGL_ES_API))
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -396,15 +396,20 @@ int renderer_init(struct renderer* self, uint32_t width, uint32_t height)
|
||||||
if (gl_load_late_extensions() < 0)
|
if (gl_load_late_extensions() < 0)
|
||||||
goto late_extension_failure;
|
goto late_extension_failure;
|
||||||
|
|
||||||
if (gl_compile_shader_program(&self->dmabuf_shader_program,
|
switch (input_type) {
|
||||||
"dmabuf-vertex.glsl",
|
case RENDERER_INPUT_DMABUF:
|
||||||
"dmabuf-fragment.glsl") < 0)
|
if (gl_compile_shader_program(&self->shader_program,
|
||||||
goto shader_failure;
|
"dmabuf-vertex.glsl",
|
||||||
|
"dmabuf-fragment.glsl") < 0)
|
||||||
if (gl_compile_shader_program(&self->texture_shader_program,
|
goto shader_failure;
|
||||||
"texture-vertex.glsl",
|
break;
|
||||||
"texture-fragment.glsl") < 0)
|
case RENDERER_INPUT_FB:
|
||||||
goto shader_failure;
|
if (gl_compile_shader_program(&self->shader_program,
|
||||||
|
"texture-vertex.glsl",
|
||||||
|
"texture-fragment.glsl") < 0)
|
||||||
|
goto shader_failure;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
self->width = width;
|
self->width = width;
|
||||||
self->height = height;
|
self->height = height;
|
||||||
|
@ -479,8 +484,8 @@ int render_dmabuf_frame(struct renderer* self, struct dmabuf_frame* frame)
|
||||||
glBindTexture(GL_TEXTURE_EXTERNAL_OES, tex);
|
glBindTexture(GL_TEXTURE_EXTERNAL_OES, tex);
|
||||||
glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, image);
|
glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, image);
|
||||||
|
|
||||||
glUseProgram(self->dmabuf_shader_program);
|
glUseProgram(self->shader_program);
|
||||||
glUniform1i(glGetUniformLocation(self->dmabuf_shader_program, "u_tex"), 0);
|
glUniform1i(glGetUniformLocation(self->shader_program, "u_tex"), 0);
|
||||||
gl_render();
|
gl_render();
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
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);
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, 0);
|
glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, 0);
|
||||||
|
|
||||||
glUseProgram(self->texture_shader_program);
|
glUseProgram(self->shader_program);
|
||||||
glUniform1i(glGetUniformLocation(self->texture_shader_program, "u_tex"), 0);
|
glUniform1i(glGetUniformLocation(self->shader_program, "u_tex"), 0);
|
||||||
gl_render();
|
gl_render();
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
|
Loading…
Reference in New Issue