Use symbolic names

This commit is contained in:
Kovid Goyal
2021-12-01 22:51:12 +05:30
parent 91c0f4e2d9
commit 142b6fcc00

View File

@@ -7,6 +7,10 @@
#define tex_top 0
#define tex_right 1
#define tex_bottom 1
#define x_axis 0
#define y_axis 1
#define window i
#define image i + 2
uniform float adjust_scale;
uniform vec2 transform; // [ pos_left_relative, pos_top_relative ]
@@ -29,15 +33,18 @@ const vec2 tex_map[] = vec2[4](
float scaling_factor(int i) {
return adjust_scale * (sizes[i] / sizes[i + 2]) + (1 - adjust_scale);
return adjust_scale * (sizes[window] / sizes[image]) + (1 - adjust_scale);
}
float position_divisor(int i) {
return (sizes[i] - sizes[i + 2]) * transform[i] / sizes[i + 2];
return (sizes[window] - sizes[image]) * transform[i] / sizes[image];
}
void main() {
vec2 tex_coords = tex_map[gl_VertexID];
texcoord = vec2(tex_coords[0] * scaling_factor(0) - position_divisor(0), tex_coords[1] * scaling_factor(1) - position_divisor(1));
texcoord = vec2(
tex_coords[x_axis] * scaling_factor(x_axis) - position_divisor(x_axis),
tex_coords[y_axis] * scaling_factor(y_axis) - position_divisor(y_axis)
);
gl_Position = vec4(pos_map[gl_VertexID], 0, 1);
}