Maybe don't use all of the lines. Or maybe do.
authorSam Moore <[email protected]>
Fri, 4 Jul 2014 06:05:44 +0000 (14:05 +0800)
committerSam Moore <[email protected]>
Fri, 4 Jul 2014 06:05:44 +0000 (14:05 +0800)
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?

src/Makefile
src/objectrenderer.cpp
src/rational.h

index a26843f..0041932 100644 (file)
@@ -30,7 +30,7 @@ RM = rm -f
 BIN = ../bin/ipdf
 
 
 BIN = ../bin/ipdf
 
 
-
+all : DEF = -DREAL=4
 all : $(BIN)
 
 single : DEF = -DREAL=0
 all : $(BIN)
 
 single : DEF = -DREAL=0
index 13d17b2..ac25c4a 100644 (file)
@@ -13,7 +13,9 @@ namespace IPDF
 
 /**
  * ObjectRenderer constructor
 
 /**
  * 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)
  */
 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));
                
                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);
                }
                
                        ObjectRenderer::RenderLineOnCPU((int64_t)Double(x[0]),(int64_t)Double(y[0]), (int64_t)Double(x[1]),(int64_t)Double(y[1]), target);
                }
                
index c2215a0..41cce09 100644 (file)
@@ -51,7 +51,7 @@ template <class T = int64_t>
 struct Rational
 {
        /** Construct from a double.**/
 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");
        {
                Simplify();
                CheckAccuracy(d, "Construct from double");
@@ -74,7 +74,11 @@ struct Rational
                        P = (P < 0) ? -P : P;
                        Q = -Q;
                }
                        P = (P < 0) ? -P : P;
                        Q = -Q;
                }
-
+               if (P == 0)
+               {
+                       Q = 1;
+                       return;
+               }
                T g = gcd(llabs(P),llabs(Q));
                P /= g;
                Q /= g;
                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);}
 
        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);
        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;
        }
                result.CheckAccuracy(ToDouble() - r.ToDouble(),"-");
                return result;
        }
-       */
        Rational operator*(const Rational & r) const 
        {
                Rational result(P * r.P, Q * r.Q);
        Rational operator*(const Rational & r) const 
        {
                Rational result(P * r.P, Q * r.Q);
@@ -128,8 +128,9 @@ struct Rational
                return result;
        }       
 
                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());}
 
        //Rational operator*(const Rational & r) const {return Rational(ToDouble()*r.ToDouble());}
        //Rational operator/(const Rational & r) const {return Rational(ToDouble()/r.ToDouble());}
 

UCC git Repository :: git.ucc.asn.au