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:
Thomas Goyne 2010-06-07 07:24:43 +00:00
parent fae2af36fc
commit b867eec7f3
3 changed files with 35 additions and 24 deletions

View file

@ -289,9 +289,11 @@ void Spline::MovePoint(int curveIndex,int point,wxPoint pos) {
/// @brief Gets a list of points in the curve /// @brief Gets a list of points in the curve
/// @param points /// @param points
/// @param pointCurve /// @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 // Prepare
points.clear(); points.clear();
points.reserve((curves.size() + 1) * 2);
pointCurve.reserve(curves.size() + 1);
pointCurve.clear(); pointCurve.clear();
Vector2D pt; Vector2D pt;
bool isFirst = true; 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++) { for (std::list<SplineCurve>::iterator cur = curves.begin();cur!=curves.end();cur++,curve++) {
// First point // First point
if (isFirst) { if (isFirst) {
points.push_back(cur->p1); points.push_back(cur->p1.x);
points.push_back(cur->p1.y);
pointCurve.push_back(curve); pointCurve.push_back(curve);
isFirst = false; isFirst = false;
} }
// Line // Line
if (cur->type == CURVE_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); 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++) { for (int i=1;i<=steps;i++) {
// Get t and t-1 (u) // Get t and t-1 (u)
float t = float(i)/float(steps); 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); pointCurve.push_back(curve);
} }
} }
} }
// Insert a copy of the first point at the end // 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[0]);
points.push_back(points[1]);
pointCurve.push_back(curve); pointCurve.push_back(curve);
} }
} }

View file

@ -71,7 +71,7 @@ public:
void MovePoint(int curveIndex,int point,wxPoint pos); void MovePoint(int curveIndex,int point,wxPoint pos);
void Smooth(float smooth=1.0f); 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); SplineCurve *GetCurve(int index);
void GetClosestParametricPoint(Vector2D reference,int &curve,float &t,Vector2D &point); void GetClosestParametricPoint(Vector2D reference,int &curve,float &t,Vector2D &point);

View file

@ -125,14 +125,19 @@ void VisualToolVectorClip::SetMode(int _mode) {
/// @brief Draw /// @brief Draw
void VisualToolVectorClip::Draw() { void VisualToolVectorClip::Draw() {
if (spline.curves.empty()) return;
// Get line // Get line
AssDialogue *line = GetActiveDialogueLine(); AssDialogue *line = GetActiveDialogueLine();
if (!line) return; if (!line) return;
// Parse vector // Parse vector
std::vector<Vector2D> points; std::vector<float> points;
std::vector<int> pointCurve; std::vector<int> pointCurve;
spline.GetPointList(points,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 // The following is nonzero winding-number PIP based on stencils
@ -151,20 +156,12 @@ void VisualToolVectorClip::Draw() {
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
glCullFace(GL_BACK); glCullFace(GL_BACK);
glBegin(GL_TRIANGLE_FAN); glDrawArrays(GL_TRIANGLE_FAN, 0, points.size() / 2);
for (size_t i = 0; i < points.size(); i++) {
glVertex2f(points[i].x,points[i].y);
}
glEnd();
// Decrement the winding number for each backfacing triangle // Decrement the winding number for each backfacing triangle
glStencilOp(GL_DECR, GL_DECR, GL_DECR); glStencilOp(GL_DECR, GL_DECR, GL_DECR);
glCullFace(GL_FRONT); glCullFace(GL_FRONT);
glBegin(GL_TRIANGLE_FAN); glDrawArrays(GL_TRIANGLE_FAN, 0, points.size() / 2);
for (size_t i = 0; i < points.size(); i++) {
glVertex2f(points[i].x,points[i].y);
}
glEnd();
glDisable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
// Draw the actual rectangle // Draw the actual rectangle
@ -190,16 +187,23 @@ void VisualToolVectorClip::Draw() {
// Draw lines // Draw lines
SetFillColour(colour[3],0.0f); SetFillColour(colour[3],0.0f);
SetLineColour(colour[3],1.0f,2); SetLineColour(colour[3],1.0f,2);
int col = 3; SetModeLine();
for (size_t i=1;i<points.size();i++) { glDrawArrays(GL_LINE_STRIP, 0, points.size() / 2);
int useCol = pointCurve[i] == highCurve && !curFeature ? 2 : 3;
if (col != useCol) { // Draw highlighted line
col = useCol; if (!curFeature && points.size() > 1 && highCurve > -1) {
SetLineColour(colour[col],1.0f,2); 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 // Draw lines connecting the bicubic features
SetLineColour(colour[3],0.9f,1); SetLineColour(colour[3],0.9f,1);
for (std::list<SplineCurve>::iterator cur=spline.curves.begin();cur!=spline.curves.end();cur++) { for (std::list<SplineCurve>::iterator cur=spline.curves.begin();cur!=spline.curves.end();cur++) {