Tizen 2.0 Release
[profile/ivi/osmesa.git] / src / mesa / math / m_translate.c
1 /*
2  * Mesa 3-D graphics library
3  * Version:  6.5.1
4  *
5  * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
6  *
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:
13  *
14  * The above copyright notice and this permission notice shall be included
15  * in all copies or substantial portions of the Software.
16  *
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.
23  */
24
25 /**
26  * \brief  Translate vectors of numbers between various types.
27  * \author Keith Whitwell.
28  */
29
30
31 #include "main/glheader.h"
32 #include "main/macros.h"
33 #include "main/mtypes.h"                /* GLchan hack */
34
35 #include "m_translate.h"
36
37
38
39 typedef void (*trans_1f_func)(GLfloat *to,
40                               CONST void *ptr,
41                               GLuint stride,
42                               GLuint start,
43                               GLuint n );
44
45 typedef void (*trans_1ui_func)(GLuint *to,
46                                CONST void *ptr,
47                                GLuint stride,
48                                GLuint start,
49                                GLuint n );
50
51 typedef void (*trans_1ub_func)(GLubyte *to,
52                                CONST void *ptr,
53                                GLuint stride,
54                                GLuint start,
55                                GLuint n );
56
57 typedef void (*trans_4ub_func)(GLubyte (*to)[4],
58                                CONST void *ptr,
59                                GLuint stride,
60                                GLuint start,
61                                GLuint n );
62
63 typedef void (*trans_4us_func)(GLushort (*to)[4],
64                                CONST void *ptr,
65                                GLuint stride,
66                                GLuint start,
67                                GLuint n );
68
69 typedef void (*trans_4f_func)(GLfloat (*to)[4],
70                               CONST void *ptr,
71                               GLuint stride,
72                               GLuint start,
73                               GLuint n );
74
75 typedef void (*trans_3fn_func)(GLfloat (*to)[3],
76                               CONST void *ptr,
77                               GLuint stride,
78                               GLuint start,
79                               GLuint n );
80
81
82
83
84 #define TYPE_IDX(t) ((t) & 0xf)
85 #define MAX_TYPES TYPE_IDX(GL_DOUBLE)+1      /* 0xa + 1 */
86
87
88 /* This macro is used on other systems, so undefine it for this module */
89
90 #undef  CHECK
91
92 static trans_1f_func  _math_trans_1f_tab[MAX_TYPES];
93 static trans_1ui_func _math_trans_1ui_tab[MAX_TYPES];
94 static trans_1ub_func _math_trans_1ub_tab[MAX_TYPES];
95 static trans_3fn_func  _math_trans_3fn_tab[MAX_TYPES];
96 static trans_4ub_func _math_trans_4ub_tab[5][MAX_TYPES];
97 static trans_4us_func _math_trans_4us_tab[5][MAX_TYPES];
98 static trans_4f_func  _math_trans_4f_tab[5][MAX_TYPES];
99 static trans_4f_func  _math_trans_4fn_tab[5][MAX_TYPES];
100
101
102 #define PTR_ELT(ptr, elt) (((SRC *)ptr)[elt])
103
104
105 #define TAB(x) _math_trans##x##_tab
106 #define ARGS   GLuint start, GLuint n
107 #define SRC_START  start
108 #define DST_START  0
109 #define STRIDE stride
110 #define NEXT_F f += stride
111 #define NEXT_F2
112 #define CHECK
113
114
115
116
117 /**
118  * Translate from GL_BYTE.
119  */
120 #define SRC GLbyte
121 #define SRC_IDX TYPE_IDX(GL_BYTE)
122 #define TRX_3FN(f,n)   BYTE_TO_FLOAT( PTR_ELT(f,n) )
123 #if 1
124 #define TRX_4F(f,n)   BYTE_TO_FLOAT( PTR_ELT(f,n) )
125 #else
126 #define TRX_4F(f,n)   (GLfloat)( PTR_ELT(f,n) )
127 #endif
128 #define TRX_4FN(f,n)   BYTE_TO_FLOAT( PTR_ELT(f,n) )
129 #define TRX_UB(ub, f,n)  ub = BYTE_TO_UBYTE( PTR_ELT(f,n) )
130 #define TRX_US(ch, f,n)  ch = BYTE_TO_USHORT( PTR_ELT(f,n) )
131 #define TRX_UI(f,n)  (PTR_ELT(f,n) < 0 ? 0 : (GLuint)  PTR_ELT(f,n))
132
133
134 #define SZ 4
135 #define INIT init_trans_4_GLbyte_raw
136 #define DEST_4F trans_4_GLbyte_4f_raw
137 #define DEST_4FN trans_4_GLbyte_4fn_raw
138 #define DEST_4UB trans_4_GLbyte_4ub_raw
139 #define DEST_4US trans_4_GLbyte_4us_raw
140 #include "m_trans_tmp.h"
141
142 #define SZ 3
143 #define INIT init_trans_3_GLbyte_raw
144 #define DEST_4F trans_3_GLbyte_4f_raw
145 #define DEST_4FN trans_3_GLbyte_4fn_raw
146 #define DEST_4UB trans_3_GLbyte_4ub_raw
147 #define DEST_4US trans_3_GLbyte_4us_raw
148 #define DEST_3FN trans_3_GLbyte_3fn_raw
149 #include "m_trans_tmp.h"
150
151 #define SZ 2
152 #define INIT init_trans_2_GLbyte_raw
153 #define DEST_4F trans_2_GLbyte_4f_raw
154 #define DEST_4FN trans_2_GLbyte_4fn_raw
155 #include "m_trans_tmp.h"
156
157 #define SZ 1
158 #define INIT init_trans_1_GLbyte_raw
159 #define DEST_4F trans_1_GLbyte_4f_raw
160 #define DEST_4FN trans_1_GLbyte_4fn_raw
161 #define DEST_1UB trans_1_GLbyte_1ub_raw
162 #define DEST_1UI trans_1_GLbyte_1ui_raw
163 #include "m_trans_tmp.h"
164
165 #undef SRC
166 #undef TRX_3FN
167 #undef TRX_4F
168 #undef TRX_4FN
169 #undef TRX_UB
170 #undef TRX_US
171 #undef TRX_UI
172 #undef SRC_IDX
173
174
175 /**
176  * Translate from GL_UNSIGNED_BYTE.
177  */
178 #define SRC GLubyte
179 #define SRC_IDX TYPE_IDX(GL_UNSIGNED_BYTE)
180 #define TRX_3FN(f,n)         UBYTE_TO_FLOAT(PTR_ELT(f,n))
181 #define TRX_4F(f,n)          (GLfloat)( PTR_ELT(f,n) )
182 #define TRX_4FN(f,n)         UBYTE_TO_FLOAT(PTR_ELT(f,n))
183 #define TRX_UB(ub, f,n)      ub = PTR_ELT(f,n)
184 #define TRX_US(us, f,n)      us = UBYTE_TO_USHORT(PTR_ELT(f,n))
185 #define TRX_UI(f,n)          (GLuint)PTR_ELT(f,n)
186
187 /* 4ub->4ub handled in special case below.
188  */
189 #define SZ 4
190 #define INIT init_trans_4_GLubyte_raw
191 #define DEST_4F trans_4_GLubyte_4f_raw
192 #define DEST_4FN trans_4_GLubyte_4fn_raw
193 #define DEST_4US trans_4_GLubyte_4us_raw
194 #include "m_trans_tmp.h"
195
196
197 #define SZ 3
198 #define INIT init_trans_3_GLubyte_raw
199 #define DEST_4UB trans_3_GLubyte_4ub_raw
200 #define DEST_4US trans_3_GLubyte_4us_raw
201 #define DEST_3FN trans_3_GLubyte_3fn_raw
202 #define DEST_4F trans_3_GLubyte_4f_raw
203 #define DEST_4FN trans_3_GLubyte_4fn_raw
204 #include "m_trans_tmp.h"
205
206
207 #define SZ 1
208 #define INIT init_trans_1_GLubyte_raw
209 #define DEST_1UI trans_1_GLubyte_1ui_raw
210 #define DEST_1UB trans_1_GLubyte_1ub_raw
211 #include "m_trans_tmp.h"
212
213 #undef SRC
214 #undef SRC_IDX
215 #undef TRX_3FN
216 #undef TRX_4F
217 #undef TRX_4FN
218 #undef TRX_UB
219 #undef TRX_US
220 #undef TRX_UI
221
222
223 /* GL_SHORT
224  */
225 #define SRC GLshort
226 #define SRC_IDX TYPE_IDX(GL_SHORT)
227 #define TRX_3FN(f,n)   SHORT_TO_FLOAT( PTR_ELT(f,n) )
228 #define TRX_4F(f,n)   (GLfloat)( PTR_ELT(f,n) )
229 #define TRX_4FN(f,n)  SHORT_TO_FLOAT( PTR_ELT(f,n) )
230 #define TRX_UB(ub, f,n)  ub = SHORT_TO_UBYTE(PTR_ELT(f,n))
231 #define TRX_US(us, f,n)  us = SHORT_TO_USHORT(PTR_ELT(f,n))
232 #define TRX_UI(f,n)  (PTR_ELT(f,n) < 0 ? 0 : (GLuint)  PTR_ELT(f,n))
233
234
235 #define SZ  4
236 #define INIT init_trans_4_GLshort_raw
237 #define DEST_4F trans_4_GLshort_4f_raw
238 #define DEST_4FN trans_4_GLshort_4fn_raw
239 #define DEST_4UB trans_4_GLshort_4ub_raw
240 #define DEST_4US trans_4_GLshort_4us_raw
241 #include "m_trans_tmp.h"
242
243 #define SZ 3
244 #define INIT init_trans_3_GLshort_raw
245 #define DEST_4F trans_3_GLshort_4f_raw
246 #define DEST_4FN trans_3_GLshort_4fn_raw
247 #define DEST_4UB trans_3_GLshort_4ub_raw
248 #define DEST_4US trans_3_GLshort_4us_raw
249 #define DEST_3FN trans_3_GLshort_3fn_raw
250 #include "m_trans_tmp.h"
251
252 #define SZ 2
253 #define INIT init_trans_2_GLshort_raw
254 #define DEST_4F trans_2_GLshort_4f_raw
255 #define DEST_4FN trans_2_GLshort_4fn_raw
256 #include "m_trans_tmp.h"
257
258 #define SZ 1
259 #define INIT init_trans_1_GLshort_raw
260 #define DEST_4F trans_1_GLshort_4f_raw
261 #define DEST_4FN trans_1_GLshort_4fn_raw
262 #define DEST_1UB trans_1_GLshort_1ub_raw
263 #define DEST_1UI trans_1_GLshort_1ui_raw
264 #include "m_trans_tmp.h"
265
266
267 #undef SRC
268 #undef SRC_IDX
269 #undef TRX_3FN
270 #undef TRX_4F
271 #undef TRX_4FN
272 #undef TRX_UB
273 #undef TRX_US
274 #undef TRX_UI
275
276
277 /* GL_UNSIGNED_SHORT
278  */
279 #define SRC GLushort
280 #define SRC_IDX TYPE_IDX(GL_UNSIGNED_SHORT)
281 #define TRX_3FN(f,n)   USHORT_TO_FLOAT( PTR_ELT(f,n) )
282 #define TRX_4F(f,n)   (GLfloat)( PTR_ELT(f,n) )
283 #define TRX_4FN(f,n)  USHORT_TO_FLOAT( PTR_ELT(f,n) )
284 #define TRX_UB(ub,f,n)  ub = (GLubyte) (PTR_ELT(f,n) >> 8)
285 #define TRX_US(us,f,n)  us = PTR_ELT(f,n)
286 #define TRX_UI(f,n)  (GLuint)   PTR_ELT(f,n)
287
288
289 #define SZ 4
290 #define INIT init_trans_4_GLushort_raw
291 #define DEST_4F trans_4_GLushort_4f_raw
292 #define DEST_4FN trans_4_GLushort_4fn_raw
293 #define DEST_4UB trans_4_GLushort_4ub_raw
294 #define DEST_4US trans_4_GLushort_4us_raw
295 #include "m_trans_tmp.h"
296
297 #define SZ 3
298 #define INIT init_trans_3_GLushort_raw
299 #define DEST_4F trans_3_GLushort_4f_raw
300 #define DEST_4FN trans_3_GLushort_4fn_raw
301 #define DEST_4UB trans_3_GLushort_4ub_raw
302 #define DEST_4US trans_3_GLushort_4us_raw
303 #define DEST_3FN trans_3_GLushort_3fn_raw
304 #include "m_trans_tmp.h"
305
306 #define SZ 2
307 #define INIT init_trans_2_GLushort_raw
308 #define DEST_4F trans_2_GLushort_4f_raw
309 #define DEST_4FN trans_2_GLushort_4fn_raw
310 #include "m_trans_tmp.h"
311
312 #define SZ 1
313 #define INIT init_trans_1_GLushort_raw
314 #define DEST_4F trans_1_GLushort_4f_raw
315 #define DEST_4FN trans_1_GLushort_4fn_raw
316 #define DEST_1UB trans_1_GLushort_1ub_raw
317 #define DEST_1UI trans_1_GLushort_1ui_raw
318 #include "m_trans_tmp.h"
319
320 #undef SRC
321 #undef SRC_IDX
322 #undef TRX_3FN
323 #undef TRX_4F
324 #undef TRX_4FN
325 #undef TRX_UB
326 #undef TRX_US
327 #undef TRX_UI
328
329
330 /* GL_INT
331  */
332 #define SRC GLint
333 #define SRC_IDX TYPE_IDX(GL_INT)
334 #define TRX_3FN(f,n)   INT_TO_FLOAT( PTR_ELT(f,n) )
335 #define TRX_4F(f,n)   (GLfloat)( PTR_ELT(f,n) )
336 #define TRX_4FN(f,n)  INT_TO_FLOAT( PTR_ELT(f,n) )
337 #define TRX_UB(ub, f,n)  ub = INT_TO_UBYTE(PTR_ELT(f,n))
338 #define TRX_US(us, f,n)  us = INT_TO_USHORT(PTR_ELT(f,n))
339 #define TRX_UI(f,n)  (PTR_ELT(f,n) < 0 ? 0 : (GLuint)  PTR_ELT(f,n))
340
341
342 #define SZ 4
343 #define INIT init_trans_4_GLint_raw
344 #define DEST_4F trans_4_GLint_4f_raw
345 #define DEST_4FN trans_4_GLint_4fn_raw
346 #define DEST_4UB trans_4_GLint_4ub_raw
347 #define DEST_4US trans_4_GLint_4us_raw
348 #include "m_trans_tmp.h"
349
350 #define SZ 3
351 #define INIT init_trans_3_GLint_raw
352 #define DEST_4F trans_3_GLint_4f_raw
353 #define DEST_4FN trans_3_GLint_4fn_raw
354 #define DEST_4UB trans_3_GLint_4ub_raw
355 #define DEST_4US trans_3_GLint_4us_raw
356 #define DEST_3FN trans_3_GLint_3fn_raw
357 #include "m_trans_tmp.h"
358
359 #define SZ 2
360 #define INIT init_trans_2_GLint_raw
361 #define DEST_4F trans_2_GLint_4f_raw
362 #define DEST_4FN trans_2_GLint_4fn_raw
363 #include "m_trans_tmp.h"
364
365 #define SZ 1
366 #define INIT init_trans_1_GLint_raw
367 #define DEST_4F trans_1_GLint_4f_raw
368 #define DEST_4FN trans_1_GLint_4fn_raw
369 #define DEST_1UB trans_1_GLint_1ub_raw
370 #define DEST_1UI trans_1_GLint_1ui_raw
371 #include "m_trans_tmp.h"
372
373
374 #undef SRC
375 #undef SRC_IDX
376 #undef TRX_3FN
377 #undef TRX_4F
378 #undef TRX_4FN
379 #undef TRX_UB
380 #undef TRX_US
381 #undef TRX_UI
382
383
384 /* GL_UNSIGNED_INT
385  */
386 #define SRC GLuint
387 #define SRC_IDX TYPE_IDX(GL_UNSIGNED_INT)
388 #define TRX_3FN(f,n)   INT_TO_FLOAT( PTR_ELT(f,n) )
389 #define TRX_4F(f,n)   (GLfloat)( PTR_ELT(f,n) )
390 #define TRX_4FN(f,n)  UINT_TO_FLOAT( PTR_ELT(f,n) )
391 #define TRX_UB(ub, f,n)  ub = (GLubyte) (PTR_ELT(f,n) >> 24)
392 #define TRX_US(us, f,n)  us = (GLshort) (PTR_ELT(f,n) >> 16)
393 #define TRX_UI(f,n)             PTR_ELT(f,n)
394
395
396 #define SZ 4
397 #define INIT init_trans_4_GLuint_raw
398 #define DEST_4F trans_4_GLuint_4f_raw
399 #define DEST_4FN trans_4_GLuint_4fn_raw
400 #define DEST_4UB trans_4_GLuint_4ub_raw
401 #define DEST_4US trans_4_GLuint_4us_raw
402 #include "m_trans_tmp.h"
403
404 #define SZ 3
405 #define INIT init_trans_3_GLuint_raw
406 #define DEST_4F trans_3_GLuint_4f_raw
407 #define DEST_4FN trans_3_GLuint_4fn_raw
408 #define DEST_4UB trans_3_GLuint_4ub_raw
409 #define DEST_4US trans_3_GLuint_4us_raw
410 #define DEST_3FN trans_3_GLuint_3fn_raw
411 #include "m_trans_tmp.h"
412
413 #define SZ 2
414 #define INIT init_trans_2_GLuint_raw
415 #define DEST_4F trans_2_GLuint_4f_raw
416 #define DEST_4FN trans_2_GLuint_4fn_raw
417 #include "m_trans_tmp.h"
418
419 #define SZ 1
420 #define INIT init_trans_1_GLuint_raw
421 #define DEST_4F trans_1_GLuint_4f_raw
422 #define DEST_4FN trans_1_GLuint_4fn_raw
423 #define DEST_1UB trans_1_GLuint_1ub_raw
424 #define DEST_1UI trans_1_GLuint_1ui_raw
425 #include "m_trans_tmp.h"
426
427 #undef SRC
428 #undef SRC_IDX
429 #undef TRX_3FN
430 #undef TRX_4F
431 #undef TRX_4FN
432 #undef TRX_UB
433 #undef TRX_US
434 #undef TRX_UI
435
436
437 /* GL_DOUBLE
438  */
439 #define SRC GLdouble
440 #define SRC_IDX TYPE_IDX(GL_DOUBLE)
441 #define TRX_3FN(f,n)   (GLfloat) PTR_ELT(f,n)
442 #define TRX_4F(f,n)   (GLfloat) PTR_ELT(f,n)
443 #define TRX_4FN(f,n)   (GLfloat) PTR_ELT(f,n)
444 #define TRX_UB(ub,f,n) UNCLAMPED_FLOAT_TO_UBYTE(ub, PTR_ELT(f,n))
445 #define TRX_US(us,f,n) UNCLAMPED_FLOAT_TO_USHORT(us, PTR_ELT(f,n))
446 #define TRX_UI(f,n)  (GLuint) (GLint) PTR_ELT(f,n)
447 #define TRX_1F(f,n)   (GLfloat) PTR_ELT(f,n)
448
449
450 #define SZ 4
451 #define INIT init_trans_4_GLdouble_raw
452 #define DEST_4F trans_4_GLdouble_4f_raw
453 #define DEST_4FN trans_4_GLdouble_4fn_raw
454 #define DEST_4UB trans_4_GLdouble_4ub_raw
455 #define DEST_4US trans_4_GLdouble_4us_raw
456 #include "m_trans_tmp.h"
457
458 #define SZ 3
459 #define INIT init_trans_3_GLdouble_raw
460 #define DEST_4F trans_3_GLdouble_4f_raw
461 #define DEST_4FN trans_3_GLdouble_4fn_raw
462 #define DEST_4UB trans_3_GLdouble_4ub_raw
463 #define DEST_4US trans_3_GLdouble_4us_raw
464 #define DEST_3FN trans_3_GLdouble_3fn_raw
465 #include "m_trans_tmp.h"
466
467 #define SZ 2
468 #define INIT init_trans_2_GLdouble_raw
469 #define DEST_4F trans_2_GLdouble_4f_raw
470 #define DEST_4FN trans_2_GLdouble_4fn_raw
471 #include "m_trans_tmp.h"
472
473 #define SZ 1
474 #define INIT init_trans_1_GLdouble_raw
475 #define DEST_4F trans_1_GLdouble_4f_raw
476 #define DEST_4FN trans_1_GLdouble_4fn_raw
477 #define DEST_1UB trans_1_GLdouble_1ub_raw
478 #define DEST_1UI trans_1_GLdouble_1ui_raw
479 #define DEST_1F trans_1_GLdouble_1f_raw
480 #include "m_trans_tmp.h"
481
482 #undef SRC
483 #undef SRC_IDX
484
485 /* GL_FLOAT
486  */
487 #define SRC GLfloat
488 #define SRC_IDX TYPE_IDX(GL_FLOAT)
489 #define SZ 4
490 #define INIT init_trans_4_GLfloat_raw
491 #define DEST_4UB trans_4_GLfloat_4ub_raw
492 #define DEST_4US trans_4_GLfloat_4us_raw
493 #define DEST_4F  trans_4_GLfloat_4f_raw
494 #define DEST_4FN  trans_4_GLfloat_4fn_raw
495 #include "m_trans_tmp.h"
496
497 #define SZ 3
498 #define INIT init_trans_3_GLfloat_raw
499 #define DEST_4F  trans_3_GLfloat_4f_raw
500 #define DEST_4FN  trans_3_GLfloat_4fn_raw
501 #define DEST_4UB trans_3_GLfloat_4ub_raw
502 #define DEST_4US trans_3_GLfloat_4us_raw
503 #define DEST_3FN trans_3_GLfloat_3fn_raw
504 #include "m_trans_tmp.h"
505
506 #define SZ 2
507 #define INIT init_trans_2_GLfloat_raw
508 #define DEST_4F trans_2_GLfloat_4f_raw
509 #define DEST_4FN trans_2_GLfloat_4fn_raw
510 #include "m_trans_tmp.h"
511
512 #define SZ 1
513 #define INIT init_trans_1_GLfloat_raw
514 #define DEST_4F  trans_1_GLfloat_4f_raw
515 #define DEST_4FN  trans_1_GLfloat_4fn_raw
516 #define DEST_1UB trans_1_GLfloat_1ub_raw
517 #define DEST_1UI trans_1_GLfloat_1ui_raw
518 #define DEST_1F trans_1_GLfloat_1f_raw
519
520 #include "m_trans_tmp.h"
521
522 #undef SRC
523 #undef SRC_IDX
524 #undef TRX_3FN
525 #undef TRX_4F
526 #undef TRX_4FN
527 #undef TRX_UB
528 #undef TRX_US
529 #undef TRX_UI
530
531
532 static void trans_4_GLubyte_4ub_raw(GLubyte (*t)[4],
533                                     CONST void *Ptr,
534                                     GLuint stride,
535                                     ARGS )
536 {
537    const GLubyte *f = (GLubyte *) Ptr + SRC_START * stride;
538    GLuint i;
539
540    if (((((uintptr_t) f | (uintptr_t) stride)) & 3L) == 0L) {
541       /* Aligned.
542        */
543       for (i = DST_START ; i < n ; i++, f += stride) {
544          COPY_4UBV( t[i], f );
545       }
546    } else {
547       for (i = DST_START ; i < n ; i++, f += stride) {
548          t[i][0] = f[0];
549          t[i][1] = f[1];
550          t[i][2] = f[2];
551          t[i][3] = f[3];
552       }
553    }
554 }
555
556
557 static void init_translate_raw(void)
558 {
559    memset( TAB(_1ui), 0, sizeof(TAB(_1ui)) );
560    memset( TAB(_1ub), 0, sizeof(TAB(_1ub)) );
561    memset( TAB(_3fn),  0, sizeof(TAB(_3fn)) );
562    memset( TAB(_4ub), 0, sizeof(TAB(_4ub)) );
563    memset( TAB(_4us), 0, sizeof(TAB(_4us)) );
564    memset( TAB(_4f),  0, sizeof(TAB(_4f)) );
565    memset( TAB(_4fn),  0, sizeof(TAB(_4fn)) );
566
567    init_trans_4_GLbyte_raw();
568    init_trans_3_GLbyte_raw();
569    init_trans_2_GLbyte_raw();
570    init_trans_1_GLbyte_raw();
571    init_trans_1_GLubyte_raw();
572    init_trans_3_GLubyte_raw();
573    init_trans_4_GLubyte_raw();
574    init_trans_4_GLshort_raw();
575    init_trans_3_GLshort_raw();
576    init_trans_2_GLshort_raw();
577    init_trans_1_GLshort_raw();
578    init_trans_4_GLushort_raw();
579    init_trans_3_GLushort_raw();
580    init_trans_2_GLushort_raw();
581    init_trans_1_GLushort_raw();
582    init_trans_4_GLint_raw();
583    init_trans_3_GLint_raw();
584    init_trans_2_GLint_raw();
585    init_trans_1_GLint_raw();
586    init_trans_4_GLuint_raw();
587    init_trans_3_GLuint_raw();
588    init_trans_2_GLuint_raw();
589    init_trans_1_GLuint_raw();
590    init_trans_4_GLdouble_raw();
591    init_trans_3_GLdouble_raw();
592    init_trans_2_GLdouble_raw();
593    init_trans_1_GLdouble_raw();
594    init_trans_4_GLfloat_raw();
595    init_trans_3_GLfloat_raw();
596    init_trans_2_GLfloat_raw();
597    init_trans_1_GLfloat_raw();
598
599    TAB(_4ub)[4][TYPE_IDX(GL_UNSIGNED_BYTE)] = trans_4_GLubyte_4ub_raw;
600 }
601
602
603 #undef TAB
604 #ifdef CLASS
605 #undef CLASS
606 #endif
607 #undef ARGS
608 #undef CHECK
609 #undef SRC_START
610 #undef DST_START
611 #undef NEXT_F
612 #undef NEXT_F2
613
614
615
616
617
618 void _math_init_translate( void )
619 {
620    init_translate_raw();
621 }
622
623
624 /**
625  * Translate vector of values to GLfloat [1].
626  */
627 void _math_trans_1f(GLfloat *to,
628                     CONST void *ptr,
629                     GLuint stride,
630                     GLenum type,
631                     GLuint start,
632                     GLuint n )
633 {
634    _math_trans_1f_tab[TYPE_IDX(type)]( to, ptr, stride, start, n );
635 }
636
637 /**
638  * Translate vector of values to GLuint [1].
639  */
640 void _math_trans_1ui(GLuint *to,
641                      CONST void *ptr,
642                      GLuint stride,
643                      GLenum type,
644                      GLuint start,
645                      GLuint n )
646 {
647    _math_trans_1ui_tab[TYPE_IDX(type)]( to, ptr, stride, start, n );
648 }
649
650 /**
651  * Translate vector of values to GLubyte [1].
652  */
653 void _math_trans_1ub(GLubyte *to,
654                      CONST void *ptr,
655                      GLuint stride,
656                      GLenum type,
657                      GLuint start,
658                      GLuint n )
659 {
660    _math_trans_1ub_tab[TYPE_IDX(type)]( to, ptr, stride, start, n );
661 }
662
663
664 /**
665  * Translate vector of values to GLubyte [4].
666  */
667 void _math_trans_4ub(GLubyte (*to)[4],
668                      CONST void *ptr,
669                      GLuint stride,
670                      GLenum type,
671                      GLuint size,
672                      GLuint start,
673                      GLuint n )
674 {
675    _math_trans_4ub_tab[size][TYPE_IDX(type)]( to, ptr, stride, start, n );
676 }
677
678 /**
679  * Translate vector of values to GLchan [4].
680  */
681 void _math_trans_4chan( GLchan (*to)[4],
682                         CONST void *ptr,
683                         GLuint stride,
684                         GLenum type,
685                         GLuint size,
686                         GLuint start,
687                         GLuint n )
688 {
689 #if CHAN_TYPE == GL_UNSIGNED_BYTE
690    _math_trans_4ub( to, ptr, stride, type, size, start, n );
691 #elif CHAN_TYPE == GL_UNSIGNED_SHORT
692    _math_trans_4us( to, ptr, stride, type, size, start, n );
693 #elif CHAN_TYPE == GL_FLOAT
694    _math_trans_4fn( to, ptr, stride, type, size, start, n );
695 #endif
696 }
697
698 /**
699  * Translate vector of values to GLushort [4].
700  */
701 void _math_trans_4us(GLushort (*to)[4],
702                      CONST void *ptr,
703                      GLuint stride,
704                      GLenum type,
705                      GLuint size,
706                      GLuint start,
707                      GLuint n )
708 {
709    _math_trans_4us_tab[size][TYPE_IDX(type)]( to, ptr, stride, start, n );
710 }
711
712 /**
713  * Translate vector of values to GLfloat [4].
714  */
715 void _math_trans_4f(GLfloat (*to)[4],
716                     CONST void *ptr,
717                     GLuint stride,
718                     GLenum type,
719                     GLuint size,
720                     GLuint start,
721                     GLuint n )
722 {
723    _math_trans_4f_tab[size][TYPE_IDX(type)]( to, ptr, stride, start, n );
724 }
725
726 /**
727  * Translate vector of values to GLfloat[4], normalized to [-1, 1].
728  */
729 void _math_trans_4fn(GLfloat (*to)[4],
730                     CONST void *ptr,
731                     GLuint stride,
732                     GLenum type,
733                     GLuint size,
734                     GLuint start,
735                     GLuint n )
736 {
737    _math_trans_4fn_tab[size][TYPE_IDX(type)]( to, ptr, stride, start, n );
738 }
739
740 /**
741  * Translate vector of values to GLfloat[3], normalized to [-1, 1].
742  */
743 void _math_trans_3fn(GLfloat (*to)[3],
744                     CONST void *ptr,
745                     GLuint stride,
746                     GLenum type,
747                     GLuint start,
748                     GLuint n )
749 {
750    _math_trans_3fn_tab[TYPE_IDX(type)]( to, ptr, stride, start, n );
751 }