renderer: Add u_tex1 to shaders

shader-damage-experiments
Andri Yngvason 2020-03-25 20:26:15 +00:00
parent 49c584f80d
commit 13216fa507
4 changed files with 17 additions and 8 deletions

View File

@ -50,7 +50,8 @@ struct renderer {
struct { struct {
GLuint program; GLuint program;
GLint u_tex; GLint u_tex0;
GLint u_tex1;
GLint u_proj; GLint u_proj;
} shader; } shader;
}; };

View File

@ -2,11 +2,11 @@
precision mediump float; precision mediump float;
uniform samplerExternalOES u_tex; uniform samplerExternalOES u_tex0;
varying vec2 v_texture; varying vec2 v_texture;
void main() void main()
{ {
gl_FragColor = texture2D(u_tex, v_texture); gl_FragColor = texture2D(u_tex0, v_texture);
} }

View File

@ -1,10 +1,10 @@
precision mediump float; precision mediump float;
uniform sampler2D u_tex; uniform sampler2D u_tex0;
varying vec2 v_texture; varying vec2 v_texture;
void main() void main()
{ {
gl_FragColor = texture2D(u_tex, v_texture); gl_FragColor = texture2D(u_tex0, v_texture);
} }

View File

@ -332,7 +332,7 @@ GLuint renderer_next_tex(struct renderer* self)
GLuint renderer_last_tex(const struct renderer* self) GLuint renderer_last_tex(const struct renderer* self)
{ {
size_t len = ARRAY_LEN(self->tex); 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]; return self->tex[index];
} }
@ -346,7 +346,8 @@ void render(struct renderer* self)
{ {
glUseProgram(self->shader.program); 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]; const float* proj = transforms[self->output->transform];
glUniformMatrix2fv(self->shader.u_proj, 1, GL_FALSE, proj); glUniformMatrix2fv(self->shader.u_proj, 1, GL_FALSE, proj);
@ -505,7 +506,8 @@ int renderer_init(struct renderer* self, const struct output* output,
break; 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->shader.u_proj = glGetUniformLocation(self->shader.program, "u_proj");
self->output = output; self->output = output;
@ -583,6 +585,9 @@ int renderer_import_dmabuf_frame(struct renderer* self, GLuint tex,
glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, image); glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, image);
eglDestroyImageKHR(self->display, image); eglDestroyImageKHR(self->display, image);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, renderer_last_tex(self));
return 0; return 0;
} }
@ -604,6 +609,9 @@ int renderer_import_framebuffer(struct renderer* self, GLuint tex,
glGenerateMipmap(GL_TEXTURE_2D); glGenerateMipmap(GL_TEXTURE_2D);
glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, 0); glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, renderer_last_tex(self));
return 0; return 0;
} }