blob: 14beabb978d8f554eac71e8149f02d3987ed1bbc [file] [log] [blame]
Keith Whitwell23caf202000-11-16 21:05:34 +00001/*
2 * Mesa 3-D graphics library
Brian Pauld18c08f2003-05-28 15:30:53 +00003 * Version: 5.1
Gareth Hughes22144ab2001-03-12 00:48:37 +00004 *
Brian Pauld18c08f2003-05-28 15:30:53 +00005 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
Gareth Hughes22144ab2001-03-12 00:48:37 +00006 *
Keith Whitwell23caf202000-11-16 21:05:34 +00007 * 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:
Gareth Hughes22144ab2001-03-12 00:48:37 +000013 *
Keith Whitwell23caf202000-11-16 21:05:34 +000014 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
Gareth Hughes22144ab2001-03-12 00:48:37 +000016 *
Keith Whitwell23caf202000-11-16 21:05:34 +000017 * 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 * New (3.1) transformation code written by Keith Whitwell.
27 */
28
29
30#include "glheader.h"
Keith Whitwell4eebc902001-02-20 18:28:52 +000031#include "mtypes.h" /* GLchan hack */
Keith Whitwell23caf202000-11-16 21:05:34 +000032#include "colormac.h"
Keith Whitwell23caf202000-11-16 21:05:34 +000033
34#include "m_translate.h"
35
Keith Whitwellcab974c2000-12-26 05:09:27 +000036
37
38typedef void (*trans_1f_func)(GLfloat *to,
39 CONST void *ptr,
40 GLuint stride,
Gareth Hughes22144ab2001-03-12 00:48:37 +000041 GLuint start,
Keith Whitwellcab974c2000-12-26 05:09:27 +000042 GLuint n );
43
44typedef void (*trans_1ui_func)(GLuint *to,
45 CONST void *ptr,
46 GLuint stride,
Gareth Hughes22144ab2001-03-12 00:48:37 +000047 GLuint start,
Keith Whitwellcab974c2000-12-26 05:09:27 +000048 GLuint n );
49
50typedef void (*trans_1ub_func)(GLubyte *to,
51 CONST void *ptr,
52 GLuint stride,
53 GLuint start,
54 GLuint n );
55
56typedef void (*trans_4ub_func)(GLubyte (*to)[4],
Brian Paul74b493a2001-01-24 00:04:58 +000057 CONST void *ptr,
58 GLuint stride,
59 GLuint start,
60 GLuint n );
61
62typedef void (*trans_4us_func)(GLushort (*to)[4],
63 CONST void *ptr,
64 GLuint stride,
65 GLuint start,
66 GLuint n );
Keith Whitwellcab974c2000-12-26 05:09:27 +000067
68typedef void (*trans_4f_func)(GLfloat (*to)[4],
69 CONST void *ptr,
70 GLuint stride,
Gareth Hughes22144ab2001-03-12 00:48:37 +000071 GLuint start,
Keith Whitwellcab974c2000-12-26 05:09:27 +000072 GLuint n );
73
74typedef void (*trans_3f_func)(GLfloat (*to)[3],
75 CONST void *ptr,
76 GLuint stride,
Gareth Hughes22144ab2001-03-12 00:48:37 +000077 GLuint start,
Keith Whitwellcab974c2000-12-26 05:09:27 +000078 GLuint n );
79
80
81
82
83#define TYPE_IDX(t) ((t) & 0xf)
84#define MAX_TYPES TYPE_IDX(GL_DOUBLE)+1 /* 0xa + 1 */
85
86
Keith Whitwell23caf202000-11-16 21:05:34 +000087/* This macro is used on other systems, so undefine it for this module */
88
89#undef CHECK
90
Keith Whitwellcab974c2000-12-26 05:09:27 +000091static trans_1f_func _math_trans_1f_tab[MAX_TYPES];
92static trans_1ui_func _math_trans_1ui_tab[MAX_TYPES];
93static trans_1ub_func _math_trans_1ub_tab[MAX_TYPES];
94static trans_3f_func _math_trans_3f_tab[MAX_TYPES];
95static trans_4ub_func _math_trans_4ub_tab[5][MAX_TYPES];
Brian Paul74b493a2001-01-24 00:04:58 +000096static trans_4us_func _math_trans_4us_tab[5][MAX_TYPES];
Keith Whitwellcab974c2000-12-26 05:09:27 +000097static trans_4f_func _math_trans_4f_tab[5][MAX_TYPES];
Keith Whitwell12c037d2003-08-20 07:21:41 +000098static trans_4f_func _math_trans_4fc_tab[5][MAX_TYPES];
Keith Whitwell23caf202000-11-16 21:05:34 +000099
100
101#define PTR_ELT(ptr, elt) (((SRC *)ptr)[elt])
102
103
Keith Whitwellcab974c2000-12-26 05:09:27 +0000104#define TAB(x) _math_trans##x##_tab
Keith Whitwell23caf202000-11-16 21:05:34 +0000105#define ARGS GLuint start, GLuint n
106#define SRC_START start
107#define DST_START 0
108#define STRIDE stride
109#define NEXT_F f += stride
110#define NEXT_F2
111#define CHECK
112
113
114
115
116/* GL_BYTE
117 */
118#define SRC GLbyte
119#define SRC_IDX TYPE_IDX(GL_BYTE)
120#define TRX_3F(f,n) BYTE_TO_FLOAT( PTR_ELT(f,n) )
Keith Whitwell5f2230c2001-05-09 14:12:34 +0000121#define TRX_4F(f,n) BYTE_TO_FLOAT( PTR_ELT(f,n) )
Keith Whitwell12c037d2003-08-20 07:21:41 +0000122#define TRX_4FC(f,n) BYTE_TO_FLOAT( PTR_ELT(f,n) )
Keith Whitwell23caf202000-11-16 21:05:34 +0000123#define TRX_UB(ub, f,n) ub = BYTE_TO_UBYTE( PTR_ELT(f,n) )
Brian Paul74b493a2001-01-24 00:04:58 +0000124#define TRX_US(ch, f,n) ch = BYTE_TO_USHORT( PTR_ELT(f,n) )
Keith Whitwell23caf202000-11-16 21:05:34 +0000125#define TRX_UI(f,n) (PTR_ELT(f,n) < 0 ? 0 : (GLuint) PTR_ELT(f,n))
126
127
128#define SZ 4
129#define INIT init_trans_4_GLbyte_raw
130#define DEST_4F trans_4_GLbyte_4f_raw
Keith Whitwell12c037d2003-08-20 07:21:41 +0000131#define DEST_4FC trans_4_GLbyte_4fc_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000132#define DEST_4UB trans_4_GLbyte_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000133#define DEST_4US trans_4_GLbyte_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000134#include "m_trans_tmp.h"
135
136#define SZ 3
137#define INIT init_trans_3_GLbyte_raw
138#define DEST_4F trans_3_GLbyte_4f_raw
Keith Whitwell12c037d2003-08-20 07:21:41 +0000139#define DEST_4FC trans_3_GLbyte_4fc_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000140#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
Keith Whitwell12c037d2003-08-20 07:21:41 +0000148#define DEST_4FC trans_2_GLbyte_4fc_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000149#include "m_trans_tmp.h"
150
151#define SZ 1
152#define INIT init_trans_1_GLbyte_raw
153#define DEST_4F trans_1_GLbyte_4f_raw
Keith Whitwell12c037d2003-08-20 07:21:41 +0000154#define DEST_4FC trans_1_GLbyte_4fc_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000155#define DEST_1UB trans_1_GLbyte_1ub_raw
156#define DEST_1UI trans_1_GLbyte_1ui_raw
157#include "m_trans_tmp.h"
158
159#undef SRC
160#undef TRX_3F
161#undef TRX_4F
Keith Whitwell12c037d2003-08-20 07:21:41 +0000162#undef TRX_4FC
Keith Whitwell23caf202000-11-16 21:05:34 +0000163#undef TRX_UB
Brian Paul74b493a2001-01-24 00:04:58 +0000164#undef TRX_US
Keith Whitwell23caf202000-11-16 21:05:34 +0000165#undef TRX_UI
166#undef SRC_IDX
167
Brian Paul74b493a2001-01-24 00:04:58 +0000168
Keith Whitwell23caf202000-11-16 21:05:34 +0000169/* GL_UNSIGNED_BYTE
170 */
171#define SRC GLubyte
172#define SRC_IDX TYPE_IDX(GL_UNSIGNED_BYTE)
Keith Whitwell51c0c712001-04-28 08:39:17 +0000173#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))
Keith Whitwell12c037d2003-08-20 07:21:41 +0000175#define TRX_4FC(f,n) UBYTE_TO_FLOAT(PTR_ELT(f,n))
Keith Whitwell23caf202000-11-16 21:05:34 +0000176#define TRX_UB(ub, f,n) ub = PTR_ELT(f,n)
Brian Paul74b493a2001-01-24 00:04:58 +0000177#define TRX_US(us, f,n) us = UBYTE_TO_USHORT(PTR_ELT(f,n))
Keith Whitwell23caf202000-11-16 21:05:34 +0000178#define TRX_UI(f,n) (GLuint)PTR_ELT(f,n)
179
180/* 4ub->4ub handled in special case below.
181 */
Keith Whitwell51c0c712001-04-28 08:39:17 +0000182#define SZ 4
183#define INIT init_trans_4_GLubyte_raw
184#define DEST_4F trans_4_GLubyte_4f_raw
Keith Whitwell12c037d2003-08-20 07:21:41 +0000185#define DEST_4FC trans_4_GLubyte_4fc_raw
Keith Whitwell51c0c712001-04-28 08:39:17 +0000186#define DEST_4US trans_4_GLubyte_4us_raw
187#include "m_trans_tmp.h"
188
Keith Whitwell23caf202000-11-16 21:05:34 +0000189
190#define SZ 3
191#define INIT init_trans_3_GLubyte_raw
192#define DEST_4UB trans_3_GLubyte_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000193#define DEST_4US trans_3_GLubyte_4us_raw
Keith Whitwell51c0c712001-04-28 08:39:17 +0000194#define DEST_3F trans_3_GLubyte_3f_raw
195#define DEST_4F trans_3_GLubyte_4f_raw
Keith Whitwell12c037d2003-08-20 07:21:41 +0000196#define DEST_4FC trans_3_GLubyte_4fc_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000197#include "m_trans_tmp.h"
198
199
200#define SZ 1
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"
205
206#undef SRC
207#undef SRC_IDX
208#undef TRX_3F
209#undef TRX_4F
Keith Whitwell12c037d2003-08-20 07:21:41 +0000210#undef TRX_4FC
Keith Whitwell23caf202000-11-16 21:05:34 +0000211#undef TRX_UB
Brian Paul74b493a2001-01-24 00:04:58 +0000212#undef TRX_US
Keith Whitwell23caf202000-11-16 21:05:34 +0000213#undef TRX_UI
214
215
216/* GL_SHORT
217 */
218#define SRC GLshort
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) )
Keith Whitwell12c037d2003-08-20 07:21:41 +0000222#define TRX_4FC(f,n) (GLfloat)( PTR_ELT(f,n) )
Keith Whitwell23caf202000-11-16 21:05:34 +0000223#define TRX_UB(ub, f,n) ub = SHORT_TO_UBYTE(PTR_ELT(f,n))
Brian Paul74b493a2001-01-24 00:04:58 +0000224#define TRX_US(us, f,n) us = SHORT_TO_USHORT(PTR_ELT(f,n))
Keith Whitwell23caf202000-11-16 21:05:34 +0000225#define TRX_UI(f,n) (PTR_ELT(f,n) < 0 ? 0 : (GLuint) PTR_ELT(f,n))
226
227
228#define SZ 4
229#define INIT init_trans_4_GLshort_raw
230#define DEST_4F trans_4_GLshort_4f_raw
Keith Whitwell12c037d2003-08-20 07:21:41 +0000231#define DEST_4FC trans_4_GLshort_4fc_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000232#define DEST_4UB trans_4_GLshort_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000233#define DEST_4US trans_4_GLshort_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000234#include "m_trans_tmp.h"
235
236#define SZ 3
237#define INIT init_trans_3_GLshort_raw
238#define DEST_4F trans_3_GLshort_4f_raw
Keith Whitwell12c037d2003-08-20 07:21:41 +0000239#define DEST_4FC trans_3_GLshort_4fc_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000240#define DEST_4UB trans_3_GLshort_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000241#define DEST_4US trans_3_GLshort_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000242#define DEST_3F trans_3_GLshort_3f_raw
243#include "m_trans_tmp.h"
244
245#define SZ 2
246#define INIT init_trans_2_GLshort_raw
247#define DEST_4F trans_2_GLshort_4f_raw
Keith Whitwell12c037d2003-08-20 07:21:41 +0000248#define DEST_4FC trans_2_GLshort_4fc_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000249#include "m_trans_tmp.h"
250
251#define SZ 1
252#define INIT init_trans_1_GLshort_raw
253#define DEST_4F trans_1_GLshort_4f_raw
Keith Whitwell12c037d2003-08-20 07:21:41 +0000254#define DEST_4FC trans_1_GLshort_4fc_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000255#define DEST_1UB trans_1_GLshort_1ub_raw
256#define DEST_1UI trans_1_GLshort_1ui_raw
257#include "m_trans_tmp.h"
258
259
260#undef SRC
261#undef SRC_IDX
262#undef TRX_3F
263#undef TRX_4F
Keith Whitwell12c037d2003-08-20 07:21:41 +0000264#undef TRX_4FC
Keith Whitwell23caf202000-11-16 21:05:34 +0000265#undef TRX_UB
Brian Paul74b493a2001-01-24 00:04:58 +0000266#undef TRX_US
Keith Whitwell23caf202000-11-16 21:05:34 +0000267#undef TRX_UI
268
269
270/* GL_UNSIGNED_SHORT
271 */
272#define SRC GLushort
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) )
Keith Whitwell12c037d2003-08-20 07:21:41 +0000276#define TRX_4FC(f,n) (GLfloat)( PTR_ELT(f,n) )
Keith Whitwell23caf202000-11-16 21:05:34 +0000277#define TRX_UB(ub,f,n) ub = (GLubyte) (PTR_ELT(f,n) >> 8)
Brian Paul74b493a2001-01-24 00:04:58 +0000278#define TRX_US(us,f,n) us = (GLushort) (PTR_ELT(f,n) >> 8)
Keith Whitwell23caf202000-11-16 21:05:34 +0000279#define TRX_UI(f,n) (GLuint) PTR_ELT(f,n)
280
281
282#define SZ 4
283#define INIT init_trans_4_GLushort_raw
284#define DEST_4F trans_4_GLushort_4f_raw
Keith Whitwell12c037d2003-08-20 07:21:41 +0000285#define DEST_4FC trans_4_GLushort_4fc_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000286#define DEST_4UB trans_4_GLushort_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000287#define DEST_4US trans_4_GLushort_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000288#include "m_trans_tmp.h"
289
290#define SZ 3
291#define INIT init_trans_3_GLushort_raw
292#define DEST_4F trans_3_GLushort_4f_raw
Keith Whitwell12c037d2003-08-20 07:21:41 +0000293#define DEST_4FC trans_3_GLushort_4fc_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000294#define DEST_4UB trans_3_GLushort_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000295#define DEST_4US trans_3_GLushort_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000296#define DEST_3F trans_3_GLushort_3f_raw
297#include "m_trans_tmp.h"
298
299#define SZ 2
300#define INIT init_trans_2_GLushort_raw
301#define DEST_4F trans_2_GLushort_4f_raw
Keith Whitwell12c037d2003-08-20 07:21:41 +0000302#define DEST_4FC trans_2_GLushort_4fc_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000303#include "m_trans_tmp.h"
304
305#define SZ 1
306#define INIT init_trans_1_GLushort_raw
307#define DEST_4F trans_1_GLushort_4f_raw
Keith Whitwell12c037d2003-08-20 07:21:41 +0000308#define DEST_4FC trans_1_GLushort_4fc_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000309#define DEST_1UB trans_1_GLushort_1ub_raw
310#define DEST_1UI trans_1_GLushort_1ui_raw
311#include "m_trans_tmp.h"
312
313#undef SRC
314#undef SRC_IDX
315#undef TRX_3F
316#undef TRX_4F
Keith Whitwell12c037d2003-08-20 07:21:41 +0000317#undef TRX_4FC
Keith Whitwell23caf202000-11-16 21:05:34 +0000318#undef TRX_UB
Brian Paul74b493a2001-01-24 00:04:58 +0000319#undef TRX_US
Keith Whitwell23caf202000-11-16 21:05:34 +0000320#undef TRX_UI
321
322
323/* GL_INT
324 */
325#define SRC GLint
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) )
Keith Whitwell12c037d2003-08-20 07:21:41 +0000329#define TRX_4FC(f,n) (GLfloat)( PTR_ELT(f,n) )
Keith Whitwell23caf202000-11-16 21:05:34 +0000330#define TRX_UB(ub, f,n) ub = INT_TO_UBYTE(PTR_ELT(f,n))
Brian Paul74b493a2001-01-24 00:04:58 +0000331#define TRX_US(us, f,n) us = INT_TO_USHORT(PTR_ELT(f,n))
Keith Whitwell23caf202000-11-16 21:05:34 +0000332#define TRX_UI(f,n) (PTR_ELT(f,n) < 0 ? 0 : (GLuint) PTR_ELT(f,n))
333
334
335#define SZ 4
336#define INIT init_trans_4_GLint_raw
337#define DEST_4F trans_4_GLint_4f_raw
Keith Whitwell12c037d2003-08-20 07:21:41 +0000338#define DEST_4FC trans_4_GLint_4fc_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000339#define DEST_4UB trans_4_GLint_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000340#define DEST_4US trans_4_GLint_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000341#include "m_trans_tmp.h"
342
343#define SZ 3
344#define INIT init_trans_3_GLint_raw
345#define DEST_4F trans_3_GLint_4f_raw
Keith Whitwell12c037d2003-08-20 07:21:41 +0000346#define DEST_4FC trans_3_GLint_4fc_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000347#define DEST_4UB trans_3_GLint_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000348#define DEST_4US trans_3_GLint_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000349#define DEST_3F trans_3_GLint_3f_raw
350#include "m_trans_tmp.h"
351
352#define SZ 2
353#define INIT init_trans_2_GLint_raw
354#define DEST_4F trans_2_GLint_4f_raw
Keith Whitwell12c037d2003-08-20 07:21:41 +0000355#define DEST_4FC trans_2_GLint_4fc_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000356#include "m_trans_tmp.h"
357
358#define SZ 1
359#define INIT init_trans_1_GLint_raw
360#define DEST_4F trans_1_GLint_4f_raw
Keith Whitwell12c037d2003-08-20 07:21:41 +0000361#define DEST_4FC trans_1_GLint_4fc_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000362#define DEST_1UB trans_1_GLint_1ub_raw
363#define DEST_1UI trans_1_GLint_1ui_raw
364#include "m_trans_tmp.h"
365
366
367#undef SRC
368#undef SRC_IDX
369#undef TRX_3F
370#undef TRX_4F
Keith Whitwell12c037d2003-08-20 07:21:41 +0000371#undef TRX_4FC
Keith Whitwell23caf202000-11-16 21:05:34 +0000372#undef TRX_UB
Brian Paul74b493a2001-01-24 00:04:58 +0000373#undef TRX_US
Keith Whitwell23caf202000-11-16 21:05:34 +0000374#undef TRX_UI
375
376
377/* GL_UNSIGNED_INT
378 */
379#define SRC GLuint
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) )
Keith Whitwell12c037d2003-08-20 07:21:41 +0000383#define TRX_4FC(f,n) (GLfloat)( PTR_ELT(f,n) )
Keith Whitwell23caf202000-11-16 21:05:34 +0000384#define TRX_UB(ub, f,n) ub = (GLubyte) (PTR_ELT(f,n) >> 24)
Brian Paul74b493a2001-01-24 00:04:58 +0000385#define TRX_US(us, f,n) us = (GLshort) (PTR_ELT(f,n) >> 16)
Keith Whitwell23caf202000-11-16 21:05:34 +0000386#define TRX_UI(f,n) PTR_ELT(f,n)
387
388
389#define SZ 4
390#define INIT init_trans_4_GLuint_raw
391#define DEST_4F trans_4_GLuint_4f_raw
Keith Whitwell12c037d2003-08-20 07:21:41 +0000392#define DEST_4FC trans_4_GLuint_4fc_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000393#define DEST_4UB trans_4_GLuint_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000394#define DEST_4US trans_4_GLuint_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000395#include "m_trans_tmp.h"
396
397#define SZ 3
398#define INIT init_trans_3_GLuint_raw
399#define DEST_4F trans_3_GLuint_4f_raw
Keith Whitwell12c037d2003-08-20 07:21:41 +0000400#define DEST_4FC trans_3_GLuint_4fc_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000401#define DEST_4UB trans_3_GLuint_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000402#define DEST_4US trans_3_GLuint_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000403#define DEST_3F trans_3_GLuint_3f_raw
404#include "m_trans_tmp.h"
405
406#define SZ 2
407#define INIT init_trans_2_GLuint_raw
408#define DEST_4F trans_2_GLuint_4f_raw
Keith Whitwell12c037d2003-08-20 07:21:41 +0000409#define DEST_4FC trans_2_GLuint_4fc_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000410#include "m_trans_tmp.h"
411
412#define SZ 1
413#define INIT init_trans_1_GLuint_raw
414#define DEST_4F trans_1_GLuint_4f_raw
Keith Whitwell12c037d2003-08-20 07:21:41 +0000415#define DEST_4FC trans_1_GLuint_4fc_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000416#define DEST_1UB trans_1_GLuint_1ub_raw
417#define DEST_1UI trans_1_GLuint_1ui_raw
418#include "m_trans_tmp.h"
419
420#undef SRC
421#undef SRC_IDX
422#undef TRX_3F
423#undef TRX_4F
Keith Whitwell12c037d2003-08-20 07:21:41 +0000424#undef TRX_4FC
Keith Whitwell23caf202000-11-16 21:05:34 +0000425#undef TRX_UB
Brian Paul74b493a2001-01-24 00:04:58 +0000426#undef TRX_US
Keith Whitwell23caf202000-11-16 21:05:34 +0000427#undef TRX_UI
428
429
430/* GL_DOUBLE
431 */
432#define SRC GLdouble
433#define SRC_IDX TYPE_IDX(GL_DOUBLE)
Karl Schultz7b9fe822001-09-18 23:06:14 +0000434#define TRX_3F(f,n) (GLfloat) PTR_ELT(f,n)
435#define TRX_4F(f,n) (GLfloat) PTR_ELT(f,n)
Keith Whitwell12c037d2003-08-20 07:21:41 +0000436#define TRX_4FC(f,n) (GLfloat) PTR_ELT(f,n)
Brian Paul74b493a2001-01-24 00:04:58 +0000437#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))
Keith Whitwell23caf202000-11-16 21:05:34 +0000439#define TRX_UI(f,n) (GLuint) (GLint) PTR_ELT(f,n)
Karl Schultz7b9fe822001-09-18 23:06:14 +0000440#define TRX_1F(f,n) (GLfloat) PTR_ELT(f,n)
Keith Whitwell23caf202000-11-16 21:05:34 +0000441
442
443#define SZ 4
444#define INIT init_trans_4_GLdouble_raw
445#define DEST_4F trans_4_GLdouble_4f_raw
Keith Whitwell12c037d2003-08-20 07:21:41 +0000446#define DEST_4FC trans_4_GLdouble_4fc_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000447#define DEST_4UB trans_4_GLdouble_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000448#define DEST_4US trans_4_GLdouble_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000449#include "m_trans_tmp.h"
450
451#define SZ 3
452#define INIT init_trans_3_GLdouble_raw
453#define DEST_4F trans_3_GLdouble_4f_raw
Keith Whitwell12c037d2003-08-20 07:21:41 +0000454#define DEST_4FC trans_3_GLdouble_4fc_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000455#define DEST_4UB trans_3_GLdouble_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000456#define DEST_4US trans_3_GLdouble_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000457#define DEST_3F trans_3_GLdouble_3f_raw
458#include "m_trans_tmp.h"
459
460#define SZ 2
461#define INIT init_trans_2_GLdouble_raw
462#define DEST_4F trans_2_GLdouble_4f_raw
Keith Whitwell12c037d2003-08-20 07:21:41 +0000463#define DEST_4FC trans_2_GLdouble_4fc_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000464#include "m_trans_tmp.h"
465
466#define SZ 1
467#define INIT init_trans_1_GLdouble_raw
468#define DEST_4F trans_1_GLdouble_4f_raw
Keith Whitwell12c037d2003-08-20 07:21:41 +0000469#define DEST_4FC trans_1_GLdouble_4fc_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000470#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"
474
475#undef SRC
476#undef SRC_IDX
477
478/* GL_FLOAT
479 */
480#define SRC GLfloat
481#define SRC_IDX TYPE_IDX(GL_FLOAT)
482#define SZ 4
Gareth Hughes22144ab2001-03-12 00:48:37 +0000483#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
Keith Whitwell23caf202000-11-16 21:05:34 +0000486#define DEST_4F trans_4_GLfloat_4f_raw
Keith Whitwell12c037d2003-08-20 07:21:41 +0000487#define DEST_4FC trans_4_GLfloat_4fc_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000488#include "m_trans_tmp.h"
489
490#define SZ 3
491#define INIT init_trans_3_GLfloat_raw
492#define DEST_4F trans_3_GLfloat_4f_raw
Keith Whitwell12c037d2003-08-20 07:21:41 +0000493#define DEST_4FC trans_3_GLfloat_4fc_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000494#define DEST_4UB trans_3_GLfloat_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000495#define DEST_4US trans_3_GLfloat_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000496#define DEST_3F trans_3_GLfloat_3f_raw
497#include "m_trans_tmp.h"
498
499#define SZ 2
500#define INIT init_trans_2_GLfloat_raw
501#define DEST_4F trans_2_GLfloat_4f_raw
Keith Whitwell12c037d2003-08-20 07:21:41 +0000502#define DEST_4FC trans_2_GLfloat_4fc_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000503#include "m_trans_tmp.h"
504
505#define SZ 1
506#define INIT init_trans_1_GLfloat_raw
507#define DEST_4F trans_1_GLfloat_4f_raw
Keith Whitwell12c037d2003-08-20 07:21:41 +0000508#define DEST_4FC trans_1_GLfloat_4fc_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000509#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
512
513#include "m_trans_tmp.h"
514
515#undef SRC
516#undef SRC_IDX
517#undef TRX_3F
518#undef TRX_4F
Keith Whitwell12c037d2003-08-20 07:21:41 +0000519#undef TRX_4FC
Keith Whitwell23caf202000-11-16 21:05:34 +0000520#undef TRX_UB
Brian Paul74b493a2001-01-24 00:04:58 +0000521#undef TRX_US
Keith Whitwell23caf202000-11-16 21:05:34 +0000522#undef TRX_UI
523
524
Brian Paul74b493a2001-01-24 00:04:58 +0000525static void trans_4_GLubyte_4ub_raw(GLubyte (*t)[4],
526 CONST void *Ptr,
527 GLuint stride,
528 ARGS )
Keith Whitwell23caf202000-11-16 21:05:34 +0000529{
530 const GLubyte *f = (GLubyte *) Ptr + SRC_START * stride;
531 GLuint i;
532
Gareth Hughes22144ab2001-03-12 00:48:37 +0000533 if (((((long) f | (long) stride)) & 3L) == 0L) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000534 /* Aligned.
535 */
536 for (i = DST_START ; i < n ; i++, f += stride) {
537 COPY_4UBV( t[i], f );
538 }
539 } else {
540 for (i = DST_START ; i < n ; i++, f += stride) {
541 t[i][0] = f[0];
542 t[i][1] = f[1];
543 t[i][2] = f[2];
544 t[i][3] = f[3];
545 }
546 }
547}
548
549
550static void init_translate_raw(void)
551{
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)) );
Brian Paul74b493a2001-01-24 00:04:58 +0000556 MEMSET( TAB(_4us), 0, sizeof(TAB(_4us)) );
Keith Whitwell23caf202000-11-16 21:05:34 +0000557 MEMSET( TAB(_4f), 0, sizeof(TAB(_4f)) );
Keith Whitwell12c037d2003-08-20 07:21:41 +0000558 MEMSET( TAB(_4fc), 0, sizeof(TAB(_4fc)) );
Keith Whitwell23caf202000-11-16 21:05:34 +0000559
Keith Whitwell23caf202000-11-16 21:05:34 +0000560 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();
Keith Whitwell51c0c712001-04-28 08:39:17 +0000566 init_trans_4_GLubyte_raw();
Keith Whitwell23caf202000-11-16 21:05:34 +0000567 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();
Keith Whitwell51c0c712001-04-28 08:39:17 +0000591
592 TAB(_4ub)[4][TYPE_IDX(GL_UNSIGNED_BYTE)] = trans_4_GLubyte_4ub_raw;
Keith Whitwell23caf202000-11-16 21:05:34 +0000593}
594
595
596#undef TAB
Brian Pauld18c08f2003-05-28 15:30:53 +0000597#ifdef CLASS
Keith Whitwell23caf202000-11-16 21:05:34 +0000598#undef CLASS
Brian Pauld18c08f2003-05-28 15:30:53 +0000599#endif
Keith Whitwell23caf202000-11-16 21:05:34 +0000600#undef ARGS
601#undef CHECK
602#undef SRC_START
603#undef DST_START
604#undef NEXT_F
605#undef NEXT_F2
606
607
608
609
610
Keith Whitwellcab974c2000-12-26 05:09:27 +0000611void _math_init_translate( void )
Keith Whitwell23caf202000-11-16 21:05:34 +0000612{
613 init_translate_raw();
614}
Keith Whitwellcab974c2000-12-26 05:09:27 +0000615
616
617
618void _math_trans_1f(GLfloat *to,
619 CONST void *ptr,
620 GLuint stride,
621 GLenum type,
622 GLuint start,
623 GLuint n )
624{
625 _math_trans_1f_tab[TYPE_IDX(type)]( to, ptr, stride, start, n );
626}
627
628void _math_trans_1ui(GLuint *to,
629 CONST void *ptr,
630 GLuint stride,
631 GLenum type,
632 GLuint start,
633 GLuint n )
634{
Gareth Hughes22144ab2001-03-12 00:48:37 +0000635 _math_trans_1ui_tab[TYPE_IDX(type)]( to, ptr, stride, start, n );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000636}
637
638void _math_trans_1ub(GLubyte *to,
639 CONST void *ptr,
640 GLuint stride,
641 GLenum type,
642 GLuint start,
643 GLuint n )
644{
Gareth Hughes22144ab2001-03-12 00:48:37 +0000645 _math_trans_1ub_tab[TYPE_IDX(type)]( to, ptr, stride, start, n );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000646}
647
648
649void _math_trans_4ub(GLubyte (*to)[4],
650 CONST void *ptr,
651 GLuint stride,
652 GLenum type,
653 GLuint size,
654 GLuint start,
655 GLuint n )
656{
Gareth Hughes22144ab2001-03-12 00:48:37 +0000657 _math_trans_4ub_tab[size][TYPE_IDX(type)]( to, ptr, stride, start, n );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000658}
659
Keith Whitwell4eebc902001-02-20 18:28:52 +0000660void _math_trans_4chan( GLchan (*to)[4],
661 CONST void *ptr,
662 GLuint stride,
663 GLenum type,
664 GLuint size,
665 GLuint start,
666 GLuint n )
667{
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
Keith Whitwell12c037d2003-08-20 07:21:41 +0000673 _math_trans_4fc( to, ptr, stride, type, size, start, n );
Keith Whitwell4eebc902001-02-20 18:28:52 +0000674#endif
675}
676
Brian Paul74b493a2001-01-24 00:04:58 +0000677void _math_trans_4us(GLushort (*to)[4],
678 CONST void *ptr,
679 GLuint stride,
680 GLenum type,
681 GLuint size,
682 GLuint start,
683 GLuint n )
684{
Gareth Hughes22144ab2001-03-12 00:48:37 +0000685 _math_trans_4us_tab[size][TYPE_IDX(type)]( to, ptr, stride, start, n );
Brian Paul74b493a2001-01-24 00:04:58 +0000686}
687
Keith Whitwellcab974c2000-12-26 05:09:27 +0000688void _math_trans_4f(GLfloat (*to)[4],
689 CONST void *ptr,
690 GLuint stride,
691 GLenum type,
692 GLuint size,
693 GLuint start,
694 GLuint n )
695{
Gareth Hughes22144ab2001-03-12 00:48:37 +0000696 _math_trans_4f_tab[size][TYPE_IDX(type)]( to, ptr, stride, start, n );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000697}
698
Keith Whitwell12c037d2003-08-20 07:21:41 +0000699void _math_trans_4fc(GLfloat (*to)[4],
700 CONST void *ptr,
701 GLuint stride,
702 GLenum type,
703 GLuint size,
704 GLuint start,
705 GLuint n )
706{
707 _math_trans_4fc_tab[size][TYPE_IDX(type)]( to, ptr, stride, start, n );
708}
709
Keith Whitwellcab974c2000-12-26 05:09:27 +0000710void _math_trans_3f(GLfloat (*to)[3],
711 CONST void *ptr,
712 GLuint stride,
713 GLenum type,
714 GLuint start,
715 GLuint n )
716{
Gareth Hughes22144ab2001-03-12 00:48:37 +0000717 _math_trans_3f_tab[TYPE_IDX(type)]( to, ptr, stride, start, n );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000718}