Convert all uses of CARD32 and CARD8 to int32_t and int8_t.
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_vtxfmt_c.c
1 /* $XFree86: xc/lib/GL/mesa/src/drv/radeon/radeon_vtxfmt_c.c,v 1.2 2002/12/16 16:18:59 dawes Exp $ */
2 /**************************************************************************
3
4 Copyright 2002 ATI Technologies Inc., Ontario, Canada, and
5 Tungsten Graphics Inc., Cedar Park, Texas.
6
7 All Rights Reserved.
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 #include "glheader.h"
36 #include "mtypes.h"
37 #include "colormac.h"
38 #include "simple_list.h"
39 #include "api_noop.h"
40 #include "vtxfmt.h"
41
42 #include "radeon_vtxfmt.h"
43
44 /* Fallback versions of all the entrypoints for situations where
45 * codegen isn't available. This is still a lot faster than the
46 * vb/pipeline implementation in Mesa.
47 */
48 static void radeon_Vertex3f( GLfloat x, GLfloat y, GLfloat z )
49 {
50 GET_CURRENT_CONTEXT(ctx);
51 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
52 int i;
53
54 *rmesa->vb.dmaptr++ = *(int *)&x;
55 *rmesa->vb.dmaptr++ = *(int *)&y;
56 *rmesa->vb.dmaptr++ = *(int *)&z;
57
58 for (i = 3; i < rmesa->vb.vertex_size; i++)
59 *rmesa->vb.dmaptr++ = rmesa->vb.vertex[i].i;
60
61 if (--rmesa->vb.counter == 0)
62 rmesa->vb.notify();
63 }
64
65
66 static void radeon_Vertex3fv( const GLfloat *v )
67 {
68 GET_CURRENT_CONTEXT(ctx);
69 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
70 int i;
71
72 *rmesa->vb.dmaptr++ = *(int *)&v[0];
73 *rmesa->vb.dmaptr++ = *(int *)&v[1];
74 *rmesa->vb.dmaptr++ = *(int *)&v[2];
75
76 for (i = 3; i < rmesa->vb.vertex_size; i++)
77 *rmesa->vb.dmaptr++ = rmesa->vb.vertex[i].i;
78
79 if (--rmesa->vb.counter == 0)
80 rmesa->vb.notify();
81 }
82
83
84 static void radeon_Vertex2f( GLfloat x, GLfloat y )
85 {
86 GET_CURRENT_CONTEXT(ctx);
87 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
88 int i;
89
90 *rmesa->vb.dmaptr++ = *(int *)&x;
91 *rmesa->vb.dmaptr++ = *(int *)&y;
92 *rmesa->vb.dmaptr++ = 0;
93
94 for (i = 3; i < rmesa->vb.vertex_size; i++)
95 *rmesa->vb.dmaptr++ = *(int *)&rmesa->vb.vertex[i];
96
97 if (--rmesa->vb.counter == 0)
98 rmesa->vb.notify();
99 }
100
101
102 static void radeon_Vertex2fv( const GLfloat *v )
103 {
104 GET_CURRENT_CONTEXT(ctx);
105 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
106 int i;
107
108 *rmesa->vb.dmaptr++ = *(int *)&v[0];
109 *rmesa->vb.dmaptr++ = *(int *)&v[1];
110 *rmesa->vb.dmaptr++ = 0;
111
112 for (i = 3; i < rmesa->vb.vertex_size; i++)
113 *rmesa->vb.dmaptr++ = rmesa->vb.vertex[i].i;
114
115 if (--rmesa->vb.counter == 0)
116 rmesa->vb.notify();
117 }
118
119
120
121 /* Color for ubyte (packed) color formats:
122 */
123 static void radeon_Color3ub_ub( GLubyte r, GLubyte g, GLubyte b )
124 {
125 GET_CURRENT_CONTEXT(ctx);
126 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
127 radeon_color_t *dest = rmesa->vb.colorptr;
128 dest->red = r;
129 dest->green = g;
130 dest->blue = b;
131 dest->alpha = 0xff;
132 }
133
134 static void radeon_Color3ubv_ub( const GLubyte *v )
135 {
136 GET_CURRENT_CONTEXT(ctx);
137 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
138 radeon_color_t *dest = rmesa->vb.colorptr;
139 dest->red = v[0];
140 dest->green = v[1];
141 dest->blue = v[2];
142 dest->alpha = 0xff;
143 }
144
145 static void radeon_Color4ub_ub( GLubyte r, GLubyte g, GLubyte b, GLubyte a )
146 {
147 GET_CURRENT_CONTEXT(ctx);
148 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
149 radeon_color_t *dest = rmesa->vb.colorptr;
150 dest->red = r;
151 dest->green = g;
152 dest->blue = b;
153 dest->alpha = a;
154 }
155
156 static void radeon_Color4ubv_ub( const GLubyte *v )
157 {
158 GET_CURRENT_CONTEXT(ctx);
159 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
160 *(GLuint *)rmesa->vb.colorptr = LE32_TO_CPU(*(GLuint *)v);
161 }
162
163
164 static void radeon_Color3f_ub( GLfloat r, GLfloat g, GLfloat b )
165 {
166 GET_CURRENT_CONTEXT(ctx);
167 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
168 radeon_color_t *dest = rmesa->vb.colorptr;
169 UNCLAMPED_FLOAT_TO_UBYTE( dest->red, r );
170 UNCLAMPED_FLOAT_TO_UBYTE( dest->green, g );
171 UNCLAMPED_FLOAT_TO_UBYTE( dest->blue, b );
172 dest->alpha = 255;
173 }
174
175 static void radeon_Color3fv_ub( const GLfloat *v )
176 {
177 GET_CURRENT_CONTEXT(ctx);
178 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
179 radeon_color_t *dest = rmesa->vb.colorptr;
180 UNCLAMPED_FLOAT_TO_UBYTE( dest->red, v[0] );
181 UNCLAMPED_FLOAT_TO_UBYTE( dest->green, v[1] );
182 UNCLAMPED_FLOAT_TO_UBYTE( dest->blue, v[2] );
183 dest->alpha = 255;
184 }
185
186 static void radeon_Color4f_ub( GLfloat r, GLfloat g, GLfloat b, GLfloat a )
187 {
188 GET_CURRENT_CONTEXT(ctx);
189 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
190 radeon_color_t *dest = rmesa->vb.colorptr;
191 UNCLAMPED_FLOAT_TO_UBYTE( dest->red, r );
192 UNCLAMPED_FLOAT_TO_UBYTE( dest->green, g );
193 UNCLAMPED_FLOAT_TO_UBYTE( dest->blue, b );
194 UNCLAMPED_FLOAT_TO_UBYTE( dest->alpha, a );
195 }
196
197 static void radeon_Color4fv_ub( const GLfloat *v )
198 {
199 GET_CURRENT_CONTEXT(ctx);
200 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
201 radeon_color_t *dest = rmesa->vb.colorptr;
202 UNCLAMPED_FLOAT_TO_UBYTE( dest->red, v[0] );
203 UNCLAMPED_FLOAT_TO_UBYTE( dest->green, v[1] );
204 UNCLAMPED_FLOAT_TO_UBYTE( dest->blue, v[2] );
205 UNCLAMPED_FLOAT_TO_UBYTE( dest->alpha, v[3] );
206 }
207
208
209 /* Color for float color+alpha formats:
210 */
211 static void radeon_Color3ub_4f( GLubyte r, GLubyte g, GLubyte b )
212 {
213 GET_CURRENT_CONTEXT(ctx);
214 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
215 GLfloat *dest = rmesa->vb.floatcolorptr;
216 dest[0] = UBYTE_TO_FLOAT(r);
217 dest[1] = UBYTE_TO_FLOAT(g);
218 dest[2] = UBYTE_TO_FLOAT(b);
219 dest[3] = 1.0;
220 }
221
222 static void radeon_Color3ubv_4f( const GLubyte *v )
223 {
224 GET_CURRENT_CONTEXT(ctx);
225 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
226 GLfloat *dest = rmesa->vb.floatcolorptr;
227 dest[0] = UBYTE_TO_FLOAT(v[0]);
228 dest[1] = UBYTE_TO_FLOAT(v[1]);
229 dest[2] = UBYTE_TO_FLOAT(v[2]);
230 dest[3] = 1.0;
231 }
232
233 static void radeon_Color4ub_4f( GLubyte r, GLubyte g, GLubyte b, GLubyte a )
234 {
235 GET_CURRENT_CONTEXT(ctx);
236 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
237 GLfloat *dest = rmesa->vb.floatcolorptr;
238 dest[0] = UBYTE_TO_FLOAT(r);
239 dest[1] = UBYTE_TO_FLOAT(g);
240 dest[2] = UBYTE_TO_FLOAT(b);
241 dest[3] = UBYTE_TO_FLOAT(a);
242 }
243
244 static void radeon_Color4ubv_4f( const GLubyte *v )
245 {
246 GET_CURRENT_CONTEXT(ctx);
247 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
248 GLfloat *dest = rmesa->vb.floatcolorptr;
249 dest[0] = UBYTE_TO_FLOAT(v[0]);
250 dest[1] = UBYTE_TO_FLOAT(v[1]);
251 dest[2] = UBYTE_TO_FLOAT(v[2]);
252 dest[3] = UBYTE_TO_FLOAT(v[3]);
253 }
254
255
256 static void radeon_Color3f_4f( GLfloat r, GLfloat g, GLfloat b )
257 {
258 GET_CURRENT_CONTEXT(ctx);
259 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
260 GLfloat *dest = rmesa->vb.floatcolorptr;
261 dest[0] = r;
262 dest[1] = g;
263 dest[2] = b;
264 dest[3] = 1.0;
265 }
266
267 static void radeon_Color3fv_4f( const GLfloat *v )
268 {
269 GET_CURRENT_CONTEXT(ctx);
270 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
271 GLfloat *dest = rmesa->vb.floatcolorptr;
272 dest[0] = v[0];
273 dest[1] = v[1];
274 dest[2] = v[2];
275 dest[3] = 1.0;
276 }
277
278 static void radeon_Color4f_4f( GLfloat r, GLfloat g, GLfloat b, GLfloat a )
279 {
280 GET_CURRENT_CONTEXT(ctx);
281 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
282 GLfloat *dest = rmesa->vb.floatcolorptr;
283 dest[0] = r;
284 dest[1] = g;
285 dest[2] = b;
286 dest[3] = a;
287 }
288
289 static void radeon_Color4fv_4f( const GLfloat *v )
290 {
291 GET_CURRENT_CONTEXT(ctx);
292 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
293 GLfloat *dest = rmesa->vb.floatcolorptr;
294 dest[0] = v[0];
295 dest[1] = v[1];
296 dest[2] = v[2];
297 dest[3] = v[3];
298 }
299
300
301 /* Color for float color formats:
302 */
303 static void radeon_Color3ub_3f( GLubyte r, GLubyte g, GLubyte b )
304 {
305 GET_CURRENT_CONTEXT(ctx);
306 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
307 GLfloat *dest = rmesa->vb.floatcolorptr;
308 dest[0] = UBYTE_TO_FLOAT(r);
309 dest[1] = UBYTE_TO_FLOAT(g);
310 dest[2] = UBYTE_TO_FLOAT(b);
311 }
312
313 static void radeon_Color3ubv_3f( const GLubyte *v )
314 {
315 GET_CURRENT_CONTEXT(ctx);
316 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
317 GLfloat *dest = rmesa->vb.floatcolorptr;
318 dest[0] = UBYTE_TO_FLOAT(v[0]);
319 dest[1] = UBYTE_TO_FLOAT(v[1]);
320 dest[2] = UBYTE_TO_FLOAT(v[2]);
321 }
322
323 static void radeon_Color4ub_3f( GLubyte r, GLubyte g, GLubyte b, GLubyte a )
324 {
325 GET_CURRENT_CONTEXT(ctx);
326 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
327 GLfloat *dest = rmesa->vb.floatcolorptr;
328 dest[0] = UBYTE_TO_FLOAT(r);
329 dest[1] = UBYTE_TO_FLOAT(g);
330 dest[2] = UBYTE_TO_FLOAT(b);
331 ctx->Current.Attrib[VERT_ATTRIB_COLOR0][3] = UBYTE_TO_FLOAT(a);
332 }
333
334 static void radeon_Color4ubv_3f( const GLubyte *v )
335 {
336 GET_CURRENT_CONTEXT(ctx);
337 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
338 GLfloat *dest = rmesa->vb.floatcolorptr;
339 dest[0] = UBYTE_TO_FLOAT(v[0]);
340 dest[1] = UBYTE_TO_FLOAT(v[1]);
341 dest[2] = UBYTE_TO_FLOAT(v[2]);
342 ctx->Current.Attrib[VERT_ATTRIB_COLOR0][3] = UBYTE_TO_FLOAT(v[3]);
343 }
344
345
346 static void radeon_Color3f_3f( GLfloat r, GLfloat g, GLfloat b )
347 {
348 GET_CURRENT_CONTEXT(ctx);
349 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
350 GLfloat *dest = rmesa->vb.floatcolorptr;
351 dest[0] = r;
352 dest[1] = g;
353 dest[2] = b;
354 }
355
356 static void radeon_Color3fv_3f( const GLfloat *v )
357 {
358 GET_CURRENT_CONTEXT(ctx);
359 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
360 GLfloat *dest = rmesa->vb.floatcolorptr;
361 dest[0] = v[0];
362 dest[1] = v[1];
363 dest[2] = v[2];
364 }
365
366 static void radeon_Color4f_3f( GLfloat r, GLfloat g, GLfloat b, GLfloat a )
367 {
368 GET_CURRENT_CONTEXT(ctx);
369 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
370 GLfloat *dest = rmesa->vb.floatcolorptr;
371 dest[0] = r;
372 dest[1] = g;
373 dest[2] = b;
374 ctx->Current.Attrib[VERT_ATTRIB_COLOR0][3] = a;
375 }
376
377 static void radeon_Color4fv_3f( const GLfloat *v )
378 {
379 GET_CURRENT_CONTEXT(ctx);
380 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
381 GLfloat *dest = rmesa->vb.floatcolorptr;
382 dest[0] = v[0];
383 dest[1] = v[1];
384 dest[2] = v[2];
385 ctx->Current.Attrib[VERT_ATTRIB_COLOR0][3] = v[3];
386 }
387
388
389 /* Secondary Color:
390 */
391 static void radeon_SecondaryColor3ubEXT_ub( GLubyte r, GLubyte g, GLubyte b )
392 {
393 GET_CURRENT_CONTEXT(ctx);
394 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
395 radeon_color_t *dest = rmesa->vb.specptr;
396 dest->red = r;
397 dest->green = g;
398 dest->blue = b;
399 dest->alpha = 0xff;
400 }
401
402 static void radeon_SecondaryColor3ubvEXT_ub( const GLubyte *v )
403 {
404 GET_CURRENT_CONTEXT(ctx);
405 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
406 radeon_color_t *dest = rmesa->vb.specptr;
407 dest->red = v[0];
408 dest->green = v[1];
409 dest->blue = v[2];
410 dest->alpha = 0xff;
411 }
412
413 static void radeon_SecondaryColor3fEXT_ub( GLfloat r, GLfloat g, GLfloat b )
414 {
415 GET_CURRENT_CONTEXT(ctx);
416 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
417 radeon_color_t *dest = rmesa->vb.specptr;
418 UNCLAMPED_FLOAT_TO_UBYTE( dest->red, r );
419 UNCLAMPED_FLOAT_TO_UBYTE( dest->green, g );
420 UNCLAMPED_FLOAT_TO_UBYTE( dest->blue, b );
421 dest->alpha = 255;
422 }
423
424 static void radeon_SecondaryColor3fvEXT_ub( const GLfloat *v )
425 {
426 GET_CURRENT_CONTEXT(ctx);
427 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
428 radeon_color_t *dest = rmesa->vb.specptr;
429 UNCLAMPED_FLOAT_TO_UBYTE( dest->red, v[0] );
430 UNCLAMPED_FLOAT_TO_UBYTE( dest->green, v[1] );
431 UNCLAMPED_FLOAT_TO_UBYTE( dest->blue, v[2] );
432 dest->alpha = 255;
433 }
434
435 static void radeon_SecondaryColor3ubEXT_3f( GLubyte r, GLubyte g, GLubyte b )
436 {
437 GET_CURRENT_CONTEXT(ctx);
438 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
439 GLfloat *dest = rmesa->vb.floatspecptr;
440 dest[0] = UBYTE_TO_FLOAT(r);
441 dest[1] = UBYTE_TO_FLOAT(g);
442 dest[2] = UBYTE_TO_FLOAT(b);
443 dest[3] = 1.0;
444 }
445
446 static void radeon_SecondaryColor3ubvEXT_3f( const GLubyte *v )
447 {
448 GET_CURRENT_CONTEXT(ctx);
449 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
450 GLfloat *dest = rmesa->vb.floatspecptr;
451 dest[0] = UBYTE_TO_FLOAT(v[0]);
452 dest[1] = UBYTE_TO_FLOAT(v[1]);
453 dest[2] = UBYTE_TO_FLOAT(v[2]);
454 dest[3] = 1.0;
455 }
456
457 static void radeon_SecondaryColor3fEXT_3f( GLfloat r, GLfloat g, GLfloat b )
458 {
459 GET_CURRENT_CONTEXT(ctx);
460 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
461 GLfloat *dest = rmesa->vb.floatspecptr;
462 dest[0] = r;
463 dest[1] = g;
464 dest[2] = b;
465 dest[3] = 1.0;
466 }
467
468 static void radeon_SecondaryColor3fvEXT_3f( const GLfloat *v )
469 {
470 GET_CURRENT_CONTEXT(ctx);
471 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
472 GLfloat *dest = rmesa->vb.floatspecptr;
473 dest[0] = v[0];
474 dest[1] = v[1];
475 dest[2] = v[2];
476 dest[3] = 1.0;
477 }
478
479
480 /* Normal
481 */
482 static void radeon_Normal3f( GLfloat n0, GLfloat n1, GLfloat n2 )
483 {
484 GET_CURRENT_CONTEXT(ctx);
485 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
486 GLfloat *dest = rmesa->vb.normalptr;
487 dest[0] = n0;
488 dest[1] = n1;
489 dest[2] = n2;
490 }
491
492 static void radeon_Normal3fv( const GLfloat *v )
493 {
494 GET_CURRENT_CONTEXT(ctx);
495 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
496 GLfloat *dest = rmesa->vb.normalptr;
497 dest[0] = v[0];
498 dest[1] = v[1];
499 dest[2] = v[2];
500 }
501
502
503 /* TexCoord
504 */
505 static void radeon_TexCoord1f( GLfloat s )
506 {
507 GET_CURRENT_CONTEXT(ctx);
508 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
509 GLfloat *dest = rmesa->vb.texcoordptr[0];
510 dest[0] = s;
511 dest[1] = 0;
512 }
513
514 static void radeon_TexCoord1fv( const GLfloat *v )
515 {
516 GET_CURRENT_CONTEXT(ctx);
517 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
518 GLfloat *dest = rmesa->vb.texcoordptr[0];
519 dest[0] = v[0];
520 dest[1] = 0;
521 }
522
523 static void radeon_TexCoord2f( GLfloat s, GLfloat t )
524 {
525 GET_CURRENT_CONTEXT(ctx);
526 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
527 GLfloat *dest = rmesa->vb.texcoordptr[0];
528 dest[0] = s;
529 dest[1] = t;
530 }
531
532 static void radeon_TexCoord2fv( const GLfloat *v )
533 {
534 GET_CURRENT_CONTEXT(ctx);
535 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
536 GLfloat *dest = rmesa->vb.texcoordptr[0];
537 dest[0] = v[0];
538 dest[1] = v[1];
539 }
540
541
542 /* MultiTexcoord
543 *
544 * Technically speaking, these functions should subtract GL_TEXTURE0 from
545 * \c target before masking and using it. The value of GL_TEXTURE0 is 0x84C0,
546 * which has the low-order 5 bits 0. For all possible valid values of
547 * \c target. Subtracting GL_TEXTURE0 has the net effect of masking \c target
548 * with 0x1F. Masking with 0x1F and then masking with 0x01 is redundant, so
549 * the subtraction has been omitted.
550 */
551
552 static void radeon_MultiTexCoord1fARB( GLenum target, GLfloat s )
553 {
554 GET_CURRENT_CONTEXT(ctx);
555 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
556 GLfloat *dest = rmesa->vb.texcoordptr[target & 1];
557 dest[0] = s;
558 dest[1] = 0;
559 }
560
561 static void radeon_MultiTexCoord1fvARB( GLenum target, const GLfloat *v )
562 {
563 GET_CURRENT_CONTEXT(ctx);
564 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
565 GLfloat *dest = rmesa->vb.texcoordptr[target & 1];
566 dest[0] = v[0];
567 dest[1] = 0;
568 }
569
570 static void radeon_MultiTexCoord2fARB( GLenum target, GLfloat s, GLfloat t )
571 {
572 GET_CURRENT_CONTEXT(ctx);
573 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
574 GLfloat *dest = rmesa->vb.texcoordptr[target & 1];
575 dest[0] = s;
576 dest[1] = t;
577 }
578
579 static void radeon_MultiTexCoord2fvARB( GLenum target, const GLfloat *v )
580 {
581 GET_CURRENT_CONTEXT(ctx);
582 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
583 GLfloat *dest = rmesa->vb.texcoordptr[target & 1];
584 dest[0] = v[0];
585 dest[1] = v[1];
586 }
587
588 static struct dynfn *lookup( struct dynfn *l, int key )
589 {
590 struct dynfn *f;
591
592 foreach( f, l ) {
593 if (f->key == key)
594 return f;
595 }
596
597 return 0;
598 }
599
600 /* Can't use the loopback template for this:
601 */
602
603 #define CHOOSE(FN, FNTYPE, MASK, ACTIVE, ARGS1, ARGS2 ) \
604 static void choose_##FN ARGS1 \
605 { \
606 GET_CURRENT_CONTEXT(ctx); \
607 radeonContextPtr rmesa = RADEON_CONTEXT(ctx); \
608 int key = rmesa->vb.vertex_format & (MASK|ACTIVE); \
609 struct dynfn *dfn; \
610 \
611 dfn = lookup( &rmesa->vb.dfn_cache.FN, key ); \
612 if (dfn == 0) \
613 dfn = rmesa->vb.codegen.FN( ctx, key ); \
614 else if (RADEON_DEBUG & DEBUG_CODEGEN) \
615 fprintf(stderr, "%s -- cached codegen\n", __FUNCTION__ ); \
616 \
617 if (dfn) \
618 ctx->Exec->FN = (FNTYPE)(dfn->code); \
619 else { \
620 if (RADEON_DEBUG & DEBUG_CODEGEN) \
621 fprintf(stderr, "%s -- generic version\n", __FUNCTION__ ); \
622 ctx->Exec->FN = radeon_##FN; \
623 } \
624 \
625 ctx->Driver.NeedFlush |= FLUSH_UPDATE_CURRENT; \
626 ctx->Exec->FN ARGS2; \
627 }
628
629
630
631 /* For the _3f case, only allow one color function to be hooked in at
632 * a time. Eventually, use a similar mechanism to allow selecting the
633 * color component of the vertex format based on client behaviour.
634 *
635 * Note: Perform these actions even if there is a codegen or cached
636 * codegen version of the chosen function.
637 */
638 #define CHOOSE_COLOR(FN, FNTYPE, NR, MASK, ACTIVE, ARGS1, ARGS2 ) \
639 static void choose_##FN ARGS1 \
640 { \
641 GET_CURRENT_CONTEXT(ctx); \
642 radeonContextPtr rmesa = RADEON_CONTEXT(ctx); \
643 int key = rmesa->vb.vertex_format & (MASK|ACTIVE); \
644 struct dynfn *dfn; \
645 \
646 if (rmesa->vb.vertex_format & ACTIVE_PKCOLOR) { \
647 ctx->Exec->FN = radeon_##FN##_ub; \
648 } \
649 else if ((rmesa->vb.vertex_format & \
650 (ACTIVE_FPCOLOR|ACTIVE_FPALPHA)) == ACTIVE_FPCOLOR) { \
651 \
652 if (rmesa->vb.installed_color_3f_sz != NR) { \
653 rmesa->vb.installed_color_3f_sz = NR; \
654 if (NR == 3) ctx->Current.Attrib[VERT_ATTRIB_COLOR0][3] = 1.0; \
655 if (ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT) { \
656 radeon_copy_to_current( ctx ); \
657 _mesa_install_exec_vtxfmt( ctx, &rmesa->vb.vtxfmt ); \
658 ctx->Exec->FN ARGS2; \
659 return; \
660 } \
661 } \
662 \
663 ctx->Exec->FN = radeon_##FN##_3f; \
664 } \
665 else { \
666 ctx->Exec->FN = radeon_##FN##_4f; \
667 } \
668 \
669 \
670 dfn = lookup( &rmesa->vb.dfn_cache.FN, key ); \
671 if (!dfn) dfn = rmesa->vb.codegen.FN( ctx, key ); \
672 \
673 if (dfn) { \
674 if (RADEON_DEBUG & DEBUG_CODEGEN) \
675 fprintf(stderr, "%s -- codegen version\n", __FUNCTION__ ); \
676 ctx->Exec->FN = (FNTYPE)dfn->code; \
677 } \
678 else if (RADEON_DEBUG & DEBUG_CODEGEN) \
679 fprintf(stderr, "%s -- 'c' version\n", __FUNCTION__ ); \
680 \
681 ctx->Driver.NeedFlush |= FLUSH_UPDATE_CURRENT; \
682 ctx->Exec->FN ARGS2; \
683 }
684
685
686
687 /* Right now there are both _ub and _3f versions of the secondary color
688 * functions. Currently, we only set-up the hardware to use the _ub versions.
689 * The _3f versions are needed for the cases where secondary color isn't used
690 * in the vertex format, but it still needs to be stored in the context
691 * state vector.
692 */
693 #define CHOOSE_SECONDARY_COLOR(FN, FNTYPE, MASK, ACTIVE, ARGS1, ARGS2 ) \
694 static void choose_##FN ARGS1 \
695 { \
696 GET_CURRENT_CONTEXT(ctx); \
697 radeonContextPtr rmesa = RADEON_CONTEXT(ctx); \
698 int key = rmesa->vb.vertex_format & (MASK|ACTIVE); \
699 struct dynfn *dfn = lookup( &rmesa->vb.dfn_cache.FN, key ); \
700 \
701 if (dfn == 0) \
702 dfn = rmesa->vb.codegen.FN( ctx, key ); \
703 else if (RADEON_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 (RADEON_DEBUG & DEBUG_CODEGEN) \
710 fprintf(stderr, "%s -- generic version\n", __FUNCTION__ ); \
711 ctx->Exec->FN = ((rmesa->vb.vertex_format & ACTIVE_PKSPEC) != 0) \
712 ? radeon_##FN##_ub : radeon_##FN##_3f; \
713 } \
714 \
715 ctx->Driver.NeedFlush |= FLUSH_UPDATE_CURRENT; \
716 ctx->Exec->FN ARGS2; \
717 }
718
719
720
721
722
723 /* Shorthands
724 */
725 #define ACTIVE_XYZW (RADEON_CP_VC_FRMT_W0|RADEON_CP_VC_FRMT_Z)
726 #define ACTIVE_NORM RADEON_CP_VC_FRMT_N0
727
728 #define ACTIVE_PKCOLOR RADEON_CP_VC_FRMT_PKCOLOR
729 #define ACTIVE_FPCOLOR RADEON_CP_VC_FRMT_FPCOLOR
730 #define ACTIVE_FPALPHA RADEON_CP_VC_FRMT_FPALPHA
731 #define ACTIVE_COLOR (ACTIVE_FPCOLOR|ACTIVE_PKCOLOR)
732
733 #define ACTIVE_PKSPEC RADEON_CP_VC_FRMT_PKSPEC
734 #define ACTIVE_FPSPEC RADEON_CP_VC_FRMT_FPSPEC
735 #define ACTIVE_SPEC (ACTIVE_FPSPEC|ACTIVE_PKSPEC)
736
737 #define ACTIVE_ST0 RADEON_CP_VC_FRMT_ST0
738 #define ACTIVE_ST1 RADEON_CP_VC_FRMT_ST1
739 #define ACTIVE_ST_ALL (RADEON_CP_VC_FRMT_ST1|RADEON_CP_VC_FRMT_ST0)
740
741 /* Each codegen function should be able to be fully specified by a
742 * subsetted version of rmesa->vb.vertex_format.
743 */
744 #define MASK_NORM (ACTIVE_XYZW)
745 #define MASK_COLOR (MASK_NORM|ACTIVE_NORM)
746 #define MASK_SPEC (MASK_COLOR|ACTIVE_COLOR)
747 #define MASK_ST0 (MASK_SPEC|ACTIVE_SPEC)
748 #define MASK_ST1 (MASK_ST0|ACTIVE_ST0)
749 #define MASK_ST_ALL (MASK_ST1|ACTIVE_ST1)
750 #define MASK_VERTEX (MASK_ST_ALL|ACTIVE_FPALPHA)
751
752
753 typedef void (*p4f)( GLfloat, GLfloat, GLfloat, GLfloat );
754 typedef void (*p3f)( GLfloat, GLfloat, GLfloat );
755 typedef void (*p2f)( GLfloat, GLfloat );
756 typedef void (*p1f)( GLfloat );
757 typedef void (*pe2f)( GLenum, GLfloat, GLfloat );
758 typedef void (*pe1f)( GLenum, GLfloat );
759 typedef void (*p4ub)( GLubyte, GLubyte, GLubyte, GLubyte );
760 typedef void (*p3ub)( GLubyte, GLubyte, GLubyte );
761 typedef void (*pfv)( const GLfloat * );
762 typedef void (*pefv)( GLenum, const GLfloat * );
763 typedef void (*pubv)( const GLubyte * );
764
765
766 CHOOSE(Normal3f, p3f, MASK_NORM, ACTIVE_NORM,
767 (GLfloat a,GLfloat b,GLfloat c), (a,b,c))
768 CHOOSE(Normal3fv, pfv, MASK_NORM, ACTIVE_NORM,
769 (const GLfloat *v), (v))
770
771 CHOOSE_COLOR(Color4ub, p4ub, 4, MASK_COLOR, ACTIVE_COLOR,
772 (GLubyte a,GLubyte b, GLubyte c, GLubyte d), (a,b,c,d))
773 CHOOSE_COLOR(Color4ubv, pubv, 4, MASK_COLOR, ACTIVE_COLOR,
774 (const GLubyte *v), (v))
775 CHOOSE_COLOR(Color3ub, p3ub, 3, MASK_COLOR, ACTIVE_COLOR,
776 (GLubyte a,GLubyte b, GLubyte c), (a,b,c))
777 CHOOSE_COLOR(Color3ubv, pubv, 3, MASK_COLOR, ACTIVE_COLOR,
778 (const GLubyte *v), (v))
779
780 CHOOSE_COLOR(Color4f, p4f, 4, MASK_COLOR, ACTIVE_COLOR,
781 (GLfloat a,GLfloat b, GLfloat c, GLfloat d), (a,b,c,d))
782 CHOOSE_COLOR(Color4fv, pfv, 4, MASK_COLOR, ACTIVE_COLOR,
783 (const GLfloat *v), (v))
784 CHOOSE_COLOR(Color3f, p3f, 3, MASK_COLOR, ACTIVE_COLOR,
785 (GLfloat a,GLfloat b, GLfloat c), (a,b,c))
786 CHOOSE_COLOR(Color3fv, pfv, 3, MASK_COLOR, ACTIVE_COLOR,
787 (const GLfloat *v), (v))
788
789
790 CHOOSE_SECONDARY_COLOR(SecondaryColor3ubEXT, p3ub, MASK_SPEC, ACTIVE_SPEC,
791 (GLubyte a,GLubyte b, GLubyte c), (a,b,c))
792 CHOOSE_SECONDARY_COLOR(SecondaryColor3ubvEXT, pubv, MASK_SPEC, ACTIVE_SPEC,
793 (const GLubyte *v), (v))
794 CHOOSE_SECONDARY_COLOR(SecondaryColor3fEXT, p3f, MASK_SPEC, ACTIVE_SPEC,
795 (GLfloat a,GLfloat b, GLfloat c), (a,b,c))
796 CHOOSE_SECONDARY_COLOR(SecondaryColor3fvEXT, pfv, MASK_SPEC, ACTIVE_SPEC,
797 (const GLfloat *v), (v))
798
799 CHOOSE(TexCoord2f, p2f, MASK_ST0, ACTIVE_ST0,
800 (GLfloat a,GLfloat b), (a,b))
801 CHOOSE(TexCoord2fv, pfv, MASK_ST0, ACTIVE_ST0,
802 (const GLfloat *v), (v))
803 CHOOSE(TexCoord1f, p1f, MASK_ST0, ACTIVE_ST0,
804 (GLfloat a), (a))
805 CHOOSE(TexCoord1fv, pfv, MASK_ST0, ACTIVE_ST0,
806 (const GLfloat *v), (v))
807
808 CHOOSE(MultiTexCoord2fARB, pe2f, MASK_ST_ALL, ACTIVE_ST_ALL,
809 (GLenum u,GLfloat a,GLfloat b), (u,a,b))
810 CHOOSE(MultiTexCoord2fvARB, pefv, MASK_ST_ALL, ACTIVE_ST_ALL,
811 (GLenum u,const GLfloat *v), (u,v))
812 CHOOSE(MultiTexCoord1fARB, pe1f, MASK_ST_ALL, ACTIVE_ST_ALL,
813 (GLenum u,GLfloat a), (u,a))
814 CHOOSE(MultiTexCoord1fvARB, pefv, MASK_ST_ALL, ACTIVE_ST_ALL,
815 (GLenum u,const GLfloat *v), (u,v))
816
817 CHOOSE(Vertex3f, p3f, MASK_VERTEX, MASK_VERTEX,
818 (GLfloat a,GLfloat b,GLfloat c), (a,b,c))
819 CHOOSE(Vertex3fv, pfv, MASK_VERTEX, MASK_VERTEX,
820 (const GLfloat *v), (v))
821 CHOOSE(Vertex2f, p2f, MASK_VERTEX, MASK_VERTEX,
822 (GLfloat a,GLfloat b), (a,b))
823 CHOOSE(Vertex2fv, pfv, MASK_VERTEX, MASK_VERTEX,
824 (const GLfloat *v), (v))
825
826
827
828
829
830 void radeonVtxfmtInitChoosers( GLvertexformat *vfmt )
831 {
832 vfmt->Color3f = choose_Color3f;
833 vfmt->Color3fv = choose_Color3fv;
834 vfmt->Color4f = choose_Color4f;
835 vfmt->Color4fv = choose_Color4fv;
836 vfmt->SecondaryColor3fEXT = choose_SecondaryColor3fEXT;
837 vfmt->SecondaryColor3fvEXT = choose_SecondaryColor3fvEXT;
838 vfmt->MultiTexCoord1fARB = choose_MultiTexCoord1fARB;
839 vfmt->MultiTexCoord1fvARB = choose_MultiTexCoord1fvARB;
840 vfmt->MultiTexCoord2fARB = choose_MultiTexCoord2fARB;
841 vfmt->MultiTexCoord2fvARB = choose_MultiTexCoord2fvARB;
842 vfmt->Normal3f = choose_Normal3f;
843 vfmt->Normal3fv = choose_Normal3fv;
844 vfmt->TexCoord1f = choose_TexCoord1f;
845 vfmt->TexCoord1fv = choose_TexCoord1fv;
846 vfmt->TexCoord2f = choose_TexCoord2f;
847 vfmt->TexCoord2fv = choose_TexCoord2fv;
848 vfmt->Vertex2f = choose_Vertex2f;
849 vfmt->Vertex2fv = choose_Vertex2fv;
850 vfmt->Vertex3f = choose_Vertex3f;
851 vfmt->Vertex3fv = choose_Vertex3fv;
852
853 #if 0
854 vfmt->Color3ub = choose_Color3ub;
855 vfmt->Color3ubv = choose_Color3ubv;
856 vfmt->Color4ub = choose_Color4ub;
857 vfmt->Color4ubv = choose_Color4ubv;
858 vfmt->SecondaryColor3ubEXT = choose_SecondaryColor3ubEXT;
859 vfmt->SecondaryColor3ubvEXT = choose_SecondaryColor3ubvEXT;
860 #endif
861 }
862
863
864 static struct dynfn *codegen_noop( GLcontext *ctx, int key )
865 {
866 (void) ctx; (void) key;
867 return 0;
868 }
869
870 void radeonInitCodegen( struct dfn_generators *gen, GLboolean useCodegen )
871 {
872 gen->Vertex3f = codegen_noop;
873 gen->Vertex3fv = codegen_noop;
874 gen->Color4ub = codegen_noop;
875 gen->Color4ubv = codegen_noop;
876 gen->Normal3f = codegen_noop;
877 gen->Normal3fv = codegen_noop;
878 gen->TexCoord2f = codegen_noop;
879 gen->TexCoord2fv = codegen_noop;
880 gen->MultiTexCoord2fARB = codegen_noop;
881 gen->MultiTexCoord2fvARB = codegen_noop;
882 gen->Vertex2f = codegen_noop;
883 gen->Vertex2fv = codegen_noop;
884 gen->Color3ub = codegen_noop;
885 gen->Color3ubv = codegen_noop;
886 gen->Color4f = codegen_noop;
887 gen->Color4fv = codegen_noop;
888 gen->Color3f = codegen_noop;
889 gen->Color3fv = codegen_noop;
890 gen->SecondaryColor3fEXT = codegen_noop;
891 gen->SecondaryColor3fvEXT = codegen_noop;
892 gen->SecondaryColor3ubEXT = codegen_noop;
893 gen->SecondaryColor3ubvEXT = codegen_noop;
894 gen->TexCoord1f = codegen_noop;
895 gen->TexCoord1fv = codegen_noop;
896 gen->MultiTexCoord1fARB = codegen_noop;
897 gen->MultiTexCoord1fvARB = codegen_noop;
898
899 if (useCodegen) {
900 #if defined(USE_X86_ASM)
901 radeonInitX86Codegen( gen );
902 #endif
903
904 #if defined(USE_SSE_ASM)
905 radeonInitSSECodegen( gen );
906 #endif
907 }
908 }