[canvas cleanup]
- Remove attributes/color arguments in functions where we don't need them anymore (since they're defined when calling mg_next_shape()) - Renamed "_with_zindex" functions with "_path" -> these function only fill a path (eg rect), but don't increment the current shape
This commit is contained in:
parent
09a18419e4
commit
35e396e4c4
|
@ -516,11 +516,11 @@ void mg_push_vertex(mg_canvas_data* canvas, vec2 pos, vec4 cubic)
|
||||||
// Path Filling
|
// Path Filling
|
||||||
//-----------------------------------------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------------------------------------
|
||||||
//NOTE(martin): forward declarations
|
//NOTE(martin): forward declarations
|
||||||
void mg_render_fill_cubic(mg_canvas_data* canvas, vec2 p[4], mg_color color);
|
void mg_render_fill_cubic(mg_canvas_data* canvas, vec2 p[4]);
|
||||||
|
|
||||||
//NOTE(martin): quadratics filling
|
//NOTE(martin): quadratics filling
|
||||||
|
|
||||||
void mg_render_fill_quadratic(mg_canvas_data* canvas, vec2 p[3], mg_color color)
|
void mg_render_fill_quadratic(mg_canvas_data* canvas, vec2 p[3])
|
||||||
{
|
{
|
||||||
u32 baseIndex = mg_vertices_base_index(canvas);
|
u32 baseIndex = mg_vertices_base_index(canvas);
|
||||||
|
|
||||||
|
@ -545,7 +545,7 @@ void mg_render_fill_quadratic(mg_canvas_data* canvas, vec2 p[3], mg_color color)
|
||||||
|
|
||||||
//NOTE(martin): cubic filling
|
//NOTE(martin): cubic filling
|
||||||
|
|
||||||
void mg_split_and_fill_cubic(mg_canvas_data* canvas, vec2 p[4], f32 tSplit, mg_color color)
|
void mg_split_and_fill_cubic(mg_canvas_data* canvas, vec2 p[4], f32 tSplit)
|
||||||
{
|
{
|
||||||
int subVertexCount = 0;
|
int subVertexCount = 0;
|
||||||
int subIndexCount = 0;
|
int subIndexCount = 0;
|
||||||
|
@ -593,13 +593,13 @@ void mg_split_and_fill_cubic(mg_canvas_data* canvas, vec2 p[4], f32 tSplit, mg_c
|
||||||
indices[1] = baseIndex + 1;
|
indices[1] = baseIndex + 1;
|
||||||
indices[2] = baseIndex + 2;
|
indices[2] = baseIndex + 2;
|
||||||
|
|
||||||
mg_render_fill_cubic(canvas, subPointsLow, color);
|
mg_render_fill_cubic(canvas, subPointsLow);
|
||||||
mg_render_fill_cubic(canvas, subPointsHigh, color);
|
mg_render_fill_cubic(canvas, subPointsHigh);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mg_render_fill_cubic(mg_canvas_data* canvas, vec2 p[4], mg_color color)
|
void mg_render_fill_cubic(mg_canvas_data* canvas, vec2 p[4])
|
||||||
{
|
{
|
||||||
LOG_DEBUG("graphics render fill cubic\n");
|
LOG_DEBUG("graphics render fill cubic\n");
|
||||||
|
|
||||||
|
@ -671,7 +671,7 @@ void mg_render_fill_cubic(mg_canvas_data* canvas, vec2 p[4], mg_color color)
|
||||||
{1.5*p[1].x - 0.5*p[0].x, 1.5*p[1].y - 0.5*p[0].y},
|
{1.5*p[1].x - 0.5*p[0].x, 1.5*p[1].y - 0.5*p[0].y},
|
||||||
p[3]};
|
p[3]};
|
||||||
|
|
||||||
mg_render_fill_quadratic(canvas, quadControlPoints, color);
|
mg_render_fill_quadratic(canvas, quadControlPoints);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if( (discrFactor2 > 0 && d1 != 0)
|
else if( (discrFactor2 > 0 && d1 != 0)
|
||||||
|
@ -740,13 +740,13 @@ void mg_render_fill_cubic(mg_canvas_data* canvas, vec2 p[4], mg_color color)
|
||||||
if(sd != 0 && td/sd < 0.99 && td/sd > 0.01)
|
if(sd != 0 && td/sd < 0.99 && td/sd > 0.01)
|
||||||
{
|
{
|
||||||
LOG_DEBUG("split curve at first double point\n");
|
LOG_DEBUG("split curve at first double point\n");
|
||||||
mg_split_and_fill_cubic(canvas, p, td/sd, color);
|
mg_split_and_fill_cubic(canvas, p, td/sd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(se != 0 && te/se < 0.99 && te/se > 0.01)
|
if(se != 0 && te/se < 0.99 && te/se > 0.01)
|
||||||
{
|
{
|
||||||
LOG_DEBUG("split curve at second double point\n");
|
LOG_DEBUG("split curve at second double point\n");
|
||||||
mg_split_and_fill_cubic(canvas, p, te/se, color);
|
mg_split_and_fill_cubic(canvas, p, te/se);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1044,7 +1044,7 @@ void mg_render_fill_cubic(mg_canvas_data* canvas, vec2 p[4], mg_color color)
|
||||||
|
|
||||||
//NOTE(martin): global path fill
|
//NOTE(martin): global path fill
|
||||||
|
|
||||||
void mg_render_fill(mg_canvas_data* canvas, mg_path_elt* elements, mg_path_descriptor* path, mg_color color)
|
void mg_render_fill(mg_canvas_data* canvas, mg_path_elt* elements, mg_path_descriptor* path)
|
||||||
{
|
{
|
||||||
u32 eltCount = path->count;
|
u32 eltCount = path->count;
|
||||||
vec2 startPoint = path->startPoint;
|
vec2 startPoint = path->startPoint;
|
||||||
|
@ -1074,14 +1074,14 @@ void mg_render_fill(mg_canvas_data* canvas, mg_path_elt* elements, mg_path_descr
|
||||||
|
|
||||||
case MG_PATH_QUADRATIC:
|
case MG_PATH_QUADRATIC:
|
||||||
{
|
{
|
||||||
mg_render_fill_quadratic(canvas, controlPoints, color);
|
mg_render_fill_quadratic(canvas, controlPoints);
|
||||||
endPoint = controlPoints[2];
|
endPoint = controlPoints[2];
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case MG_PATH_CUBIC:
|
case MG_PATH_CUBIC:
|
||||||
{
|
{
|
||||||
mg_render_fill_cubic(canvas, controlPoints, color);
|
mg_render_fill_cubic(canvas, controlPoints);
|
||||||
endPoint = controlPoints[3];
|
endPoint = controlPoints[3];
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
|
@ -1122,9 +1122,6 @@ void mg_render_stroke_line(mg_canvas_data* canvas, vec2 p[2], mg_attributes* att
|
||||||
n0.x *= halfW/norm0;
|
n0.x *= halfW/norm0;
|
||||||
n0.y *= halfW/norm0;
|
n0.y *= halfW/norm0;
|
||||||
|
|
||||||
|
|
||||||
mg_color color = attributes->color;
|
|
||||||
|
|
||||||
u32 baseIndex = mg_vertices_base_index(canvas);
|
u32 baseIndex = mg_vertices_base_index(canvas);
|
||||||
i32* indices = mg_reserve_indices(canvas, 6);
|
i32* indices = mg_reserve_indices(canvas, 6);
|
||||||
|
|
||||||
|
@ -1331,8 +1328,8 @@ void mg_render_stroke_quadratic(mg_canvas_data* canvas, vec2 p[4], mg_attributes
|
||||||
|
|
||||||
mg_next_shape(canvas, attributes->color);
|
mg_next_shape(canvas, attributes->color);
|
||||||
|
|
||||||
mg_render_fill_quadratic(canvas, positiveOffsetHull, attributes->color);
|
mg_render_fill_quadratic(canvas, positiveOffsetHull);
|
||||||
mg_render_fill_quadratic(canvas, negativeOffsetHull, attributes->color);
|
mg_render_fill_quadratic(canvas, negativeOffsetHull);
|
||||||
|
|
||||||
//NOTE(martin): add base triangles
|
//NOTE(martin): add base triangles
|
||||||
u32 baseIndex = mg_vertices_base_index(canvas);
|
u32 baseIndex = mg_vertices_base_index(canvas);
|
||||||
|
@ -1482,8 +1479,8 @@ void mg_render_stroke_cubic(mg_canvas_data* canvas, vec2 p[4], mg_attributes* at
|
||||||
//NOTE(martin): push the actual fill commands for the offset contour
|
//NOTE(martin): push the actual fill commands for the offset contour
|
||||||
mg_next_shape(canvas, attributes->color);
|
mg_next_shape(canvas, attributes->color);
|
||||||
|
|
||||||
mg_render_fill_cubic(canvas, positiveOffsetHull, attributes->color);
|
mg_render_fill_cubic(canvas, positiveOffsetHull);
|
||||||
mg_render_fill_cubic(canvas, negativeOffsetHull, attributes->color);
|
mg_render_fill_cubic(canvas, negativeOffsetHull);
|
||||||
|
|
||||||
//NOTE(martin): add base triangles
|
//NOTE(martin): add base triangles
|
||||||
u32 baseIndex = mg_vertices_base_index(canvas);
|
u32 baseIndex = mg_vertices_base_index(canvas);
|
||||||
|
@ -1872,7 +1869,7 @@ void mg_render_rectangle_stroke(mg_canvas_data* canvas, mp_rect rect, mg_attribu
|
||||||
indices[11] = baseIndex + 7;
|
indices[11] = baseIndex + 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mg_render_fill_arc_corner(mg_canvas_data* canvas, f32 x, f32 y, f32 rx, f32 ry, mg_color color)
|
void mg_render_fill_arc_corner(mg_canvas_data* canvas, f32 x, f32 y, f32 rx, f32 ry)
|
||||||
{
|
{
|
||||||
//NOTE(martin): draw a precomputed arc corner, using a bezier approximation
|
//NOTE(martin): draw a precomputed arc corner, using a bezier approximation
|
||||||
u32 baseIndex = mg_vertices_base_index(canvas);
|
u32 baseIndex = mg_vertices_base_index(canvas);
|
||||||
|
@ -1904,9 +1901,8 @@ void mg_render_fill_arc_corner(mg_canvas_data* canvas, f32 x, f32 y, f32 rx, f32
|
||||||
indices[5] = baseIndex + 3;
|
indices[5] = baseIndex + 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mg_render_rounded_rectangle_fill_with_z_index(mg_canvas_data* canvas,
|
void mg_render_rounded_rectangle_fill_path(mg_canvas_data* canvas,
|
||||||
mg_rounded_rect rect,
|
mg_rounded_rect rect)
|
||||||
mg_attributes* attributes)
|
|
||||||
{
|
{
|
||||||
//NOTE(martin): draw a rounded rectangle by drawing a normal rectangle and 4 corners,
|
//NOTE(martin): draw a rounded rectangle by drawing a normal rectangle and 4 corners,
|
||||||
// approximating an arc by a precomputed bezier curve
|
// approximating an arc by a precomputed bezier curve
|
||||||
|
@ -1938,10 +1934,10 @@ void mg_render_rounded_rectangle_fill_with_z_index(mg_canvas_data* canvas,
|
||||||
indices[i] = fanIndices[i] + baseIndex;
|
indices[i] = fanIndices[i] + baseIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
mg_render_fill_arc_corner(canvas, rect.x, rect.y, rect.r, rect.r, attributes->color);
|
mg_render_fill_arc_corner(canvas, rect.x, rect.y, rect.r, rect.r);
|
||||||
mg_render_fill_arc_corner(canvas, rect.x + rect.w, rect.y, -rect.r, rect.r, attributes->color);
|
mg_render_fill_arc_corner(canvas, rect.x + rect.w, rect.y, -rect.r, rect.r);
|
||||||
mg_render_fill_arc_corner(canvas, rect.x + rect.w, rect.y + rect.h, -rect.r, -rect.r, attributes->color);
|
mg_render_fill_arc_corner(canvas, rect.x + rect.w, rect.y + rect.h, -rect.r, -rect.r);
|
||||||
mg_render_fill_arc_corner(canvas, rect.x, rect.y + rect.h, rect.r, -rect.r, attributes->color);
|
mg_render_fill_arc_corner(canvas, rect.x, rect.y + rect.h, rect.r, -rect.r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1950,7 +1946,7 @@ void mg_render_rounded_rectangle_fill(mg_canvas_data* canvas,
|
||||||
mg_attributes* attributes)
|
mg_attributes* attributes)
|
||||||
{
|
{
|
||||||
mg_next_shape(canvas, attributes->color);
|
mg_next_shape(canvas, attributes->color);
|
||||||
mg_render_rounded_rectangle_fill_with_z_index(canvas, rect, attributes);
|
mg_render_rounded_rectangle_fill_path(canvas, rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mg_render_rounded_rectangle_stroke(mg_canvas_data* canvas,
|
void mg_render_rounded_rectangle_stroke(mg_canvas_data* canvas,
|
||||||
|
@ -1965,11 +1961,11 @@ void mg_render_rounded_rectangle_stroke(mg_canvas_data* canvas,
|
||||||
mg_rounded_rect outer = {rect.x - halfW, rect.y - halfW, rect.w + width, rect.h + width, rect.r + halfW};
|
mg_rounded_rect outer = {rect.x - halfW, rect.y - halfW, rect.w + width, rect.h + width, rect.r + halfW};
|
||||||
|
|
||||||
mg_next_shape(canvas, attributes->color);
|
mg_next_shape(canvas, attributes->color);
|
||||||
mg_render_rounded_rectangle_fill_with_z_index(canvas, outer, attributes);
|
mg_render_rounded_rectangle_fill_path(canvas, outer);
|
||||||
mg_render_rounded_rectangle_fill_with_z_index(canvas, inner, attributes);
|
mg_render_rounded_rectangle_fill_path(canvas, inner);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mg_render_ellipse_fill_with_z_index(mg_canvas_data* canvas, mp_rect rect, mg_attributes* attributes)
|
void mg_render_ellipse_fill_path(mg_canvas_data* canvas, mp_rect rect)
|
||||||
{
|
{
|
||||||
//NOTE(martin): draw a filled ellipse by drawing a diamond and 4 corners,
|
//NOTE(martin): draw a filled ellipse by drawing a diamond and 4 corners,
|
||||||
// approximating an arc by a precomputed bezier curve
|
// approximating an arc by a precomputed bezier curve
|
||||||
|
@ -2000,16 +1996,16 @@ void mg_render_ellipse_fill_with_z_index(mg_canvas_data* canvas, mp_rect rect, m
|
||||||
indices[4] = baseIndex + 2;
|
indices[4] = baseIndex + 2;
|
||||||
indices[5] = baseIndex + 3;
|
indices[5] = baseIndex + 3;
|
||||||
|
|
||||||
mg_render_fill_arc_corner(canvas, rect.x, rect.y, rx, ry, attributes->color);
|
mg_render_fill_arc_corner(canvas, rect.x, rect.y, rx, ry);
|
||||||
mg_render_fill_arc_corner(canvas, rect.x + rect.w, rect.y, -rx, ry, attributes->color);
|
mg_render_fill_arc_corner(canvas, rect.x + rect.w, rect.y, -rx, ry);
|
||||||
mg_render_fill_arc_corner(canvas, rect.x + rect.w, rect.y + rect.h, -rx, -ry, attributes->color);
|
mg_render_fill_arc_corner(canvas, rect.x + rect.w, rect.y + rect.h, -rx, -ry);
|
||||||
mg_render_fill_arc_corner(canvas, rect.x, rect.y + rect.h, rx, -ry, attributes->color);
|
mg_render_fill_arc_corner(canvas, rect.x, rect.y + rect.h, rx, -ry);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mg_render_ellipse_fill(mg_canvas_data* canvas, mp_rect rect, mg_attributes* attributes)
|
void mg_render_ellipse_fill(mg_canvas_data* canvas, mp_rect rect, mg_attributes* attributes)
|
||||||
{
|
{
|
||||||
mg_next_shape(canvas, attributes->color);
|
mg_next_shape(canvas, attributes->color);
|
||||||
mg_render_ellipse_fill_with_z_index(canvas, rect, attributes);
|
mg_render_ellipse_fill_path(canvas, rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mg_render_ellipse_stroke(mg_canvas_data* canvas, mp_rect rect, mg_attributes* attributes)
|
void mg_render_ellipse_stroke(mg_canvas_data* canvas, mp_rect rect, mg_attributes* attributes)
|
||||||
|
@ -2022,8 +2018,8 @@ void mg_render_ellipse_stroke(mg_canvas_data* canvas, mp_rect rect, mg_attribute
|
||||||
mp_rect outer = {rect.x - halfW, rect.y - halfW, rect.w + width, rect.h + width};
|
mp_rect outer = {rect.x - halfW, rect.y - halfW, rect.w + width, rect.h + width};
|
||||||
|
|
||||||
mg_next_shape(canvas, attributes->color);
|
mg_next_shape(canvas, attributes->color);
|
||||||
mg_render_ellipse_fill_with_z_index(canvas, outer, attributes);
|
mg_render_ellipse_fill_path(canvas, outer);
|
||||||
mg_render_ellipse_fill_with_z_index(canvas, inner, attributes);
|
mg_render_ellipse_fill_path(canvas, inner);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mg_render_image(mg_canvas_data* canvas, mg_image image, mp_rect rect)
|
void mg_render_image(mg_canvas_data* canvas, mg_image image, mp_rect rect)
|
||||||
|
@ -2847,8 +2843,7 @@ void mg_flush_commands(int primitiveCount, mg_primitive* primitives, mg_path_elt
|
||||||
mg_next_shape(canvas, primitive->attributes.color);
|
mg_next_shape(canvas, primitive->attributes.color);
|
||||||
mg_render_fill(canvas,
|
mg_render_fill(canvas,
|
||||||
pathElements + primitive->path.startIndex,
|
pathElements + primitive->path.startIndex,
|
||||||
&primitive->path,
|
&primitive->path);
|
||||||
primitive->attributes.color);
|
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case MG_CMD_STROKE:
|
case MG_CMD_STROKE:
|
||||||
|
|
7
todo.txt
7
todo.txt
|
@ -16,10 +16,11 @@ Overview
|
||||||
|
|
||||||
Clean+Fixes
|
Clean+Fixes
|
||||||
-----------
|
-----------
|
||||||
[ ] Clean canvas code
|
[.] Clean canvas code
|
||||||
[x] make zIndex implicit when calling push_vertex
|
|
||||||
[x] rename zIndex with "shapeIndex" everywhere
|
[x] rename zIndex with "shapeIndex" everywhere
|
||||||
[ ] remove color args in functions that don't need it anymore
|
[x] make shapeIndex implicit when calling push_vertex
|
||||||
|
[x] remove color args in functions that don't need it anymore
|
||||||
|
[x] remove or rename "_with_zindex" functions
|
||||||
|
|
||||||
[ ] Rename MG_GL_CANVAS_TILE_ARRAY_SIZE/LENGTH unambiguously and make it consistent between C and glsl code
|
[ ] Rename MG_GL_CANVAS_TILE_ARRAY_SIZE/LENGTH unambiguously and make it consistent between C and glsl code
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue