From: Sam Moore Date: Fri, 4 Jul 2014 06:05:44 +0000 (+0800) Subject: Maybe don't use all of the lines. Or maybe do. X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=commitdiff_plain;h=00ef152dc3a065e37fe45c1cd8023d739f518b8e Maybe don't use all of the lines. Or maybe do. The CPU version. CPU rendering still looks slightly different to GPU. Replicates behaviour in 54798ed9050d0742c6cdab067fad0cc364b1d6b2 Also actually use the right +/- operators for Rational. Oh and compile as rational by default because we like things to explode right? --- diff --git a/src/Makefile b/src/Makefile index a26843f..0041932 100644 --- a/src/Makefile +++ b/src/Makefile @@ -30,7 +30,7 @@ RM = rm -f BIN = ../bin/ipdf - +all : DEF = -DREAL=4 all : $(BIN) single : DEF = -DREAL=0 diff --git a/src/objectrenderer.cpp b/src/objectrenderer.cpp index 13d17b2..ac25c4a 100644 --- a/src/objectrenderer.cpp +++ b/src/objectrenderer.cpp @@ -13,7 +13,9 @@ namespace IPDF /** * ObjectRenderer constructor - * Note we cannot compile the shaders in the constructor because the Screen class needs to initialise GL and it has a ShaderProgram member + * Note we cannot compile the shaders in the ShaderProgram constructor + * because the Screen class needs to initialise GL first and it has a + * ShaderProgram member */ ObjectRenderer::ObjectRenderer(const ObjectType & type, const char * vert_glsl_file, const char * frag_glsl_file, const char * geom_glsl_file) @@ -225,9 +227,12 @@ void BezierRenderer::RenderUsingCPU(const Objects & objects, const View & view, Real x[2]; Real y[2]; control.Evaluate(x[0], y[0], Real(0)); - for (unsigned j = 1; j <= 100; ++j) + int64_t blen = max(2L, min(100L, pix_bounds.w)); + Real invblen(1); invblen /= blen; + Debug("Using %li lines, inverse %f", blen, Double(invblen)); + for (int64_t j = 1; j <= blen; ++j) { - control.Evaluate(x[j % 2],y[j % 2], Real(0.01)*j); + control.Evaluate(x[j % 2],y[j % 2], invblen*j); ObjectRenderer::RenderLineOnCPU((int64_t)Double(x[0]),(int64_t)Double(y[0]), (int64_t)Double(x[1]),(int64_t)Double(y[1]), target); } diff --git a/src/rational.h b/src/rational.h index c2215a0..41cce09 100644 --- a/src/rational.h +++ b/src/rational.h @@ -51,7 +51,7 @@ template struct Rational { /** Construct from a double.**/ - Rational(double d = 0) : P(d*1e6), Q(1e6) // Possibly the worst thing ever... + Rational(double d=0) : P(d*1e6), Q(1e6) // Possibly the worst thing ever... { Simplify(); CheckAccuracy(d, "Construct from double"); @@ -74,7 +74,11 @@ struct Rational P = (P < 0) ? -P : P; Q = -Q; } - + if (P == 0) + { + Q = 1; + return; + } T g = gcd(llabs(P),llabs(Q)); P /= g; Q /= g; @@ -93,9 +97,6 @@ struct Rational bool operator>=(const Rational & r) const {return *this == r || *this > r;} bool operator!=(const Rational & r) const {return !(*this == r);} - - - /* Rational operator+(const Rational & r) const { Rational result = (r.P == 0) ? Rational(P,Q) : Rational(P*r.Q + r.P*Q, Q*r.Q); @@ -108,7 +109,6 @@ struct Rational result.CheckAccuracy(ToDouble() - r.ToDouble(),"-"); return result; } - */ Rational operator*(const Rational & r) const { Rational result(P * r.P, Q * r.Q); @@ -128,8 +128,9 @@ struct Rational return result; } - Rational operator+(const Rational & r) const {return Rational(ToDouble()+r.ToDouble());} - Rational operator-(const Rational & r) const {return Rational(ToDouble()-r.ToDouble());} + /** To cheat, use these **/ + //Rational operator+(const Rational & r) const {return Rational(ToDouble()+r.ToDouble());} + //Rational operator-(const Rational & r) const {return Rational(ToDouble()-r.ToDouble());} //Rational operator*(const Rational & r) const {return Rational(ToDouble()*r.ToDouble());} //Rational operator/(const Rational & r) const {return Rational(ToDouble()/r.ToDouble());}