Debian Codegraph @

debian/external_deps/fetk/sg/src/gl/draw.c

raw
1 /* $Id: draw.c,v 1.2 2000/10/27 15:21:40 mholst Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 2.2
6 * Copyright (C) 1995-1997 Brian Paul
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the Free
20 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 /*
24 * Draw points, lines, and polygons.
25 */
26
27
28 #ifdef DEBUG
29 # include <assert.h>
30 #endif
31 #include <math.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include "clip.h"
36 #include "context.h"
37 #include "draw.h"
38 #include "feedback.h"
39 #include "fog.h"
40 #include "light.h"
41 #include "lines.h"
42 #include "dlist.h"
43 #include "macros.h"
44 #include "matrix.h"
45 #include "pb.h"
46 #include "points.h"
47 #include "texture.h"
48 #include "types.h"
49 #include "vb.h"
50 #include "xform.h"
51
52
53
54 #ifdef DEBUG
55 # define ASSERT(X) assert(X)
56 #else
57 # define ASSERT(X)
58 #endif
59
60
61
62 #ifdef PROFILE
63 # define START_PROFILE \
64 { \
65 GLdouble t0 = gl_time();
66
67 # define END_PROFILE( TIMER, COUNTER, INCR ) \
68 TIMER += (gl_time() - t0); \
69 COUNTER += INCR; \
70 }
71 #else
72 # define START_PROFILE
73 # define END_PROFILE( TIMER, COUNTER, INCR )
74 #endif
75
76
77
78 /*
79 * Check if the global material has to be updated with info that was
80 * associated with a vertex via glMaterial.
81 */
82 static void update_material( GLcontext *ctx, GLuint i )
83 {
84 struct vertex_buffer *VB = ctx->VB;
85
86 if (VB->MaterialMask[i]) {
87 if (VB->MaterialMask[i] & FRONT_AMBIENT_BIT) {
88 COPY_4V( ctx->Light.Material[0].Ambient, VB->Material[i][0].Ambient );
89 }
90 if (VB->MaterialMask[i] & BACK_AMBIENT_BIT) {
91 COPY_4V( ctx->Light.Material[1].Ambient, VB->Material[i][1].Ambient );
92 }
93 if (VB->MaterialMask[i] & FRONT_DIFFUSE_BIT) {
94 COPY_4V( ctx->Light.Material[0].Diffuse, VB->Material[i][0].Diffuse );
95 }
96 if (VB->MaterialMask[i] & BACK_DIFFUSE_BIT) {
97 COPY_4V( ctx->Light.Material[1].Diffuse, VB->Material[i][1].Diffuse );
98 }
99 if (VB->MaterialMask[i] & FRONT_SPECULAR_BIT) {
100 COPY_4V( ctx->Light.Material[0].Specular, VB->Material[i][0].Specular );
101 }
102 if (VB->MaterialMask[i] & BACK_SPECULAR_BIT) {
103 COPY_4V( ctx->Light.Material[1].Specular, VB->Material[i][1].Specular );
104 }
105 if (VB->MaterialMask[i] & FRONT_EMISSION_BIT) {
106 COPY_4V( ctx->Light.Material[0].Emission, VB->Material[i][0].Emission );
107 }
108 if (VB->MaterialMask[i] & BACK_EMISSION_BIT) {
109 COPY_4V( ctx->Light.Material[1].Emission, VB->Material[i][1].Emission );
110 }
111 if (VB->MaterialMask[i] & FRONT_SHININESS_BIT) {
112 ctx->Light.Material[0].Shininess = VB->Material[i][0].Shininess;
113 }
114 if (VB->MaterialMask[i] & BACK_SHININESS_BIT) {
115 ctx->Light.Material[1].Shininess = VB->Material[i][1].Shininess;
116 }
117 if (VB->MaterialMask[i] & FRONT_INDEXES_BIT) {
118 ctx->Light.Material[0].AmbientIndex = VB->Material[i][0].AmbientIndex;
119 ctx->Light.Material[0].DiffuseIndex = VB->Material[i][0].DiffuseIndex;
120 ctx->Light.Material[0].SpecularIndex = VB->Material[i][0].SpecularIndex;
121 }
122 if (VB->MaterialMask[i] & BACK_INDEXES_BIT) {
123 ctx->Light.Material[1].AmbientIndex = VB->Material[i][1].AmbientIndex;
124 ctx->Light.Material[1].DiffuseIndex = VB->Material[i][1].DiffuseIndex;
125 ctx->Light.Material[1].SpecularIndex = VB->Material[i][1].SpecularIndex;
126 }
127 VB->MaterialMask[i] = 0; /* reset now */
128 }
129 }
130
131
132
133 /*
134 * Render a line segment from VB[v1] to VB[v2] when either one or both
135 * endpoints must be clipped.
136 */
137 static void render_clipped_line( GLcontext *ctx, GLuint v1, GLuint v2 )
138 {
139 GLfloat d;
140 GLfloat ndc_x, ndc_y, ndc_z;
141 GLuint provoking_vertex;
142 struct vertex_buffer *VB = ctx->VB;
143
144 /* which vertex dictates the color when flat shading: */
145 provoking_vertex = v2;
146
147 /*
148 * Clipping may introduce new vertices. New vertices will be stored
149 * in the vertex buffer arrays starting with location VB->Free. After
150 * we've rendered the line, these extra vertices can be overwritten.
151 */
152 VB->Free = VB_MAX;
153
154 /* Clip against user clipping planes */
155 if (ctx->Transform.AnyClip) {
156 GLuint orig_v1 = v1, orig_v2 = v2;
157 if (gl_userclip_line( ctx, &v1, &v2 )==0)
158 return;
159 /* Apply projection matrix: clip = Proj * eye */
160 if (v1!=orig_v1) {
161 TRANSFORM_POINT( VB->Clip[v1], ctx->ProjectionMatrix, VB->Eye[v1] );
162 }
163 if (v2!=orig_v2) {
164 TRANSFORM_POINT( VB->Clip[v2], ctx->ProjectionMatrix, VB->Eye[v2] );
165 }
166 }
167
168 /* Clip against view volume */
169 if (gl_viewclip_line( ctx, &v1, &v2 )==0)
170 return;
171
172 /* Transform from clip coords to ndc: ndc = clip / W */
173 ASSERT( VB->Clip[v1][3] != 0.0 );
174 d = 1.0F / VB->Clip[v1][3];
175 ndc_x = VB->Clip[v1][0] * d;
176 ndc_y = VB->Clip[v1][1] * d;
177 ndc_z = VB->Clip[v1][2] * d;
178
179 /* Map ndc coord to window coords. */
180 VB->Win[v1][0] = ndc_x * ctx->Viewport.Sx + ctx->Viewport.Tx;
181 VB->Win[v1][1] = ndc_y * ctx->Viewport.Sy + ctx->Viewport.Ty;
182 VB->Win[v1][2] = ndc_z * ctx->Viewport.Sz + ctx->Viewport.Tz;
183
184 /* Transform from clip coords to ndc: ndc = clip / W */
185 ASSERT( VB->Clip[v2][3] != 0.0 );
186 d = 1.0F / VB->Clip[v2][3];
187 ndc_x = VB->Clip[v2][0] * d;
188 ndc_y = VB->Clip[v2][1] * d;
189 ndc_z = VB->Clip[v2][2] * d;
190
191 /* Map ndc coord to window coords. */
192 VB->Win[v2][0] = ndc_x * ctx->Viewport.Sx + ctx->Viewport.Tx;
193 VB->Win[v2][1] = ndc_y * ctx->Viewport.Sy + ctx->Viewport.Ty;
194 VB->Win[v2][2] = ndc_z * ctx->Viewport.Sz + ctx->Viewport.Tz;
195
196 START_PROFILE
197 (*ctx->LineFunc)( ctx, v1, v2, provoking_vertex );
198 END_PROFILE( ctx->LineTime, ctx->LineCount, 1 )
199 }
200
201
202
203 /*
204 * Compute Z offsets for a polygon with plane defined by (A,B,C,D)
205 * D is not needed.
206 */
207 static void offset_polygon( GLcontext *ctx, GLfloat a, GLfloat b, GLfloat c )
208 {
209 GLfloat ac, bc, m;
210 GLfloat offset;
211
212 if (c<0.001F && c>-0.001F) {
213 /* to prevent underflow problems */
214 offset = 0.0F;
215 }
216 else {
217 ac = a / c;
218 bc = b / c;
219 if (ac<0.0F) ac = -ac;
220 if (bc<0.0F) bc = -bc;
221 m = MAX2( ac, bc );
222 /* m = sqrt( ac*ac + bc*bc ); */
223
224 offset = m * ctx->Polygon.OffsetFactor + ctx->Polygon.OffsetUnits;
225 }
226
227 ctx->PointZoffset = ctx->Polygon.OffsetPoint ? offset : 0.0F;
228 ctx->LineZoffset = ctx->Polygon.OffsetLine ? offset : 0.0F;
229 ctx->PolygonZoffset = ctx->Polygon.OffsetFill ? offset : 0.0F;
230 }
231
232
233
234 /*
235 * When glPolygonMode() is used to specify that the front/back rendering
236 * mode for polygons is not GL_FILL we end up calling this function.
237 */
238 static void unfilled_polygon( GLcontext *ctx,
239 GLuint n, GLuint vlist[],
240 GLuint pv, GLuint facing )
241 {
242 GLenum mode = facing ? ctx->Polygon.BackMode : ctx->Polygon.FrontMode;
243 struct vertex_buffer *VB = ctx->VB;
244
245 if (mode==GL_POINT) {
246 GLint i, j;
247 GLboolean edge;
248
249 if ( ctx->Primitive==GL_TRIANGLES
250 || ctx->Primitive==GL_QUADS
251 || ctx->Primitive==GL_POLYGON) {
252 edge = GL_FALSE;
253 }
254 else {
255 edge = GL_TRUE;
256 }
257
258 for (i=0;i<n;i++) {
259 j = vlist[i];
260 if (edge || VB->Edgeflag[j]) {
261 (*ctx->PointsFunc)( ctx, j, j );
262 }
263 }
264 }
265 else if (mode==GL_LINE) {
266 GLuint i, j0, j1;
267 GLboolean edge;
268
269 ctx->StippleCounter = 0;
270
271 if ( ctx->Primitive==GL_TRIANGLES
272 || ctx->Primitive==GL_QUADS
273 || ctx->Primitive==GL_POLYGON) {
274 edge = GL_FALSE;
275 }
276 else {
277 edge = GL_TRUE;
278 }
279
280 /* draw the edges */
281 for (i=0;i<n;i++) {
282 j0 = (i==0) ? vlist[n-1] : vlist[i-1];
283 j1 = vlist[i];
284 if (edge || VB->Edgeflag[j0]) {
285 START_PROFILE
286 (*ctx->LineFunc)( ctx, j0, j1, pv );
287 END_PROFILE( ctx->LineTime, ctx->LineCount, 1 )
288 }
289 }
290 }
291 else {
292 /* Fill the polygon */
293 GLuint j0, i;
294 j0 = vlist[0];
295 for (i=2;i<n;i++) {
296 START_PROFILE
297 (*ctx->TriangleFunc)( ctx, j0, vlist[i-1], vlist[i], pv );
298 END_PROFILE( ctx->PolygonTime, ctx->PolygonCount, 1 )
299 }
300 }
301 }
302
303
304 /*
305 * Compute signed area of the n-sided polgyon specified by vertices vb->Win[]
306 * and vertex list vlist[].
307 * A clockwise polygon will return a negative area.
308 * A counter-clockwise polygon will return a positive area.
309 */
310 static GLfloat polygon_area( const struct vertex_buffer *vb,
311 GLuint n, const GLuint vlist[] )
312 {
313 GLfloat area = 0.0F;
314 GLint i;
315 for (i=0;i<n;i++) {
316 /* area = sum of trapezoids */
317 GLuint j0 = vlist[i];
318 GLuint j1 = vlist[(i+1)%n];
319 GLfloat x0 = vb->Win[j0][0];
320 GLfloat y0 = vb->Win[j0][1];
321 GLfloat x1 = vb->Win[j1][0];
322 GLfloat y1 = vb->Win[j1][1];
323 GLfloat trapArea = (x0-x1)*(y0+y1); /* Note: no divide by two here! */
324 area += trapArea;
325 }
326 return area * 0.5F; /* divide by two now! */
327 }
328
329
330 /*
331 * Render a polygon in which doesn't have to be clipped.
332 * Input: n - number of vertices
333 * vlist - list of vertices in the polygon.
334 * odd_flag - if non-zero, reverse the orientation of the polygon
335 */
336 static void render_polygon( GLcontext *ctx,
337 GLuint n, GLuint vlist[], GLuint odd_flag )
338 {
339 struct vertex_buffer *VB = ctx->VB;
340 GLuint pv;
341
342 /* which vertex dictates the color when flat shading: */
343 pv = (ctx->Primitive==GL_POLYGON) ? vlist[0] : vlist[n-1];
344
345 /* Compute orientation of polygon, do cull test, offset, etc */
346 {
347 GLuint facing; /* 0=front, 1=back */
348 GLfloat area = polygon_area( VB, n, vlist );
349
350 if (area==0.0F) {
351 /* polygon has zero area, don't draw it */
352 return;
353 }
354
355 facing = (area<0.0F) ^ odd_flag ^ (ctx->Polygon.FrontFace==GL_CW);
356
357 if ((facing+1) & ctx->Polygon.CullBits) {
358 return; /* culled */
359 }
360
361 if (ctx->Polygon.OffsetAny) {
362 /* compute plane equation of polygon, apply offset */
363 GLuint j0 = vlist[0];
364 GLuint j1 = vlist[1];
365 GLuint j2 = vlist[2];
366 GLuint j3 = vlist[ (n==3) ? 0 : 3 ];
367 GLfloat ex = VB->Win[j1][0] - VB->Win[j3][0];
368 GLfloat ey = VB->Win[j1][1] - VB->Win[j3][1];
369 GLfloat ez = VB->Win[j1][2] - VB->Win[j3][2];
370 GLfloat fx = VB->Win[j2][0] - VB->Win[j0][0];
371 GLfloat fy = VB->Win[j2][1] - VB->Win[j0][1];
372 GLfloat fz = VB->Win[j2][2] - VB->Win[j0][2];
373 GLfloat a = ey*fz-ez*fy;
374 GLfloat b = ez*fx-ex*fz;
375 GLfloat c = ex*fy-ey*fx;
376 offset_polygon( ctx, a, b, c );
377 }
378
379 if (ctx->Light.Model.TwoSide) {
380 if (facing==1 && ctx->Light.Enabled) {
381 /* use back color or index */
382 VB->Color = VB->Bcolor;
383 VB->Index = VB->Bindex;
384 }
385 else {
386 /* use front color or index */
387 VB->Color = VB->Fcolor;
388 VB->Index = VB->Findex;
389 }
390 }
391
392 /* Render the polygon! */
393 if (ctx->Polygon.Unfilled) {
394 unfilled_polygon( ctx, n, vlist, pv, facing );
395 }
396 else {
397 /* Draw filled polygon as a triangle fan */
398 GLint i;
399 GLuint j0 = vlist[0];
400 for (i=2;i<n;i++) {
401 START_PROFILE
402 (*ctx->TriangleFunc)( ctx, j0, vlist[i-1], vlist[i], pv );
403 END_PROFILE( ctx->PolygonTime, ctx->PolygonCount, 1 )
404 }
405 }
406 }
407 }
408
409
410
411 /*
412 * Render a polygon in which at least one vertex has to be clipped.
413 * Input: n - number of vertices
414 * vlist - list of vertices in the polygon.
415 * odd_flag - if non-zero, reverse the orientation of the polygon
416 */
417 static void render_clipped_polygon( GLcontext *ctx,
418 GLuint n, GLuint vlist[], GLuint odd_flag )
419 {
420 GLuint pv;
421 struct vertex_buffer *VB = ctx->VB;
422 GLfloat (*win)[3] = VB->Win;
423
424 /* which vertex dictates the color when flat shading: */
425 pv = (ctx->Primitive==GL_POLYGON) ? vlist[0] : vlist[n-1];
426
427 /*
428 * Clipping may introduce new vertices. New vertices will be stored
429 * in the vertex buffer arrays starting with location VB->Free. After
430 * we've rendered the polygon, these extra vertices can be overwritten.
431 */
432 VB->Free = VB_MAX;
433
434 /* Clip against user clipping planes in eye coord space. */
435 if (ctx->Transform.AnyClip) {
436 GLfloat *proj = ctx->ProjectionMatrix;
437 GLuint i;
438 n = gl_userclip_polygon( ctx, n, vlist );
439 if (n<3)
440 return;
441 /* Transform vertices from eye to clip coordinates: clip = Proj * eye */
442 for (i=0;i<n;i++) {
443 GLuint j = vlist[i];
444 TRANSFORM_POINT( VB->Clip[j], proj, VB->Eye[j] );
445 }
446 }
447
448 /* Clip against view volume in clip coord space */
449 n = gl_viewclip_polygon( ctx, n, vlist );
450 if (n<3)
451 return;
452
453 /* Transform vertices from clip to ndc to window coords. */
454 /* ndc = clip / W window = viewport_mapping(ndc) */
455 /* Note that window Z values are scaled to the range of integer */
456 /* depth buffer values. */
457 {
458 GLfloat sx = ctx->Viewport.Sx;
459 GLfloat tx = ctx->Viewport.Tx;
460 GLfloat sy = ctx->Viewport.Sy;
461 GLfloat ty = ctx->Viewport.Ty;
462 GLfloat sz = ctx->Viewport.Sz;
463 GLfloat tz = ctx->Viewport.Tz;
464 GLuint i;
465 for (i=0;i<n;i++) {
466 GLuint j = vlist[i];
467 GLfloat d;
468 ASSERT( VB->Clip[j][3] != 0.0 );
469 d = 1.0F / VB->Clip[j][3];
470 win[j][0] = VB->Clip[j][0] * d * sx + tx;
471 win[j][1] = VB->Clip[j][1] * d * sy + ty;
472 win[j][2] = VB->Clip[j][2] * d * sz + tz;
473 }
474 }
475
476 /* Compute orientation of polygon, do cull test, offset, etc */
477 {
478 GLuint facing; /* 0=front, 1=back */
479 GLfloat area = polygon_area( VB, n, vlist );
480
481 if (area==0.0F) {
482 /* polygon has zero area, don't draw it */
483 return;
484 }
485
486 facing = (area<0.0F) ^ odd_flag ^ (ctx->Polygon.FrontFace==GL_CW);
487
488 if ((facing+1) & ctx->Polygon.CullBits) {
489 return; /* culled */
490 }
491
492 if (ctx->Polygon.OffsetAny) {
493 /* compute plane equation of polygon, apply offset */
494 GLuint j0 = vlist[0];
495 GLuint j1 = vlist[1];
496 GLuint j2 = vlist[2];
497 GLuint j3 = vlist[ (n==3) ? 0 : 3 ];
498 GLfloat ex = win[j1][0] - win[j3][0];
499 GLfloat ey = win[j1][1] - win[j3][1];
500 GLfloat ez = win[j1][2] - win[j3][2];
501 GLfloat fx = win[j2][0] - win[j0][0];
502 GLfloat fy = win[j2][1] - win[j0][1];
503 GLfloat fz = win[j2][2] - win[j0][2];
504 GLfloat a = ey*fz-ez*fy;
505 GLfloat b = ez*fx-ex*fz;
506 GLfloat c = ex*fy-ey*fx;
507 offset_polygon( ctx, a, b, c );
508 }
509
510 if (ctx->Light.Model.TwoSide) {
511 if (facing==1 && ctx->Light.Enabled) {
512 /* use back color or index */
513 VB->Color = VB->Bcolor;
514 VB->Index = VB->Bindex;
515 }
516 else {
517 /* use front color or index */
518 VB->Color = VB->Fcolor;
519 VB->Index = VB->Findex;
520 }
521 }
522
523 /* Render the polygon! */
524 if (ctx->Polygon.Unfilled) {
525 unfilled_polygon( ctx, n, vlist, pv, facing );
526 }
527 else {
528 /* Draw filled polygon as a triangle fan */
529 GLint i;
530 GLuint j0 = vlist[0];
531 for (i=2;i<n;i++) {
532 START_PROFILE
533 (*ctx->TriangleFunc)( ctx, j0, vlist[i-1], vlist[i], pv );
534 END_PROFILE( ctx->PolygonTime, ctx->PolygonCount, 1 )
535 }
536 }
537 }
538 }
539
540
541
542 /*
543 * Render an un-clipped triangle.
544 */
545 static void render_triangle( GLcontext *ctx,
546 GLuint v0, GLuint v1, GLuint v2, GLuint pv,
547 GLuint odd_flag )
548 {
549 struct vertex_buffer *VB = ctx->VB;
550 GLfloat ex, ey, fx, fy, c;
551 GLuint facing; /* 0=front, 1=back */
552
553 /* Compute orientation of triangle */
554 ex = VB->Win[v1][0] - VB->Win[v0][0];
555 ey = VB->Win[v1][1] - VB->Win[v0][1];
556 fx = VB->Win[v2][0] - VB->Win[v0][0];
557 fy = VB->Win[v2][1] - VB->Win[v0][1];
558 c = ex*fy-ey*fx;
559
560 if (c==0.0F) {
561 /* polygon is perpindicular to view plane, don't draw it */
562 return;
563 }
564
565 facing = (c<0.0F) ^ odd_flag ^ (ctx->Polygon.FrontFace==GL_CW);
566
567 if ((facing+1) & ctx->Polygon.CullBits) {
568 return; /* culled */
569 }
570
571 if (ctx->Polygon.OffsetAny) {
572 /* finish computing plane equation of polygon, compute offset */
573 GLfloat fz = VB->Win[v2][2] - VB->Win[v0][2];
574 GLfloat ez = VB->Win[v1][2] - VB->Win[v0][2];
575 GLfloat a = ey*fz-ez*fy;
576 GLfloat b = ez*fx-ex*fz;
577 offset_polygon( ctx, a, b, c );
578 }
579
580 if (ctx->Light.Model.TwoSide) {
581 if (facing==1 && ctx->Light.Enabled) {
582 /* use back color or index */
583 VB->Color = VB->Bcolor;
584 VB->Index = VB->Bindex;
585 }
586 else {
587 /* use front color or index */
588 VB->Color = VB->Fcolor;
589 VB->Index = VB->Findex;
590 }
591 }
592
593 if (ctx->Polygon.Unfilled) {
594 GLuint vlist[3];
595 vlist[0] = v0;
596 vlist[1] = v1;
597 vlist[2] = v2;
598 unfilled_polygon( ctx, 3, vlist, pv, facing );
599 }
600 else {
601 START_PROFILE
602 (*ctx->TriangleFunc)( ctx, v0, v1, v2, pv );
603 END_PROFILE( ctx->PolygonTime, ctx->PolygonCount, 1 )
604 }
605 }
606
607
608
609 /*
610 * Render an un-clipped quadrilateral.
611 */
612 static void render_quad( GLcontext *ctx,
613 GLuint v0, GLuint v1, GLuint v2, GLuint v3,
614 GLuint pv, GLuint odd_flag )
615 {
616 struct vertex_buffer *VB = ctx->VB;
617 GLfloat ex, ey, fx, fy, c;
618 GLuint facing; /* 0=front, 1=back */
619
620 /* Compute polygon orientation */
621 ex = VB->Win[v2][0] - VB->Win[v0][0];
622 ey = VB->Win[v2][1] - VB->Win[v0][1];
623 fx = VB->Win[v3][0] - VB->Win[v1][0];
624 fy = VB->Win[v3][1] - VB->Win[v1][1];
625 c = ex*fy-ey*fx;
626
627 if (c==0.0F) {
628 /* polygon is perpindicular to view plane, don't draw it */
629 return;
630 }
631
632 facing = (c<0.0F) ^ odd_flag ^ (ctx->Polygon.FrontFace==GL_CW);
633
634 if ((facing+1) & ctx->Polygon.CullBits) {
635 return; /* culled */
636 }
637
638 if (ctx->Polygon.OffsetAny) {
639 /* finish computing plane equation of polygon, compute offset */
640 GLfloat ez = VB->Win[v2][2] - VB->Win[v0][2];
641 GLfloat fz = VB->Win[v3][2] - VB->Win[v1][2];
642 GLfloat a = ey*fz-ez*fy;
643 GLfloat b = ez*fx-ex*fz;
644 offset_polygon( ctx, a, b, c );
645 }
646
647 if (ctx->Light.Model.TwoSide) {
648 if (facing==1 && ctx->Light.Enabled) {
649 /* use back color or index */
650 VB->Color = VB->Bcolor;
651 VB->Index = VB->Bindex;
652 }
653 else {
654 /* use front color or index */
655 VB->Color = VB->Fcolor;
656 VB->Index = VB->Findex;
657 }
658 }
659
660 /* Render the quad! */
661 if (ctx->Polygon.Unfilled) {
662 GLuint vlist[4];
663 vlist[0] = v0;
664 vlist[1] = v1;
665 vlist[2] = v2;
666 vlist[3] = v3;
667 unfilled_polygon( ctx, 4, vlist, pv, facing );
668 }
669 else {
670 START_PROFILE
671 (*ctx->TriangleFunc)( ctx, v0, v1, v3, pv );
672 (*ctx->TriangleFunc)( ctx, v1, v2, v3, pv );
673 END_PROFILE( ctx->PolygonTime, ctx->PolygonCount, 2 )
674 }
675 }
676
677
678
679 /*
680 * When the vertex buffer is full, we transform/render it. Sometimes we
681 * have to copy the last vertex (or two) to the front of the vertex list
682 * to "continue" the primitive. For example: line or triangle strips.
683 * This function is a helper for that.
684 */
685 static void copy_vertex( struct vertex_buffer *vb, GLuint dst, GLuint src )
686 {
687 COPY_4V( vb->Clip[dst], vb->Clip[src] );
688 COPY_4V( vb->Eye[dst], vb->Eye[src] );
689 COPY_3V( vb->Win[dst], vb->Win[src] );
690 COPY_4V( vb->Fcolor[dst], vb->Fcolor[src] );
691 COPY_4V( vb->Bcolor[dst], vb->Bcolor[src] );
692 COPY_4V( vb->TexCoord[dst], vb->TexCoord[src] );
693 vb->Findex[dst] = vb->Findex[src];
694 vb->Bindex[dst] = vb->Bindex[src];
695 vb->Edgeflag[dst] = vb->Edgeflag[src];
696 vb->Unclipped[dst] = vb->Unclipped[src];
697 }
698
699
700
701
702 /*
703 * Either the vertex buffer is full (VB->Count==VB_MAX) or glEnd() has been
704 * called. Render the primitives defined by the vertices and reset the
705 * buffer.
706 * Input: alldone - GL_TRUE = caller is glEnd()
707 * GL_FALSE = calling because buffer is full.
708 */
709 void gl_render_vb( GLcontext *ctx, GLboolean alldone )
710 {
711 struct vertex_buffer *VB = ctx->VB;
712 GLuint vlist[VB_SIZE];
713
714 switch (ctx->Primitive) {
715 case GL_POINTS:
716 START_PROFILE
717 (*ctx->PointsFunc)( ctx, 0, VB->Count-1 );
718 END_PROFILE( ctx->PointTime, ctx->PointCount, VB->Count )
719 VB->Count = 0;
720 VB->AnyClipped = GL_FALSE;
721 break;
722
723 case GL_LINES:
724 if (VB->AnyClipped) {
725 GLuint i;
726 for (i=1;i<VB->Count;i+=2) {
727 if (VB->Unclipped[i-1] & VB->Unclipped[i]) {
728 START_PROFILE
729 (*ctx->LineFunc)( ctx, i-1, i, i );
730 END_PROFILE( ctx->LineTime, ctx->LineCount, 1 )
731 }
732 else {
733 render_clipped_line( ctx, i-1, i );
734 }
735 ctx->StippleCounter = 0;
736 }
737 }
738 else {
739 GLuint i;
740 for (i=1;i<VB->Count;i+=2) {
741 START_PROFILE
742 (*ctx->LineFunc)( ctx, i-1, i, i );
743 END_PROFILE( ctx->LineTime, ctx->LineCount, 1 )
744 ctx->StippleCounter = 0;
745 }
746 }
747 VB->Count = 0;
748 VB->AnyClipped = GL_FALSE;
749 break;
750
751 case GL_LINE_STRIP:
752 if (VB->AnyClipped) {
753 GLuint i;
754 for (i=1;i<VB->Count;i++) {
755 if (VB->Unclipped[i-1] & VB->Unclipped[i]) {
756 START_PROFILE
757 (*ctx->LineFunc)( ctx, i-1, i, i );
758 END_PROFILE( ctx->LineTime, ctx->LineCount, 1 )
759 }
760 else {
761 render_clipped_line( ctx, i-1, i );
762 }
763 }
764 }
765 else {
766 /* no clipping needed */
767 GLuint i;
768 for (i=1;i<VB->Count;i++) {
769 START_PROFILE
770 (*ctx->LineFunc)( ctx, i-1, i, i );
771 END_PROFILE( ctx->LineTime, ctx->LineCount, 1 )
772 }
773 }
774 if (!alldone) {
775 copy_vertex( VB, 0, VB->Count-1 ); /* copy last vertex to front */
776 VB->Count = 1;
777 VB->AnyClipped = VB->Unclipped[0] ? GL_FALSE : GL_TRUE;
778 }
779 break;
780
781 case GL_LINE_LOOP:
782 {
783 GLuint i;
784 if (VB->Start==0) {
785 i = 1; /* start at 0th vertex */
786 }
787 else {
788 i = 2; /* skip first vertex, we're saving it until glEnd */
789 }
790 while (i<VB->Count) {
791 if (VB->Unclipped[i-1] & VB->Unclipped[i]) {
792 START_PROFILE
793 (*ctx->LineFunc)( ctx, i-1, i, i );
794 END_PROFILE( ctx->LineTime, ctx->LineCount, 1 )
795 }
796 else {
797 render_clipped_line( ctx, i-1, i );
798 }
799 i++;
800 }
801 }
802 if (alldone) {
803 if (VB->Unclipped[VB->Count-1] & VB->Unclipped[0]) {
804 START_PROFILE
805 (*ctx->LineFunc)( ctx, VB->Count-1, 0, 0 );
806 END_PROFILE( ctx->LineTime, ctx->LineCount, 1 )
807 }
808 else {
809 render_clipped_line( ctx, VB->Count-1, 0 );
810 }
811 }
812 else {
813 ASSERT(VB->Count==VB_MAX);
814 /* recycle the vertex list */
815 copy_vertex( VB, 1, VB_MAX-1 );
816 VB->Count = 2;
817 VB->AnyClipped = !VB->Unclipped[0] || !VB->Unclipped[1];
818 }
819 break;
820
821 case GL_TRIANGLES:
822 if (VB->AnyClipped) {
823 GLuint i;
824 for (i=2;i<VB->Count;i+=3) {
825 if (VB->Unclipped[i-2] & VB->Unclipped[i-1] & VB->Unclipped[i]) {
826 if (ctx->DirectTriangles) {
827 START_PROFILE
828 (*ctx->TriangleFunc)( ctx, i-2, i-1, i, i );
829 END_PROFILE( ctx->PolygonTime, ctx->PolygonCount, 1 )
830 }
831 else {
832 render_triangle( ctx, i-2, i-1, i, i, 0 );
833 }
834 }
835 else {
836 vlist[0] = i-2;
837 vlist[1] = i-1;
838 vlist[2] = i-0;
839 render_clipped_polygon( ctx, 3, vlist, 0 );
840 }
841 }
842 }
843 else {
844 /* no clipping needed */
845 GLuint i;
846 if (ctx->DirectTriangles) {
847 for (i=2;i<VB->Count;i+=3) {
848 START_PROFILE
849 (*ctx->TriangleFunc)( ctx, i-2, i-1, i, i );
850 END_PROFILE( ctx->PolygonTime, ctx->PolygonCount, 1 )
851 }
852 }
853 else {
854 for (i=2;i<VB->Count;i+=3) {
855 render_triangle( ctx, i-2, i-1, i, i, 0 );
856 }
857 }
858 }
859 VB->Count = 0;
860 VB->AnyClipped = GL_FALSE;
861 break;
862
863 case GL_TRIANGLE_STRIP:
864 if (VB->AnyClipped) {
865 GLuint i;
866 for (i=2;i<VB->Count;i++) {
867 if (VB->Unclipped[i-2] & VB->Unclipped[i-1] & VB->Unclipped[i]) {
868 /* TODO: if direct triangle... */
869 if (ctx->DirectTriangles) {
870 START_PROFILE
871 (*ctx->TriangleFunc)( ctx, i-2, i-1, i, i );
872 END_PROFILE( ctx->PolygonTime, ctx->PolygonCount, 1 )
873 }
874 else {
875 render_triangle( ctx, i-2, i-1, i, i, i&1 );
876 }
877 }
878 else {
879 vlist[0] = i-2;
880 vlist[1] = i-1;
881 vlist[2] = i-0;
882 render_clipped_polygon( ctx, 3, vlist, i&1 );
883 }
884 }
885 }
886 else {
887 /* no vertices were clipped */
888 GLuint i;
889 if (ctx->DirectTriangles) {
890 for (i=2;i<VB->Count;i++) {
891 START_PROFILE
892 (*ctx->TriangleFunc)( ctx, i-2, i-1, i, i );
893 END_PROFILE( ctx->PolygonTime, ctx->PolygonCount, 1 )
894 }
895 }
896 else {
897 for (i=2;i<VB->Count;i++) {
898 render_triangle( ctx, i-2, i-1, i, i, i&1 );
899 }
900 }
901 }
902 if (!alldone) {
903 /* get ready for more vertices in this triangle strip */
904 copy_vertex( VB, 0, VB_MAX-2 );
905 copy_vertex( VB, 1, VB_MAX-1 );
906 VB->Count = 2;
907 VB->AnyClipped = !VB->Unclipped[0] || !VB->Unclipped[1];
908 }
909 break;
910
911 case GL_TRIANGLE_FAN:
912 if (VB->AnyClipped) {
913 GLuint i;
914 for (i=2;i<VB->Count;i++) {
915 if (VB->Unclipped[0] & VB->Unclipped[i-1] & VB->Unclipped[i]) {
916 if (ctx->DirectTriangles) {
917 START_PROFILE
918 (*ctx->TriangleFunc)( ctx, 0, i-1, i, i );
919 END_PROFILE( ctx->PolygonTime, ctx->PolygonCount, 1 )
920 }
921 else {
922 render_triangle( ctx, 0, i-1, i, i, 0 );
923 }
924 }
925 else {
926 vlist[0] = 0;
927 vlist[1] = i-1;
928 vlist[2] = i;
929 render_clipped_polygon( ctx, 3, vlist, 0 );
930 }
931 }
932 }
933 else {
934 /* no clipping needed */
935 GLuint i;
936 if (ctx->DirectTriangles) {
937 for (i=2;i<VB->Count;i++) {
938 START_PROFILE
939 (*ctx->TriangleFunc)( ctx, 0, i-1, i, i );
940 END_PROFILE( ctx->PolygonTime, ctx->PolygonCount, 1 )
941 }
942 }
943 else {
944 for (i=2;i<VB->Count;i++) {
945 render_triangle( ctx, 0, i-1, i, i, 0 );
946 }
947 }
948 }
949 if (!alldone) {
950 /* get ready for more vertices in this triangle fan */
951 copy_vertex( VB, 1, VB_MAX-1 );
952 VB->Count = 2;
953 VB->AnyClipped = !VB->Unclipped[0] || !VB->Unclipped[1];
954 }
955 break;
956
957 case GL_QUADS:
958 if (VB->AnyClipped) {
959 GLuint i;
960 for (i=3;i<VB->Count;i+=4) {
961 if ( VB->Unclipped[i-3] & VB->Unclipped[i-2]
962 & VB->Unclipped[i-1] & VB->Unclipped[i]) {
963 if (ctx->DirectTriangles) {
964 START_PROFILE
965 (*ctx->TriangleFunc)( ctx, i-3, i-2, i, i );
966 (*ctx->TriangleFunc)( ctx, i-2, i-1, i, i );
967 END_PROFILE( ctx->PolygonTime, ctx->PolygonCount, 2 )
968 }
969 else {
970 render_quad( ctx, i-3, i-2, i-1, i, i, 0 );
971 }
972 }
973 else {
974 vlist[0] = i-3;
975 vlist[1] = i-2;
976 vlist[2] = i-1;
977 vlist[3] = i-0;
978 render_clipped_polygon( ctx, 4, vlist, 0 );
979 }
980 }
981 }
982 else {
983 /* no vertices were clipped */
984 GLuint i;
985 if (ctx->DirectTriangles) {
986 for (i=3;i<VB->Count;i+=4) {
987 START_PROFILE
988 (*ctx->TriangleFunc)( ctx, i-3, i-2, i, i );
989 (*ctx->TriangleFunc)( ctx, i-2, i-1, i, i );
990 END_PROFILE( ctx->PolygonTime, ctx->PolygonCount, 2 )
991 }
992 }
993 else {
994 for (i=3;i<VB->Count;i+=4) {
995 render_quad( ctx, i-3, i-2, i-1, i, i, 0 );
996 }
997 }
998 }
999 VB->Count = 0;
1000 VB->AnyClipped = GL_FALSE;
1001 break;
1002
1003 case GL_QUAD_STRIP:
1004 if (VB->AnyClipped) {
1005 GLuint i;
1006 for (i=3;i<VB->Count;i+=2) {
1007 if ( VB->Unclipped[i-2] & VB->Unclipped[i-3]
1008 & VB->Unclipped[i-1] & VB->Unclipped[i]) {
1009 if (ctx->DirectTriangles) {
1010 START_PROFILE
1011 (*ctx->TriangleFunc)( ctx, i-2, i-3, i, i );
1012 (*ctx->TriangleFunc)( ctx, i-3, i-1, i, i );
1013 END_PROFILE( ctx->PolygonTime, ctx->PolygonCount, 2 )
1014 }
1015 else {
1016 render_quad( ctx, i-2, i-3, i-1, i, i, 1 );
1017 }
1018 }
1019 else {
1020 vlist[0] = i-2;
1021 vlist[1] = i-3;
1022 vlist[2] = i-1;
1023 vlist[3] = i-0;
1024 render_clipped_polygon( ctx, 4, vlist, 1 );
1025 }
1026 }
1027 }
1028 else {
1029 /* no clipping needed */
1030 GLuint i;
1031 if (ctx->DirectTriangles) {
1032 for (i=3;i<VB->Count;i+=2) {
1033 START_PROFILE
1034 (*ctx->TriangleFunc)( ctx, i-2, i-3, i, i );
1035 (*ctx->TriangleFunc)( ctx, i-3, i-1, i, i );
1036 END_PROFILE( ctx->PolygonTime, ctx->PolygonCount, 2 )
1037 }
1038 }
1039 else {
1040 for (i=3;i<VB->Count;i+=2) {
1041 render_quad( ctx, i-2, i-3, i-1, i, i, 1 );
1042 }
1043 }
1044 }
1045 if (!alldone) {
1046 /* get ready for more vertices in this quad strip */
1047 copy_vertex( VB, 0, VB_MAX-2 );
1048 copy_vertex( VB, 1, VB_MAX-1 );
1049 VB->Count = 2;
1050 VB->AnyClipped = !VB->Unclipped[0] || !VB->Unclipped[1];
1051 }
1052 break;
1053
1054 case GL_POLYGON:
1055 if (VB->Count>2) {
1056 GLuint i;
1057 for (i=0;i<VB->Count;i++) {
1058 vlist[i] = i;
1059 }
1060 if (VB->AnyClipped) {
1061 render_clipped_polygon( ctx, VB->Count, vlist, 0 );
1062 }
1063 else {
1064 render_polygon( ctx, VB->Count, vlist, 0 );
1065 }
1066 }
1067 if (!alldone) {
1068 /* get ready for more vertices just like a triangle fan */
1069 copy_vertex( VB, 1, VB_MAX-1 );
1070 VB->Count = 2;
1071 VB->AnyClipped = !VB->Unclipped[0] || !VB->Unclipped[1];
1072 }
1073 break;
1074
1075 default:
1076 /* should never get here */
1077 abort();
1078 }
1079
1080 /* Start = first vertex which hasn't been transformed yet */
1081 VB->Start = VB->Count;
1082 }
1083
1084
1085
1086 /*
1087 * Part 2 of Vertex Buffer transformation: compute lighting, clipflags,
1088 * fog, texture coords, etc.
1089 * The function is called either by xform_vb_part1() or by glDrawArraysEXT().
1090 */
1091 void gl_transform_vb_part2( GLcontext *ctx, GLboolean alldone )
1092 {
1093 struct vertex_buffer *VB = ctx->VB;
1094 #ifdef PROFILE
1095 GLdouble t0 = gl_time();
1096 #endif
1097
1098 ASSERT( VB->Count>0 );
1099
1100 /* Lighting */
1101 if (ctx->Light.Enabled) {
1102 if (ctx->Visual->RGBAflag) {
1103 if (VB->MaterialChanges) {
1104 GLuint i;
1105 /* NOTE the <= here. This is needed in case glColor/glMaterial
1106 * is called after the last glVertex inside a glBegin/glEnd pair.
1107 */
1108 for (i=VB->Start;i<=VB->Count;i++) {
1109 update_material( ctx, i );
1110 gl_color_shade_vertices( ctx, 1, &VB->Eye[i], &VB->Normal[i],
1111 ctx->LightTwoSide,
1112 &VB->Fcolor[i], &VB->Bcolor[i] );
1113 }
1114 }
1115 else {
1116 if (ctx->Light.Fast) {
1117 /* call optimized shader */
1118 gl_color_shade_vertices_fast( ctx, VB->Count-VB->Start,
1119 VB->Eye + VB->Start,
1120 VB->Normal + VB->Start,
1121 ctx->LightTwoSide,
1122 VB->Fcolor + VB->Start,
1123 VB->Bcolor + VB->Start );
1124 }
1125 else {
1126 /* call full-featured shader */
1127 gl_color_shade_vertices( ctx, VB->Count-VB->Start,
1128 VB->Eye + VB->Start,
1129 VB->Normal + VB->Start,
1130 ctx->LightTwoSide,
1131 VB->Fcolor + VB->Start,
1132 VB->Bcolor + VB->Start );
1133 }
1134 }
1135 }
1136 else {
1137 if (VB->MaterialChanges) {
1138 GLuint i;
1139 /* NOTE the <= here. This is needed in case glColor/glMaterial
1140 * is called after the last glVertex inside a glBegin/glEnd pair.
1141 */
1142 for (i=VB->Start;i<=VB->Count;i++) {
1143 update_material( ctx, i );
1144 gl_index_shade_vertices( ctx, 1, &VB->Eye[i], &VB->Normal[i],
1145 ctx->LightTwoSide,
1146 &VB->Findex[i], &VB->Bindex[i] );
1147 }
1148 }
1149 else {
1150 gl_index_shade_vertices( ctx, VB->Count-VB->Start,
1151 VB->Eye + VB->Start, VB->Normal + VB->Start,
1152 ctx->LightTwoSide,
1153 VB->Findex + VB->Start, VB->Bindex + VB->Start );
1154 }
1155 }
1156 }
1157
1158 /* Per-vertex fog */
1159 if (ctx->Fog.Enabled && ctx->Hint.Fog!=GL_NICEST) {
1160 if (ctx->Visual->RGBAflag) {
1161 /* Fog RGB colors */
1162 gl_fog_color_vertices( ctx, VB->Count - VB->Start,
1163 VB->Eye + VB->Start,
1164 VB->Fcolor + VB->Start );
1165 if (ctx->LightTwoSide) {
1166 gl_fog_color_vertices( ctx, VB->Count - VB->Start,
1167 VB->Eye + VB->Start,
1168 VB->Bcolor + VB->Start );
1169 }
1170 }
1171 else {
1172 /* Fog color indexes */
1173 gl_fog_index_vertices( ctx, VB->Count - VB->Start,
1174 VB->Eye + VB->Start,
1175 VB->Findex + VB->Start );
1176 if (ctx->LightTwoSide) {
1177 gl_fog_index_vertices( ctx, VB->Count - VB->Start,
1178 VB->Eye + VB->Start,
1179 VB->Bindex + VB->Start );
1180 }
1181 }
1182 }
1183
1184 /* Generate/transform texture coords */
1185 if (ctx->Texture.Enabled || ctx->RenderMode==GL_FEEDBACK) {
1186 if (ctx->Texture.TexGenEnabled) {
1187 gl_texgen( ctx, VB->Count - VB->Start,
1188 VB->Obj + VB->Start,
1189 VB->Eye + VB->Start,
1190 VB->Normal + VB->Start,
1191 VB->TexCoord + VB->Start );
1192 }
1193 if (!ctx->IdentityTexMat) {
1194 gl_xform_texcoords_4fv( VB->Count - VB->Start,
1195 VB->TexCoord + VB->Start,
1196 ctx->TextureMatrix );
1197 }
1198 }
1199
1200 /* Initialize clip flags */
1201 MEMSET( VB->Unclipped+VB->Start, GL_TRUE, VB->Count-VB->Start );
1202
1203 if (ctx->Transform.AnyClip) {
1204 /* Clip against user-defined clip planes */
1205 GLuint p;
1206 for (p=0;p<MAX_CLIP_PLANES;p++) {
1207 if (ctx->Transform.ClipEnabled[p]) {
1208 GLuint i;
1209 GLfloat a = ctx->Transform.ClipEquation[p][0];
1210 GLfloat b = ctx->Transform.ClipEquation[p][1];
1211 GLfloat c = ctx->Transform.ClipEquation[p][2];
1212 GLfloat d = ctx->Transform.ClipEquation[p][3];
1213 for (i=VB->Start;i<VB->Count;i++) {
1214 GLfloat dot = VB->Eye[i][0] * a + VB->Eye[i][1] * b
1215 + VB->Eye[i][2] * c + VB->Eye[i][3] * d;
1216 if (dot < 0.0F) {
1217 VB->Unclipped[i] = GL_FALSE;
1218 VB->AnyClipped = GL_TRUE;
1219 }
1220 }
1221 }
1222 }
1223 }
1224
1225 /* Transform vertices from eye to clip coords */
1226 /* Even transform clipped vertices because it's usually faster. */
1227 gl_xform_points_4fv( VB->Count-VB->Start, VB->Clip+VB->Start,
1228 ctx->ProjectionMatrix, VB->Eye+VB->Start );
1229
1230 /*
1231 * Combined clip testing with clip-to-window coordinate mapping.
1232 */
1233 {
1234 GLfloat sx = ctx->Viewport.Sx;
1235 GLfloat tx = ctx->Viewport.Tx;
1236 GLfloat sy = ctx->Viewport.Sy;
1237 GLfloat ty = ctx->Viewport.Ty;
1238 GLfloat sz = ctx->Viewport.Sz;
1239 GLfloat tz = ctx->Viewport.Tz;
1240 GLuint i, start = VB->Start, n = VB->Count;
1241 for (i=start;i<n;i++) {
1242 GLfloat clipx = VB->Clip[i][0], clipy = VB->Clip[i][1];
1243 GLfloat clipz = VB->Clip[i][2], clipw = VB->Clip[i][3];
1244 if (clipx > clipw || clipx < -clipw ||
1245 clipy > clipw || clipy < -clipw ||
1246 clipz > clipw || clipz < -clipw ) {
1247 /* vertex is clipped */
1248 VB->Unclipped[i] = GL_FALSE;
1249 VB->AnyClipped = GL_TRUE;
1250 }
1251 else {
1252 /* vertex not clipped */
1253 GLfloat d = 1.0F / clipw;
1254 VB->Win[i][0] = clipx * d * sx + tx;
1255 VB->Win[i][1] = clipy * d * sy + ty;
1256 VB->Win[i][2] = clipz * d * sz + tz;
1257 }
1258 }
1259 }
1260
1261 #ifdef PROFILE
1262 ctx->VertexTime += gl_time() - t0;
1263 ctx->VertexCount += VB->Count - VB->Start;
1264 #endif
1265 }
1266
1267
1268
1269 /*
1270 * When the Vertex Buffer is full, this function transforms all the
1271 * vertices and normals then calls xform_vb_part2()...
1272 */
1273 void gl_transform_vb_part1( GLcontext *ctx, GLboolean alldone )
1274 {
1275 struct vertex_buffer *VB = ctx->VB;
1276 #ifdef PROFILE
1277 GLdouble t0 = gl_time();
1278 #endif
1279
1280 ASSERT( VB->Count>0 );
1281
1282 /* Transform vertexes from object to eye coords */
1283 gl_xform_points_4fv( VB->Count-VB->Start, VB->Eye+VB->Start,
1284 ctx->ModelViewMatrix, VB->Obj+VB->Start );
1285
1286 /* Transform normals from object to eye coords */
1287 if (ctx->NeedNormals) {
1288 gl_xform_normals_3fv( VB->Count-VB->Start,
1289 VB->Normal+VB->Start, ctx->ModelViewInv,
1290 VB->Normal+VB->Start, ctx->Transform.Normalize );
1291 }
1292
1293 #ifdef PROFILE
1294 ctx->VertexTime += gl_time() - t0;
1295 #endif
1296
1297 /* lighting, project, etc */
1298 gl_transform_vb_part2( ctx, alldone );
1299
1300 /* Render the primitives */
1301 gl_render_vb( ctx, alldone );
1302 }
1303
1304
1305
1306 /**********************************************************************/
1307 /**** Vertex functions. These are called via ctx->Exec.Vertex4f() ****/
1308 /**********************************************************************/
1309
1310 /*
1311 * Save a glVertex call into a display list AND execute it.
1312 */
1313 void gl_save_and_execute_vertex( GLcontext *ctx,
1314 GLfloat x, GLfloat y, GLfloat z, GLfloat w )
1315 {
1316 struct vertex_buffer *VB = ctx->VB;
1317 GLuint count = VB->Count; /* copy to local var to encourage optimization */
1318
1319 /* Put vertex into display list */
1320 gl_save_Vertex4f( ctx, x, y, z, w );
1321
1322 /* Exectue vertex command */
1323 ASSIGN_4V( VB->Obj[count], x, y, z, w );
1324 if (ctx->Visual->RGBAflag) {
1325 if (ctx->Light.Enabled) {
1326 /* need normal vector, vertex color is computed from material */
1327 COPY_3V( VB->Normal[count], ctx->Current.Normal );
1328 }
1329 else {
1330 /* not lighting, need vertex color */
1331 GLint shift = ctx->ColorShift;
1332 VB->Fcolor[count][0] = ctx->Current.IntColor[0] << shift;
1333 VB->Fcolor[count][1] = ctx->Current.IntColor[1] << shift;
1334 VB->Fcolor[count][2] = ctx->Current.IntColor[2] << shift;
1335 VB->Fcolor[count][3] = ctx->Current.IntColor[3] << shift;
1336 }
1337 if (ctx->Texture.Enabled) {
1338 COPY_4V( VB->TexCoord[count], ctx->Current.TexCoord );
1339 }
1340 }
1341 else {
1342 if (ctx->Light.Enabled) {
1343 /* need normal vector, vertex color index computed from material*/
1344 COPY_3V( VB->Normal[count], ctx->Current.Normal );
1345 }
1346 else {
1347 /* not lighting, new vertex color index */
1348 VB->Findex[count] = ctx->Current.Index;
1349 }
1350 }
1351 VB->Edgeflag[count] = ctx->Current.EdgeFlag;
1352
1353 count++;
1354 VB->Count = count;
1355 if (count==VB_MAX) {
1356 gl_transform_vb_part1( ctx, GL_FALSE );
1357 }
1358 }
1359
1360
1361 /*
1362 * Used when in feedback mode.
1363 */
1364 static void vertex_feedback( GLcontext *ctx,
1365 GLfloat x, GLfloat y, GLfloat z, GLfloat w )
1366 {
1367 struct vertex_buffer *VB = ctx->VB;
1368 GLuint count = VB->Count;
1369 GLint shift = ctx->ColorShift;
1370
1371 /* vertex */
1372 ASSIGN_4V( VB->Obj[count], x, y, z, w );
1373
1374 /* color */
1375 VB->Fcolor[count][0] = ctx->Current.IntColor[0] << shift;
1376 VB->Fcolor[count][1] = ctx->Current.IntColor[1] << shift;
1377 VB->Fcolor[count][2] = ctx->Current.IntColor[2] << shift;
1378 VB->Fcolor[count][3] = ctx->Current.IntColor[3] << shift;
1379
1380 /* index */
1381 VB->Findex[count] = ctx->Current.Index;
1382
1383 /* normal */
1384 COPY_3V( VB->Normal[count], ctx->Current.Normal );
1385
1386 /* texcoord */
1387 COPY_4V( VB->TexCoord[count], ctx->Current.TexCoord );
1388
1389 /* edgeflag */
1390 VB->Edgeflag[count] = ctx->Current.EdgeFlag;
1391
1392 count++;
1393 VB->Count = count;
1394 if (count==VB_MAX) {
1395 gl_transform_vb_part1( ctx, GL_FALSE );
1396 }
1397 }
1398
1399
1400 /* RGB, lit, textured vertex */
1401 static void vertex_normal_texture( GLcontext *ctx,
1402 GLfloat x, GLfloat y, GLfloat z, GLfloat w )
1403 {
1404 struct vertex_buffer *VB = ctx->VB;
1405 GLuint count = VB->Count;
1406
1407 ASSIGN_4V( VB->Obj[count], x, y, z, w );
1408 COPY_3V( VB->Normal[count], ctx->Current.Normal );
1409 COPY_4V( VB->TexCoord[count], ctx->Current.TexCoord );
1410 VB->Edgeflag[count] = ctx->Current.EdgeFlag;
1411
1412 count++;
1413 VB->Count = count;
1414 if (count==VB_MAX) {
1415 gl_transform_vb_part1( ctx, GL_FALSE );
1416 }
1417 }
1418
1419
1420 /* RGB or CI, lit, untextured vertex */
1421 static void vertex_normal( GLcontext *ctx,
1422 GLfloat x, GLfloat y, GLfloat z, GLfloat w )
1423 {
1424 struct vertex_buffer *VB = ctx->VB;
1425 GLuint count = VB->Count;
1426
1427 ASSIGN_4V( VB->Obj[count], x, y, z, w );
1428 COPY_3V( VB->Normal[count], ctx->Current.Normal );
1429 VB->Edgeflag[count] = ctx->Current.EdgeFlag;
1430
1431 count++;
1432 VB->Count = count;
1433 if (count==VB_MAX) {
1434 gl_transform_vb_part1( ctx, GL_FALSE );
1435 }
1436 }
1437
1438
1439 /* RGB, unlit, textured vertex */
1440 static void vertex_texture( GLcontext *ctx,
1441 GLfloat x, GLfloat y, GLfloat z, GLfloat w )
1442 {
1443 struct vertex_buffer *VB = ctx->VB;
1444 GLuint count = VB->Count;
1445 GLint shift = ctx->ColorShift;
1446
1447 ASSIGN_4V( VB->Obj[count], x, y, z, w );
1448 VB->Fcolor[count][0] = ctx->Current.IntColor[0] << shift;
1449 VB->Fcolor[count][1] = ctx->Current.IntColor[1] << shift;
1450 VB->Fcolor[count][2] = ctx->Current.IntColor[2] << shift;
1451 VB->Fcolor[count][3] = ctx->Current.IntColor[3] << shift;
1452 COPY_4V( VB->TexCoord[count], ctx->Current.TexCoord );
1453 VB->Edgeflag[count] = ctx->Current.EdgeFlag;
1454
1455 count++;
1456 VB->Count = count;
1457 if (count==VB_MAX) {
1458 gl_transform_vb_part1( ctx, GL_FALSE );
1459 }
1460 }
1461
1462
1463 /* RGB, unlit, untextured vertex */
1464 static void vertex_color( GLcontext *ctx,
1465 GLfloat x, GLfloat y, GLfloat z, GLfloat w )
1466 {
1467 struct vertex_buffer *VB = ctx->VB;
1468 GLuint count = VB->Count;
1469 GLint shift = ctx->ColorShift;
1470
1471 ASSIGN_4V( VB->Obj[count], x, y, z, w );
1472 VB->Fcolor[count][0] = ctx->Current.IntColor[0] << shift;
1473 VB->Fcolor[count][1] = ctx->Current.IntColor[1] << shift;
1474 VB->Fcolor[count][2] = ctx->Current.IntColor[2] << shift;
1475 VB->Fcolor[count][3] = ctx->Current.IntColor[3] << shift;
1476 VB->Edgeflag[count] = ctx->Current.EdgeFlag;
1477
1478 count++;
1479 VB->Count = count;
1480 if (count==VB_MAX) {
1481 gl_transform_vb_part1( ctx, GL_FALSE );
1482 }
1483 }
1484
1485
1486 /* CI, unlit vertex */
1487 static void vertex_index( GLcontext *ctx,
1488 GLfloat x, GLfloat y, GLfloat z, GLfloat w )
1489 {
1490 struct vertex_buffer *VB = ctx->VB;
1491 GLuint count = VB->Count;
1492
1493 ASSIGN_4V( VB->Obj[count], x, y, z, w );
1494 VB->Findex[count] = ctx->Current.Index;
1495 VB->Edgeflag[count] = ctx->Current.EdgeFlag;
1496
1497 count++;
1498 VB->Count = count;
1499 if (count==VB_MAX) {
1500 gl_transform_vb_part1( ctx, GL_FALSE );
1501 }
1502 }
1503
1504
1505 /*
1506 * Called when outside glBegin/glEnd, raises an error.
1507 */
1508 void gl_nop_vertex( GLcontext *ctx,
1509 GLfloat x, GLfloat y, GLfloat z, GLfloat w )
1510 {
1511 gl_error( ctx, GL_INVALID_OPERATION, "glVertex" );
1512 }
1513
1514
1515
1516 /*
1517 * This function examines the current GL state and sets the
1518 * ctx->Exec.Vertex4f pointer to point at the appropriate vertex function.
1519 */
1520 void gl_set_vertex_function( GLcontext *ctx )
1521 {
1522 ASSERT( !INSIDE_BEGIN_END(ctx) );
1523 if (ctx->RenderMode==GL_FEEDBACK) {
1524 ctx->Exec.Vertex4f = vertex_feedback;
1525 }
1526 else {
1527 if (ctx->Visual->RGBAflag) {
1528 if (ctx->Light.Enabled) {
1529 if (ctx->Texture.Enabled) {
1530 ctx->Exec.Vertex4f = vertex_normal_texture;
1531 }
1532 else {
1533 ctx->Exec.Vertex4f = vertex_normal;
1534 }
1535 }
1536 else {
1537 /* not lighting, need vertex color */
1538 if (ctx->Texture.Enabled) {
1539 ctx->Exec.Vertex4f = vertex_texture;
1540 }
1541 else {
1542 ctx->Exec.Vertex4f = vertex_color;
1543 }
1544 }
1545 }
1546 else {
1547 /* color index mode */
1548 if (ctx->Light.Enabled) {
1549 ctx->Exec.Vertex4f = vertex_normal;
1550 }
1551 else {
1552 ctx->Exec.Vertex4f = vertex_index;
1553 }
1554 }
1555 }
1556
1557 if (!ctx->CompileFlag) {
1558 ctx->API.Vertex4f = ctx->Exec.Vertex4f;
1559 }
1560 }
1561
1562
1563
1564 /*
1565 * Process a vertex produced by an evaluator.
1566 * Input: vertex - the X,Y,Z,W vertex
1567 * normal - normal vector
1568 * color - 4 integer color components
1569 * index - color index
1570 * texcoord - texture coordinate
1571 */
1572 void gl_eval_vertex( GLcontext *ctx,
1573 const GLfloat vertex[4], const GLfloat normal[3],
1574 const GLint color[4], GLuint index,
1575 const GLfloat texcoord[4] )
1576 {
1577 struct vertex_buffer *VB = ctx->VB;
1578 GLuint count = VB->Count; /* copy to local var to encourage optimization */
1579 GLint shift = ctx->ColorShift;
1580
1581 COPY_4V( VB->Obj[count], vertex );
1582 COPY_3V( VB->Normal[count], normal );
1583 VB->Fcolor[count][0] = color[0] << shift;
1584 VB->Fcolor[count][1] = color[1] << shift;
1585 VB->Fcolor[count][2] = color[2] << shift;
1586 VB->Fcolor[count][3] = color[3] << shift;
1587 #ifdef GL_VERSION_1_1
1588 if (ctx->Light.ColorMaterialEnabled
1589 && (ctx->Eval.Map1Color4 || ctx->Eval.Map1Color4)) {
1590 GLfloat fcolor[4];
1591 fcolor[0] = color[0] * ctx->Visual->InvRedScale;
1592 fcolor[1] = color[1] * ctx->Visual->InvGreenScale;
1593 fcolor[2] = color[2] * ctx->Visual->InvBlueScale;
1594 fcolor[3] = color[3] * ctx->Visual->InvAlphaScale;
1595 gl_set_material( ctx, ctx->Light.ColorMaterialBitmask, fcolor );
1596 }
1597 #endif
1598 VB->Findex[count] = index;
1599 COPY_4V( VB->TexCoord[count], texcoord );
1600 VB->Edgeflag[count] = ctx->Current.EdgeFlag;
1601
1602 count++;
1603 VB->Count = count;
1604 if (count==VB_MAX) {
1605 gl_transform_vb_part1( ctx, GL_FALSE );
1606 }
1607 }
1608
1609
1610
1611
1612 void gl_RasterPos4f( GLcontext *ctx,
1613 GLfloat x, GLfloat y, GLfloat z, GLfloat w )
1614 {
1615 GLfloat v[4], eye[4], clip[4], ndc[3], d;
1616
1617 v[0] = x;
1618 v[1] = y;
1619 v[2] = z;
1620 v[3] = w;
1621
1622 /* transform v to eye coords: eye = ModelView * v */
1623 TRANSFORM_POINT( eye, ctx->ModelViewMatrix, v );
1624
1625 /* raster color */
1626 if (ctx->Light.Enabled) {
1627 GLfloat eyenorm[3];
1628 if (!ctx->ModelViewInvValid) {
1629 gl_compute_modelview_inverse(ctx);
1630 }
1631 TRANSFORM_NORMAL( eyenorm[0], eyenorm[1], eyenorm[2], ctx->Current.Normal,
1632 ctx->ModelViewInv );
1633 ctx->ColorShift = 0; /* Colors only shifted when smooth shading */
1634 if (ctx->Visual->RGBAflag) {
1635 GLfixed color[4]; /* not really fixed point but integers */
1636 GLfixed bcolor[4]; /* not used, dummy arg */
1637 gl_color_shade_vertices( ctx, 1, &eye, &eyenorm, 0, &color, &bcolor );
1638 ctx->Current.RasterColor[0] = color[0] * ctx->Visual->InvRedScale;
1639 ctx->Current.RasterColor[1] = color[1] * ctx->Visual->InvGreenScale;
1640 ctx->Current.RasterColor[2] = color[2] * ctx->Visual->InvBlueScale;
1641 ctx->Current.RasterColor[3] = color[3] * ctx->Visual->InvAlphaScale;
1642 }
1643 else {
1644 GLuint dummy;
1645 gl_index_shade_vertices( ctx, 1, &eye, &eyenorm, 0,
1646 &ctx->Current.RasterIndex, &dummy );
1647 }
1648 }
1649 else {
1650 /* use current color or index */
1651 if (ctx->Visual->RGBAflag) {
1652 ctx->Current.RasterColor[0] = ctx->Current.IntColor[0]
1653 * ctx->Visual->InvRedScale;
1654 ctx->Current.RasterColor[1] = ctx->Current.IntColor[1]
1655 * ctx->Visual->InvGreenScale;
1656 ctx->Current.RasterColor[2] = ctx->Current.IntColor[2]
1657 * ctx->Visual->InvBlueScale;
1658 ctx->Current.RasterColor[3] = ctx->Current.IntColor[3]
1659 * ctx->Visual->InvAlphaScale;
1660 }
1661 else {
1662 ctx->Current.RasterIndex = ctx->Current.Index;
1663 }
1664 }
1665
1666 /* clip to user clipping planes */
1667 if (gl_userclip_point(ctx, eye)==0) {
1668 ctx->Current.RasterPosValid = GL_FALSE;
1669 return;
1670 }
1671
1672 /* compute raster distance */
1673 ctx->Current.RasterDistance = (GLfloat)
1674 sqrt( eye[0]*eye[0] + eye[1]*eye[1] + eye[2]*eye[2] );
1675
1676 /* apply projection matrix: clip = Proj * eye */
1677 TRANSFORM_POINT( clip, ctx->ProjectionMatrix, eye );
1678
1679 /* clip to view volume */
1680 if (gl_viewclip_point( clip )==0) {
1681 ctx->Current.RasterPosValid = GL_FALSE;
1682 return;
1683 }
1684
1685 /* ndc = clip / W */
1686 ASSERT( clip[3]!=0.0 );
1687 d = 1.0F / clip[3];
1688 ndc[0] = clip[0] * d;
1689 ndc[1] = clip[1] * d;
1690 ndc[2] = clip[2] * d;
1691
1692 ctx->Current.RasterPos[0] = ndc[0] * ctx->Viewport.Sx + ctx->Viewport.Tx;
1693 ctx->Current.RasterPos[1] = ndc[1] * ctx->Viewport.Sy + ctx->Viewport.Ty;
1694 ctx->Current.RasterPos[2] = (ndc[2] * ctx->Viewport.Sz + ctx->Viewport.Tz)
1695 / DEPTH_SCALE;
1696 ctx->Current.RasterPos[3] = clip[3];
1697 ctx->Current.RasterPosValid = GL_TRUE;
1698
1699 /* FOG??? */
1700
1701 if (ctx->Texture.Enabled) {
1702 COPY_4V( ctx->Current.RasterTexCoord, ctx->Current.TexCoord );
1703 }
1704
1705 if (ctx->RenderMode==GL_SELECT) {
1706 gl_update_hitflag( ctx, ctx->Current.RasterPos[2] );
1707 }
1708
1709 }
1710
1711
1712
1713
1714 void gl_windowpos( GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z, GLfloat w )
1715 {
1716
1717 /* set raster position */
1718 ctx->Current.RasterPos[0] = x;
1719 ctx->Current.RasterPos[1] = y;
1720 ctx->Current.RasterPos[2] = CLAMP( z, 0.0F, 1.0F );
1721 ctx->Current.RasterPos[3] = w;
1722
1723 ctx->Current.RasterPosValid = GL_TRUE;
1724
1725 /* raster color */
1726 if (ctx->Light.Enabled) {
1727 GLfloat eye[4];
1728 GLfloat eyenorm[3];
1729 COPY_4V( eye, ctx->Current.RasterPos );
1730 if (!ctx->ModelViewInvValid) {
1731 gl_compute_modelview_inverse(ctx);
1732 }
1733 TRANSFORM_NORMAL( eyenorm[0], eyenorm[1], eyenorm[2], ctx->Current.Normal,
1734 ctx->ModelViewInv );
1735 ctx->ColorShift = 0; /* Colors only shifted when smooth shading */
1736 if (ctx->Visual->RGBAflag) {
1737 GLfixed color[4]; /* not really fixed point but integers */
1738 GLfixed bcolor[4]; /* not used, dummy arg */
1739 gl_color_shade_vertices( ctx, 1, &eye, &eyenorm, 0, &color, &bcolor );
1740 ctx->Current.RasterColor[0] = (GLfloat) color[0] * ctx->Visual->InvRedScale;
1741 ctx->Current.RasterColor[1] = (GLfloat) color[1] * ctx->Visual->InvGreenScale;
1742 ctx->Current.RasterColor[2] = (GLfloat) color[2] * ctx->Visual->InvBlueScale;
1743 ctx->Current.RasterColor[3] = (GLfloat) color[3] * ctx->Visual->InvAlphaScale;
1744 }
1745 else {
1746 GLuint dummy;
1747 gl_index_shade_vertices( ctx, 1, &eye, &eyenorm, 0,
1748 &ctx->Current.RasterIndex, &dummy );
1749 }
1750 }
1751 else {
1752 /* use current color or index */
1753 if (ctx->Visual->RGBAflag) {
1754 ctx->Current.RasterColor[0] = ctx->Current.IntColor[0] * ctx->Visual->InvRedScale;
1755 ctx->Current.RasterColor[1] = ctx->Current.IntColor[1] * ctx->Visual->InvGreenScale;
1756 ctx->Current.RasterColor[2] = ctx->Current.IntColor[2] * ctx->Visual->InvBlueScale;
1757 ctx->Current.RasterColor[3] = ctx->Current.IntColor[3] * ctx->Visual->InvAlphaScale;
1758 }
1759 else {
1760 ctx->Current.RasterIndex = ctx->Current.Index;
1761 }
1762 }
1763
1764 ctx->Current.RasterDistance = 0.0;
1765
1766 if (ctx->Texture.Enabled) {
1767 COPY_4V( ctx->Current.RasterTexCoord, ctx->Current.TexCoord );
1768 }
1769
1770 if (ctx->RenderMode==GL_SELECT) {
1771 gl_update_hitflag( ctx, ctx->Current.RasterPos[2] );
1772 }
1773 }
1774
1775
1776
1777
1778 #ifdef PROFILE
1779 static GLdouble begin_time;
1780 #endif
1781
1782
1783 void gl_Begin( GLcontext *ctx, GLenum p )
1784 {
1785 struct vertex_buffer *VB = ctx->VB;
1786 struct pixel_buffer *PB = ctx->PB;
1787 #ifdef PROFILE
1788 begin_time = gl_time();
1789 #endif
1790
1791 if (INSIDE_BEGIN_END(ctx)) {
1792 gl_error( ctx, GL_INVALID_OPERATION, "glBegin" );
1793 return;
1794 }
1795 if (!ctx->ModelViewInvValid) {
1796 gl_compute_modelview_inverse(ctx);
1797 }
1798 if (ctx->NewState) {
1799 gl_update_state(ctx);
1800 }
1801 else if (ctx->Exec.Vertex4f==gl_nop_vertex) {
1802 gl_set_vertex_function(ctx);
1803 }
1804
1805 if (ctx->Driver.Begin) {
1806 (*ctx->Driver.Begin)( ctx, p );
1807 }
1808
1809 ctx->Primitive = p;
1810 VB->Start = VB->Count = 0;
1811 VB->AnyClipped = GL_FALSE;
1812
1813 VB->MonoColor = ctx->MonoPixels;
1814 if (VB->MonoColor) {
1815 /* All pixels generated are likely to be the same color so have
1816 * the device driver set the "monocolor" now.
1817 */
1818 if (ctx->Visual->RGBAflag) {
1819 GLubyte r = ctx->Current.IntColor[0];
1820 GLubyte g = ctx->Current.IntColor[1];
1821 GLubyte b = ctx->Current.IntColor[2];
1822 GLubyte a = ctx->Current.IntColor[3];
1823 (*ctx->Driver.Color)( ctx, r, g, b, a );
1824 }
1825 else {
1826 (*ctx->Driver.Index)( ctx, ctx->Current.Index );
1827 }
1828 }
1829
1830 /*
1831 * If flat shading, save integer vertex colors
1832 * else, save fixed-point (scaled) vertex colors
1833 */
1834 ctx->ColorShift = (ctx->Light.ShadeModel==GL_FLAT) ? 0 : FIXED_SHIFT;
1835
1836 /* By default use front color/index. Two-sided lighting may override. */
1837 VB->Color = VB->Fcolor;
1838 VB->Index = VB->Findex;
1839
1840 switch (ctx->Primitive) {
1841 case GL_POINTS:
1842 ctx->LightTwoSide = 0;
1843 PB_INIT( PB, GL_POINT );
1844 break;
1845 case GL_LINES:
1846 case GL_LINE_STRIP:
1847 case GL_LINE_LOOP:
1848 ctx->LightTwoSide = 0;
1849 ctx->StippleCounter = 0;
1850 PB_INIT( PB, GL_LINE );
1851 break;
1852 case GL_TRIANGLES:
1853 case GL_TRIANGLE_STRIP:
1854 case GL_TRIANGLE_FAN:
1855 case GL_QUADS:
1856 case GL_QUAD_STRIP:
1857 case GL_POLYGON:
1858 ctx->LightTwoSide = (GLuint) ctx->Light.Model.TwoSide;
1859 PB_INIT( PB, GL_POLYGON );
1860 break;
1861 default:
1862 gl_error( ctx, GL_INVALID_ENUM, "glBegin" );
1863 ctx->Primitive = GL_BITMAP;
1864 }
1865 }
1866
1867
1868
1869 void gl_End( GLcontext *ctx )
1870 {
1871 struct pixel_buffer *PB = ctx->PB;
1872 struct vertex_buffer *VB = ctx->VB;
1873
1874 if (ctx->Primitive==GL_BITMAP) {
1875 /* glEnd without glBegin */
1876 gl_error( ctx, GL_INVALID_OPERATION, "glEnd" );
1877 return;
1878 }
1879
1880 if (VB->Count>VB->Start) {
1881 gl_transform_vb_part1( ctx, GL_TRUE );
1882 }
1883 if (PB->count>0) {
1884 gl_flush_pb(ctx);
1885 }
1886 PB->primitive = ctx->Primitive = GL_BITMAP; /* Default mode */
1887 VB->MaterialChanges = GL_FALSE;
1888
1889 if (ctx->Driver.End) {
1890 (*ctx->Driver.End)(ctx);
1891 }
1892
1893 #ifdef PROFILE
1894 ctx->BeginEndTime += gl_time() - begin_time;
1895 ctx->BeginEndCount++;
1896 #endif
1897 }
1898