1 /* $Id: t_imm_elt.c,v 1.2 2001/01/02 22:02:53 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999 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_4f_func
)(GLfloat (*to
)[4],
88 typedef void (*trans_elt_3f_func
)(GLfloat (*to
)[3],
100 static trans_elt_1f_func _tnl_trans_elt_1f_tab
[MAX_TYPES
];
101 static trans_elt_1ui_func _tnl_trans_elt_1ui_tab
[MAX_TYPES
];
102 static trans_elt_1ub_func _tnl_trans_elt_1ub_tab
[MAX_TYPES
];
103 static trans_elt_3f_func _tnl_trans_elt_3f_tab
[MAX_TYPES
];
104 static trans_elt_4ub_func _tnl_trans_elt_4ub_tab
[5][MAX_TYPES
];
105 static trans_elt_4f_func _tnl_trans_elt_4f_tab
[5][MAX_TYPES
];
108 #define PTR_ELT(ptr, elt) (((SRC *)ptr)[elt])
114 /* Code specific to array element implementation. There is a small
115 * subtlety in the bits CHECK() tests, and the way bits are set in
116 * glArrayElement which ensures that if, eg, in the case that the
117 * vertex array is disabled and normal array is enabled, and we get
120 * ArrayElement() OR Normal()
121 * Normal() ArrayElement()
124 * That the correct value for normal is used.
126 #define TAB(x) _tnl_trans_elt##x##_tab
127 #define ARGS GLuint *flags, GLuint *elts, GLuint match, \
128 GLuint start, GLuint n
130 #define DST_START start
132 #define CHECK if ((flags[i]&match) == VERT_ELT)
133 #define NEXT_F (void)1
134 #define NEXT_F2 f = first + elts[i] * stride;
140 #define SRC_IDX TYPE_IDX(GL_BYTE)
141 #define TRX_3F(f,n) BYTE_TO_FLOAT( PTR_ELT(f,n) )
142 #define TRX_4F(f,n) (GLfloat)( PTR_ELT(f,n) )
143 #define TRX_UB(ub, f,n) ub = BYTE_TO_UBYTE( PTR_ELT(f,n) )
144 #define TRX_UI(f,n) (PTR_ELT(f,n) < 0 ? 0 : (GLuint) PTR_ELT(f,n))
148 #define INIT init_trans_4_GLbyte_elt
149 #define DEST_4F trans_4_GLbyte_4f_elt
150 #define DEST_4UB trans_4_GLbyte_4ub_elt
151 #include "math/m_trans_tmp.h"
154 #define INIT init_trans_3_GLbyte_elt
155 #define DEST_4F trans_3_GLbyte_4f_elt
156 #define DEST_4UB trans_3_GLbyte_4ub_elt
157 #define DEST_3F trans_3_GLbyte_3f_elt
158 #include "math/m_trans_tmp.h"
161 #define INIT init_trans_2_GLbyte_elt
162 #define DEST_4F trans_2_GLbyte_4f_elt
163 #include "math/m_trans_tmp.h"
166 #define INIT init_trans_1_GLbyte_elt
167 #define DEST_4F trans_1_GLbyte_4f_elt
168 #define DEST_1UB trans_1_GLbyte_1ub_elt
169 #define DEST_1UI trans_1_GLbyte_1ui_elt
170 #include "math/m_trans_tmp.h"
182 #define SRC_IDX TYPE_IDX(GL_UNSIGNED_BYTE)
183 #define TRX_3F(f,n) /* unused */
184 #define TRX_4F(f,n) /* unused */
185 #define TRX_UB(ub, f,n) ub = PTR_ELT(f,n)
186 #define TRX_UI(f,n) (GLuint)PTR_ELT(f,n)
188 /* 4ub->4ub handled in special case below.
192 #define INIT init_trans_3_GLubyte_elt
193 #define DEST_4UB trans_3_GLubyte_4ub_elt
194 #include "math/m_trans_tmp.h"
198 #define INIT init_trans_1_GLubyte_elt
199 #define DEST_1UI trans_1_GLubyte_1ui_elt
200 #define DEST_1UB trans_1_GLubyte_1ub_elt
201 #include "math/m_trans_tmp.h"
214 #define SRC_IDX TYPE_IDX(GL_SHORT)
215 #define TRX_3F(f,n) SHORT_TO_FLOAT( PTR_ELT(f,n) )
216 #define TRX_4F(f,n) (GLfloat)( PTR_ELT(f,n) )
217 #define TRX_UB(ub, f,n) ub = SHORT_TO_UBYTE(PTR_ELT(f,n))
218 #define TRX_UI(f,n) (PTR_ELT(f,n) < 0 ? 0 : (GLuint) PTR_ELT(f,n))
222 #define INIT init_trans_4_GLshort_elt
223 #define DEST_4F trans_4_GLshort_4f_elt
224 #define DEST_4UB trans_4_GLshort_4ub_elt
225 #include "math/m_trans_tmp.h"
228 #define INIT init_trans_3_GLshort_elt
229 #define DEST_4F trans_3_GLshort_4f_elt
230 #define DEST_4UB trans_3_GLshort_4ub_elt
231 #define DEST_3F trans_3_GLshort_3f_elt
232 #include "math/m_trans_tmp.h"
235 #define INIT init_trans_2_GLshort_elt
236 #define DEST_4F trans_2_GLshort_4f_elt
237 #include "math/m_trans_tmp.h"
240 #define INIT init_trans_1_GLshort_elt
241 #define DEST_4F trans_1_GLshort_4f_elt
242 #define DEST_1UB trans_1_GLshort_1ub_elt
243 #define DEST_1UI trans_1_GLshort_1ui_elt
244 #include "math/m_trans_tmp.h"
258 #define SRC_IDX TYPE_IDX(GL_UNSIGNED_SHORT)
259 #define TRX_3F(f,n) USHORT_TO_FLOAT( PTR_ELT(f,n) )
260 #define TRX_4F(f,n) (GLfloat)( PTR_ELT(f,n) )
261 #define TRX_UB(ub,f,n) ub = (GLubyte) (PTR_ELT(f,n) >> 8)
262 #define TRX_UI(f,n) (GLuint) PTR_ELT(f,n)
266 #define INIT init_trans_4_GLushort_elt
267 #define DEST_4F trans_4_GLushort_4f_elt
268 #define DEST_4UB trans_4_GLushort_4ub_elt
269 #include "math/m_trans_tmp.h"
272 #define INIT init_trans_3_GLushort_elt
273 #define DEST_4F trans_3_GLushort_4f_elt
274 #define DEST_4UB trans_3_GLushort_4ub_elt
275 #define DEST_3F trans_3_GLushort_3f_elt
276 #include "math/m_trans_tmp.h"
279 #define INIT init_trans_2_GLushort_elt
280 #define DEST_4F trans_2_GLushort_4f_elt
281 #include "math/m_trans_tmp.h"
284 #define INIT init_trans_1_GLushort_elt
285 #define DEST_4F trans_1_GLushort_4f_elt
286 #define DEST_1UB trans_1_GLushort_1ub_elt
287 #define DEST_1UI trans_1_GLushort_1ui_elt
288 #include "math/m_trans_tmp.h"
301 #define SRC_IDX TYPE_IDX(GL_INT)
302 #define TRX_3F(f,n) INT_TO_FLOAT( PTR_ELT(f,n) )
303 #define TRX_4F(f,n) (GLfloat)( PTR_ELT(f,n) )
304 #define TRX_UB(ub, f,n) ub = INT_TO_UBYTE(PTR_ELT(f,n))
305 #define TRX_UI(f,n) (PTR_ELT(f,n) < 0 ? 0 : (GLuint) PTR_ELT(f,n))
309 #define INIT init_trans_4_GLint_elt
310 #define DEST_4F trans_4_GLint_4f_elt
311 #define DEST_4UB trans_4_GLint_4ub_elt
312 #include "math/m_trans_tmp.h"
315 #define INIT init_trans_3_GLint_elt
316 #define DEST_4F trans_3_GLint_4f_elt
317 #define DEST_4UB trans_3_GLint_4ub_elt
318 #define DEST_3F trans_3_GLint_3f_elt
319 #include "math/m_trans_tmp.h"
322 #define INIT init_trans_2_GLint_elt
323 #define DEST_4F trans_2_GLint_4f_elt
324 #include "math/m_trans_tmp.h"
327 #define INIT init_trans_1_GLint_elt
328 #define DEST_4F trans_1_GLint_4f_elt
329 #define DEST_1UB trans_1_GLint_1ub_elt
330 #define DEST_1UI trans_1_GLint_1ui_elt
331 #include "math/m_trans_tmp.h"
345 #define SRC_IDX TYPE_IDX(GL_UNSIGNED_INT)
346 #define TRX_3F(f,n) UINT_TO_FLOAT( PTR_ELT(f,n) )
347 #define TRX_4F(f,n) (GLfloat)( PTR_ELT(f,n) )
348 #define TRX_UB(ub, f,n) ub = (GLubyte) (PTR_ELT(f,n) >> 24)
349 #define TRX_UI(f,n) PTR_ELT(f,n)
353 #define INIT init_trans_4_GLuint_elt
354 #define DEST_4F trans_4_GLuint_4f_elt
355 #define DEST_4UB trans_4_GLuint_4ub_elt
356 #include "math/m_trans_tmp.h"
359 #define INIT init_trans_3_GLuint_elt
360 #define DEST_4F trans_3_GLuint_4f_elt
361 #define DEST_4UB trans_3_GLuint_4ub_elt
362 #define DEST_3F trans_3_GLuint_3f_elt
363 #include "math/m_trans_tmp.h"
366 #define INIT init_trans_2_GLuint_elt
367 #define DEST_4F trans_2_GLuint_4f_elt
368 #include "math/m_trans_tmp.h"
371 #define INIT init_trans_1_GLuint_elt
372 #define DEST_4F trans_1_GLuint_4f_elt
373 #define DEST_1UB trans_1_GLuint_1ub_elt
374 #define DEST_1UI trans_1_GLuint_1ui_elt
375 #include "math/m_trans_tmp.h"
388 #define SRC_IDX TYPE_IDX(GL_DOUBLE)
389 #define TRX_3F(f,n) PTR_ELT(f,n)
390 #define TRX_4F(f,n) PTR_ELT(f,n)
391 #define TRX_UB(ub,f,n) UNCLAMPED_FLOAT_TO_CHAN(ub, PTR_ELT(f,n))
392 #define TRX_UI(f,n) (GLuint) (GLint) PTR_ELT(f,n)
393 #define TRX_1F(f,n) PTR_ELT(f,n)
397 #define INIT init_trans_4_GLdouble_elt
398 #define DEST_4F trans_4_GLdouble_4f_elt
399 #define DEST_4UB trans_4_GLdouble_4ub_elt
400 #include "math/m_trans_tmp.h"
403 #define INIT init_trans_3_GLdouble_elt
404 #define DEST_4F trans_3_GLdouble_4f_elt
405 #define DEST_4UB trans_3_GLdouble_4ub_elt
406 #define DEST_3F trans_3_GLdouble_3f_elt
407 #include "math/m_trans_tmp.h"
410 #define INIT init_trans_2_GLdouble_elt
411 #define DEST_4F trans_2_GLdouble_4f_elt
412 #include "math/m_trans_tmp.h"
415 #define INIT init_trans_1_GLdouble_elt
416 #define DEST_4F trans_1_GLdouble_4f_elt
417 #define DEST_1UB trans_1_GLdouble_1ub_elt
418 #define DEST_1UI trans_1_GLdouble_1ui_elt
419 #define DEST_1F trans_1_GLdouble_1f_elt
420 #include "math/m_trans_tmp.h"
428 #define SRC_IDX TYPE_IDX(GL_FLOAT)
430 #define INIT init_trans_4_GLfloat_elt
431 #define DEST_4UB trans_4_GLfloat_4ub_elt
432 #define DEST_4F trans_4_GLfloat_4f_elt
433 #include "math/m_trans_tmp.h"
436 #define INIT init_trans_3_GLfloat_elt
437 #define DEST_4F trans_3_GLfloat_4f_elt
438 #define DEST_4UB trans_3_GLfloat_4ub_elt
439 #define DEST_3F trans_3_GLfloat_3f_elt
440 #include "math/m_trans_tmp.h"
443 #define INIT init_trans_2_GLfloat_elt
444 #define DEST_4F trans_2_GLfloat_4f_elt
445 #include "math/m_trans_tmp.h"
448 #define INIT init_trans_1_GLfloat_elt
449 #define DEST_4F trans_1_GLfloat_3f_elt
450 #define DEST_1UB trans_1_GLfloat_1ub_elt
451 #define DEST_1UI trans_1_GLfloat_1ui_elt
452 #define DEST_1F trans_1_GLfloat_1f_elt
453 #include "math/m_trans_tmp.h"
463 static void trans_4_GLubyte_4ub(GLubyte (*t
)[4],
468 const GLubyte
*f
= (GLubyte
*) Ptr
+ SRC_START
* stride
;
469 const GLubyte
*first
= f
;
472 if (((((long) f
| (long) stride
)) & 3L) == 0L) {
475 for (i
= DST_START
; i
< n
; i
++, NEXT_F
) {
478 COPY_4UBV( t
[i
], f
);
482 for (i
= DST_START
; i
< n
; i
++, NEXT_F
) {
495 static void init_translate_elt(void)
497 MEMSET( TAB(_1ui
), 0, sizeof(TAB(_1ui
)) );
498 MEMSET( TAB(_1ub
), 0, sizeof(TAB(_1ub
)) );
499 MEMSET( TAB(_3f
), 0, sizeof(TAB(_3f
)) );
500 MEMSET( TAB(_4ub
), 0, sizeof(TAB(_4ub
)) );
501 MEMSET( TAB(_4f
), 0, sizeof(TAB(_4f
)) );
503 TAB(_4ub
)[4][TYPE_IDX(GL_UNSIGNED_BYTE
)] = trans_4_GLubyte_4ub
;
505 init_trans_4_GLbyte_elt();
506 init_trans_3_GLbyte_elt();
507 init_trans_2_GLbyte_elt();
508 init_trans_1_GLbyte_elt();
509 init_trans_1_GLubyte_elt();
510 init_trans_3_GLubyte_elt();
511 init_trans_4_GLshort_elt();
512 init_trans_3_GLshort_elt();
513 init_trans_2_GLshort_elt();
514 init_trans_1_GLshort_elt();
515 init_trans_4_GLushort_elt();
516 init_trans_3_GLushort_elt();
517 init_trans_2_GLushort_elt();
518 init_trans_1_GLushort_elt();
519 init_trans_4_GLint_elt();
520 init_trans_3_GLint_elt();
521 init_trans_2_GLint_elt();
522 init_trans_1_GLint_elt();
523 init_trans_4_GLuint_elt();
524 init_trans_3_GLuint_elt();
525 init_trans_2_GLuint_elt();
526 init_trans_1_GLuint_elt();
527 init_trans_4_GLdouble_elt();
528 init_trans_3_GLdouble_elt();
529 init_trans_2_GLdouble_elt();
530 init_trans_1_GLdouble_elt();
531 init_trans_4_GLfloat_elt();
532 init_trans_3_GLfloat_elt();
533 init_trans_2_GLfloat_elt();
534 init_trans_1_GLfloat_elt();
547 void _tnl_imm_elt_init( void )
549 init_translate_elt();
553 static void _tnl_trans_elt_1f(GLfloat
*to
,
554 const struct gl_client_array
*from
,
561 _tnl_trans_elt_1f_tab
[TYPE_IDX(from
->Type
)]( to
,
572 static void _tnl_trans_elt_1ui(GLuint
*to
,
573 const struct gl_client_array
*from
,
580 _tnl_trans_elt_1ui_tab
[TYPE_IDX(from
->Type
)]( to
,
592 static void _tnl_trans_elt_1ub(GLubyte
*to
,
593 const struct gl_client_array
*from
,
600 _tnl_trans_elt_1ub_tab
[TYPE_IDX(from
->Type
)]( to
,
612 static void _tnl_trans_elt_4ub(GLubyte (*to
)[4],
613 const struct gl_client_array
*from
,
620 _tnl_trans_elt_4ub_tab
[from
->Size
][TYPE_IDX(from
->Type
)]( to
,
631 static void _tnl_trans_elt_4f(GLfloat (*to
)[4],
632 const struct gl_client_array
*from
,
639 _tnl_trans_elt_4f_tab
[from
->Size
][TYPE_IDX(from
->Type
)]( to
,
650 static void _tnl_trans_elt_3f(GLfloat (*to
)[3],
651 const struct gl_client_array
*from
,
658 _tnl_trans_elt_3f_tab
[TYPE_IDX(from
->Type
)]( to
,
671 /* Batch function to translate away all the array elements in the
672 * input buffer prior to transform. Done only the first time a vertex
673 * buffer is executed or compiled.
675 * KW: Have to do this after each glEnd if arrays aren't locked.
677 void _tnl_translate_array_elts( GLcontext
*ctx
, struct immediate
*IM
,
678 GLuint start
, GLuint count
)
680 GLuint
*flags
= IM
->Flag
;
681 GLuint
*elts
= IM
->Elt
;
682 GLuint translate
= ctx
->Array
._Enabled
;
685 if (MESA_VERBOSE
&VERBOSE_IMMEDIATE
)
686 fprintf(stderr
, "exec_array_elements %d .. %d\n", start
, count
);
688 if (translate
& VERT_OBJ
) {
689 _tnl_trans_elt_4f( IM
->Obj
,
691 flags
, elts
, (VERT_ELT
|VERT_OBJ
),
694 if (ctx
->Array
.Vertex
.Size
== 4)
695 translate
|= VERT_OBJ_234
;
696 else if (ctx
->Array
.Vertex
.Size
== 3)
697 translate
|= VERT_OBJ_23
;
701 if (translate
& VERT_NORM
)
702 _tnl_trans_elt_3f( IM
->Normal
,
704 flags
, elts
, (VERT_ELT
|VERT_NORM
),
707 if (translate
& VERT_EDGE
)
708 _tnl_trans_elt_1ub( IM
->EdgeFlag
,
709 &ctx
->Array
.EdgeFlag
,
710 flags
, elts
, (VERT_ELT
|VERT_EDGE
),
713 if (translate
& VERT_RGBA
)
714 _tnl_trans_elt_4ub( IM
->Color
,
716 flags
, elts
, (VERT_ELT
|VERT_RGBA
),
720 if (translate
& VERT_SPEC_RGB
)
721 _tnl_trans_elt_4ub( IM
->SecondaryColor
,
722 &ctx
->Array
.SecondaryColor
,
723 flags
, elts
, (VERT_ELT
|VERT_SPEC_RGB
),
726 if (translate
& VERT_FOG_COORD
)
727 _tnl_trans_elt_1f( IM
->FogCoord
,
728 &ctx
->Array
.FogCoord
,
729 flags
, elts
, (VERT_ELT
|VERT_FOG_COORD
),
732 if (translate
& VERT_INDEX
)
733 _tnl_trans_elt_1ui( IM
->Index
,
735 flags
, elts
, (VERT_ELT
|VERT_INDEX
),
738 if (translate
& VERT_TEX_ANY
) {
739 for (i
= 0 ; i
< ctx
->Const
.MaxTextureUnits
; i
++)
740 if (translate
& VERT_TEX(i
)) {
741 _tnl_trans_elt_4f( IM
->TexCoord
[i
],
742 &ctx
->Array
.TexCoord
[i
],
743 flags
, elts
, (VERT_ELT
|VERT_TEX(i
)),
746 if (ctx
->Array
.TexCoord
[i
].Size
== 4)
747 IM
->TexSize
|= TEX_SIZE_4(i
);
748 else if (ctx
->Array
.TexCoord
[i
].Size
== 3)
749 IM
->TexSize
|= TEX_SIZE_3(i
);
753 for (i
= start
; i
< count
; i
++)
754 if (flags
[i
] & VERT_ELT
) flags
[i
] |= translate
;
756 IM
->CopyOrFlag
|= translate
;