renderer: Pass frame dimmensions to damage shader
parent
dc7adf8f3b
commit
96e8c63042
|
@ -59,6 +59,8 @@ struct renderer {
|
||||||
GLuint program;
|
GLuint program;
|
||||||
GLint u_tex0;
|
GLint u_tex0;
|
||||||
GLint u_tex1;
|
GLint u_tex1;
|
||||||
|
GLint u_width;
|
||||||
|
GLint u_height;
|
||||||
} damage_shader;
|
} damage_shader;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,18 @@ precision mediump float;
|
||||||
uniform sampler2D u_tex0;
|
uniform sampler2D u_tex0;
|
||||||
uniform sampler2D u_tex1;
|
uniform sampler2D u_tex1;
|
||||||
|
|
||||||
|
uniform int u_width;
|
||||||
|
uniform int u_height;
|
||||||
|
|
||||||
varying vec2 v_texture;
|
varying vec2 v_texture;
|
||||||
|
|
||||||
|
bool is_damaged(vec2 pos)
|
||||||
|
{
|
||||||
|
return texture2D(u_tex0, pos).rgb != texture2D(u_tex1, pos).rgb;
|
||||||
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
float r = float(texture2D(u_tex0, v_texture).rgb != texture2D(u_tex1, v_texture).rgb);
|
float r = float(is_damaged(v_texture));
|
||||||
gl_FragColor = vec4(r);
|
gl_FragColor = vec4(r);
|
||||||
}
|
}
|
||||||
|
|
10
src/render.c
10
src/render.c
|
@ -423,6 +423,12 @@ void render_damage(struct renderer* self)
|
||||||
glUniform1i(self->damage_shader.u_tex0, 0);
|
glUniform1i(self->damage_shader.u_tex0, 0);
|
||||||
glUniform1i(self->damage_shader.u_tex1, 1);
|
glUniform1i(self->damage_shader.u_tex1, 1);
|
||||||
|
|
||||||
|
uint32_t width = output_get_transformed_width(self->output);
|
||||||
|
uint32_t height = output_get_transformed_height(self->output);
|
||||||
|
|
||||||
|
glUniform1i(self->damage_shader.u_width, width);
|
||||||
|
glUniform1i(self->damage_shader.u_height, height);
|
||||||
|
|
||||||
gl_draw();
|
gl_draw();
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
|
@ -605,6 +611,10 @@ int renderer_init(struct renderer* self, const struct output* output,
|
||||||
glGetUniformLocation(self->damage_shader.program, "u_tex0");
|
glGetUniformLocation(self->damage_shader.program, "u_tex0");
|
||||||
self->damage_shader.u_tex1 =
|
self->damage_shader.u_tex1 =
|
||||||
glGetUniformLocation(self->damage_shader.program, "u_tex1");
|
glGetUniformLocation(self->damage_shader.program, "u_tex1");
|
||||||
|
self->damage_shader.u_width =
|
||||||
|
glGetUniformLocation(self->damage_shader.program, "u_width");
|
||||||
|
self->damage_shader.u_height =
|
||||||
|
glGetUniformLocation(self->damage_shader.program, "u_height");
|
||||||
|
|
||||||
self->output = output;
|
self->output = output;
|
||||||
glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &self->read_format);
|
glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &self->read_format);
|
||||||
|
|
Loading…
Reference in New Issue