So the quad tree should just have to care about bounding rectangles.
Also so the GPU renderer now doesn't need transforming but CPU renderer does now.
AddBezier assumes absolute coordinates and transforms to relative coordinates
AddBezierData is assuming relative coordinates.
Totally clear.
PS: Basically whatever is convenient/efficient for the GPU is inconvenient/inefficient for the CPU
and vice versa. Fun!
Rect SolveBounds() const;
+ Bezier ToAbsolute(const Rect & bounds) const
+ {
+ return Bezier(*this, bounds);
+ }
+
/** Convert absolute control points to control points relative to bounds
* (This basically does the opposite of the Copy constructor)
* ie: If this is absolute, the returned Bezier will be relative to the bounds rectangle
*/
- Bezier CopyInverse(const Rect & bounds) const
+ Bezier ToRelative(const Rect & bounds) const
{
// x' <- (x - x0)/w etc
// special cases when w or h = 0
return result;
}
+/**
+ * Add a Bezier using Absolute coords
+ */
unsigned Document::AddBezier(const Bezier & bezier)
{
- unsigned index = AddBezierData(bezier);
- return Add(BEZIER, bezier.SolveBounds(), index);
+ Rect bounds = bezier.SolveBounds();
+ Bezier data = bezier.ToRelative(bounds); // Relative
+ unsigned index = AddBezierData(data);
+ return Add(BEZIER, bounds, index);
}
unsigned Document::Add(ObjectType type, const Rect & bounds, unsigned data_index)
Real old_x(current_x), old_y(current_y);
current_x = inst_x;
current_y = inst_y;
- unsigned bezier_index;
+ //unsigned bezier_index;
switch(instructions[i].type)
{
// Move To
break;
// Line To
case STBTT_vline:
- bezier_index = AddBezierData(Bezier(old_x + x, old_y + y, old_x + x, old_y + y, current_x + x, current_y + y, current_x + x, current_y + y));
- Add(BEZIER,Rect(0,0,1,1),bezier_index);
+ AddBezier(Bezier(old_x + x, old_y + y, old_x + x, old_y + y, current_x + x, current_y + y, current_x + x, current_y + y));
+ //Add(BEZIER,Rect(0,0,1,1),bezier_index);
break;
// Quadratic Bezier To:
case STBTT_vcurve:
// - Endpoints are the same.
// - cubic1 = quad0+(2/3)*(quad1-quad0)
// - cubic2 = quad2+(2/3)*(quad1-quad2)
- bezier_index = AddBezier(Bezier(old_x + x, old_y + y, old_x + Real(2)*(inst_cx-old_x)/Real(3) + x, old_y + Real(2)*(inst_cy-old_y)/Real(3) + y,
+ AddBezier(Bezier(old_x + x, old_y + y, old_x + Real(2)*(inst_cx-old_x)/Real(3) + x, old_y + Real(2)*(inst_cy-old_y)/Real(3) + y,
current_x + Real(2)*(inst_cx-current_x)/Real(3) + x, current_y + Real(2)*(inst_cy-current_y)/Real(3) + y, current_x + x, current_y + y));
break;
}
else
{
//doc.AddBezier(Bezier(0,0, 1,0.5, 0.5,1, 1,1));
- doc.AddText("c",1,0,0);
+ doc.AddText("The quick brown\nfox jumps over\nthe lazy dog",0.1,0,0.5);
+ //doc.AddBezier(Bezier(0,0,0,0.1,0,0.1,0,0.1));
}
Debug("Start!");
Rect bounds(b[0],b[1],b[2],b[3]);
{
if (m_indexes[i] < first_obj_id) continue;
if (m_indexes[i] >= last_obj_id) continue;
- Rect bounds(CPURenderBounds(objects.bounds[m_indexes[i]], view, target));
- PixelBounds pix_bounds(bounds);
+ const Rect & bounds = objects.bounds[m_indexes[i]];
+ PixelBounds pix_bounds(CPURenderBounds(bounds,view,target));
- Bezier control(objects.beziers[objects.data_indices[m_indexes[i]]],CPURenderBounds(Rect(0,0,1,1), view, target));
+ Bezier control(objects.beziers[objects.data_indices[m_indexes[i]]].ToAbsolute(bounds),CPURenderBounds(Rect(0,0,1,1), view, target));
//Debug("%s -> %s via %s", objects.beziers[objects.data_indices[m_indexes[i]]].Str().c_str(), control.Str().c_str(), bounds.Str().c_str());
// Draw a rectangle around the bezier for debugging the bounds rectangle calculations
ObjectRenderer::RenderLineOnCPU(pix_bounds.x, pix_bounds.y, pix_bounds.x+pix_bounds.w, pix_bounds.y, target, Colour(1,0,0,1));
for (unsigned i = 0; i < objects.types.size(); ++i)
{
if (objects.types[i] != BEZIER) continue;
- Bezier bez = objects.beziers[objects.data_indices[i]].CopyInverse(objects.bounds[i]);
+ const Bezier & bez = objects.beziers[objects.data_indices[i]];//objects.beziers[objects.data_indices[i]].CopyInverse(objects.bounds[i]);
GPUBezierCoeffs coeffs = {
Float(bez.x0), Float(bez.y0),