From 88d02011195354c5af801e5afc39b6126c86088b Mon Sep 17 00:00:00 2001
From: vigmond <ed.vigmond@gmail.com>
Date: Sun, 18 Oct 2020 11:32:14 +0200
Subject: [PATCH] more fixing of vertices and visibility

---
 src/TBmeshWin.cc | 49 ++++++++++++++++++++++++++++--------------------
 src/TBmeshWin.h  |  2 +-
 src/trimesh.fl   | 17 +++++++++--------
 3 files changed, 39 insertions(+), 29 deletions(-)

diff --git a/src/TBmeshWin.cc b/src/TBmeshWin.cc
index 6ae7449..2c6449b 100644
--- a/src/TBmeshWin.cc
+++ b/src/TBmeshWin.cc
@@ -273,18 +273,17 @@ void TBmeshWin :: draw()
 
       RRegion *reg = model->region(revDrawOrder ? model->_numReg-s-1 : s);
 
-      if ( !reg->visible() ) continue;
-
       model->pt.setVis(&reg->pt_membership());
 
       if ( reg->show(Cnnx) && model->_cnnx->num() )
         draw_cnnx(reg);
-      if ( reg->show(Vertex) || renderMode==GL_SELECT )
-        draw_vertices(reg, s==model->_numReg-1);
+
+      draw_vertices(reg, false);
 
       if ( renderMode == GL_RENDER )
         draw_cut_planes( reg );
     }
+    draw_vertices(NULL, true);
   }
 
   if ( renderMode == GL_RENDER ){
@@ -565,12 +564,21 @@ void TBmeshWin::draw_cnnx(RRegion* sf)
  */
 void TBmeshWin::draw_vertices(RRegion* reg, bool last )
 {
-  static bool first = true;    //!< first visible region since last redraw?
-  PPoint &pt = model->pt;
-  static int numTrans = 0;
+  static bool  first    = true;    //!< first visible region since last redraw?
+  PPoint      &pt       = model->pt;
+  static int   numTrans = 0;
   vector<bool> draw_vert;
 
   if ( renderMode==GL_RENDER ) {
+
+    if( last ) {
+      if( !first && _rd_pt.num() ) _rd_pt.update_nodalbuff();
+      _rd_pt.opaque( _rd_pt.num()-numTrans );
+      _rd_pt.mesh_render();
+      first = true;
+      return;
+    }
+
     pt.threeD( reg->threeD(Vertex) );
     pt.size( reg->size(Vertex) );
     dataOpac &dop = dataopac->dop[Vertex];
@@ -578,7 +586,6 @@ void TBmeshWin::draw_vertices(RRegion* reg, bool last )
     bool update =_rd_pt.setup_render_data(context());
     update |= REDRAW(VBO_Pt_Color|VBO_Pt|VBO_Position) || (REDRAW(VBO_Colour) && datadst&Vertex_flg) ||
               (REDRAW(VBO_Visible)) ;
-    _rd_pt.radius(pt.size());
     if( update || _rd_pt.dirty() ) {
       if( !_draw_all_vert ) trim_vertices( draw_vert, reg->show(Cnnx) );
       if( first ) {
@@ -586,21 +593,29 @@ void TBmeshWin::draw_vertices(RRegion* reg, bool last )
         first = false;
         numTrans = 0;
       }
+      
+      if( !reg->show(Vertex) || !reg->visible()) return;
+      
+      _rd_pt.radius(pt.size());
       _rd_pt.threeD( reg->threeD(Vertex) );
       int nvis = pt.buffer( _rd_pt, 0, pt.num()-1, reg->get_color(Vertex), cs, datadst&Vertex_flg?data:NULL, 1, &dop );
       if( translucent ) {
         numTrans += nvis;
-      } else {
-        if( numTrans ) _rd_pt.buff_rotate(nvis);  // move last opaque elements to the beginning of the buffer
+      } else if( numTrans ) {
+        _rd_pt.buff_rotate(nvis);  // move just drawn opaque elements to the beginning of the buffer
       }
     }
+
+  } else {                                       // GL_SELECT
+
     if( last ) {
-      if( !first && _rd_pt.num() ) _rd_pt.update_nodalbuff();
-      _rd_pt.opaque( _rd_pt.num()-numTrans );
-      _rd_pt.mesh_render();
+      _select.update_nodalbuff();
+      _rd_pt.opaque(-1);
+      _select.mesh_render();
       first = true;
+      return;
     }
-  } else {                                       // GL_SELECT
+
     _select.setup_render_data(context());
     if( !_draw_all_vert ) trim_vertices( draw_vert, reg->show(Cnnx) );
     if( first ) {
@@ -611,12 +626,6 @@ void TBmeshWin::draw_vertices(RRegion* reg, bool last )
     _select.buff_append( count(pt.vis()->begin(), pt.vis()->end(), true) );
     for ( int i=0; i<model->pt.num(); i++ )
       if ( pt.vis(i) ) _select.buff_vtx( bp++, pt[i], i );
-    if( last ) {
-      _select.update_nodalbuff();
-      _rd_pt.opaque(-1);
-      _select.mesh_render();
-      first = true;
-    }
   }
 }
 
diff --git a/src/TBmeshWin.h b/src/TBmeshWin.h
index 11d27bf..2659668 100644
--- a/src/TBmeshWin.h
+++ b/src/TBmeshWin.h
@@ -70,7 +70,7 @@ class TBmeshWin:public Fl_Gl_Tb_Window
     inline void set_hilight( bool a ){ hilighton=a; redraw(a?VBO_Hilight:VBO_None); }
     inline void dispmode( Display_t d ){ disp = d; redraw(); }
     inline Display_t dispmode(void){ return disp; }
-    void showobj( Object_t o, bool *r, bool a ){model->showobj(o,r,a);redraw();}
+    void showobj( Object_t o, bool *r, bool a ){model->showobj(o,r,a);redraw(VBO_Visible);}
     inline bool showobj( Object_t o, int s ){ return model->showobj(o,s);}
     GLfloat* get_color( Object_t obj, int s );
     void set_color( Object_t, int, float, float, float, float );
diff --git a/src/trimesh.fl b/src/trimesh.fl
index 8cbddad..2ae4b57 100644
--- a/src/trimesh.fl
+++ b/src/trimesh.fl
@@ -14,6 +14,9 @@ decl {\#include<list>} {public global
 decl {\#include <algorithm>} {private local
 }
 
+decl {\#include<memory>} {private local
+}
+
 decl {class TBmeshWin;} {public local
 }
 
@@ -842,13 +845,12 @@ cc=pickcolor(VolEle, "Voxele colour",cc);}
       } {
         Fl_Light_Button vertbut {
           label Vertices
-          callback {bool *selreg = regselected();
-mwtb->showobj(Vertex,selreg,static_cast<bool>(o->value()));
+          callback {unique_ptr<bool> selreg (regselected());
+mwtb->showobj(Vertex,selreg.get(),static_cast<bool>(o->value()));
 if(o->value())
   pickvert->activate();
 else
-  pickvert->deactivate();
-free(selreg);}
+  pickvert->deactivate();} selected
           xywh {160 145 75 25} when 1
         }
         Fl_Light_Button cnnxbut {
@@ -914,7 +916,7 @@ reglist->do_callback();}
         xywh {10 270 330 260} align 0
       } {
         Fl_Group hilightgrp {
-          label Highlight selected
+          label Highlight
           xywh {10 305 330 225} color 11 labelfont 1 labelsize 12 labelcolor 121 align 4
         } {
           Fl_Value_Input tethi {
@@ -2217,8 +2219,7 @@ lightorient->spinOnly(true);} {}
   }
   decl {ObjProps *objprops[maxobject];} {private local
   }
-  Function {add_recent(  char *fn, DATA_SET_TYPE dst )} {open
-  } {
+  Function {add_recent(  char *fn, DATA_SET_TYPE dst )} {} {
     code {for( auto &p : recentLst )  
   if( p.first==fn ) {
    recentLst.remove( p );
@@ -3128,7 +3129,7 @@ class ObjProps {open
   Function {ObjProps( TBmeshWin* wtb, Object_t o ):mwtb(wtb),obj(o)} {open
   } {
     Fl_Window win {open
-      xywh {939 466 220 245} type Single box ENGRAVED_BOX visible
+      xywh {939 466 220 245} type Single box ENGRAVED_BOX hide
     } {
       Fl_Check_Button thrD {
         label {3D }
-- 
GitLab