-O -Wall warnings cleanups in r200.
[mesa.git] / src / mesa / drivers / dri / r200 / r200_vtxfmt_c.c
1 /* $XFree86: xc/lib/GL/mesa/src/drv/r200/r200_vtxfmt_c.c,v 1.2 2002/12/16 16:18:56 dawes Exp $ */
2 /*
3 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
4
5 The Weather Channel (TM) funded Tungsten Graphics to develop the
6 initial release of the Radeon 8500 driver under the XFree86 license.
7 This notice must be preserved.
8
9 Permission is hereby granted, free of charge, to any person obtaining
10 a copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sublicense, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
16
17 The above copyright notice and this permission notice (including the
18 next paragraph) shall be included in all copies or substantial
19 portions of the Software.
20
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
25 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
29 **************************************************************************/
30
31 /*
32 * Authors:
33 * Keith Whitwell <keith@tungstengraphics.com>
34 */
35
36 #include "glheader.h"
37 #include "imports.h"
38 #include "mtypes.h"
39 #include "colormac.h"
40 #include "simple_list.h"
41 #include "api_noop.h"
42 #include "vtxfmt.h"
43
44 #include "r200_vtxfmt.h"
45
46 /* Fallback versions of all the entrypoints for situations where
47 * codegen isn't available. This is still a lot faster than the
48 * vb/pipeline implementation in Mesa.
49 */
50 static void r200_Vertex3f( GLfloat x, GLfloat y, GLfloat z )
51 {
52 GET_CURRENT_CONTEXT(ctx);
53 r200ContextPtr rmesa = R200_CONTEXT(ctx);
54 int i;
55
56 *rmesa->vb.dmaptr++ = *(int *)&x;
57 *rmesa->vb.dmaptr++ = *(int *)&y;
58 *rmesa->vb.dmaptr++ = *(int *)&z;
59
60 for (i = 3; i < rmesa->vb.vertex_size; i++)
61 *rmesa->vb.dmaptr++ = rmesa->vb.vertex[i].i;
62
63 if (--rmesa->vb.counter == 0)
64 rmesa->vb.notify();
65 }
66
67
68 static void r200_Vertex3fv( const GLfloat *v )
69 {
70 GET_CURRENT_CONTEXT(ctx);
71 r200ContextPtr rmesa = R200_CONTEXT(ctx);
72 int i;
73
74 *rmesa->vb.dmaptr++ = *(int *)&v[0];
75 *rmesa->vb.dmaptr++ = *(int *)&v[1];
76 *rmesa->vb.dmaptr++ = *(int *)&v[2];
77
78 for (i = 3; i < rmesa->vb.vertex_size; i++)
79 *rmesa->vb.dmaptr++ = rmesa->vb.vertex[i].i;
80
81 if (--rmesa->vb.counter == 0)
82 rmesa->vb.notify();
83 }
84
85
86 static void r200_Vertex2f( GLfloat x, GLfloat y )
87 {
88 GET_CURRENT_CONTEXT(ctx);
89 r200ContextPtr rmesa = R200_CONTEXT(ctx);
90 int i;
91
92 *rmesa->vb.dmaptr++ = *(int *)&x;
93 *rmesa->vb.dmaptr++ = *(int *)&y;
94 *rmesa->vb.dmaptr++ = 0;
95
96 for (i = 3; i < rmesa->vb.vertex_size; i++)
97 *rmesa->vb.dmaptr++ = rmesa->vb.vertex[i].i;
98
99 if (--rmesa->vb.counter == 0)
100 rmesa->vb.notify();
101 }
102
103
104 static void r200_Vertex2fv( const GLfloat *v )
105 {
106 GET_CURRENT_CONTEXT(ctx);
107 r200ContextPtr rmesa = R200_CONTEXT(ctx);
108 int i;
109
110 *rmesa->vb.dmaptr++ = *(int *)&v[0];
111 *rmesa->vb.dmaptr++ = *(int *)&v[1];
112 *rmesa->vb.dmaptr++ = 0;
113
114 for (i = 3; i < rmesa->vb.vertex_size; i++)
115 *rmesa->vb.dmaptr++ = rmesa->vb.vertex[i].i;
116
117 if (--rmesa->vb.counter == 0)
118 rmesa->vb.notify();
119 }
120
121
122
123 /* Color for ubyte (packed) color formats:
124 */
125 #if 0
126 static void r200_Color3ub_ub( GLubyte r, GLubyte g, GLubyte b )
127 {
128 GET_CURRENT_CONTEXT(ctx);
129 r200ContextPtr rmesa = R200_CONTEXT(ctx);
130 r200_color_t *dest = rmesa->vb.colorptr;
131 dest->red = r;
132 dest->green = g;
133 dest->blue = b;
134 dest->alpha = 0xff;
135 }
136
137 static void r200_Color3ubv_ub( const GLubyte *v )
138 {
139 GET_CURRENT_CONTEXT(ctx);
140 r200ContextPtr rmesa = R200_CONTEXT(ctx);
141 r200_color_t *dest = rmesa->vb.colorptr;
142 dest->red = v[0];
143 dest->green = v[1];
144 dest->blue = v[2];
145 dest->alpha = 0xff;
146 }
147
148 static void r200_Color4ub_ub( GLubyte r, GLubyte g, GLubyte b, GLubyte a )
149 {
150 GET_CURRENT_CONTEXT(ctx);
151 r200ContextPtr rmesa = R200_CONTEXT(ctx);
152 r200_color_t *dest = rmesa->vb.colorptr;
153 dest->red = r;
154 dest->green = g;
155 dest->blue = b;
156 dest->alpha = a;
157 }
158
159 static void r200_Color4ubv_ub( const GLubyte *v )
160 {
161 GET_CURRENT_CONTEXT(ctx);
162 r200ContextPtr rmesa = R200_CONTEXT(ctx);
163 *(GLuint *)rmesa->vb.colorptr = LE32_TO_CPU(*(GLuint *)v);
164 }
165 #endif /* 0 */
166
167 static void r200_Color3f_ub( GLfloat r, GLfloat g, GLfloat b )
168 {
169 GET_CURRENT_CONTEXT(ctx);
170 r200ContextPtr rmesa = R200_CONTEXT(ctx);
171 r200_color_t *dest = rmesa->vb.colorptr;
172 UNCLAMPED_FLOAT_TO_UBYTE( dest->red, r );
173 UNCLAMPED_FLOAT_TO_UBYTE( dest->green, g );
174 UNCLAMPED_FLOAT_TO_UBYTE( dest->blue, b );
175 dest->alpha = 255;
176 }
177
178 static void r200_Color3fv_ub( const GLfloat *v )
179 {
180 GET_CURRENT_CONTEXT(ctx);
181 r200ContextPtr rmesa = R200_CONTEXT(ctx);
182 r200_color_t *dest = rmesa->vb.colorptr;
183 UNCLAMPED_FLOAT_TO_UBYTE( dest->red, v[0] );
184 UNCLAMPED_FLOAT_TO_UBYTE( dest->green, v[1] );
185 UNCLAMPED_FLOAT_TO_UBYTE( dest->blue, v[2] );
186 dest->alpha = 255;
187 }
188
189 static void r200_Color4f_ub( GLfloat r, GLfloat g, GLfloat b, GLfloat a )
190 {
191 GET_CURRENT_CONTEXT(ctx);
192 r200ContextPtr rmesa = R200_CONTEXT(ctx);
193 r200_color_t *dest = rmesa->vb.colorptr;
194 UNCLAMPED_FLOAT_TO_UBYTE( dest->red, r );
195 UNCLAMPED_FLOAT_TO_UBYTE( dest->green, g );
196 UNCLAMPED_FLOAT_TO_UBYTE( dest->blue, b );
197 UNCLAMPED_FLOAT_TO_UBYTE( dest->alpha, a );
198 }
199
200 static void r200_Color4fv_ub( const GLfloat *v )
201 {
202 GET_CURRENT_CONTEXT(ctx);
203 r200ContextPtr rmesa = R200_CONTEXT(ctx);
204 r200_color_t *dest = rmesa->vb.colorptr;
205 UNCLAMPED_FLOAT_TO_UBYTE( dest->red, v[0] );
206 UNCLAMPED_FLOAT_TO_UBYTE( dest->green, v[1] );
207 UNCLAMPED_FLOAT_TO_UBYTE( dest->blue, v[2] );
208 UNCLAMPED_FLOAT_TO_UBYTE( dest->alpha, v[3] );
209 }
210
211
212 /* Color for float color+alpha formats:
213 */
214 #if 0
215 static void r200_Color3ub_4f( GLubyte r, GLubyte g, GLubyte b )
216 {
217 GET_CURRENT_CONTEXT(ctx);
218 r200ContextPtr rmesa = R200_CONTEXT(ctx);
219 GLfloat *dest = rmesa->vb.floatcolorptr;
220 dest[0] = UBYTE_TO_FLOAT(r);
221 dest[1] = UBYTE_TO_FLOAT(g);
222 dest[2] = UBYTE_TO_FLOAT(b);
223 dest[3] = 1.0;
224 }
225
226 static void r200_Color3ubv_4f( const GLubyte *v )
227 {
228 GET_CURRENT_CONTEXT(ctx);
229 r200ContextPtr rmesa = R200_CONTEXT(ctx);
230 GLfloat *dest = rmesa->vb.floatcolorptr;
231 dest[0] = UBYTE_TO_FLOAT(v[0]);
232 dest[1] = UBYTE_TO_FLOAT(v[1]);
233 dest[2] = UBYTE_TO_FLOAT(v[2]);
234 dest[3] = 1.0;
235 }
236
237 static void r200_Color4ub_4f( GLubyte r, GLubyte g, GLubyte b, GLubyte a )
238 {
239 GET_CURRENT_CONTEXT(ctx);
240 r200ContextPtr rmesa = R200_CONTEXT(ctx);
241 GLfloat *dest = rmesa->vb.floatcolorptr;
242 dest[0] = UBYTE_TO_FLOAT(r);
243 dest[1] = UBYTE_TO_FLOAT(g);
244 dest[2] = UBYTE_TO_FLOAT(b);
245 dest[3] = UBYTE_TO_FLOAT(a);
246 }
247
248 static void r200_Color4ubv_4f( const GLubyte *v )
249 {
250 GET_CURRENT_CONTEXT(ctx);
251 r200ContextPtr rmesa = R200_CONTEXT(ctx);
252 GLfloat *dest = rmesa->vb.floatcolorptr;
253 dest[0] = UBYTE_TO_FLOAT(v[0]);
254 dest[1] = UBYTE_TO_FLOAT(v[1]);
255 dest[2] = UBYTE_TO_FLOAT(v[2]);
256 dest[3] = UBYTE_TO_FLOAT(v[3]);
257 }
258 #endif /* 0 */
259
260
261 static void r200_Color3f_4f( GLfloat r, GLfloat g, GLfloat b )
262 {
263 GET_CURRENT_CONTEXT(ctx);
264 r200ContextPtr rmesa = R200_CONTEXT(ctx);
265 GLfloat *dest = rmesa->vb.floatcolorptr;
266 dest[0] = r;
267 dest[1] = g;
268 dest[2] = b;
269 dest[3] = 1.0;
270 }
271
272 static void r200_Color3fv_4f( const GLfloat *v )
273 {
274 GET_CURRENT_CONTEXT(ctx);
275 r200ContextPtr rmesa = R200_CONTEXT(ctx);
276 GLfloat *dest = rmesa->vb.floatcolorptr;
277 dest[0] = v[0];
278 dest[1] = v[1];
279 dest[2] = v[2];
280 dest[3] = 1.0;
281 }
282
283 static void r200_Color4f_4f( GLfloat r, GLfloat g, GLfloat b, GLfloat a )
284 {
285 GET_CURRENT_CONTEXT(ctx);
286 r200ContextPtr rmesa = R200_CONTEXT(ctx);
287 GLfloat *dest = rmesa->vb.floatcolorptr;
288 dest[0] = r;
289 dest[1] = g;
290 dest[2] = b;
291 dest[3] = a;
292 }
293
294 static void r200_Color4fv_4f( const GLfloat *v )
295 {
296 GET_CURRENT_CONTEXT(ctx);
297 r200ContextPtr rmesa = R200_CONTEXT(ctx);
298 GLfloat *dest = rmesa->vb.floatcolorptr;
299 dest[0] = v[0];
300 dest[1] = v[1];
301 dest[2] = v[2];
302 dest[3] = v[3];
303 }
304
305
306 /* Color for float color formats:
307 */
308 #if 0
309 static void r200_Color3ub_3f( GLubyte r, GLubyte g, GLubyte b )
310 {
311 GET_CURRENT_CONTEXT(ctx);
312 r200ContextPtr rmesa = R200_CONTEXT(ctx);
313 GLfloat *dest = rmesa->vb.floatcolorptr;
314 dest[0] = UBYTE_TO_FLOAT(r);
315 dest[1] = UBYTE_TO_FLOAT(g);
316 dest[2] = UBYTE_TO_FLOAT(b);
317 }
318
319 static void r200_Color3ubv_3f( const GLubyte *v )
320 {
321 GET_CURRENT_CONTEXT(ctx);
322 r200ContextPtr rmesa = R200_CONTEXT(ctx);
323 GLfloat *dest = rmesa->vb.floatcolorptr;
324 dest[0] = UBYTE_TO_FLOAT(v[0]);
325 dest[1] = UBYTE_TO_FLOAT(v[1]);
326 dest[2] = UBYTE_TO_FLOAT(v[2]);
327 }
328
329 static void r200_Color4ub_3f( GLubyte r, GLubyte g, GLubyte b, GLubyte a )
330 {
331 GET_CURRENT_CONTEXT(ctx);
332 r200ContextPtr rmesa = R200_CONTEXT(ctx);
333 GLfloat *dest = rmesa->vb.floatcolorptr;
334 dest[0] = UBYTE_TO_FLOAT(r);
335 dest[1] = UBYTE_TO_FLOAT(g);
336 dest[2] = UBYTE_TO_FLOAT(b);
337 ctx->Current.Attrib[VERT_ATTRIB_COLOR0][3] = UBYTE_TO_FLOAT(a);
338 }
339
340 static void r200_Color4ubv_3f( const GLubyte *v )
341 {
342 GET_CURRENT_CONTEXT(ctx);
343 r200ContextPtr rmesa = R200_CONTEXT(ctx);
344 GLfloat *dest = rmesa->vb.floatcolorptr;
345 dest[0] = UBYTE_TO_FLOAT(v[0]);
346 dest[1] = UBYTE_TO_FLOAT(v[1]);
347 dest[2] = UBYTE_TO_FLOAT(v[2]);
348 ctx->Current.Attrib[VERT_ATTRIB_COLOR0][3] = UBYTE_TO_FLOAT(v[3]);
349 }
350 #endif /* 0 */
351
352
353 static void r200_Color3f_3f( GLfloat r, GLfloat g, GLfloat b )
354 {
355 GET_CURRENT_CONTEXT(ctx);
356 r200ContextPtr rmesa = R200_CONTEXT(ctx);
357 GLfloat *dest = rmesa->vb.floatcolorptr;
358 dest[0] = r;
359 dest[1] = g;
360 dest[2] = b;
361 }
362
363 static void r200_Color3fv_3f( const GLfloat *v )
364 {
365 GET_CURRENT_CONTEXT(ctx);
366 r200ContextPtr rmesa = R200_CONTEXT(ctx);
367 GLfloat *dest = rmesa->vb.floatcolorptr;
368 dest[0] = v[0];
369 dest[1] = v[1];
370 dest[2] = v[2];
371 }
372
373 static void r200_Color4f_3f( GLfloat r, GLfloat g, GLfloat b, GLfloat a )
374 {
375 GET_CURRENT_CONTEXT(ctx);
376 r200ContextPtr rmesa = R200_CONTEXT(ctx);
377 GLfloat *dest = rmesa->vb.floatcolorptr;
378 dest[0] = r;
379 dest[1] = g;
380 dest[2] = b;
381 ctx->Current.Attrib[VERT_ATTRIB_COLOR0][3] = a;
382 }
383
384 static void r200_Color4fv_3f( const GLfloat *v )
385 {
386 GET_CURRENT_CONTEXT(ctx);
387 r200ContextPtr rmesa = R200_CONTEXT(ctx);
388 GLfloat *dest = rmesa->vb.floatcolorptr;
389 dest[0] = v[0];
390 dest[1] = v[1];
391 dest[2] = v[2];
392 ctx->Current.Attrib[VERT_ATTRIB_COLOR0][3] = v[3];
393 }
394
395
396 /* Secondary Color:
397 */
398 #if 0
399 static void r200_SecondaryColor3ubEXT_ub( GLubyte r, GLubyte g, GLubyte b )
400 {
401 GET_CURRENT_CONTEXT(ctx);
402 r200ContextPtr rmesa = R200_CONTEXT(ctx);
403 r200_color_t *dest = rmesa->vb.specptr;
404 dest->red = r;
405 dest->green = g;
406 dest->blue = b;
407 dest->alpha = 0xff;
408 }
409
410 static void r200_SecondaryColor3ubvEXT_ub( const GLubyte *v )
411 {
412 GET_CURRENT_CONTEXT(ctx);
413 r200ContextPtr rmesa = R200_CONTEXT(ctx);
414 r200_color_t *dest = rmesa->vb.specptr;
415 dest->red = v[0];
416 dest->green = v[1];
417 dest->blue = v[2];
418 dest->alpha = 0xff;
419 }
420 #endif /* 0 */
421
422 static void r200_SecondaryColor3fEXT_ub( GLfloat r, GLfloat g, GLfloat b )
423 {
424 GET_CURRENT_CONTEXT(ctx);
425 r200ContextPtr rmesa = R200_CONTEXT(ctx);
426 r200_color_t *dest = rmesa->vb.specptr;
427 UNCLAMPED_FLOAT_TO_UBYTE( dest->red, r );
428 UNCLAMPED_FLOAT_TO_UBYTE( dest->green, g );
429 UNCLAMPED_FLOAT_TO_UBYTE( dest->blue, b );
430 dest->alpha = 255;
431 }
432
433 static void r200_SecondaryColor3fvEXT_ub( const GLfloat *v )
434 {
435 GET_CURRENT_CONTEXT(ctx);
436 r200ContextPtr rmesa = R200_CONTEXT(ctx);
437 r200_color_t *dest = rmesa->vb.specptr;
438 UNCLAMPED_FLOAT_TO_UBYTE( dest->red, v[0] );
439 UNCLAMPED_FLOAT_TO_UBYTE( dest->green, v[1] );
440 UNCLAMPED_FLOAT_TO_UBYTE( dest->blue, v[2] );
441 dest->alpha = 255;
442 }
443
444 #if 0
445 static void r200_SecondaryColor3ubEXT_3f( GLubyte r, GLubyte g, GLubyte b )
446 {
447 GET_CURRENT_CONTEXT(ctx);
448 r200ContextPtr rmesa = R200_CONTEXT(ctx);
449 GLfloat *dest = rmesa->vb.floatspecptr;
450 dest[0] = UBYTE_TO_FLOAT(r);
451 dest[1] = UBYTE_TO_FLOAT(g);
452 dest[2] = UBYTE_TO_FLOAT(b);
453 dest[3] = 1.0;
454 }
455
456 static void r200_SecondaryColor3ubvEXT_3f( const GLubyte *v )
457 {
458 GET_CURRENT_CONTEXT(ctx);
459 r200ContextPtr rmesa = R200_CONTEXT(ctx);
460 GLfloat *dest = rmesa->vb.floatspecptr;
461 dest[0] = UBYTE_TO_FLOAT(v[0]);
462 dest[1] = UBYTE_TO_FLOAT(v[1]);
463 dest[2] = UBYTE_TO_FLOAT(v[2]);
464 dest[3] = 1.0;
465 }
466 #endif /* 0 */
467
468 static void r200_SecondaryColor3fEXT_3f( GLfloat r, GLfloat g, GLfloat b )
469 {
470 GET_CURRENT_CONTEXT(ctx);
471 r200ContextPtr rmesa = R200_CONTEXT(ctx);
472 GLfloat *dest = rmesa->vb.floatspecptr;
473 dest[0] = r;
474 dest[1] = g;
475 dest[2] = b;
476 dest[3] = 1.0;
477 }
478
479 static void r200_SecondaryColor3fvEXT_3f( const GLfloat *v )
480 {
481 GET_CURRENT_CONTEXT(ctx);
482 r200ContextPtr rmesa = R200_CONTEXT(ctx);
483 GLfloat *dest = rmesa->vb.floatspecptr;
484 dest[0] = v[0];
485 dest[1] = v[1];
486 dest[2] = v[2];
487 dest[3] = 1.0;
488 }
489
490
491
492 /* Normal
493 */
494 static void r200_Normal3f( GLfloat n0, GLfloat n1, GLfloat n2 )
495 {
496 GET_CURRENT_CONTEXT(ctx);
497 r200ContextPtr rmesa = R200_CONTEXT(ctx);
498 GLfloat *dest = rmesa->vb.normalptr;
499 dest[0] = n0;
500 dest[1] = n1;
501 dest[2] = n2;
502 }
503
504 static void r200_Normal3fv( const GLfloat *v )
505 {
506 GET_CURRENT_CONTEXT(ctx);
507 r200ContextPtr rmesa = R200_CONTEXT(ctx);
508 GLfloat *dest = rmesa->vb.normalptr;
509 dest[0] = v[0];
510 dest[1] = v[1];
511 dest[2] = v[2];
512 }
513
514
515 /* TexCoord
516 */
517
518 #define TEX_to_nF(N, P, S, T, R) \
519 static void r200_TexCoord ## N P \
520 { \
521 GET_CURRENT_CONTEXT(ctx); r200ContextPtr rmesa = R200_CONTEXT(ctx); \
522 GLfloat * const dest = rmesa->vb.texcoordptr[0]; \
523 switch( ctx->Texture.Unit[0]._ReallyEnabled ) { \
524 case TEXTURE_CUBE_BIT: \
525 case TEXTURE_3D_BIT: \
526 dest[2] = R; \
527 case TEXTURE_2D_BIT: \
528 case TEXTURE_RECT_BIT: \
529 dest[1] = T; \
530 case TEXTURE_1D_BIT: \
531 dest[0] = S; \
532 } \
533 }
534
535 TEX_to_nF( 1f, (GLfloat s), s, 0.0, 0.0 )
536 TEX_to_nF( 2f, (GLfloat s, GLfloat t), s, t, 0.0 )
537 TEX_to_nF( 3f, (GLfloat s, GLfloat t, GLfloat r), s, t, r )
538 TEX_to_nF( 1fv, (const GLfloat * v), v[0], 0.0, 0.0 )
539 TEX_to_nF( 2fv, (const GLfloat * v), v[0], v[1], 0.0 )
540 TEX_to_nF( 3fv, (const GLfloat * v), v[0], v[1], v[2] )
541
542
543 /* MultiTexcoord
544 *
545 * Technically speaking, these functions should subtract GL_TEXTURE0 from
546 * \c target before masking and using it. The value of GL_TEXTURE0 is 0x84C0,
547 * which has the low-order 5 bits 0. For all possible valid values of
548 * \c target. Subtracting GL_TEXTURE0 has the net effect of masking \c target
549 * with 0x1F. Masking with 0x1F and then masking with 0x07 is redundant, so
550 * the subtraction has been omitted.
551 */
552
553 #define MTEX_to_nF(N, P, U, S, T, R) \
554 static void r200_MultiTexCoord ## N ## ARB P \
555 { \
556 GET_CURRENT_CONTEXT(ctx); r200ContextPtr rmesa = R200_CONTEXT(ctx); \
557 GLfloat * const dest = rmesa->vb.texcoordptr[U]; \
558 switch( ctx->Texture.Unit[U]._ReallyEnabled ) { \
559 case TEXTURE_CUBE_BIT: \
560 case TEXTURE_3D_BIT: \
561 dest[2] = R; \
562 case TEXTURE_2D_BIT: \
563 case TEXTURE_RECT_BIT: \
564 dest[1] = T; \
565 case TEXTURE_1D_BIT: \
566 dest[0] = S; \
567 } \
568 }
569
570 /* \todo maybe (target & 4 ? target & 5 : target & 3) is more save than (target & 7) */
571 MTEX_to_nF( 1f, (GLenum target, GLfloat s), (target & 7), s, 0.0, 0.0 )
572 MTEX_to_nF( 2f, (GLenum target, GLfloat s, GLfloat t), (target & 7), s, t, 0.0 )
573 MTEX_to_nF( 3f, (GLenum target, GLfloat s, GLfloat t, GLfloat r), (target & 7), s, t, r )
574
575 MTEX_to_nF( 1fv, (GLenum target, const GLfloat *v), (target & 7), v[0], 0.0, 0.0 )
576 MTEX_to_nF( 2fv, (GLenum target, const GLfloat *v), (target & 7), v[0], v[1], 0.0 )
577 MTEX_to_nF( 3fv, (GLenum target, const GLfloat *v), (target & 7), v[0], v[1], v[2] )
578
579 static struct dynfn *lookup( struct dynfn *l, const int *key )
580 {
581 struct dynfn *f;
582
583 foreach( f, l ) {
584 if (f->key[0] == key[0] && f->key[1] == key[1])
585 return f;
586 }
587
588 return 0;
589 }
590
591 /* Can't use the loopback template for this:
592 */
593
594 #define CHOOSE(FN, FNTYPE, MASK0, MASK1, ARGS1, ARGS2 ) \
595 static void choose_##FN ARGS1 \
596 { \
597 GET_CURRENT_CONTEXT(ctx); \
598 r200ContextPtr rmesa = R200_CONTEXT(ctx); \
599 int key[2]; \
600 struct dynfn *dfn; \
601 \
602 key[0] = rmesa->vb.vtxfmt_0 & MASK0; \
603 key[1] = rmesa->vb.vtxfmt_1 & MASK1; \
604 \
605 dfn = lookup( &rmesa->vb.dfn_cache.FN, key ); \
606 if (dfn == 0) \
607 dfn = rmesa->vb.codegen.FN( ctx, key ); \
608 else if (R200_DEBUG & DEBUG_CODEGEN) \
609 fprintf(stderr, "%s -- cached codegen\n", __FUNCTION__ ); \
610 \
611 if (dfn) \
612 ctx->Exec->FN = (FNTYPE)(dfn->code); \
613 else { \
614 if (R200_DEBUG & DEBUG_CODEGEN) \
615 fprintf(stderr, "%s -- generic version\n", __FUNCTION__ ); \
616 ctx->Exec->FN = r200_##FN; \
617 } \
618 \
619 ctx->Driver.NeedFlush |= FLUSH_UPDATE_CURRENT; \
620 ctx->Exec->FN ARGS2; \
621 }
622
623
624
625 /* For the _3f case, only allow one color function to be hooked in at
626 * a time. Eventually, use a similar mechanism to allow selecting the
627 * color component of the vertex format based on client behaviour.
628 *
629 * Note: Perform these actions even if there is a codegen or cached
630 * codegen version of the chosen function.
631 */
632 #define CHOOSE_COLOR(FN, FNTYPE, NR, MASK0, MASK1, ARGS1, ARGS2 ) \
633 static void choose_##FN ARGS1 \
634 { \
635 GET_CURRENT_CONTEXT(ctx); \
636 r200ContextPtr rmesa = R200_CONTEXT(ctx); \
637 int key[2]; \
638 struct dynfn *dfn; \
639 \
640 key[0] = rmesa->vb.vtxfmt_0 & MASK0; \
641 key[1] = rmesa->vb.vtxfmt_1 & MASK1; \
642 \
643 if (VTX_COLOR(rmesa->vb.vtxfmt_0,0) == R200_VTX_PK_RGBA) { \
644 ctx->Exec->FN = r200_##FN##_ub; \
645 } \
646 else if (VTX_COLOR(rmesa->vb.vtxfmt_0,0) == R200_VTX_FP_RGB) { \
647 \
648 if (rmesa->vb.installed_color_3f_sz != NR) { \
649 rmesa->vb.installed_color_3f_sz = NR; \
650 if (NR == 3) ctx->Current.Attrib[VERT_ATTRIB_COLOR0][3] = 1.0; \
651 if (ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT) { \
652 r200_copy_to_current( ctx ); \
653 _mesa_install_exec_vtxfmt( ctx, &rmesa->vb.vtxfmt ); \
654 ctx->Exec->FN ARGS2; \
655 return; \
656 } \
657 } \
658 \
659 ctx->Exec->FN = r200_##FN##_3f; \
660 } \
661 else { \
662 ctx->Exec->FN = r200_##FN##_4f; \
663 } \
664 \
665 \
666 dfn = lookup( &rmesa->vb.dfn_cache.FN, key ); \
667 if (!dfn) dfn = rmesa->vb.codegen.FN( ctx, key ); \
668 \
669 if (dfn) { \
670 if (R200_DEBUG & DEBUG_CODEGEN) \
671 fprintf(stderr, "%s -- codegen version\n", __FUNCTION__ ); \
672 ctx->Exec->FN = (FNTYPE)dfn->code; \
673 } \
674 else if (R200_DEBUG & DEBUG_CODEGEN) \
675 fprintf(stderr, "%s -- 'c' version\n", __FUNCTION__ ); \
676 \
677 ctx->Driver.NeedFlush |= FLUSH_UPDATE_CURRENT; \
678 ctx->Exec->FN ARGS2; \
679 }
680
681
682
683 /* Right now there are both _ub and _3f versions of the secondary color
684 * functions. Currently, we only set-up the hardware to use the _ub versions.
685 * The _3f versions are needed for the cases where secondary color isn't used
686 * in the vertex format, but it still needs to be stored in the context
687 * state vector.
688 */
689 #define CHOOSE_SECONDARY_COLOR(FN, FNTYPE, MASK0, MASK1, ARGS1, ARGS2 ) \
690 static void choose_##FN ARGS1 \
691 { \
692 GET_CURRENT_CONTEXT(ctx); \
693 r200ContextPtr rmesa = R200_CONTEXT(ctx); \
694 int key[2]; \
695 struct dynfn *dfn; \
696 \
697 key[0] = rmesa->vb.vtxfmt_0 & MASK0; \
698 key[1] = rmesa->vb.vtxfmt_1 & MASK1; \
699 \
700 dfn = lookup( &rmesa->vb.dfn_cache.FN, key ); \
701 if (dfn == 0) \
702 dfn = rmesa->vb.codegen.FN( ctx, key ); \
703 else if (R200_DEBUG & DEBUG_CODEGEN) \
704 fprintf(stderr, "%s -- cached version\n", __FUNCTION__ ); \
705 \
706 if (dfn) \
707 ctx->Exec->FN = (FNTYPE)(dfn->code); \
708 else { \
709 if (R200_DEBUG & DEBUG_CODEGEN) \
710 fprintf(stderr, "%s -- generic version\n", __FUNCTION__ ); \
711 ctx->Exec->FN = (VTX_COLOR(rmesa->vb.vtxfmt_0,1) == R200_VTX_PK_RGBA) \
712 ? r200_##FN##_ub : r200_##FN##_3f; \
713 } \
714 \
715 ctx->Driver.NeedFlush |= FLUSH_UPDATE_CURRENT; \
716 ctx->Exec->FN ARGS2; \
717 }
718
719
720
721
722
723
724
725 /* VTXFMT_0
726 */
727 #define MASK_XYZW (R200_VTX_W0|R200_VTX_Z0)
728 #define MASK_NORM (MASK_XYZW|R200_VTX_N0)
729 #define MASK_COLOR (MASK_NORM |(R200_VTX_COLOR_MASK<<R200_VTX_COLOR_0_SHIFT))
730 #define MASK_SPEC (MASK_COLOR|(R200_VTX_COLOR_MASK<<R200_VTX_COLOR_1_SHIFT))
731
732 /* VTXFMT_1
733 */
734 #define MASK_ST0 (0x7 << R200_VTX_TEX0_COMP_CNT_SHIFT)
735 /* FIXME: maybe something like in the radeon driver is needed here? */
736
737
738 typedef void (*p4f)( GLfloat, GLfloat, GLfloat, GLfloat );
739 typedef void (*p3f)( GLfloat, GLfloat, GLfloat );
740 typedef void (*p2f)( GLfloat, GLfloat );
741 typedef void (*p1f)( GLfloat );
742 typedef void (*pe3f)( GLenum, GLfloat, GLfloat, GLfloat );
743 typedef void (*pe2f)( GLenum, GLfloat, GLfloat );
744 typedef void (*pe1f)( GLenum, GLfloat );
745 typedef void (*p4ub)( GLubyte, GLubyte, GLubyte, GLubyte );
746 typedef void (*p3ub)( GLubyte, GLubyte, GLubyte );
747 typedef void (*pfv)( const GLfloat * );
748 typedef void (*pefv)( GLenum, const GLfloat * );
749 typedef void (*pubv)( const GLubyte * );
750
751
752 CHOOSE(Normal3f, p3f, MASK_NORM, 0,
753 (GLfloat a,GLfloat b,GLfloat c), (a,b,c))
754 CHOOSE(Normal3fv, pfv, MASK_NORM, 0,
755 (const GLfloat *v), (v))
756
757 #if 0
758 CHOOSE_COLOR(Color4ub, p4ub, 4, MASK_COLOR, 0,
759 (GLubyte a,GLubyte b, GLubyte c, GLubyte d), (a,b,c,d))
760 CHOOSE_COLOR(Color4ubv, pubv, 4, MASK_COLOR, 0,
761 (const GLubyte *v), (v))
762 CHOOSE_COLOR(Color3ub, p3ub, 3, MASK_COLOR, 0,
763 (GLubyte a,GLubyte b, GLubyte c), (a,b,c))
764 CHOOSE_COLOR(Color3ubv, pubv, 3, MASK_COLOR, 0,
765 (const GLubyte *v), (v))
766 CHOOSE_SECONDARY_COLOR(SecondaryColor3ubEXT, p3ub, MASK_SPEC, 0,
767 (GLubyte a,GLubyte b, GLubyte c), (a,b,c))
768 CHOOSE_SECONDARY_COLOR(SecondaryColor3ubvEXT, pubv, MASK_SPEC, 0,
769 (const GLubyte *v), (v))
770 #endif
771
772 CHOOSE_COLOR(Color4f, p4f, 4, MASK_COLOR, 0,
773 (GLfloat a,GLfloat b, GLfloat c, GLfloat d), (a,b,c,d))
774 CHOOSE_COLOR(Color4fv, pfv, 4, MASK_COLOR, 0,
775 (const GLfloat *v), (v))
776 CHOOSE_COLOR(Color3f, p3f, 3, MASK_COLOR, 0,
777 (GLfloat a,GLfloat b, GLfloat c), (a,b,c))
778 CHOOSE_COLOR(Color3fv, pfv, 3, MASK_COLOR, 0,
779 (const GLfloat *v), (v))
780
781
782 CHOOSE_SECONDARY_COLOR(SecondaryColor3fEXT, p3f, MASK_SPEC, 0,
783 (GLfloat a,GLfloat b, GLfloat c), (a,b,c))
784 CHOOSE_SECONDARY_COLOR(SecondaryColor3fvEXT, pfv, MASK_SPEC, 0,
785 (const GLfloat *v), (v))
786
787 CHOOSE(TexCoord3f, p3f, ~0, MASK_ST0,
788 (GLfloat a,GLfloat b,GLfloat c), (a,b,c))
789 CHOOSE(TexCoord3fv, pfv, ~0, MASK_ST0,
790 (const GLfloat *v), (v))
791 CHOOSE(TexCoord2f, p2f, ~0, MASK_ST0,
792 (GLfloat a,GLfloat b), (a,b))
793 CHOOSE(TexCoord2fv, pfv, ~0, MASK_ST0,
794 (const GLfloat *v), (v))
795 CHOOSE(TexCoord1f, p1f, ~0, MASK_ST0,
796 (GLfloat a), (a))
797 CHOOSE(TexCoord1fv, pfv, ~0, MASK_ST0,
798 (const GLfloat *v), (v))
799
800 CHOOSE(MultiTexCoord3fARB, pe3f, ~0, ~0,
801 (GLenum u,GLfloat a,GLfloat b,GLfloat c), (u,a,b,c))
802 CHOOSE(MultiTexCoord3fvARB, pefv, ~0, ~0,
803 (GLenum u,const GLfloat *v), (u,v))
804 CHOOSE(MultiTexCoord2fARB, pe2f, ~0, ~0,
805 (GLenum u,GLfloat a,GLfloat b), (u,a,b))
806 CHOOSE(MultiTexCoord2fvARB, pefv, ~0, ~0,
807 (GLenum u,const GLfloat *v), (u,v))
808 CHOOSE(MultiTexCoord1fARB, pe1f, ~0, ~0,
809 (GLenum u,GLfloat a), (u,a))
810 CHOOSE(MultiTexCoord1fvARB, pefv, ~0, ~0,
811 (GLenum u,const GLfloat *v), (u,v))
812
813 CHOOSE(Vertex3f, p3f, ~0, ~0,
814 (GLfloat a,GLfloat b,GLfloat c), (a,b,c))
815 CHOOSE(Vertex3fv, pfv, ~0, ~0,
816 (const GLfloat *v), (v))
817 CHOOSE(Vertex2f, p2f, ~0, ~0,
818 (GLfloat a,GLfloat b), (a,b))
819 CHOOSE(Vertex2fv, pfv, ~0, ~0,
820 (const GLfloat *v), (v))
821
822
823
824
825
826 void r200VtxfmtInitChoosers( GLvertexformat *vfmt )
827 {
828 vfmt->Color3f = choose_Color3f;
829 vfmt->Color3fv = choose_Color3fv;
830 vfmt->Color4f = choose_Color4f;
831 vfmt->Color4fv = choose_Color4fv;
832 vfmt->SecondaryColor3fEXT = choose_SecondaryColor3fEXT;
833 vfmt->SecondaryColor3fvEXT = choose_SecondaryColor3fvEXT;
834 vfmt->MultiTexCoord1fARB = choose_MultiTexCoord1fARB;
835 vfmt->MultiTexCoord1fvARB = choose_MultiTexCoord1fvARB;
836 vfmt->MultiTexCoord2fARB = choose_MultiTexCoord2fARB;
837 vfmt->MultiTexCoord2fvARB = choose_MultiTexCoord2fvARB;
838 vfmt->MultiTexCoord3fARB = choose_MultiTexCoord3fARB;
839 vfmt->MultiTexCoord3fvARB = choose_MultiTexCoord3fvARB;
840 vfmt->Normal3f = choose_Normal3f;
841 vfmt->Normal3fv = choose_Normal3fv;
842 vfmt->TexCoord1f = choose_TexCoord1f;
843 vfmt->TexCoord1fv = choose_TexCoord1fv;
844 vfmt->TexCoord2f = choose_TexCoord2f;
845 vfmt->TexCoord2fv = choose_TexCoord2fv;
846 vfmt->TexCoord3f = choose_TexCoord3f;
847 vfmt->TexCoord3fv = choose_TexCoord3fv;
848 vfmt->Vertex2f = choose_Vertex2f;
849 vfmt->Vertex2fv = choose_Vertex2fv;
850 vfmt->Vertex3f = choose_Vertex3f;
851 vfmt->Vertex3fv = choose_Vertex3fv;
852
853 /* TODO: restore ubyte colors to vtxfmt.
854 */
855 #if 0
856 vfmt->Color3ub = choose_Color3ub;
857 vfmt->Color3ubv = choose_Color3ubv;
858 vfmt->Color4ub = choose_Color4ub;
859 vfmt->Color4ubv = choose_Color4ubv;
860 vfmt->SecondaryColor3ubEXT = choose_SecondaryColor3ubEXT;
861 vfmt->SecondaryColor3ubvEXT = choose_SecondaryColor3ubvEXT;
862 #endif
863 }
864
865
866 static struct dynfn *codegen_noop( GLcontext *ctx, const int *key )
867 {
868 (void) ctx; (void) key;
869 return 0;
870 }
871
872 void r200InitCodegen( struct dfn_generators *gen, GLboolean useCodegen )
873 {
874 gen->Vertex3f = codegen_noop;
875 gen->Vertex3fv = codegen_noop;
876 gen->Color4ub = codegen_noop;
877 gen->Color4ubv = codegen_noop;
878 gen->Normal3f = codegen_noop;
879 gen->Normal3fv = codegen_noop;
880
881 gen->TexCoord3f = codegen_noop;
882 gen->TexCoord3fv = codegen_noop;
883 gen->TexCoord2f = codegen_noop;
884 gen->TexCoord2fv = codegen_noop;
885 gen->TexCoord1f = codegen_noop;
886 gen->TexCoord1fv = codegen_noop;
887
888 gen->MultiTexCoord3fARB = codegen_noop;
889 gen->MultiTexCoord3fvARB = codegen_noop;
890 gen->MultiTexCoord2fARB = codegen_noop;
891 gen->MultiTexCoord2fvARB = codegen_noop;
892 gen->MultiTexCoord1fARB = codegen_noop;
893 gen->MultiTexCoord1fvARB = codegen_noop;
894
895 gen->Vertex2f = codegen_noop;
896 gen->Vertex2fv = codegen_noop;
897 gen->Color3ub = codegen_noop;
898 gen->Color3ubv = codegen_noop;
899 gen->Color4f = codegen_noop;
900 gen->Color4fv = codegen_noop;
901 gen->Color3f = codegen_noop;
902 gen->Color3fv = codegen_noop;
903 gen->SecondaryColor3fEXT = codegen_noop;
904 gen->SecondaryColor3fvEXT = codegen_noop;
905 gen->SecondaryColor3ubEXT = codegen_noop;
906 gen->SecondaryColor3ubvEXT = codegen_noop;
907
908 if (useCodegen) {
909 #if defined(USE_X86_ASM)
910 r200InitX86Codegen( gen );
911 #endif
912
913 #if defined(USE_SSE_ASM)
914 r200InitSSECodegen( gen );
915 #endif
916 }
917 }