Update J2D.cpp
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 2m26s
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 2m26s
Dramatically improve the speed of J2D::DrawCubicBezierCurve
This commit is contained in:
@@ -826,23 +826,24 @@ void JGL::J2D::FillGradientTriangle(const Color4& a_color, const Color4& b_color
|
||||
glColor4fv(default_state.draw_color);
|
||||
}
|
||||
|
||||
//TODO render all in once pass with GL_LINE_LOOP instead of separate lines.
|
||||
void JGL::J2D::DrawCubicBezierCurve(const Color4& color, const Vector2& controlA, const Vector2& pointA, const Vector2& pointB, const Vector2& controlB,
|
||||
int subdivisions, float thickness) {
|
||||
|
||||
|
||||
Vector2 last = controlA;
|
||||
const Vector2& first = controlB;
|
||||
for (int i = 0; i < subdivisions; ++i)
|
||||
{
|
||||
|
||||
std::vector<Vector2> vertices(2 * subdivisions + 2);
|
||||
for (int i = 0; i < subdivisions; ++i) {
|
||||
float alpha = (float) i / (float) subdivisions;
|
||||
Vector2 step = J3ML::Algorithm::Bezier(alpha, controlA, pointA, pointB, controlB);
|
||||
DrawLine(color, last, step, thickness);
|
||||
vertices[2 * i] = last;
|
||||
vertices[2 * i + 1] = step;
|
||||
last = step;
|
||||
}
|
||||
|
||||
// Have to manually draw the last segment of the curve.
|
||||
DrawLine(color, last, first, thickness);
|
||||
vertices[2 * subdivisions] = last;
|
||||
vertices[2 * subdivisions + 1] = first;
|
||||
DrawLines(color, vertices.data(), vertices.size(), thickness);
|
||||
}
|
||||
|
||||
void JGL::J2D::OutlinePolygon(const Color4& color, const Vector2* points, int points_size, float thickness) {
|
||||
|
Reference in New Issue
Block a user