From 185c8a3d509bbdb2c7e38c4df079cb225795584a Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Sat, 29 May 2004 20:25:29 +0000 Subject: [PATCH] simplified vertex array logic --- Common/VertexArray.cpp | 6 ++- Common/VertexArray.h | 2 +- Common/Views.cpp | 4 +- Common/Views.h | 1 - Fltk/Callbacks.cpp | 4 +- Graphics/Iso.cpp | 4 +- Graphics/Mesh.cpp | 84 +++++++++++++++++++++------------------- Graphics/Post.cpp | 79 ++++++++++++++++++------------------- Graphics/PostElement.cpp | 19 +++++---- 9 files changed, 106 insertions(+), 97 deletions(-) diff --git a/Common/VertexArray.cpp b/Common/VertexArray.cpp index 59b98f978f..2793c0b4b9 100644 --- a/Common/VertexArray.cpp +++ b/Common/VertexArray.cpp @@ -1,4 +1,4 @@ -// $Id: VertexArray.cpp,v 1.1 2004-05-29 10:11:10 geuzaine Exp $ +// $Id: VertexArray.cpp,v 1.2 2004-05-29 20:25:28 geuzaine Exp $ // // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // @@ -26,7 +26,9 @@ triangleVertexArray::triangleVertexArray(int nb) { - num_triangles = 0; + num_triangles = fill = 0; + if(!nb) + nb = 1000; vertices = List_Create(nb * 3 * 3, 9000, sizeof(float)); normals = List_Create(nb * 3 * 3, 9000, sizeof(float)); colors = List_Create(nb * 3 * 4, 12000, sizeof(unsigned char)); diff --git a/Common/VertexArray.h b/Common/VertexArray.h index 2b621972b5..3562103cd6 100644 --- a/Common/VertexArray.h +++ b/Common/VertexArray.h @@ -24,7 +24,7 @@ class triangleVertexArray{ public: - int num_triangles; + int num_triangles, fill; List_T *vertices, *normals, *colors; triangleVertexArray(int nb); ~triangleVertexArray(); diff --git a/Common/Views.cpp b/Common/Views.cpp index 0e8874778d..23b44fe7d6 100644 --- a/Common/Views.cpp +++ b/Common/Views.cpp @@ -1,4 +1,4 @@ -// $Id: Views.cpp,v 1.119 2004-05-29 10:11:10 geuzaine Exp $ +// $Id: Views.cpp,v 1.120 2004-05-29 20:25:28 geuzaine Exp $ // // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // @@ -73,8 +73,6 @@ Post_View *BeginView(int allocate) v->Index = i; v->Dirty = 1; v->VertexArray = NULL; - v->FillVertexArray = 0; - v->UseVertexArray = 0; v->NbTimeStep = 0; v->TimeStepMin = NULL; v->TimeStepMax = NULL; diff --git a/Common/Views.h b/Common/Views.h index f39a3af4d4..d343255f0b 100644 --- a/Common/Views.h +++ b/Common/Views.h @@ -62,7 +62,6 @@ class Post_View{ // a vertex array to draw triangles efficiently triangleVertexArray *VertexArray; - int FillVertexArray, UseVertexArray; // options int Type, Position[2], AutoPosition, Size[2]; diff --git a/Fltk/Callbacks.cpp b/Fltk/Callbacks.cpp index 1a1704f66a..6ab4ae5b33 100644 --- a/Fltk/Callbacks.cpp +++ b/Fltk/Callbacks.cpp @@ -1,4 +1,4 @@ -// $Id: Callbacks.cpp,v 1.242 2004-05-29 10:11:11 geuzaine Exp $ +// $Id: Callbacks.cpp,v 1.243 2004-05-29 20:25:28 geuzaine Exp $ // // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // @@ -2487,7 +2487,7 @@ void mesh_degree_cb(CALLBACK_ARGS) Degre1(); break; } - + CTX.mesh.changed = 1; Draw(); Msg(STATUS3N, "Ready"); } diff --git a/Graphics/Iso.cpp b/Graphics/Iso.cpp index e69d3e51c1..0df6b8a752 100644 --- a/Graphics/Iso.cpp +++ b/Graphics/Iso.cpp @@ -1,4 +1,4 @@ -// $Id: Iso.cpp,v 1.24 2004-05-29 10:11:12 geuzaine Exp $ +// $Id: Iso.cpp,v 1.25 2004-05-29 20:25:28 geuzaine Exp $ // // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // @@ -422,7 +422,7 @@ void IsoSimplex(Post_View * View, int preproNormals, if(preproNormals) return; - if(View->FillVertexArray){ + if(View->VertexArray && View->VertexArray->fill){ for(int i = 2; i < nb; i++){ View->VertexArray->add(Xp[0] + View->Raise[0] * V, Yp[0] + View->Raise[1] * V, diff --git a/Graphics/Mesh.cpp b/Graphics/Mesh.cpp index b20676131e..ed105101d4 100644 --- a/Graphics/Mesh.cpp +++ b/Graphics/Mesh.cpp @@ -1,4 +1,4 @@ -// $Id: Mesh.cpp,v 1.90 2004-05-29 10:39:32 geuzaine Exp $ +// $Id: Mesh.cpp,v 1.91 2004-05-29 20:25:28 geuzaine Exp $ // // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // @@ -40,9 +40,7 @@ extern int edges_pyramid[8][2]; static DrawingColor theColor; static int thePhysical = 0; -static triangleVertexArray *theVertexArray = NULL; -static int fillTheVertexArray = 0; -static int useTheVertexArray = 0; +static Surface *theSurface = NULL; void draw_polygon_2d(double r, double g, double b, int n, double *x, double *y, double *z) @@ -224,33 +222,35 @@ void Draw_Mesh_Volume(void *a, void *b) void Draw_Mesh_Surface(void *a, void *b) { Surface *s = *(Surface **) a; - theColor = s->Color; - thePhysical = getFirstPhysical(MSH_PHYSICAL_SURFACE, s->Num); if(!(s->Visible & VIS_MESH)) return; - if(CTX.mesh.vertex_arrays && Tree_Nbr(s->Simplexes)){ + theSurface = s; + theColor = s->Color; + thePhysical = getFirstPhysical(MSH_PHYSICAL_SURFACE, s->Num); + + if(CTX.mesh.vertex_arrays){ if(CTX.mesh.changed){ Msg(DEBUG, "regenerate mesh vertex array"); if(s->vertexArray) delete s->vertexArray; s->vertexArray = new triangleVertexArray(Tree_Nbr(s->Simplexes)); - theVertexArray = s->vertexArray; - fillTheVertexArray = 1; - useTheVertexArray = 1; + s->vertexArray->fill = 1; Tree_Action(s->Simplexes, Draw_Mesh_Triangle); - fillTheVertexArray = 0; + if(s->vertexArray) + s->vertexArray->fill = 0; } - if(s->vertexArray && useTheVertexArray) + if(s->vertexArray) Draw_Mesh_Triangle_Array(s->vertexArray); } - fillTheVertexArray = 0; // just to make sure... - if(!useTheVertexArray || CTX.mesh.dual || - CTX.mesh.surfaces_num || CTX.mesh.normals){ + if(!s->vertexArray || CTX.mesh.dual || CTX.mesh.surfaces_num || CTX.mesh.normals){ + Msg(DEBUG, "classic triangle data path"); Tree_Action(s->Simplexes, Draw_Mesh_Triangle); } - + Tree_Action(s->Quadrangles, Draw_Mesh_Quadrangle); + + theSurface = NULL; } void Draw_Mesh_Extruded_Surfaces(void *a, void *b) @@ -520,7 +520,11 @@ void Draw_Mesh_Triangle(void *a, void *b) Z[i] = Zc + CTX.mesh.explode * (s->V[i]->Pos.Z - Zc); } if(s->VSUP){ - useTheVertexArray = 0; + if(theSurface && theSurface->vertexArray){ + // vertex arrays not implemented for second order elements + delete theSurface->vertexArray; + theSurface->vertexArray = NULL; + } for(int i = 0; i < 3; i++) { X2[i] = Xc + CTX.mesh.explode * (s->VSUP[i]->Pos.X - Xc); Y2[i] = Yc + CTX.mesh.explode * (s->VSUP[i]->Pos.Y - Yc); @@ -528,34 +532,36 @@ void Draw_Mesh_Triangle(void *a, void *b) } } - if(CTX.mesh.normals || CTX.mesh.light || fillTheVertexArray) + if(CTX.mesh.normals || CTX.mesh.light || + (theSurface && theSurface->vertexArray && theSurface->vertexArray->fill)) _normal3points(X[0], Y[0], Z[0], X[1], Y[1], Z[1], X[2], Y[2], Z[2], n); - if(fillTheVertexArray && !s->VSUP){ - for(int i = 0; i < 3; i++) { - float x = X[i], y = Y[i], z = Z[i]; - float n0 = n[0], n1 = n[1], n2 = n[2]; - unsigned char r = UNPACK_RED(col); - unsigned char g = UNPACK_GREEN(col); - unsigned char b = UNPACK_BLUE(col); - unsigned char a = UNPACK_ALPHA(col); - List_Add(theVertexArray->vertices, &x); - List_Add(theVertexArray->vertices, &y); - List_Add(theVertexArray->vertices, &z); - List_Add(theVertexArray->normals, &n0); - List_Add(theVertexArray->normals, &n1); - List_Add(theVertexArray->normals, &n2); - List_Add(theVertexArray->colors, &r); - List_Add(theVertexArray->colors, &g); - List_Add(theVertexArray->colors, &b); - List_Add(theVertexArray->colors, &a); + if(theSurface && theSurface->vertexArray){ + if(theSurface->vertexArray->fill){ + for(int i = 0; i < 3; i++) { + float x = X[i], y = Y[i], z = Z[i]; + float n0 = n[0], n1 = n[1], n2 = n[2]; + unsigned char r = UNPACK_RED(col); + unsigned char g = UNPACK_GREEN(col); + unsigned char b = UNPACK_BLUE(col); + unsigned char a = UNPACK_ALPHA(col); + List_Add(theSurface->vertexArray->vertices, &x); + List_Add(theSurface->vertexArray->vertices, &y); + List_Add(theSurface->vertexArray->vertices, &z); + List_Add(theSurface->vertexArray->normals, &n0); + List_Add(theSurface->vertexArray->normals, &n1); + List_Add(theSurface->vertexArray->normals, &n2); + List_Add(theSurface->vertexArray->colors, &r); + List_Add(theSurface->vertexArray->colors, &g); + List_Add(theSurface->vertexArray->colors, &b); + List_Add(theSurface->vertexArray->colors, &a); + } + theSurface->vertexArray->num_triangles++; } - theVertexArray->num_triangles++; } - - if(!useTheVertexArray){ + else{ if(CTX.mesh.surfaces_edges){ if(CTX.mesh.surfaces_faces) glColor4ubv((GLubyte *) & CTX.color.mesh.line); diff --git a/Graphics/Post.cpp b/Graphics/Post.cpp index 552b576caf..2c26bf37f6 100644 --- a/Graphics/Post.cpp +++ b/Graphics/Post.cpp @@ -1,4 +1,4 @@ -// $Id: Post.cpp,v 1.63 2004-05-29 11:08:32 geuzaine Exp $ +// $Id: Post.cpp,v 1.64 2004-05-29 20:25:29 geuzaine Exp $ // // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // @@ -447,34 +447,37 @@ void Draw_Post(void) Draw_TensorList(v, ValMin, ValMax, v->TL, v->NbTL, 2, Draw_TensorLine); } - for(int p = 0; p < 2; p++){ // two-passes for vertex arrays + for(int pass = 0; pass < 2; pass++){ int skip_2d = 0, skip_3d = 0; - if(p == 0){ + if(pass == 0){ if(CTX.post.vertex_arrays){ if(v->Changed){ Msg(DEBUG, "regenerate View[%d] vertex array", v->Index); if(v->VertexArray) delete v->VertexArray; v->VertexArray = new triangleVertexArray(10000); - v->FillVertexArray = 1; + v->VertexArray->fill = 1; + goto pass_0; } - else - goto pass2; } - else - goto pass2; + goto pass_1; } - if(p == 1){ - if(CTX.post.vertex_arrays && v->VertexArray){ - v->UseVertexArray = 1; + else{ + // don't even enter the classic data path if we don't have to + if(v->VertexArray){ if(v->Boundary < 1 && !v->ShowElement && - v->IntervalsType != DRAW_POST_NUMERIC && v->IntervalsType != DRAW_POST_ISO) + v->IntervalsType != DRAW_POST_NUMERIC && v->IntervalsType != DRAW_POST_ISO){ + Msg(DEBUG, "Skiping 2D scalar pass alltogether!"); skip_2d = 1; + } if(v->Boundary < 2 && !v->ShowElement && - v->IntervalsType != DRAW_POST_NUMERIC && v->IntervalsType != DRAW_POST_ISO) + v->IntervalsType != DRAW_POST_NUMERIC && v->IntervalsType != DRAW_POST_ISO){ + Msg(DEBUG, "Skiping 3D scalar pass alltogether!"); skip_3d = 1; + } } } + pass_0: if(v->DrawTriangles) { if(!skip_2d) Draw_ScalarList(v, ValMin, ValMax, v->ST, v->NbST, 3, 1, Draw_ScalarTriangle); @@ -512,37 +515,35 @@ void Draw_Post(void) Draw_TensorList(v, ValMin, ValMax, v->TY, v->NbTY, 5, Draw_TensorPyramid); } - pass2: - v->FillVertexArray = 0; - v->UseVertexArray = 0; + pass_1: + if(v->VertexArray) + v->VertexArray->fill = 0; } - if(CTX.post.vertex_arrays && v->VertexArray){ - if(v->VertexArray->num_triangles){ + if(v->VertexArray && v->VertexArray->num_triangles){ - if(CTX.alpha && ColorTable_IsAlpha(&v->CT) && (changedEye() || v->Changed)){ - Msg(DEBUG, "Sorting for transparency (WITH vertex array)"); - v->VertexArray->sort(storedEye); - } - - glVertexPointer(3, GL_FLOAT, 0, v->VertexArray->vertices->array); - glNormalPointer(GL_FLOAT, 0, v->VertexArray->normals->array); - glColorPointer(4, GL_UNSIGNED_BYTE, 0, v->VertexArray->colors->array); - - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); - glEnableClientState(GL_NORMAL_ARRAY); - - if(v->Light) - glEnable(GL_LIGHTING); - else - glDisableClientState(GL_NORMAL_ARRAY); - glEnable(GL_POLYGON_OFFSET_FILL); - glDrawArrays(GL_TRIANGLES, 0, 3 * v->VertexArray->num_triangles); - glDisable(GL_POLYGON_OFFSET_FILL); - glDisable(GL_LIGHTING); + if(CTX.alpha && ColorTable_IsAlpha(&v->CT) && (changedEye() || v->Changed)){ + Msg(DEBUG, "Sorting for transparency (WITH vertex array)"); + v->VertexArray->sort(storedEye); } + glVertexPointer(3, GL_FLOAT, 0, v->VertexArray->vertices->array); + glNormalPointer(GL_FLOAT, 0, v->VertexArray->normals->array); + glColorPointer(4, GL_UNSIGNED_BYTE, 0, v->VertexArray->colors->array); + + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); + glEnableClientState(GL_NORMAL_ARRAY); + + if(v->Light) + glEnable(GL_LIGHTING); + else + glDisableClientState(GL_NORMAL_ARRAY); + glEnable(GL_POLYGON_OFFSET_FILL); + glDrawArrays(GL_TRIANGLES, 0, 3 * v->VertexArray->num_triangles); + glDisable(GL_POLYGON_OFFSET_FILL); + glDisable(GL_LIGHTING); + glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); diff --git a/Graphics/PostElement.cpp b/Graphics/PostElement.cpp index 140e79dade..6b897f937c 100644 --- a/Graphics/PostElement.cpp +++ b/Graphics/PostElement.cpp @@ -1,4 +1,4 @@ -// $Id: PostElement.cpp,v 1.31 2004-05-29 10:11:12 geuzaine Exp $ +// $Id: PostElement.cpp,v 1.32 2004-05-29 20:25:29 geuzaine Exp $ // // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // @@ -393,7 +393,8 @@ void Draw_ScalarTriangle(Post_View * View, int preproNormals, for(int k = 0; k < 3; k++) Raise[i][k] = View->Raise[i] * Val[k]; - if(!View->UseVertexArray && View->Light || View->FillVertexArray) { + if(View->Light && + (!View->VertexArray || (View->VertexArray && View->VertexArray->fill))) { x1x0 = (X[1] + Raise[0][1]) - (X[0] + Raise[0][0]); y1y0 = (Y[1] + Raise[1][1]) - (Y[0] + Raise[1][0]); z1z0 = (Z[1] + Raise[2][1]) - (Z[0] + Raise[2][0]); @@ -452,11 +453,12 @@ void Draw_ScalarTriangle(Post_View * View, int preproNormals, } } - if(!View->UseVertexArray && View->IntervalsType == DRAW_POST_CONTINUOUS) { + if(View->IntervalsType == DRAW_POST_CONTINUOUS && + (!View->VertexArray || (View->VertexArray && View->VertexArray->fill))) { if(Val[0] >= ValMin && Val[0] <= ValMax && Val[1] >= ValMin && Val[1] <= ValMax && Val[2] >= ValMin && Val[2] <= ValMax) { - if(View->FillVertexArray){ + if(View->VertexArray && View->VertexArray->fill){ unsigned int col; col = PaletteContinuous(View, ValMin, ValMax, Val[0]); View->VertexArray->add(X[0] + Raise[0][0], Y[0] + Raise[1][0], Z[0] + Raise[2][0], @@ -490,7 +492,7 @@ void Draw_ScalarTriangle(Post_View * View, int preproNormals, else { CutTriangle2D(X, Y, Z, Val, ValMin, ValMax, Xp, Yp, Zp, &nb, value); if(nb >= 3) { - if(View->FillVertexArray){ + if(View->VertexArray && View->VertexArray->fill){ for(int i = 2; i < nb; i++) { unsigned int col; col = PaletteContinuous(View, ValMin, ValMax, value[0]); @@ -529,7 +531,8 @@ void Draw_ScalarTriangle(Post_View * View, int preproNormals, } } - if(!View->UseVertexArray && View->IntervalsType == DRAW_POST_DISCRETE) { + if(View->IntervalsType == DRAW_POST_DISCRETE && + (!View->VertexArray || (View->VertexArray && View->VertexArray->fill))) { for(int k = 0; k < View->NbIso; k++) { unsigned int col = PaletteDiscrete(View, View->NbIso, k); CutTriangle2D(X, Y, Z, Val, @@ -537,7 +540,7 @@ void Draw_ScalarTriangle(Post_View * View, int preproNormals, View->GVFI(ValMin, ValMax, View->NbIso + 1, k + 1), Xp, Yp, Zp, &nb, value); if(nb >= 3) { - if(View->FillVertexArray){ + if(View->VertexArray && View->VertexArray->fill){ for(int i = 2; i < nb; i++) { View->VertexArray->add(Xp[0] + View->Raise[0] * value[0], Yp[0] + View->Raise[1] * value[0], @@ -643,7 +646,7 @@ void Draw_ScalarTetrahedron(Post_View * View, int preproNormals, Draw_String(Num); } } - else if(!View->UseVertexArray){ + else if(!View->VertexArray || (View->VertexArray && View->VertexArray->fill)){ for(int k = 0; k < View->NbIso; k++) { unsigned int col = PaletteDiscrete(View, View->NbIso, k); IsoSimplex(View, preproNormals, X, Y, Z, Val, -- GitLab