diff --git a/include/render.h b/include/render.h index f606f1a..98bfc6d 100644 --- a/include/render.h +++ b/include/render.h @@ -50,7 +50,8 @@ struct renderer { struct { GLuint program; - GLint u_tex; + GLint u_tex0; + GLint u_tex1; GLint u_proj; } shader; }; diff --git a/shaders/dmabuf-fragment.glsl b/shaders/dmabuf-fragment.glsl index 0f40cf1..a7fb423 100644 --- a/shaders/dmabuf-fragment.glsl +++ b/shaders/dmabuf-fragment.glsl @@ -2,11 +2,11 @@ precision mediump float; -uniform samplerExternalOES u_tex; +uniform samplerExternalOES u_tex0; varying vec2 v_texture; void main() { - gl_FragColor = texture2D(u_tex, v_texture); + gl_FragColor = texture2D(u_tex0, v_texture); } diff --git a/shaders/texture-fragment.glsl b/shaders/texture-fragment.glsl index 04eb5c0..b4420d8 100644 --- a/shaders/texture-fragment.glsl +++ b/shaders/texture-fragment.glsl @@ -1,10 +1,10 @@ precision mediump float; -uniform sampler2D u_tex; +uniform sampler2D u_tex0; varying vec2 v_texture; void main() { - gl_FragColor = texture2D(u_tex, v_texture); + gl_FragColor = texture2D(u_tex0, v_texture); } diff --git a/src/render.c b/src/render.c index 9a5e778..cf6a6bd 100644 --- a/src/render.c +++ b/src/render.c @@ -332,7 +332,7 @@ GLuint renderer_next_tex(struct renderer* self) GLuint renderer_last_tex(const struct renderer* self) { size_t len = ARRAY_LEN(self->tex); - size_t index = (len + self->tex_index - 1) % len; + size_t index = (len + self->tex_index - 2) % len; return self->tex[index]; } @@ -346,7 +346,8 @@ void render(struct renderer* self) { glUseProgram(self->shader.program); - glUniform1i(self->shader.u_tex, 0); + glUniform1i(self->shader.u_tex0, 0); + glUniform1i(self->shader.u_tex1, 1); const float* proj = transforms[self->output->transform]; glUniformMatrix2fv(self->shader.u_proj, 1, GL_FALSE, proj); @@ -505,7 +506,8 @@ int renderer_init(struct renderer* self, const struct output* output, break; } - self->shader.u_tex = glGetUniformLocation(self->shader.program, "u_tex"); + self->shader.u_tex0 = glGetUniformLocation(self->shader.program, "u_tex0"); + self->shader.u_tex1 = glGetUniformLocation(self->shader.program, "u_tex1"); self->shader.u_proj = glGetUniformLocation(self->shader.program, "u_proj"); self->output = output; @@ -583,6 +585,9 @@ int renderer_import_dmabuf_frame(struct renderer* self, GLuint tex, glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, image); eglDestroyImageKHR(self->display, image); + glActiveTexture(GL_TEXTURE1); + glBindTexture(GL_TEXTURE_2D, renderer_last_tex(self)); + return 0; } @@ -604,6 +609,9 @@ int renderer_import_framebuffer(struct renderer* self, GLuint tex, glGenerateMipmap(GL_TEXTURE_2D); glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, 0); + glActiveTexture(GL_TEXTURE1); + glBindTexture(GL_TEXTURE_2D, renderer_last_tex(self)); + return 0; }