blob: d12babe5b867b00a3727eda2520157586510339d [file] [log] [blame]
Keith Whitwell5f2230c2001-05-09 14:12:34 +00001/* $Id: m_translate.c,v 1.8 2001/05/09 14:12:34 keithw 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) )
Keith Whitwell5f2230c2001-05-09 14:12:34 +0000124#define TRX_4F(f,n) BYTE_TO_FLOAT( PTR_ELT(f,n) )
Keith Whitwell23caf202000-11-16 21:05:34 +0000125#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)
Keith Whitwell51c0c712001-04-28 08:39:17 +0000170#define TRX_3F(f,n) UBYTE_TO_FLOAT(PTR_ELT(f,n))
171#define TRX_4F(f,n) UBYTE_TO_FLOAT(PTR_ELT(f,n))
Keith Whitwell23caf202000-11-16 21:05:34 +0000172#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 */
Keith Whitwell51c0c712001-04-28 08:39:17 +0000178#define SZ 4
179#define INIT init_trans_4_GLubyte_raw
180#define DEST_4F trans_4_GLubyte_4f_raw
181#define DEST_4US trans_4_GLubyte_4us_raw
182#include "m_trans_tmp.h"
183
Keith Whitwell23caf202000-11-16 21:05:34 +0000184
185#define SZ 3
186#define INIT init_trans_3_GLubyte_raw
187#define DEST_4UB trans_3_GLubyte_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000188#define DEST_4US trans_3_GLubyte_4us_raw
Keith Whitwell51c0c712001-04-28 08:39:17 +0000189#define DEST_3F trans_3_GLubyte_3f_raw
190#define DEST_4F trans_3_GLubyte_4f_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000191#include "m_trans_tmp.h"
192
193
194#define SZ 1
195#define INIT init_trans_1_GLubyte_raw
196#define DEST_1UI trans_1_GLubyte_1ui_raw
197#define DEST_1UB trans_1_GLubyte_1ub_raw
198#include "m_trans_tmp.h"
199
200#undef SRC
201#undef SRC_IDX
202#undef TRX_3F
203#undef TRX_4F
204#undef TRX_UB
Brian Paul74b493a2001-01-24 00:04:58 +0000205#undef TRX_US
Keith Whitwell23caf202000-11-16 21:05:34 +0000206#undef TRX_UI
207
208
209/* GL_SHORT
210 */
211#define SRC GLshort
212#define SRC_IDX TYPE_IDX(GL_SHORT)
213#define TRX_3F(f,n) SHORT_TO_FLOAT( PTR_ELT(f,n) )
214#define TRX_4F(f,n) (GLfloat)( PTR_ELT(f,n) )
215#define TRX_UB(ub, f,n) ub = SHORT_TO_UBYTE(PTR_ELT(f,n))
Brian Paul74b493a2001-01-24 00:04:58 +0000216#define TRX_US(us, f,n) us = SHORT_TO_USHORT(PTR_ELT(f,n))
Keith Whitwell23caf202000-11-16 21:05:34 +0000217#define TRX_UI(f,n) (PTR_ELT(f,n) < 0 ? 0 : (GLuint) PTR_ELT(f,n))
218
219
220#define SZ 4
221#define INIT init_trans_4_GLshort_raw
222#define DEST_4F trans_4_GLshort_4f_raw
223#define DEST_4UB trans_4_GLshort_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000224#define DEST_4US trans_4_GLshort_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000225#include "m_trans_tmp.h"
226
227#define SZ 3
228#define INIT init_trans_3_GLshort_raw
229#define DEST_4F trans_3_GLshort_4f_raw
230#define DEST_4UB trans_3_GLshort_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000231#define DEST_4US trans_3_GLshort_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000232#define DEST_3F trans_3_GLshort_3f_raw
233#include "m_trans_tmp.h"
234
235#define SZ 2
236#define INIT init_trans_2_GLshort_raw
237#define DEST_4F trans_2_GLshort_4f_raw
238#include "m_trans_tmp.h"
239
240#define SZ 1
241#define INIT init_trans_1_GLshort_raw
242#define DEST_4F trans_1_GLshort_4f_raw
243#define DEST_1UB trans_1_GLshort_1ub_raw
244#define DEST_1UI trans_1_GLshort_1ui_raw
245#include "m_trans_tmp.h"
246
247
248#undef SRC
249#undef SRC_IDX
250#undef TRX_3F
251#undef TRX_4F
252#undef TRX_UB
Brian Paul74b493a2001-01-24 00:04:58 +0000253#undef TRX_US
Keith Whitwell23caf202000-11-16 21:05:34 +0000254#undef TRX_UI
255
256
257/* GL_UNSIGNED_SHORT
258 */
259#define SRC GLushort
260#define SRC_IDX TYPE_IDX(GL_UNSIGNED_SHORT)
261#define TRX_3F(f,n) USHORT_TO_FLOAT( PTR_ELT(f,n) )
262#define TRX_4F(f,n) (GLfloat)( PTR_ELT(f,n) )
263#define TRX_UB(ub,f,n) ub = (GLubyte) (PTR_ELT(f,n) >> 8)
Brian Paul74b493a2001-01-24 00:04:58 +0000264#define TRX_US(us,f,n) us = (GLushort) (PTR_ELT(f,n) >> 8)
Keith Whitwell23caf202000-11-16 21:05:34 +0000265#define TRX_UI(f,n) (GLuint) PTR_ELT(f,n)
266
267
268#define SZ 4
269#define INIT init_trans_4_GLushort_raw
270#define DEST_4F trans_4_GLushort_4f_raw
271#define DEST_4UB trans_4_GLushort_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000272#define DEST_4US trans_4_GLushort_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000273#include "m_trans_tmp.h"
274
275#define SZ 3
276#define INIT init_trans_3_GLushort_raw
277#define DEST_4F trans_3_GLushort_4f_raw
278#define DEST_4UB trans_3_GLushort_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000279#define DEST_4US trans_3_GLushort_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000280#define DEST_3F trans_3_GLushort_3f_raw
281#include "m_trans_tmp.h"
282
283#define SZ 2
284#define INIT init_trans_2_GLushort_raw
285#define DEST_4F trans_2_GLushort_4f_raw
286#include "m_trans_tmp.h"
287
288#define SZ 1
289#define INIT init_trans_1_GLushort_raw
290#define DEST_4F trans_1_GLushort_4f_raw
291#define DEST_1UB trans_1_GLushort_1ub_raw
292#define DEST_1UI trans_1_GLushort_1ui_raw
293#include "m_trans_tmp.h"
294
295#undef SRC
296#undef SRC_IDX
297#undef TRX_3F
298#undef TRX_4F
299#undef TRX_UB
Brian Paul74b493a2001-01-24 00:04:58 +0000300#undef TRX_US
Keith Whitwell23caf202000-11-16 21:05:34 +0000301#undef TRX_UI
302
303
304/* GL_INT
305 */
306#define SRC GLint
307#define SRC_IDX TYPE_IDX(GL_INT)
308#define TRX_3F(f,n) INT_TO_FLOAT( PTR_ELT(f,n) )
309#define TRX_4F(f,n) (GLfloat)( PTR_ELT(f,n) )
310#define TRX_UB(ub, f,n) ub = INT_TO_UBYTE(PTR_ELT(f,n))
Brian Paul74b493a2001-01-24 00:04:58 +0000311#define TRX_US(us, f,n) us = INT_TO_USHORT(PTR_ELT(f,n))
Keith Whitwell23caf202000-11-16 21:05:34 +0000312#define TRX_UI(f,n) (PTR_ELT(f,n) < 0 ? 0 : (GLuint) PTR_ELT(f,n))
313
314
315#define SZ 4
316#define INIT init_trans_4_GLint_raw
317#define DEST_4F trans_4_GLint_4f_raw
318#define DEST_4UB trans_4_GLint_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000319#define DEST_4US trans_4_GLint_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000320#include "m_trans_tmp.h"
321
322#define SZ 3
323#define INIT init_trans_3_GLint_raw
324#define DEST_4F trans_3_GLint_4f_raw
325#define DEST_4UB trans_3_GLint_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000326#define DEST_4US trans_3_GLint_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000327#define DEST_3F trans_3_GLint_3f_raw
328#include "m_trans_tmp.h"
329
330#define SZ 2
331#define INIT init_trans_2_GLint_raw
332#define DEST_4F trans_2_GLint_4f_raw
333#include "m_trans_tmp.h"
334
335#define SZ 1
336#define INIT init_trans_1_GLint_raw
337#define DEST_4F trans_1_GLint_4f_raw
338#define DEST_1UB trans_1_GLint_1ub_raw
339#define DEST_1UI trans_1_GLint_1ui_raw
340#include "m_trans_tmp.h"
341
342
343#undef SRC
344#undef SRC_IDX
345#undef TRX_3F
346#undef TRX_4F
347#undef TRX_UB
Brian Paul74b493a2001-01-24 00:04:58 +0000348#undef TRX_US
Keith Whitwell23caf202000-11-16 21:05:34 +0000349#undef TRX_UI
350
351
352/* GL_UNSIGNED_INT
353 */
354#define SRC GLuint
355#define SRC_IDX TYPE_IDX(GL_UNSIGNED_INT)
356#define TRX_3F(f,n) INT_TO_FLOAT( PTR_ELT(f,n) )
357#define TRX_4F(f,n) (GLfloat)( PTR_ELT(f,n) )
358#define TRX_UB(ub, f,n) ub = (GLubyte) (PTR_ELT(f,n) >> 24)
Brian Paul74b493a2001-01-24 00:04:58 +0000359#define TRX_US(us, f,n) us = (GLshort) (PTR_ELT(f,n) >> 16)
Keith Whitwell23caf202000-11-16 21:05:34 +0000360#define TRX_UI(f,n) PTR_ELT(f,n)
361
362
363#define SZ 4
364#define INIT init_trans_4_GLuint_raw
365#define DEST_4F trans_4_GLuint_4f_raw
366#define DEST_4UB trans_4_GLuint_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000367#define DEST_4US trans_4_GLuint_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000368#include "m_trans_tmp.h"
369
370#define SZ 3
371#define INIT init_trans_3_GLuint_raw
372#define DEST_4F trans_3_GLuint_4f_raw
373#define DEST_4UB trans_3_GLuint_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000374#define DEST_4US trans_3_GLuint_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000375#define DEST_3F trans_3_GLuint_3f_raw
376#include "m_trans_tmp.h"
377
378#define SZ 2
379#define INIT init_trans_2_GLuint_raw
380#define DEST_4F trans_2_GLuint_4f_raw
381#include "m_trans_tmp.h"
382
383#define SZ 1
384#define INIT init_trans_1_GLuint_raw
385#define DEST_4F trans_1_GLuint_4f_raw
386#define DEST_1UB trans_1_GLuint_1ub_raw
387#define DEST_1UI trans_1_GLuint_1ui_raw
388#include "m_trans_tmp.h"
389
390#undef SRC
391#undef SRC_IDX
392#undef TRX_3F
393#undef TRX_4F
394#undef TRX_UB
Brian Paul74b493a2001-01-24 00:04:58 +0000395#undef TRX_US
Keith Whitwell23caf202000-11-16 21:05:34 +0000396#undef TRX_UI
397
398
399/* GL_DOUBLE
400 */
401#define SRC GLdouble
402#define SRC_IDX TYPE_IDX(GL_DOUBLE)
403#define TRX_3F(f,n) PTR_ELT(f,n)
404#define TRX_4F(f,n) PTR_ELT(f,n)
Brian Paul74b493a2001-01-24 00:04:58 +0000405#define TRX_UB(ub,f,n) UNCLAMPED_FLOAT_TO_UBYTE(ub, PTR_ELT(f,n))
406#define TRX_US(us,f,n) UNCLAMPED_FLOAT_TO_USHORT(us, PTR_ELT(f,n))
Keith Whitwell23caf202000-11-16 21:05:34 +0000407#define TRX_UI(f,n) (GLuint) (GLint) PTR_ELT(f,n)
408#define TRX_1F(f,n) PTR_ELT(f,n)
409
410
411#define SZ 4
412#define INIT init_trans_4_GLdouble_raw
413#define DEST_4F trans_4_GLdouble_4f_raw
414#define DEST_4UB trans_4_GLdouble_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000415#define DEST_4US trans_4_GLdouble_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000416#include "m_trans_tmp.h"
417
418#define SZ 3
419#define INIT init_trans_3_GLdouble_raw
420#define DEST_4F trans_3_GLdouble_4f_raw
421#define DEST_4UB trans_3_GLdouble_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000422#define DEST_4US trans_3_GLdouble_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000423#define DEST_3F trans_3_GLdouble_3f_raw
424#include "m_trans_tmp.h"
425
426#define SZ 2
427#define INIT init_trans_2_GLdouble_raw
428#define DEST_4F trans_2_GLdouble_4f_raw
429#include "m_trans_tmp.h"
430
431#define SZ 1
432#define INIT init_trans_1_GLdouble_raw
433#define DEST_4F trans_1_GLdouble_4f_raw
434#define DEST_1UB trans_1_GLdouble_1ub_raw
435#define DEST_1UI trans_1_GLdouble_1ui_raw
436#define DEST_1F trans_1_GLdouble_1f_raw
437#include "m_trans_tmp.h"
438
439#undef SRC
440#undef SRC_IDX
441
442/* GL_FLOAT
443 */
444#define SRC GLfloat
445#define SRC_IDX TYPE_IDX(GL_FLOAT)
446#define SZ 4
Gareth Hughes22144ab2001-03-12 00:48:37 +0000447#define INIT init_trans_4_GLfloat_raw
448#define DEST_4UB trans_4_GLfloat_4ub_raw
449#define DEST_4US trans_4_GLfloat_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000450#define DEST_4F trans_4_GLfloat_4f_raw
451#include "m_trans_tmp.h"
452
453#define SZ 3
454#define INIT init_trans_3_GLfloat_raw
455#define DEST_4F trans_3_GLfloat_4f_raw
456#define DEST_4UB trans_3_GLfloat_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000457#define DEST_4US trans_3_GLfloat_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000458#define DEST_3F trans_3_GLfloat_3f_raw
459#include "m_trans_tmp.h"
460
461#define SZ 2
462#define INIT init_trans_2_GLfloat_raw
463#define DEST_4F trans_2_GLfloat_4f_raw
464#include "m_trans_tmp.h"
465
466#define SZ 1
467#define INIT init_trans_1_GLfloat_raw
468#define DEST_4F trans_1_GLfloat_4f_raw
469#define DEST_1UB trans_1_GLfloat_1ub_raw
470#define DEST_1UI trans_1_GLfloat_1ui_raw
471#define DEST_1F trans_1_GLfloat_1f_raw
472
473#include "m_trans_tmp.h"
474
475#undef SRC
476#undef SRC_IDX
477#undef TRX_3F
478#undef TRX_4F
479#undef TRX_UB
Brian Paul74b493a2001-01-24 00:04:58 +0000480#undef TRX_US
Keith Whitwell23caf202000-11-16 21:05:34 +0000481#undef TRX_UI
482
483
Brian Paul74b493a2001-01-24 00:04:58 +0000484static void trans_4_GLubyte_4ub_raw(GLubyte (*t)[4],
485 CONST void *Ptr,
486 GLuint stride,
487 ARGS )
Keith Whitwell23caf202000-11-16 21:05:34 +0000488{
489 const GLubyte *f = (GLubyte *) Ptr + SRC_START * stride;
490 GLuint i;
491
Gareth Hughes22144ab2001-03-12 00:48:37 +0000492 if (((((long) f | (long) stride)) & 3L) == 0L) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000493 /* Aligned.
494 */
495 for (i = DST_START ; i < n ; i++, f += stride) {
496 COPY_4UBV( t[i], f );
497 }
498 } else {
499 for (i = DST_START ; i < n ; i++, f += stride) {
500 t[i][0] = f[0];
501 t[i][1] = f[1];
502 t[i][2] = f[2];
503 t[i][3] = f[3];
504 }
505 }
506}
507
508
509static void init_translate_raw(void)
510{
511 MEMSET( TAB(_1ui), 0, sizeof(TAB(_1ui)) );
512 MEMSET( TAB(_1ub), 0, sizeof(TAB(_1ub)) );
513 MEMSET( TAB(_3f), 0, sizeof(TAB(_3f)) );
514 MEMSET( TAB(_4ub), 0, sizeof(TAB(_4ub)) );
Brian Paul74b493a2001-01-24 00:04:58 +0000515 MEMSET( TAB(_4us), 0, sizeof(TAB(_4us)) );
Keith Whitwell23caf202000-11-16 21:05:34 +0000516 MEMSET( TAB(_4f), 0, sizeof(TAB(_4f)) );
517
Keith Whitwell23caf202000-11-16 21:05:34 +0000518 init_trans_4_GLbyte_raw();
519 init_trans_3_GLbyte_raw();
520 init_trans_2_GLbyte_raw();
521 init_trans_1_GLbyte_raw();
522 init_trans_1_GLubyte_raw();
523 init_trans_3_GLubyte_raw();
Keith Whitwell51c0c712001-04-28 08:39:17 +0000524 init_trans_4_GLubyte_raw();
Keith Whitwell23caf202000-11-16 21:05:34 +0000525 init_trans_4_GLshort_raw();
526 init_trans_3_GLshort_raw();
527 init_trans_2_GLshort_raw();
528 init_trans_1_GLshort_raw();
529 init_trans_4_GLushort_raw();
530 init_trans_3_GLushort_raw();
531 init_trans_2_GLushort_raw();
532 init_trans_1_GLushort_raw();
533 init_trans_4_GLint_raw();
534 init_trans_3_GLint_raw();
535 init_trans_2_GLint_raw();
536 init_trans_1_GLint_raw();
537 init_trans_4_GLuint_raw();
538 init_trans_3_GLuint_raw();
539 init_trans_2_GLuint_raw();
540 init_trans_1_GLuint_raw();
541 init_trans_4_GLdouble_raw();
542 init_trans_3_GLdouble_raw();
543 init_trans_2_GLdouble_raw();
544 init_trans_1_GLdouble_raw();
545 init_trans_4_GLfloat_raw();
546 init_trans_3_GLfloat_raw();
547 init_trans_2_GLfloat_raw();
548 init_trans_1_GLfloat_raw();
Keith Whitwell51c0c712001-04-28 08:39:17 +0000549
550 TAB(_4ub)[4][TYPE_IDX(GL_UNSIGNED_BYTE)] = trans_4_GLubyte_4ub_raw;
Keith Whitwell23caf202000-11-16 21:05:34 +0000551}
552
553
554#undef TAB
555#undef CLASS
556#undef ARGS
557#undef CHECK
558#undef SRC_START
559#undef DST_START
560#undef NEXT_F
561#undef NEXT_F2
562
563
564
565
566
Keith Whitwellcab974c2000-12-26 05:09:27 +0000567void _math_init_translate( void )
Keith Whitwell23caf202000-11-16 21:05:34 +0000568{
569 init_translate_raw();
570}
Keith Whitwellcab974c2000-12-26 05:09:27 +0000571
572
573
574void _math_trans_1f(GLfloat *to,
575 CONST void *ptr,
576 GLuint stride,
577 GLenum type,
578 GLuint start,
579 GLuint n )
580{
581 _math_trans_1f_tab[TYPE_IDX(type)]( to, ptr, stride, start, n );
582}
583
584void _math_trans_1ui(GLuint *to,
585 CONST void *ptr,
586 GLuint stride,
587 GLenum type,
588 GLuint start,
589 GLuint n )
590{
Gareth Hughes22144ab2001-03-12 00:48:37 +0000591 _math_trans_1ui_tab[TYPE_IDX(type)]( to, ptr, stride, start, n );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000592}
593
594void _math_trans_1ub(GLubyte *to,
595 CONST void *ptr,
596 GLuint stride,
597 GLenum type,
598 GLuint start,
599 GLuint n )
600{
Gareth Hughes22144ab2001-03-12 00:48:37 +0000601 _math_trans_1ub_tab[TYPE_IDX(type)]( to, ptr, stride, start, n );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000602}
603
604
605void _math_trans_4ub(GLubyte (*to)[4],
606 CONST void *ptr,
607 GLuint stride,
608 GLenum type,
609 GLuint size,
610 GLuint start,
611 GLuint n )
612{
Gareth Hughes22144ab2001-03-12 00:48:37 +0000613 _math_trans_4ub_tab[size][TYPE_IDX(type)]( to, ptr, stride, start, n );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000614}
615
Keith Whitwell4eebc902001-02-20 18:28:52 +0000616void _math_trans_4chan( GLchan (*to)[4],
617 CONST void *ptr,
618 GLuint stride,
619 GLenum type,
620 GLuint size,
621 GLuint start,
622 GLuint n )
623{
624#if CHAN_TYPE == GL_UNSIGNED_BYTE
625 _math_trans_4ub( to, ptr, stride, type, size, start, n );
626#elif CHAN_TYPE == GL_UNSIGNED_SHORT
627 _math_trans_4us( to, ptr, stride, type, size, start, n );
628#elif CHAN_TYPE == GL_FLOAT
629 _math_trans_4f( to, ptr, stride, type, size, start, n );
630#endif
631}
632
Brian Paul74b493a2001-01-24 00:04:58 +0000633void _math_trans_4us(GLushort (*to)[4],
634 CONST void *ptr,
635 GLuint stride,
636 GLenum type,
637 GLuint size,
638 GLuint start,
639 GLuint n )
640{
Gareth Hughes22144ab2001-03-12 00:48:37 +0000641 _math_trans_4us_tab[size][TYPE_IDX(type)]( to, ptr, stride, start, n );
Brian Paul74b493a2001-01-24 00:04:58 +0000642}
643
Keith Whitwellcab974c2000-12-26 05:09:27 +0000644void _math_trans_4f(GLfloat (*to)[4],
645 CONST void *ptr,
646 GLuint stride,
647 GLenum type,
648 GLuint size,
649 GLuint start,
650 GLuint n )
651{
Gareth Hughes22144ab2001-03-12 00:48:37 +0000652 _math_trans_4f_tab[size][TYPE_IDX(type)]( to, ptr, stride, start, n );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000653}
654
655void _math_trans_3f(GLfloat (*to)[3],
656 CONST void *ptr,
657 GLuint stride,
658 GLenum type,
659 GLuint start,
660 GLuint n )
661{
Gareth Hughes22144ab2001-03-12 00:48:37 +0000662 _math_trans_3f_tab[TYPE_IDX(type)]( to, ptr, stride, start, n );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000663}