Separate out the point_to_gl_Position function, which needs to be updated later

This commit is contained in:
Grant Sanderson 2020-02-12 18:05:22 -08:00
parent 50c7dd7d48
commit 3f0cc56665
4 changed files with 28 additions and 18 deletions

View file

@ -0,0 +1,11 @@
// Assumes theese uniforms exist in the surrounding context
// uniform float scale;
// uniform float aspect_ratio;
// uniform float frame_center;
vec4 point_to_gl_Position(vec3 p){
vec3 result = p / scale;
result.x /= aspect_ratio;
result -= frame_center;
gl_Position = vec4(result, 1.0);
}

View file

@ -36,6 +36,7 @@ const float SQRT5 = 2.236068;
// so to share functionality between this and others, the caller
// replaces this line with the contents of named file
#INSERT quadratic_bezier_geometry_functions.glsl
#INSERT set_gl_Position.glsl
mat3 get_xy_to_wz(vec2 b0, vec2 b1, vec2 b2){
@ -60,18 +61,11 @@ mat3 get_xy_to_wz(vec2 b0, vec2 b1, vec2 b2){
return transform * shift;
}
void set_gl_Position(vec2 p){
vec2 result = p / scale;
result.x /= aspect_ratio;
result -= frame_center.xy;
gl_Position = vec4(result, 0.0, 1.0);
}
void emit_simple_triangle(){
for(int i = 0; i < 3; i++){
color = v_color[i];
set_gl_Position(bp[i]);
set_gl_Position(vec3(bp[i], 0));
EmitVertex();
}
EndPrimitive();
@ -129,7 +123,7 @@ void emit_pentagon(vec2 bp0, vec2 bp1, vec2 bp2, float orientation){
if(i < 2) color = v_color[0];
else if(i == 2) color = v_color[1];
else color = v_color[2];
set_gl_Position(corner);
set_gl_Position(vec3(corner, 0));
EmitVertex();
}
EndPrimitive();

View file

@ -43,6 +43,7 @@ const float MITER_JOINT = 3;
// so to share functionality between this and others, the caller
// replaces this line with the contents of named file
#INSERT quadratic_bezier_geometry_functions.glsl
#INSERT set_gl_Position.glsl
float angle_between_vectors(vec2 v1, vec2 v2){
@ -264,14 +265,6 @@ void set_previous_and_next(vec2 controls[3], int degree){
}
void set_gl_Position(vec2 p){
vec2 result = p / scale;
result.x /= aspect_ratio;
result -= frame_center.xy;
gl_Position = vec4(result, 0.0, 1.0);
}
void main() {
vec2 controls[3];
int degree = get_reduced_control_points(bp[0], bp[1], bp[2], controls);
@ -311,7 +304,7 @@ void main() {
uv_stroke_width = stroke_widths[i] / scale_factor;
color = stroke_colors[i];
set_gl_Position(corner);
set_gl_Position(vec3(corner, 0));
EmitVertex();
}
EndPrimitive();

View file

@ -0,0 +1,12 @@
// Assumes theese uniforms exist in the surrounding context
// uniform float scale;
// uniform float aspect_ratio;
// uniform float frame_center;
void set_gl_Position(vec3 point){
// TODO, orient in 3d based on certain rotation matrices
point /= scale;
point.x /= aspect_ratio;
point -= frame_center;
gl_Position = vec4(point, 1.0);
}