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.8 by gwlarson, Tue Oct 6 18:16:54 1998 UTC vs.
Revision 3.10 by gwlarson, Mon Dec 28 18:07:35 1998 UTC

# Line 47 | Line 47 | static QT_LUENT        *qt_htbl = NULL;        /* quadtree cache */
47   static int      qt_hsiz = 0;            /* quadtree cache size */
48  
49  
50 <
51 < mark_active_tris(qtptr,fptr)
52 < QUADTREE *qtptr;
53 < int *fptr;
54 < {
55 <  QUADTREE qt = *qtptr;
56 <  OBJECT *os,*optr;
57 <  register int i,t_id;
58 <  TRI *tri;
59 <
60 <
61 <  if(!QT_FLAG_FILL_TRI(*fptr))
62 <     (*fptr)++;
63 <
64 <  if(QT_IS_EMPTY(qt) || QT_LEAF_IS_FLAG(qt))
65 <    return;
66 <  /* For each triangle in the set, set the which flag*/
67 <  os = qtqueryset(qt);
68 <
69 <  for (i = QT_SET_CNT(os), optr = QT_SET_PTR(os); i > 0; i--)
70 <  {
71 <    t_id = QT_SET_NEXT_ELEM(optr);
72 <    /* Set the render flag */
73 <    tri = SM_NTH_TRI(smMesh,t_id);
74 <    if(!T_IS_VALID(tri) || SM_IS_NTH_T_BASE(smMesh,t_id))
75 <        continue;
76 <    SM_SET_NTH_T_ACTIVE(smMesh,t_id);
77 <    /* Set the Active bits of the Vertices */
78 <    S_SET_FLAG(T_NTH_V(tri,0));
79 <    S_SET_FLAG(T_NTH_V(tri,1));
80 <    S_SET_FLAG(T_NTH_V(tri,2));
81 <
82 <  }
83 < }
84 <
85 < #define mark_active_interior mark_active_tris
86 <
87 < mark_tris_in_frustum(view)
88 < VIEW *view;
89 < {
90 <    FVECT nr[4],far[4];
91 <    FPEQ peq;
92 <    int debug=0;
93 <    /* Mark triangles in approx. view frustum as being active:set
94 <       LRU counter: for use in discarding samples when out
95 <       of space
96 <       Radiance often has no far clipping plane: but driver will set
97 <       dev_zmin,dev_zmax to satisfy OGL
98 <    */
99 <
100 <    /* First clear all the quadtree node and triangle active flags */
101 <    qtClearAllFlags();
102 <    smClear_flags(smMesh,T_ACTIVE_FLAG);
103 <    /* Clear all of the active sample flags*/
104 <    sClear_all_flags(smMesh->samples);
105 <
106 <
107 <    /* calculate the world space coordinates of the view frustum */
108 <    calculate_view_frustum(view->vp,view->hvec,view->vvec,view->horiz,
109 <                           view->vert, dev_zmin,dev_zmax,nr,far);
110 <
111 < #ifdef TEST_DRIVER
112 <    VCOPY(FrustumFar[0],far[0]);
113 <    VCOPY(FrustumFar[1],far[1]);
114 <    VCOPY(FrustumFar[2],far[2]);
115 <    VCOPY(FrustumFar[3],far[3]);
116 <    VCOPY(FrustumNear[0],nr[0]);
117 <    VCOPY(FrustumNear[1],nr[1]);
118 <    VCOPY(FrustumNear[2],nr[2]);
119 <    VCOPY(FrustumNear[3],nr[3]);
120 < #endif
121 <    /* Project the view frustum onto the spherical quadtree */
122 <    /* For every cell intersected by the projection of the faces
123 <
124 <       of the frustum: mark all triangles in the cell as ACTIVE-
125 <       Also set the triangles LRU clock counter
126 <       */
127 <    
128 <    if(EQUAL_VEC3(view->vp,SM_VIEW_CENTER(smMesh)))
129 <    {/* Near face triangles */
130 <      smLocator_apply_func(smMesh,nr[3],nr[2],nr[0],mark_active_tris,
131 <                         mark_active_interior,NULL);
132 <      smLocator_apply_func(smMesh,nr[1],nr[0],nr[2],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 < /*
234 < * smClean()            : display has been wiped clean
235 < *
236 < * Called after display has been effectively cleared, meaning that all
237 < * geometry must be resent down the pipeline in the next call to smUpdate().
238 < */
50 > /*
51 >  * smClean()           : display has been wiped clean
52 >  *
53 >  * Called after display has been effectively cleared, meaning that all
54 >  * geometry must be resent down the pipeline in the next call to smUpdate().
55 >  */
56   smClean()
57   {
58      smClean_notify = TRUE;
# Line 322 | Line 139 | register QUADTREE qt;
139      stCount_level_leaves(lcnt+1, QT_NTH_CHILD(qt,3));
140    }
141    else
142 <    lcnt[0]++;
142 >    if(QT_LEAF_IS_FLAG(qt))
143 >      lcnt[0]++;
144   }
145  
146  
# Line 342 | Line 160 | int lvl;
160      return(NULL);
161    if (QT_IS_TREE(qt) && !QT_IS_FLAG(qt))        /* not in our frustum */
162      return(NULL);
163 +  if(QT_IS_LEAF(qt)  && !QT_LEAF_IS_FLAG(qt))   /* not in our frustum */
164 +    return(NULL);
165                                          /* else look up node */
166    if ((le = qtCache_find(qt)) == NULL)
167      error(SYSTEM, "out of memory in qtRender_level");
# Line 378 | Line 198 | int lvl;
198        os = qtqueryset(qt);
199        for (n = os[0]; n; n--)
200        {
201 +        if(SM_IS_NTH_T_BASE(sm,os[n]))
202 +           continue;
203          tri = SM_NTH_TRI(sm,os[n]);
204          if(!T_IS_VALID(tri))
205            continue;
206 <
206 >        
207          s0 = T_NTH_V(tri,0);
208          s1 = T_NTH_V(tri,1);
209          s2 = T_NTH_V(tri,2);
# Line 419 | Line 241 | int lvl;
241      VSUM(c,SM_VIEW_CENTER(sm),c,le->av.dist);
242                                          /* draw triangle */
243      glColor3ub(le->av.rgb[0],le->av.rgb[1],le->av.rgb[2]);
422    /* NOTE: Triangle vertex order may change */
423    glVertex3d(c[0],c[1],c[2]);
424    glVertex3d(b[0],b[1],b[2]);
244      glVertex3d(a[0],a[1],a[2]);
245 +    glVertex3d(b[0],b[1],b[2]);
246 +    glVertex3d(c[0],c[1],c[2]);
247 +
248    }
249    return(&le->av);
250   }
# Line 432 | Line 254 | smRender_stree_level(sm,lvl)
254   SM *sm;
255   int lvl;
256   {
257 <  QUADTREE root;
257 >  QUADTREE qt;
258    int i;
259    FVECT t0,t1,t2;
260    STREE *st;
# Line 446 | Line 268 | int lvl;
268    glBegin(GL_TRIANGLES);
269    for(i=0; i < ST_NUM_ROOT_NODES; i++)
270    {
271 <    root = ST_NTH_ROOT(st,i);
272 <    qtRender_level(root,ST_NTH_V(st,i,0),ST_NTH_V(st,i,1),ST_NTH_V(st,i,2),
271 >    qt = ST_ROOT_QT(st,i);
272 >    qtRender_level(qt,ST_NTH_V(st,i,0),ST_NTH_V(st,i,1),ST_NTH_V(st,i,2),
273                     sm,lvl-1);
274    }
275    glEnd();
# Line 461 | Line 283 | int qual;
283   {
284    int i, ntarget;
285    int lvlcnt[QT_MAX_LEVELS];
286 +  STREE *st;
287  
288    if (qual <= 0)
289      return;
# Line 473 | Line 296 | int qual;
296      return;
297    for (i = QT_MAX_LEVELS; i--; )
298      lvlcnt[i] = 0;
299 <  stCount_level_leaves(lvlcnt, ST_TOP_ROOT(SM_LOCATOR(sm)));
300 <  stCount_level_leaves(lvlcnt, ST_BOTTOM_ROOT(SM_LOCATOR(sm)));  
299 >  
300 >  st = SM_LOCATOR(sm);
301 >  for(i=0; i < ST_NUM_ROOT_NODES;i++)
302 >    stCount_level_leaves(lvlcnt, ST_ROOT_QT(st,i));
303 >  
304    for (ntarget -= lvlcnt[i=0]; i < QT_MAX_LEVELS-1; ntarget -= lvlcnt[++i])
305      if (ntarget < lvlcnt[i+1])
306        break;
# Line 495 | Line 321 | int clr;
321  
322    tri = SM_NTH_TRI(sm,i);
323    if (clr) SM_CLR_NTH_T_NEW(sm,i);
324 <
499 <  /* NOTE:Triangles are defined clockwise:historical relative to spherical
500 <     tris: could change
501 <     */
502 <  for(j=2; j>= 0; j--)
324 >  for(j=0; j <= 2; j++)
325    {
326   #ifdef DEBUG
327      if(SM_BG_SAMPLE(sm,T_NTH_V(tri,j)))
# Line 550 | Line 372 | int clr;
372      rgb[0]/=cnt; rgb[1]/=cnt; rgb[2]/=cnt;
373      d /= (double)cnt;
374    }
375 <  for(j=2; j>= 0; j--)
375 >  for(j=0; j <= 2; j++)
376    {
377      if(SM_BG_SAMPLE(sm,ids[j]))
378      {
# Line 588 | Line 410 | int clr;
410    /* NOTE:Triangles are defined clockwise:historical relative to spherical
411       tris: could change
412       */
413 <  for(j=2; j>= 0; j--)
413 >  for(j=0; j <= 2; j++)
414    {
415        id = T_NTH_V(tri,j);
416        glColor3ub(SM_NTH_RGB(sm,id)[0],SM_NTH_RGB(sm,id)[1],
# Line 628 | Line 450 | int clr;
450    glBegin(GL_TRIANGLES);
451    SM_FOR_ALL_ACTIVE_FG_TRIS(sm,i)
452    {
631      if(SM_BG_TRI(sm,i))
632         continue;
453        if(!SM_MIXED_TRI(sm,i))
454          smRender_tri(sm,i,vp,clr);
455     else
# Line 651 | Line 471 | int i;
471  
472    tri = SM_NTH_TRI(sm,i);
473  
474 <  /* Triangles are defined clockwise:historical relative to spherical
655 <     tris: could change
656 <     */
657 <  for(j=2; j >=0; j--)
474 >  for(j=0; j <= 2; j++)
475    {
476      VCOPY(ptr,SM_NTH_WV(sm,T_NTH_V(tri,j)));
477      glVertex3d(ptr[0],ptr[1],ptr[2]);
# Line 758 | Line 575 | int clr;
575  
576    /* Turn Depth Test off -- using Painter's algorithm */
577    glPushAttrib(GL_DEPTH_BUFFER_BIT);
578 <  glDisable(GL_DEPTH_TEST);
578 >  glDepthFunc(GL_ALWAYS);
579    d = (dev_zmin+dev_zmax)/2.0;
580    /* Now render back-to front */
581    /* First render bg triangles */
# Line 808 | Line 625 | smUpdate(view,qual)
625  
626    if(!smMesh)
627      return;
628 +
629 +
630 +
631    d = DIST(view->vp,SM_VIEW_CENTER(smMesh));
632    if(qual >= 100 && d > SM_ALLOWED_VIEW_CHANGE(smMesh))
633    {
# Line 830 | Line 650 | smUpdate(view,qual)
650      {
651         tmClearHisto();
652         tmAddHisto(SM_BRT(smMesh),SM_NUM_SAMP(smMesh),1);
653 <       if(tmComputeMapping(0.,0.,0.) != TM_E_OK ||
654 <                   tmMapPixels(SM_RGB(smMesh),SM_BRT(smMesh),SM_CHR(smMesh),
655 <                                SM_NUM_SAMP(smMesh)) != TM_E_OK)
836 <            return;
653 >       tmComputeMapping(0.,0.,0.);
654 >       tmMapPixels(SM_RGB(smMesh),SM_BRT(smMesh),SM_CHR(smMesh),
655 >                   SM_NUM_SAMP(smMesh));
656      }
657   #endif
658      mark_tris_in_frustum(view);
# Line 862 | Line 681 | smUpdate(view,qual)
681          if(tmComputeMapping(0.,0.,0.) != TM_E_OK)
682             return;
683      }
684 <    if(tmMapPixels(SM_NTH_RGB(smMesh,t),&SM_NTH_BRT(smMesh,t),
685 <                   SM_NTH_CHR(smMesh,t), SM_NUM_SAMP(smMesh)-t) != TM_E_OK)
686 <          return;
684 >    tmMapPixels(SM_NTH_RGB(smMesh,t),&SM_NTH_BRT(smMesh,t),
685 >                   SM_NTH_CHR(smMesh,t), SM_NUM_SAMP(smMesh)-t);
686 >        
687   #endif    
688      smUpdate_Rendered_mesh(smMesh,view->vp,last_update);
689      
# Line 872 | Line 691 | smUpdate(view,qual)
691      glDrawBuffer(GL_BACK);
692   #endif
693    }
694 +
695    SM_TONE_MAP(smMesh) = SM_NUM_SAMP(smMesh);
696 +
697    if (last_update)
698    {
699      smClean_notify = FALSE;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines