diff --git a/aegisub/src/spline.cpp b/aegisub/src/spline.cpp index 43ff2b647..7b97821df 100644 --- a/aegisub/src/spline.cpp +++ b/aegisub/src/spline.cpp @@ -289,9 +289,11 @@ void Spline::MovePoint(int curveIndex,int point,wxPoint pos) { /// @brief Gets a list of points in the curve /// @param points /// @param pointCurve -void Spline::GetPointList(std::vector &points,std::vector &pointCurve) { +void Spline::GetPointList(std::vector &points,std::vector &pointCurve) { // Prepare points.clear(); + points.reserve((curves.size() + 1) * 2); + pointCurve.reserve(curves.size() + 1); pointCurve.clear(); Vector2D pt; bool isFirst = true; @@ -301,14 +303,16 @@ void Spline::GetPointList(std::vector &points,std::vector &pointC for (std::list::iterator cur = curves.begin();cur!=curves.end();cur++,curve++) { // First point if (isFirst) { - points.push_back(cur->p1); + points.push_back(cur->p1.x); + points.push_back(cur->p1.y); pointCurve.push_back(curve); isFirst = false; } // Line if (cur->type == CURVE_LINE) { - points.push_back(cur->p2); + points.push_back(cur->p2.x); + points.push_back(cur->p2.y); pointCurve.push_back(curve); } @@ -328,15 +332,18 @@ void Spline::GetPointList(std::vector &points,std::vector &pointC for (int i=1;i<=steps;i++) { // Get t and t-1 (u) float t = float(i)/float(steps); - points.push_back(cur->GetPoint(t)); + Vector2D p = cur->GetPoint(t); + points.push_back(p.x); + points.push_back(p.y); pointCurve.push_back(curve); } } } // Insert a copy of the first point at the end - if (points.size()) { + if (!points.empty()) { points.push_back(points[0]); + points.push_back(points[1]); pointCurve.push_back(curve); } } diff --git a/aegisub/src/spline.h b/aegisub/src/spline.h index c4af6ba64..ad7552913 100644 --- a/aegisub/src/spline.h +++ b/aegisub/src/spline.h @@ -71,7 +71,7 @@ public: void MovePoint(int curveIndex,int point,wxPoint pos); void Smooth(float smooth=1.0f); - void GetPointList(std::vector &points,std::vector &pointCurve); + void GetPointList(std::vector &points,std::vector &pointCurve); SplineCurve *GetCurve(int index); void GetClosestParametricPoint(Vector2D reference,int &curve,float &t,Vector2D &point); diff --git a/aegisub/src/visual_tool_vector_clip.cpp b/aegisub/src/visual_tool_vector_clip.cpp index 962a692e4..16c4207c0 100644 --- a/aegisub/src/visual_tool_vector_clip.cpp +++ b/aegisub/src/visual_tool_vector_clip.cpp @@ -125,14 +125,19 @@ void VisualToolVectorClip::SetMode(int _mode) { /// @brief Draw void VisualToolVectorClip::Draw() { + if (spline.curves.empty()) return; + // Get line AssDialogue *line = GetActiveDialogueLine(); if (!line) return; // Parse vector - std::vector points; + std::vector points; std::vector pointCurve; spline.GetPointList(points,pointCurve); + + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(2, GL_FLOAT, 0, &points[0]); // The following is nonzero winding-number PIP based on stencils @@ -151,20 +156,12 @@ void VisualToolVectorClip::Draw() { glEnable(GL_CULL_FACE); glCullFace(GL_BACK); - glBegin(GL_TRIANGLE_FAN); - for (size_t i = 0; i < points.size(); i++) { - glVertex2f(points[i].x,points[i].y); - } - glEnd(); + glDrawArrays(GL_TRIANGLE_FAN, 0, points.size() / 2); // Decrement the winding number for each backfacing triangle glStencilOp(GL_DECR, GL_DECR, GL_DECR); glCullFace(GL_FRONT); - glBegin(GL_TRIANGLE_FAN); - for (size_t i = 0; i < points.size(); i++) { - glVertex2f(points[i].x,points[i].y); - } - glEnd(); + glDrawArrays(GL_TRIANGLE_FAN, 0, points.size() / 2); glDisable(GL_CULL_FACE); // Draw the actual rectangle @@ -190,16 +187,23 @@ void VisualToolVectorClip::Draw() { // Draw lines SetFillColour(colour[3],0.0f); SetLineColour(colour[3],1.0f,2); - int col = 3; - for (size_t i=1;i 1 && highCurve > -1) { + std::pair::iterator, std::vector::iterator> high = std::equal_range(pointCurve.begin(), pointCurve.end(), highCurve); + if (high.first != high.second) { + SetLineColour(colour[2], 1.f, 2); + int first = std::distance(pointCurve.begin(), high.first); + int count = std::distance(high.first, high.second); + if (first > 0) first -= 1; + glDrawArrays(GL_LINE_STRIP, first, count); } - DrawLine(points[i-1].x,points[i-1].y,points[i].x,points[i].y); } + glDisableClientState(GL_VERTEX_ARRAY); + // Draw lines connecting the bicubic features SetLineColour(colour[3],0.9f,1); for (std::list::iterator cur=spline.curves.begin();cur!=spline.curves.end();cur++) {