mirror of https://github.com/odrling/Aegisub
Make the vector clip visual tool use vertex arrays rather than immediate mode to render the spline
Originally committed to SVN as r4458.
This commit is contained in:
parent
fae2af36fc
commit
b867eec7f3
|
@ -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<Vector2D> &points,std::vector<int> &pointCurve) {
|
||||
void Spline::GetPointList(std::vector<float> &points,std::vector<int> &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<Vector2D> &points,std::vector<int> &pointC
|
|||
for (std::list<SplineCurve>::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<Vector2D> &points,std::vector<int> &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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ public:
|
|||
void MovePoint(int curveIndex,int point,wxPoint pos);
|
||||
void Smooth(float smooth=1.0f);
|
||||
|
||||
void GetPointList(std::vector<Vector2D> &points,std::vector<int> &pointCurve);
|
||||
void GetPointList(std::vector<float> &points,std::vector<int> &pointCurve);
|
||||
SplineCurve *GetCurve(int index);
|
||||
|
||||
void GetClosestParametricPoint(Vector2D reference,int &curve,float &t,Vector2D &point);
|
||||
|
|
|
@ -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<Vector2D> points;
|
||||
std::vector<float> points;
|
||||
std::vector<int> 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<points.size();i++) {
|
||||
int useCol = pointCurve[i] == highCurve && !curFeature ? 2 : 3;
|
||||
if (col != useCol) {
|
||||
col = useCol;
|
||||
SetLineColour(colour[col],1.0f,2);
|
||||
SetModeLine();
|
||||
glDrawArrays(GL_LINE_STRIP, 0, points.size() / 2);
|
||||
|
||||
// Draw highlighted line
|
||||
if (!curFeature && points.size() > 1 && highCurve > -1) {
|
||||
std::pair<std::vector<int>::iterator, std::vector<int>::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<SplineCurve>::iterator cur=spline.curves.begin();cur!=spline.curves.end();cur++) {
|
||||
|
|
Loading…
Reference in New Issue