ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/sm_ogl.c
(Generate patch)

Comparing ray/src/hd/sm_ogl.c (file contents):
Revision 3.3 by gwlarson, Thu Sep 3 08:14:29 1998 UTC vs.
Revision 3.9 by gwlarson, Wed Nov 11 12:05:39 1998 UTC

# Line 16 | Line 16 | static char SCCSid[] = "$SunId$ SGI";
16   #include <GL/glu.h>
17   #include <glut.h>
18   #endif
19 < #include "object.h"
19 > #include "sm_flag.h"
20   #include "sm_list.h"
21   #include "sm_geom.h"
22 + #include "sm_qtree.h"
23 + #include "sm_stree.h"
24   #include "sm.h"
23 #include "lookup.h"
25  
26   #ifdef TEST_DRIVER
27   #include "sm_draw.h"
# Line 29 | Line 30 | MAKE STATIC LATER: ui.c using for now;
30   */
31   char smClean_notify = TRUE;
32   #else
33 < static char smClean_notify = TRUE;
33 > static int smClean_notify = TRUE;
34   #endif
35  
35 extern unsigned long qthash();
36 extern int qtcmp();
37 extern int free();
38
39 static LUTAB qtr_tab = {qthash,qtcmp,NULL,(void (*)())free,0,NULL,0};
40
36   typedef struct {
42        BYTE    rgb[3];         /* average color */
37          float   dist;           /* average distance */
38 +        BYTE    rgb[3];         /* average color */
39   } QTRAVG;               /* average quadtree value */
40  
41 + typedef struct {
42 +        QUADTREE        qt;     /* quadtree node (key & hash value) */
43 +        QTRAVG          av;     /* node average */
44 + } QT_LUENT;             /* lookup table entry */
45  
46 < unsigned long
47 < qthash(qtc)                     /* hash a quadtree node value */
49 < char *qtc;
50 < {
51 <    register unsigned long qt = qtc;
46 > static QT_LUENT *qt_htbl = NULL;        /* quadtree cache */
47 > static int      qt_hsiz = 0;            /* quadtree cache size */
48  
53    return(qt>>10 ^ qt<<5);
54 }
49  
56 int
57 qtcmp(qt1, qt2)
58 char *qt1, *qt2;
59 {
60    return(qt1 - qt2);
61 }
50  
51 <
64 < int
65 < mark_active_tris(qtptr,arg)
51 > mark_active_tris(qtptr,fptr)
52   QUADTREE *qtptr;
53 < char *arg;
53 > int *fptr;
54   {
55    QUADTREE qt = *qtptr;
56 <  OBJECT os[QT_MAX_SET+1],*optr;
56 >  OBJECT *os,*optr;
57    register int i,t_id;
58 +  TRI *tri;
59  
60 <  if (!QT_IS_LEAF(qt))
61 <    return(TRUE);
60 >  if(!QT_FLAG_FILL_TRI(*fptr))
61 >     (*fptr)++;
62 >  if(QT_IS_EMPTY(qt) || QT_LEAF_IS_FLAG(qt))
63 >    return;
64 >
65    /* For each triangle in the set, set the which flag*/
66 <  qtgetset(os,qt);
66 >  os = qtqueryset(qt);
67  
68    for (i = QT_SET_CNT(os), optr = QT_SET_PTR(os); i > 0; i--)
69    {
70      t_id = QT_SET_NEXT_ELEM(optr);
71      /* Set the render flag */
72 <    if(SM_IS_NTH_T_BASE(smMesh,t_id))
72 >    tri = SM_NTH_TRI(smMesh,t_id);
73 >    if(!T_IS_VALID(tri) || SM_IS_NTH_T_BASE(smMesh,t_id))
74          continue;
75      SM_SET_NTH_T_ACTIVE(smMesh,t_id);
76 <    /* FOR NOW:Also set the LRU clock bit: MAY WANT TO CHANGE: */      
77 <    SM_SET_NTH_T_LRU(smMesh,t_id);
76 >    /* Set the Active bits of the Vertices */
77 >    S_SET_FLAG(T_NTH_V(tri,0));
78 >    S_SET_FLAG(T_NTH_V(tri,1));
79 >    S_SET_FLAG(T_NTH_V(tri,2));
80 >
81    }
88  return(TRUE);
82   }
83  
84 + #define mark_active_interior mark_active_tris
85 +
86   mark_tris_in_frustum(view)
87   VIEW *view;
88   {
89      FVECT nr[4],far[4];
90 <
90 >    FPEQ peq;
91 >    int debug=0;
92      /* Mark triangles in approx. view frustum as being active:set
93         LRU counter: for use in discarding samples when out
94         of space
# Line 103 | Line 99 | VIEW *view;
99      /* First clear all the quadtree node and triangle active flags */
100      qtClearAllFlags();
101      smClear_flags(smMesh,T_ACTIVE_FLAG);
102 +    /* Clear all of the active sample flags*/
103 +    sClear_all_flags(SM_SAMP(smMesh));
104  
105 +
106      /* calculate the world space coordinates of the view frustum */
107      calculate_view_frustum(view->vp,view->hvec,view->vvec,view->horiz,
108                             view->vert, dev_zmin,dev_zmax,nr,far);
109  
111    /* Project the view frustum onto the spherical quadtree */
112    /* For every cell intersected by the projection of the faces
113       of the frustum: mark all triangles in the cell as ACTIVE-
114       Also set the triangles LRU clock counter
115       */
116    /* Near face triangles */
117    smLocator_apply_func(smMesh,nr[0],nr[2],nr[3],mark_active_tris,NULL);
118    smLocator_apply_func(smMesh,nr[2],nr[0],nr[1],mark_active_tris,NULL);
119    /* Right face triangles */
120    smLocator_apply_func(smMesh,nr[0],far[3],far[0],mark_active_tris,NULL);
121    smLocator_apply_func(smMesh,far[3],nr[0],nr[3],mark_active_tris,NULL);
122    /* Left face triangles */
123    smLocator_apply_func(smMesh,nr[1],far[2],nr[2],mark_active_tris,NULL);
124    smLocator_apply_func(smMesh,far[2],nr[1],far[1],mark_active_tris,NULL);
125    /* Top face triangles */
126    smLocator_apply_func(smMesh,nr[0],far[0],nr[1],mark_active_tris,NULL);
127    smLocator_apply_func(smMesh,nr[1],far[0],far[1],mark_active_tris,NULL);
128    /* Bottom face triangles */
129    smLocator_apply_func(smMesh,nr[3],nr[2],far[3],mark_active_tris,NULL);
130    smLocator_apply_func(smMesh,nr[2],far[2],far[3],mark_active_tris,NULL);
131    /* Far face triangles */
132    smLocator_apply_func(smMesh,far[0],far[2],far[1],mark_active_tris,NULL);
133    smLocator_apply_func(smMesh,far[2],far[0],far[3],mark_active_tris,NULL);
134
110   #ifdef TEST_DRIVER
111      VCOPY(FrustumFar[0],far[0]);
112      VCOPY(FrustumFar[1],far[1]);
# Line 142 | Line 117 | VIEW *view;
117      VCOPY(FrustumNear[2],nr[2]);
118      VCOPY(FrustumNear[3],nr[3]);
119   #endif
120 +    /* Project the view frustum onto the spherical quadtree */
121 +    /* For every cell intersected by the projection of the faces
122 +
123 +       of the frustum: mark all triangles in the cell as ACTIVE-
124 +       Also set the triangles LRU clock counter
125 +       */
126 +    
127 +    if(EQUAL_VEC3(view->vp,SM_VIEW_CENTER(smMesh)))
128 +    {/* Near face triangles */
129 +
130 +      smLocator_apply_func(smMesh,nr[0],nr[2],nr[3],mark_active_tris,
131 +                         mark_active_interior,NULL);
132 +      smLocator_apply_func(smMesh,nr[2],nr[0],nr[1],mark_active_tris,
133 +                         mark_active_interior,NULL);
134 +      return;
135 +    }
136 +
137 +    /* Test the view against the planes: and swap orientation if inside:*/
138 +    tri_plane_equation(nr[0],nr[2],nr[3], &peq,FALSE);
139 +    if(PT_ON_PLANE(SM_VIEW_CENTER(smMesh),peq) < 0.0)
140 +    {/* Near face triangles */
141 +      smLocator_apply_func(smMesh,nr[3],nr[2],nr[0],mark_active_tris,
142 +                           mark_active_interior,NULL);
143 +      smLocator_apply_func(smMesh,nr[1],nr[0],nr[2],mark_active_tris,
144 +                         mark_active_interior,NULL);
145 +    }
146 +    else
147 +    {/* Near face triangles */
148 +      smLocator_apply_func(smMesh,nr[0],nr[2],nr[3],mark_active_tris,
149 +                           mark_active_interior,NULL);
150 +      smLocator_apply_func(smMesh,nr[2],nr[0],nr[1],mark_active_tris,
151 +                         mark_active_interior,NULL);
152 +    }
153 +    tri_plane_equation(nr[0],far[3],far[0], &peq,FALSE);
154 +    if(PT_ON_PLANE(SM_VIEW_CENTER(smMesh),peq) < 0.0)
155 +    { /* Right face triangles */
156 +      smLocator_apply_func(smMesh,far[0],far[3],nr[0],mark_active_tris,
157 +                           mark_active_interior,NULL);
158 +      smLocator_apply_func(smMesh,nr[3],nr[0],far[3],mark_active_tris,
159 +                           mark_active_interior,NULL);
160 +    }
161 +    else
162 +    {/* Right face triangles */
163 +      smLocator_apply_func(smMesh,nr[0],far[3],far[0],mark_active_tris,
164 +                           mark_active_interior,NULL);
165 +      smLocator_apply_func(smMesh,far[3],nr[0],nr[3],mark_active_tris,
166 +                           mark_active_interior,NULL);
167 +    }
168 +
169 +    tri_plane_equation(nr[1],far[2],nr[2], &peq,FALSE);
170 +    if(PT_ON_PLANE(SM_VIEW_CENTER(smMesh),peq) < 0.0)
171 +    { /* Left face triangles */
172 +      smLocator_apply_func(smMesh,nr[2],far[2],nr[1],mark_active_tris,
173 +                           mark_active_interior,NULL);
174 +      smLocator_apply_func(smMesh,far[1],nr[1],far[2],mark_active_tris,
175 +                           mark_active_interior,NULL);  
176 +    }
177 +    else
178 +    { /* Left face triangles */
179 +      smLocator_apply_func(smMesh,nr[1],far[2],nr[2],mark_active_tris,
180 +                           mark_active_interior,NULL);
181 +      smLocator_apply_func(smMesh,far[2],nr[1],far[1],mark_active_tris,
182 +                   mark_active_interior,NULL);
183 +
184 +    }
185 +    tri_plane_equation(nr[0],far[0],nr[1], &peq,FALSE);
186 +    if(PT_ON_PLANE(SM_VIEW_CENTER(smMesh),peq) < 0.0)
187 +    {/* Top face triangles */
188 +      smLocator_apply_func(smMesh,nr[1],far[0],nr[0],mark_active_tris,
189 +                           mark_active_interior,NULL);
190 +      smLocator_apply_func(smMesh,far[1],far[0],nr[1],mark_active_tris,
191 +                           mark_active_interior,NULL);
192 +    }
193 +    else
194 +    {/* Top face triangles */
195 +      smLocator_apply_func(smMesh,nr[0],far[0],nr[1],mark_active_tris,
196 +                           mark_active_interior,NULL);
197 +      smLocator_apply_func(smMesh,nr[1],far[0],far[1],mark_active_tris,
198 +                           mark_active_interior,NULL);
199 +    }
200 +    tri_plane_equation(nr[3],nr[2],far[3], &peq,FALSE);
201 +    if(PT_ON_PLANE(SM_VIEW_CENTER(smMesh),peq) < 0.0)
202 +    {/* Bottom face triangles */
203 +      smLocator_apply_func(smMesh,far[3],nr[2],nr[3],mark_active_tris,
204 +                           mark_active_interior,NULL);
205 +      smLocator_apply_func(smMesh,far[3],far[2],nr[2],mark_active_tris,
206 +                           mark_active_interior,NULL);
207 +    }
208 +    else
209 +    { /* Bottom face triangles */
210 +      smLocator_apply_func(smMesh,nr[3],nr[2],far[3],mark_active_tris,
211 +                           mark_active_interior,NULL);
212 +      smLocator_apply_func(smMesh,nr[2],far[2],far[3],mark_active_tris,
213 +                           mark_active_interior,NULL);
214 +    }
215 +     tri_plane_equation(far[2],far[0],far[1], &peq,FALSE);
216 +    if(PT_ON_PLANE(SM_VIEW_CENTER(smMesh),peq) < 0.0)
217 +    {/* Far face triangles */
218 +      smLocator_apply_func(smMesh,far[0],far[2],far[1],mark_active_tris,
219 +                           mark_active_interior,NULL);
220 +      smLocator_apply_func(smMesh,far[2],far[0],far[3],mark_active_tris,
221 +                           mark_active_interior,NULL);
222 +    }
223 +    else
224 +    {/* Far face triangles */
225 +      smLocator_apply_func(smMesh,far[1],far[2],far[0],mark_active_tris,
226 +                           mark_active_interior,NULL);
227 +      smLocator_apply_func(smMesh,far[3],far[0],far[2],mark_active_tris,
228 +                           mark_active_interior,NULL);
229 +    }
230 +
231   }
232  
233   /*
# Line 155 | Line 241 | smClean()
241      smClean_notify = TRUE;
242   }
243  
244 + int
245 + qtCache_init(nel)               /* initialize for at least nel elements */
246 + int     nel;
247 + {
248 +        static int  hsiztab[] = {
249 +                8191, 16381, 32749, 65521, 131071, 262139, 524287, 1048573, 0
250 +        };
251 +        register int  i;
252  
253 +        if (nel <= 0) {                 /* call to free table */
254 +                if (qt_hsiz) {
255 +                        free((char *)qt_htbl);
256 +                        qt_htbl = NULL;
257 +                        qt_hsiz = 0;
258 +                }
259 +                return(0);
260 +        }
261 +        nel += nel>>1;                  /* 66% occupancy */
262 +        for (i = 0; hsiztab[i]; i++)
263 +                if (hsiztab[i] > nel)
264 +                        break;
265 +        if (!(qt_hsiz = hsiztab[i]))
266 +                qt_hsiz = nel*2 + 1;            /* not always prime */
267 +        qt_htbl = (QT_LUENT *)calloc(qt_hsiz, sizeof(QT_LUENT));
268 +        if (qt_htbl == NULL)
269 +                qt_hsiz = 0;
270 +        for (i = qt_hsiz; i--; )
271 +                qt_htbl[i].qt = EMPTY;
272 +        return(qt_hsiz);
273 + }
274 +
275 + QT_LUENT *
276 + qtCache_find(qt)                /* find a quadtree table entry */
277 + QUADTREE qt;
278 + {
279 +        int     i, n;
280 +        register int    ndx;
281 +        register QT_LUENT       *le;
282 +
283 +        if (qt_hsiz == 0 && !qtCache_init(1))
284 +                return(NULL);
285 + tryagain:                               /* hash table lookup */
286 +        ndx = (unsigned long)qt % qt_hsiz;
287 +        for (i = 0, n = 1; i < qt_hsiz; i++, n += 2) {
288 +                le = &qt_htbl[ndx];
289 +                if (QT_IS_EMPTY(le->qt) || le->qt == qt)
290 +                        return(le);
291 +                if ((ndx += n) >= qt_hsiz)      /* this happens rarely */
292 +                        ndx = ndx % qt_hsiz;
293 +        }
294 +                                        /* table is full, reallocate */
295 +        le = qt_htbl;
296 +        ndx = qt_hsiz;
297 +        if (!qtCache_init(ndx+1)) {     /* no more memory! */
298 +                qt_htbl = le;
299 +                qt_hsiz = ndx;
300 +                return(NULL);
301 +        }
302 +                                        /* copy old table to new and free */
303 +        while (ndx--)
304 +                if (!QT_IS_EMPTY(le[ndx].qt))
305 +                        copystruct(qtCache_find(le[ndx].qt), &le[ndx]);
306 +        free((char *)le);
307 +        goto tryagain;                  /* should happen only once! */
308 + }
309 +
310   stCount_level_leaves(lcnt, qt)  /* count quadtree leaf nodes at each level */
311   int lcnt[];
312   register QUADTREE qt;
# Line 183 | Line 334 | SM *sm;
334   int lvl;
335   {
336    FVECT a,b,c;
337 <  LUENT *le;
337 >  register QT_LUENT *le;
338    QTRAVG *rc[4];
339 <  register QTRAVG *ra;
339 >  TRI *tri;
340    
341    if (QT_IS_EMPTY(qt))                          /* empty leaf node */
342      return(NULL);
343    if (QT_IS_TREE(qt) && !QT_IS_FLAG(qt))        /* not in our frustum */
344      return(NULL);
345                                          /* else look up node */
346 <  if ((le = lu_find(&qtr_tab,(char *)qt)) == NULL)
347 <    goto nomemory;
348 <  ra = (QTRAVG *)le->data;
198 <  if (QT_IS_TREE(qt) && (ra == NULL || lvl > 0))
346 >  if ((le = qtCache_find(qt)) == NULL)
347 >    error(SYSTEM, "out of memory in qtRender_level");
348 >  if (QT_IS_TREE(qt) && (QT_IS_EMPTY(le->qt) || lvl > 0))
349    {                                     /* compute children */
350      qtSubdivide_tri(v0,v1,v2,a,b,c);
351      rc[0] = qtRender_level(QT_NTH_CHILD(qt,0),v0,a,c,sm,lvl-1);
# Line 203 | Line 353 | int lvl;
353      rc[2] = qtRender_level(QT_NTH_CHILD(qt,2),c,b,v2,sm,lvl-1);
354      rc[3] = qtRender_level(QT_NTH_CHILD(qt,3),b,c,a,sm,lvl-1);
355    }
356 <  if (ra == NULL)
356 >  if (QT_IS_EMPTY(le->qt))
357    {                                     /* let's make some data! */
358      int rgbs[3];
359      double distsum;
360 <    int i;
211 <    register int n;
360 >    register int i, n;
361                                          /* average our triangle vertices */
362      rgbs[0] = rgbs[1] = rgbs[2] = 0;
363      distsum = 0.; n = 0;
364      if(QT_IS_TREE(qt))
365      {                                   /* from subtree */
366        for (i = 4; i--; )
367 <        if ((ra = rc[i]) != NULL)
367 >        if (rc[i] != NULL)
368          {
369 <          rgbs[0] += ra->rgb[0]; rgbs[1] += ra->rgb[1]; rgbs[2] += ra->rgb[2];
370 <          distsum += ra->dist; n++;
369 >          rgbs[0] += rc[i]->rgb[0]; rgbs[1] += rc[i]->rgb[1];
370 >          rgbs[2] += rc[i]->rgb[2]; distsum += rc[i]->dist; n++;
371          }
372      }
373      else
374      {                                   /* from triangle set */
375 <      OBJECT os[QT_MAX_SET+1];
375 >      OBJECT *os;
376        int s0, s1, s2;
377  
378 <      qtgetset(os,qt);
378 >      os = qtqueryset(qt);
379        for (n = os[0]; n; n--)
380        {
381 <        qtTri_from_id(os[n],a,b,c,NULL,NULL,NULL,&s0,&s1,&s2);
381 >        if(SM_IS_NTH_T_BASE(sm,os[n]))
382 >           continue;
383 >        tri = SM_NTH_TRI(sm,os[n]);
384 >        if(!T_IS_VALID(tri))
385 >          continue;
386 >        
387 >        s0 = T_NTH_V(tri,0);
388 >        s1 = T_NTH_V(tri,1);
389 >        s2 = T_NTH_V(tri,2);
390 >        VCOPY(a,SM_NTH_WV(sm,s0));
391 >        VCOPY(b,SM_NTH_WV(sm,s1));
392 >        VCOPY(c,SM_NTH_WV(sm,s2));            
393          distsum += SM_BG_SAMPLE(sm,s0) ? dev_zmax
394                                  : sqrt(dist2(a,SM_VIEW_CENTER(sm)));
395          distsum += SM_BG_SAMPLE(sm,s1) ? dev_zmax
# Line 247 | Line 407 | int lvl;
407      }
408      if (!n)
409        return(NULL);
410 <    if ((ra = (QTRAVG *)malloc(sizeof(QTRAVG))) == NULL)
411 <      goto nomemory;
412 <    ra->rgb[0] = rgbs[0]/n; ra->rgb[1] = rgbs[1]/n; ra->rgb[2] = rgbs[2]/n;
253 <    ra->dist = distsum/(double)n;
254 <    le->key = (char *)qt;
255 <    le->data = (char *)ra;
410 >    le->qt = qt;
411 >    le->av.rgb[0] = rgbs[0]/n; le->av.rgb[1] = rgbs[1]/n;
412 >    le->av.rgb[2] = rgbs[2]/n; le->av.dist = distsum/(double)n;
413    }
414    if (lvl == 0 || (lvl > 0 && QT_IS_LEAF(qt)))
415    {                             /* render this node */
416                                          /* compute pseudo vertices */
417      VCOPY(a,v0); VCOPY(b,v1); VCOPY(c,v2);
418      normalize(a); normalize(b); normalize(c);
419 <    VSUM(a,SM_VIEW_CENTER(sm),a,ra->dist);
420 <    VSUM(b,SM_VIEW_CENTER(sm),b,ra->dist);
421 <    VSUM(c,SM_VIEW_CENTER(sm),c,ra->dist);
419 >    VSUM(a,SM_VIEW_CENTER(sm),a,le->av.dist);
420 >    VSUM(b,SM_VIEW_CENTER(sm),b,le->av.dist);
421 >    VSUM(c,SM_VIEW_CENTER(sm),c,le->av.dist);
422                                          /* draw triangle */
423 <    glColor3ub(ra->rgb[0],ra->rgb[1],ra->rgb[2]);
267 <    /* NOTE: Triangle vertex order may change */
268 <    glVertex3d(c[0],c[1],c[2]);
269 <    glVertex3d(b[0],b[1],b[2]);
423 >    glColor3ub(le->av.rgb[0],le->av.rgb[1],le->av.rgb[2]);
424      glVertex3d(a[0],a[1],a[2]);
425 +    glVertex3d(b[0],b[1],b[2]);
426 +    glVertex3d(c[0],c[1],c[2]);
427 +
428    }
429 <  return(ra);
273 < nomemory:
274 <  error(SYSTEM, "out of memory in qtRender_level");
429 >  return(&le->av);
430   }
431  
432  
# Line 282 | Line 437 | int lvl;
437    QUADTREE root;
438    int i;
439    FVECT t0,t1,t2;
440 +  STREE *st;
441  
442 +  
443    if (lvl < 1)
444      return;
445 +  st = SM_LOCATOR(sm);
446    glPushAttrib(GL_LIGHTING_BIT);
447    glShadeModel(GL_FLAT);
448    glBegin(GL_TRIANGLES);
449 <  for(i=0; i < 4; i++)
449 >  for(i=0; i < ST_NUM_ROOT_NODES; i++)
450    {
451 <    root = ST_NTH_ROOT(SM_LOCATOR(sm),i);
452 <    stNth_base_verts(SM_LOCATOR(sm),i,t0,t1,t2);
453 <    qtRender_level(root,t0,t1,t2,sm,lvl-1);
451 >    root = ST_NTH_ROOT(st,i);
452 >    qtRender_level(root,ST_NTH_V(st,i,0),ST_NTH_V(st,i,1),ST_NTH_V(st,i,2),
453 >                   sm,lvl-1);
454    }
455    glEnd();
456    glPopAttrib();
# Line 317 | Line 475 | int qual;
475      return;
476    for (i = QT_MAX_LEVELS; i--; )
477      lvlcnt[i] = 0;
478 <  stCount_level_leaves(lvlcnt, SM_LOCATOR(sm)->root);
478 >  stCount_level_leaves(lvlcnt, ST_TOP_ROOT(SM_LOCATOR(sm)));
479 >  stCount_level_leaves(lvlcnt, ST_BOTTOM_ROOT(SM_LOCATOR(sm)));  
480    for (ntarget -= lvlcnt[i=0]; i < QT_MAX_LEVELS-1; ntarget -= lvlcnt[++i])
481      if (ntarget < lvlcnt[i+1])
482        break;
# Line 337 | Line 496 | int clr;
496    int j;
497  
498    tri = SM_NTH_TRI(sm,i);
499 <  if (clr) SM_CLEAR_NTH_T_NEW(sm,i);
500 <
342 <  /* NOTE:Triangles are defined clockwise:historical relative to spherical
343 <     tris: could change
344 <     */
345 <  for(j=2; j>= 0; j--)
499 >  if (clr) SM_CLR_NTH_T_NEW(sm,i);
500 >  for(j=0; j <= 2; j++)
501    {
502   #ifdef DEBUG
503      if(SM_BG_SAMPLE(sm,T_NTH_V(tri,j)))
# Line 368 | Line 523 | int clr;
523    int rgb[3];
524  
525    tri = SM_NTH_TRI(sm,i);
526 <  if (clr) SM_CLEAR_NTH_T_NEW(sm,i);
526 >  if (clr) SM_CLR_NTH_T_NEW(sm,i);
527  
528    /* NOTE:Triangles are defined clockwise:historical relative to spherical
529       tris: could change
# Line 393 | Line 548 | int clr;
548      rgb[0]/=cnt; rgb[1]/=cnt; rgb[2]/=cnt;
549      d /= (double)cnt;
550    }
551 <  for(j=2; j>= 0; j--)
551 >  for(j=0; j <= 2; j++)
552    {
553      if(SM_BG_SAMPLE(sm,ids[j]))
554      {
# Line 426 | Line 581 | int clr;
581    TRI *tri;
582    
583    tri = SM_NTH_TRI(sm,i);
584 <  if (clr) SM_CLEAR_NTH_T_NEW(sm,i);
584 >  if (clr) SM_CLR_NTH_T_NEW(sm,i);
585  
586    /* NOTE:Triangles are defined clockwise:historical relative to spherical
587       tris: could change
588       */
589 <  for(j=2; j>= 0; j--)
589 >  for(j=0; j <= 2; j++)
590    {
591        id = T_NTH_V(tri,j);
592        glColor3ub(SM_NTH_RGB(sm,id)[0],SM_NTH_RGB(sm,id)[1],
# Line 462 | Line 617 | int clr;
617    glPushAttrib(GL_DEPTH_BUFFER_BIT);
618    
619    /* First draw background polygons */
465
620    glDisable(GL_DEPTH_TEST);
621    glBegin(GL_TRIANGLES);
622    SM_FOR_ALL_ACTIVE_BG_TRIS(sm,i)
623       smRender_bg_tri(sm,i,vp,d,clr);
624    glEnd();
471  
625    glEnable(GL_DEPTH_TEST);
626    glBegin(GL_TRIANGLES);
627    SM_FOR_ALL_ACTIVE_FG_TRIS(sm,i)
628    {
629        if(!SM_MIXED_TRI(sm,i))
630          smRender_tri(sm,i,vp,clr);
631 <     else
631 >   else
632          smRender_mixed_tri(sm,i,vp,clr);
633    }
634    glEnd();
# Line 494 | Line 647 | int i;
647  
648    tri = SM_NTH_TRI(sm,i);
649  
650 <  /* Triangles are defined clockwise:historical relative to spherical
498 <     tris: could change
499 <     */
500 <  for(j=2; j >=0; j--)
650 >  for(j=0; j <= 2; j++)
651    {
652      VCOPY(ptr,SM_NTH_WV(sm,T_NTH_V(tri,j)));
653      glVertex3d(ptr[0],ptr[1],ptr[2]);
# Line 541 | Line 691 | T_DEPTH *td;
691          continue;
692      }
693      tri = SM_NTH_TRI(sm,t_id);
694 + #ifdef DEBUG
695 +    if(i >= smNew_tri_cnt)
696 +    {
697 +      eputs("smDepth_sort_tris():More tris than reported by smNew_tri_cnt\n");
698 +      break;
699 +    }
700 + #endif
701      td[i].tri = t_id;
702      min_d = -1;
703      for(j=0;j < 3;j++)
# Line 594 | Line 751 | int clr;
751  
752    /* Turn Depth Test off -- using Painter's algorithm */
753    glPushAttrib(GL_DEPTH_BUFFER_BIT);
754 <  glDisable(GL_DEPTH_TEST);
754 >  glDepthFunc(GL_ALWAYS);
755    d = (dev_zmin+dev_zmax)/2.0;
756    /* Now render back-to front */
757    /* First render bg triangles */
# Line 603 | Line 760 | int clr;
760       smRender_bg_tri(sm,pop_list(&bglist),vp,d,clr);
761    glEnd();
762  
763 <  glEnable(GL_DEPTH_TEST);
763 >
764    glBegin(GL_TRIANGLES);
765    i=0;
766    while(td[i].tri != -1)
# Line 641 | Line 798 | smUpdate(view,qual)
798       epsilon is calculated as running avg of distance of sample points
799       from canonical view: m = 1/(AVG(1/r)): some fraction of this
800     */
801 +
802 +  if(!smMesh)
803 +    return;
804    d = DIST(view->vp,SM_VIEW_CENTER(smMesh));
805    if(qual >= 100 && d > SM_ALLOWED_VIEW_CHANGE(smMesh))
806    {
807        /* Re-build the mesh */
808   #ifdef TEST_DRIVER
809      odev.v = *view;
810 < #endif    
811 <      smRebuild_mesh(smMesh,view->vp);
810 > #endif  
811 >      mark_tris_in_frustum(view);
812 >      smRebuild_mesh(smMesh,view);
813    }
814    /* This is our final update iff qual==100 and view==&odev.v */
815    last_update = qual>=100 && view==&(odev.v);
816    /* Check if we should draw ALL triangles in current frustum */
817 <  if(smClean_notify || smNew_tri_cnt > SM_NUM_TRIS(smMesh)*SM_INC_PERCENT)
817 >  if(smClean_notify || smNew_tri_cnt > SM_SAMPLE_TRIS(smMesh)*SM_INC_PERCENT)
818    {
819   #ifdef TEST_DRIVER
820      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
821   #else
822 <    if (SM_TONE_MAP(smMesh) < SM_NUM_SAMP(smMesh))
822 >    if ( SM_TONE_MAP(smMesh) < SM_NUM_SAMP(smMesh))
823      {
824         tmClearHisto();
825         tmAddHisto(SM_BRT(smMesh),SM_NUM_SAMP(smMesh),1);
# Line 680 | Line 841 | smUpdate(view,qual)
841    }
842    /* Do an incremental update instead */
843    else
844 <  {  
845 <    if(!smNew_tri_cnt)
844 >  {
845 >      if(!smNew_tri_cnt)
846        return;
847   #ifdef TEST_DRIVER
848      glDrawBuffer(GL_FRONT);
# Line 704 | Line 865 | smUpdate(view,qual)
865      glDrawBuffer(GL_BACK);
866   #endif
867    }
868 +
869    SM_TONE_MAP(smMesh) = SM_NUM_SAMP(smMesh);
870 +
871    if (last_update)
872    {
873      smClean_notify = FALSE;
874      smNew_tri_cnt = 0;
875 <    lu_done(&qtr_tab);
875 >    smClear_flags(smMesh,T_NEW_FLAG);
876 >    qtCache_init(0);
877    }
878  
879   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines