1 /* $Id: t_imm_elt.c,v 1.10 2001/05/09 14:12:34 keithw Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * Keith Whitwell <keithw@valinux.com>
36 #include "math/m_translate.h"
38 #include "t_context.h"
39 #include "t_imm_elt.h"
43 typedef void (*trans_elt_1f_func
)(GLfloat
*to
,
52 typedef void (*trans_elt_1ui_func
)(GLuint
*to
,
61 typedef void (*trans_elt_1ub_func
)(GLubyte
*to
,
70 typedef void (*trans_elt_4ub_func
)(GLubyte (*to
)[4],
79 typedef void (*trans_elt_4us_func
)(GLushort (*to
)[4],
88 typedef void (*trans_elt_4f_func
)(GLfloat (*to
)[4],
97 typedef void (*trans_elt_3f_func
)(GLfloat (*to
)[3],
109 static trans_elt_1f_func _tnl_trans_elt_1f_tab
[MAX_TYPES
];
110 static trans_elt_1ui_func _tnl_trans_elt_1ui_tab
[MAX_TYPES
];
111 static trans_elt_1ub_func _tnl_trans_elt_1ub_tab
[MAX_TYPES
];
112 static trans_elt_3f_func _tnl_trans_elt_3f_tab
[MAX_TYPES
];
113 static trans_elt_4ub_func _tnl_trans_elt_4ub_tab
[5][MAX_TYPES
];
114 static trans_elt_4us_func _tnl_trans_elt_4us_tab
[5][MAX_TYPES
];
115 static trans_elt_4f_func _tnl_trans_elt_4f_tab
[5][MAX_TYPES
];
118 #define PTR_ELT(ptr, elt) (((SRC *)ptr)[elt])
124 /* Code specific to array element implementation. There is a small
125 * subtlety in the bits CHECK() tests, and the way bits are set in
126 * glArrayElement which ensures that if, eg, in the case that the
127 * vertex array is disabled and normal array is enabled, and we get
130 * ArrayElement() OR Normal()
131 * Normal() ArrayElement()
134 * That the correct value for normal is used.
136 #define TAB(x) _tnl_trans_elt##x##_tab
137 #define ARGS GLuint *flags, GLuint *elts, GLuint match, \
138 GLuint start, GLuint n
140 #define DST_START start
141 #define CHECK if ((flags[i]&match) == VERT_ELT)
142 #define NEXT_F (void)1
143 #define NEXT_F2 f = first + elts[i] * stride;
149 #define SRC_IDX TYPE_IDX(GL_BYTE)
150 #define TRX_3F(f,n) BYTE_TO_FLOAT( PTR_ELT(f,n) )
151 #define TRX_4F(f,n) BYTE_TO_FLOAT( PTR_ELT(f,n) )
152 #define TRX_UB(ub, f,n) ub = BYTE_TO_UBYTE( PTR_ELT(f,n) )
153 #define TRX_US(us, f,n) us = BYTE_TO_USHORT( PTR_ELT(f,n) )
154 #define TRX_UI(f,n) (PTR_ELT(f,n) < 0 ? 0 : (GLuint) PTR_ELT(f,n))
158 #define INIT init_trans_4_GLbyte_elt
159 #define DEST_4F trans_4_GLbyte_4f_elt
160 #define DEST_4UB trans_4_GLbyte_4ub_elt
161 #define DEST_4US trans_4_GLbyte_4us_elt
162 #include "math/m_trans_tmp.h"
165 #define INIT init_trans_3_GLbyte_elt
166 #define DEST_4F trans_3_GLbyte_4f_elt
167 #define DEST_4UB trans_3_GLbyte_4ub_elt
168 #define DEST_4US trans_3_GLbyte_4us_elt
169 #define DEST_3F trans_3_GLbyte_3f_elt
170 #include "math/m_trans_tmp.h"
173 #define INIT init_trans_2_GLbyte_elt
174 #define DEST_4F trans_2_GLbyte_4f_elt
175 #include "math/m_trans_tmp.h"
178 #define INIT init_trans_1_GLbyte_elt
179 #define DEST_4F trans_1_GLbyte_4f_elt
180 #define DEST_1UB trans_1_GLbyte_1ub_elt
181 #define DEST_1UI trans_1_GLbyte_1ui_elt
182 #include "math/m_trans_tmp.h"
195 #define SRC_IDX TYPE_IDX(GL_UNSIGNED_BYTE)
196 #define TRX_3F(f,n) UBYTE_TO_FLOAT( PTR_ELT(f,n) )
197 #define TRX_4F(f,n) UBYTE_TO_FLOAT( PTR_ELT(f,n) )
198 #define TRX_UB(ub, f,n) ub = PTR_ELT(f,n)
199 #define TRX_US(us, f,n) us = PTR_ELT(f,n)
200 #define TRX_UI(f,n) (GLuint)PTR_ELT(f,n)
202 /* 4ub->4ub handled in special case below.
205 #define INIT init_trans_4_GLubyte_elt
206 #define DEST_4F trans_4_GLubyte_4f_elt
207 #define DEST_4US trans_4_GLubyte_4us_elt
208 #include "math/m_trans_tmp.h"
211 #define INIT init_trans_3_GLubyte_elt
212 #define DEST_4F trans_3_GLubyte_4f_elt
213 #define DEST_3F trans_3_GLubyte_3f_elt
214 #define DEST_4UB trans_3_GLubyte_4ub_elt
215 #define DEST_4US trans_3_GLubyte_4us_elt
216 #include "math/m_trans_tmp.h"
220 #define INIT init_trans_1_GLubyte_elt
221 #define DEST_1UI trans_1_GLubyte_1ui_elt
222 #define DEST_1UB trans_1_GLubyte_1ub_elt
223 #include "math/m_trans_tmp.h"
237 #define SRC_IDX TYPE_IDX(GL_SHORT)
238 #define TRX_3F(f,n) SHORT_TO_FLOAT( PTR_ELT(f,n) )
239 #define TRX_4F(f,n) (GLfloat)( PTR_ELT(f,n) )
240 #define TRX_UB(ub, f,n) ub = SHORT_TO_UBYTE(PTR_ELT(f,n))
241 #define TRX_US(us, f,n) us = SHORT_TO_USHORT(PTR_ELT(f,n))
242 #define TRX_UI(f,n) (PTR_ELT(f,n) < 0 ? 0 : (GLuint) PTR_ELT(f,n))
246 #define INIT init_trans_4_GLshort_elt
247 #define DEST_4F trans_4_GLshort_4f_elt
248 #define DEST_4UB trans_4_GLshort_4ub_elt
249 #define DEST_4US trans_4_GLshort_4us_elt
250 #include "math/m_trans_tmp.h"
253 #define INIT init_trans_3_GLshort_elt
254 #define DEST_4F trans_3_GLshort_4f_elt
255 #define DEST_4UB trans_3_GLshort_4ub_elt
256 #define DEST_4US trans_3_GLshort_4us_elt
257 #define DEST_3F trans_3_GLshort_3f_elt
258 #include "math/m_trans_tmp.h"
261 #define INIT init_trans_2_GLshort_elt
262 #define DEST_4F trans_2_GLshort_4f_elt
263 #include "math/m_trans_tmp.h"
266 #define INIT init_trans_1_GLshort_elt
267 #define DEST_4F trans_1_GLshort_4f_elt
268 #define DEST_1UB trans_1_GLshort_1ub_elt
269 #define DEST_1UI trans_1_GLshort_1ui_elt
270 #include "math/m_trans_tmp.h"
285 #define SRC_IDX TYPE_IDX(GL_UNSIGNED_SHORT)
286 #define TRX_3F(f,n) USHORT_TO_FLOAT( PTR_ELT(f,n) )
287 #define TRX_4F(f,n) (GLfloat)( PTR_ELT(f,n) )
288 #define TRX_UB(ub,f,n) ub = (GLubyte) (PTR_ELT(f,n) >> 8)
289 #define TRX_US(us,f,n) us = PTR_ELT(f,n)
290 #define TRX_UI(f,n) (GLuint) PTR_ELT(f,n)
294 #define INIT init_trans_4_GLushort_elt
295 #define DEST_4F trans_4_GLushort_4f_elt
296 #define DEST_4UB trans_4_GLushort_4ub_elt
297 #define DEST_4US trans_4_GLushort_4us_elt
298 #include "math/m_trans_tmp.h"
301 #define INIT init_trans_3_GLushort_elt
302 #define DEST_4F trans_3_GLushort_4f_elt
303 #define DEST_4UB trans_3_GLushort_4ub_elt
304 #define DEST_4US trans_3_GLushort_4us_elt
305 #define DEST_3F trans_3_GLushort_3f_elt
306 #include "math/m_trans_tmp.h"
309 #define INIT init_trans_2_GLushort_elt
310 #define DEST_4F trans_2_GLushort_4f_elt
311 #include "math/m_trans_tmp.h"
314 #define INIT init_trans_1_GLushort_elt
315 #define DEST_4F trans_1_GLushort_4f_elt
316 #define DEST_1UB trans_1_GLushort_1ub_elt
317 #define DEST_1UI trans_1_GLushort_1ui_elt
318 #include "math/m_trans_tmp.h"
332 #define SRC_IDX TYPE_IDX(GL_INT)
333 #define TRX_3F(f,n) INT_TO_FLOAT( PTR_ELT(f,n) )
334 #define TRX_4F(f,n) (GLfloat)( PTR_ELT(f,n) )
335 #define TRX_UB(ub, f,n) ub = INT_TO_UBYTE(PTR_ELT(f,n))
336 #define TRX_US(us, f,n) us = INT_TO_USHORT(PTR_ELT(f,n))
337 #define TRX_UI(f,n) (PTR_ELT(f,n) < 0 ? 0 : (GLuint) PTR_ELT(f,n))
341 #define INIT init_trans_4_GLint_elt
342 #define DEST_4F trans_4_GLint_4f_elt
343 #define DEST_4UB trans_4_GLint_4ub_elt
344 #define DEST_4US trans_4_GLint_4us_elt
345 #include "math/m_trans_tmp.h"
348 #define INIT init_trans_3_GLint_elt
349 #define DEST_4F trans_3_GLint_4f_elt
350 #define DEST_4UB trans_3_GLint_4ub_elt
351 #define DEST_4US trans_3_GLint_4us_elt
352 #define DEST_3F trans_3_GLint_3f_elt
353 #include "math/m_trans_tmp.h"
356 #define INIT init_trans_2_GLint_elt
357 #define DEST_4F trans_2_GLint_4f_elt
358 #include "math/m_trans_tmp.h"
361 #define INIT init_trans_1_GLint_elt
362 #define DEST_4F trans_1_GLint_4f_elt
363 #define DEST_1UB trans_1_GLint_1ub_elt
364 #define DEST_1UI trans_1_GLint_1ui_elt
365 #include "math/m_trans_tmp.h"
380 #define SRC_IDX TYPE_IDX(GL_UNSIGNED_INT)
381 #define TRX_3F(f,n) UINT_TO_FLOAT( PTR_ELT(f,n) )
382 #define TRX_4F(f,n) (GLfloat)( PTR_ELT(f,n) )
383 #define TRX_UB(ub, f,n) ub = (GLubyte) (PTR_ELT(f,n) >> 24)
384 #define TRX_US(us, f,n) us = (GLushort) (PTR_ELT(f,n) >> 16)
385 #define TRX_UI(f,n) PTR_ELT(f,n)
389 #define INIT init_trans_4_GLuint_elt
390 #define DEST_4F trans_4_GLuint_4f_elt
391 #define DEST_4UB trans_4_GLuint_4ub_elt
392 #define DEST_4US trans_4_GLuint_4us_elt
393 #include "math/m_trans_tmp.h"
396 #define INIT init_trans_3_GLuint_elt
397 #define DEST_4F trans_3_GLuint_4f_elt
398 #define DEST_4UB trans_3_GLuint_4ub_elt
399 #define DEST_4US trans_3_GLuint_4us_elt
400 #define DEST_3F trans_3_GLuint_3f_elt
401 #include "math/m_trans_tmp.h"
404 #define INIT init_trans_2_GLuint_elt
405 #define DEST_4F trans_2_GLuint_4f_elt
406 #include "math/m_trans_tmp.h"
409 #define INIT init_trans_1_GLuint_elt
410 #define DEST_4F trans_1_GLuint_4f_elt
411 #define DEST_1UB trans_1_GLuint_1ub_elt
412 #define DEST_1UI trans_1_GLuint_1ui_elt
413 #include "math/m_trans_tmp.h"
427 #define SRC_IDX TYPE_IDX(GL_DOUBLE)
428 #define TRX_3F(f,n) PTR_ELT(f,n)
429 #define TRX_4F(f,n) PTR_ELT(f,n)
430 #define TRX_UB(ub,f,n) UNCLAMPED_FLOAT_TO_UBYTE(ub, PTR_ELT(f,n))
431 #define TRX_US(us,f,n) UNCLAMPED_FLOAT_TO_USHORT(us, PTR_ELT(f,n))
432 #define TRX_UI(f,n) (GLuint) (GLint) PTR_ELT(f,n)
433 #define TRX_1F(f,n) PTR_ELT(f,n)
437 #define INIT init_trans_4_GLdouble_elt
438 #define DEST_4F trans_4_GLdouble_4f_elt
439 #define DEST_4UB trans_4_GLdouble_4ub_elt
440 #define DEST_4US trans_4_GLdouble_4us_elt
441 #include "math/m_trans_tmp.h"
444 #define INIT init_trans_3_GLdouble_elt
445 #define DEST_4F trans_3_GLdouble_4f_elt
446 #define DEST_4UB trans_3_GLdouble_4ub_elt
447 #define DEST_4US trans_3_GLdouble_4us_elt
448 #define DEST_3F trans_3_GLdouble_3f_elt
449 #include "math/m_trans_tmp.h"
452 #define INIT init_trans_2_GLdouble_elt
453 #define DEST_4F trans_2_GLdouble_4f_elt
454 #include "math/m_trans_tmp.h"
457 #define INIT init_trans_1_GLdouble_elt
458 #define DEST_4F trans_1_GLdouble_4f_elt
459 #define DEST_1UB trans_1_GLdouble_1ub_elt
460 #define DEST_1UI trans_1_GLdouble_1ui_elt
461 #define DEST_1F trans_1_GLdouble_1f_elt
462 #include "math/m_trans_tmp.h"
470 #define SRC_IDX TYPE_IDX(GL_FLOAT)
472 #define INIT init_trans_4_GLfloat_elt
473 #define DEST_4UB trans_4_GLfloat_4ub_elt
474 #define DEST_4US trans_4_GLfloat_4us_elt
475 #define DEST_4F trans_4_GLfloat_4f_elt
476 #include "math/m_trans_tmp.h"
479 #define INIT init_trans_3_GLfloat_elt
480 #define DEST_4F trans_3_GLfloat_4f_elt
481 #define DEST_4UB trans_3_GLfloat_4ub_elt
482 #define DEST_4US trans_3_GLfloat_4us_elt
483 #define DEST_3F trans_3_GLfloat_3f_elt
484 #include "math/m_trans_tmp.h"
487 #define INIT init_trans_2_GLfloat_elt
488 #define DEST_4F trans_2_GLfloat_4f_elt
489 #include "math/m_trans_tmp.h"
492 #define INIT init_trans_1_GLfloat_elt
493 #define DEST_4F trans_1_GLfloat_3f_elt
494 #define DEST_1UB trans_1_GLfloat_1ub_elt
495 #define DEST_1UI trans_1_GLfloat_1ui_elt
496 #define DEST_1F trans_1_GLfloat_1f_elt
497 #include "math/m_trans_tmp.h"
508 static void trans_4_GLubyte_4ub(GLubyte (*t
)[4],
513 const GLubyte
*f
= (GLubyte
*) Ptr
+ SRC_START
* stride
;
514 const GLubyte
*first
= f
;
517 if (((((long) f
| (long) stride
)) & 3L) == 0L) {
520 for (i
= DST_START
; i
< n
; i
++, NEXT_F
) {
523 COPY_4UBV( t
[i
], f
);
527 for (i
= DST_START
; i
< n
; i
++, NEXT_F
) {
540 static void init_translate_elt(void)
542 MEMSET( TAB(_1ui
), 0, sizeof(TAB(_1ui
)) );
543 MEMSET( TAB(_1ub
), 0, sizeof(TAB(_1ub
)) );
544 MEMSET( TAB(_3f
), 0, sizeof(TAB(_3f
)) );
545 MEMSET( TAB(_4ub
), 0, sizeof(TAB(_4ub
)) );
546 MEMSET( TAB(_4us
), 0, sizeof(TAB(_4us
)) );
547 MEMSET( TAB(_4f
), 0, sizeof(TAB(_4f
)) );
549 TAB(_4ub
)[4][TYPE_IDX(GL_UNSIGNED_BYTE
)] = trans_4_GLubyte_4ub
;
551 init_trans_4_GLbyte_elt();
552 init_trans_3_GLbyte_elt();
553 init_trans_2_GLbyte_elt();
554 init_trans_1_GLbyte_elt();
555 init_trans_1_GLubyte_elt();
556 init_trans_3_GLubyte_elt();
557 init_trans_4_GLubyte_elt();
558 init_trans_4_GLshort_elt();
559 init_trans_3_GLshort_elt();
560 init_trans_2_GLshort_elt();
561 init_trans_1_GLshort_elt();
562 init_trans_4_GLushort_elt();
563 init_trans_3_GLushort_elt();
564 init_trans_2_GLushort_elt();
565 init_trans_1_GLushort_elt();
566 init_trans_4_GLint_elt();
567 init_trans_3_GLint_elt();
568 init_trans_2_GLint_elt();
569 init_trans_1_GLint_elt();
570 init_trans_4_GLuint_elt();
571 init_trans_3_GLuint_elt();
572 init_trans_2_GLuint_elt();
573 init_trans_1_GLuint_elt();
574 init_trans_4_GLdouble_elt();
575 init_trans_3_GLdouble_elt();
576 init_trans_2_GLdouble_elt();
577 init_trans_1_GLdouble_elt();
578 init_trans_4_GLfloat_elt();
579 init_trans_3_GLfloat_elt();
580 init_trans_2_GLfloat_elt();
581 init_trans_1_GLfloat_elt();
594 void _tnl_imm_elt_init( void )
596 init_translate_elt();
600 static void _tnl_trans_elt_1f(GLfloat
*to
,
601 const struct gl_client_array
*from
,
608 _tnl_trans_elt_1f_tab
[TYPE_IDX(from
->Type
)]( to
,
619 static void _tnl_trans_elt_1ui(GLuint
*to
,
620 const struct gl_client_array
*from
,
627 _tnl_trans_elt_1ui_tab
[TYPE_IDX(from
->Type
)]( to
,
639 static void _tnl_trans_elt_1ub(GLubyte
*to
,
640 const struct gl_client_array
*from
,
647 _tnl_trans_elt_1ub_tab
[TYPE_IDX(from
->Type
)]( to
,
660 static void _tnl_trans_elt_4ub(GLubyte (*to
)[4],
661 const struct gl_client_array
*from
,
668 _tnl_trans_elt_4ub_tab
[from
->Size
][TYPE_IDX(from
->Type
)]( to
,
681 static void _tnl_trans_elt_4us(GLushort (*to
)[4],
682 const struct gl_client_array
*from
,
689 _tnl_trans_elt_4us_tab
[from
->Size
][TYPE_IDX(from
->Type
)]( to
,
701 static void _tnl_trans_elt_4f(GLfloat (*to
)[4],
702 const struct gl_client_array
*from
,
709 _tnl_trans_elt_4f_tab
[from
->Size
][TYPE_IDX(from
->Type
)]( to
,
722 static void _tnl_trans_elt_3f(GLfloat (*to
)[3],
723 const struct gl_client_array
*from
,
730 _tnl_trans_elt_3f_tab
[TYPE_IDX(from
->Type
)]( to
,
743 /* Batch function to translate away all the array elements in the
744 * input buffer prior to transform. Done only the first time a vertex
745 * buffer is executed or compiled.
747 * KW: Have to do this after each glEnd if arrays aren't locked.
749 void _tnl_translate_array_elts( GLcontext
*ctx
, struct immediate
*IM
,
750 GLuint start
, GLuint count
)
752 GLuint
*flags
= IM
->Flag
;
753 GLuint
*elts
= IM
->Elt
;
754 GLuint translate
= ctx
->Array
._Enabled
;
757 if (MESA_VERBOSE
&VERBOSE_IMMEDIATE
)
758 fprintf(stderr
, "exec_array_elements %d .. %d\n", start
, count
);
760 if (translate
& VERT_OBJ
) {
761 _tnl_trans_elt_4f( IM
->Obj
,
763 flags
, elts
, (VERT_ELT
|VERT_OBJ
),
766 if (ctx
->Array
.Vertex
.Size
== 4)
767 translate
|= VERT_OBJ_234
;
768 else if (ctx
->Array
.Vertex
.Size
== 3)
769 translate
|= VERT_OBJ_23
;
773 if (translate
& VERT_NORM
)
774 _tnl_trans_elt_3f( IM
->Normal
,
776 flags
, elts
, (VERT_ELT
|VERT_NORM
),
779 if (translate
& VERT_EDGE
)
780 _tnl_trans_elt_1ub( IM
->EdgeFlag
,
781 &ctx
->Array
.EdgeFlag
,
782 flags
, elts
, (VERT_ELT
|VERT_EDGE
),
785 if (translate
& VERT_RGBA
) {
786 _tnl_trans_elt_4f( IM
->Color
,
788 flags
, elts
, (VERT_ELT
|VERT_RGBA
),
792 if (translate
& VERT_SPEC_RGB
) {
793 _tnl_trans_elt_4f( IM
->SecondaryColor
,
794 &ctx
->Array
.SecondaryColor
,
795 flags
, elts
, (VERT_ELT
|VERT_SPEC_RGB
),
799 if (translate
& VERT_FOG_COORD
)
800 _tnl_trans_elt_1f( IM
->FogCoord
,
801 &ctx
->Array
.FogCoord
,
802 flags
, elts
, (VERT_ELT
|VERT_FOG_COORD
),
805 if (translate
& VERT_INDEX
)
806 _tnl_trans_elt_1ui( IM
->Index
,
808 flags
, elts
, (VERT_ELT
|VERT_INDEX
),
811 if (translate
& VERT_TEX_ANY
) {
812 for (i
= 0 ; i
< ctx
->Const
.MaxTextureUnits
; i
++)
813 if (translate
& VERT_TEX(i
)) {
814 _tnl_trans_elt_4f( IM
->TexCoord
[i
],
815 &ctx
->Array
.TexCoord
[i
],
816 flags
, elts
, (VERT_ELT
|VERT_TEX(i
)),
819 if (ctx
->Array
.TexCoord
[i
].Size
== 4)
820 IM
->TexSize
|= TEX_SIZE_4(i
);
821 else if (ctx
->Array
.TexCoord
[i
].Size
== 3)
822 IM
->TexSize
|= TEX_SIZE_3(i
);
826 for (i
= start
; i
< count
; i
++)
827 if (flags
[i
] & VERT_ELT
) flags
[i
] |= translate
;