blob: c7423e9d9db4d1c3ae08eaf66b9ba8c17cf002bd [file] [log] [blame]
Keith Whitwell23caf202000-11-16 21:05:34 +00001/*
2 * Mesa 3-D graphics library
Brian Paul0395cc02006-06-13 03:22:52 +00003 * Version: 6.5.1
Gareth Hughes22144ab2001-03-12 00:48:37 +00004 *
Brian Paul0395cc02006-06-13 03:22:52 +00005 * Copyright (C) 1999-2006 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
Brian Paul0395cc02006-06-13 03:22:52 +000025/**
26 * \brief Translate vectors of numbers between various types.
27 * \author Keith Whitwell.
Keith Whitwell23caf202000-11-16 21:05:34 +000028 */
29
30
31#include "glheader.h"
Keith Whitwell4eebc902001-02-20 18:28:52 +000032#include "mtypes.h" /* GLchan hack */
Keith Whitwell23caf202000-11-16 21:05:34 +000033#include "colormac.h"
Keith Whitwell23caf202000-11-16 21:05:34 +000034
35#include "m_translate.h"
36
Keith Whitwellcab974c2000-12-26 05:09:27 +000037
38
39typedef void (*trans_1f_func)(GLfloat *to,
40 CONST void *ptr,
41 GLuint stride,
Gareth Hughes22144ab2001-03-12 00:48:37 +000042 GLuint start,
Keith Whitwellcab974c2000-12-26 05:09:27 +000043 GLuint n );
44
45typedef void (*trans_1ui_func)(GLuint *to,
46 CONST void *ptr,
47 GLuint stride,
Gareth Hughes22144ab2001-03-12 00:48:37 +000048 GLuint start,
Keith Whitwellcab974c2000-12-26 05:09:27 +000049 GLuint n );
50
51typedef void (*trans_1ub_func)(GLubyte *to,
52 CONST void *ptr,
53 GLuint stride,
54 GLuint start,
55 GLuint n );
56
57typedef void (*trans_4ub_func)(GLubyte (*to)[4],
Brian Paul74b493a2001-01-24 00:04:58 +000058 CONST void *ptr,
59 GLuint stride,
60 GLuint start,
61 GLuint n );
62
63typedef void (*trans_4us_func)(GLushort (*to)[4],
64 CONST void *ptr,
65 GLuint stride,
66 GLuint start,
67 GLuint n );
Keith Whitwellcab974c2000-12-26 05:09:27 +000068
69typedef void (*trans_4f_func)(GLfloat (*to)[4],
70 CONST void *ptr,
71 GLuint stride,
Gareth Hughes22144ab2001-03-12 00:48:37 +000072 GLuint start,
Keith Whitwellcab974c2000-12-26 05:09:27 +000073 GLuint n );
74
Brian Paul7dfdf3a2006-06-13 17:13:15 +000075typedef void (*trans_3fn_func)(GLfloat (*to)[3],
Keith Whitwellcab974c2000-12-26 05:09:27 +000076 CONST void *ptr,
77 GLuint stride,
Gareth Hughes22144ab2001-03-12 00:48:37 +000078 GLuint start,
Keith Whitwellcab974c2000-12-26 05:09:27 +000079 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
Keith Whitwell23caf202000-11-16 21:05:34 +000088/* This macro is used on other systems, so undefine it for this module */
89
90#undef CHECK
91
Keith Whitwellcab974c2000-12-26 05:09:27 +000092static trans_1f_func _math_trans_1f_tab[MAX_TYPES];
93static trans_1ui_func _math_trans_1ui_tab[MAX_TYPES];
94static trans_1ub_func _math_trans_1ub_tab[MAX_TYPES];
Brian Paul7dfdf3a2006-06-13 17:13:15 +000095static trans_3fn_func _math_trans_3fn_tab[MAX_TYPES];
Keith Whitwellcab974c2000-12-26 05:09:27 +000096static trans_4ub_func _math_trans_4ub_tab[5][MAX_TYPES];
Brian Paul74b493a2001-01-24 00:04:58 +000097static trans_4us_func _math_trans_4us_tab[5][MAX_TYPES];
Keith Whitwellcab974c2000-12-26 05:09:27 +000098static trans_4f_func _math_trans_4f_tab[5][MAX_TYPES];
Brian Paul7dfdf3a2006-06-13 17:13:15 +000099static trans_4f_func _math_trans_4fn_tab[5][MAX_TYPES];
Keith Whitwell23caf202000-11-16 21:05:34 +0000100
101
102#define PTR_ELT(ptr, elt) (((SRC *)ptr)[elt])
103
104
Keith Whitwellcab974c2000-12-26 05:09:27 +0000105#define TAB(x) _math_trans##x##_tab
Keith Whitwell23caf202000-11-16 21:05:34 +0000106#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
Brian Paul0395cc02006-06-13 03:22:52 +0000117/**
118 * Translate from GL_BYTE.
Keith Whitwell23caf202000-11-16 21:05:34 +0000119 */
120#define SRC GLbyte
121#define SRC_IDX TYPE_IDX(GL_BYTE)
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000122#define TRX_3FN(f,n) BYTE_TO_FLOAT( PTR_ELT(f,n) )
Brian Paul0395cc02006-06-13 03:22:52 +0000123#if 1
Keith Whitwell5f2230c2001-05-09 14:12:34 +0000124#define TRX_4F(f,n) BYTE_TO_FLOAT( PTR_ELT(f,n) )
Brian Paul0395cc02006-06-13 03:22:52 +0000125#else
126#define TRX_4F(f,n) (GLfloat)( PTR_ELT(f,n) )
127#endif
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000128#define TRX_4FN(f,n) BYTE_TO_FLOAT( PTR_ELT(f,n) )
Keith Whitwell23caf202000-11-16 21:05:34 +0000129#define TRX_UB(ub, f,n) ub = BYTE_TO_UBYTE( PTR_ELT(f,n) )
Brian Paul74b493a2001-01-24 00:04:58 +0000130#define TRX_US(ch, f,n) ch = BYTE_TO_USHORT( PTR_ELT(f,n) )
Keith Whitwell23caf202000-11-16 21:05:34 +0000131#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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000137#define DEST_4FN trans_4_GLbyte_4fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000138#define DEST_4UB trans_4_GLbyte_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000139#define DEST_4US trans_4_GLbyte_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000140#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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000145#define DEST_4FN trans_3_GLbyte_4fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000146#define DEST_4UB trans_3_GLbyte_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000147#define DEST_4US trans_3_GLbyte_4us_raw
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000148#define DEST_3FN trans_3_GLbyte_3fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000149#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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000154#define DEST_4FN trans_2_GLbyte_4fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000155#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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000160#define DEST_4FN trans_1_GLbyte_4fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000161#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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000166#undef TRX_3FN
Keith Whitwell23caf202000-11-16 21:05:34 +0000167#undef TRX_4F
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000168#undef TRX_4FN
Keith Whitwell23caf202000-11-16 21:05:34 +0000169#undef TRX_UB
Brian Paul74b493a2001-01-24 00:04:58 +0000170#undef TRX_US
Keith Whitwell23caf202000-11-16 21:05:34 +0000171#undef TRX_UI
172#undef SRC_IDX
173
Brian Paul74b493a2001-01-24 00:04:58 +0000174
Brian Paul0395cc02006-06-13 03:22:52 +0000175/**
176 * Translate from GL_UNSIGNED_BYTE.
Keith Whitwell23caf202000-11-16 21:05:34 +0000177 */
178#define SRC GLubyte
179#define SRC_IDX TYPE_IDX(GL_UNSIGNED_BYTE)
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000180#define TRX_3FN(f,n) UBYTE_TO_FLOAT(PTR_ELT(f,n))
Brian Paul0395cc02006-06-13 03:22:52 +0000181#define TRX_4F(f,n) (GLfloat)( PTR_ELT(f,n) )
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000182#define TRX_4FN(f,n) UBYTE_TO_FLOAT(PTR_ELT(f,n))
Keith Whitwell23caf202000-11-16 21:05:34 +0000183#define TRX_UB(ub, f,n) ub = PTR_ELT(f,n)
Brian Paul74b493a2001-01-24 00:04:58 +0000184#define TRX_US(us, f,n) us = UBYTE_TO_USHORT(PTR_ELT(f,n))
Keith Whitwell23caf202000-11-16 21:05:34 +0000185#define TRX_UI(f,n) (GLuint)PTR_ELT(f,n)
186
187/* 4ub->4ub handled in special case below.
188 */
Keith Whitwell51c0c712001-04-28 08:39:17 +0000189#define SZ 4
190#define INIT init_trans_4_GLubyte_raw
191#define DEST_4F trans_4_GLubyte_4f_raw
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000192#define DEST_4FN trans_4_GLubyte_4fn_raw
Keith Whitwell51c0c712001-04-28 08:39:17 +0000193#define DEST_4US trans_4_GLubyte_4us_raw
194#include "m_trans_tmp.h"
195
Keith Whitwell23caf202000-11-16 21:05:34 +0000196
197#define SZ 3
198#define INIT init_trans_3_GLubyte_raw
199#define DEST_4UB trans_3_GLubyte_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000200#define DEST_4US trans_3_GLubyte_4us_raw
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000201#define DEST_3FN trans_3_GLubyte_3fn_raw
Keith Whitwell51c0c712001-04-28 08:39:17 +0000202#define DEST_4F trans_3_GLubyte_4f_raw
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000203#define DEST_4FN trans_3_GLubyte_4fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000204#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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000215#undef TRX_3FN
Keith Whitwell23caf202000-11-16 21:05:34 +0000216#undef TRX_4F
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000217#undef TRX_4FN
Keith Whitwell23caf202000-11-16 21:05:34 +0000218#undef TRX_UB
Brian Paul74b493a2001-01-24 00:04:58 +0000219#undef TRX_US
Keith Whitwell23caf202000-11-16 21:05:34 +0000220#undef TRX_UI
221
222
223/* GL_SHORT
224 */
225#define SRC GLshort
226#define SRC_IDX TYPE_IDX(GL_SHORT)
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000227#define TRX_3FN(f,n) SHORT_TO_FLOAT( PTR_ELT(f,n) )
Keith Whitwell23caf202000-11-16 21:05:34 +0000228#define TRX_4F(f,n) (GLfloat)( PTR_ELT(f,n) )
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000229#define TRX_4FN(f,n) SHORT_TO_FLOAT( PTR_ELT(f,n) )
Keith Whitwell23caf202000-11-16 21:05:34 +0000230#define TRX_UB(ub, f,n) ub = SHORT_TO_UBYTE(PTR_ELT(f,n))
Brian Paul74b493a2001-01-24 00:04:58 +0000231#define TRX_US(us, f,n) us = SHORT_TO_USHORT(PTR_ELT(f,n))
Keith Whitwell23caf202000-11-16 21:05:34 +0000232#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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000238#define DEST_4FN trans_4_GLshort_4fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000239#define DEST_4UB trans_4_GLshort_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000240#define DEST_4US trans_4_GLshort_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000241#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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000246#define DEST_4FN trans_3_GLshort_4fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000247#define DEST_4UB trans_3_GLshort_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000248#define DEST_4US trans_3_GLshort_4us_raw
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000249#define DEST_3FN trans_3_GLshort_3fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000250#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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000255#define DEST_4FN trans_2_GLshort_4fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000256#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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000261#define DEST_4FN trans_1_GLshort_4fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000262#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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000269#undef TRX_3FN
Keith Whitwell23caf202000-11-16 21:05:34 +0000270#undef TRX_4F
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000271#undef TRX_4FN
Keith Whitwell23caf202000-11-16 21:05:34 +0000272#undef TRX_UB
Brian Paul74b493a2001-01-24 00:04:58 +0000273#undef TRX_US
Keith Whitwell23caf202000-11-16 21:05:34 +0000274#undef TRX_UI
275
276
277/* GL_UNSIGNED_SHORT
278 */
279#define SRC GLushort
280#define SRC_IDX TYPE_IDX(GL_UNSIGNED_SHORT)
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000281#define TRX_3FN(f,n) USHORT_TO_FLOAT( PTR_ELT(f,n) )
Keith Whitwell23caf202000-11-16 21:05:34 +0000282#define TRX_4F(f,n) (GLfloat)( PTR_ELT(f,n) )
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000283#define TRX_4FN(f,n) USHORT_TO_FLOAT( PTR_ELT(f,n) )
Keith Whitwell23caf202000-11-16 21:05:34 +0000284#define TRX_UB(ub,f,n) ub = (GLubyte) (PTR_ELT(f,n) >> 8)
Brian Paul0395cc02006-06-13 03:22:52 +0000285#define TRX_US(us,f,n) us = PTR_ELT(f,n)
Keith Whitwell23caf202000-11-16 21:05:34 +0000286#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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000292#define DEST_4FN trans_4_GLushort_4fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000293#define DEST_4UB trans_4_GLushort_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000294#define DEST_4US trans_4_GLushort_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000295#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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000300#define DEST_4FN trans_3_GLushort_4fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000301#define DEST_4UB trans_3_GLushort_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000302#define DEST_4US trans_3_GLushort_4us_raw
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000303#define DEST_3FN trans_3_GLushort_3fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000304#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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000309#define DEST_4FN trans_2_GLushort_4fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000310#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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000315#define DEST_4FN trans_1_GLushort_4fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000316#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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000322#undef TRX_3FN
Keith Whitwell23caf202000-11-16 21:05:34 +0000323#undef TRX_4F
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000324#undef TRX_4FN
Keith Whitwell23caf202000-11-16 21:05:34 +0000325#undef TRX_UB
Brian Paul74b493a2001-01-24 00:04:58 +0000326#undef TRX_US
Keith Whitwell23caf202000-11-16 21:05:34 +0000327#undef TRX_UI
328
329
330/* GL_INT
331 */
332#define SRC GLint
333#define SRC_IDX TYPE_IDX(GL_INT)
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000334#define TRX_3FN(f,n) INT_TO_FLOAT( PTR_ELT(f,n) )
Keith Whitwell23caf202000-11-16 21:05:34 +0000335#define TRX_4F(f,n) (GLfloat)( PTR_ELT(f,n) )
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000336#define TRX_4FN(f,n) INT_TO_FLOAT( PTR_ELT(f,n) )
Keith Whitwell23caf202000-11-16 21:05:34 +0000337#define TRX_UB(ub, f,n) ub = INT_TO_UBYTE(PTR_ELT(f,n))
Brian Paul74b493a2001-01-24 00:04:58 +0000338#define TRX_US(us, f,n) us = INT_TO_USHORT(PTR_ELT(f,n))
Keith Whitwell23caf202000-11-16 21:05:34 +0000339#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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000345#define DEST_4FN trans_4_GLint_4fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000346#define DEST_4UB trans_4_GLint_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000347#define DEST_4US trans_4_GLint_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000348#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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000353#define DEST_4FN trans_3_GLint_4fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000354#define DEST_4UB trans_3_GLint_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000355#define DEST_4US trans_3_GLint_4us_raw
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000356#define DEST_3FN trans_3_GLint_3fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000357#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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000362#define DEST_4FN trans_2_GLint_4fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000363#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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000368#define DEST_4FN trans_1_GLint_4fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000369#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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000376#undef TRX_3FN
Keith Whitwell23caf202000-11-16 21:05:34 +0000377#undef TRX_4F
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000378#undef TRX_4FN
Keith Whitwell23caf202000-11-16 21:05:34 +0000379#undef TRX_UB
Brian Paul74b493a2001-01-24 00:04:58 +0000380#undef TRX_US
Keith Whitwell23caf202000-11-16 21:05:34 +0000381#undef TRX_UI
382
383
384/* GL_UNSIGNED_INT
385 */
386#define SRC GLuint
387#define SRC_IDX TYPE_IDX(GL_UNSIGNED_INT)
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000388#define TRX_3FN(f,n) INT_TO_FLOAT( PTR_ELT(f,n) )
Keith Whitwell23caf202000-11-16 21:05:34 +0000389#define TRX_4F(f,n) (GLfloat)( PTR_ELT(f,n) )
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000390#define TRX_4FN(f,n) UINT_TO_FLOAT( PTR_ELT(f,n) )
Keith Whitwell23caf202000-11-16 21:05:34 +0000391#define TRX_UB(ub, f,n) ub = (GLubyte) (PTR_ELT(f,n) >> 24)
Brian Paul74b493a2001-01-24 00:04:58 +0000392#define TRX_US(us, f,n) us = (GLshort) (PTR_ELT(f,n) >> 16)
Keith Whitwell23caf202000-11-16 21:05:34 +0000393#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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000399#define DEST_4FN trans_4_GLuint_4fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000400#define DEST_4UB trans_4_GLuint_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000401#define DEST_4US trans_4_GLuint_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000402#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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000407#define DEST_4FN trans_3_GLuint_4fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000408#define DEST_4UB trans_3_GLuint_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000409#define DEST_4US trans_3_GLuint_4us_raw
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000410#define DEST_3FN trans_3_GLuint_3fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000411#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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000416#define DEST_4FN trans_2_GLuint_4fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000417#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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000422#define DEST_4FN trans_1_GLuint_4fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000423#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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000429#undef TRX_3FN
Keith Whitwell23caf202000-11-16 21:05:34 +0000430#undef TRX_4F
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000431#undef TRX_4FN
Keith Whitwell23caf202000-11-16 21:05:34 +0000432#undef TRX_UB
Brian Paul74b493a2001-01-24 00:04:58 +0000433#undef TRX_US
Keith Whitwell23caf202000-11-16 21:05:34 +0000434#undef TRX_UI
435
436
437/* GL_DOUBLE
438 */
439#define SRC GLdouble
440#define SRC_IDX TYPE_IDX(GL_DOUBLE)
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000441#define TRX_3FN(f,n) (GLfloat) PTR_ELT(f,n)
Karl Schultz7b9fe822001-09-18 23:06:14 +0000442#define TRX_4F(f,n) (GLfloat) PTR_ELT(f,n)
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000443#define TRX_4FN(f,n) (GLfloat) PTR_ELT(f,n)
Brian Paul74b493a2001-01-24 00:04:58 +0000444#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))
Keith Whitwell23caf202000-11-16 21:05:34 +0000446#define TRX_UI(f,n) (GLuint) (GLint) PTR_ELT(f,n)
Karl Schultz7b9fe822001-09-18 23:06:14 +0000447#define TRX_1F(f,n) (GLfloat) PTR_ELT(f,n)
Keith Whitwell23caf202000-11-16 21:05:34 +0000448
449
450#define SZ 4
451#define INIT init_trans_4_GLdouble_raw
452#define DEST_4F trans_4_GLdouble_4f_raw
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000453#define DEST_4FN trans_4_GLdouble_4fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000454#define DEST_4UB trans_4_GLdouble_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000455#define DEST_4US trans_4_GLdouble_4us_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000456#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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000461#define DEST_4FN trans_3_GLdouble_4fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000462#define DEST_4UB trans_3_GLdouble_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000463#define DEST_4US trans_3_GLdouble_4us_raw
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000464#define DEST_3FN trans_3_GLdouble_3fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000465#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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000470#define DEST_4FN trans_2_GLdouble_4fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000471#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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000476#define DEST_4FN trans_1_GLdouble_4fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000477#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
Gareth Hughes22144ab2001-03-12 00:48:37 +0000490#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
Keith Whitwell23caf202000-11-16 21:05:34 +0000493#define DEST_4F trans_4_GLfloat_4f_raw
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000494#define DEST_4FN trans_4_GLfloat_4fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000495#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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000500#define DEST_4FN trans_3_GLfloat_4fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000501#define DEST_4UB trans_3_GLfloat_4ub_raw
Brian Paul74b493a2001-01-24 00:04:58 +0000502#define DEST_4US trans_3_GLfloat_4us_raw
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000503#define DEST_3FN trans_3_GLfloat_3fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000504#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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000509#define DEST_4FN trans_2_GLfloat_4fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000510#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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000515#define DEST_4FN trans_1_GLfloat_4fn_raw
Keith Whitwell23caf202000-11-16 21:05:34 +0000516#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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000524#undef TRX_3FN
Keith Whitwell23caf202000-11-16 21:05:34 +0000525#undef TRX_4F
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000526#undef TRX_4FN
Keith Whitwell23caf202000-11-16 21:05:34 +0000527#undef TRX_UB
Brian Paul74b493a2001-01-24 00:04:58 +0000528#undef TRX_US
Keith Whitwell23caf202000-11-16 21:05:34 +0000529#undef TRX_UI
530
531
Brian Paul74b493a2001-01-24 00:04:58 +0000532static void trans_4_GLubyte_4ub_raw(GLubyte (*t)[4],
533 CONST void *Ptr,
534 GLuint stride,
535 ARGS )
Keith Whitwell23caf202000-11-16 21:05:34 +0000536{
537 const GLubyte *f = (GLubyte *) Ptr + SRC_START * stride;
538 GLuint i;
539
Karl Schultz6258b762005-05-05 21:08:07 +0000540 if (((((uintptr_t) f | (uintptr_t) stride)) & 3L) == 0L) {
Keith Whitwell23caf202000-11-16 21:05:34 +0000541 /* 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
557static void init_translate_raw(void)
558{
559 MEMSET( TAB(_1ui), 0, sizeof(TAB(_1ui)) );
560 MEMSET( TAB(_1ub), 0, sizeof(TAB(_1ub)) );
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000561 MEMSET( TAB(_3fn), 0, sizeof(TAB(_3fn)) );
Keith Whitwell23caf202000-11-16 21:05:34 +0000562 MEMSET( TAB(_4ub), 0, sizeof(TAB(_4ub)) );
Brian Paul74b493a2001-01-24 00:04:58 +0000563 MEMSET( TAB(_4us), 0, sizeof(TAB(_4us)) );
Keith Whitwell23caf202000-11-16 21:05:34 +0000564 MEMSET( TAB(_4f), 0, sizeof(TAB(_4f)) );
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000565 MEMSET( TAB(_4fn), 0, sizeof(TAB(_4fn)) );
Keith Whitwell23caf202000-11-16 21:05:34 +0000566
Keith Whitwell23caf202000-11-16 21:05:34 +0000567 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();
Keith Whitwell51c0c712001-04-28 08:39:17 +0000573 init_trans_4_GLubyte_raw();
Keith Whitwell23caf202000-11-16 21:05:34 +0000574 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();
Keith Whitwell51c0c712001-04-28 08:39:17 +0000598
599 TAB(_4ub)[4][TYPE_IDX(GL_UNSIGNED_BYTE)] = trans_4_GLubyte_4ub_raw;
Keith Whitwell23caf202000-11-16 21:05:34 +0000600}
601
602
603#undef TAB
Brian Pauld18c08f2003-05-28 15:30:53 +0000604#ifdef CLASS
Keith Whitwell23caf202000-11-16 21:05:34 +0000605#undef CLASS
Brian Pauld18c08f2003-05-28 15:30:53 +0000606#endif
Keith Whitwell23caf202000-11-16 21:05:34 +0000607#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
Keith Whitwellcab974c2000-12-26 05:09:27 +0000618void _math_init_translate( void )
Keith Whitwell23caf202000-11-16 21:05:34 +0000619{
620 init_translate_raw();
621}
Keith Whitwellcab974c2000-12-26 05:09:27 +0000622
623
Brian Paul0395cc02006-06-13 03:22:52 +0000624/**
625 * Translate vector of values to GLfloat [1].
626 */
Keith Whitwellcab974c2000-12-26 05:09:27 +0000627void _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
Brian Paul0395cc02006-06-13 03:22:52 +0000637/**
638 * Translate vector of values to GLuint [1].
639 */
Keith Whitwellcab974c2000-12-26 05:09:27 +0000640void _math_trans_1ui(GLuint *to,
641 CONST void *ptr,
642 GLuint stride,
643 GLenum type,
644 GLuint start,
645 GLuint n )
646{
Gareth Hughes22144ab2001-03-12 00:48:37 +0000647 _math_trans_1ui_tab[TYPE_IDX(type)]( to, ptr, stride, start, n );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000648}
649
Brian Paul0395cc02006-06-13 03:22:52 +0000650/**
651 * Translate vector of values to GLubyte [1].
652 */
Keith Whitwellcab974c2000-12-26 05:09:27 +0000653void _math_trans_1ub(GLubyte *to,
654 CONST void *ptr,
655 GLuint stride,
656 GLenum type,
657 GLuint start,
658 GLuint n )
659{
Gareth Hughes22144ab2001-03-12 00:48:37 +0000660 _math_trans_1ub_tab[TYPE_IDX(type)]( to, ptr, stride, start, n );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000661}
662
663
Brian Paul0395cc02006-06-13 03:22:52 +0000664/**
665 * Translate vector of values to GLubyte [4].
666 */
Keith Whitwellcab974c2000-12-26 05:09:27 +0000667void _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{
Gareth Hughes22144ab2001-03-12 00:48:37 +0000675 _math_trans_4ub_tab[size][TYPE_IDX(type)]( to, ptr, stride, start, n );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000676}
677
Brian Paul0395cc02006-06-13 03:22:52 +0000678/**
679 * Translate vector of values to GLchan [4].
680 */
Keith Whitwell4eebc902001-02-20 18:28:52 +0000681void _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
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000694 _math_trans_4fn( to, ptr, stride, type, size, start, n );
Keith Whitwell4eebc902001-02-20 18:28:52 +0000695#endif
696}
697
Brian Paul0395cc02006-06-13 03:22:52 +0000698/**
699 * Translate vector of values to GLushort [4].
700 */
Brian Paul74b493a2001-01-24 00:04:58 +0000701void _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{
Gareth Hughes22144ab2001-03-12 00:48:37 +0000709 _math_trans_4us_tab[size][TYPE_IDX(type)]( to, ptr, stride, start, n );
Brian Paul74b493a2001-01-24 00:04:58 +0000710}
711
Brian Paul0395cc02006-06-13 03:22:52 +0000712/**
713 * Translate vector of values to GLfloat [4].
714 */
Keith Whitwellcab974c2000-12-26 05:09:27 +0000715void _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{
Gareth Hughes22144ab2001-03-12 00:48:37 +0000723 _math_trans_4f_tab[size][TYPE_IDX(type)]( to, ptr, stride, start, n );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000724}
725
Brian Paul0395cc02006-06-13 03:22:52 +0000726/**
727 * Translate vector of values to GLfloat[4], normalized to [-1, 1].
728 */
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000729void _math_trans_4fn(GLfloat (*to)[4],
Keith Whitwell12c037d2003-08-20 07:21:41 +0000730 CONST void *ptr,
731 GLuint stride,
732 GLenum type,
733 GLuint size,
734 GLuint start,
735 GLuint n )
736{
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000737 _math_trans_4fn_tab[size][TYPE_IDX(type)]( to, ptr, stride, start, n );
Keith Whitwell12c037d2003-08-20 07:21:41 +0000738}
739
Brian Paul0395cc02006-06-13 03:22:52 +0000740/**
741 * Translate vector of values to GLfloat[3], normalized to [-1, 1].
742 */
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000743void _math_trans_3fn(GLfloat (*to)[3],
Keith Whitwellcab974c2000-12-26 05:09:27 +0000744 CONST void *ptr,
745 GLuint stride,
746 GLenum type,
747 GLuint start,
748 GLuint n )
749{
Brian Paul7dfdf3a2006-06-13 17:13:15 +0000750 _math_trans_3fn_tab[TYPE_IDX(type)]( to, ptr, stride, start, n );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000751}