fix for moebius infinite loop
[mesa.git] / src / mesa / drivers / common / t_dd_vbtmp.h
1 /* $Id: t_dd_vbtmp.h,v 1.14 2001/05/03 16:49:28 keithw Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 * Authors:
27 * Keith Whitwell <keithw@valinux.com>
28 */
29
30
31 /* Unlike the other templates here, this assumes quite a bit about the
32 * underlying hardware. Specifically it assumes a d3d-like vertex
33 * format, with a layout more or less constrained to look like the
34 * following:
35 *
36 * union {
37 * struct {
38 * float x, y, z, w;
39 * struct { char r, g, b, a; } color;
40 * struct { char r, g, b, fog; } spec;
41 * float u0, v0;
42 * float u1, v1;
43 * float u2, v2;
44 * float u3, v3;
45 * } v;
46 * struct {
47 * float x, y, z, w;
48 * struct { char r, g, b, a; } color;
49 * struct { char r, g, b, fog; } spec;
50 * float u0, v0, q0;
51 * float u1, v1, q1;
52 * float u2, v2, q2;
53 * float u3, v3, q3;
54 * } pv;
55 * struct {
56 * float x, y, z;
57 * struct { char r, g, b, a; } color;
58 * } tv;
59 * float f[16];
60 * unsigned int ui[16];
61 * unsigned char ub4[4][16];
62 * }
63 *
64
65 * DO_XYZW: Emit xyz and maybe w coordinates.
66 * DO_RGBA: Emit color.
67 * DO_SPEC: Emit specular color.
68 * DO_FOG: Emit fog coordinate in specular alpha.
69 * DO_TEX0: Emit tex0 u,v coordinates.
70 * DO_TEX1: Emit tex1 u,v coordinates.
71 * DO_TEX2: Emit tex2 u,v coordinates.
72 * DO_TEX3: Emit tex3 u,v coordinates.
73 * DO_PTEX: Emit tex0,1,2,3 q coordinates where possible.
74 *
75 * HAVE_RGBA_COLOR: Hardware takes color in rgba order (else bgra).
76 *
77 * HAVE_HW_VIEWPORT: Hardware performs viewport transform.
78 * HAVE_HW_DIVIDE: Hardware performs perspective divide.
79 *
80 * HAVE_TINY_VERTICES: Hardware understands v.tv format.
81 * HAVE_PTEX_VERTICES: Hardware understands v.pv format.
82 * HAVE_NOTEX_VERTICES: Hardware understands v.v format with texcount 0.
83 *
84 * Additionally, this template assumes it is emitting *transformed*
85 * vertices; the modifications to emit untransformed vertices (ie. to
86 * t&l hardware) are probably too great to cooexist with the code
87 * already in this file.
88 *
89 * NOTE: The PTEX vertex format always includes TEX0 and TEX1, even if
90 * only TEX0 is enabled, in order to maintain a vertex size which is
91 * an exact number of quadwords.
92 */
93
94 #if (HAVE_HW_VIEWPORT)
95 #define VIEWPORT_X(dst,x) dst = x
96 #define VIEWPORT_Y(dst,y) dst = y
97 #define VIEWPORT_Z(dst,z) dst = z
98 #else
99 #define VIEWPORT_X(dst,x) dst = s[0] * x + s[12]
100 #define VIEWPORT_Y(dst,y) dst = s[5] * y + s[13]
101 #define VIEWPORT_Z(dst,z) dst = s[10] * z + s[14]
102 #endif
103
104 #if (HAVE_HW_DIVIDE && !HAVE_PTEX_VERTICES)
105 #error "can't cope with this combination"
106 #endif
107
108 #ifndef LOCALVARS
109 #define LOCALVARS
110 #endif
111
112 #ifndef CHECK_HW_DIVIDE
113 #define CHECK_HW_DIVIDE 1
114 #endif
115
116 #if (HAVE_HW_DIVIDE || DO_SPEC || DO_TEX0 || DO_FOG || !HAVE_TINY_VERTICES)
117
118 static void TAG(emit)( GLcontext *ctx,
119 GLuint start, GLuint end,
120 void *dest,
121 GLuint stride )
122 {
123 LOCALVARS
124 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
125 GLfloat (*tc0)[4], (*tc1)[4], *fog;
126 GLfloat (*tc2)[4], (*tc3)[4];
127 GLubyte (*col)[4], (*spec)[4];
128 GLuint tc0_stride, tc1_stride, col_stride, spec_stride, fog_stride;
129 GLuint tc2_stride, tc3_stride;
130 GLuint tc0_size, tc1_size;
131 GLuint tc2_size, tc3_size;
132 GLfloat (*coord)[4];
133 GLuint coord_stride;
134 VERTEX *v = (VERTEX *)dest;
135 const GLfloat *s = GET_VIEWPORT_MAT();
136 const GLubyte *mask = VB->ClipMask;
137 int i;
138
139 if (HAVE_HW_VIEWPORT && HAVE_HW_DIVIDE && CHECK_HW_DIVIDE) {
140 (void) s;
141 coord = VB->ClipPtr->data;
142 coord_stride = VB->ClipPtr->stride;
143 }
144 else {
145 coord = VB->ProjectedClipPtr->data;
146 coord_stride = VB->ProjectedClipPtr->stride;
147 }
148
149 if (DO_TEX3) {
150 const GLuint t3 = GET_TEXSOURCE(3);
151 tc3 = VB->TexCoordPtr[t3]->data;
152 tc3_stride = VB->TexCoordPtr[t3]->stride;
153 if (DO_PTEX)
154 tc3_size = VB->TexCoordPtr[t3]->size;
155 }
156
157 if (DO_TEX2) {
158 const GLuint t2 = GET_TEXSOURCE(2);
159 tc2 = VB->TexCoordPtr[t2]->data;
160 tc2_stride = VB->TexCoordPtr[t2]->stride;
161 if (DO_PTEX)
162 tc2_size = VB->TexCoordPtr[t2]->size;
163 }
164
165 if (DO_TEX1) {
166 const GLuint t1 = GET_TEXSOURCE(1);
167 tc1 = VB->TexCoordPtr[t1]->data;
168 tc1_stride = VB->TexCoordPtr[t1]->stride;
169 if (DO_PTEX)
170 tc1_size = VB->TexCoordPtr[t1]->size;
171 }
172
173 if (DO_TEX0) {
174 const GLuint t0 = GET_TEXSOURCE(0);
175 tc0_stride = VB->TexCoordPtr[t0]->stride;
176 tc0 = VB->TexCoordPtr[t0]->data;
177 if (DO_PTEX)
178 tc0_size = VB->TexCoordPtr[t0]->size;
179 }
180
181 if (DO_RGBA) {
182 if (VB->ColorPtr[0]->Type != GL_UNSIGNED_BYTE)
183 IMPORT_FLOAT_COLORS( ctx );
184 col = (GLubyte (*)[4])VB->ColorPtr[0]->Ptr;
185 col_stride = VB->ColorPtr[0]->StrideB;
186 }
187
188 if (DO_SPEC) {
189 if (VB->SecondaryColorPtr[0]->Type != GL_UNSIGNED_BYTE)
190 IMPORT_FLOAT_SPEC_COLORS( ctx );
191 spec = (GLubyte (*)[4])VB->SecondaryColorPtr[0]->Ptr;
192 spec_stride = VB->SecondaryColorPtr[0]->StrideB;
193 }
194
195 if (DO_FOG) {
196 fog = VB->FogCoordPtr->data;
197 fog_stride = VB->FogCoordPtr->stride;
198 }
199
200 if (VB->importable_data) {
201 /* May have nonstandard strides:
202 */
203 if (start) {
204 coord = (GLfloat (*)[4])((GLubyte *)coord + start * coord_stride);
205 if (DO_TEX0)
206 tc0 = (GLfloat (*)[4])((GLubyte *)tc0 + start * tc0_stride);
207 if (DO_TEX1)
208 tc1 = (GLfloat (*)[4])((GLubyte *)tc1 + start * tc1_stride);
209 if (DO_TEX2)
210 tc2 = (GLfloat (*)[4])((GLubyte *)tc2 + start * tc2_stride);
211 if (DO_TEX3)
212 tc3 = (GLfloat (*)[4])((GLubyte *)tc3 + start * tc3_stride);
213 if (DO_RGBA)
214 STRIDE_4UB(col, start * col_stride);
215 if (DO_SPEC)
216 STRIDE_4UB(spec, start * spec_stride);
217 if (DO_FOG)
218 STRIDE_F(fog, start * fog_stride);
219 }
220
221 for (i=start; i < end; i++, v = (VERTEX *)((GLubyte *)v + stride)) {
222 if (DO_XYZW) {
223 if (HAVE_HW_VIEWPORT || mask[i] == 0) {
224 VIEWPORT_X(v->v.x, coord[0][0]);
225 VIEWPORT_Y(v->v.y, coord[0][1]);
226 VIEWPORT_Z(v->v.z, coord[0][2]);
227 v->v.w = coord[0][3];
228 }
229 coord = (GLfloat (*)[4])((GLubyte *)coord + coord_stride);
230 }
231 if (DO_RGBA) {
232 if (HAVE_RGBA_COLOR) {
233 *(GLuint *)&v->v.color = *(GLuint *)&col[0];
234 STRIDE_4UB(col, col_stride);
235 } else {
236 v->v.color.blue = col[0][2];
237 v->v.color.green = col[0][1];
238 v->v.color.red = col[0][0];
239 v->v.color.alpha = col[0][3];
240 STRIDE_4UB(col, col_stride);
241 }
242 }
243 if (DO_SPEC) {
244 v->v.specular.red = spec[0][0];
245 v->v.specular.green = spec[0][1];
246 v->v.specular.blue = spec[0][2];
247 STRIDE_4UB(spec, spec_stride);
248 }
249 if (DO_FOG) {
250 v->v.specular.alpha = fog[0] * 255.0;
251 STRIDE_F(fog, fog_stride);
252 }
253 if (DO_TEX0) {
254 v->v.u0 = tc0[0][0];
255 v->v.v0 = tc0[0][1];
256 if (DO_PTEX) {
257 if (HAVE_PTEX_VERTICES) {
258 if (tc0_size == 4)
259 v->pv.q0 = tc0[0][3];
260 else
261 v->pv.q0 = 1.0;
262 }
263 else if (tc0_size == 4) {
264 float rhw = 1.0 / tc0[0][3];
265 v->v.w *= tc0[0][3];
266 v->v.u0 *= rhw;
267 v->v.v0 *= rhw;
268 }
269 }
270 tc0 = (GLfloat (*)[4])((GLubyte *)tc0 + tc0_stride);
271 }
272 if (DO_TEX1) {
273 if (DO_PTEX) {
274 v->pv.u1 = tc1[0][0];
275 v->pv.v1 = tc1[0][1];
276 if (tc1_size == 4)
277 v->pv.q1 = tc1[0][3];
278 else
279 v->pv.q1 = 1.0;
280 }
281 else {
282 v->v.u1 = tc1[0][0];
283 v->v.v1 = tc1[0][1];
284 }
285 tc1 = (GLfloat (*)[4])((GLubyte *)tc1 + tc1_stride);
286 }
287 else if (DO_PTEX) {
288 *(GLuint *)&v->pv.q1 = 0; /* avoid culling on radeon */
289 }
290 if (DO_TEX2) {
291 if (DO_PTEX) {
292 v->pv.u2 = tc2[0][0];
293 v->pv.v2 = tc2[0][1];
294 if (tc2_size == 4)
295 v->pv.q2 = tc2[0][3];
296 else
297 v->pv.q2 = 1.0;
298 }
299 else {
300 v->v.u2 = tc2[0][0];
301 v->v.v2 = tc2[0][1];
302 }
303 tc2 = (GLfloat (*)[4])((GLubyte *)tc2 + tc2_stride);
304 }
305 if (DO_TEX3) {
306 if (DO_PTEX) {
307 v->pv.u3 = tc3[0][0];
308 v->pv.v3 = tc3[0][1];
309 if (tc3_size == 4)
310 v->pv.q3 = tc3[0][3];
311 else
312 v->pv.q3 = 1.0;
313 }
314 else {
315 v->v.u3 = tc3[0][0];
316 v->v.v3 = tc3[0][1];
317 }
318 tc3 = (GLfloat (*)[4])((GLubyte *)tc3 + tc3_stride);
319 }
320 }
321 }
322 else {
323 for (i=start; i < end; i++, v = (VERTEX *)((GLubyte *)v + stride)) {
324 if (DO_XYZW) {
325 if (HAVE_HW_VIEWPORT || mask[i] == 0) {
326 VIEWPORT_X(v->v.x, coord[i][0]);
327 VIEWPORT_Y(v->v.y, coord[i][1]);
328 VIEWPORT_Z(v->v.z, coord[i][2]);
329 v->v.w = coord[i][3];
330 }
331 }
332 if (DO_RGBA) {
333 if (HAVE_RGBA_COLOR) {
334 *(GLuint *)&v->v.color = *(GLuint *)&col[i];
335 }
336 else {
337 v->v.color.blue = col[i][2];
338 v->v.color.green = col[i][1];
339 v->v.color.red = col[i][0];
340 v->v.color.alpha = col[i][3];
341 }
342 }
343 if (DO_SPEC) {
344 v->v.specular.red = spec[i][0];
345 v->v.specular.green = spec[i][1];
346 v->v.specular.blue = spec[i][2];
347 }
348 if (DO_FOG) {
349 v->v.specular.alpha = fog[i] * 255.0;
350 }
351 if (DO_TEX0) {
352 v->v.u0 = tc0[i][0];
353 v->v.v0 = tc0[i][1];
354 if (DO_PTEX) {
355 if (HAVE_PTEX_VERTICES) {
356 if (tc0_size == 4)
357 v->pv.q0 = tc0[i][3];
358 else
359 v->pv.q0 = 1.0;
360
361 v->pv.q1 = 0; /* radeon */
362 }
363 else if (tc0_size == 4) {
364 float rhw = 1.0 / tc0[i][3];
365 v->v.w *= tc0[i][3];
366 v->v.u0 *= rhw;
367 v->v.v0 *= rhw;
368 }
369 }
370 }
371 if (DO_TEX1) {
372 if (DO_PTEX) {
373 v->pv.u1 = tc1[i][0];
374 v->pv.v1 = tc1[i][1];
375 if (tc1_size == 4)
376 v->pv.q1 = tc1[i][3];
377 else
378 v->pv.q1 = 1.0;
379 }
380 else {
381 v->v.u1 = tc1[i][0];
382 v->v.v1 = tc1[i][1];
383 }
384 }
385 }
386 }
387 }
388 #else
389 #if DO_XYZW
390
391 #if HAVE_HW_DIVIDE
392 #error "cannot use tiny vertices with hw perspective divide"
393 #endif
394
395 static void TAG(emit)( GLcontext *ctx, GLuint start, GLuint end,
396 void *dest, GLuint stride )
397 {
398 LOCALVARS
399 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
400 GLubyte (*col)[4];
401 GLuint col_stride;
402 GLfloat (*coord)[4] = VB->ProjectedClipPtr->data;
403 GLuint coord_stride = VB->ProjectedClipPtr->stride;
404 GLfloat *v = (GLfloat *)dest;
405 const GLubyte *mask = VB->ClipMask;
406 const GLfloat *s = GET_VIEWPORT_MAT();
407 int i;
408
409 (void) s;
410
411 ASSERT(stride == 4);
412
413 if (VB->ColorPtr[0]->Type != GL_UNSIGNED_BYTE)
414 IMPORT_FLOAT_COLORS( ctx );
415
416 col = (GLubyte (*)[4])VB->ColorPtr[0]->Ptr;
417 col_stride = VB->ColorPtr[0]->StrideB;
418 ASSERT(VB->ColorPtr[0]->Type == GL_UNSIGNED_BYTE);
419
420 /* fprintf(stderr, "%s stride %d importable %d\n", */
421 /* __FUNCTION__, col_stride, VB->importable_data); */
422
423 /* Pack what's left into a 4-dword vertex. Color is in a different
424 * place, and there is no 'w' coordinate.
425 */
426 if (VB->importable_data) {
427 if (start) {
428 coord = (GLfloat (*)[4])((GLubyte *)coord + start * coord_stride);
429 STRIDE_4UB(col, start * col_stride);
430 }
431
432 for (i=start; i < end; i++, v+=4) {
433 if (HAVE_HW_VIEWPORT || mask[i] == 0) {
434 VIEWPORT_X(v[0], coord[0][0]);
435 VIEWPORT_Y(v[1], coord[0][1]);
436 VIEWPORT_Z(v[2], coord[0][2]);
437 }
438 coord = (GLfloat (*)[4])((GLubyte *)coord + coord_stride);
439 if (DO_RGBA) {
440 if (HAVE_RGBA_COLOR) {
441 *(GLuint *)&v[3] = *(GLuint *)col;
442 }
443 else {
444 GLubyte *b = (GLubyte *)&v[3];
445 b[0] = col[0][2];
446 b[1] = col[0][1];
447 b[2] = col[0][0];
448 b[3] = col[0][3];
449 }
450 STRIDE_4UB( col, col_stride );
451 }
452 }
453 }
454 else {
455 for (i=start; i < end; i++, v+=4) {
456 if (HAVE_HW_VIEWPORT || mask[i] == 0) {
457 VIEWPORT_X(v[0], coord[i][0]);
458 VIEWPORT_Y(v[1], coord[i][1]);
459 VIEWPORT_Z(v[2], coord[i][2]);
460 }
461 if (DO_RGBA) {
462 if (HAVE_RGBA_COLOR) {
463 *(GLuint *)&v[3] = *(GLuint *)&col[i];
464 }
465 else {
466 GLubyte *b = (GLubyte *)&v[3];
467 b[0] = col[i][2];
468 b[1] = col[i][1];
469 b[2] = col[i][0];
470 b[3] = col[i][3];
471 }
472 }
473 }
474 }
475 }
476 #else
477 static void TAG(emit)( GLcontext *ctx, GLuint start, GLuint end,
478 void *dest, GLuint stride )
479 {
480 LOCALVARS
481 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
482 GLubyte (*col)[4];
483 GLuint col_stride;
484 GLfloat *v = (GLfloat *)dest;
485 int i;
486
487 if (VB->ColorPtr[0]->Type != GL_UNSIGNED_BYTE)
488 IMPORT_FLOAT_COLORS( ctx );
489
490 col = VB->ColorPtr[0]->Ptr;
491 col_stride = VB->ColorPtr[0]->StrideB;
492
493 if (start)
494 STRIDE_4UB(col, col_stride * start);
495
496 /* Need to figure out where color is:
497 */
498 if (GET_VERTEX_FORMAT() == TINY_VERTEX_FORMAT)
499 v += 3;
500 else
501 v += 4;
502
503 for (i=start; i < end; i++, STRIDE_F(v, stride)) {
504 if (HAVE_RGBA_COLOR) {
505 *(GLuint *)v = *(GLuint *)col[0];
506 }
507 else {
508 GLubyte *b = (GLubyte *)v;
509 b[0] = col[0][2];
510 b[1] = col[0][1];
511 b[2] = col[0][0];
512 b[3] = col[0][3];
513 }
514 STRIDE_4UB( col, col_stride );
515 }
516 }
517 #endif /* emit */
518 #endif /* emit */
519
520 #if (DO_XYZW) && (DO_RGBA)
521
522
523 #if (HAVE_PTEX_VERTICES)
524 static GLboolean TAG(check_tex_sizes)( GLcontext *ctx )
525 {
526 LOCALVARS
527 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
528
529 /* Force 'missing' texcoords to something valid.
530 */
531 if (DO_TEX3 && VB->TexCoordPtr[2] == 0)
532 VB->TexCoordPtr[2] = VB->TexCoordPtr[3];
533
534 if (DO_TEX2 && VB->TexCoordPtr[1] == 0)
535 VB->TexCoordPtr[1] = VB->TexCoordPtr[2];
536
537 if (DO_TEX1 && VB->TexCoordPtr[0] == 0)
538 VB->TexCoordPtr[0] = VB->TexCoordPtr[1];
539
540 if (DO_PTEX)
541 return GL_TRUE;
542
543 if ((DO_TEX3 && VB->TexCoordPtr[GET_TEXSOURCE(3)]->size == 4) ||
544 (DO_TEX2 && VB->TexCoordPtr[GET_TEXSOURCE(2)]->size == 4) ||
545 (DO_TEX1 && VB->TexCoordPtr[GET_TEXSOURCE(1)]->size == 4) ||
546 (DO_TEX0 && VB->TexCoordPtr[GET_TEXSOURCE(0)]->size == 4))
547 return GL_FALSE;
548
549 return GL_TRUE;
550 }
551 #else
552 static GLboolean TAG(check_tex_sizes)( GLcontext *ctx )
553 {
554 LOCALVARS
555 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
556
557 /* Force 'missing' texcoords to something valid.
558 */
559 if (DO_TEX3 && VB->TexCoordPtr[2] == 0)
560 VB->TexCoordPtr[2] = VB->TexCoordPtr[3];
561
562 if (DO_TEX2 && VB->TexCoordPtr[1] == 0)
563 VB->TexCoordPtr[1] = VB->TexCoordPtr[2];
564
565 if (DO_TEX1 && VB->TexCoordPtr[0] == 0)
566 VB->TexCoordPtr[0] = VB->TexCoordPtr[1];
567
568 if (DO_PTEX)
569 return GL_TRUE;
570
571 /* No hardware support for projective texture. Can fake it for
572 * TEX0 only.
573 */
574 if ((DO_TEX3 && VB->TexCoordPtr[GET_TEXSOURCE(3)]->size == 4) ||
575 (DO_TEX2 && VB->TexCoordPtr[GET_TEXSOURCE(2)]->size == 4) ||
576 (DO_TEX1 && VB->TexCoordPtr[GET_TEXSOURCE(1)]->size == 4)) {
577 PTEX_FALLBACK();
578 return GL_FALSE;
579 }
580
581 if (DO_TEX0 && VB->TexCoordPtr[GET_TEXSOURCE(0)]->size == 4) {
582 if (DO_TEX1 || DO_TEX2 || DO_TEX3) {
583 PTEX_FALLBACK();
584 }
585 return GL_FALSE;
586 }
587
588 return GL_TRUE;
589 }
590 #endif /* ptex */
591
592
593 static void TAG(interp)( GLcontext *ctx,
594 GLfloat t,
595 GLuint edst, GLuint eout, GLuint ein,
596 GLboolean force_boundary )
597 {
598 LOCALVARS
599 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
600 GLubyte *ddverts = GET_VERTEX_STORE();
601 GLuint shift = GET_VERTEX_STRIDE_SHIFT();
602 const GLfloat *dstclip = VB->ClipPtr->data[edst];
603 GLfloat w;
604 const GLfloat *s = GET_VIEWPORT_MAT();
605
606 VERTEX *dst = (VERTEX *)(ddverts + (edst << shift));
607 VERTEX *in = (VERTEX *)(ddverts + (ein << shift));
608 VERTEX *out = (VERTEX *)(ddverts + (eout << shift));
609
610 (void)s;
611
612 if (HAVE_HW_DIVIDE && CHECK_HW_DIVIDE) {
613 VIEWPORT_X( dst->v.x, dstclip[0] );
614 VIEWPORT_Y( dst->v.y, dstclip[1] );
615 VIEWPORT_Z( dst->v.z, dstclip[2] );
616 w = dstclip[3];
617 }
618 else {
619 w = 1.0 / dstclip[3];
620 VIEWPORT_X( dst->v.x, dstclip[0] * w );
621 VIEWPORT_Y( dst->v.y, dstclip[1] * w );
622 VIEWPORT_Z( dst->v.z, dstclip[2] * w );
623 }
624
625 if ((HAVE_HW_DIVIDE && CHECK_HW_DIVIDE) ||
626 DO_FOG || DO_SPEC || DO_TEX0 || DO_TEX1 ||
627 DO_TEX2 || DO_TEX3) {
628
629 dst->v.w = w;
630
631 INTERP_UB( t, dst->ub4[4][0], out->ub4[4][0], in->ub4[4][0] );
632 INTERP_UB( t, dst->ub4[4][1], out->ub4[4][1], in->ub4[4][1] );
633 INTERP_UB( t, dst->ub4[4][2], out->ub4[4][2], in->ub4[4][2] );
634 INTERP_UB( t, dst->ub4[4][3], out->ub4[4][3], in->ub4[4][3] );
635
636 if (DO_SPEC) {
637 INTERP_UB( t, dst->ub4[5][0], out->ub4[5][0], in->ub4[5][0] );
638 INTERP_UB( t, dst->ub4[5][1], out->ub4[5][1], in->ub4[5][1] );
639 INTERP_UB( t, dst->ub4[5][2], out->ub4[5][2], in->ub4[5][2] );
640 }
641 if (DO_FOG) {
642 INTERP_UB( t, dst->ub4[5][3], out->ub4[5][3], in->ub4[5][3] );
643 }
644 if (DO_TEX0) {
645 if (DO_PTEX) {
646 if (HAVE_PTEX_VERTICES) {
647 INTERP_F( t, dst->pv.u0, out->pv.u0, in->pv.u0 );
648 INTERP_F( t, dst->pv.v0, out->pv.v0, in->pv.v0 );
649 INTERP_F( t, dst->pv.q0, out->pv.q0, in->pv.q0 );
650 } else {
651 GLfloat wout = VB->ProjectedClipPtr->data[eout][3];
652 GLfloat win = VB->ProjectedClipPtr->data[ein][3];
653 GLfloat qout = out->pv.w / wout;
654 GLfloat qin = in->pv.w / win;
655 GLfloat qdst, rqdst;
656
657 ASSERT( !HAVE_HW_DIVIDE );
658
659 INTERP_F( t, dst->v.u0, out->v.u0 * qout, in->v.u0 * qin );
660 INTERP_F( t, dst->v.v0, out->v.v0 * qout, in->v.v0 * qin );
661 INTERP_F( t, qdst, qout, qin );
662
663 rqdst = 1.0 / qdst;
664 dst->v.u0 *= rqdst;
665 dst->v.v0 *= rqdst;
666 dst->v.w *= rqdst;
667 }
668 }
669 else {
670 INTERP_F( t, dst->v.u0, out->v.u0, in->v.u0 );
671 INTERP_F( t, dst->v.v0, out->v.v0, in->v.v0 );
672 }
673 }
674 if (DO_TEX1) {
675 if (DO_PTEX) {
676 INTERP_F( t, dst->pv.u1, out->pv.u1, in->pv.u1 );
677 INTERP_F( t, dst->pv.v1, out->pv.v1, in->pv.v1 );
678 INTERP_F( t, dst->pv.q1, out->pv.q1, in->pv.q1 );
679 } else {
680 INTERP_F( t, dst->v.u1, out->v.u1, in->v.u1 );
681 INTERP_F( t, dst->v.v1, out->v.v1, in->v.v1 );
682 }
683 }
684 else if (DO_PTEX) {
685 dst->pv.q0 = 0.0; /* must be a valid float on radeon */
686 }
687 if (DO_TEX2) {
688 if (DO_PTEX) {
689 INTERP_F( t, dst->pv.u2, out->pv.u2, in->pv.u2 );
690 INTERP_F( t, dst->pv.v2, out->pv.v2, in->pv.v2 );
691 INTERP_F( t, dst->pv.q2, out->pv.q2, in->pv.q2 );
692 } else {
693 INTERP_F( t, dst->v.u2, out->v.u2, in->v.u2 );
694 INTERP_F( t, dst->v.v2, out->v.v2, in->v.v2 );
695 }
696 }
697 if (DO_TEX3) {
698 if (DO_PTEX) {
699 INTERP_F( t, dst->pv.u3, out->pv.u3, in->pv.u3 );
700 INTERP_F( t, dst->pv.v3, out->pv.v3, in->pv.v3 );
701 INTERP_F( t, dst->pv.q3, out->pv.q3, in->pv.q3 );
702 } else {
703 INTERP_F( t, dst->v.u3, out->v.u3, in->v.u3 );
704 INTERP_F( t, dst->v.v3, out->v.v3, in->v.v3 );
705 }
706 }
707 } else {
708 /* 4-dword vertex. Color is in v[3] and there is no oow coordinate.
709 */
710 INTERP_UB( t, dst->ub4[3][0], out->ub4[3][0], in->ub4[3][0] );
711 INTERP_UB( t, dst->ub4[3][1], out->ub4[3][1], in->ub4[3][1] );
712 INTERP_UB( t, dst->ub4[3][2], out->ub4[3][2], in->ub4[3][2] );
713 INTERP_UB( t, dst->ub4[3][3], out->ub4[3][3], in->ub4[3][3] );
714 }
715 }
716
717 #endif /* rgba && xyzw */
718
719
720 static void TAG(init)( void )
721 {
722 setup_tab[IND].emit = TAG(emit);
723
724 #if (DO_XYZW && DO_RGBA)
725 setup_tab[IND].check_tex_sizes = TAG(check_tex_sizes);
726 setup_tab[IND].interp = TAG(interp);
727 #endif
728
729 if (DO_SPEC)
730 setup_tab[IND].copy_pv = copy_pv_rgba4_spec5;
731 else if (HAVE_HW_DIVIDE || DO_SPEC || DO_FOG || DO_TEX0 || DO_TEX1 ||
732 DO_TEX2 || DO_TEX3)
733 setup_tab[IND].copy_pv = copy_pv_rgba4;
734 else
735 setup_tab[IND].copy_pv = copy_pv_rgba3;
736
737 if (DO_TEX3) {
738 if (DO_PTEX) {
739 ASSERT(HAVE_PTEX_VERTICES);
740 setup_tab[IND].vertex_format = PROJ_TEX3_VERTEX_FORMAT;
741 setup_tab[IND].vertex_size = 18;
742 setup_tab[IND].vertex_stride_shift = 7;
743 }
744 else {
745 setup_tab[IND].vertex_format = TEX3_VERTEX_FORMAT;
746 setup_tab[IND].vertex_size = 14;
747 setup_tab[IND].vertex_stride_shift = 6;
748 }
749 }
750 else if (DO_TEX2) {
751 if (DO_PTEX) {
752 ASSERT(HAVE_PTEX_VERTICES);
753 setup_tab[IND].vertex_format = PROJ_TEX3_VERTEX_FORMAT;
754 setup_tab[IND].vertex_size = 18;
755 setup_tab[IND].vertex_stride_shift = 7;
756 }
757 else {
758 setup_tab[IND].vertex_format = TEX2_VERTEX_FORMAT;
759 setup_tab[IND].vertex_size = 12;
760 setup_tab[IND].vertex_stride_shift = 6;
761 }
762 }
763 else if (DO_TEX1) {
764 if (DO_PTEX) {
765 ASSERT(HAVE_PTEX_VERTICES);
766 setup_tab[IND].vertex_format = PROJ_TEX1_VERTEX_FORMAT;
767 setup_tab[IND].vertex_size = 12;
768 setup_tab[IND].vertex_stride_shift = 6;
769 }
770 else {
771 setup_tab[IND].vertex_format = TEX1_VERTEX_FORMAT;
772 setup_tab[IND].vertex_size = 10;
773 setup_tab[IND].vertex_stride_shift = 6;
774 }
775 }
776 else if (DO_TEX0) {
777 if (DO_PTEX && HAVE_PTEX_VERTICES) {
778 setup_tab[IND].vertex_format = PROJ_TEX1_VERTEX_FORMAT;
779 setup_tab[IND].vertex_size = 12;
780 setup_tab[IND].vertex_stride_shift = 6;
781 } else {
782 setup_tab[IND].vertex_format = TEX0_VERTEX_FORMAT;
783 setup_tab[IND].vertex_size = 8;
784 setup_tab[IND].vertex_stride_shift = 5;
785 }
786 }
787 else if (!HAVE_HW_DIVIDE && !DO_SPEC && !DO_FOG && HAVE_TINY_VERTICES) {
788 setup_tab[IND].vertex_format = TINY_VERTEX_FORMAT;
789 setup_tab[IND].vertex_size = 4;
790 setup_tab[IND].vertex_stride_shift = 4;
791 } else if (HAVE_NOTEX_VERTICES) {
792 setup_tab[IND].vertex_format = NOTEX_VERTEX_FORMAT;
793 setup_tab[IND].vertex_size = 6;
794 setup_tab[IND].vertex_stride_shift = 5;
795 } else {
796 setup_tab[IND].vertex_format = TEX0_VERTEX_FORMAT;
797 setup_tab[IND].vertex_size = 8;
798 setup_tab[IND].vertex_stride_shift = 5;
799 }
800
801 assert(setup_tab[IND].vertex_size * 4 <=
802 1 << setup_tab[IND].vertex_stride_shift);
803 }
804
805
806 #undef IND
807 #undef TAG