diff options
author | Fox Caminiti <fox@foxcam.net> | 2023-01-04 18:30:56 -0500 |
---|---|---|
committer | Fox Caminiti <fox@foxcam.net> | 2023-01-04 18:30:56 -0500 |
commit | eebbdd012b0d156e9e92369585c6ad82ed3de371 (patch) | |
tree | bbaeec7569de49f68bf853158a95c095878cf825 /src/nanovg.cpp | |
parent | a37ea807e93886e6a6ebc22a878a5649e97f015a (diff) |
shapes; remove stencil buffer?
Diffstat (limited to 'src/nanovg.cpp')
-rw-r--r-- | src/nanovg.cpp | 65 |
1 files changed, 50 insertions, 15 deletions
diff --git a/src/nanovg.cpp b/src/nanovg.cpp index 06b2910..5627b5f 100644 --- a/src/nanovg.cpp +++ b/src/nanovg.cpp @@ -128,20 +128,23 @@ static real32 * NVG_RoundCap(nvg_point * Point, real32 *StrokeData, // NOTE(fox): We only have to care about winding if we want to do HW accelerated // shape subtraction with the stencil buffer (I think). static uint32 -NVG_FlattenPath(void *Memory, block_bezier *Bezier, int PointCount, nvg_point *PointData, int *Width, int *Height) +NVG_FlattenPath(memory *Memory, shape_layer *Shape, nvg_point *PointData, int *Width, int *Height) { uint32 NumberOfVerts = 0; nvg_point *PointPlayhead = PointData; - for (int i = 0; i < PointCount; i++) { - if (i == 0 || Bezier->Point[i].Type == interpolation_type_linear) { - *(v2 *)PointPlayhead = Bezier->Point[i].Pos[0]; - if (i != 0 && i != (PointCount - 1)) { + for (int i = 0; i < Shape->Point_Count; i++) { + bezier_point *Point = Bezier_LookupAddress(Memory, Shape->Block_Bezier_Index, i, 1); +#if 0 + if (i == 0 || Point->Type == interpolation_type_linear) { + *(v2 *)PointPlayhead = Point->Pos[0]; + if (i != 0 && i != (Shape->Point_Count - 1)) { PointPlayhead->Flags |= NVG_PT_CORNER; } PointPlayhead++; NumberOfVerts++; - } else if (Bezier->Point[i].Type == interpolation_type_bezier) { - v2 Pos[4] = { Bezier->Point[i].Pos[0], Bezier->Point[i].Pos[1], Bezier->Point[i+1].Pos[2], Bezier->Point[i+1].Pos[0] }; + } else if (Point->Type == interpolation_type_bezier) { + bezier_point *Point_1 = Bezier_LookupAddress(Memory, Shape->Block_Bezier_Index, i-1, 1); + v2 Pos[4] = { Point->Pos[0], Point->Pos[1], Point_1->Pos[2], Point_1->Pos[0] }; Pos[1] = Pos[1] + Pos[0]; Pos[2] = Pos[2] + Pos[3]; NumberOfVerts += Bezier_CubicCalcPoints(Pos[3], Pos[2], Pos[1], Pos[0], PointPlayhead, sizeof(nvg_point)); @@ -151,6 +154,14 @@ NVG_FlattenPath(void *Memory, block_bezier *Bezier, int PointCount, nvg_point *P } else { Assert(0); } +#else + *(v2 *)PointPlayhead = Point->Pos[0]; + if (i != 0 && i != (Shape->Point_Count - 1)) { + PointPlayhead->Flags |= NVG_PT_CORNER; + } + PointPlayhead++; + NumberOfVerts++; +#endif } nvg_point *Point = &PointData[NumberOfVerts - 1]; nvg_point *NextPoint = PointData; @@ -178,17 +189,26 @@ NVG_FlattenPath(void *Memory, block_bezier *Bezier, int PointCount, nvg_point *P real32 MiterLimit = 2.4f; static uint32 -NVG_ExpandStroke(void *Memory, block_bezier *Bezier, int NumberOfVerts, nvg_point *PointData, real32 *StrokeData) +NVG_ExpandStroke(void *Memory, int NumberOfVerts, real32 StartWidth, bool32 IsClosed, nvg_point *PointData, real32 *StrokeData) { - real32 Width = 50 * 0.5; - nvg_point *Point = PointData; - nvg_point *NextPoint = &PointData[1]; + real32 Width = StartWidth * 0.5; int ncap = 12; real32 *StartingStrokeData = StrokeData; - StrokeData = NVG_RoundCap(Point, StrokeData, Point->dx, Point->dy, Width, ncap, 0.5, 0.5, 0); + nvg_point *Point = &PointData[NumberOfVerts - 1]; + nvg_point *NextPoint = PointData; + int Start = 0; + int LoopAmount = NumberOfVerts; + + if (!IsClosed) { + Point = PointData; + NextPoint = &PointData[1]; + Start = 1; + LoopAmount = NumberOfVerts - 1; + StrokeData = NVG_RoundCap(Point, StrokeData, Point->dx, Point->dy, Width, ncap, 0.5, 0.5, 0); + } - for (int i = 1; i < (NumberOfVerts - 1); i++) { + for (int i = Start; i < LoopAmount; i++) { real32 dlx0, dly0, dlx1, dly1, dmr2, cross, limit; dlx0 = Point->dy; @@ -223,7 +243,7 @@ NVG_ExpandStroke(void *Memory, block_bezier *Bezier, int NumberOfVerts, nvg_poin // Check to see if the corner needs to be beveled. if (NextPoint->Flags & NVG_PT_CORNER) { // if ((dmr2 * MiterLimit*MiterLimit) < 1.0f) r // || lineJoin == NVG_BEVEL || lineJoin == NVG_ROUND) { - NextPoint->Flags |= NVG_PT_BEVEL; + // NextPoint->Flags |= NVG_PT_BEVEL; // } } @@ -239,9 +259,24 @@ NVG_ExpandStroke(void *Memory, block_bezier *Bezier, int NumberOfVerts, nvg_poin Point = NextPoint++; } - StrokeData = NVG_RoundCap(NextPoint, StrokeData, Point->dx, Point->dy, Width, ncap, 0.5, 0.5, 1); + if (!IsClosed) { + StrokeData = NVG_RoundCap(NextPoint, StrokeData, Point->dx, Point->dy, Width, ncap, 0.5, 0.5, 1); + } else { + StrokeData = NVG_Point(StrokeData, StartingStrokeData[0], StartingStrokeData[1], 0, 0); + StrokeData = NVG_Point(StrokeData, StartingStrokeData[4], StartingStrokeData[5], 0, 0); + } int GL_PointCount = (StrokeData - StartingStrokeData) / 4; return GL_PointCount; } + +static void +NVG_ExpandFill(void *Memory, int NumberOfVerts, nvg_point *PointData, real32 *FillData) +{ + nvg_point *Point = PointData; + for (int i = 0; i < NumberOfVerts; i++) { + FillData = NVG_Point(FillData, Point->x, Point->y, 0, 0); + Point++; + } +} |