1848b8605Smrg/*
2848b8605Smrg * Mesa 3-D graphics library
3848b8605Smrg *
4848b8605Smrg * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
5848b8605Smrg *
6848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a
7848b8605Smrg * copy of this software and associated documentation files (the "Software"),
8848b8605Smrg * to deal in the Software without restriction, including without limitation
9848b8605Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10848b8605Smrg * and/or sell copies of the Software, and to permit persons to whom the
11848b8605Smrg * Software is furnished to do so, subject to the following conditions:
12848b8605Smrg *
13848b8605Smrg * The above copyright notice and this permission notice shall be included
14848b8605Smrg * in all copies or substantial portions of the Software.
15848b8605Smrg *
16848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19848b8605Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20848b8605Smrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21848b8605Smrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22848b8605Smrg * OTHER DEALINGS IN THE SOFTWARE.
23848b8605Smrg */
24848b8605Smrg
25848b8605Smrg/**
26848b8605Smrg * \brief  Translate vectors of numbers between various types.
27848b8605Smrg * \author Keith Whitwell.
28848b8605Smrg */
29848b8605Smrg
30848b8605Smrg
31848b8605Smrg#include "main/glheader.h"
32848b8605Smrg#include "main/macros.h"
33848b8605Smrg
34848b8605Smrg#include "m_translate.h"
35848b8605Smrg
36848b8605Smrg
37848b8605Smrg
38848b8605Smrgtypedef void (*trans_1f_func)(GLfloat *to,
39848b8605Smrg			      const void *ptr,
40848b8605Smrg			      GLuint stride,
41848b8605Smrg			      GLuint start,
42848b8605Smrg			      GLuint n );
43848b8605Smrg
44848b8605Smrgtypedef void (*trans_1ui_func)(GLuint *to,
45848b8605Smrg			       const void *ptr,
46848b8605Smrg			       GLuint stride,
47848b8605Smrg			       GLuint start,
48848b8605Smrg			       GLuint n );
49848b8605Smrg
50848b8605Smrgtypedef void (*trans_1ub_func)(GLubyte *to,
51848b8605Smrg			       const void *ptr,
52848b8605Smrg			       GLuint stride,
53848b8605Smrg			       GLuint start,
54848b8605Smrg			       GLuint n );
55848b8605Smrg
56848b8605Smrgtypedef void (*trans_4ub_func)(GLubyte (*to)[4],
57848b8605Smrg                               const void *ptr,
58848b8605Smrg                               GLuint stride,
59848b8605Smrg                               GLuint start,
60848b8605Smrg                               GLuint n );
61848b8605Smrg
62848b8605Smrgtypedef void (*trans_4us_func)(GLushort (*to)[4],
63848b8605Smrg                               const void *ptr,
64848b8605Smrg                               GLuint stride,
65848b8605Smrg                               GLuint start,
66848b8605Smrg                               GLuint n );
67848b8605Smrg
68848b8605Smrgtypedef void (*trans_4f_func)(GLfloat (*to)[4],
69848b8605Smrg			      const void *ptr,
70848b8605Smrg			      GLuint stride,
71848b8605Smrg			      GLuint start,
72848b8605Smrg			      GLuint n );
73848b8605Smrg
74848b8605Smrgtypedef void (*trans_3fn_func)(GLfloat (*to)[3],
75848b8605Smrg			      const void *ptr,
76848b8605Smrg			      GLuint stride,
77848b8605Smrg			      GLuint start,
78848b8605Smrg			      GLuint n );
79848b8605Smrg
80848b8605Smrg
81848b8605Smrg
82848b8605Smrg
83848b8605Smrg#define TYPE_IDX(t) ((t) & 0xf)
84848b8605Smrg#define MAX_TYPES TYPE_IDX(GL_DOUBLE)+1      /* 0xa + 1 */
85848b8605Smrg
86848b8605Smrg
87848b8605Smrgstatic trans_1f_func  _math_trans_1f_tab[MAX_TYPES];
88848b8605Smrgstatic trans_1ui_func _math_trans_1ui_tab[MAX_TYPES];
89848b8605Smrgstatic trans_1ub_func _math_trans_1ub_tab[MAX_TYPES];
90848b8605Smrgstatic trans_3fn_func  _math_trans_3fn_tab[MAX_TYPES];
91848b8605Smrgstatic trans_4ub_func _math_trans_4ub_tab[5][MAX_TYPES];
92848b8605Smrgstatic trans_4us_func _math_trans_4us_tab[5][MAX_TYPES];
93848b8605Smrgstatic trans_4f_func  _math_trans_4f_tab[5][MAX_TYPES];
94848b8605Smrgstatic trans_4f_func  _math_trans_4fn_tab[5][MAX_TYPES];
95848b8605Smrg
96848b8605Smrg
97848b8605Smrg#define PTR_ELT(ptr, elt) (((SRC *)ptr)[elt])
98848b8605Smrg
99848b8605Smrg
100848b8605Smrg#define TAB(x) _math_trans##x##_tab
101848b8605Smrg#define ARGS   GLuint start, GLuint n
102848b8605Smrg#define SRC_START  start
103848b8605Smrg#define DST_START  0
104848b8605Smrg#define STRIDE stride
105848b8605Smrg#define NEXT_F f += stride
106848b8605Smrg#define NEXT_F2
107848b8605Smrg
108848b8605Smrg
109848b8605Smrg
110848b8605Smrg
111848b8605Smrg/**
112848b8605Smrg * Translate from GL_BYTE.
113848b8605Smrg */
114848b8605Smrg#define SRC GLbyte
115848b8605Smrg#define SRC_IDX TYPE_IDX(GL_BYTE)
116848b8605Smrg#define TRX_3FN(f,n)   BYTE_TO_FLOAT( PTR_ELT(f,n) )
117848b8605Smrg#if 1
118848b8605Smrg#define TRX_4F(f,n)   BYTE_TO_FLOAT( PTR_ELT(f,n) )
119848b8605Smrg#else
120848b8605Smrg#define TRX_4F(f,n)   (GLfloat)( PTR_ELT(f,n) )
121848b8605Smrg#endif
122848b8605Smrg#define TRX_4FN(f,n)   BYTE_TO_FLOAT( PTR_ELT(f,n) )
123848b8605Smrg#define TRX_UB(ub, f,n)  ub = BYTE_TO_UBYTE( PTR_ELT(f,n) )
124848b8605Smrg#define TRX_US(ch, f,n)  ch = BYTE_TO_USHORT( PTR_ELT(f,n) )
125848b8605Smrg#define TRX_UI(f,n)  (PTR_ELT(f,n) < 0 ? 0 : (GLuint)  PTR_ELT(f,n))
126848b8605Smrg
127848b8605Smrg
128848b8605Smrg#define SZ 4
129848b8605Smrg#define INIT init_trans_4_GLbyte_raw
130848b8605Smrg#define DEST_4F trans_4_GLbyte_4f_raw
131848b8605Smrg#define DEST_4FN trans_4_GLbyte_4fn_raw
132848b8605Smrg#define DEST_4UB trans_4_GLbyte_4ub_raw
133848b8605Smrg#define DEST_4US trans_4_GLbyte_4us_raw
134848b8605Smrg#include "m_trans_tmp.h"
135848b8605Smrg
136848b8605Smrg#define SZ 3
137848b8605Smrg#define INIT init_trans_3_GLbyte_raw
138848b8605Smrg#define DEST_4F trans_3_GLbyte_4f_raw
139848b8605Smrg#define DEST_4FN trans_3_GLbyte_4fn_raw
140848b8605Smrg#define DEST_4UB trans_3_GLbyte_4ub_raw
141848b8605Smrg#define DEST_4US trans_3_GLbyte_4us_raw
142848b8605Smrg#define DEST_3FN trans_3_GLbyte_3fn_raw
143848b8605Smrg#include "m_trans_tmp.h"
144848b8605Smrg
145848b8605Smrg#define SZ 2
146848b8605Smrg#define INIT init_trans_2_GLbyte_raw
147848b8605Smrg#define DEST_4F trans_2_GLbyte_4f_raw
148848b8605Smrg#define DEST_4FN trans_2_GLbyte_4fn_raw
149848b8605Smrg#include "m_trans_tmp.h"
150848b8605Smrg
151848b8605Smrg#define SZ 1
152848b8605Smrg#define INIT init_trans_1_GLbyte_raw
153848b8605Smrg#define DEST_4F trans_1_GLbyte_4f_raw
154848b8605Smrg#define DEST_4FN trans_1_GLbyte_4fn_raw
155848b8605Smrg#define DEST_1UB trans_1_GLbyte_1ub_raw
156848b8605Smrg#define DEST_1UI trans_1_GLbyte_1ui_raw
157848b8605Smrg#include "m_trans_tmp.h"
158848b8605Smrg
159848b8605Smrg#undef SRC
160848b8605Smrg#undef TRX_3FN
161848b8605Smrg#undef TRX_4F
162848b8605Smrg#undef TRX_4FN
163848b8605Smrg#undef TRX_UB
164848b8605Smrg#undef TRX_US
165848b8605Smrg#undef TRX_UI
166848b8605Smrg#undef SRC_IDX
167848b8605Smrg
168848b8605Smrg
169848b8605Smrg/**
170848b8605Smrg * Translate from GL_UNSIGNED_BYTE.
171848b8605Smrg */
172848b8605Smrg#define SRC GLubyte
173848b8605Smrg#define SRC_IDX TYPE_IDX(GL_UNSIGNED_BYTE)
174848b8605Smrg#define TRX_3FN(f,n)	     UBYTE_TO_FLOAT(PTR_ELT(f,n))
175848b8605Smrg#define TRX_4F(f,n)	     (GLfloat)( PTR_ELT(f,n) )
176848b8605Smrg#define TRX_4FN(f,n)	     UBYTE_TO_FLOAT(PTR_ELT(f,n))
177848b8605Smrg#define TRX_UB(ub, f,n)	     ub = PTR_ELT(f,n)
178848b8605Smrg#define TRX_US(us, f,n)      us = UBYTE_TO_USHORT(PTR_ELT(f,n))
179848b8605Smrg#define TRX_UI(f,n)          (GLuint)PTR_ELT(f,n)
180848b8605Smrg
181848b8605Smrg/* 4ub->4ub handled in special case below.
182848b8605Smrg */
183848b8605Smrg#define SZ 4
184848b8605Smrg#define INIT init_trans_4_GLubyte_raw
185848b8605Smrg#define DEST_4F trans_4_GLubyte_4f_raw
186848b8605Smrg#define DEST_4FN trans_4_GLubyte_4fn_raw
187848b8605Smrg#define DEST_4US trans_4_GLubyte_4us_raw
188848b8605Smrg#include "m_trans_tmp.h"
189848b8605Smrg
190848b8605Smrg
191848b8605Smrg#define SZ 3
192848b8605Smrg#define INIT init_trans_3_GLubyte_raw
193848b8605Smrg#define DEST_4UB trans_3_GLubyte_4ub_raw
194848b8605Smrg#define DEST_4US trans_3_GLubyte_4us_raw
195848b8605Smrg#define DEST_3FN trans_3_GLubyte_3fn_raw
196848b8605Smrg#define DEST_4F trans_3_GLubyte_4f_raw
197848b8605Smrg#define DEST_4FN trans_3_GLubyte_4fn_raw
198848b8605Smrg#include "m_trans_tmp.h"
199848b8605Smrg
200848b8605Smrg
201848b8605Smrg#define SZ 1
202848b8605Smrg#define INIT init_trans_1_GLubyte_raw
203848b8605Smrg#define DEST_1UI trans_1_GLubyte_1ui_raw
204848b8605Smrg#define DEST_1UB trans_1_GLubyte_1ub_raw
205848b8605Smrg#include "m_trans_tmp.h"
206848b8605Smrg
207848b8605Smrg#undef SRC
208848b8605Smrg#undef SRC_IDX
209848b8605Smrg#undef TRX_3FN
210848b8605Smrg#undef TRX_4F
211848b8605Smrg#undef TRX_4FN
212848b8605Smrg#undef TRX_UB
213848b8605Smrg#undef TRX_US
214848b8605Smrg#undef TRX_UI
215848b8605Smrg
216848b8605Smrg
217848b8605Smrg/* GL_SHORT
218848b8605Smrg */
219848b8605Smrg#define SRC GLshort
220848b8605Smrg#define SRC_IDX TYPE_IDX(GL_SHORT)
221848b8605Smrg#define TRX_3FN(f,n)   SHORT_TO_FLOAT( PTR_ELT(f,n) )
222848b8605Smrg#define TRX_4F(f,n)   (GLfloat)( PTR_ELT(f,n) )
223848b8605Smrg#define TRX_4FN(f,n)  SHORT_TO_FLOAT( PTR_ELT(f,n) )
224848b8605Smrg#define TRX_UB(ub, f,n)  ub = SHORT_TO_UBYTE(PTR_ELT(f,n))
225848b8605Smrg#define TRX_US(us, f,n)  us = SHORT_TO_USHORT(PTR_ELT(f,n))
226848b8605Smrg#define TRX_UI(f,n)  (PTR_ELT(f,n) < 0 ? 0 : (GLuint)  PTR_ELT(f,n))
227848b8605Smrg
228848b8605Smrg
229848b8605Smrg#define SZ  4
230848b8605Smrg#define INIT init_trans_4_GLshort_raw
231848b8605Smrg#define DEST_4F trans_4_GLshort_4f_raw
232848b8605Smrg#define DEST_4FN trans_4_GLshort_4fn_raw
233848b8605Smrg#define DEST_4UB trans_4_GLshort_4ub_raw
234848b8605Smrg#define DEST_4US trans_4_GLshort_4us_raw
235848b8605Smrg#include "m_trans_tmp.h"
236848b8605Smrg
237848b8605Smrg#define SZ 3
238848b8605Smrg#define INIT init_trans_3_GLshort_raw
239848b8605Smrg#define DEST_4F trans_3_GLshort_4f_raw
240848b8605Smrg#define DEST_4FN trans_3_GLshort_4fn_raw
241848b8605Smrg#define DEST_4UB trans_3_GLshort_4ub_raw
242848b8605Smrg#define DEST_4US trans_3_GLshort_4us_raw
243848b8605Smrg#define DEST_3FN trans_3_GLshort_3fn_raw
244848b8605Smrg#include "m_trans_tmp.h"
245848b8605Smrg
246848b8605Smrg#define SZ 2
247848b8605Smrg#define INIT init_trans_2_GLshort_raw
248848b8605Smrg#define DEST_4F trans_2_GLshort_4f_raw
249848b8605Smrg#define DEST_4FN trans_2_GLshort_4fn_raw
250848b8605Smrg#include "m_trans_tmp.h"
251848b8605Smrg
252848b8605Smrg#define SZ 1
253848b8605Smrg#define INIT init_trans_1_GLshort_raw
254848b8605Smrg#define DEST_4F trans_1_GLshort_4f_raw
255848b8605Smrg#define DEST_4FN trans_1_GLshort_4fn_raw
256848b8605Smrg#define DEST_1UB trans_1_GLshort_1ub_raw
257848b8605Smrg#define DEST_1UI trans_1_GLshort_1ui_raw
258848b8605Smrg#include "m_trans_tmp.h"
259848b8605Smrg
260848b8605Smrg
261848b8605Smrg#undef SRC
262848b8605Smrg#undef SRC_IDX
263848b8605Smrg#undef TRX_3FN
264848b8605Smrg#undef TRX_4F
265848b8605Smrg#undef TRX_4FN
266848b8605Smrg#undef TRX_UB
267848b8605Smrg#undef TRX_US
268848b8605Smrg#undef TRX_UI
269848b8605Smrg
270848b8605Smrg
271848b8605Smrg/* GL_UNSIGNED_SHORT
272848b8605Smrg */
273848b8605Smrg#define SRC GLushort
274848b8605Smrg#define SRC_IDX TYPE_IDX(GL_UNSIGNED_SHORT)
275848b8605Smrg#define TRX_3FN(f,n)   USHORT_TO_FLOAT( PTR_ELT(f,n) )
276848b8605Smrg#define TRX_4F(f,n)   (GLfloat)( PTR_ELT(f,n) )
277848b8605Smrg#define TRX_4FN(f,n)  USHORT_TO_FLOAT( PTR_ELT(f,n) )
278848b8605Smrg#define TRX_UB(ub,f,n)  ub = (GLubyte) (PTR_ELT(f,n) >> 8)
279848b8605Smrg#define TRX_US(us,f,n)  us = PTR_ELT(f,n)
280848b8605Smrg#define TRX_UI(f,n)  (GLuint)   PTR_ELT(f,n)
281848b8605Smrg
282848b8605Smrg
283848b8605Smrg#define SZ 4
284848b8605Smrg#define INIT init_trans_4_GLushort_raw
285848b8605Smrg#define DEST_4F trans_4_GLushort_4f_raw
286848b8605Smrg#define DEST_4FN trans_4_GLushort_4fn_raw
287848b8605Smrg#define DEST_4UB trans_4_GLushort_4ub_raw
288848b8605Smrg#define DEST_4US trans_4_GLushort_4us_raw
289848b8605Smrg#include "m_trans_tmp.h"
290848b8605Smrg
291848b8605Smrg#define SZ 3
292848b8605Smrg#define INIT init_trans_3_GLushort_raw
293848b8605Smrg#define DEST_4F trans_3_GLushort_4f_raw
294848b8605Smrg#define DEST_4FN trans_3_GLushort_4fn_raw
295848b8605Smrg#define DEST_4UB trans_3_GLushort_4ub_raw
296848b8605Smrg#define DEST_4US trans_3_GLushort_4us_raw
297848b8605Smrg#define DEST_3FN trans_3_GLushort_3fn_raw
298848b8605Smrg#include "m_trans_tmp.h"
299848b8605Smrg
300848b8605Smrg#define SZ 2
301848b8605Smrg#define INIT init_trans_2_GLushort_raw
302848b8605Smrg#define DEST_4F trans_2_GLushort_4f_raw
303848b8605Smrg#define DEST_4FN trans_2_GLushort_4fn_raw
304848b8605Smrg#include "m_trans_tmp.h"
305848b8605Smrg
306848b8605Smrg#define SZ 1
307848b8605Smrg#define INIT init_trans_1_GLushort_raw
308848b8605Smrg#define DEST_4F trans_1_GLushort_4f_raw
309848b8605Smrg#define DEST_4FN trans_1_GLushort_4fn_raw
310848b8605Smrg#define DEST_1UB trans_1_GLushort_1ub_raw
311848b8605Smrg#define DEST_1UI trans_1_GLushort_1ui_raw
312848b8605Smrg#include "m_trans_tmp.h"
313848b8605Smrg
314848b8605Smrg#undef SRC
315848b8605Smrg#undef SRC_IDX
316848b8605Smrg#undef TRX_3FN
317848b8605Smrg#undef TRX_4F
318848b8605Smrg#undef TRX_4FN
319848b8605Smrg#undef TRX_UB
320848b8605Smrg#undef TRX_US
321848b8605Smrg#undef TRX_UI
322848b8605Smrg
323848b8605Smrg
324848b8605Smrg/* GL_INT
325848b8605Smrg */
326848b8605Smrg#define SRC GLint
327848b8605Smrg#define SRC_IDX TYPE_IDX(GL_INT)
328848b8605Smrg#define TRX_3FN(f,n)   INT_TO_FLOAT( PTR_ELT(f,n) )
329848b8605Smrg#define TRX_4F(f,n)   (GLfloat)( PTR_ELT(f,n) )
330848b8605Smrg#define TRX_4FN(f,n)  INT_TO_FLOAT( PTR_ELT(f,n) )
331848b8605Smrg#define TRX_UB(ub, f,n)  ub = INT_TO_UBYTE(PTR_ELT(f,n))
332848b8605Smrg#define TRX_US(us, f,n)  us = INT_TO_USHORT(PTR_ELT(f,n))
333848b8605Smrg#define TRX_UI(f,n)  (PTR_ELT(f,n) < 0 ? 0 : (GLuint)  PTR_ELT(f,n))
334848b8605Smrg
335848b8605Smrg
336848b8605Smrg#define SZ 4
337848b8605Smrg#define INIT init_trans_4_GLint_raw
338848b8605Smrg#define DEST_4F trans_4_GLint_4f_raw
339848b8605Smrg#define DEST_4FN trans_4_GLint_4fn_raw
340848b8605Smrg#define DEST_4UB trans_4_GLint_4ub_raw
341848b8605Smrg#define DEST_4US trans_4_GLint_4us_raw
342848b8605Smrg#include "m_trans_tmp.h"
343848b8605Smrg
344848b8605Smrg#define SZ 3
345848b8605Smrg#define INIT init_trans_3_GLint_raw
346848b8605Smrg#define DEST_4F trans_3_GLint_4f_raw
347848b8605Smrg#define DEST_4FN trans_3_GLint_4fn_raw
348848b8605Smrg#define DEST_4UB trans_3_GLint_4ub_raw
349848b8605Smrg#define DEST_4US trans_3_GLint_4us_raw
350848b8605Smrg#define DEST_3FN trans_3_GLint_3fn_raw
351848b8605Smrg#include "m_trans_tmp.h"
352848b8605Smrg
353848b8605Smrg#define SZ 2
354848b8605Smrg#define INIT init_trans_2_GLint_raw
355848b8605Smrg#define DEST_4F trans_2_GLint_4f_raw
356848b8605Smrg#define DEST_4FN trans_2_GLint_4fn_raw
357848b8605Smrg#include "m_trans_tmp.h"
358848b8605Smrg
359848b8605Smrg#define SZ 1
360848b8605Smrg#define INIT init_trans_1_GLint_raw
361848b8605Smrg#define DEST_4F trans_1_GLint_4f_raw
362848b8605Smrg#define DEST_4FN trans_1_GLint_4fn_raw
363848b8605Smrg#define DEST_1UB trans_1_GLint_1ub_raw
364848b8605Smrg#define DEST_1UI trans_1_GLint_1ui_raw
365848b8605Smrg#include "m_trans_tmp.h"
366848b8605Smrg
367848b8605Smrg
368848b8605Smrg#undef SRC
369848b8605Smrg#undef SRC_IDX
370848b8605Smrg#undef TRX_3FN
371848b8605Smrg#undef TRX_4F
372848b8605Smrg#undef TRX_4FN
373848b8605Smrg#undef TRX_UB
374848b8605Smrg#undef TRX_US
375848b8605Smrg#undef TRX_UI
376848b8605Smrg
377848b8605Smrg
378848b8605Smrg/* GL_UNSIGNED_INT
379848b8605Smrg */
380848b8605Smrg#define SRC GLuint
381848b8605Smrg#define SRC_IDX TYPE_IDX(GL_UNSIGNED_INT)
382848b8605Smrg#define TRX_3FN(f,n)   INT_TO_FLOAT( PTR_ELT(f,n) )
383848b8605Smrg#define TRX_4F(f,n)   (GLfloat)( PTR_ELT(f,n) )
384848b8605Smrg#define TRX_4FN(f,n)  UINT_TO_FLOAT( PTR_ELT(f,n) )
385848b8605Smrg#define TRX_UB(ub, f,n)  ub = (GLubyte) (PTR_ELT(f,n) >> 24)
386848b8605Smrg#define TRX_US(us, f,n)  us = (GLshort) (PTR_ELT(f,n) >> 16)
387848b8605Smrg#define TRX_UI(f,n)		PTR_ELT(f,n)
388848b8605Smrg
389848b8605Smrg
390848b8605Smrg#define SZ 4
391848b8605Smrg#define INIT init_trans_4_GLuint_raw
392848b8605Smrg#define DEST_4F trans_4_GLuint_4f_raw
393848b8605Smrg#define DEST_4FN trans_4_GLuint_4fn_raw
394848b8605Smrg#define DEST_4UB trans_4_GLuint_4ub_raw
395848b8605Smrg#define DEST_4US trans_4_GLuint_4us_raw
396848b8605Smrg#include "m_trans_tmp.h"
397848b8605Smrg
398848b8605Smrg#define SZ 3
399848b8605Smrg#define INIT init_trans_3_GLuint_raw
400848b8605Smrg#define DEST_4F trans_3_GLuint_4f_raw
401848b8605Smrg#define DEST_4FN trans_3_GLuint_4fn_raw
402848b8605Smrg#define DEST_4UB trans_3_GLuint_4ub_raw
403848b8605Smrg#define DEST_4US trans_3_GLuint_4us_raw
404848b8605Smrg#define DEST_3FN trans_3_GLuint_3fn_raw
405848b8605Smrg#include "m_trans_tmp.h"
406848b8605Smrg
407848b8605Smrg#define SZ 2
408848b8605Smrg#define INIT init_trans_2_GLuint_raw
409848b8605Smrg#define DEST_4F trans_2_GLuint_4f_raw
410848b8605Smrg#define DEST_4FN trans_2_GLuint_4fn_raw
411848b8605Smrg#include "m_trans_tmp.h"
412848b8605Smrg
413848b8605Smrg#define SZ 1
414848b8605Smrg#define INIT init_trans_1_GLuint_raw
415848b8605Smrg#define DEST_4F trans_1_GLuint_4f_raw
416848b8605Smrg#define DEST_4FN trans_1_GLuint_4fn_raw
417848b8605Smrg#define DEST_1UB trans_1_GLuint_1ub_raw
418848b8605Smrg#define DEST_1UI trans_1_GLuint_1ui_raw
419848b8605Smrg#include "m_trans_tmp.h"
420848b8605Smrg
421848b8605Smrg#undef SRC
422848b8605Smrg#undef SRC_IDX
423848b8605Smrg#undef TRX_3FN
424848b8605Smrg#undef TRX_4F
425848b8605Smrg#undef TRX_4FN
426848b8605Smrg#undef TRX_UB
427848b8605Smrg#undef TRX_US
428848b8605Smrg#undef TRX_UI
429848b8605Smrg
430848b8605Smrg
431848b8605Smrg/* GL_DOUBLE
432848b8605Smrg */
433848b8605Smrg#define SRC GLdouble
434848b8605Smrg#define SRC_IDX TYPE_IDX(GL_DOUBLE)
435848b8605Smrg#define TRX_3FN(f,n)   (GLfloat) PTR_ELT(f,n)
436848b8605Smrg#define TRX_4F(f,n)   (GLfloat) PTR_ELT(f,n)
437848b8605Smrg#define TRX_4FN(f,n)   (GLfloat) PTR_ELT(f,n)
438848b8605Smrg#define TRX_UB(ub,f,n) UNCLAMPED_FLOAT_TO_UBYTE(ub, PTR_ELT(f,n))
439848b8605Smrg#define TRX_US(us,f,n) UNCLAMPED_FLOAT_TO_USHORT(us, PTR_ELT(f,n))
440848b8605Smrg#define TRX_UI(f,n)  (GLuint) (GLint) PTR_ELT(f,n)
441848b8605Smrg#define TRX_1F(f,n)   (GLfloat) PTR_ELT(f,n)
442848b8605Smrg
443848b8605Smrg
444848b8605Smrg#define SZ 4
445848b8605Smrg#define INIT init_trans_4_GLdouble_raw
446848b8605Smrg#define DEST_4F trans_4_GLdouble_4f_raw
447848b8605Smrg#define DEST_4FN trans_4_GLdouble_4fn_raw
448848b8605Smrg#define DEST_4UB trans_4_GLdouble_4ub_raw
449848b8605Smrg#define DEST_4US trans_4_GLdouble_4us_raw
450848b8605Smrg#include "m_trans_tmp.h"
451848b8605Smrg
452848b8605Smrg#define SZ 3
453848b8605Smrg#define INIT init_trans_3_GLdouble_raw
454848b8605Smrg#define DEST_4F trans_3_GLdouble_4f_raw
455848b8605Smrg#define DEST_4FN trans_3_GLdouble_4fn_raw
456848b8605Smrg#define DEST_4UB trans_3_GLdouble_4ub_raw
457848b8605Smrg#define DEST_4US trans_3_GLdouble_4us_raw
458848b8605Smrg#define DEST_3FN trans_3_GLdouble_3fn_raw
459848b8605Smrg#include "m_trans_tmp.h"
460848b8605Smrg
461848b8605Smrg#define SZ 2
462848b8605Smrg#define INIT init_trans_2_GLdouble_raw
463848b8605Smrg#define DEST_4F trans_2_GLdouble_4f_raw
464848b8605Smrg#define DEST_4FN trans_2_GLdouble_4fn_raw
465848b8605Smrg#include "m_trans_tmp.h"
466848b8605Smrg
467848b8605Smrg#define SZ 1
468848b8605Smrg#define INIT init_trans_1_GLdouble_raw
469848b8605Smrg#define DEST_4F trans_1_GLdouble_4f_raw
470848b8605Smrg#define DEST_4FN trans_1_GLdouble_4fn_raw
471848b8605Smrg#define DEST_1UB trans_1_GLdouble_1ub_raw
472848b8605Smrg#define DEST_1UI trans_1_GLdouble_1ui_raw
473848b8605Smrg#define DEST_1F trans_1_GLdouble_1f_raw
474848b8605Smrg#include "m_trans_tmp.h"
475848b8605Smrg
476848b8605Smrg#undef SRC
477848b8605Smrg#undef SRC_IDX
478848b8605Smrg
479848b8605Smrg/* GL_FLOAT
480848b8605Smrg */
481848b8605Smrg#define SRC GLfloat
482848b8605Smrg#define SRC_IDX TYPE_IDX(GL_FLOAT)
483848b8605Smrg#define SZ 4
484848b8605Smrg#define INIT init_trans_4_GLfloat_raw
485848b8605Smrg#define DEST_4UB trans_4_GLfloat_4ub_raw
486848b8605Smrg#define DEST_4US trans_4_GLfloat_4us_raw
487848b8605Smrg#define DEST_4F  trans_4_GLfloat_4f_raw
488848b8605Smrg#define DEST_4FN  trans_4_GLfloat_4fn_raw
489848b8605Smrg#include "m_trans_tmp.h"
490848b8605Smrg
491848b8605Smrg#define SZ 3
492848b8605Smrg#define INIT init_trans_3_GLfloat_raw
493848b8605Smrg#define DEST_4F  trans_3_GLfloat_4f_raw
494848b8605Smrg#define DEST_4FN  trans_3_GLfloat_4fn_raw
495848b8605Smrg#define DEST_4UB trans_3_GLfloat_4ub_raw
496848b8605Smrg#define DEST_4US trans_3_GLfloat_4us_raw
497848b8605Smrg#define DEST_3FN trans_3_GLfloat_3fn_raw
498848b8605Smrg#include "m_trans_tmp.h"
499848b8605Smrg
500848b8605Smrg#define SZ 2
501848b8605Smrg#define INIT init_trans_2_GLfloat_raw
502848b8605Smrg#define DEST_4F trans_2_GLfloat_4f_raw
503848b8605Smrg#define DEST_4FN trans_2_GLfloat_4fn_raw
504848b8605Smrg#include "m_trans_tmp.h"
505848b8605Smrg
506848b8605Smrg#define SZ 1
507848b8605Smrg#define INIT init_trans_1_GLfloat_raw
508848b8605Smrg#define DEST_4F  trans_1_GLfloat_4f_raw
509848b8605Smrg#define DEST_4FN  trans_1_GLfloat_4fn_raw
510848b8605Smrg#define DEST_1UB trans_1_GLfloat_1ub_raw
511848b8605Smrg#define DEST_1UI trans_1_GLfloat_1ui_raw
512848b8605Smrg#define DEST_1F trans_1_GLfloat_1f_raw
513848b8605Smrg
514848b8605Smrg#include "m_trans_tmp.h"
515848b8605Smrg
516848b8605Smrg#undef SRC
517848b8605Smrg#undef SRC_IDX
518848b8605Smrg#undef TRX_3FN
519848b8605Smrg#undef TRX_4F
520848b8605Smrg#undef TRX_4FN
521848b8605Smrg#undef TRX_UB
522848b8605Smrg#undef TRX_US
523848b8605Smrg#undef TRX_UI
524848b8605Smrg
525848b8605Smrg
526848b8605Smrgstatic void trans_4_GLubyte_4ub_raw(GLubyte (*t)[4],
527848b8605Smrg				    const void *Ptr,
528848b8605Smrg				    GLuint stride,
529848b8605Smrg				    ARGS )
530848b8605Smrg{
531848b8605Smrg   const GLubyte *f = (GLubyte *) Ptr + SRC_START * stride;
532848b8605Smrg   GLuint i;
533848b8605Smrg
534848b8605Smrg   if (((((uintptr_t) f | (uintptr_t) stride)) & 3L) == 0L) {
535848b8605Smrg      /* Aligned.
536848b8605Smrg       */
537848b8605Smrg      for (i = DST_START ; i < n ; i++, f += stride) {
538848b8605Smrg	 COPY_4UBV( t[i], f );
539848b8605Smrg      }
540848b8605Smrg   } else {
541848b8605Smrg      for (i = DST_START ; i < n ; i++, f += stride) {
542848b8605Smrg	 t[i][0] = f[0];
543848b8605Smrg	 t[i][1] = f[1];
544848b8605Smrg	 t[i][2] = f[2];
545848b8605Smrg	 t[i][3] = f[3];
546848b8605Smrg      }
547848b8605Smrg   }
548848b8605Smrg}
549848b8605Smrg
550848b8605Smrg
551848b8605Smrgstatic void init_translate_raw(void)
552848b8605Smrg{
553848b8605Smrg   memset( TAB(_1ui), 0, sizeof(TAB(_1ui)) );
554848b8605Smrg   memset( TAB(_1ub), 0, sizeof(TAB(_1ub)) );
555848b8605Smrg   memset( TAB(_3fn),  0, sizeof(TAB(_3fn)) );
556848b8605Smrg   memset( TAB(_4ub), 0, sizeof(TAB(_4ub)) );
557848b8605Smrg   memset( TAB(_4us), 0, sizeof(TAB(_4us)) );
558848b8605Smrg   memset( TAB(_4f),  0, sizeof(TAB(_4f)) );
559848b8605Smrg   memset( TAB(_4fn),  0, sizeof(TAB(_4fn)) );
560848b8605Smrg
561848b8605Smrg   init_trans_4_GLbyte_raw();
562848b8605Smrg   init_trans_3_GLbyte_raw();
563848b8605Smrg   init_trans_2_GLbyte_raw();
564848b8605Smrg   init_trans_1_GLbyte_raw();
565848b8605Smrg   init_trans_1_GLubyte_raw();
566848b8605Smrg   init_trans_3_GLubyte_raw();
567848b8605Smrg   init_trans_4_GLubyte_raw();
568848b8605Smrg   init_trans_4_GLshort_raw();
569848b8605Smrg   init_trans_3_GLshort_raw();
570848b8605Smrg   init_trans_2_GLshort_raw();
571848b8605Smrg   init_trans_1_GLshort_raw();
572848b8605Smrg   init_trans_4_GLushort_raw();
573848b8605Smrg   init_trans_3_GLushort_raw();
574848b8605Smrg   init_trans_2_GLushort_raw();
575848b8605Smrg   init_trans_1_GLushort_raw();
576848b8605Smrg   init_trans_4_GLint_raw();
577848b8605Smrg   init_trans_3_GLint_raw();
578848b8605Smrg   init_trans_2_GLint_raw();
579848b8605Smrg   init_trans_1_GLint_raw();
580848b8605Smrg   init_trans_4_GLuint_raw();
581848b8605Smrg   init_trans_3_GLuint_raw();
582848b8605Smrg   init_trans_2_GLuint_raw();
583848b8605Smrg   init_trans_1_GLuint_raw();
584848b8605Smrg   init_trans_4_GLdouble_raw();
585848b8605Smrg   init_trans_3_GLdouble_raw();
586848b8605Smrg   init_trans_2_GLdouble_raw();
587848b8605Smrg   init_trans_1_GLdouble_raw();
588848b8605Smrg   init_trans_4_GLfloat_raw();
589848b8605Smrg   init_trans_3_GLfloat_raw();
590848b8605Smrg   init_trans_2_GLfloat_raw();
591848b8605Smrg   init_trans_1_GLfloat_raw();
592848b8605Smrg
593848b8605Smrg   TAB(_4ub)[4][TYPE_IDX(GL_UNSIGNED_BYTE)] = trans_4_GLubyte_4ub_raw;
594848b8605Smrg}
595848b8605Smrg
596848b8605Smrg
597848b8605Smrg#undef TAB
598848b8605Smrg#ifdef CLASS
599848b8605Smrg#undef CLASS
600848b8605Smrg#endif
601848b8605Smrg#undef ARGS
602848b8605Smrg#undef SRC_START
603848b8605Smrg#undef DST_START
604848b8605Smrg#undef NEXT_F
605848b8605Smrg#undef NEXT_F2
606848b8605Smrg
607848b8605Smrg
608848b8605Smrg
609848b8605Smrg
610848b8605Smrg
611848b8605Smrgvoid _math_init_translate( void )
612848b8605Smrg{
613848b8605Smrg   init_translate_raw();
614848b8605Smrg}
615848b8605Smrg
616848b8605Smrg
617848b8605Smrg/**
618848b8605Smrg * Translate vector of values to GLfloat [1].
619848b8605Smrg */
620848b8605Smrgvoid _math_trans_1f(GLfloat *to,
621848b8605Smrg		    const void *ptr,
622848b8605Smrg		    GLuint stride,
623848b8605Smrg		    GLenum type,
624848b8605Smrg		    GLuint start,
625848b8605Smrg		    GLuint n )
626848b8605Smrg{
627848b8605Smrg   _math_trans_1f_tab[TYPE_IDX(type)]( to, ptr, stride, start, n );
628848b8605Smrg}
629848b8605Smrg
630848b8605Smrg/**
631848b8605Smrg * Translate vector of values to GLuint [1].
632848b8605Smrg */
633848b8605Smrgvoid _math_trans_1ui(GLuint *to,
634848b8605Smrg		     const void *ptr,
635848b8605Smrg		     GLuint stride,
636848b8605Smrg		     GLenum type,
637848b8605Smrg		     GLuint start,
638848b8605Smrg		     GLuint n )
639848b8605Smrg{
640848b8605Smrg   _math_trans_1ui_tab[TYPE_IDX(type)]( to, ptr, stride, start, n );
641848b8605Smrg}
642848b8605Smrg
643848b8605Smrg/**
644848b8605Smrg * Translate vector of values to GLubyte [1].
645848b8605Smrg */
646848b8605Smrgvoid _math_trans_1ub(GLubyte *to,
647848b8605Smrg		     const void *ptr,
648848b8605Smrg		     GLuint stride,
649848b8605Smrg		     GLenum type,
650848b8605Smrg		     GLuint start,
651848b8605Smrg		     GLuint n )
652848b8605Smrg{
653848b8605Smrg   _math_trans_1ub_tab[TYPE_IDX(type)]( to, ptr, stride, start, n );
654848b8605Smrg}
655848b8605Smrg
656848b8605Smrg
657848b8605Smrg/**
658848b8605Smrg * Translate vector of values to GLubyte [4].
659848b8605Smrg */
660848b8605Smrgvoid _math_trans_4ub(GLubyte (*to)[4],
661848b8605Smrg		     const void *ptr,
662848b8605Smrg		     GLuint stride,
663848b8605Smrg		     GLenum type,
664848b8605Smrg		     GLuint size,
665848b8605Smrg		     GLuint start,
666848b8605Smrg		     GLuint n )
667848b8605Smrg{
668848b8605Smrg   _math_trans_4ub_tab[size][TYPE_IDX(type)]( to, ptr, stride, start, n );
669848b8605Smrg}
670848b8605Smrg
671848b8605Smrg/**
672848b8605Smrg * Translate vector of values to GLushort [4].
673848b8605Smrg */
674848b8605Smrgvoid _math_trans_4us(GLushort (*to)[4],
675848b8605Smrg		     const void *ptr,
676848b8605Smrg		     GLuint stride,
677848b8605Smrg		     GLenum type,
678848b8605Smrg		     GLuint size,
679848b8605Smrg		     GLuint start,
680848b8605Smrg		     GLuint n )
681848b8605Smrg{
682848b8605Smrg   _math_trans_4us_tab[size][TYPE_IDX(type)]( to, ptr, stride, start, n );
683848b8605Smrg}
684848b8605Smrg
685848b8605Smrg/**
686848b8605Smrg * Translate vector of values to GLfloat [4].
687848b8605Smrg */
688848b8605Smrgvoid _math_trans_4f(GLfloat (*to)[4],
689848b8605Smrg		    const void *ptr,
690848b8605Smrg		    GLuint stride,
691848b8605Smrg		    GLenum type,
692848b8605Smrg		    GLuint size,
693848b8605Smrg		    GLuint start,
694848b8605Smrg		    GLuint n )
695848b8605Smrg{
696848b8605Smrg   _math_trans_4f_tab[size][TYPE_IDX(type)]( to, ptr, stride, start, n );
697848b8605Smrg}
698848b8605Smrg
699848b8605Smrg/**
700848b8605Smrg * Translate vector of values to GLfloat[4], normalized to [-1, 1].
701848b8605Smrg */
702848b8605Smrgvoid _math_trans_4fn(GLfloat (*to)[4],
703848b8605Smrg		    const void *ptr,
704848b8605Smrg		    GLuint stride,
705848b8605Smrg		    GLenum type,
706848b8605Smrg		    GLuint size,
707848b8605Smrg		    GLuint start,
708848b8605Smrg		    GLuint n )
709848b8605Smrg{
710848b8605Smrg   _math_trans_4fn_tab[size][TYPE_IDX(type)]( to, ptr, stride, start, n );
711848b8605Smrg}
712848b8605Smrg
713848b8605Smrg/**
714848b8605Smrg * Translate vector of values to GLfloat[3], normalized to [-1, 1].
715848b8605Smrg */
716848b8605Smrgvoid _math_trans_3fn(GLfloat (*to)[3],
717848b8605Smrg		    const void *ptr,
718848b8605Smrg		    GLuint stride,
719848b8605Smrg		    GLenum type,
720848b8605Smrg		    GLuint start,
721848b8605Smrg		    GLuint n )
722848b8605Smrg{
723848b8605Smrg   _math_trans_3fn_tab[TYPE_IDX(type)]( to, ptr, stride, start, n );
724848b8605Smrg}
725