1 /**************************************************************************
3 Copyright 2004 Tungsten Graphics Inc., Cedar Park, Texas.
7 Permission is hereby granted, free of charge, to any person obtaining a
8 copy of this software and associated documentation files (the "Software"),
9 to deal in the Software without restriction, including without limitation
10 on the rights to use, copy, modify, merge, publish, distribute, sub
11 license, and/or sell copies of the Software, and to permit persons to whom
12 the Software is furnished to do so, subject to the following conditions:
14 The above copyright notice and this permission notice (including the next
15 paragraph) shall be included in all copies or substantial portions of the
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 ATI, TUNGSTEN GRAPHICS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 * Keith Whitwell <keith@tungstengraphics.com>
40 #include "api_arrayelt.h"
46 /* Versions of all the entrypoints for situations where codegen isn't
49 * Note: Only one size for each attribute may be active at once.
50 * Eg. if Color3f is installed/active, then Color4f may not be, even
51 * if the vertex actually contains 4 color coordinates. This is
52 * because the 3f version won't otherwise set color[3] to 1.0 -- this
53 * is the job of the chooser function when switching between Color4f
56 #define ATTRFV( ATTR, N ) \
57 static void attrib_##ATTR##_##N( const GLfloat *v ) \
59 GET_CURRENT_CONTEXT( ctx ); \
60 struct brw_exec_context *exec = IMM_CONTEXT(ctx)->exec; \
65 if (N>0) exec->vtx.vbptr[0] = v[0]; \
66 if (N>1) exec->vtx.vbptr[1] = v[1]; \
67 if (N>2) exec->vtx.vbptr[2] = v[2]; \
68 if (N>3) exec->vtx.vbptr[3] = v[3]; \
70 for (i = N; i < exec->vtx.vertex_size; i++) \
71 exec->vtx.vbptr[i] = exec->vtx.vertex[i]; \
73 exec->vtx.vbptr += exec->vtx.vertex_size; \
74 exec->ctx->Driver.NeedFlush |= FLUSH_STORED_VERTICES; \
76 if (++exec->vtx.vert_count >= exec->vtx.max_vert) \
77 brw_exec_vtx_wrap( exec ); \
80 GLfloat *dest = exec->vtx.attrptr[ATTR]; \
81 if (N>0) dest[0] = v[0]; \
82 if (N>1) dest[1] = v[1]; \
83 if (N>2) dest[2] = v[2]; \
84 if (N>3) dest[3] = v[3]; \
88 #define INIT(TAB, ATTR) \
89 TAB[ATTR][0] = attrib_##ATTR##_1; \
90 TAB[ATTR][1] = attrib_##ATTR##_2; \
91 TAB[ATTR][2] = attrib_##ATTR##_3; \
92 TAB[ATTR][3] = attrib_##ATTR##_4;
95 #define ATTRS( ATTRIB ) \
118 void brw_exec_generic_attr_table_init( brw_attrfv_func (*tab
)[4] )
138 /* These can be made efficient with codegen. Further, by adding more
139 * logic to do_choose(), the double-dispatch for legacy entrypoints
140 * like glVertex3f() can be removed.
142 #define DISPATCH_ATTRFV( ATTR, COUNT, P ) \
144 GET_CURRENT_CONTEXT( ctx ); \
145 struct brw_exec_context *exec = IMM_CONTEXT(ctx)->exec; \
146 exec->vtx.tabfv[ATTR][COUNT-1]( P ); \
149 #define DISPATCH_ATTR1FV( ATTR, V ) DISPATCH_ATTRFV( ATTR, 1, V )
150 #define DISPATCH_ATTR2FV( ATTR, V ) DISPATCH_ATTRFV( ATTR, 2, V )
151 #define DISPATCH_ATTR3FV( ATTR, V ) DISPATCH_ATTRFV( ATTR, 3, V )
152 #define DISPATCH_ATTR4FV( ATTR, V ) DISPATCH_ATTRFV( ATTR, 4, V )
154 #define DISPATCH_ATTR1F( ATTR, S ) DISPATCH_ATTRFV( ATTR, 1, &(S) )
156 #define DISPATCH_ATTR2F( ATTR, S,T ) \
159 v[0] = S; v[1] = T; \
160 DISPATCH_ATTR2FV( ATTR, v ); \
162 #define DISPATCH_ATTR3F( ATTR, S,T,R ) \
165 v[0] = S; v[1] = T; v[2] = R; \
166 DISPATCH_ATTR3FV( ATTR, v ); \
168 #define DISPATCH_ATTR4F( ATTR, S,T,R,Q ) \
171 v[0] = S; v[1] = T; v[2] = R; v[3] = Q; \
172 DISPATCH_ATTR4FV( ATTR, v ); \
176 static void GLAPIENTRY
brw_Vertex2f( GLfloat x
, GLfloat y
)
178 DISPATCH_ATTR2F( BRW_ATTRIB_POS
, x
, y
);
181 static void GLAPIENTRY
brw_Vertex2fv( const GLfloat
*v
)
183 DISPATCH_ATTR2FV( BRW_ATTRIB_POS
, v
);
186 static void GLAPIENTRY
brw_Vertex3f( GLfloat x
, GLfloat y
, GLfloat z
)
188 DISPATCH_ATTR3F( BRW_ATTRIB_POS
, x
, y
, z
);
191 static void GLAPIENTRY
brw_Vertex3fv( const GLfloat
*v
)
193 DISPATCH_ATTR3FV( BRW_ATTRIB_POS
, v
);
196 static void GLAPIENTRY
brw_Vertex4f( GLfloat x
, GLfloat y
, GLfloat z
,
199 DISPATCH_ATTR4F( BRW_ATTRIB_POS
, x
, y
, z
, w
);
202 static void GLAPIENTRY
brw_Vertex4fv( const GLfloat
*v
)
204 DISPATCH_ATTR4FV( BRW_ATTRIB_POS
, v
);
207 static void GLAPIENTRY
brw_TexCoord1f( GLfloat x
)
209 DISPATCH_ATTR1F( BRW_ATTRIB_TEX0
, x
);
212 static void GLAPIENTRY
brw_TexCoord1fv( const GLfloat
*v
)
214 DISPATCH_ATTR1FV( BRW_ATTRIB_TEX0
, v
);
217 static void GLAPIENTRY
brw_TexCoord2f( GLfloat x
, GLfloat y
)
219 DISPATCH_ATTR2F( BRW_ATTRIB_TEX0
, x
, y
);
222 static void GLAPIENTRY
brw_TexCoord2fv( const GLfloat
*v
)
224 DISPATCH_ATTR2FV( BRW_ATTRIB_TEX0
, v
);
227 static void GLAPIENTRY
brw_TexCoord3f( GLfloat x
, GLfloat y
, GLfloat z
)
229 DISPATCH_ATTR3F( BRW_ATTRIB_TEX0
, x
, y
, z
);
232 static void GLAPIENTRY
brw_TexCoord3fv( const GLfloat
*v
)
234 DISPATCH_ATTR3FV( BRW_ATTRIB_TEX0
, v
);
237 static void GLAPIENTRY
brw_TexCoord4f( GLfloat x
, GLfloat y
, GLfloat z
,
240 DISPATCH_ATTR4F( BRW_ATTRIB_TEX0
, x
, y
, z
, w
);
243 static void GLAPIENTRY
brw_TexCoord4fv( const GLfloat
*v
)
245 DISPATCH_ATTR4FV( BRW_ATTRIB_TEX0
, v
);
248 static void GLAPIENTRY
brw_Normal3f( GLfloat x
, GLfloat y
, GLfloat z
)
250 DISPATCH_ATTR3F( BRW_ATTRIB_NORMAL
, x
, y
, z
);
253 static void GLAPIENTRY
brw_Normal3fv( const GLfloat
*v
)
255 DISPATCH_ATTR3FV( BRW_ATTRIB_NORMAL
, v
);
258 static void GLAPIENTRY
brw_FogCoordfEXT( GLfloat x
)
260 DISPATCH_ATTR1F( BRW_ATTRIB_FOG
, x
);
263 static void GLAPIENTRY
brw_FogCoordfvEXT( const GLfloat
*v
)
265 DISPATCH_ATTR1FV( BRW_ATTRIB_FOG
, v
);
268 static void GLAPIENTRY
brw_Color3f( GLfloat x
, GLfloat y
, GLfloat z
)
270 DISPATCH_ATTR3F( BRW_ATTRIB_COLOR0
, x
, y
, z
);
273 static void GLAPIENTRY
brw_Color3fv( const GLfloat
*v
)
275 DISPATCH_ATTR3FV( BRW_ATTRIB_COLOR0
, v
);
278 static void GLAPIENTRY
brw_Color4f( GLfloat x
, GLfloat y
, GLfloat z
,
281 DISPATCH_ATTR4F( BRW_ATTRIB_COLOR0
, x
, y
, z
, w
);
284 static void GLAPIENTRY
brw_Color4fv( const GLfloat
*v
)
286 DISPATCH_ATTR4FV( BRW_ATTRIB_COLOR0
, v
);
289 static void GLAPIENTRY
brw_SecondaryColor3fEXT( GLfloat x
, GLfloat y
,
292 DISPATCH_ATTR3F( BRW_ATTRIB_COLOR1
, x
, y
, z
);
295 static void GLAPIENTRY
brw_SecondaryColor3fvEXT( const GLfloat
*v
)
297 DISPATCH_ATTR3FV( BRW_ATTRIB_COLOR1
, v
);
300 static void GLAPIENTRY
brw_MultiTexCoord1f( GLenum target
, GLfloat x
)
302 GLuint attr
= (target
& 0x7) + BRW_ATTRIB_TEX0
;
303 DISPATCH_ATTR1F( attr
, x
);
306 static void GLAPIENTRY
brw_MultiTexCoord1fv( GLenum target
,
309 GLuint attr
= (target
& 0x7) + BRW_ATTRIB_TEX0
;
310 DISPATCH_ATTR1FV( attr
, v
);
313 static void GLAPIENTRY
brw_MultiTexCoord2f( GLenum target
, GLfloat x
,
316 GLuint attr
= (target
& 0x7) + BRW_ATTRIB_TEX0
;
317 DISPATCH_ATTR2F( attr
, x
, y
);
320 static void GLAPIENTRY
brw_MultiTexCoord2fv( GLenum target
,
323 GLuint attr
= (target
& 0x7) + BRW_ATTRIB_TEX0
;
324 DISPATCH_ATTR2FV( attr
, v
);
327 static void GLAPIENTRY
brw_MultiTexCoord3f( GLenum target
, GLfloat x
,
328 GLfloat y
, GLfloat z
)
330 GLuint attr
= (target
& 0x7) + BRW_ATTRIB_TEX0
;
331 DISPATCH_ATTR3F( attr
, x
, y
, z
);
334 static void GLAPIENTRY
brw_MultiTexCoord3fv( GLenum target
,
337 GLuint attr
= (target
& 0x7) + BRW_ATTRIB_TEX0
;
338 DISPATCH_ATTR3FV( attr
, v
);
341 static void GLAPIENTRY
brw_MultiTexCoord4f( GLenum target
, GLfloat x
,
342 GLfloat y
, GLfloat z
,
345 GLuint attr
= (target
& 0x7) + BRW_ATTRIB_TEX0
;
346 DISPATCH_ATTR4F( attr
, x
, y
, z
, w
);
349 static void GLAPIENTRY
brw_MultiTexCoord4fv( GLenum target
,
352 GLuint attr
= (target
& 0x7) + BRW_ATTRIB_TEX0
;
353 DISPATCH_ATTR4FV( attr
, v
);
357 static void GLAPIENTRY
brw_VertexAttrib1fNV( GLuint index
, GLfloat x
)
359 if (index
>= BRW_ATTRIB_FIRST_MATERIAL
) index
= ERROR_ATTRIB
;
360 DISPATCH_ATTR1F( index
, x
);
363 static void GLAPIENTRY
brw_VertexAttrib1fvNV( GLuint index
,
366 if (index
>= BRW_ATTRIB_FIRST_MATERIAL
) index
= ERROR_ATTRIB
;
367 DISPATCH_ATTR1FV( index
, v
);
370 static void GLAPIENTRY
brw_VertexAttrib2fNV( GLuint index
, GLfloat x
,
373 if (index
>= BRW_ATTRIB_FIRST_MATERIAL
) index
= ERROR_ATTRIB
;
374 DISPATCH_ATTR2F( index
, x
, y
);
377 static void GLAPIENTRY
brw_VertexAttrib2fvNV( GLuint index
,
380 if (index
>= BRW_ATTRIB_FIRST_MATERIAL
) index
= ERROR_ATTRIB
;
381 DISPATCH_ATTR2FV( index
, v
);
384 static void GLAPIENTRY
brw_VertexAttrib3fNV( GLuint index
, GLfloat x
,
385 GLfloat y
, GLfloat z
)
387 if (index
>= BRW_ATTRIB_FIRST_MATERIAL
) index
= ERROR_ATTRIB
;
388 DISPATCH_ATTR3F( index
, x
, y
, z
);
391 static void GLAPIENTRY
brw_VertexAttrib3fvNV( GLuint index
,
394 if (index
>= BRW_ATTRIB_FIRST_MATERIAL
) index
= ERROR_ATTRIB
;
395 DISPATCH_ATTR3FV( index
, v
);
398 static void GLAPIENTRY
brw_VertexAttrib4fNV( GLuint index
, GLfloat x
,
399 GLfloat y
, GLfloat z
,
402 if (index
>= BRW_ATTRIB_FIRST_MATERIAL
) index
= ERROR_ATTRIB
;
403 DISPATCH_ATTR4F( index
, x
, y
, z
, w
);
406 static void GLAPIENTRY
brw_VertexAttrib4fvNV( GLuint index
,
409 if (index
>= BRW_ATTRIB_FIRST_MATERIAL
) index
= ERROR_ATTRIB
;
410 DISPATCH_ATTR4FV( index
, v
);
418 static void GLAPIENTRY
brw_VertexAttrib1fARB( GLuint index
, GLfloat x
)
420 if (index
>= BRW_ATTRIB_FIRST_MATERIAL
) index
= ERROR_ATTRIB
;
421 DISPATCH_ATTR1F( index
, x
);
424 static void GLAPIENTRY
brw_VertexAttrib1fvARB( GLuint index
,
427 if (index
>= BRW_ATTRIB_FIRST_MATERIAL
) index
= ERROR_ATTRIB
;
428 DISPATCH_ATTR1FV( index
, v
);
431 static void GLAPIENTRY
brw_VertexAttrib2fARB( GLuint index
, GLfloat x
,
434 if (index
>= BRW_ATTRIB_FIRST_MATERIAL
) index
= ERROR_ATTRIB
;
435 DISPATCH_ATTR2F( index
, x
, y
);
438 static void GLAPIENTRY
brw_VertexAttrib2fvARB( GLuint index
,
441 if (index
>= BRW_ATTRIB_FIRST_MATERIAL
) index
= ERROR_ATTRIB
;
442 DISPATCH_ATTR2FV( index
, v
);
445 static void GLAPIENTRY
brw_VertexAttrib3fARB( GLuint index
, GLfloat x
,
446 GLfloat y
, GLfloat z
)
448 if (index
>= BRW_ATTRIB_FIRST_MATERIAL
) index
= ERROR_ATTRIB
;
449 DISPATCH_ATTR3F( index
, x
, y
, z
);
452 static void GLAPIENTRY
brw_VertexAttrib3fvARB( GLuint index
,
455 if (index
>= BRW_ATTRIB_FIRST_MATERIAL
) index
= ERROR_ATTRIB
;
456 DISPATCH_ATTR3FV( index
, v
);
459 static void GLAPIENTRY
brw_VertexAttrib4fARB( GLuint index
, GLfloat x
,
460 GLfloat y
, GLfloat z
,
463 if (index
>= BRW_ATTRIB_FIRST_MATERIAL
) index
= ERROR_ATTRIB
;
464 DISPATCH_ATTR4F( index
, x
, y
, z
, w
);
467 static void GLAPIENTRY
brw_VertexAttrib4fvARB( GLuint index
,
470 if (index
>= BRW_ATTRIB_FIRST_MATERIAL
) index
= ERROR_ATTRIB
;
471 DISPATCH_ATTR4FV( index
, v
);
475 /* Install the generic versions of the 2nd level dispatch
476 * functions. Some of these have a codegen alternative.
478 void brw_exec_vtx_generic_init( struct brw_exec_context
*exec
)
480 GLvertexformat
*vfmt
= &exec
->vtxfmt
;
482 vfmt
->Color3f
= brw_Color3f
;
483 vfmt
->Color3fv
= brw_Color3fv
;
484 vfmt
->Color4f
= brw_Color4f
;
485 vfmt
->Color4fv
= brw_Color4fv
;
486 vfmt
->FogCoordfEXT
= brw_FogCoordfEXT
;
487 vfmt
->FogCoordfvEXT
= brw_FogCoordfvEXT
;
488 vfmt
->MultiTexCoord1fARB
= brw_MultiTexCoord1f
;
489 vfmt
->MultiTexCoord1fvARB
= brw_MultiTexCoord1fv
;
490 vfmt
->MultiTexCoord2fARB
= brw_MultiTexCoord2f
;
491 vfmt
->MultiTexCoord2fvARB
= brw_MultiTexCoord2fv
;
492 vfmt
->MultiTexCoord3fARB
= brw_MultiTexCoord3f
;
493 vfmt
->MultiTexCoord3fvARB
= brw_MultiTexCoord3fv
;
494 vfmt
->MultiTexCoord4fARB
= brw_MultiTexCoord4f
;
495 vfmt
->MultiTexCoord4fvARB
= brw_MultiTexCoord4fv
;
496 vfmt
->Normal3f
= brw_Normal3f
;
497 vfmt
->Normal3fv
= brw_Normal3fv
;
498 vfmt
->SecondaryColor3fEXT
= brw_SecondaryColor3fEXT
;
499 vfmt
->SecondaryColor3fvEXT
= brw_SecondaryColor3fvEXT
;
500 vfmt
->TexCoord1f
= brw_TexCoord1f
;
501 vfmt
->TexCoord1fv
= brw_TexCoord1fv
;
502 vfmt
->TexCoord2f
= brw_TexCoord2f
;
503 vfmt
->TexCoord2fv
= brw_TexCoord2fv
;
504 vfmt
->TexCoord3f
= brw_TexCoord3f
;
505 vfmt
->TexCoord3fv
= brw_TexCoord3fv
;
506 vfmt
->TexCoord4f
= brw_TexCoord4f
;
507 vfmt
->TexCoord4fv
= brw_TexCoord4fv
;
508 vfmt
->Vertex2f
= brw_Vertex2f
;
509 vfmt
->Vertex2fv
= brw_Vertex2fv
;
510 vfmt
->Vertex3f
= brw_Vertex3f
;
511 vfmt
->Vertex3fv
= brw_Vertex3fv
;
512 vfmt
->Vertex4f
= brw_Vertex4f
;
513 vfmt
->Vertex4fv
= brw_Vertex4fv
;
514 vfmt
->VertexAttrib1fNV
= brw_VertexAttrib1fNV
;
515 vfmt
->VertexAttrib1fvNV
= brw_VertexAttrib1fvNV
;
516 vfmt
->VertexAttrib2fNV
= brw_VertexAttrib2fNV
;
517 vfmt
->VertexAttrib2fvNV
= brw_VertexAttrib2fvNV
;
518 vfmt
->VertexAttrib3fNV
= brw_VertexAttrib3fNV
;
519 vfmt
->VertexAttrib3fvNV
= brw_VertexAttrib3fvNV
;
520 vfmt
->VertexAttrib4fNV
= brw_VertexAttrib4fNV
;
521 vfmt
->VertexAttrib4fvNV
= brw_VertexAttrib4fvNV
;
522 vfmt
->VertexAttrib1fARB
= brw_VertexAttrib1fARB
;
523 vfmt
->VertexAttrib1fvARB
= brw_VertexAttrib1fvARB
;
524 vfmt
->VertexAttrib2fARB
= brw_VertexAttrib2fARB
;
525 vfmt
->VertexAttrib2fvARB
= brw_VertexAttrib2fvARB
;
526 vfmt
->VertexAttrib3fARB
= brw_VertexAttrib3fARB
;
527 vfmt
->VertexAttrib3fvARB
= brw_VertexAttrib3fvARB
;
528 vfmt
->VertexAttrib4fARB
= brw_VertexAttrib4fARB
;
529 vfmt
->VertexAttrib4fvARB
= brw_VertexAttrib4fvARB
;