make render_quads_verts call EMIT_PRIM with the arguments in the right order,
[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 #if 0
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 #endif /* 0 */
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 #if 0
212 static void radeon_Color3ub_4f( GLubyte r, GLubyte g, GLubyte b )
213 {
214 GET_CURRENT_CONTEXT(ctx);
215 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
216 GLfloat *dest = rmesa->vb.floatcolorptr;
217 dest[0] = UBYTE_TO_FLOAT(r);
218 dest[1] = UBYTE_TO_FLOAT(g);
219 dest[2] = UBYTE_TO_FLOAT(b);
220 dest[3] = 1.0;
221 }
222
223 static void radeon_Color3ubv_4f( const GLubyte *v )
224 {
225 GET_CURRENT_CONTEXT(ctx);
226 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
227 GLfloat *dest = rmesa->vb.floatcolorptr;
228 dest[0] = UBYTE_TO_FLOAT(v[0]);
229 dest[1] = UBYTE_TO_FLOAT(v[1]);
230 dest[2] = UBYTE_TO_FLOAT(v[2]);
231 dest[3] = 1.0;
232 }
233
234 static void radeon_Color4ub_4f( GLubyte r, GLubyte g, GLubyte b, GLubyte a )
235 {
236 GET_CURRENT_CONTEXT(ctx);
237 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
238 GLfloat *dest = rmesa->vb.floatcolorptr;
239 dest[0] = UBYTE_TO_FLOAT(r);
240 dest[1] = UBYTE_TO_FLOAT(g);
241 dest[2] = UBYTE_TO_FLOAT(b);
242 dest[3] = UBYTE_TO_FLOAT(a);
243 }
244
245 static void radeon_Color4ubv_4f( const GLubyte *v )
246 {
247 GET_CURRENT_CONTEXT(ctx);
248 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
249 GLfloat *dest = rmesa->vb.floatcolorptr;
250 dest[0] = UBYTE_TO_FLOAT(v[0]);
251 dest[1] = UBYTE_TO_FLOAT(v[1]);
252 dest[2] = UBYTE_TO_FLOAT(v[2]);
253 dest[3] = UBYTE_TO_FLOAT(v[3]);
254 }
255 #endif /* 0 */
256
257
258 static void radeon_Color3f_4f( GLfloat r, GLfloat g, GLfloat b )
259 {
260 GET_CURRENT_CONTEXT(ctx);
261 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
262 GLfloat *dest = rmesa->vb.floatcolorptr;
263 dest[0] = r;
264 dest[1] = g;
265 dest[2] = b;
266 dest[3] = 1.0;
267 }
268
269 static void radeon_Color3fv_4f( const GLfloat *v )
270 {
271 GET_CURRENT_CONTEXT(ctx);
272 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
273 GLfloat *dest = rmesa->vb.floatcolorptr;
274 dest[0] = v[0];
275 dest[1] = v[1];
276 dest[2] = v[2];
277 dest[3] = 1.0;
278 }
279
280 static void radeon_Color4f_4f( GLfloat r, GLfloat g, GLfloat b, GLfloat a )
281 {
282 GET_CURRENT_CONTEXT(ctx);
283 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
284 GLfloat *dest = rmesa->vb.floatcolorptr;
285 dest[0] = r;
286 dest[1] = g;
287 dest[2] = b;
288 dest[3] = a;
289 }
290
291 static void radeon_Color4fv_4f( const GLfloat *v )
292 {
293 GET_CURRENT_CONTEXT(ctx);
294 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
295 GLfloat *dest = rmesa->vb.floatcolorptr;
296 dest[0] = v[0];
297 dest[1] = v[1];
298 dest[2] = v[2];
299 dest[3] = v[3];
300 }
301
302
303 /* Color for float color formats:
304 */
305 #if 0
306 static void radeon_Color3ub_3f( GLubyte r, GLubyte g, GLubyte b )
307 {
308 GET_CURRENT_CONTEXT(ctx);
309 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
310 GLfloat *dest = rmesa->vb.floatcolorptr;
311 dest[0] = UBYTE_TO_FLOAT(r);
312 dest[1] = UBYTE_TO_FLOAT(g);
313 dest[2] = UBYTE_TO_FLOAT(b);
314 }
315
316 static void radeon_Color3ubv_3f( const GLubyte *v )
317 {
318 GET_CURRENT_CONTEXT(ctx);
319 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
320 GLfloat *dest = rmesa->vb.floatcolorptr;
321 dest[0] = UBYTE_TO_FLOAT(v[0]);
322 dest[1] = UBYTE_TO_FLOAT(v[1]);
323 dest[2] = UBYTE_TO_FLOAT(v[2]);
324 }
325
326 static void radeon_Color4ub_3f( GLubyte r, GLubyte g, GLubyte b, GLubyte a )
327 {
328 GET_CURRENT_CONTEXT(ctx);
329 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
330 GLfloat *dest = rmesa->vb.floatcolorptr;
331 dest[0] = UBYTE_TO_FLOAT(r);
332 dest[1] = UBYTE_TO_FLOAT(g);
333 dest[2] = UBYTE_TO_FLOAT(b);
334 ctx->Current.Attrib[VERT_ATTRIB_COLOR0][3] = UBYTE_TO_FLOAT(a);
335 }
336
337 static void radeon_Color4ubv_3f( const GLubyte *v )
338 {
339 GET_CURRENT_CONTEXT(ctx);
340 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
341 GLfloat *dest = rmesa->vb.floatcolorptr;
342 dest[0] = UBYTE_TO_FLOAT(v[0]);
343 dest[1] = UBYTE_TO_FLOAT(v[1]);
344 dest[2] = UBYTE_TO_FLOAT(v[2]);
345 ctx->Current.Attrib[VERT_ATTRIB_COLOR0][3] = UBYTE_TO_FLOAT(v[3]);
346 }
347 #endif /* 0 */
348
349
350 static void radeon_Color3f_3f( GLfloat r, GLfloat g, GLfloat b )
351 {
352 GET_CURRENT_CONTEXT(ctx);
353 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
354 GLfloat *dest = rmesa->vb.floatcolorptr;
355 dest[0] = r;
356 dest[1] = g;
357 dest[2] = b;
358 }
359
360 static void radeon_Color3fv_3f( const GLfloat *v )
361 {
362 GET_CURRENT_CONTEXT(ctx);
363 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
364 GLfloat *dest = rmesa->vb.floatcolorptr;
365 dest[0] = v[0];
366 dest[1] = v[1];
367 dest[2] = v[2];
368 }
369
370 static void radeon_Color4f_3f( GLfloat r, GLfloat g, GLfloat b, GLfloat a )
371 {
372 GET_CURRENT_CONTEXT(ctx);
373 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
374 GLfloat *dest = rmesa->vb.floatcolorptr;
375 dest[0] = r;
376 dest[1] = g;
377 dest[2] = b;
378 ctx->Current.Attrib[VERT_ATTRIB_COLOR0][3] = a;
379 }
380
381 static void radeon_Color4fv_3f( const GLfloat *v )
382 {
383 GET_CURRENT_CONTEXT(ctx);
384 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
385 GLfloat *dest = rmesa->vb.floatcolorptr;
386 dest[0] = v[0];
387 dest[1] = v[1];
388 dest[2] = v[2];
389 ctx->Current.Attrib[VERT_ATTRIB_COLOR0][3] = v[3];
390 }
391
392
393 /* Secondary Color:
394 */
395 #if 0
396 static void radeon_SecondaryColor3ubEXT_ub( GLubyte r, GLubyte g, GLubyte b )
397 {
398 GET_CURRENT_CONTEXT(ctx);
399 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
400 radeon_color_t *dest = rmesa->vb.specptr;
401 dest->red = r;
402 dest->green = g;
403 dest->blue = b;
404 dest->alpha = 0xff;
405 }
406
407 static void radeon_SecondaryColor3ubvEXT_ub( const GLubyte *v )
408 {
409 GET_CURRENT_CONTEXT(ctx);
410 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
411 radeon_color_t *dest = rmesa->vb.specptr;
412 dest->red = v[0];
413 dest->green = v[1];
414 dest->blue = v[2];
415 dest->alpha = 0xff;
416 }
417 #endif /* 0 */
418
419 static void radeon_SecondaryColor3fEXT_ub( GLfloat r, GLfloat g, GLfloat b )
420 {
421 GET_CURRENT_CONTEXT(ctx);
422 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
423 radeon_color_t *dest = rmesa->vb.specptr;
424 UNCLAMPED_FLOAT_TO_UBYTE( dest->red, r );
425 UNCLAMPED_FLOAT_TO_UBYTE( dest->green, g );
426 UNCLAMPED_FLOAT_TO_UBYTE( dest->blue, b );
427 dest->alpha = 255;
428 }
429
430 static void radeon_SecondaryColor3fvEXT_ub( const GLfloat *v )
431 {
432 GET_CURRENT_CONTEXT(ctx);
433 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
434 radeon_color_t *dest = rmesa->vb.specptr;
435 UNCLAMPED_FLOAT_TO_UBYTE( dest->red, v[0] );
436 UNCLAMPED_FLOAT_TO_UBYTE( dest->green, v[1] );
437 UNCLAMPED_FLOAT_TO_UBYTE( dest->blue, v[2] );
438 dest->alpha = 255;
439 }
440
441 #if 0
442 static void radeon_SecondaryColor3ubEXT_3f( GLubyte r, GLubyte g, GLubyte b )
443 {
444 GET_CURRENT_CONTEXT(ctx);
445 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
446 GLfloat *dest = rmesa->vb.floatspecptr;
447 dest[0] = UBYTE_TO_FLOAT(r);
448 dest[1] = UBYTE_TO_FLOAT(g);
449 dest[2] = UBYTE_TO_FLOAT(b);
450 dest[3] = 1.0;
451 }
452
453 static void radeon_SecondaryColor3ubvEXT_3f( const GLubyte *v )
454 {
455 GET_CURRENT_CONTEXT(ctx);
456 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
457 GLfloat *dest = rmesa->vb.floatspecptr;
458 dest[0] = UBYTE_TO_FLOAT(v[0]);
459 dest[1] = UBYTE_TO_FLOAT(v[1]);
460 dest[2] = UBYTE_TO_FLOAT(v[2]);
461 dest[3] = 1.0;
462 }
463 #endif /* 0 */
464
465 static void radeon_SecondaryColor3fEXT_3f( GLfloat r, GLfloat g, GLfloat b )
466 {
467 GET_CURRENT_CONTEXT(ctx);
468 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
469 GLfloat *dest = rmesa->vb.floatspecptr;
470 dest[0] = r;
471 dest[1] = g;
472 dest[2] = b;
473 dest[3] = 1.0;
474 }
475
476 static void radeon_SecondaryColor3fvEXT_3f( const GLfloat *v )
477 {
478 GET_CURRENT_CONTEXT(ctx);
479 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
480 GLfloat *dest = rmesa->vb.floatspecptr;
481 dest[0] = v[0];
482 dest[1] = v[1];
483 dest[2] = v[2];
484 dest[3] = 1.0;
485 }
486
487
488 /* Normal
489 */
490 static void radeon_Normal3f( GLfloat n0, GLfloat n1, GLfloat n2 )
491 {
492 GET_CURRENT_CONTEXT(ctx);
493 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
494 GLfloat *dest = rmesa->vb.normalptr;
495 dest[0] = n0;
496 dest[1] = n1;
497 dest[2] = n2;
498 }
499
500 static void radeon_Normal3fv( const GLfloat *v )
501 {
502 GET_CURRENT_CONTEXT(ctx);
503 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
504 GLfloat *dest = rmesa->vb.normalptr;
505 dest[0] = v[0];
506 dest[1] = v[1];
507 dest[2] = v[2];
508 }
509
510
511 /* TexCoord
512 */
513 static void radeon_TexCoord1f( GLfloat s )
514 {
515 GET_CURRENT_CONTEXT(ctx);
516 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
517 GLfloat *dest = rmesa->vb.texcoordptr[0];
518 dest[0] = s;
519 dest[1] = 0;
520 }
521
522 static void radeon_TexCoord1fv( const GLfloat *v )
523 {
524 GET_CURRENT_CONTEXT(ctx);
525 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
526 GLfloat *dest = rmesa->vb.texcoordptr[0];
527 dest[0] = v[0];
528 dest[1] = 0;
529 }
530
531 static void radeon_TexCoord2f( GLfloat s, GLfloat t )
532 {
533 GET_CURRENT_CONTEXT(ctx);
534 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
535 GLfloat *dest = rmesa->vb.texcoordptr[0];
536 dest[0] = s;
537 dest[1] = t;
538 }
539
540 static void radeon_TexCoord2fv( const GLfloat *v )
541 {
542 GET_CURRENT_CONTEXT(ctx);
543 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
544 GLfloat *dest = rmesa->vb.texcoordptr[0];
545 dest[0] = v[0];
546 dest[1] = v[1];
547 }
548
549
550 /* MultiTexcoord
551 *
552 * Technically speaking, these functions should subtract GL_TEXTURE0 from
553 * \c target before masking and using it. The value of GL_TEXTURE0 is 0x84C0,
554 * which has the low-order 5 bits 0. For all possible valid values of
555 * \c target. Subtracting GL_TEXTURE0 has the net effect of masking \c target
556 * with 0x1F. Masking with 0x1F and then masking with 0x01 is redundant, so
557 * the subtraction has been omitted.
558 */
559
560 static void radeon_MultiTexCoord1fARB( GLenum target, GLfloat s )
561 {
562 GET_CURRENT_CONTEXT(ctx);
563 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
564 GLfloat *dest = rmesa->vb.texcoordptr[target & 1];
565 dest[0] = s;
566 dest[1] = 0;
567 }
568
569 static void radeon_MultiTexCoord1fvARB( GLenum target, const GLfloat *v )
570 {
571 GET_CURRENT_CONTEXT(ctx);
572 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
573 GLfloat *dest = rmesa->vb.texcoordptr[target & 1];
574 dest[0] = v[0];
575 dest[1] = 0;
576 }
577
578 static void radeon_MultiTexCoord2fARB( GLenum target, GLfloat s, GLfloat t )
579 {
580 GET_CURRENT_CONTEXT(ctx);
581 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
582 GLfloat *dest = rmesa->vb.texcoordptr[target & 1];
583 dest[0] = s;
584 dest[1] = t;
585 }
586
587 static void radeon_MultiTexCoord2fvARB( GLenum target, const GLfloat *v )
588 {
589 GET_CURRENT_CONTEXT(ctx);
590 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
591 GLfloat *dest = rmesa->vb.texcoordptr[target & 1];
592 dest[0] = v[0];
593 dest[1] = v[1];
594 }
595
596 static struct dynfn *lookup( struct dynfn *l, int key )
597 {
598 struct dynfn *f;
599
600 foreach( f, l ) {
601 if (f->key == key)
602 return f;
603 }
604
605 return 0;
606 }
607
608 /* Can't use the loopback template for this:
609 */
610
611 #define CHOOSE(FN, FNTYPE, MASK, ACTIVE, ARGS1, ARGS2 ) \
612 static void choose_##FN ARGS1 \
613 { \
614 GET_CURRENT_CONTEXT(ctx); \
615 radeonContextPtr rmesa = RADEON_CONTEXT(ctx); \
616 int key = rmesa->vb.vertex_format & (MASK|ACTIVE); \
617 struct dynfn *dfn; \
618 \
619 dfn = lookup( &rmesa->vb.dfn_cache.FN, key ); \
620 if (dfn == 0) \
621 dfn = rmesa->vb.codegen.FN( ctx, key ); \
622 else if (RADEON_DEBUG & DEBUG_CODEGEN) \
623 fprintf(stderr, "%s -- cached codegen\n", __FUNCTION__ ); \
624 \
625 if (dfn) \
626 ctx->Exec->FN = (FNTYPE)(dfn->code); \
627 else { \
628 if (RADEON_DEBUG & DEBUG_CODEGEN) \
629 fprintf(stderr, "%s -- generic version\n", __FUNCTION__ ); \
630 ctx->Exec->FN = radeon_##FN; \
631 } \
632 \
633 ctx->Driver.NeedFlush |= FLUSH_UPDATE_CURRENT; \
634 ctx->Exec->FN ARGS2; \
635 }
636
637
638
639 /* For the _3f case, only allow one color function to be hooked in at
640 * a time. Eventually, use a similar mechanism to allow selecting the
641 * color component of the vertex format based on client behaviour.
642 *
643 * Note: Perform these actions even if there is a codegen or cached
644 * codegen version of the chosen function.
645 */
646 #define CHOOSE_COLOR(FN, FNTYPE, NR, MASK, ACTIVE, ARGS1, ARGS2 ) \
647 static void choose_##FN ARGS1 \
648 { \
649 GET_CURRENT_CONTEXT(ctx); \
650 radeonContextPtr rmesa = RADEON_CONTEXT(ctx); \
651 int key = rmesa->vb.vertex_format & (MASK|ACTIVE); \
652 struct dynfn *dfn; \
653 \
654 if (rmesa->vb.vertex_format & ACTIVE_PKCOLOR) { \
655 ctx->Exec->FN = radeon_##FN##_ub; \
656 } \
657 else if ((rmesa->vb.vertex_format & \
658 (ACTIVE_FPCOLOR|ACTIVE_FPALPHA)) == ACTIVE_FPCOLOR) { \
659 \
660 if (rmesa->vb.installed_color_3f_sz != NR) { \
661 rmesa->vb.installed_color_3f_sz = NR; \
662 if (NR == 3) ctx->Current.Attrib[VERT_ATTRIB_COLOR0][3] = 1.0; \
663 if (ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT) { \
664 radeon_copy_to_current( ctx ); \
665 _mesa_install_exec_vtxfmt( ctx, &rmesa->vb.vtxfmt ); \
666 ctx->Exec->FN ARGS2; \
667 return; \
668 } \
669 } \
670 \
671 ctx->Exec->FN = radeon_##FN##_3f; \
672 } \
673 else { \
674 ctx->Exec->FN = radeon_##FN##_4f; \
675 } \
676 \
677 \
678 dfn = lookup( &rmesa->vb.dfn_cache.FN, key ); \
679 if (!dfn) dfn = rmesa->vb.codegen.FN( ctx, key ); \
680 \
681 if (dfn) { \
682 if (RADEON_DEBUG & DEBUG_CODEGEN) \
683 fprintf(stderr, "%s -- codegen version\n", __FUNCTION__ ); \
684 ctx->Exec->FN = (FNTYPE)dfn->code; \
685 } \
686 else if (RADEON_DEBUG & DEBUG_CODEGEN) \
687 fprintf(stderr, "%s -- 'c' version\n", __FUNCTION__ ); \
688 \
689 ctx->Driver.NeedFlush |= FLUSH_UPDATE_CURRENT; \
690 ctx->Exec->FN ARGS2; \
691 }
692
693
694
695 /* Right now there are both _ub and _3f versions of the secondary color
696 * functions. Currently, we only set-up the hardware to use the _ub versions.
697 * The _3f versions are needed for the cases where secondary color isn't used
698 * in the vertex format, but it still needs to be stored in the context
699 * state vector.
700 */
701 #define CHOOSE_SECONDARY_COLOR(FN, FNTYPE, MASK, ACTIVE, ARGS1, ARGS2 ) \
702 static void choose_##FN ARGS1 \
703 { \
704 GET_CURRENT_CONTEXT(ctx); \
705 radeonContextPtr rmesa = RADEON_CONTEXT(ctx); \
706 int key = rmesa->vb.vertex_format & (MASK|ACTIVE); \
707 struct dynfn *dfn = lookup( &rmesa->vb.dfn_cache.FN, key ); \
708 \
709 if (dfn == 0) \
710 dfn = rmesa->vb.codegen.FN( ctx, key ); \
711 else if (RADEON_DEBUG & DEBUG_CODEGEN) \
712 fprintf(stderr, "%s -- cached version\n", __FUNCTION__ ); \
713 \
714 if (dfn) \
715 ctx->Exec->FN = (FNTYPE)(dfn->code); \
716 else { \
717 if (RADEON_DEBUG & DEBUG_CODEGEN) \
718 fprintf(stderr, "%s -- generic version\n", __FUNCTION__ ); \
719 ctx->Exec->FN = ((rmesa->vb.vertex_format & ACTIVE_PKSPEC) != 0) \
720 ? radeon_##FN##_ub : radeon_##FN##_3f; \
721 } \
722 \
723 ctx->Driver.NeedFlush |= FLUSH_UPDATE_CURRENT; \
724 ctx->Exec->FN ARGS2; \
725 }
726
727
728
729
730
731 /* Shorthands
732 */
733 #define ACTIVE_XYZW (RADEON_CP_VC_FRMT_W0|RADEON_CP_VC_FRMT_Z)
734 #define ACTIVE_NORM RADEON_CP_VC_FRMT_N0
735
736 #define ACTIVE_PKCOLOR RADEON_CP_VC_FRMT_PKCOLOR
737 #define ACTIVE_FPCOLOR RADEON_CP_VC_FRMT_FPCOLOR
738 #define ACTIVE_FPALPHA RADEON_CP_VC_FRMT_FPALPHA
739 #define ACTIVE_COLOR (ACTIVE_FPCOLOR|ACTIVE_PKCOLOR)
740
741 #define ACTIVE_PKSPEC RADEON_CP_VC_FRMT_PKSPEC
742 #define ACTIVE_FPSPEC RADEON_CP_VC_FRMT_FPSPEC
743 #define ACTIVE_SPEC (ACTIVE_FPSPEC|ACTIVE_PKSPEC)
744
745 #define ACTIVE_ST0 RADEON_CP_VC_FRMT_ST0
746 #define ACTIVE_ST1 RADEON_CP_VC_FRMT_ST1
747 #define ACTIVE_ST_ALL (RADEON_CP_VC_FRMT_ST1|RADEON_CP_VC_FRMT_ST0)
748
749 /* Each codegen function should be able to be fully specified by a
750 * subsetted version of rmesa->vb.vertex_format.
751 */
752 #define MASK_NORM (ACTIVE_XYZW)
753 #define MASK_COLOR (MASK_NORM|ACTIVE_NORM)
754 #define MASK_SPEC (MASK_COLOR|ACTIVE_COLOR)
755 #define MASK_ST0 (MASK_SPEC|ACTIVE_SPEC)
756 #define MASK_ST1 (MASK_ST0|ACTIVE_ST0)
757 #define MASK_ST_ALL (MASK_ST1|ACTIVE_ST1)
758 #define MASK_VERTEX (MASK_ST_ALL|ACTIVE_FPALPHA)
759
760
761 typedef void (*p4f)( GLfloat, GLfloat, GLfloat, GLfloat );
762 typedef void (*p3f)( GLfloat, GLfloat, GLfloat );
763 typedef void (*p2f)( GLfloat, GLfloat );
764 typedef void (*p1f)( GLfloat );
765 typedef void (*pe2f)( GLenum, GLfloat, GLfloat );
766 typedef void (*pe1f)( GLenum, GLfloat );
767 typedef void (*p4ub)( GLubyte, GLubyte, GLubyte, GLubyte );
768 typedef void (*p3ub)( GLubyte, GLubyte, GLubyte );
769 typedef void (*pfv)( const GLfloat * );
770 typedef void (*pefv)( GLenum, const GLfloat * );
771 typedef void (*pubv)( const GLubyte * );
772
773
774 CHOOSE(Normal3f, p3f, MASK_NORM, ACTIVE_NORM,
775 (GLfloat a,GLfloat b,GLfloat c), (a,b,c))
776 CHOOSE(Normal3fv, pfv, MASK_NORM, ACTIVE_NORM,
777 (const GLfloat *v), (v))
778
779 #if 0
780 CHOOSE_COLOR(Color4ub, p4ub, 4, MASK_COLOR, ACTIVE_COLOR,
781 (GLubyte a,GLubyte b, GLubyte c, GLubyte d), (a,b,c,d))
782 CHOOSE_COLOR(Color4ubv, pubv, 4, MASK_COLOR, ACTIVE_COLOR,
783 (const GLubyte *v), (v))
784 CHOOSE_COLOR(Color3ub, p3ub, 3, MASK_COLOR, ACTIVE_COLOR,
785 (GLubyte a,GLubyte b, GLubyte c), (a,b,c))
786 CHOOSE_COLOR(Color3ubv, pubv, 3, MASK_COLOR, ACTIVE_COLOR,
787 (const GLubyte *v), (v))
788 #endif
789
790 CHOOSE_COLOR(Color4f, p4f, 4, MASK_COLOR, ACTIVE_COLOR,
791 (GLfloat a,GLfloat b, GLfloat c, GLfloat d), (a,b,c,d))
792 CHOOSE_COLOR(Color4fv, pfv, 4, MASK_COLOR, ACTIVE_COLOR,
793 (const GLfloat *v), (v))
794 CHOOSE_COLOR(Color3f, p3f, 3, MASK_COLOR, ACTIVE_COLOR,
795 (GLfloat a,GLfloat b, GLfloat c), (a,b,c))
796 CHOOSE_COLOR(Color3fv, pfv, 3, MASK_COLOR, ACTIVE_COLOR,
797 (const GLfloat *v), (v))
798
799
800 #if 0
801 CHOOSE_SECONDARY_COLOR(SecondaryColor3ubEXT, p3ub, MASK_SPEC, ACTIVE_SPEC,
802 (GLubyte a,GLubyte b, GLubyte c), (a,b,c))
803 CHOOSE_SECONDARY_COLOR(SecondaryColor3ubvEXT, pubv, MASK_SPEC, ACTIVE_SPEC,
804 (const GLubyte *v), (v))
805 #endif
806 CHOOSE_SECONDARY_COLOR(SecondaryColor3fEXT, p3f, MASK_SPEC, ACTIVE_SPEC,
807 (GLfloat a,GLfloat b, GLfloat c), (a,b,c))
808 CHOOSE_SECONDARY_COLOR(SecondaryColor3fvEXT, pfv, MASK_SPEC, ACTIVE_SPEC,
809 (const GLfloat *v), (v))
810
811 CHOOSE(TexCoord2f, p2f, MASK_ST0, ACTIVE_ST0,
812 (GLfloat a,GLfloat b), (a,b))
813 CHOOSE(TexCoord2fv, pfv, MASK_ST0, ACTIVE_ST0,
814 (const GLfloat *v), (v))
815 CHOOSE(TexCoord1f, p1f, MASK_ST0, ACTIVE_ST0,
816 (GLfloat a), (a))
817 CHOOSE(TexCoord1fv, pfv, MASK_ST0, ACTIVE_ST0,
818 (const GLfloat *v), (v))
819
820 CHOOSE(MultiTexCoord2fARB, pe2f, MASK_ST_ALL, ACTIVE_ST_ALL,
821 (GLenum u,GLfloat a,GLfloat b), (u,a,b))
822 CHOOSE(MultiTexCoord2fvARB, pefv, MASK_ST_ALL, ACTIVE_ST_ALL,
823 (GLenum u,const GLfloat *v), (u,v))
824 CHOOSE(MultiTexCoord1fARB, pe1f, MASK_ST_ALL, ACTIVE_ST_ALL,
825 (GLenum u,GLfloat a), (u,a))
826 CHOOSE(MultiTexCoord1fvARB, pefv, MASK_ST_ALL, ACTIVE_ST_ALL,
827 (GLenum u,const GLfloat *v), (u,v))
828
829 CHOOSE(Vertex3f, p3f, MASK_VERTEX, MASK_VERTEX,
830 (GLfloat a,GLfloat b,GLfloat c), (a,b,c))
831 CHOOSE(Vertex3fv, pfv, MASK_VERTEX, MASK_VERTEX,
832 (const GLfloat *v), (v))
833 CHOOSE(Vertex2f, p2f, MASK_VERTEX, MASK_VERTEX,
834 (GLfloat a,GLfloat b), (a,b))
835 CHOOSE(Vertex2fv, pfv, MASK_VERTEX, MASK_VERTEX,
836 (const GLfloat *v), (v))
837
838
839
840
841
842 void radeonVtxfmtInitChoosers( GLvertexformat *vfmt )
843 {
844 vfmt->Color3f = choose_Color3f;
845 vfmt->Color3fv = choose_Color3fv;
846 vfmt->Color4f = choose_Color4f;
847 vfmt->Color4fv = choose_Color4fv;
848 vfmt->SecondaryColor3fEXT = choose_SecondaryColor3fEXT;
849 vfmt->SecondaryColor3fvEXT = choose_SecondaryColor3fvEXT;
850 vfmt->MultiTexCoord1fARB = choose_MultiTexCoord1fARB;
851 vfmt->MultiTexCoord1fvARB = choose_MultiTexCoord1fvARB;
852 vfmt->MultiTexCoord2fARB = choose_MultiTexCoord2fARB;
853 vfmt->MultiTexCoord2fvARB = choose_MultiTexCoord2fvARB;
854 vfmt->Normal3f = choose_Normal3f;
855 vfmt->Normal3fv = choose_Normal3fv;
856 vfmt->TexCoord1f = choose_TexCoord1f;
857 vfmt->TexCoord1fv = choose_TexCoord1fv;
858 vfmt->TexCoord2f = choose_TexCoord2f;
859 vfmt->TexCoord2fv = choose_TexCoord2fv;
860 vfmt->Vertex2f = choose_Vertex2f;
861 vfmt->Vertex2fv = choose_Vertex2fv;
862 vfmt->Vertex3f = choose_Vertex3f;
863 vfmt->Vertex3fv = choose_Vertex3fv;
864
865 #if 0
866 vfmt->Color3ub = choose_Color3ub;
867 vfmt->Color3ubv = choose_Color3ubv;
868 vfmt->Color4ub = choose_Color4ub;
869 vfmt->Color4ubv = choose_Color4ubv;
870 vfmt->SecondaryColor3ubEXT = choose_SecondaryColor3ubEXT;
871 vfmt->SecondaryColor3ubvEXT = choose_SecondaryColor3ubvEXT;
872 #endif
873 }
874
875
876 static struct dynfn *codegen_noop( GLcontext *ctx, int key )
877 {
878 (void) ctx; (void) key;
879 return 0;
880 }
881
882 void radeonInitCodegen( struct dfn_generators *gen, GLboolean useCodegen )
883 {
884 gen->Vertex3f = codegen_noop;
885 gen->Vertex3fv = codegen_noop;
886 gen->Color4ub = codegen_noop;
887 gen->Color4ubv = codegen_noop;
888 gen->Normal3f = codegen_noop;
889 gen->Normal3fv = codegen_noop;
890 gen->TexCoord2f = codegen_noop;
891 gen->TexCoord2fv = codegen_noop;
892 gen->MultiTexCoord2fARB = codegen_noop;
893 gen->MultiTexCoord2fvARB = codegen_noop;
894 gen->Vertex2f = codegen_noop;
895 gen->Vertex2fv = codegen_noop;
896 gen->Color3ub = codegen_noop;
897 gen->Color3ubv = codegen_noop;
898 gen->Color4f = codegen_noop;
899 gen->Color4fv = codegen_noop;
900 gen->Color3f = codegen_noop;
901 gen->Color3fv = codegen_noop;
902 gen->SecondaryColor3fEXT = codegen_noop;
903 gen->SecondaryColor3fvEXT = codegen_noop;
904 gen->SecondaryColor3ubEXT = codegen_noop;
905 gen->SecondaryColor3ubvEXT = codegen_noop;
906 gen->TexCoord1f = codegen_noop;
907 gen->TexCoord1fv = codegen_noop;
908 gen->MultiTexCoord1fARB = codegen_noop;
909 gen->MultiTexCoord1fvARB = codegen_noop;
910
911 if (useCodegen) {
912 #if defined(USE_X86_ASM)
913 radeonInitX86Codegen( gen );
914 #endif
915
916 #if defined(USE_SSE_ASM)
917 radeonInitSSECodegen( gen );
918 #endif
919 }
920 }