2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
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 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * New (3.1) transformation code written by Keith Whitwell.
31 #include "mtypes.h" /* GLchan hack */
34 #include "m_translate.h"
38 typedef void (*trans_1f_func
)(GLfloat
*to
,
44 typedef void (*trans_1ui_func
)(GLuint
*to
,
50 typedef void (*trans_1ub_func
)(GLubyte
*to
,
56 typedef void (*trans_4ub_func
)(GLubyte (*to
)[4],
62 typedef void (*trans_4us_func
)(GLushort (*to
)[4],
68 typedef void (*trans_4f_func
)(GLfloat (*to
)[4],
74 typedef void (*trans_3f_func
)(GLfloat (*to
)[3],
83 #define TYPE_IDX(t) ((t) & 0xf)
84 #define MAX_TYPES TYPE_IDX(GL_DOUBLE)+1 /* 0xa + 1 */
87 /* This macro is used on other systems, so undefine it for this module */
91 static trans_1f_func _math_trans_1f_tab
[MAX_TYPES
];
92 static trans_1ui_func _math_trans_1ui_tab
[MAX_TYPES
];
93 static trans_1ub_func _math_trans_1ub_tab
[MAX_TYPES
];
94 static trans_3f_func _math_trans_3f_tab
[MAX_TYPES
];
95 static trans_4ub_func _math_trans_4ub_tab
[5][MAX_TYPES
];
96 static trans_4us_func _math_trans_4us_tab
[5][MAX_TYPES
];
97 static trans_4f_func _math_trans_4f_tab
[5][MAX_TYPES
];
98 static trans_4f_func _math_trans_4fc_tab
[5][MAX_TYPES
];
101 #define PTR_ELT(ptr, elt) (((SRC *)ptr)[elt])
104 #define TAB(x) _math_trans##x##_tab
105 #define ARGS GLuint start, GLuint n
106 #define SRC_START start
108 #define STRIDE stride
109 #define NEXT_F f += stride
119 #define SRC_IDX TYPE_IDX(GL_BYTE)
120 #define TRX_3F(f,n) BYTE_TO_FLOAT( PTR_ELT(f,n) )
121 #define TRX_4F(f,n) BYTE_TO_FLOAT( PTR_ELT(f,n) )
122 #define TRX_4FC(f,n) BYTE_TO_FLOAT( PTR_ELT(f,n) )
123 #define TRX_UB(ub, f,n) ub = BYTE_TO_UBYTE( PTR_ELT(f,n) )
124 #define TRX_US(ch, f,n) ch = BYTE_TO_USHORT( PTR_ELT(f,n) )
125 #define TRX_UI(f,n) (PTR_ELT(f,n) < 0 ? 0 : (GLuint) PTR_ELT(f,n))
129 #define INIT init_trans_4_GLbyte_raw
130 #define DEST_4F trans_4_GLbyte_4f_raw
131 #define DEST_4FC trans_4_GLbyte_4fc_raw
132 #define DEST_4UB trans_4_GLbyte_4ub_raw
133 #define DEST_4US trans_4_GLbyte_4us_raw
134 #include "m_trans_tmp.h"
137 #define INIT init_trans_3_GLbyte_raw
138 #define DEST_4F trans_3_GLbyte_4f_raw
139 #define DEST_4FC trans_3_GLbyte_4fc_raw
140 #define DEST_4UB trans_3_GLbyte_4ub_raw
141 #define DEST_4US trans_3_GLbyte_4us_raw
142 #define DEST_3F trans_3_GLbyte_3f_raw
143 #include "m_trans_tmp.h"
146 #define INIT init_trans_2_GLbyte_raw
147 #define DEST_4F trans_2_GLbyte_4f_raw
148 #define DEST_4FC trans_2_GLbyte_4fc_raw
149 #include "m_trans_tmp.h"
152 #define INIT init_trans_1_GLbyte_raw
153 #define DEST_4F trans_1_GLbyte_4f_raw
154 #define DEST_4FC trans_1_GLbyte_4fc_raw
155 #define DEST_1UB trans_1_GLbyte_1ub_raw
156 #define DEST_1UI trans_1_GLbyte_1ui_raw
157 #include "m_trans_tmp.h"
172 #define SRC_IDX TYPE_IDX(GL_UNSIGNED_BYTE)
173 #define TRX_3F(f,n) UBYTE_TO_FLOAT(PTR_ELT(f,n))
174 #define TRX_4F(f,n) UBYTE_TO_FLOAT(PTR_ELT(f,n))
175 #define TRX_4FC(f,n) UBYTE_TO_FLOAT(PTR_ELT(f,n))
176 #define TRX_UB(ub, f,n) ub = PTR_ELT(f,n)
177 #define TRX_US(us, f,n) us = UBYTE_TO_USHORT(PTR_ELT(f,n))
178 #define TRX_UI(f,n) (GLuint)PTR_ELT(f,n)
180 /* 4ub->4ub handled in special case below.
183 #define INIT init_trans_4_GLubyte_raw
184 #define DEST_4F trans_4_GLubyte_4f_raw
185 #define DEST_4FC trans_4_GLubyte_4fc_raw
186 #define DEST_4US trans_4_GLubyte_4us_raw
187 #include "m_trans_tmp.h"
191 #define INIT init_trans_3_GLubyte_raw
192 #define DEST_4UB trans_3_GLubyte_4ub_raw
193 #define DEST_4US trans_3_GLubyte_4us_raw
194 #define DEST_3F trans_3_GLubyte_3f_raw
195 #define DEST_4F trans_3_GLubyte_4f_raw
196 #define DEST_4FC trans_3_GLubyte_4fc_raw
197 #include "m_trans_tmp.h"
201 #define INIT init_trans_1_GLubyte_raw
202 #define DEST_1UI trans_1_GLubyte_1ui_raw
203 #define DEST_1UB trans_1_GLubyte_1ub_raw
204 #include "m_trans_tmp.h"
219 #define SRC_IDX TYPE_IDX(GL_SHORT)
220 #define TRX_3F(f,n) SHORT_TO_FLOAT( PTR_ELT(f,n) )
221 #define TRX_4F(f,n) (GLfloat)( PTR_ELT(f,n) )
222 #define TRX_4FC(f,n) (GLfloat)( PTR_ELT(f,n) )
223 #define TRX_UB(ub, f,n) ub = SHORT_TO_UBYTE(PTR_ELT(f,n))
224 #define TRX_US(us, f,n) us = SHORT_TO_USHORT(PTR_ELT(f,n))
225 #define TRX_UI(f,n) (PTR_ELT(f,n) < 0 ? 0 : (GLuint) PTR_ELT(f,n))
229 #define INIT init_trans_4_GLshort_raw
230 #define DEST_4F trans_4_GLshort_4f_raw
231 #define DEST_4FC trans_4_GLshort_4fc_raw
232 #define DEST_4UB trans_4_GLshort_4ub_raw
233 #define DEST_4US trans_4_GLshort_4us_raw
234 #include "m_trans_tmp.h"
237 #define INIT init_trans_3_GLshort_raw
238 #define DEST_4F trans_3_GLshort_4f_raw
239 #define DEST_4FC trans_3_GLshort_4fc_raw
240 #define DEST_4UB trans_3_GLshort_4ub_raw
241 #define DEST_4US trans_3_GLshort_4us_raw
242 #define DEST_3F trans_3_GLshort_3f_raw
243 #include "m_trans_tmp.h"
246 #define INIT init_trans_2_GLshort_raw
247 #define DEST_4F trans_2_GLshort_4f_raw
248 #define DEST_4FC trans_2_GLshort_4fc_raw
249 #include "m_trans_tmp.h"
252 #define INIT init_trans_1_GLshort_raw
253 #define DEST_4F trans_1_GLshort_4f_raw
254 #define DEST_4FC trans_1_GLshort_4fc_raw
255 #define DEST_1UB trans_1_GLshort_1ub_raw
256 #define DEST_1UI trans_1_GLshort_1ui_raw
257 #include "m_trans_tmp.h"
273 #define SRC_IDX TYPE_IDX(GL_UNSIGNED_SHORT)
274 #define TRX_3F(f,n) USHORT_TO_FLOAT( PTR_ELT(f,n) )
275 #define TRX_4F(f,n) (GLfloat)( PTR_ELT(f,n) )
276 #define TRX_4FC(f,n) (GLfloat)( PTR_ELT(f,n) )
277 #define TRX_UB(ub,f,n) ub = (GLubyte) (PTR_ELT(f,n) >> 8)
278 #define TRX_US(us,f,n) us = (GLushort) (PTR_ELT(f,n) >> 8)
279 #define TRX_UI(f,n) (GLuint) PTR_ELT(f,n)
283 #define INIT init_trans_4_GLushort_raw
284 #define DEST_4F trans_4_GLushort_4f_raw
285 #define DEST_4FC trans_4_GLushort_4fc_raw
286 #define DEST_4UB trans_4_GLushort_4ub_raw
287 #define DEST_4US trans_4_GLushort_4us_raw
288 #include "m_trans_tmp.h"
291 #define INIT init_trans_3_GLushort_raw
292 #define DEST_4F trans_3_GLushort_4f_raw
293 #define DEST_4FC trans_3_GLushort_4fc_raw
294 #define DEST_4UB trans_3_GLushort_4ub_raw
295 #define DEST_4US trans_3_GLushort_4us_raw
296 #define DEST_3F trans_3_GLushort_3f_raw
297 #include "m_trans_tmp.h"
300 #define INIT init_trans_2_GLushort_raw
301 #define DEST_4F trans_2_GLushort_4f_raw
302 #define DEST_4FC trans_2_GLushort_4fc_raw
303 #include "m_trans_tmp.h"
306 #define INIT init_trans_1_GLushort_raw
307 #define DEST_4F trans_1_GLushort_4f_raw
308 #define DEST_4FC trans_1_GLushort_4fc_raw
309 #define DEST_1UB trans_1_GLushort_1ub_raw
310 #define DEST_1UI trans_1_GLushort_1ui_raw
311 #include "m_trans_tmp.h"
326 #define SRC_IDX TYPE_IDX(GL_INT)
327 #define TRX_3F(f,n) INT_TO_FLOAT( PTR_ELT(f,n) )
328 #define TRX_4F(f,n) (GLfloat)( PTR_ELT(f,n) )
329 #define TRX_4FC(f,n) (GLfloat)( PTR_ELT(f,n) )
330 #define TRX_UB(ub, f,n) ub = INT_TO_UBYTE(PTR_ELT(f,n))
331 #define TRX_US(us, f,n) us = INT_TO_USHORT(PTR_ELT(f,n))
332 #define TRX_UI(f,n) (PTR_ELT(f,n) < 0 ? 0 : (GLuint) PTR_ELT(f,n))
336 #define INIT init_trans_4_GLint_raw
337 #define DEST_4F trans_4_GLint_4f_raw
338 #define DEST_4FC trans_4_GLint_4fc_raw
339 #define DEST_4UB trans_4_GLint_4ub_raw
340 #define DEST_4US trans_4_GLint_4us_raw
341 #include "m_trans_tmp.h"
344 #define INIT init_trans_3_GLint_raw
345 #define DEST_4F trans_3_GLint_4f_raw
346 #define DEST_4FC trans_3_GLint_4fc_raw
347 #define DEST_4UB trans_3_GLint_4ub_raw
348 #define DEST_4US trans_3_GLint_4us_raw
349 #define DEST_3F trans_3_GLint_3f_raw
350 #include "m_trans_tmp.h"
353 #define INIT init_trans_2_GLint_raw
354 #define DEST_4F trans_2_GLint_4f_raw
355 #define DEST_4FC trans_2_GLint_4fc_raw
356 #include "m_trans_tmp.h"
359 #define INIT init_trans_1_GLint_raw
360 #define DEST_4F trans_1_GLint_4f_raw
361 #define DEST_4FC trans_1_GLint_4fc_raw
362 #define DEST_1UB trans_1_GLint_1ub_raw
363 #define DEST_1UI trans_1_GLint_1ui_raw
364 #include "m_trans_tmp.h"
380 #define SRC_IDX TYPE_IDX(GL_UNSIGNED_INT)
381 #define TRX_3F(f,n) INT_TO_FLOAT( PTR_ELT(f,n) )
382 #define TRX_4F(f,n) (GLfloat)( PTR_ELT(f,n) )
383 #define TRX_4FC(f,n) (GLfloat)( PTR_ELT(f,n) )
384 #define TRX_UB(ub, f,n) ub = (GLubyte) (PTR_ELT(f,n) >> 24)
385 #define TRX_US(us, f,n) us = (GLshort) (PTR_ELT(f,n) >> 16)
386 #define TRX_UI(f,n) PTR_ELT(f,n)
390 #define INIT init_trans_4_GLuint_raw
391 #define DEST_4F trans_4_GLuint_4f_raw
392 #define DEST_4FC trans_4_GLuint_4fc_raw
393 #define DEST_4UB trans_4_GLuint_4ub_raw
394 #define DEST_4US trans_4_GLuint_4us_raw
395 #include "m_trans_tmp.h"
398 #define INIT init_trans_3_GLuint_raw
399 #define DEST_4F trans_3_GLuint_4f_raw
400 #define DEST_4FC trans_3_GLuint_4fc_raw
401 #define DEST_4UB trans_3_GLuint_4ub_raw
402 #define DEST_4US trans_3_GLuint_4us_raw
403 #define DEST_3F trans_3_GLuint_3f_raw
404 #include "m_trans_tmp.h"
407 #define INIT init_trans_2_GLuint_raw
408 #define DEST_4F trans_2_GLuint_4f_raw
409 #define DEST_4FC trans_2_GLuint_4fc_raw
410 #include "m_trans_tmp.h"
413 #define INIT init_trans_1_GLuint_raw
414 #define DEST_4F trans_1_GLuint_4f_raw
415 #define DEST_4FC trans_1_GLuint_4fc_raw
416 #define DEST_1UB trans_1_GLuint_1ub_raw
417 #define DEST_1UI trans_1_GLuint_1ui_raw
418 #include "m_trans_tmp.h"
433 #define SRC_IDX TYPE_IDX(GL_DOUBLE)
434 #define TRX_3F(f,n) (GLfloat) PTR_ELT(f,n)
435 #define TRX_4F(f,n) (GLfloat) PTR_ELT(f,n)
436 #define TRX_4FC(f,n) (GLfloat) PTR_ELT(f,n)
437 #define TRX_UB(ub,f,n) UNCLAMPED_FLOAT_TO_UBYTE(ub, PTR_ELT(f,n))
438 #define TRX_US(us,f,n) UNCLAMPED_FLOAT_TO_USHORT(us, PTR_ELT(f,n))
439 #define TRX_UI(f,n) (GLuint) (GLint) PTR_ELT(f,n)
440 #define TRX_1F(f,n) (GLfloat) PTR_ELT(f,n)
444 #define INIT init_trans_4_GLdouble_raw
445 #define DEST_4F trans_4_GLdouble_4f_raw
446 #define DEST_4FC trans_4_GLdouble_4fc_raw
447 #define DEST_4UB trans_4_GLdouble_4ub_raw
448 #define DEST_4US trans_4_GLdouble_4us_raw
449 #include "m_trans_tmp.h"
452 #define INIT init_trans_3_GLdouble_raw
453 #define DEST_4F trans_3_GLdouble_4f_raw
454 #define DEST_4FC trans_3_GLdouble_4fc_raw
455 #define DEST_4UB trans_3_GLdouble_4ub_raw
456 #define DEST_4US trans_3_GLdouble_4us_raw
457 #define DEST_3F trans_3_GLdouble_3f_raw
458 #include "m_trans_tmp.h"
461 #define INIT init_trans_2_GLdouble_raw
462 #define DEST_4F trans_2_GLdouble_4f_raw
463 #define DEST_4FC trans_2_GLdouble_4fc_raw
464 #include "m_trans_tmp.h"
467 #define INIT init_trans_1_GLdouble_raw
468 #define DEST_4F trans_1_GLdouble_4f_raw
469 #define DEST_4FC trans_1_GLdouble_4fc_raw
470 #define DEST_1UB trans_1_GLdouble_1ub_raw
471 #define DEST_1UI trans_1_GLdouble_1ui_raw
472 #define DEST_1F trans_1_GLdouble_1f_raw
473 #include "m_trans_tmp.h"
481 #define SRC_IDX TYPE_IDX(GL_FLOAT)
483 #define INIT init_trans_4_GLfloat_raw
484 #define DEST_4UB trans_4_GLfloat_4ub_raw
485 #define DEST_4US trans_4_GLfloat_4us_raw
486 #define DEST_4F trans_4_GLfloat_4f_raw
487 #define DEST_4FC trans_4_GLfloat_4fc_raw
488 #include "m_trans_tmp.h"
491 #define INIT init_trans_3_GLfloat_raw
492 #define DEST_4F trans_3_GLfloat_4f_raw
493 #define DEST_4FC trans_3_GLfloat_4fc_raw
494 #define DEST_4UB trans_3_GLfloat_4ub_raw
495 #define DEST_4US trans_3_GLfloat_4us_raw
496 #define DEST_3F trans_3_GLfloat_3f_raw
497 #include "m_trans_tmp.h"
500 #define INIT init_trans_2_GLfloat_raw
501 #define DEST_4F trans_2_GLfloat_4f_raw
502 #define DEST_4FC trans_2_GLfloat_4fc_raw
503 #include "m_trans_tmp.h"
506 #define INIT init_trans_1_GLfloat_raw
507 #define DEST_4F trans_1_GLfloat_4f_raw
508 #define DEST_4FC trans_1_GLfloat_4fc_raw
509 #define DEST_1UB trans_1_GLfloat_1ub_raw
510 #define DEST_1UI trans_1_GLfloat_1ui_raw
511 #define DEST_1F trans_1_GLfloat_1f_raw
513 #include "m_trans_tmp.h"
525 static void trans_4_GLubyte_4ub_raw(GLubyte (*t
)[4],
530 const GLubyte
*f
= (GLubyte
*) Ptr
+ SRC_START
* stride
;
533 if (((((uintptr_t) f
| (uintptr_t) stride
)) & 3L) == 0L) {
536 for (i
= DST_START
; i
< n
; i
++, f
+= stride
) {
537 COPY_4UBV( t
[i
], f
);
540 for (i
= DST_START
; i
< n
; i
++, f
+= stride
) {
550 static void init_translate_raw(void)
552 MEMSET( TAB(_1ui
), 0, sizeof(TAB(_1ui
)) );
553 MEMSET( TAB(_1ub
), 0, sizeof(TAB(_1ub
)) );
554 MEMSET( TAB(_3f
), 0, sizeof(TAB(_3f
)) );
555 MEMSET( TAB(_4ub
), 0, sizeof(TAB(_4ub
)) );
556 MEMSET( TAB(_4us
), 0, sizeof(TAB(_4us
)) );
557 MEMSET( TAB(_4f
), 0, sizeof(TAB(_4f
)) );
558 MEMSET( TAB(_4fc
), 0, sizeof(TAB(_4fc
)) );
560 init_trans_4_GLbyte_raw();
561 init_trans_3_GLbyte_raw();
562 init_trans_2_GLbyte_raw();
563 init_trans_1_GLbyte_raw();
564 init_trans_1_GLubyte_raw();
565 init_trans_3_GLubyte_raw();
566 init_trans_4_GLubyte_raw();
567 init_trans_4_GLshort_raw();
568 init_trans_3_GLshort_raw();
569 init_trans_2_GLshort_raw();
570 init_trans_1_GLshort_raw();
571 init_trans_4_GLushort_raw();
572 init_trans_3_GLushort_raw();
573 init_trans_2_GLushort_raw();
574 init_trans_1_GLushort_raw();
575 init_trans_4_GLint_raw();
576 init_trans_3_GLint_raw();
577 init_trans_2_GLint_raw();
578 init_trans_1_GLint_raw();
579 init_trans_4_GLuint_raw();
580 init_trans_3_GLuint_raw();
581 init_trans_2_GLuint_raw();
582 init_trans_1_GLuint_raw();
583 init_trans_4_GLdouble_raw();
584 init_trans_3_GLdouble_raw();
585 init_trans_2_GLdouble_raw();
586 init_trans_1_GLdouble_raw();
587 init_trans_4_GLfloat_raw();
588 init_trans_3_GLfloat_raw();
589 init_trans_2_GLfloat_raw();
590 init_trans_1_GLfloat_raw();
592 TAB(_4ub
)[4][TYPE_IDX(GL_UNSIGNED_BYTE
)] = trans_4_GLubyte_4ub_raw
;
611 void _math_init_translate( void )
613 init_translate_raw();
618 void _math_trans_1f(GLfloat
*to
,
625 _math_trans_1f_tab
[TYPE_IDX(type
)]( to
, ptr
, stride
, start
, n
);
628 void _math_trans_1ui(GLuint
*to
,
635 _math_trans_1ui_tab
[TYPE_IDX(type
)]( to
, ptr
, stride
, start
, n
);
638 void _math_trans_1ub(GLubyte
*to
,
645 _math_trans_1ub_tab
[TYPE_IDX(type
)]( to
, ptr
, stride
, start
, n
);
649 void _math_trans_4ub(GLubyte (*to
)[4],
657 _math_trans_4ub_tab
[size
][TYPE_IDX(type
)]( to
, ptr
, stride
, start
, n
);
660 void _math_trans_4chan( GLchan (*to
)[4],
668 #if CHAN_TYPE == GL_UNSIGNED_BYTE
669 _math_trans_4ub( to
, ptr
, stride
, type
, size
, start
, n
);
670 #elif CHAN_TYPE == GL_UNSIGNED_SHORT
671 _math_trans_4us( to
, ptr
, stride
, type
, size
, start
, n
);
672 #elif CHAN_TYPE == GL_FLOAT
673 _math_trans_4fc( to
, ptr
, stride
, type
, size
, start
, n
);
677 void _math_trans_4us(GLushort (*to
)[4],
685 _math_trans_4us_tab
[size
][TYPE_IDX(type
)]( to
, ptr
, stride
, start
, n
);
688 void _math_trans_4f(GLfloat (*to
)[4],
696 _math_trans_4f_tab
[size
][TYPE_IDX(type
)]( to
, ptr
, stride
, start
, n
);
699 void _math_trans_4fc(GLfloat (*to
)[4],
707 _math_trans_4fc_tab
[size
][TYPE_IDX(type
)]( to
, ptr
, stride
, start
, n
);
710 void _math_trans_3f(GLfloat (*to
)[3],
717 _math_trans_3f_tab
[TYPE_IDX(type
)]( to
, ptr
, stride
, start
, n
);