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