home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / System / Mesa-3.1 / src / translate.c < prev    next >
C/C++ Source or Header  |  2000-01-07  |  22KB  |  900 lines

  1. /* $Id: translate.c,v 1.2 1999/10/19 18:37:04 keithw Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  3.1
  6.  * 
  7.  * Copyright (C) 1999  Brian Paul   All Rights Reserved.
  8.  * 
  9.  * 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:
  15.  * 
  16.  * The above copyright notice and this permission notice shall be included
  17.  * in all copies or substantial portions of the Software.
  18.  * 
  19.  * 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 "types.h"
  33. #include "translate.h"
  34. #include "mmath.h"
  35.  
  36. trans_1ui_func gl_trans_1ui_tab[MAX_TYPES];
  37. trans_1ub_func gl_trans_1ub_tab[MAX_TYPES];
  38. trans_3f_func  gl_trans_3f_tab[MAX_TYPES];
  39. trans_4ub_func gl_trans_4ub_tab[5][MAX_TYPES];
  40. trans_4f_func  gl_trans_4f_tab[5][MAX_TYPES];
  41.  
  42. trans_elt_1ui_func gl_trans_elt_1ui_tab[MAX_TYPES];
  43. trans_elt_1ub_func gl_trans_elt_1ub_tab[MAX_TYPES];
  44. trans_elt_3f_func  gl_trans_elt_3f_tab[MAX_TYPES];
  45. trans_elt_4ub_func gl_trans_elt_4ub_tab[5][MAX_TYPES];
  46. trans_elt_4f_func  gl_trans_elt_4f_tab[5][MAX_TYPES];
  47.  
  48.  
  49. #define PTR_ELT(ptr, elt) (((SRC *)ptr)[elt])
  50.  
  51.  
  52. #define TAB(x) gl_trans_##x##_tab
  53. #define ARGS   GLuint start, GLuint n
  54. #define SRC_START  start
  55. #define DST_START  0
  56. #define STRIDE stride
  57. #define NEXT_F f += stride
  58. #define NEXT_F2
  59. #define CHECK
  60.  
  61.  
  62.  
  63.  
  64. /* GL_BYTE
  65.  */
  66. #define SRC GLbyte
  67. #define SRC_IDX TYPE_IDX(GL_BYTE)
  68. #define TRX_3F(f,n)   BYTE_TO_FLOAT( PTR_ELT(f,n) )
  69. #define TRX_4F(f,n)   (GLfloat)( PTR_ELT(f,n) )
  70. #define TRX_UB(ub, f,n)  ub = BYTE_TO_UBYTE( PTR_ELT(f,n) )
  71. #define TRX_UI(f,n)  (PTR_ELT(f,n) < 0 ? 0 : (GLuint)  PTR_ELT(f,n))
  72.  
  73.  
  74. #define SZ 4
  75. #define INIT init_trans_4_GLbyte_raw
  76. #define DEST_4F trans_4_GLbyte_4f_raw
  77. #define DEST_4UB trans_4_GLbyte_4ub_raw
  78. #include "trans_tmp.h"
  79.  
  80. #define SZ 3
  81. #define INIT init_trans_3_GLbyte_raw
  82. #define DEST_4F trans_3_GLbyte_4f_raw
  83. #define DEST_4UB trans_3_GLbyte_4ub_raw
  84. #define DEST_3F trans_3_GLbyte_3f_raw
  85. #include "trans_tmp.h"
  86.  
  87. #define SZ 2
  88. #define INIT init_trans_2_GLbyte_raw
  89. #define DEST_4F trans_2_GLbyte_4f_raw
  90. #include "trans_tmp.h"
  91.  
  92. #define SZ 1
  93. #define INIT init_trans_1_GLbyte_raw
  94. #define DEST_4F trans_1_GLbyte_4f_raw
  95. #define DEST_1UB trans_1_GLbyte_1ub_raw
  96. #define DEST_1UI trans_1_GLbyte_1ui_raw
  97. #include "trans_tmp.h"
  98.  
  99. #undef SRC
  100. #undef TRX_3F
  101. #undef TRX_4F
  102. #undef TRX_UB
  103. #undef TRX_UI
  104. #undef SRC_IDX
  105.  
  106. /* GL_UNSIGNED_BYTE
  107.  */
  108. #define SRC GLubyte
  109. #define SRC_IDX TYPE_IDX(GL_UNSIGNED_BYTE)
  110. #define TRX_3F(f,n)        /* unused */
  111. #define TRX_4F(f,n)        /* unused */
  112. #define TRX_UB(ub, f,n)         ub = PTR_ELT(f,n)
  113. #define TRX_UI(f,n)          (GLuint)PTR_ELT(f,n)
  114.  
  115. /* 4ub->4ub handled in special case below.
  116.  */
  117.  
  118. #define SZ 3
  119. #define INIT init_trans_3_GLubyte_raw
  120. #define DEST_4UB trans_3_GLubyte_4ub_raw
  121. #include "trans_tmp.h"
  122.  
  123.  
  124. #define SZ 1
  125. #define INIT init_trans_1_GLubyte_raw
  126. #define DEST_1UI trans_1_GLubyte_1ui_raw
  127. #define DEST_1UB trans_1_GLubyte_1ub_raw
  128. #include "trans_tmp.h"
  129.  
  130. #undef SRC
  131. #undef SRC_IDX
  132. #undef TRX_3F
  133. #undef TRX_4F
  134. #undef TRX_UB
  135. #undef TRX_UI
  136.  
  137.  
  138. /* GL_SHORT
  139.  */
  140. #define SRC GLshort
  141. #define SRC_IDX TYPE_IDX(GL_SHORT)
  142. #define TRX_3F(f,n)   SHORT_TO_FLOAT( PTR_ELT(f,n) )
  143. #define TRX_4F(f,n)   (GLfloat)( PTR_ELT(f,n) )
  144. #define TRX_UB(ub, f,n)  ub = SHORT_TO_UBYTE(PTR_ELT(f,n))
  145. #define TRX_UI(f,n)  (PTR_ELT(f,n) < 0 ? 0 : (GLuint)  PTR_ELT(f,n))
  146.  
  147.  
  148. #define SZ  4
  149. #define INIT init_trans_4_GLshort_raw
  150. #define DEST_4F trans_4_GLshort_4f_raw
  151. #define DEST_4UB trans_4_GLshort_4ub_raw
  152. #include "trans_tmp.h"
  153.  
  154. #define SZ 3
  155. #define INIT init_trans_3_GLshort_raw
  156. #define DEST_4F trans_3_GLshort_4f_raw
  157. #define DEST_4UB trans_3_GLshort_4ub_raw
  158. #define DEST_3F trans_3_GLshort_3f_raw
  159. #include "trans_tmp.h"
  160.  
  161. #define SZ 2
  162. #define INIT init_trans_2_GLshort_raw
  163. #define DEST_4F trans_2_GLshort_4f_raw
  164. #include "trans_tmp.h"
  165.  
  166. #define SZ 1
  167. #define INIT init_trans_1_GLshort_raw
  168. #define DEST_4F trans_1_GLshort_4f_raw
  169. #define DEST_1UB trans_1_GLshort_1ub_raw
  170. #define DEST_1UI trans_1_GLshort_1ui_raw
  171. #include "trans_tmp.h"
  172.  
  173.  
  174. #undef SRC
  175. #undef SRC_IDX
  176. #undef TRX_3F
  177. #undef TRX_4F
  178. #undef TRX_UB
  179. #undef TRX_UI
  180.  
  181.  
  182. /* GL_UNSIGNED_SHORT
  183.  */
  184. #define SRC GLushort
  185. #define SRC_IDX TYPE_IDX(GL_UNSIGNED_SHORT)
  186. #define TRX_3F(f,n)   USHORT_TO_FLOAT( PTR_ELT(f,n) )
  187. #define TRX_4F(f,n)   (GLfloat)( PTR_ELT(f,n) )
  188. #define TRX_UB(ub,f,n)  ub = (GLubyte) (PTR_ELT(f,n) >> 8)
  189. #define TRX_UI(f,n)  (GLuint)   PTR_ELT(f,n)
  190.  
  191.  
  192. #define SZ 4
  193. #define INIT init_trans_4_GLushort_raw
  194. #define DEST_4F trans_4_GLushort_4f_raw
  195. #define DEST_4UB trans_4_GLushort_4ub_raw
  196. #include "trans_tmp.h"
  197.  
  198. #define SZ 3
  199. #define INIT init_trans_3_GLushort_raw
  200. #define DEST_4F trans_3_GLushort_4f_raw
  201. #define DEST_4UB trans_3_GLushort_4ub_raw
  202. #define DEST_3F trans_3_GLushort_3f_raw
  203. #include "trans_tmp.h"
  204.  
  205. #define SZ 2
  206. #define INIT init_trans_2_GLushort_raw
  207. #define DEST_4F trans_2_GLushort_4f_raw
  208. #include "trans_tmp.h"
  209.  
  210. #define SZ 1
  211. #define INIT init_trans_1_GLushort_raw
  212. #define DEST_4F trans_1_GLushort_4f_raw
  213. #define DEST_1UB trans_1_GLushort_1ub_raw
  214. #define DEST_1UI trans_1_GLushort_1ui_raw
  215. #include "trans_tmp.h"
  216.  
  217. #undef SRC
  218. #undef SRC_IDX
  219. #undef TRX_3F
  220. #undef TRX_4F
  221. #undef TRX_UB
  222. #undef TRX_UI
  223.  
  224.  
  225. /* GL_INT
  226.  */
  227. #define SRC GLint
  228. #define SRC_IDX TYPE_IDX(GL_INT)
  229. #define TRX_3F(f,n)   INT_TO_FLOAT( PTR_ELT(f,n) )
  230. #define TRX_4F(f,n)   (GLfloat)( PTR_ELT(f,n) )
  231. #define TRX_UB(ub, f,n)  ub = INT_TO_UBYTE(PTR_ELT(f,n))
  232. #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_GLint_raw
  237. #define DEST_4F trans_4_GLint_4f_raw
  238. #define DEST_4UB trans_4_GLint_4ub_raw
  239. #include "trans_tmp.h"
  240.  
  241. #define SZ 3
  242. #define INIT init_trans_3_GLint_raw
  243. #define DEST_4F trans_3_GLint_4f_raw
  244. #define DEST_4UB trans_3_GLint_4ub_raw
  245. #define DEST_3F trans_3_GLint_3f_raw
  246. #include "trans_tmp.h"
  247.  
  248. #define SZ 2
  249. #define INIT init_trans_2_GLint_raw
  250. #define DEST_4F trans_2_GLint_4f_raw
  251. #include "trans_tmp.h"
  252.  
  253. #define SZ 1
  254. #define INIT init_trans_1_GLint_raw
  255. #define DEST_4F trans_1_GLint_4f_raw
  256. #define DEST_1UB trans_1_GLint_1ub_raw
  257. #define DEST_1UI trans_1_GLint_1ui_raw
  258. #include "trans_tmp.h"
  259.  
  260.  
  261. #undef SRC
  262. #undef SRC_IDX
  263. #undef TRX_3F
  264. #undef TRX_4F
  265. #undef TRX_UB
  266. #undef TRX_UI
  267.  
  268.  
  269. /* GL_UNSIGNED_INT
  270.  */
  271. #define SRC GLuint
  272. #define SRC_IDX TYPE_IDX(GL_UNSIGNED_INT)
  273. #define TRX_3F(f,n)   INT_TO_FLOAT( PTR_ELT(f,n) )
  274. #define TRX_4F(f,n)   (GLfloat)( PTR_ELT(f,n) )
  275. #define TRX_UB(ub, f,n)  ub = (GLubyte) (PTR_ELT(f,n) >> 24)
  276. #define TRX_UI(f,n)        PTR_ELT(f,n)
  277.  
  278.  
  279. #define SZ 4
  280. #define INIT init_trans_4_GLuint_raw
  281. #define DEST_4F trans_4_GLuint_4f_raw
  282. #define DEST_4UB trans_4_GLuint_4ub_raw
  283. #include "trans_tmp.h"
  284.  
  285. #define SZ 3
  286. #define INIT init_trans_3_GLuint_raw
  287. #define DEST_4F trans_3_GLuint_4f_raw
  288. #define DEST_4UB trans_3_GLuint_4ub_raw
  289. #define DEST_3F trans_3_GLuint_3f_raw
  290. #include "trans_tmp.h"
  291.  
  292. #define SZ 2
  293. #define INIT init_trans_2_GLuint_raw
  294. #define DEST_4F trans_2_GLuint_4f_raw
  295. #include "trans_tmp.h"
  296.  
  297. #define SZ 1
  298. #define INIT init_trans_1_GLuint_raw
  299. #define DEST_4F trans_1_GLuint_4f_raw
  300. #define DEST_1UB trans_1_GLuint_1ub_raw
  301. #define DEST_1UI trans_1_GLuint_1ui_raw
  302. #include "trans_tmp.h"
  303.  
  304. #undef SRC
  305. #undef SRC_IDX
  306. #undef TRX_3F
  307. #undef TRX_4F
  308. #undef TRX_UB
  309. #undef TRX_UI
  310.  
  311.  
  312. /* GL_DOUBLE
  313.  */
  314. #define SRC GLdouble
  315. #define SRC_IDX TYPE_IDX(GL_DOUBLE)
  316. #define TRX_3F(f,n)   PTR_ELT(f,n)
  317. #define TRX_4F(f,n)   PTR_ELT(f,n)
  318. #define TRX_UB(ub,f,n) FLOAT_COLOR_TO_UBYTE_COLOR(ub, PTR_ELT(f,n))
  319. #define TRX_UI(f,n)  (GLuint) (GLint) PTR_ELT(f,n)
  320.  
  321.  
  322. #define SZ 4
  323. #define INIT init_trans_4_GLdouble_raw
  324. #define DEST_4F trans_4_GLdouble_4f_raw
  325. #define DEST_4UB trans_4_GLdouble_4ub_raw
  326. #include "trans_tmp.h"
  327.  
  328. #define SZ 3
  329. #define INIT init_trans_3_GLdouble_raw
  330. #define DEST_4F trans_3_GLdouble_4f_raw
  331. #define DEST_4UB trans_3_GLdouble_4ub_raw
  332. #define DEST_3F trans_3_GLdouble_3f_raw
  333. #include "trans_tmp.h"
  334.  
  335. #define SZ 2
  336. #define INIT init_trans_2_GLdouble_raw
  337. #define DEST_4F trans_2_GLdouble_4f_raw
  338. #include "trans_tmp.h"
  339.  
  340. #define SZ 1
  341. #define INIT init_trans_1_GLdouble_raw
  342. #define DEST_4F trans_1_GLdouble_4f_raw
  343. #define DEST_1UB trans_1_GLdouble_1ub_raw
  344. #define DEST_1UI trans_1_GLdouble_1ui_raw
  345. #include "trans_tmp.h"
  346.  
  347. #undef SRC
  348. #undef SRC_IDX
  349.  
  350. /* GL_FLOAT
  351.  */
  352. #define SRC GLfloat
  353. #define SRC_IDX TYPE_IDX(GL_FLOAT)
  354. #define SZ 4
  355. #define INIT init_trans_4_GLfloat_raw 
  356. #define DEST_4UB trans_4_GLfloat_4ub_raw 
  357. #define DEST_4F  trans_4_GLfloat_4f_raw
  358. #include "trans_tmp.h"
  359.  
  360. #define SZ 3
  361. #define INIT init_trans_3_GLfloat_raw
  362. #define DEST_4F  trans_3_GLfloat_4f_raw
  363. #define DEST_4UB trans_3_GLfloat_4ub_raw
  364. #define DEST_3F trans_3_GLfloat_3f_raw
  365. #include "trans_tmp.h"
  366.  
  367. #define SZ 2
  368. #define INIT init_trans_2_GLfloat_raw
  369. #define DEST_4F trans_2_GLfloat_4f_raw
  370. #include "trans_tmp.h"
  371.  
  372. #define SZ 1
  373. #define INIT init_trans_1_GLfloat_raw
  374. #define DEST_4F  trans_1_GLfloat_4f_raw
  375. #define DEST_1UB trans_1_GLfloat_1ub_raw
  376. #define DEST_1UI trans_1_GLfloat_1ui_raw
  377.  
  378. #include "trans_tmp.h"
  379.  
  380. #undef SRC
  381. #undef SRC_IDX
  382. #undef TRX_3F
  383. #undef TRX_4F
  384. #undef TRX_UB
  385. #undef TRX_UI
  386.  
  387.  
  388. static void trans_4_GLubyte_4ub_raw (GLubyte (*t)[4],
  389.                      const struct gl_client_array *from,
  390.                      ARGS )
  391. {
  392.    GLuint stride = from->StrideB;
  393.    const GLubyte *f = (GLubyte *) from->Ptr + SRC_START * stride;
  394.    GLuint i;
  395.  
  396.    if (((((long) f | (long) stride)) & 3L) == 0L) { 
  397.       /* Aligned.
  398.        */
  399.       for (i = DST_START ; i < n ; i++, f += stride) {
  400.      COPY_4UBV( t[i], f );
  401.       }
  402.    } else {
  403.       for (i = DST_START ; i < n ; i++, f += stride) {
  404.      t[i][0] = f[0];
  405.      t[i][1] = f[1];
  406.      t[i][2] = f[2];
  407.      t[i][3] = f[3];
  408.       }
  409.    }
  410. }
  411.  
  412.  
  413. static void init_translate_raw(void)
  414. {
  415.    MEMSET( TAB(1ui), 0, sizeof(TAB(1ui)) );
  416.    MEMSET( TAB(1ub), 0, sizeof(TAB(1ub)) );
  417.    MEMSET( TAB(3f),  0, sizeof(TAB(3f)) );
  418.    MEMSET( TAB(4ub), 0, sizeof(TAB(4ub)) );
  419.    MEMSET( TAB(4f),  0, sizeof(TAB(4f)) );
  420.  
  421.    TAB(4ub)[4][TYPE_IDX(GL_UNSIGNED_BYTE)] = trans_4_GLubyte_4ub_raw;
  422.  
  423.    init_trans_4_GLbyte_raw();
  424.    init_trans_3_GLbyte_raw();
  425.    init_trans_2_GLbyte_raw();
  426.    init_trans_1_GLbyte_raw();
  427.    init_trans_1_GLubyte_raw();
  428.    init_trans_3_GLubyte_raw();
  429.    init_trans_4_GLshort_raw();
  430.    init_trans_3_GLshort_raw();
  431.    init_trans_2_GLshort_raw();
  432.    init_trans_1_GLshort_raw();
  433.    init_trans_4_GLushort_raw();
  434.    init_trans_3_GLushort_raw();
  435.    init_trans_2_GLushort_raw();
  436.    init_trans_1_GLushort_raw();
  437.    init_trans_4_GLint_raw();
  438.    init_trans_3_GLint_raw();
  439.    init_trans_2_GLint_raw();
  440.    init_trans_1_GLint_raw();
  441.    init_trans_4_GLuint_raw();
  442.    init_trans_3_GLuint_raw();
  443.    init_trans_2_GLuint_raw();
  444.    init_trans_1_GLuint_raw();
  445.    init_trans_4_GLdouble_raw();
  446.    init_trans_3_GLdouble_raw();
  447.    init_trans_2_GLdouble_raw();
  448.    init_trans_1_GLdouble_raw();
  449.    init_trans_4_GLfloat_raw();
  450.    init_trans_3_GLfloat_raw();
  451.    init_trans_2_GLfloat_raw();
  452.    init_trans_1_GLfloat_raw();
  453. }
  454.  
  455.  
  456. #undef TAB
  457. #undef CLASS
  458. #undef ARGS
  459. #undef CHECK
  460. #undef SRC_START
  461. #undef DST_START
  462. #undef NEXT_F
  463. #undef NEXT_F2
  464.  
  465.  
  466. /* Code specific to array element implementation.  There is a small
  467.  * subtlety in the bits CHECK() tests, and the way bits are set in
  468.  * glArrayElement which ensures that if, eg, in the case that the
  469.  * vertex array is disabled and normal array is enabled, and we get
  470.  * either sequence:
  471.  *
  472.  * ArrayElement()    OR   Normal()
  473.  * Normal()               ArrayElement()
  474.  * Vertex()               Vertex()
  475.  *
  476.  * That the correct value for normal is used.  
  477.  */
  478. #define TAB(x) gl_trans_elt_##x##_tab
  479. #define ARGS   GLuint *flags, GLuint *elts, GLuint match, \
  480.                GLuint start, GLuint n
  481. #define SRC_START  0
  482. #define DST_START  start
  483. #define CHECK  if ((flags[i]&match) == VERT_ELT)
  484. #define NEXT_F  1
  485. #define NEXT_F2 f = first + elts[i] * stride; 
  486.  
  487.  
  488. /* GL_BYTE
  489.  */
  490. #define SRC GLbyte
  491. #define SRC_IDX TYPE_IDX(GL_BYTE)
  492. #define TRX_3F(f,n)   BYTE_TO_FLOAT( PTR_ELT(f,n) )
  493. #define TRX_4F(f,n)   (GLfloat)( PTR_ELT(f,n) )
  494. #define TRX_UB(ub, f,n)  ub = BYTE_TO_UBYTE( PTR_ELT(f,n) )
  495. #define TRX_UI(f,n)  (PTR_ELT(f,n) < 0 ? 0 : (GLuint)  PTR_ELT(f,n))
  496.  
  497.  
  498. #define SZ 4
  499. #define INIT init_trans_4_GLbyte_elt
  500. #define DEST_4F trans_4_GLbyte_4f_elt
  501. #define DEST_4UB trans_4_GLbyte_4ub_elt
  502. #include "trans_tmp.h"
  503.  
  504. #define SZ 3
  505. #define INIT init_trans_3_GLbyte_elt
  506. #define DEST_4F trans_3_GLbyte_4f_elt
  507. #define DEST_4UB trans_3_GLbyte_4ub_elt
  508. #define DEST_3F trans_3_GLbyte_3f_elt
  509. #include "trans_tmp.h"
  510.  
  511. #define SZ 2
  512. #define INIT init_trans_2_GLbyte_elt
  513. #define DEST_4F trans_2_GLbyte_4f_elt
  514. #include "trans_tmp.h"
  515.  
  516. #define SZ 1
  517. #define INIT init_trans_1_GLbyte_elt
  518. #define DEST_4F trans_1_GLbyte_4f_elt
  519. #define DEST_1UB trans_1_GLbyte_1ub_elt
  520. #define DEST_1UI trans_1_GLbyte_1ui_elt
  521. #include "trans_tmp.h"
  522.  
  523. #undef SRC
  524. #undef TRX_3F
  525. #undef TRX_4F
  526. #undef TRX_UB
  527. #undef TRX_UI
  528. #undef SRC_IDX
  529.  
  530. /* GL_UNSIGNED_BYTE
  531.  */
  532. #define SRC GLubyte
  533. #define SRC_IDX TYPE_IDX(GL_UNSIGNED_BYTE)
  534. #define TRX_3F(f,n)        /* unused */
  535. #define TRX_4F(f,n)        /* unused */
  536. #define TRX_UB(ub, f,n)         ub = PTR_ELT(f,n)
  537. #define TRX_UI(f,n)          (GLuint)PTR_ELT(f,n)
  538.  
  539. /* 4ub->4ub handled in special case below.
  540.  */
  541.  
  542. #define SZ 3
  543. #define INIT init_trans_3_GLubyte_elt
  544. #define DEST_4UB trans_3_GLubyte_4ub_elt
  545. #include "trans_tmp.h"
  546.  
  547.  
  548. #define SZ 1
  549. #define INIT init_trans_1_GLubyte_elt
  550. #define DEST_1UI trans_1_GLubyte_1ui_elt
  551. #define DEST_1UB trans_1_GLubyte_1ub_elt
  552. #include "trans_tmp.h"
  553.  
  554. #undef SRC
  555. #undef SRC_IDX
  556. #undef TRX_3F
  557. #undef TRX_4F
  558. #undef TRX_UB
  559. #undef TRX_UI
  560.  
  561.  
  562. /* GL_SHORT
  563.  */
  564. #define SRC GLshort
  565. #define SRC_IDX TYPE_IDX(GL_SHORT)
  566. #define TRX_3F(f,n)   SHORT_TO_FLOAT( PTR_ELT(f,n) )
  567. #define TRX_4F(f,n)   (GLfloat)( PTR_ELT(f,n) )
  568. #define TRX_UB(ub, f,n)  ub = SHORT_TO_UBYTE(PTR_ELT(f,n))
  569. #define TRX_UI(f,n)  (PTR_ELT(f,n) < 0 ? 0 : (GLuint)  PTR_ELT(f,n))
  570.  
  571.  
  572. #define SZ  4
  573. #define INIT init_trans_4_GLshort_elt
  574. #define DEST_4F trans_4_GLshort_4f_elt
  575. #define DEST_4UB trans_4_GLshort_4ub_elt
  576. #include "trans_tmp.h"
  577.  
  578. #define SZ 3
  579. #define INIT init_trans_3_GLshort_elt
  580. #define DEST_4F trans_3_GLshort_4f_elt
  581. #define DEST_4UB trans_3_GLshort_4ub_elt
  582. #define DEST_3F trans_3_GLshort_3f_elt
  583. #include "trans_tmp.h"
  584.  
  585. #define SZ 2
  586. #define INIT init_trans_2_GLshort_elt
  587. #define DEST_4F trans_2_GLshort_4f_elt
  588. #include "trans_tmp.h"
  589.  
  590. #define SZ 1
  591. #define INIT init_trans_1_GLshort_elt
  592. #define DEST_4F trans_1_GLshort_4f_elt
  593. #define DEST_1UB trans_1_GLshort_1ub_elt
  594. #define DEST_1UI trans_1_GLshort_1ui_elt
  595. #include "trans_tmp.h"
  596.  
  597.  
  598. #undef SRC
  599. #undef SRC_IDX
  600. #undef TRX_3F
  601. #undef TRX_4F
  602. #undef TRX_UB
  603. #undef TRX_UI
  604.  
  605.  
  606. /* GL_UNSIGNED_SHORT
  607.  */
  608. #define SRC GLushort
  609. #define SRC_IDX TYPE_IDX(GL_UNSIGNED_SHORT)
  610. #define TRX_3F(f,n)   USHORT_TO_FLOAT( PTR_ELT(f,n) )
  611. #define TRX_4F(f,n)   (GLfloat)( PTR_ELT(f,n) )
  612. #define TRX_UB(ub,f,n)  ub = (GLubyte) (PTR_ELT(f,n) >> 8)
  613. #define TRX_UI(f,n)  (GLuint)   PTR_ELT(f,n)
  614.  
  615.  
  616. #define SZ 4
  617. #define INIT init_trans_4_GLushort_elt
  618. #define DEST_4F trans_4_GLushort_4f_elt
  619. #define DEST_4UB trans_4_GLushort_4ub_elt
  620. #include "trans_tmp.h"
  621.  
  622. #define SZ 3
  623. #define INIT init_trans_3_GLushort_elt
  624. #define DEST_4F trans_3_GLushort_4f_elt
  625. #define DEST_4UB trans_3_GLushort_4ub_elt
  626. #define DEST_3F trans_3_GLushort_3f_elt
  627. #include "trans_tmp.h"
  628.  
  629. #define SZ 2
  630. #define INIT init_trans_2_GLushort_elt
  631. #define DEST_4F trans_2_GLushort_4f_elt
  632. #include "trans_tmp.h"
  633.  
  634. #define SZ 1
  635. #define INIT init_trans_1_GLushort_elt
  636. #define DEST_4F trans_1_GLushort_4f_elt
  637. #define DEST_1UB trans_1_GLushort_1ub_elt
  638. #define DEST_1UI trans_1_GLushort_1ui_elt
  639. #include "trans_tmp.h"
  640.  
  641. #undef SRC
  642. #undef SRC_IDX
  643. #undef TRX_3F
  644. #undef TRX_4F
  645. #undef TRX_UB
  646. #undef TRX_UI
  647.  
  648.  
  649. /* GL_INT
  650.  */
  651. #define SRC GLint
  652. #define SRC_IDX TYPE_IDX(GL_INT)
  653. #define TRX_3F(f,n)   INT_TO_FLOAT( PTR_ELT(f,n) )
  654. #define TRX_4F(f,n)   (GLfloat)( PTR_ELT(f,n) )
  655. #define TRX_UB(ub, f,n)  ub = INT_TO_UBYTE(PTR_ELT(f,n))
  656. #define TRX_UI(f,n)  (PTR_ELT(f,n) < 0 ? 0 : (GLuint)  PTR_ELT(f,n))
  657.  
  658.  
  659. #define SZ 4
  660. #define INIT init_trans_4_GLint_elt
  661. #define DEST_4F trans_4_GLint_4f_elt
  662. #define DEST_4UB trans_4_GLint_4ub_elt
  663. #include "trans_tmp.h"
  664.  
  665. #define SZ 3
  666. #define INIT init_trans_3_GLint_elt
  667. #define DEST_4F trans_3_GLint_4f_elt
  668. #define DEST_4UB trans_3_GLint_4ub_elt
  669. #define DEST_3F trans_3_GLint_3f_elt
  670. #include "trans_tmp.h"
  671.  
  672. #define SZ 2
  673. #define INIT init_trans_2_GLint_elt
  674. #define DEST_4F trans_2_GLint_4f_elt
  675. #include "trans_tmp.h"
  676.  
  677. #define SZ 1
  678. #define INIT init_trans_1_GLint_elt
  679. #define DEST_4F trans_1_GLint_4f_elt
  680. #define DEST_1UB trans_1_GLint_1ub_elt
  681. #define DEST_1UI trans_1_GLint_1ui_elt
  682. #include "trans_tmp.h"
  683.  
  684.  
  685. #undef SRC
  686. #undef SRC_IDX
  687. #undef TRX_3F
  688. #undef TRX_4F
  689. #undef TRX_UB
  690. #undef TRX_UI
  691.  
  692.  
  693. /* GL_UNSIGNED_INT
  694.  */
  695. #define SRC GLuint
  696. #define SRC_IDX TYPE_IDX(GL_UNSIGNED_INT)
  697. #define TRX_3F(f,n)   UINT_TO_FLOAT( PTR_ELT(f,n) )
  698. #define TRX_4F(f,n)   (GLfloat)( PTR_ELT(f,n) )
  699. #define TRX_UB(ub, f,n)  ub = (GLubyte) (PTR_ELT(f,n) >> 24)
  700. #define TRX_UI(f,n)        PTR_ELT(f,n)
  701.  
  702.  
  703. #define SZ 4
  704. #define INIT init_trans_4_GLuint_elt
  705. #define DEST_4F trans_4_GLuint_4f_elt
  706. #define DEST_4UB trans_4_GLuint_4ub_elt
  707. #include "trans_tmp.h"
  708.  
  709. #define SZ 3
  710. #define INIT init_trans_3_GLuint_elt
  711. #define DEST_4F trans_3_GLuint_4f_elt
  712. #define DEST_4UB trans_3_GLuint_4ub_elt
  713. #define DEST_3F trans_3_GLuint_3f_elt
  714. #include "trans_tmp.h"
  715.  
  716. #define SZ 2
  717. #define INIT init_trans_2_GLuint_elt
  718. #define DEST_4F trans_2_GLuint_4f_elt
  719. #include "trans_tmp.h"
  720.  
  721. #define SZ 1
  722. #define INIT init_trans_1_GLuint_elt
  723. #define DEST_4F trans_1_GLuint_4f_elt
  724. #define DEST_1UB trans_1_GLuint_1ub_elt
  725. #define DEST_1UI trans_1_GLuint_1ui_elt
  726. #include "trans_tmp.h"
  727.  
  728. #undef SRC
  729. #undef SRC_IDX
  730. #undef TRX_3F
  731. #undef TRX_4F
  732. #undef TRX_UB
  733. #undef TRX_UI
  734.  
  735.  
  736. /* GL_DOUBLE
  737.  */
  738. #define SRC GLdouble
  739. #define SRC_IDX TYPE_IDX(GL_DOUBLE)
  740. #define TRX_3F(f,n)   PTR_ELT(f,n)
  741. #define TRX_4F(f,n)   PTR_ELT(f,n)
  742. #define TRX_UB(ub,f,n) FLOAT_COLOR_TO_UBYTE_COLOR(ub, PTR_ELT(f,n))
  743. #define TRX_UI(f,n)  (GLuint) (GLint) PTR_ELT(f,n)
  744.  
  745.  
  746. #define SZ 4
  747. #define INIT init_trans_4_GLdouble_elt
  748. #define DEST_4F trans_4_GLdouble_4f_elt
  749. #define DEST_4UB trans_4_GLdouble_4ub_elt
  750. #include "trans_tmp.h"
  751.  
  752. #define SZ 3
  753. #define INIT init_trans_3_GLdouble_elt
  754. #define DEST_4F trans_3_GLdouble_4f_elt
  755. #define DEST_4UB trans_3_GLdouble_4ub_elt
  756. #define DEST_3F trans_3_GLdouble_3f_elt
  757. #include "trans_tmp.h"
  758.  
  759. #define SZ 2
  760. #define INIT init_trans_2_GLdouble_elt
  761. #define DEST_4F trans_2_GLdouble_4f_elt
  762. #include "trans_tmp.h"
  763.  
  764. #define SZ 1
  765. #define INIT init_trans_1_GLdouble_elt
  766. #define DEST_4F trans_1_GLdouble_4f_elt
  767. #define DEST_1UB trans_1_GLdouble_1ub_elt
  768. #define DEST_1UI trans_1_GLdouble_1ui_elt
  769. #include "trans_tmp.h"
  770.  
  771. #undef SRC
  772. #undef SRC_IDX
  773.  
  774. /* GL_FLOAT
  775.  */
  776. #define SRC GLfloat
  777. #define SRC_IDX TYPE_IDX(GL_FLOAT)
  778. #define SZ 4
  779. #define INIT init_trans_4_GLfloat_elt 
  780. #define DEST_4UB trans_4_GLfloat_4ub_elt 
  781. #define DEST_4F  trans_4_GLfloat_4f_elt
  782. #include "trans_tmp.h"
  783.  
  784. #define SZ 3
  785. #define INIT init_trans_3_GLfloat_elt
  786. #define DEST_4F  trans_3_GLfloat_4f_elt
  787. #define DEST_4UB trans_3_GLfloat_4ub_elt
  788. #define DEST_3F trans_3_GLfloat_3f_elt
  789. #include "trans_tmp.h"
  790.  
  791. #define SZ 2
  792. #define INIT init_trans_2_GLfloat_elt
  793. #define DEST_4F trans_2_GLfloat_4f_elt
  794. #include "trans_tmp.h"
  795.  
  796. #define SZ 1
  797. #define INIT init_trans_1_GLfloat_elt
  798. #define DEST_4F  trans_1_GLfloat_3f_elt
  799. #define DEST_1UB trans_1_GLfloat_1ub_elt
  800. #define DEST_1UI trans_1_GLfloat_1ui_elt
  801. #include "trans_tmp.h"
  802.  
  803. #undef SRC
  804. #undef SRC_IDX
  805. #undef TRX_3F
  806. #undef TRX_4F
  807. #undef TRX_UB
  808. #undef TRX_UI
  809.  
  810.  
  811. static void trans_4_GLubyte_4ub(GLubyte (*t)[4],
  812.                 const struct gl_client_array *from,
  813.                 ARGS )
  814. {
  815.    GLuint stride = from->StrideB;
  816.    const GLubyte *f = (GLubyte *) from->Ptr + SRC_START * stride;
  817.    const GLubyte *first = f;
  818.    GLuint i;
  819.    (void) start;
  820.    if (((((long) f | (long) stride)) & 3L) == 0L) { 
  821.       /* Aligned.
  822.        */
  823.       for (i = DST_START ; i < n ; i++, NEXT_F) {
  824.      CHECK {
  825.         NEXT_F2;
  826.         COPY_4UBV( t[i], f );
  827.      }
  828.       }
  829.    } else {
  830.       for (i = DST_START ; i < n ; i++, NEXT_F) {
  831.      CHECK {
  832.         NEXT_F2;
  833.         t[i][0] = f[0];
  834.         t[i][1] = f[1];
  835.         t[i][2] = f[2];
  836.         t[i][3] = f[3];
  837.      }
  838.       }
  839.    }
  840. }
  841.  
  842.  
  843. static void init_translate_elt(void)
  844. {
  845.    MEMSET( TAB(1ui), 0, sizeof(TAB(1ui)) );
  846.    MEMSET( TAB(1ub), 0, sizeof(TAB(1ub)) );
  847.    MEMSET( TAB(3f),  0, sizeof(TAB(3f)) );
  848.    MEMSET( TAB(4ub), 0, sizeof(TAB(4ub)) );
  849.    MEMSET( TAB(4f),  0, sizeof(TAB(4f)) );
  850.  
  851.    TAB(4ub)[4][TYPE_IDX(GL_UNSIGNED_BYTE)] = trans_4_GLubyte_4ub;
  852.  
  853.    init_trans_4_GLbyte_elt();
  854.    init_trans_3_GLbyte_elt();
  855.    init_trans_2_GLbyte_elt();
  856.    init_trans_1_GLbyte_elt();
  857.    init_trans_1_GLubyte_elt();
  858.    init_trans_3_GLubyte_elt();
  859.    init_trans_4_GLshort_elt();
  860.    init_trans_3_GLshort_elt();
  861.    init_trans_2_GLshort_elt();
  862.    init_trans_1_GLshort_elt();
  863.    init_trans_4_GLushort_elt();
  864.    init_trans_3_GLushort_elt();
  865.    init_trans_2_GLushort_elt();
  866.    init_trans_1_GLushort_elt();
  867.    init_trans_4_GLint_elt();
  868.    init_trans_3_GLint_elt();
  869.    init_trans_2_GLint_elt();
  870.    init_trans_1_GLint_elt();
  871.    init_trans_4_GLuint_elt();
  872.    init_trans_3_GLuint_elt();
  873.    init_trans_2_GLuint_elt();
  874.    init_trans_1_GLuint_elt();
  875.    init_trans_4_GLdouble_elt();
  876.    init_trans_3_GLdouble_elt();
  877.    init_trans_2_GLdouble_elt();
  878.    init_trans_1_GLdouble_elt();
  879.    init_trans_4_GLfloat_elt();
  880.    init_trans_3_GLfloat_elt();
  881.    init_trans_2_GLfloat_elt();
  882.    init_trans_1_GLfloat_elt();
  883. }
  884.  
  885.  
  886. #undef TAB
  887. #undef CLASS
  888. #undef ARGS
  889. #undef CHECK
  890. #undef START
  891.  
  892.  
  893.  
  894.  
  895. void gl_init_translate( void )
  896. {
  897.    init_translate_raw();
  898.    init_translate_elt();
  899. }
  900.