blob: 47f6c61f5f59b70f5f8eb7d804976d740faa6542 [file] [log] [blame]
Gareth Hughes22144ab2001-03-12 00:48:37 +00001/* $Id: m_translate.c,v 1.6 2001/03/12 00:48:41 gareth Exp $ */
Keith Whitwell23caf202000-11-16 21:05:34 +00002
3/*
4 * Mesa 3-D graphics library
Brian Paul74b493a2001-01-24 00:04:58 +00005 * Version: 3.5
Gareth Hughes22144ab2001-03-12 00:48:37 +00006 *
Brian Paul74b493a2001-01-24 00:04:58 +00007 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
Gareth Hughes22144ab2001-03-12 00:48:37 +00008 *
Keith Whitwell23caf202000-11-16 21:05:34 +00009 * 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:
Gareth Hughes22144ab2001-03-12 00:48:37 +000015 *
Keith Whitwell23caf202000-11-16 21:05:34 +000016 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
Gareth Hughes22144ab2001-03-12 00:48:37 +000018 *
Keith Whitwell23caf202000-11-16 21:05:34 +000019 * 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.
25 */
26
27/*
28 * New (3.1) transformation code written by Keith Whitwell.
29 */
30
31
32#include "glheader.h"
Keith Whitwell4eebc902001-02-20 18:28:52 +000033#include "mtypes.h" /* GLchan hack */
Keith Whitwell23caf202000-11-16 21:05:34 +000034#include "colormac.h"
35#include "mem.h"
36#include "mmath.h"
37
38#include "m_translate.h"
39
Keith Whitwellcab974c2000-12-26 05:09:27 +000040
41
42typedef void (*trans_1f_func)(GLfloat *to,
43 CONST void *ptr,
44 GLuint stride,
Gareth Hughes22144ab2001-03-12 00:48:37 +000045 GLuint start,
Keith Whitwellcab974c2000-12-26 05:09:27 +000046 GLuint n );
47
48typedef void (*trans_1ui_func)(GLuint *to,
49 CONST void *ptr,
50 GLuint stride,
Gareth Hughes22144ab2001-03-12 00:48:37 +000051 GLuint start,
Keith Whitwellcab974c2000-12-26 05:09:27 +000052 GLuint n );
53
54typedef void (*trans_1ub_func)(GLubyte *to,
55 CONST void *ptr,
56 GLuint stride,
57 GLuint start,
58 GLuint n );
59
60typedef void (*trans_4ub_func)(GLubyte (*to)[4],
Brian Paul74b493a2001-01-24 00:04:58 +000061 CONST void *ptr,
62 GLuint stride,
63 GLuint start,
64 GLuint n );
65
66typedef void (*trans_4us_func)(GLushort (*to)[4],
67 CONST void *ptr,
68 GLuint stride,
69 GLuint start,
70 GLuint n );
Keith Whitwellcab974c2000-12-26 05:09:27 +000071
72typedef void (*trans_4f_func)(GLfloat (*to)[4],
73 CONST void *ptr,
74 GLuint stride,
Gareth Hughes22144ab2001-03-12 00:48:37 +000075 GLuint start,
Keith Whitwellcab974c2000-12-26 05:09:27 +000076 GLuint n );
77
78typedef void (*trans_3f_func)(GLfloat (*to)[3],
79 CONST void *ptr,
80 GLuint stride,
Gareth Hughes22144ab2001-03-12 00:48:37 +000081 GLuint start,
Keith Whitwellcab974c2000-12-26 05:09:27 +000082 GLuint n );
83
84
85
86
87#define TYPE_IDX(t) ((t) & 0xf)
88#define MAX_TYPES TYPE_IDX(GL_DOUBLE)+1 /* 0xa + 1 */
89
90
Keith Whitwell23caf202000-11-16 21:05:34 +000091/* This macro is used on other systems, so undefine it for this module */
92
93#undef CHECK
94
Keith Whitwellcab974c2000-12-26 05:09:27 +000095static trans_1f_func _math_trans_1f_tab[MAX_TYPES];
96static trans_1ui_func _math_trans_1ui_tab[MAX_TYPES];
97static trans_1ub_func _math_trans_1ub_tab[MAX_TYPES];
98static trans_3f_func _math_trans_3f_tab[MAX_TYPES];
99static trans_4ub_func _math_trans_4ub_tab[5][MAX_TYPES];
Brian Paul74b493a2001-01-24 00:04:58 +0000100static trans_4us_func _math_trans_4us_tab[5][MAX_TYPES];
Keith Whitwellcab974c2000-12-26 05:09:27 +0000101static trans_4f_func _math_trans_4f_tab[5][MAX_TYPES];
Keith Whitwell23caf202000-11-16 21:05:34 +0000102
103
104#define PTR_ELT(ptr, elt) (((SRC *)ptr)[elt])
105
106
Keith Whitwellcab974c2000-12-26 05:09:27 +0000107#define TAB(x) _math_trans##x##_tab
Keith Whitwell23caf202000-11-16 21:05:34 +0000108#define ARGS GLuint start, GLuint n
109#define SRC_START start
110#define DST_START 0
111#define STRIDE stride
112#define NEXT_F f += stride
113#define NEXT_F2
114#define CHECK
115
116
117
118
119/* GL_BYTE
120 */
121#define SRC GLbyte
122#define SRC_IDX TYPE_IDX(GL_BYTE)
123#define TRX_3F(f,n) BYTE_TO_FLOAT( PTR_ELT(f,n) )
124#define TRX_4F(f,n) (GLfloat)( PTR_ELT(f,n) )
125#define TRX_UB(ub, f,n) ub = BYTE_TO_UBYTE( PTR_ELT(f,n) )
Brian Paul74b493a2001-01-24 00:04:58 +0000126#define TRX_US(ch, f,n) ch = BYTE_TO_USHORT( PTR_ELT(f,n) )
Keith Whitwell23caf202000-11-16 21:05:34 +0000127#define TRX_UI(f,n) (PTR_ELT(f,n) < 0 ? 0 : (GLuint) PTR_ELT(f,n))
128
129
130#define SZ 4
131#define INIT init_trans_4_GLbyte_raw
132#define DEST_4F trans_4_GLbyte_4f_raw
133#define DEST_4UB trans_4_GLbyte_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000134#define DEST_4US trans_4_GLbyte_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000135#include "m_trans_tmp.h"
136
137#define SZ 3
138#define INIT init_trans_3_GLbyte_raw
139#define DEST_4F trans_3_GLbyte_4f_raw
140#define DEST_4UB trans_3_GLbyte_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000141#define DEST_4US trans_3_GLbyte_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000142#define DEST_3F trans_3_GLbyte_3f_raw
143#include "m_trans_tmp.h"
144
145#define SZ 2
146#define INIT init_trans_2_GLbyte_raw
147#define DEST_4F trans_2_GLbyte_4f_raw
148#include "m_trans_tmp.h"
149
150#define SZ 1
151#define INIT init_trans_1_GLbyte_raw
152#define DEST_4F trans_1_GLbyte_4f_raw
153#define DEST_1UB trans_1_GLbyte_1ub_raw
154#define DEST_1UI trans_1_GLbyte_1ui_raw
155#include "m_trans_tmp.h"
156
157#undef SRC
158#undef TRX_3F
159#undef TRX_4F
160#undef TRX_UB
Brian Paul74b493a2001-01-24 00:04:58 +0000161#undef TRX_US
Keith Whitwell23caf202000-11-16 21:05:34 +0000162#undef TRX_UI
163#undef SRC_IDX
164
Brian Paul74b493a2001-01-24 00:04:58 +0000165
Keith Whitwell23caf202000-11-16 21:05:34 +0000166/* GL_UNSIGNED_BYTE
167 */
168#define SRC GLubyte
169#define SRC_IDX TYPE_IDX(GL_UNSIGNED_BYTE)
170#define TRX_3F(f,n) /* unused */
171#define TRX_4F(f,n) /* unused */
172#define TRX_UB(ub, f,n) ub = PTR_ELT(f,n)
Brian Paul74b493a2001-01-24 00:04:58 +0000173#define TRX_US(us, f,n) us = UBYTE_TO_USHORT(PTR_ELT(f,n))
Keith Whitwell23caf202000-11-16 21:05:34 +0000174#define TRX_UI(f,n) (GLuint)PTR_ELT(f,n)
175
176/* 4ub->4ub handled in special case below.
177 */
178
179#define SZ 3
180#define INIT init_trans_3_GLubyte_raw
181#define DEST_4UB trans_3_GLubyte_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000182#define DEST_4US trans_3_GLubyte_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000183#include "m_trans_tmp.h"
184
185
186#define SZ 1
187#define INIT init_trans_1_GLubyte_raw
188#define DEST_1UI trans_1_GLubyte_1ui_raw
189#define DEST_1UB trans_1_GLubyte_1ub_raw
190#include "m_trans_tmp.h"
191
192#undef SRC
193#undef SRC_IDX
194#undef TRX_3F
195#undef TRX_4F
196#undef TRX_UB
Brian Paul74b493a2001-01-24 00:04:58 +0000197#undef TRX_US
Keith Whitwell23caf202000-11-16 21:05:34 +0000198#undef TRX_UI
199
200
201/* GL_SHORT
202 */
203#define SRC GLshort
204#define SRC_IDX TYPE_IDX(GL_SHORT)
205#define TRX_3F(f,n) SHORT_TO_FLOAT( PTR_ELT(f,n) )
206#define TRX_4F(f,n) (GLfloat)( PTR_ELT(f,n) )
207#define TRX_UB(ub, f,n) ub = SHORT_TO_UBYTE(PTR_ELT(f,n))
Brian Paul74b493a2001-01-24 00:04:58 +0000208#define TRX_US(us, f,n) us = SHORT_TO_USHORT(PTR_ELT(f,n))
Keith Whitwell23caf202000-11-16 21:05:34 +0000209#define TRX_UI(f,n) (PTR_ELT(f,n) < 0 ? 0 : (GLuint) PTR_ELT(f,n))
210
211
212#define SZ 4
213#define INIT init_trans_4_GLshort_raw
214#define DEST_4F trans_4_GLshort_4f_raw
215#define DEST_4UB trans_4_GLshort_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000216#define DEST_4US trans_4_GLshort_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000217#include "m_trans_tmp.h"
218
219#define SZ 3
220#define INIT init_trans_3_GLshort_raw
221#define DEST_4F trans_3_GLshort_4f_raw
222#define DEST_4UB trans_3_GLshort_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000223#define DEST_4US trans_3_GLshort_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000224#define DEST_3F trans_3_GLshort_3f_raw
225#include "m_trans_tmp.h"
226
227#define SZ 2
228#define INIT init_trans_2_GLshort_raw
229#define DEST_4F trans_2_GLshort_4f_raw
230#include "m_trans_tmp.h"
231
232#define SZ 1
233#define INIT init_trans_1_GLshort_raw
234#define DEST_4F trans_1_GLshort_4f_raw
235#define DEST_1UB trans_1_GLshort_1ub_raw
236#define DEST_1UI trans_1_GLshort_1ui_raw
237#include "m_trans_tmp.h"
238
239
240#undef SRC
241#undef SRC_IDX
242#undef TRX_3F
243#undef TRX_4F
244#undef TRX_UB
Brian Paul74b493a2001-01-24 00:04:58 +0000245#undef TRX_US
Keith Whitwell23caf202000-11-16 21:05:34 +0000246#undef TRX_UI
247
248
249/* GL_UNSIGNED_SHORT
250 */
251#define SRC GLushort
252#define SRC_IDX TYPE_IDX(GL_UNSIGNED_SHORT)
253#define TRX_3F(f,n) USHORT_TO_FLOAT( PTR_ELT(f,n) )
254#define TRX_4F(f,n) (GLfloat)( PTR_ELT(f,n) )
255#define TRX_UB(ub,f,n) ub = (GLubyte) (PTR_ELT(f,n) >> 8)
Brian Paul74b493a2001-01-24 00:04:58 +0000256#define TRX_US(us,f,n) us = (GLushort) (PTR_ELT(f,n) >> 8)
Keith Whitwell23caf202000-11-16 21:05:34 +0000257#define TRX_UI(f,n) (GLuint) PTR_ELT(f,n)
258
259
260#define SZ 4
261#define INIT init_trans_4_GLushort_raw
262#define DEST_4F trans_4_GLushort_4f_raw
263#define DEST_4UB trans_4_GLushort_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000264#define DEST_4US trans_4_GLushort_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000265#include "m_trans_tmp.h"
266
267#define SZ 3
268#define INIT init_trans_3_GLushort_raw
269#define DEST_4F trans_3_GLushort_4f_raw
270#define DEST_4UB trans_3_GLushort_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000271#define DEST_4US trans_3_GLushort_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000272#define DEST_3F trans_3_GLushort_3f_raw
273#include "m_trans_tmp.h"
274
275#define SZ 2
276#define INIT init_trans_2_GLushort_raw
277#define DEST_4F trans_2_GLushort_4f_raw
278#include "m_trans_tmp.h"
279
280#define SZ 1
281#define INIT init_trans_1_GLushort_raw
282#define DEST_4F trans_1_GLushort_4f_raw
283#define DEST_1UB trans_1_GLushort_1ub_raw
284#define DEST_1UI trans_1_GLushort_1ui_raw
285#include "m_trans_tmp.h"
286
287#undef SRC
288#undef SRC_IDX
289#undef TRX_3F
290#undef TRX_4F
291#undef TRX_UB
Brian Paul74b493a2001-01-24 00:04:58 +0000292#undef TRX_US
Keith Whitwell23caf202000-11-16 21:05:34 +0000293#undef TRX_UI
294
295
296/* GL_INT
297 */
298#define SRC GLint
299#define SRC_IDX TYPE_IDX(GL_INT)
300#define TRX_3F(f,n) INT_TO_FLOAT( PTR_ELT(f,n) )
301#define TRX_4F(f,n) (GLfloat)( PTR_ELT(f,n) )
302#define TRX_UB(ub, f,n) ub = INT_TO_UBYTE(PTR_ELT(f,n))
Brian Paul74b493a2001-01-24 00:04:58 +0000303#define TRX_US(us, f,n) us = INT_TO_USHORT(PTR_ELT(f,n))
Keith Whitwell23caf202000-11-16 21:05:34 +0000304#define TRX_UI(f,n) (PTR_ELT(f,n) < 0 ? 0 : (GLuint) PTR_ELT(f,n))
305
306
307#define SZ 4
308#define INIT init_trans_4_GLint_raw
309#define DEST_4F trans_4_GLint_4f_raw
310#define DEST_4UB trans_4_GLint_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000311#define DEST_4US trans_4_GLint_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000312#include "m_trans_tmp.h"
313
314#define SZ 3
315#define INIT init_trans_3_GLint_raw
316#define DEST_4F trans_3_GLint_4f_raw
317#define DEST_4UB trans_3_GLint_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000318#define DEST_4US trans_3_GLint_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000319#define DEST_3F trans_3_GLint_3f_raw
320#include "m_trans_tmp.h"
321
322#define SZ 2
323#define INIT init_trans_2_GLint_raw
324#define DEST_4F trans_2_GLint_4f_raw
325#include "m_trans_tmp.h"
326
327#define SZ 1
328#define INIT init_trans_1_GLint_raw
329#define DEST_4F trans_1_GLint_4f_raw
330#define DEST_1UB trans_1_GLint_1ub_raw
331#define DEST_1UI trans_1_GLint_1ui_raw
332#include "m_trans_tmp.h"
333
334
335#undef SRC
336#undef SRC_IDX
337#undef TRX_3F
338#undef TRX_4F
339#undef TRX_UB
Brian Paul74b493a2001-01-24 00:04:58 +0000340#undef TRX_US
Keith Whitwell23caf202000-11-16 21:05:34 +0000341#undef TRX_UI
342
343
344/* GL_UNSIGNED_INT
345 */
346#define SRC GLuint
347#define SRC_IDX TYPE_IDX(GL_UNSIGNED_INT)
348#define TRX_3F(f,n) INT_TO_FLOAT( PTR_ELT(f,n) )
349#define TRX_4F(f,n) (GLfloat)( PTR_ELT(f,n) )
350#define TRX_UB(ub, f,n) ub = (GLubyte) (PTR_ELT(f,n) >> 24)
Brian Paul74b493a2001-01-24 00:04:58 +0000351#define TRX_US(us, f,n) us = (GLshort) (PTR_ELT(f,n) >> 16)
Keith Whitwell23caf202000-11-16 21:05:34 +0000352#define TRX_UI(f,n) PTR_ELT(f,n)
353
354
355#define SZ 4
356#define INIT init_trans_4_GLuint_raw
357#define DEST_4F trans_4_GLuint_4f_raw
358#define DEST_4UB trans_4_GLuint_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000359#define DEST_4US trans_4_GLuint_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000360#include "m_trans_tmp.h"
361
362#define SZ 3
363#define INIT init_trans_3_GLuint_raw
364#define DEST_4F trans_3_GLuint_4f_raw
365#define DEST_4UB trans_3_GLuint_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000366#define DEST_4US trans_3_GLuint_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000367#define DEST_3F trans_3_GLuint_3f_raw
368#include "m_trans_tmp.h"
369
370#define SZ 2
371#define INIT init_trans_2_GLuint_raw
372#define DEST_4F trans_2_GLuint_4f_raw
373#include "m_trans_tmp.h"
374
375#define SZ 1
376#define INIT init_trans_1_GLuint_raw
377#define DEST_4F trans_1_GLuint_4f_raw
378#define DEST_1UB trans_1_GLuint_1ub_raw
379#define DEST_1UI trans_1_GLuint_1ui_raw
380#include "m_trans_tmp.h"
381
382#undef SRC
383#undef SRC_IDX
384#undef TRX_3F
385#undef TRX_4F
386#undef TRX_UB
Brian Paul74b493a2001-01-24 00:04:58 +0000387#undef TRX_US
Keith Whitwell23caf202000-11-16 21:05:34 +0000388#undef TRX_UI
389
390
391/* GL_DOUBLE
392 */
393#define SRC GLdouble
394#define SRC_IDX TYPE_IDX(GL_DOUBLE)
395#define TRX_3F(f,n) PTR_ELT(f,n)
396#define TRX_4F(f,n) PTR_ELT(f,n)
Brian Paul74b493a2001-01-24 00:04:58 +0000397#define TRX_UB(ub,f,n) UNCLAMPED_FLOAT_TO_UBYTE(ub, PTR_ELT(f,n))
398#define TRX_US(us,f,n) UNCLAMPED_FLOAT_TO_USHORT(us, PTR_ELT(f,n))
Keith Whitwell23caf202000-11-16 21:05:34 +0000399#define TRX_UI(f,n) (GLuint) (GLint) PTR_ELT(f,n)
400#define TRX_1F(f,n) PTR_ELT(f,n)
401
402
403#define SZ 4
404#define INIT init_trans_4_GLdouble_raw
405#define DEST_4F trans_4_GLdouble_4f_raw
406#define DEST_4UB trans_4_GLdouble_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000407#define DEST_4US trans_4_GLdouble_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000408#include "m_trans_tmp.h"
409
410#define SZ 3
411#define INIT init_trans_3_GLdouble_raw
412#define DEST_4F trans_3_GLdouble_4f_raw
413#define DEST_4UB trans_3_GLdouble_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000414#define DEST_4US trans_3_GLdouble_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000415#define DEST_3F trans_3_GLdouble_3f_raw
416#include "m_trans_tmp.h"
417
418#define SZ 2
419#define INIT init_trans_2_GLdouble_raw
420#define DEST_4F trans_2_GLdouble_4f_raw
421#include "m_trans_tmp.h"
422
423#define SZ 1
424#define INIT init_trans_1_GLdouble_raw
425#define DEST_4F trans_1_GLdouble_4f_raw
426#define DEST_1UB trans_1_GLdouble_1ub_raw
427#define DEST_1UI trans_1_GLdouble_1ui_raw
428#define DEST_1F trans_1_GLdouble_1f_raw
429#include "m_trans_tmp.h"
430
431#undef SRC
432#undef SRC_IDX
433
434/* GL_FLOAT
435 */
436#define SRC GLfloat
437#define SRC_IDX TYPE_IDX(GL_FLOAT)
438#define SZ 4
Gareth Hughes22144ab2001-03-12 00:48:37 +0000439#define INIT init_trans_4_GLfloat_raw
440#define DEST_4UB trans_4_GLfloat_4ub_raw
441#define DEST_4US trans_4_GLfloat_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000442#define DEST_4F trans_4_GLfloat_4f_raw
443#include "m_trans_tmp.h"
444
445#define SZ 3
446#define INIT init_trans_3_GLfloat_raw
447#define DEST_4F trans_3_GLfloat_4f_raw
448#define DEST_4UB trans_3_GLfloat_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000449#define DEST_4US trans_3_GLfloat_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000450#define DEST_3F trans_3_GLfloat_3f_raw
451#include "m_trans_tmp.h"
452
453#define SZ 2
454#define INIT init_trans_2_GLfloat_raw
455#define DEST_4F trans_2_GLfloat_4f_raw
456#include "m_trans_tmp.h"
457
458#define SZ 1
459#define INIT init_trans_1_GLfloat_raw
460#define DEST_4F trans_1_GLfloat_4f_raw
461#define DEST_1UB trans_1_GLfloat_1ub_raw
462#define DEST_1UI trans_1_GLfloat_1ui_raw
463#define DEST_1F trans_1_GLfloat_1f_raw
464
465#include "m_trans_tmp.h"
466
467#undef SRC
468#undef SRC_IDX
469#undef TRX_3F
470#undef TRX_4F
471#undef TRX_UB
Brian Paul74b493a2001-01-24 00:04:58 +0000472#undef TRX_US
Keith Whitwell23caf202000-11-16 21:05:34 +0000473#undef TRX_UI
474
475
Brian Paul74b493a2001-01-24 00:04:58 +0000476static void trans_4_GLubyte_4ub_raw(GLubyte (*t)[4],
477 CONST void *Ptr,
478 GLuint stride,
479 ARGS )
Keith Whitwell23caf202000-11-16 21:05:34 +0000480{
481 const GLubyte *f = (GLubyte *) Ptr + SRC_START * stride;
482 GLuint i;
483
Gareth Hughes22144ab2001-03-12 00:48:37 +0000484 if (((((long) f | (long) stride)) & 3L) == 0L) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000485 /* Aligned.
486 */
487 for (i = DST_START ; i < n ; i++, f += stride) {
488 COPY_4UBV( t[i], f );
489 }
490 } else {
491 for (i = DST_START ; i < n ; i++, f += stride) {
492 t[i][0] = f[0];
493 t[i][1] = f[1];
494 t[i][2] = f[2];
495 t[i][3] = f[3];
496 }
497 }
498}
499
500
501static void init_translate_raw(void)
502{
503 MEMSET( TAB(_1ui), 0, sizeof(TAB(_1ui)) );
504 MEMSET( TAB(_1ub), 0, sizeof(TAB(_1ub)) );
505 MEMSET( TAB(_3f), 0, sizeof(TAB(_3f)) );
506 MEMSET( TAB(_4ub), 0, sizeof(TAB(_4ub)) );
Brian Paul74b493a2001-01-24 00:04:58 +0000507 MEMSET( TAB(_4us), 0, sizeof(TAB(_4us)) );
Keith Whitwell23caf202000-11-16 21:05:34 +0000508 MEMSET( TAB(_4f), 0, sizeof(TAB(_4f)) );
509
510 TAB(_4ub)[4][TYPE_IDX(GL_UNSIGNED_BYTE)] = trans_4_GLubyte_4ub_raw;
511
512 init_trans_4_GLbyte_raw();
513 init_trans_3_GLbyte_raw();
514 init_trans_2_GLbyte_raw();
515 init_trans_1_GLbyte_raw();
516 init_trans_1_GLubyte_raw();
517 init_trans_3_GLubyte_raw();
518 init_trans_4_GLshort_raw();
519 init_trans_3_GLshort_raw();
520 init_trans_2_GLshort_raw();
521 init_trans_1_GLshort_raw();
522 init_trans_4_GLushort_raw();
523 init_trans_3_GLushort_raw();
524 init_trans_2_GLushort_raw();
525 init_trans_1_GLushort_raw();
526 init_trans_4_GLint_raw();
527 init_trans_3_GLint_raw();
528 init_trans_2_GLint_raw();
529 init_trans_1_GLint_raw();
530 init_trans_4_GLuint_raw();
531 init_trans_3_GLuint_raw();
532 init_trans_2_GLuint_raw();
533 init_trans_1_GLuint_raw();
534 init_trans_4_GLdouble_raw();
535 init_trans_3_GLdouble_raw();
536 init_trans_2_GLdouble_raw();
537 init_trans_1_GLdouble_raw();
538 init_trans_4_GLfloat_raw();
539 init_trans_3_GLfloat_raw();
540 init_trans_2_GLfloat_raw();
541 init_trans_1_GLfloat_raw();
542}
543
544
545#undef TAB
546#undef CLASS
547#undef ARGS
548#undef CHECK
549#undef SRC_START
550#undef DST_START
551#undef NEXT_F
552#undef NEXT_F2
553
554
555
556
557
Keith Whitwellcab974c2000-12-26 05:09:27 +0000558void _math_init_translate( void )
Keith Whitwell23caf202000-11-16 21:05:34 +0000559{
560 init_translate_raw();
561}
Keith Whitwellcab974c2000-12-26 05:09:27 +0000562
563
564
565void _math_trans_1f(GLfloat *to,
566 CONST void *ptr,
567 GLuint stride,
568 GLenum type,
569 GLuint start,
570 GLuint n )
571{
572 _math_trans_1f_tab[TYPE_IDX(type)]( to, ptr, stride, start, n );
573}
574
575void _math_trans_1ui(GLuint *to,
576 CONST void *ptr,
577 GLuint stride,
578 GLenum type,
579 GLuint start,
580 GLuint n )
581{
Gareth Hughes22144ab2001-03-12 00:48:37 +0000582 _math_trans_1ui_tab[TYPE_IDX(type)]( to, ptr, stride, start, n );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000583}
584
585void _math_trans_1ub(GLubyte *to,
586 CONST void *ptr,
587 GLuint stride,
588 GLenum type,
589 GLuint start,
590 GLuint n )
591{
Gareth Hughes22144ab2001-03-12 00:48:37 +0000592 _math_trans_1ub_tab[TYPE_IDX(type)]( to, ptr, stride, start, n );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000593}
594
595
596void _math_trans_4ub(GLubyte (*to)[4],
597 CONST void *ptr,
598 GLuint stride,
599 GLenum type,
600 GLuint size,
601 GLuint start,
602 GLuint n )
603{
Gareth Hughes22144ab2001-03-12 00:48:37 +0000604 _math_trans_4ub_tab[size][TYPE_IDX(type)]( to, ptr, stride, start, n );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000605}
606
Keith Whitwell4eebc902001-02-20 18:28:52 +0000607void _math_trans_4chan( GLchan (*to)[4],
608 CONST void *ptr,
609 GLuint stride,
610 GLenum type,
611 GLuint size,
612 GLuint start,
613 GLuint n )
614{
615#if CHAN_TYPE == GL_UNSIGNED_BYTE
616 _math_trans_4ub( to, ptr, stride, type, size, start, n );
617#elif CHAN_TYPE == GL_UNSIGNED_SHORT
618 _math_trans_4us( to, ptr, stride, type, size, start, n );
619#elif CHAN_TYPE == GL_FLOAT
620 _math_trans_4f( to, ptr, stride, type, size, start, n );
621#endif
622}
623
Brian Paul74b493a2001-01-24 00:04:58 +0000624void _math_trans_4us(GLushort (*to)[4],
625 CONST void *ptr,
626 GLuint stride,
627 GLenum type,
628 GLuint size,
629 GLuint start,
630 GLuint n )
631{
Gareth Hughes22144ab2001-03-12 00:48:37 +0000632 _math_trans_4us_tab[size][TYPE_IDX(type)]( to, ptr, stride, start, n );
Brian Paul74b493a2001-01-24 00:04:58 +0000633}
634
Keith Whitwellcab974c2000-12-26 05:09:27 +0000635void _math_trans_4f(GLfloat (*to)[4],
636 CONST void *ptr,
637 GLuint stride,
638 GLenum type,
639 GLuint size,
640 GLuint start,
641 GLuint n )
642{
Gareth Hughes22144ab2001-03-12 00:48:37 +0000643 _math_trans_4f_tab[size][TYPE_IDX(type)]( to, ptr, stride, start, n );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000644}
645
646void _math_trans_3f(GLfloat (*to)[3],
647 CONST void *ptr,
648 GLuint stride,
649 GLenum type,
650 GLuint start,
651 GLuint n )
652{
Gareth Hughes22144ab2001-03-12 00:48:37 +0000653 _math_trans_3f_tab[TYPE_IDX(type)]( to, ptr, stride, start, n );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000654}