From: David Gow <david@ingeniumdigital.com>
Date: Tue, 5 Aug 2014 14:54:25 +0000 (+0800)
Subject: Fix beziers on GPU.
X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=b3c2d3472c3b3d77eae0f66731a32b852dce11f0;p=ipdf%2Fcode.git

Fix beziers on GPU.

We can now render an SVG correctly(ish)! Woah!
---

diff --git a/src/bezier.cpp b/src/bezier.cpp
index c71d0a9..f0e1f4d 100644
--- a/src/bezier.cpp
+++ b/src/bezier.cpp
@@ -34,7 +34,7 @@ int Factorial(int n)
  */
 int BinomialCoeff(int n, int k)
 {
-	return Factorial(n) / Factorial(k) / Factorial(n-k);
+	return Factorial(n) / (Factorial(k) * Factorial(n-k));
 }
 
 /**
diff --git a/src/objectrenderer.cpp b/src/objectrenderer.cpp
index 76955a6..8b3b7e4 100644
--- a/src/objectrenderer.cpp
+++ b/src/objectrenderer.cpp
@@ -281,8 +281,8 @@ void BezierRenderer::PrepareBezierGPUBuffer(const Objects& objects)
 	{
 		GPUBezierCoeffs coeffs = {
 			Float(bez->x0), Float(bez->y0),
-			Float(bez->x1 - bez->x0), Float(bez->y1 - bez->y0),
-			Float(bez->x2 - bez->x0), Float(bez->y2 - bez->y0)
+			Float(bez->x1), Float(bez->y1),
+			Float(bez->x2), Float(bez->y2)
 			};
 		builder.Add(coeffs);
 	}
diff --git a/src/shaders/bezier_texbuf_geom.glsl b/src/shaders/bezier_texbuf_geom.glsl
index 56dddbe..bb9a219 100644
--- a/src/shaders/bezier_texbuf_geom.glsl
+++ b/src/shaders/bezier_texbuf_geom.glsl
@@ -19,9 +19,9 @@ void main()
 {
 	int bezierid = texelFetch(bezier_id_buffer_texture, objectid[0]).r;
 	vec2 boundssize = gl_in[1].gl_Position.xy - gl_in[0].gl_Position.xy;
-	vec2 coeff0 = texelFetch(bezier_buffer_texture, bezierid*3).rg + gl_in[0].gl_Position.xy ;
-	vec2 coeff1 = texelFetch(bezier_buffer_texture, bezierid*3+1).rg * boundssize + gl_in[0].gl_Position.xy;
-	vec2 coeff2 = texelFetch(bezier_buffer_texture, bezierid*3+2).rg * boundssize + gl_in[0].gl_Position.xy;
+	vec2 coeff0 = texelFetch(bezier_buffer_texture, bezierid*3).rg;
+	vec2 coeff1 = texelFetch(bezier_buffer_texture, bezierid*3+1).rg;
+	vec2 coeff2 = texelFetch(bezier_buffer_texture, bezierid*3+2).rg;
 	vec2 boundspxsize = pixsize[0];
 	int blen = clamp(int(abs(boundspxsize.x)),2,100);
 	float invblen = 1.0f/float(blen);
@@ -32,7 +32,7 @@ void main()
 		float bernstein0 = t*t;
 		float bernstein1 = 2*t*oneminust;
 		float bernstein2 = oneminust*oneminust;
-		gl_Position = vec4(coeff0*bernstein0 + coeff1*bernstein1 + coeff2*bernstein2, 0.0, 1.0);
+		gl_Position = vec4((coeff0*bernstein0 + coeff1*bernstein1 + coeff2*bernstein2) * boundssize + gl_in[0].gl_Position.xy, 0.0, 1.0);
 		EmitVertex();
 		
 	}