Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Mesa 3-D graphics library
  3.  * Version:  7.7
  4.  *
  5.  * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
  6.  * Copyright (c) 2008-2009  VMware, Inc.
  7.  *
  8.  * Permission is hereby granted, free of charge, to any person obtaining a
  9.  * copy of this software and associated documentation files (the "Software"),
  10.  * to deal in the Software without restriction, including without limitation
  11.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  12.  * and/or sell copies of the Software, and to permit persons to whom the
  13.  * Software is furnished to do so, subject to the following conditions:
  14.  *
  15.  * The above copyright notice and this permission notice shall be included
  16.  * in all copies or substantial portions of the Software.
  17.  *
  18.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  21.  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  22.  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  23.  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24.  */
  25.  
  26.  
  27. /**
  28.  * \file texfetch_tmp.h
  29.  * Texel fetch functions template.
  30.  *
  31.  * This template file is used by texfetch.c to generate texel fetch functions
  32.  * for 1-D, 2-D and 3-D texture images.
  33.  *
  34.  * It should be expanded by defining \p DIM as the number texture dimensions
  35.  * (1, 2 or 3).  According to the value of \p DIM a series of macros is defined
  36.  * for the texel lookup in the gl_texture_image::Data.
  37.  *
  38.  * \author Gareth Hughes
  39.  * \author Brian Paul
  40.  */
  41.  
  42.  
  43. #if DIM == 1
  44.  
  45. #define TEXEL_ADDR( type, image, i, j, k, size ) \
  46.         ((void) (j), (void) (k), ((type *)(image)->Data + (i) * (size)))
  47.  
  48. #define FETCH(x) fetch_texel_1d_##x
  49.  
  50. #elif DIM == 2
  51.  
  52. #define TEXEL_ADDR( type, image, i, j, k, size )                        \
  53.         ((void) (k),                                                    \
  54.          ((type *)(image)->Data + ((image)->RowStride * (j) + (i)) * (size)))
  55.  
  56. #define FETCH(x) fetch_texel_2d_##x
  57.  
  58. #elif DIM == 3
  59.  
  60. #define TEXEL_ADDR( type, image, i, j, k, size )                        \
  61.         ((type *)(image)->Data + ((image)->ImageOffsets[k]              \
  62.              + (image)->RowStride * (j) + (i)) * (size))
  63.  
  64. #define FETCH(x) fetch_texel_3d_##x
  65.  
  66. #else
  67. #error  illegal number of texture dimensions
  68. #endif
  69.  
  70.  
  71. /* MESA_FORMAT_Z32 ***********************************************************/
  72.  
  73. /* Fetch depth texel from 1D, 2D or 3D 32-bit depth texture,
  74.  * returning 1 GLfloat.
  75.  * Note: no GLchan version of this function.
  76.  */
  77. static void FETCH(f_z32)( const struct gl_texture_image *texImage,
  78.                           GLint i, GLint j, GLint k, GLfloat *texel )
  79. {
  80.    const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  81.    texel[0] = src[0] * (1.0F / 0xffffffff);
  82. }
  83.  
  84. #if DIM == 3
  85. static void store_texel_z32(struct gl_texture_image *texImage,
  86.                             GLint i, GLint j, GLint k, const void *texel)
  87. {
  88.    const GLuint *depth = (const GLuint *) texel;
  89.    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  90.    dst[0] = *depth;
  91. }
  92. #endif
  93.  
  94.  
  95. /* MESA_FORMAT_Z16 ***********************************************************/
  96.  
  97. /* Fetch depth texel from 1D, 2D or 3D 16-bit depth texture,
  98.  * returning 1 GLfloat.
  99.  * Note: no GLchan version of this function.
  100.  */
  101. static void FETCH(f_z16)(const struct gl_texture_image *texImage,
  102.                          GLint i, GLint j, GLint k, GLfloat *texel )
  103. {
  104.    const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
  105.    texel[0] = src[0] * (1.0F / 65535.0F);
  106. }
  107.  
  108. #if DIM == 3
  109. static void store_texel_z16(struct gl_texture_image *texImage,
  110.                             GLint i, GLint j, GLint k, const void *texel)
  111. {
  112.    const GLushort *depth = (const GLushort *) texel;
  113.    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
  114.    dst[0] = *depth;
  115. }
  116. #endif
  117.  
  118.  
  119. /* MESA_FORMAT_RGBA_F32 ******************************************************/
  120.  
  121. /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT32 texture, returning 4 GLfloats.
  122.  */
  123. static void FETCH(f_rgba_f32)( const struct gl_texture_image *texImage,
  124.                                GLint i, GLint j, GLint k, GLfloat *texel )
  125. {
  126.    const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 4);
  127.    texel[RCOMP] = src[0];
  128.    texel[GCOMP] = src[1];
  129.    texel[BCOMP] = src[2];
  130.    texel[ACOMP] = src[3];
  131. }
  132.  
  133. #if DIM == 3
  134. static void store_texel_rgba_f32(struct gl_texture_image *texImage,
  135.                                  GLint i, GLint j, GLint k, const void *texel)
  136. {
  137.    const GLfloat *depth = (const GLfloat *) texel;
  138.    GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 4);
  139.    dst[0] = depth[RCOMP];
  140.    dst[1] = depth[GCOMP];
  141.    dst[2] = depth[BCOMP];
  142.    dst[3] = depth[ACOMP];
  143. }
  144. #endif
  145.  
  146.  
  147. /* MESA_FORMAT_RGBA_F16 ******************************************************/
  148.  
  149. /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
  150.  * returning 4 GLfloats.
  151.  */
  152. static void FETCH(f_rgba_f16)( const struct gl_texture_image *texImage,
  153.                                GLint i, GLint j, GLint k, GLfloat *texel )
  154. {
  155.    const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 4);
  156.    texel[RCOMP] = _mesa_half_to_float(src[0]);
  157.    texel[GCOMP] = _mesa_half_to_float(src[1]);
  158.    texel[BCOMP] = _mesa_half_to_float(src[2]);
  159.    texel[ACOMP] = _mesa_half_to_float(src[3]);
  160. }
  161.  
  162. #if DIM == 3
  163. static void store_texel_rgba_f16(struct gl_texture_image *texImage,
  164.                                  GLint i, GLint j, GLint k, const void *texel)
  165. {
  166.    const GLfloat *src = (const GLfloat *) texel;
  167.    GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 4);
  168.    dst[0] = _mesa_float_to_half(src[RCOMP]);
  169.    dst[1] = _mesa_float_to_half(src[GCOMP]);
  170.    dst[2] = _mesa_float_to_half(src[BCOMP]);
  171.    dst[3] = _mesa_float_to_half(src[ACOMP]);
  172. }
  173. #endif
  174.  
  175. /* MESA_FORMAT_RGB_F32 *******************************************************/
  176.  
  177. /* Fetch texel from 1D, 2D or 3D RGB_FLOAT32 texture,
  178.  * returning 4 GLfloats.
  179.  */
  180. static void FETCH(f_rgb_f32)( const struct gl_texture_image *texImage,
  181.                               GLint i, GLint j, GLint k, GLfloat *texel )
  182. {
  183.    const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 3);
  184.    texel[RCOMP] = src[0];
  185.    texel[GCOMP] = src[1];
  186.    texel[BCOMP] = src[2];
  187.    texel[ACOMP] = 1.0F;
  188. }
  189.  
  190. #if DIM == 3
  191. static void store_texel_rgb_f32(struct gl_texture_image *texImage,
  192.                                  GLint i, GLint j, GLint k, const void *texel)
  193. {
  194.    const GLfloat *src = (const GLfloat *) texel;
  195.    GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 3);
  196.    dst[0] = src[RCOMP];
  197.    dst[1] = src[GCOMP];
  198.    dst[2] = src[BCOMP];
  199. }
  200. #endif
  201.  
  202.  
  203. /* MESA_FORMAT_RGB_F16 *******************************************************/
  204.  
  205. /* Fetch texel from 1D, 2D or 3D RGB_FLOAT16 texture,
  206.  * returning 4 GLfloats.
  207.  */
  208. static void FETCH(f_rgb_f16)( const struct gl_texture_image *texImage,
  209.                               GLint i, GLint j, GLint k, GLfloat *texel )
  210. {
  211.    const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 3);
  212.    texel[RCOMP] = _mesa_half_to_float(src[0]);
  213.    texel[GCOMP] = _mesa_half_to_float(src[1]);
  214.    texel[BCOMP] = _mesa_half_to_float(src[2]);
  215.    texel[ACOMP] = 1.0F;
  216. }
  217.  
  218. #if DIM == 3
  219. static void store_texel_rgb_f16(struct gl_texture_image *texImage,
  220.                                 GLint i, GLint j, GLint k, const void *texel)
  221. {
  222.    const GLfloat *src = (const GLfloat *) texel;
  223.    GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 3);
  224.    dst[0] = _mesa_float_to_half(src[RCOMP]);
  225.    dst[1] = _mesa_float_to_half(src[GCOMP]);
  226.    dst[2] = _mesa_float_to_half(src[BCOMP]);
  227. }
  228. #endif
  229.  
  230.  
  231. /* MESA_FORMAT_ALPHA_F32 *****************************************************/
  232.  
  233. /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT32 texture,
  234.  * returning 4 GLfloats.
  235.  */
  236. static void FETCH(f_alpha_f32)( const struct gl_texture_image *texImage,
  237.                               GLint i, GLint j, GLint k, GLfloat *texel )
  238. {
  239.    const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
  240.    texel[RCOMP] =
  241.    texel[GCOMP] =
  242.    texel[BCOMP] = 0.0F;
  243.    texel[ACOMP] = src[0];
  244. }
  245.  
  246. #if DIM == 3
  247. static void store_texel_alpha_f32(struct gl_texture_image *texImage,
  248.                                   GLint i, GLint j, GLint k, const void *texel)
  249. {
  250.    const GLfloat *rgba = (const GLfloat *) texel;
  251.    GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
  252.    dst[0] = rgba[ACOMP];
  253. }
  254. #endif
  255.  
  256.  
  257. /* MESA_FORMAT_ALPHA_F32 *****************************************************/
  258.  
  259. /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT16 texture,
  260.  * returning 4 GLfloats.
  261.  */
  262. static void FETCH(f_alpha_f16)( const struct gl_texture_image *texImage,
  263.                               GLint i, GLint j, GLint k, GLfloat *texel )
  264. {
  265.    const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
  266.    texel[RCOMP] =
  267.    texel[GCOMP] =
  268.    texel[BCOMP] = 0.0F;
  269.    texel[ACOMP] = _mesa_half_to_float(src[0]);
  270. }
  271.  
  272. #if DIM == 3
  273. static void store_texel_alpha_f16(struct gl_texture_image *texImage,
  274.                                   GLint i, GLint j, GLint k, const void *texel)
  275. {
  276.    const GLfloat *rgba = (const GLfloat *) texel;
  277.    GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
  278.    dst[0] = _mesa_float_to_half(rgba[ACOMP]);
  279. }
  280. #endif
  281.  
  282.  
  283. /* MESA_FORMAT_LUMINANCE_F32 *************************************************/
  284.  
  285. /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT32 texture,
  286.  * returning 4 GLfloats.
  287.  */
  288. static void FETCH(f_luminance_f32)( const struct gl_texture_image *texImage,
  289.                                     GLint i, GLint j, GLint k, GLfloat *texel )
  290. {
  291.    const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
  292.    texel[RCOMP] =
  293.    texel[GCOMP] =
  294.    texel[BCOMP] = src[0];
  295.    texel[ACOMP] = 1.0F;
  296. }
  297.  
  298. #if DIM == 3
  299. static void store_texel_luminance_f32(struct gl_texture_image *texImage,
  300.                                   GLint i, GLint j, GLint k, const void *texel)
  301. {
  302.    const GLfloat *rgba = (const GLfloat *) texel;
  303.    GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
  304.    dst[0] = rgba[RCOMP];
  305. }
  306. #endif
  307.  
  308.  
  309. /* MESA_FORMAT_LUMINANCE_F16 *************************************************/
  310.  
  311. /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT16 texture,
  312.  * returning 4 GLfloats.
  313.  */
  314. static void FETCH(f_luminance_f16)( const struct gl_texture_image *texImage,
  315.                                     GLint i, GLint j, GLint k, GLfloat *texel )
  316. {
  317.    const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
  318.    texel[RCOMP] =
  319.    texel[GCOMP] =
  320.    texel[BCOMP] = _mesa_half_to_float(src[0]);
  321.    texel[ACOMP] = 1.0F;
  322. }
  323.  
  324. #if DIM == 3
  325. static void store_texel_luminance_f16(struct gl_texture_image *texImage,
  326.                                   GLint i, GLint j, GLint k, const void *texel)
  327. {
  328.    const GLfloat *rgba = (const GLfloat *) texel;
  329.    GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
  330.    dst[0] = _mesa_float_to_half(rgba[RCOMP]);
  331. }
  332. #endif
  333.  
  334.  
  335. /* MESA_FORMAT_LUMINANCE_ALPHA_F32 *******************************************/
  336.  
  337. /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT32 texture,
  338.  * returning 4 GLfloats.
  339.  */
  340. static void FETCH(f_luminance_alpha_f32)( const struct gl_texture_image *texImage,
  341.                                     GLint i, GLint j, GLint k, GLfloat *texel )
  342. {
  343.    const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
  344.    texel[RCOMP] =
  345.    texel[GCOMP] =
  346.    texel[BCOMP] = src[0];
  347.    texel[ACOMP] = src[1];
  348. }
  349.  
  350. #if DIM == 3
  351. static void store_texel_luminance_alpha_f32(struct gl_texture_image *texImage,
  352.                                   GLint i, GLint j, GLint k, const void *texel)
  353. {
  354.    const GLfloat *rgba = (const GLfloat *) texel;
  355.    GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
  356.    dst[0] = rgba[RCOMP];
  357.    dst[1] = rgba[ACOMP];
  358. }
  359. #endif
  360.  
  361.  
  362. /* MESA_FORMAT_LUMINANCE_ALPHA_F16 *******************************************/
  363.  
  364. /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT16 texture,
  365.  * returning 4 GLfloats.
  366.  */
  367. static void FETCH(f_luminance_alpha_f16)( const struct gl_texture_image *texImage,
  368.                                     GLint i, GLint j, GLint k, GLfloat *texel )
  369. {
  370.    const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
  371.    texel[RCOMP] =
  372.    texel[GCOMP] =
  373.    texel[BCOMP] = _mesa_half_to_float(src[0]);
  374.    texel[ACOMP] = _mesa_half_to_float(src[1]);
  375. }
  376.  
  377. #if DIM == 3
  378. static void store_texel_luminance_alpha_f16(struct gl_texture_image *texImage,
  379.                                   GLint i, GLint j, GLint k, const void *texel)
  380. {
  381.    const GLfloat *rgba = (const GLfloat *) texel;
  382.    GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
  383.    dst[0] = _mesa_float_to_half(rgba[RCOMP]);
  384.    dst[1] = _mesa_float_to_half(rgba[ACOMP]);
  385. }
  386. #endif
  387.  
  388.  
  389. /* MESA_FORMAT_INTENSITY_F32 *************************************************/
  390.  
  391. /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT32 texture,
  392.  * returning 4 GLfloats.
  393.  */
  394. static void FETCH(f_intensity_f32)( const struct gl_texture_image *texImage,
  395.                                     GLint i, GLint j, GLint k, GLfloat *texel )
  396. {
  397.    const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
  398.    texel[RCOMP] =
  399.    texel[GCOMP] =
  400.    texel[BCOMP] =
  401.    texel[ACOMP] = src[0];
  402. }
  403.  
  404. #if DIM == 3
  405. static void store_texel_intensity_f32(struct gl_texture_image *texImage,
  406.                                   GLint i, GLint j, GLint k, const void *texel)
  407. {
  408.    const GLfloat *rgba = (const GLfloat *) texel;
  409.    GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
  410.    dst[0] = rgba[RCOMP];
  411. }
  412. #endif
  413.  
  414.  
  415. /* MESA_FORMAT_INTENSITY_F16 *************************************************/
  416.  
  417. /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT16 texture,
  418.  * returning 4 GLfloats.
  419.  */
  420. static void FETCH(f_intensity_f16)( const struct gl_texture_image *texImage,
  421.                                     GLint i, GLint j, GLint k, GLfloat *texel )
  422. {
  423.    const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
  424.    texel[RCOMP] =
  425.    texel[GCOMP] =
  426.    texel[BCOMP] =
  427.    texel[ACOMP] = _mesa_half_to_float(src[0]);
  428. }
  429.  
  430. #if DIM == 3
  431. static void store_texel_intensity_f16(struct gl_texture_image *texImage,
  432.                                   GLint i, GLint j, GLint k, const void *texel)
  433. {
  434.    const GLfloat *rgba = (const GLfloat *) texel;
  435.    GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
  436.    dst[0] = _mesa_float_to_half(rgba[RCOMP]);
  437. }
  438. #endif
  439.  
  440.  
  441.  
  442.  
  443. /*
  444.  * Begin Hardware formats
  445.  */
  446.  
  447. /* MESA_FORMAT_RGBA8888 ******************************************************/
  448.  
  449. /* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLfloats */
  450. static void FETCH(f_rgba8888)( const struct gl_texture_image *texImage,
  451.                                GLint i, GLint j, GLint k, GLfloat *texel )
  452. {
  453.    const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  454.    texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 24)        );
  455.    texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
  456.    texel[BCOMP] = UBYTE_TO_FLOAT( (s >>  8) & 0xff );
  457.    texel[ACOMP] = UBYTE_TO_FLOAT( (s      ) & 0xff );
  458. }
  459.  
  460.  
  461.  
  462. #if DIM == 3
  463. static void store_texel_rgba8888(struct gl_texture_image *texImage,
  464.                                  GLint i, GLint j, GLint k, const void *texel)
  465. {
  466.    const GLubyte *rgba = (const GLubyte *) texel;
  467.    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  468.    *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
  469. }
  470. #endif
  471.  
  472.  
  473. /* MESA_FORMAT_RGBA888_REV ***************************************************/
  474.  
  475. /* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLchans */
  476. static void FETCH(f_rgba8888_rev)( const struct gl_texture_image *texImage,
  477.                                    GLint i, GLint j, GLint k, GLfloat *texel )
  478. {
  479.    const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  480.    texel[RCOMP] = UBYTE_TO_FLOAT( (s      ) & 0xff );
  481.    texel[GCOMP] = UBYTE_TO_FLOAT( (s >>  8) & 0xff );
  482.    texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
  483.    texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24)        );
  484. }
  485.  
  486. #if DIM == 3
  487. static void store_texel_rgba8888_rev(struct gl_texture_image *texImage,
  488.                                   GLint i, GLint j, GLint k, const void *texel)
  489. {
  490.    const GLubyte *rgba = (const GLubyte *) texel;
  491.    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  492.    *dst = PACK_COLOR_8888_REV(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
  493. }
  494. #endif
  495.  
  496.  
  497. /* MESA_FORMAT_ARGB8888 ******************************************************/
  498.  
  499. /* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLchans */
  500. static void FETCH(f_argb8888)( const struct gl_texture_image *texImage,
  501.                                GLint i, GLint j, GLint k, GLfloat *texel )
  502. {
  503.    const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  504.    texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
  505.    texel[GCOMP] = UBYTE_TO_FLOAT( (s >>  8) & 0xff );
  506.    texel[BCOMP] = UBYTE_TO_FLOAT( (s      ) & 0xff );
  507.    texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24)        );
  508. }
  509.  
  510. #if DIM == 3
  511. static void store_texel_argb8888(struct gl_texture_image *texImage,
  512.                                  GLint i, GLint j, GLint k, const void *texel)
  513. {
  514.    const GLubyte *rgba = (const GLubyte *) texel;
  515.    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  516.    *dst = PACK_COLOR_8888(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
  517. }
  518. #endif
  519.  
  520.  
  521. /* MESA_FORMAT_ARGB8888_REV **************************************************/
  522.  
  523. /* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLfloats */
  524. static void FETCH(f_argb8888_rev)( const struct gl_texture_image *texImage,
  525.                                    GLint i, GLint j, GLint k, GLfloat *texel )
  526. {
  527.    const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  528.    texel[RCOMP] = UBYTE_TO_FLOAT( (s >>  8) & 0xff );
  529.    texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
  530.    texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 24)        );
  531.    texel[ACOMP] = UBYTE_TO_FLOAT( (s      ) & 0xff );
  532. }
  533.  
  534. #if DIM == 3
  535. static void store_texel_argb8888_rev(struct gl_texture_image *texImage,
  536.                                   GLint i, GLint j, GLint k, const void *texel)
  537. {
  538.    const GLubyte *rgba = (const GLubyte *) texel;
  539.    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  540.    *dst = PACK_COLOR_8888(rgba[BCOMP], rgba[GCOMP], rgba[RCOMP], rgba[ACOMP]);
  541. }
  542. #endif
  543.  
  544.  
  545. /* MESA_FORMAT_XRGB8888 ******************************************************/
  546.  
  547. /* Fetch texel from 1D, 2D or 3D xrgb8888 texture, return 4 GLchans */
  548. static void FETCH(f_xrgb8888)( const struct gl_texture_image *texImage,
  549.                                GLint i, GLint j, GLint k, GLfloat *texel )
  550. {
  551.    const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  552.    texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
  553.    texel[GCOMP] = UBYTE_TO_FLOAT( (s >>  8) & 0xff );
  554.    texel[BCOMP] = UBYTE_TO_FLOAT( (s      ) & 0xff );
  555.    texel[ACOMP] = 1.0f;
  556. }
  557.  
  558. #if DIM == 3
  559. static void store_texel_xrgb8888(struct gl_texture_image *texImage,
  560.                                  GLint i, GLint j, GLint k, const void *texel)
  561. {
  562.    const GLubyte *rgba = (const GLubyte *) texel;
  563.    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  564.    *dst = PACK_COLOR_8888(0xff, rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
  565. }
  566. #endif
  567.  
  568.  
  569. /* MESA_FORMAT_XRGB8888_REV **************************************************/
  570.  
  571. /* Fetch texel from 1D, 2D or 3D xrgb8888_rev texture, return 4 GLfloats */
  572. static void FETCH(f_xrgb8888_rev)( const struct gl_texture_image *texImage,
  573.                                    GLint i, GLint j, GLint k, GLfloat *texel )
  574. {
  575.    const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  576.    texel[RCOMP] = UBYTE_TO_FLOAT( (s >>  8) & 0xff );
  577.    texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
  578.    texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 24)        );
  579.    texel[ACOMP] = 1.0f;
  580. }
  581.  
  582. #if DIM == 3
  583. static void store_texel_xrgb8888_rev(struct gl_texture_image *texImage,
  584.                                      GLint i, GLint j, GLint k, const void *texel)
  585. {
  586.    const GLubyte *rgba = (const GLubyte *) texel;
  587.    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  588.    *dst = PACK_COLOR_8888(rgba[BCOMP], rgba[GCOMP], rgba[RCOMP], 0xff);
  589. }
  590. #endif
  591.  
  592.  
  593. /* MESA_FORMAT_RGB888 ********************************************************/
  594.  
  595. /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
  596. static void FETCH(f_rgb888)( const struct gl_texture_image *texImage,
  597.                              GLint i, GLint j, GLint k, GLfloat *texel )
  598. {
  599.    const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
  600.    texel[RCOMP] = UBYTE_TO_FLOAT( src[2] );
  601.    texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
  602.    texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
  603.    texel[ACOMP] = 1.0F;
  604. }
  605.  
  606. #if DIM == 3
  607. static void store_texel_rgb888(struct gl_texture_image *texImage,
  608.                                GLint i, GLint j, GLint k, const void *texel)
  609. {
  610.    const GLubyte *rgba = (const GLubyte *) texel;
  611.    GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
  612.    dst[0] = rgba[BCOMP];
  613.    dst[1] = rgba[GCOMP];
  614.    dst[2] = rgba[RCOMP];
  615. }
  616. #endif
  617.  
  618.  
  619. /* MESA_FORMAT_BGR888 ********************************************************/
  620.  
  621. /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLchans */
  622. static void FETCH(f_bgr888)( const struct gl_texture_image *texImage,
  623.                              GLint i, GLint j, GLint k, GLfloat *texel )
  624. {
  625.    const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
  626.    texel[RCOMP] = UBYTE_TO_FLOAT( src[0] );
  627.    texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
  628.    texel[BCOMP] = UBYTE_TO_FLOAT( src[2] );
  629.    texel[ACOMP] = 1.0F;
  630. }
  631.  
  632. #if DIM == 3
  633. static void store_texel_bgr888(struct gl_texture_image *texImage,
  634.                                GLint i, GLint j, GLint k, const void *texel)
  635. {
  636.    const GLubyte *rgba = (const GLubyte *) texel;
  637.    GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
  638.    dst[0] = rgba[RCOMP];
  639.    dst[1] = rgba[GCOMP];
  640.    dst[2] = rgba[BCOMP];
  641. }
  642. #endif
  643.  
  644.  
  645. /* use color expansion like (g << 2) | (g >> 4) (does somewhat random rounding)
  646.    instead of slow (g << 2) * 255 / 252 (always rounds down) */
  647.  
  648. /* MESA_FORMAT_RGB565 ********************************************************/
  649.  
  650. /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
  651. static void FETCH(f_rgb565)( const struct gl_texture_image *texImage,
  652.                              GLint i, GLint j, GLint k, GLfloat *texel )
  653. {
  654.    const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
  655.    const GLushort s = *src;
  656.    texel[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
  657.    texel[GCOMP] = ((s >> 5 ) & 0x3f) * (1.0F / 63.0F);
  658.    texel[BCOMP] = ((s      ) & 0x1f) * (1.0F / 31.0F);
  659.    texel[ACOMP] = 1.0F;
  660. }
  661.  
  662. #if DIM == 3
  663. static void store_texel_rgb565(struct gl_texture_image *texImage,
  664.                                GLint i, GLint j, GLint k, const void *texel)
  665. {
  666.    const GLubyte *rgba = (const GLubyte *) texel;
  667.    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
  668.    *dst = PACK_COLOR_565(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
  669. }
  670. #endif
  671.  
  672.  
  673. /* MESA_FORMAT_RGB565_REV ****************************************************/
  674.  
  675. /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLchans */
  676. static void FETCH(f_rgb565_rev)( const struct gl_texture_image *texImage,
  677.                                  GLint i, GLint j, GLint k, GLfloat *texel )
  678. {
  679.    const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
  680.    const GLushort s = (*src >> 8) | (*src << 8); /* byte swap */
  681.    texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf8) | ((s >> 13) & 0x7) );
  682.    texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 3) & 0xfc) | ((s >>  9) & 0x3) );
  683.    texel[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >>  2) & 0x7) );
  684.    texel[ACOMP] = 1.0F;
  685. }
  686.  
  687. #if DIM == 3
  688. static void store_texel_rgb565_rev(struct gl_texture_image *texImage,
  689.                                   GLint i, GLint j, GLint k, const void *texel)
  690. {
  691.    const GLubyte *rgba = (const GLubyte *) texel;
  692.    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
  693.    *dst = PACK_COLOR_565(rgba[BCOMP], rgba[GCOMP], rgba[RCOMP]);
  694. }
  695. #endif
  696.  
  697.  
  698. /* MESA_FORMAT_ARGB4444 ******************************************************/
  699.  
  700. /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
  701. static void FETCH(f_argb4444)( const struct gl_texture_image *texImage,
  702.                                GLint i, GLint j, GLint k, GLfloat *texel )
  703. {
  704.    const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
  705.    const GLushort s = *src;
  706.    texel[RCOMP] = ((s >>  8) & 0xf) * (1.0F / 15.0F);
  707.    texel[GCOMP] = ((s >>  4) & 0xf) * (1.0F / 15.0F);
  708.    texel[BCOMP] = ((s      ) & 0xf) * (1.0F / 15.0F);
  709.    texel[ACOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
  710. }
  711.  
  712. #if DIM == 3
  713. static void store_texel_argb4444(struct gl_texture_image *texImage,
  714.                                  GLint i, GLint j, GLint k, const void *texel)
  715. {
  716.    const GLubyte *rgba = (const GLubyte *) texel;
  717.    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
  718.    *dst = PACK_COLOR_4444(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
  719. }
  720. #endif
  721.  
  722.  
  723. /* MESA_FORMAT_ARGB4444_REV **************************************************/
  724.  
  725. /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLchans */
  726. static void FETCH(f_argb4444_rev)( const struct gl_texture_image *texImage,
  727.                                    GLint i, GLint j, GLint k, GLfloat *texel )
  728. {
  729.    const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
  730.    texel[RCOMP] = ((s      ) & 0xf) * (1.0F / 15.0F);
  731.    texel[GCOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
  732.    texel[BCOMP] = ((s >>  8) & 0xf) * (1.0F / 15.0F);
  733.    texel[ACOMP] = ((s >>  4) & 0xf) * (1.0F / 15.0F);
  734. }
  735.  
  736. #if DIM == 3
  737. static void store_texel_argb4444_rev(struct gl_texture_image *texImage,
  738.                                  GLint i, GLint j, GLint k, const void *texel)
  739. {
  740.    const GLubyte *rgba = (const GLubyte *) texel;
  741.    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
  742.    *dst = PACK_COLOR_4444(rgba[ACOMP], rgba[BCOMP], rgba[GCOMP], rgba[RCOMP]);
  743. }
  744. #endif
  745.  
  746. /* MESA_FORMAT_RGBA5551 ******************************************************/
  747.  
  748. /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
  749. static void FETCH(f_rgba5551)( const struct gl_texture_image *texImage,
  750.                                GLint i, GLint j, GLint k, GLfloat *texel )
  751. {
  752.    const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
  753.    const GLushort s = *src;
  754.    texel[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
  755.    texel[GCOMP] = ((s >>  6) & 0x1f) * (1.0F / 31.0F);
  756.    texel[BCOMP] = ((s >>  1) & 0x1f) * (1.0F / 31.0F);
  757.    texel[ACOMP] = ((s      ) & 0x01) * 1.0F;
  758. }
  759.  
  760. #if DIM == 3
  761. static void store_texel_rgba5551(struct gl_texture_image *texImage,
  762.                                  GLint i, GLint j, GLint k, const void *texel)
  763. {
  764.    const GLubyte *rgba = (const GLubyte *) texel;
  765.    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
  766.    *dst = PACK_COLOR_5551(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
  767. }
  768. #endif
  769.  
  770. /* MESA_FORMAT_ARGB1555 ******************************************************/
  771.  
  772. /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
  773. static void FETCH(f_argb1555)( const struct gl_texture_image *texImage,
  774.                              GLint i, GLint j, GLint k, GLfloat *texel )
  775. {
  776.    const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
  777.    const GLushort s = *src;
  778.    texel[RCOMP] = ((s >> 10) & 0x1f) * (1.0F / 31.0F);
  779.    texel[GCOMP] = ((s >>  5) & 0x1f) * (1.0F / 31.0F);
  780.    texel[BCOMP] = ((s >>  0) & 0x1f) * (1.0F / 31.0F);
  781.    texel[ACOMP] = ((s >> 15) & 0x01) * 1.0F;
  782. }
  783.  
  784. #if DIM == 3
  785. static void store_texel_argb1555(struct gl_texture_image *texImage,
  786.                                  GLint i, GLint j, GLint k, const void *texel)
  787. {
  788.    const GLubyte *rgba = (const GLubyte *) texel;
  789.    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
  790.    *dst = PACK_COLOR_1555(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
  791. }
  792. #endif
  793.  
  794.  
  795. /* MESA_FORMAT_ARGB1555_REV **************************************************/
  796.  
  797. /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */
  798. static void FETCH(f_argb1555_rev)( const struct gl_texture_image *texImage,
  799.                                    GLint i, GLint j, GLint k, GLfloat *texel )
  800. {
  801.    const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
  802.    const GLushort s = (*src << 8) | (*src >> 8); /* byteswap */
  803.    texel[RCOMP] = UBYTE_TO_FLOAT( ((s >>  7) & 0xf8) | ((s >> 12) & 0x7) );
  804.    texel[GCOMP] = UBYTE_TO_FLOAT( ((s >>  2) & 0xf8) | ((s >>  7) & 0x7) );
  805.    texel[BCOMP] = UBYTE_TO_FLOAT( ((s <<  3) & 0xf8) | ((s >>  2) & 0x7) );
  806.    texel[ACOMP] = UBYTE_TO_FLOAT( ((s >> 15) & 0x01) * 255 );
  807. }
  808.  
  809. #if DIM == 3
  810. static void store_texel_argb1555_rev(struct gl_texture_image *texImage,
  811.                                  GLint i, GLint j, GLint k, const void *texel)
  812. {
  813.    const GLubyte *rgba = (const GLubyte *) texel;
  814.    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
  815.    *dst = PACK_COLOR_1555_REV(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
  816. }
  817. #endif
  818.  
  819.  
  820. /* MESA_FORMAT_RG88 **********************************************************/
  821.  
  822. /* Fetch texel from 1D, 2D or 3D rg88 texture, return 4 GLchans */
  823. static void FETCH(f_rg88)( const struct gl_texture_image *texImage,
  824.                            GLint i, GLint j, GLint k, GLfloat *texel )
  825. {
  826.    const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
  827.    texel[RCOMP] = UBYTE_TO_FLOAT( s & 0xff );
  828.    texel[GCOMP] = UBYTE_TO_FLOAT( s >> 8 );
  829.    texel[BCOMP] = 0.0;
  830.    texel[ACOMP] = 1.0;
  831. }
  832.  
  833. #if DIM == 3
  834. static void store_texel_rg88(struct gl_texture_image *texImage,
  835.                              GLint i, GLint j, GLint k, const void *texel)
  836. {
  837.    const GLubyte *rgba = (const GLubyte *) texel;
  838.    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
  839.    *dst = PACK_COLOR_88(rgba[RCOMP], rgba[GCOMP]);
  840. }
  841. #endif
  842.  
  843.  
  844. /* MESA_FORMAT_RG88_REV ******************************************************/
  845.  
  846. /* Fetch texel from 1D, 2D or 3D rg88_rev texture, return 4 GLchans */
  847. static void FETCH(f_rg88_rev)( const struct gl_texture_image *texImage,
  848.                            GLint i, GLint j, GLint k, GLfloat *texel )
  849. {
  850.    const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
  851.    texel[RCOMP] = UBYTE_TO_FLOAT( s & 0xff );
  852.    texel[GCOMP] = UBYTE_TO_FLOAT( s >> 8 );
  853.    texel[BCOMP] = 0.0;
  854.    texel[ACOMP] = 1.0;
  855. }
  856.  
  857. #if DIM == 3
  858. static void store_texel_rg88_rev(struct gl_texture_image *texImage,
  859.                              GLint i, GLint j, GLint k, const void *texel)
  860. {
  861.    const GLubyte *rgba = (const GLubyte *) texel;
  862.    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
  863.    *dst = PACK_COLOR_88(rgba[GCOMP], rgba[RCOMP]);
  864. }
  865. #endif
  866.  
  867.  
  868. /* MESA_FORMAT_AL88 **********************************************************/
  869.  
  870. /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
  871. static void FETCH(f_al88)( const struct gl_texture_image *texImage,
  872.                            GLint i, GLint j, GLint k, GLfloat *texel )
  873. {
  874.    const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
  875.    texel[RCOMP] =
  876.    texel[GCOMP] =
  877.    texel[BCOMP] = UBYTE_TO_FLOAT( s & 0xff );
  878.    texel[ACOMP] = UBYTE_TO_FLOAT( s >> 8 );
  879. }
  880.  
  881. #if DIM == 3
  882. static void store_texel_al88(struct gl_texture_image *texImage,
  883.                              GLint i, GLint j, GLint k, const void *texel)
  884. {
  885.    const GLubyte *rgba = (const GLubyte *) texel;
  886.    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
  887.    *dst = PACK_COLOR_88(rgba[ACOMP], rgba[RCOMP]);
  888. }
  889. #endif
  890.  
  891.  
  892. /* MESA_FORMAT_R8 ************************************************************/
  893.  
  894. /* Fetch texel from 1D, 2D or 3D rg88 texture, return 4 GLchans */
  895. static void FETCH(f_r8)(const struct gl_texture_image *texImage,
  896.                         GLint i, GLint j, GLint k, GLfloat *texel)
  897. {
  898.    const GLubyte s = *TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
  899.    texel[RCOMP] = UBYTE_TO_FLOAT(s);
  900.    texel[GCOMP] = 0.0;
  901.    texel[BCOMP] = 0.0;
  902.    texel[ACOMP] = 1.0;
  903. }
  904.  
  905. #if DIM == 3
  906. static void store_texel_r8(struct gl_texture_image *texImage,
  907.                            GLint i, GLint j, GLint k, const void *texel)
  908. {
  909.    const GLubyte *rgba = (const GLubyte *) texel;
  910.    GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
  911.    *dst = rgba[RCOMP];
  912. }
  913. #endif
  914.  
  915.  
  916. /* MESA_FORMAT_R16 ***********************************************************/
  917.  
  918. /* Fetch texel from 1D, 2D or 3D r16 texture, return 4 GLchans */
  919. static void FETCH(f_r16)(const struct gl_texture_image *texImage,
  920.                         GLint i, GLint j, GLint k, GLfloat *texel)
  921. {
  922.    const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
  923.    texel[RCOMP] = USHORT_TO_FLOAT(s);
  924.    texel[GCOMP] = 0.0;
  925.    texel[BCOMP] = 0.0;
  926.    texel[ACOMP] = 1.0;
  927. }
  928.  
  929. #if DIM == 3
  930. static void store_texel_r16(struct gl_texture_image *texImage,
  931.                             GLint i, GLint j, GLint k, const void *texel)
  932. {
  933.    const GLushort *rgba = (const GLushort *) texel;
  934.    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
  935.    *dst = rgba[RCOMP];
  936. }
  937. #endif
  938.  
  939.  
  940. /* MESA_FORMAT_AL88_REV ******************************************************/
  941.  
  942. /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
  943. static void FETCH(f_al88_rev)( const struct gl_texture_image *texImage,
  944.                                GLint i, GLint j, GLint k, GLfloat *texel )
  945. {
  946.    const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
  947.    texel[RCOMP] =
  948.    texel[GCOMP] =
  949.    texel[BCOMP] = UBYTE_TO_FLOAT( s >> 8 );
  950.    texel[ACOMP] = UBYTE_TO_FLOAT( s & 0xff );
  951. }
  952.  
  953. #if DIM == 3
  954. static void store_texel_al88_rev(struct gl_texture_image *texImage,
  955.                                  GLint i, GLint j, GLint k, const void *texel)
  956. {
  957.    const GLubyte *rgba = (const GLubyte *) texel;
  958.    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
  959.    *dst = PACK_COLOR_88(rgba[RCOMP], rgba[ACOMP]);
  960. }
  961. #endif
  962.  
  963.  
  964. /* MESA_FORMAT_RG1616 ********************************************************/
  965.  
  966. /* Fetch texel from 1D, 2D or 3D rg1616 texture, return 4 GLchans */
  967. static void FETCH(f_rg1616)( const struct gl_texture_image *texImage,
  968.                            GLint i, GLint j, GLint k, GLfloat *texel )
  969. {
  970.    const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  971.    texel[RCOMP] = USHORT_TO_FLOAT( s & 0xffff );
  972.    texel[GCOMP] = USHORT_TO_FLOAT( s >> 16 );
  973.    texel[BCOMP] = 0.0;
  974.    texel[ACOMP] = 1.0;
  975. }
  976.  
  977. #if DIM == 3
  978. static void store_texel_rg1616(struct gl_texture_image *texImage,
  979.                              GLint i, GLint j, GLint k, const void *texel)
  980. {
  981.    const GLubyte *rgba = (const GLubyte *) texel;
  982.    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
  983.    *dst = PACK_COLOR_1616(rgba[RCOMP], rgba[GCOMP]);
  984. }
  985. #endif
  986.  
  987.  
  988. /* MESA_FORMAT_RG1616_REV ****************************************************/
  989.  
  990. /* Fetch texel from 1D, 2D or 3D rg1616_rev texture, return 4 GLchans */
  991. static void FETCH(f_rg1616_rev)( const struct gl_texture_image *texImage,
  992.                            GLint i, GLint j, GLint k, GLfloat *texel )
  993. {
  994.    const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  995.    texel[RCOMP] = USHORT_TO_FLOAT( s >> 16 );
  996.    texel[GCOMP] = USHORT_TO_FLOAT( s & 0xffff );
  997.    texel[BCOMP] = 0.0;
  998.    texel[ACOMP] = 1.0;
  999. }
  1000.  
  1001. #if DIM == 3
  1002. static void store_texel_rg1616_rev(struct gl_texture_image *texImage,
  1003.                              GLint i, GLint j, GLint k, const void *texel)
  1004. {
  1005.    const GLubyte *rgba = (const GLubyte *) texel;
  1006.    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
  1007.    *dst = PACK_COLOR_1616(rgba[GCOMP], rgba[RCOMP]);
  1008. }
  1009. #endif
  1010.  
  1011.  
  1012. /* MESA_FORMAT_AL1616 ********************************************************/
  1013.  
  1014. /* Fetch texel from 1D, 2D or 3D al1616 texture, return 4 GLchans */
  1015. static void FETCH(f_al1616)( const struct gl_texture_image *texImage,
  1016.                              GLint i, GLint j, GLint k, GLfloat *texel )
  1017. {
  1018.    const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  1019.    texel[RCOMP] =
  1020.    texel[GCOMP] =
  1021.    texel[BCOMP] = USHORT_TO_FLOAT( s & 0xffff );
  1022.    texel[ACOMP] = USHORT_TO_FLOAT( s >> 16 );
  1023. }
  1024.  
  1025. #if DIM == 3
  1026. static void store_texel_al1616(struct gl_texture_image *texImage,
  1027.                              GLint i, GLint j, GLint k, const void *texel)
  1028. {
  1029.    const GLushort *rgba = (const GLushort *) texel;
  1030.    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  1031.    *dst = PACK_COLOR_1616(rgba[ACOMP], rgba[RCOMP]);
  1032. }
  1033. #endif
  1034.  
  1035.  
  1036. /* MESA_FORMAT_AL1616_REV ****************************************************/
  1037.  
  1038. /* Fetch texel from 1D, 2D or 3D al1616_rev texture, return 4 GLchans */
  1039. static void FETCH(f_al1616_rev)( const struct gl_texture_image *texImage,
  1040.                                  GLint i, GLint j, GLint k, GLfloat *texel )
  1041. {
  1042.    const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  1043.    texel[RCOMP] =
  1044.    texel[GCOMP] =
  1045.    texel[BCOMP] = USHORT_TO_FLOAT( s >> 16 );
  1046.    texel[ACOMP] = USHORT_TO_FLOAT( s & 0xffff );
  1047. }
  1048.  
  1049. #if DIM == 3
  1050. static void store_texel_al1616_rev(struct gl_texture_image *texImage,
  1051.                                    GLint i, GLint j, GLint k, const void *texel)
  1052. {
  1053.    const GLushort *rgba = (const GLushort *) texel;
  1054.    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  1055.    *dst = PACK_COLOR_1616(rgba[RCOMP], rgba[ACOMP]);
  1056. }
  1057. #endif
  1058.  
  1059.  
  1060. /* MESA_FORMAT_RGB332 ********************************************************/
  1061.  
  1062. /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
  1063. static void FETCH(f_rgb332)( const struct gl_texture_image *texImage,
  1064.                              GLint i, GLint j, GLint k, GLfloat *texel )
  1065. {
  1066.    const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
  1067.    const GLubyte s = *src;
  1068.    texel[RCOMP] = ((s >> 5) & 0x7) * (1.0F / 7.0F);
  1069.    texel[GCOMP] = ((s >> 2) & 0x7) * (1.0F / 7.0F);
  1070.    texel[BCOMP] = ((s     ) & 0x3) * (1.0F / 3.0F);
  1071.    texel[ACOMP] = 1.0F;
  1072. }
  1073.  
  1074. #if DIM == 3
  1075. static void store_texel_rgb332(struct gl_texture_image *texImage,
  1076.                                GLint i, GLint j, GLint k, const void *texel)
  1077. {
  1078.    const GLubyte *rgba = (const GLubyte *) texel;
  1079.    GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
  1080.    *dst = PACK_COLOR_332(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
  1081. }
  1082. #endif
  1083.  
  1084.  
  1085. /* MESA_FORMAT_A8 ************************************************************/
  1086.  
  1087. /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
  1088. static void FETCH(f_a8)( const struct gl_texture_image *texImage,
  1089.                          GLint i, GLint j, GLint k, GLfloat *texel )
  1090. {
  1091.    const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
  1092.    texel[RCOMP] =
  1093.    texel[GCOMP] =
  1094.    texel[BCOMP] = 0.0F;
  1095.    texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
  1096. }
  1097.  
  1098. #if DIM == 3
  1099. static void store_texel_a8(struct gl_texture_image *texImage,
  1100.                            GLint i, GLint j, GLint k, const void *texel)
  1101. {
  1102.    const GLubyte *rgba = (const GLubyte *) texel;
  1103.    GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
  1104.    *dst = rgba[ACOMP];
  1105. }
  1106. #endif
  1107.  
  1108.  
  1109. /* MESA_FORMAT_L8 ************************************************************/
  1110.  
  1111. /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
  1112. static void FETCH(f_l8)( const struct gl_texture_image *texImage,
  1113.                          GLint i, GLint j, GLint k, GLfloat *texel )
  1114. {
  1115.    const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
  1116.    texel[RCOMP] =
  1117.    texel[GCOMP] =
  1118.    texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
  1119.    texel[ACOMP] = 1.0F;
  1120. }
  1121.  
  1122. #if DIM == 3
  1123. static void store_texel_l8(struct gl_texture_image *texImage,
  1124.                            GLint i, GLint j, GLint k, const void *texel)
  1125. {
  1126.    const GLubyte *rgba = (const GLubyte *) texel;
  1127.    GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
  1128.    *dst = rgba[RCOMP];
  1129. }
  1130. #endif
  1131.  
  1132.  
  1133. /* MESA_FORMAT_I8 ************************************************************/
  1134.  
  1135. /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
  1136. static void FETCH(f_i8)( const struct gl_texture_image *texImage,
  1137.                          GLint i, GLint j, GLint k, GLfloat *texel )
  1138. {
  1139.    const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
  1140.    texel[RCOMP] =
  1141.    texel[GCOMP] =
  1142.    texel[BCOMP] =
  1143.    texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
  1144. }
  1145.  
  1146. #if DIM == 3
  1147. static void store_texel_i8(struct gl_texture_image *texImage,
  1148.                            GLint i, GLint j, GLint k, const void *texel)
  1149. {
  1150.    const GLubyte *rgba = (const GLubyte *) texel;
  1151.    GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
  1152.    *dst = rgba[RCOMP];
  1153. }
  1154. #endif
  1155.  
  1156.  
  1157. /* MESA_FORMAT_CI8 ***********************************************************/
  1158.  
  1159. /* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
  1160.  * color table, and return 4 GLchans.
  1161.  */
  1162. static void FETCH(f_ci8)( const struct gl_texture_image *texImage,
  1163.                           GLint i, GLint j, GLint k, GLfloat *texel )
  1164. {
  1165.    const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
  1166.    const struct gl_color_table *palette;
  1167.    GLuint index;
  1168.    GET_CURRENT_CONTEXT(ctx);
  1169.  
  1170.    if (ctx->Texture.SharedPalette) {
  1171.       palette = &ctx->Texture.Palette;
  1172.    }
  1173.    else {
  1174.       palette = &texImage->TexObject->Palette;
  1175.    }
  1176.    if (palette->Size == 0)
  1177.       return; /* undefined results */
  1178.  
  1179.    /* Mask the index against size of palette to avoid going out of bounds */
  1180.    index = (*src) & (palette->Size - 1);
  1181.  
  1182.    {
  1183.       const GLfloat *table = palette->TableF;
  1184.       switch (palette->_BaseFormat) {
  1185.       case GL_ALPHA:
  1186.          texel[RCOMP] =
  1187.          texel[GCOMP] =
  1188.          texel[BCOMP] = 0.0F;
  1189.          texel[ACOMP] = table[index];
  1190.          break;
  1191.       case GL_LUMINANCE:
  1192.          texel[RCOMP] =
  1193.          texel[GCOMP] =
  1194.          texel[BCOMP] = table[index];
  1195.          texel[ACOMP] = 1.0F;
  1196.          break;
  1197.       case GL_INTENSITY:
  1198.          texel[RCOMP] =
  1199.          texel[GCOMP] =
  1200.          texel[BCOMP] =
  1201.          texel[ACOMP] = table[index];
  1202.          break;
  1203.       case GL_LUMINANCE_ALPHA:
  1204.          texel[RCOMP] =
  1205.          texel[GCOMP] =
  1206.          texel[BCOMP] = table[index * 2 + 0];
  1207.          texel[ACOMP] = table[index * 2 + 1];
  1208.          break;
  1209.       case GL_RGB:
  1210.          texel[RCOMP] = table[index * 3 + 0];
  1211.          texel[GCOMP] = table[index * 3 + 1];
  1212.          texel[BCOMP] = table[index * 3 + 2];
  1213.          texel[ACOMP] = 1.0F;
  1214.          break;
  1215.       case GL_RGBA:
  1216.          texel[RCOMP] = table[index * 4 + 0];
  1217.          texel[GCOMP] = table[index * 4 + 1];
  1218.          texel[BCOMP] = table[index * 4 + 2];
  1219.          texel[ACOMP] = table[index * 4 + 3];
  1220.          break;
  1221.       default:
  1222.          _mesa_problem(ctx, "Bad palette format in fetch_texel_ci8");
  1223.          return;
  1224.       }
  1225.    }
  1226. }
  1227.  
  1228. #if DIM == 3
  1229. static void store_texel_ci8(struct gl_texture_image *texImage,
  1230.                             GLint i, GLint j, GLint k, const void *texel)
  1231. {
  1232.    const GLubyte *index = (const GLubyte *) texel;
  1233.    GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
  1234.    *dst = *index;
  1235. }
  1236. #endif
  1237.  
  1238.  
  1239. /* Fetch texel from 1D, 2D or 3D srgb8 texture, return 4 GLfloats */
  1240. /* Note: component order is same as for MESA_FORMAT_RGB888 */
  1241. static void FETCH(srgb8)(const struct gl_texture_image *texImage,
  1242.                          GLint i, GLint j, GLint k, GLfloat *texel )
  1243. {
  1244.    const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
  1245.    texel[RCOMP] = nonlinear_to_linear(src[2]);
  1246.    texel[GCOMP] = nonlinear_to_linear(src[1]);
  1247.    texel[BCOMP] = nonlinear_to_linear(src[0]);
  1248.    texel[ACOMP] = 1.0F;
  1249. }
  1250.  
  1251. #if DIM == 3
  1252. static void store_texel_srgb8(struct gl_texture_image *texImage,
  1253.                               GLint i, GLint j, GLint k, const void *texel)
  1254. {
  1255.    const GLubyte *rgba = (const GLubyte *) texel;
  1256.    GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
  1257.    dst[0] = rgba[BCOMP]; /* no conversion */
  1258.    dst[1] = rgba[GCOMP];
  1259.    dst[2] = rgba[RCOMP];
  1260. }
  1261. #endif
  1262.  
  1263. /* Fetch texel from 1D, 2D or 3D srgba8 texture, return 4 GLfloats */
  1264. static void FETCH(srgba8)(const struct gl_texture_image *texImage,
  1265.                           GLint i, GLint j, GLint k, GLfloat *texel )
  1266. {
  1267.    const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  1268.    texel[RCOMP] = nonlinear_to_linear( (s >> 24) );
  1269.    texel[GCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
  1270.    texel[BCOMP] = nonlinear_to_linear( (s >>  8) & 0xff );
  1271.    texel[ACOMP] = UBYTE_TO_FLOAT( (s      ) & 0xff ); /* linear! */
  1272. }
  1273.  
  1274. #if DIM == 3
  1275. static void store_texel_srgba8(struct gl_texture_image *texImage,
  1276.                                GLint i, GLint j, GLint k, const void *texel)
  1277. {
  1278.    const GLubyte *rgba = (const GLubyte *) texel;
  1279.    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  1280.    *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
  1281. }
  1282. #endif
  1283.  
  1284. /* Fetch texel from 1D, 2D or 3D sargb8 texture, return 4 GLfloats */
  1285. static void FETCH(sargb8)(const struct gl_texture_image *texImage,
  1286.                           GLint i, GLint j, GLint k, GLfloat *texel )
  1287. {
  1288.    const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  1289.    texel[RCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
  1290.    texel[GCOMP] = nonlinear_to_linear( (s >>  8) & 0xff );
  1291.    texel[BCOMP] = nonlinear_to_linear( (s      ) & 0xff );
  1292.    texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) ); /* linear! */
  1293. }
  1294.  
  1295. #if DIM == 3
  1296. static void store_texel_sargb8(struct gl_texture_image *texImage,
  1297.                                GLint i, GLint j, GLint k, const void *texel)
  1298. {
  1299.    const GLubyte *rgba = (const GLubyte *) texel;
  1300.    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  1301.    *dst = PACK_COLOR_8888(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
  1302. }
  1303. #endif
  1304.  
  1305. /* Fetch texel from 1D, 2D or 3D sl8 texture, return 4 GLfloats */
  1306. static void FETCH(sl8)(const struct gl_texture_image *texImage,
  1307.                        GLint i, GLint j, GLint k, GLfloat *texel )
  1308. {
  1309.    const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
  1310.    texel[RCOMP] =
  1311.    texel[GCOMP] =
  1312.    texel[BCOMP] = nonlinear_to_linear(src[0]);
  1313.    texel[ACOMP] = 1.0F;
  1314. }
  1315.  
  1316. #if DIM == 3
  1317. static void store_texel_sl8(struct gl_texture_image *texImage,
  1318.                             GLint i, GLint j, GLint k, const void *texel)
  1319. {
  1320.    const GLubyte *rgba = (const GLubyte *) texel;
  1321.    GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
  1322.    dst[0] = rgba[RCOMP];
  1323. }
  1324. #endif
  1325.  
  1326. /* Fetch texel from 1D, 2D or 3D sla8 texture, return 4 GLfloats */
  1327. static void FETCH(sla8)(const struct gl_texture_image *texImage,
  1328.                        GLint i, GLint j, GLint k, GLfloat *texel )
  1329. {
  1330.    const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2);
  1331.    texel[RCOMP] =
  1332.    texel[GCOMP] =
  1333.    texel[BCOMP] = nonlinear_to_linear(src[0]);
  1334.    texel[ACOMP] = UBYTE_TO_FLOAT(src[1]); /* linear */
  1335. }
  1336.  
  1337. #if DIM == 3
  1338. static void store_texel_sla8(struct gl_texture_image *texImage,
  1339.                             GLint i, GLint j, GLint k, const void *texel)
  1340. {
  1341.    const GLubyte *rgba = (const GLubyte *) texel;
  1342.    GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2);
  1343.    dst[0] = rgba[RCOMP];
  1344.    dst[1] = rgba[ACOMP];
  1345. }
  1346. #endif
  1347.  
  1348.  
  1349. /* MESA_FORMAT_RGBA_INT8 **************************************************/
  1350.  
  1351. static void
  1352. FETCH(rgba_int8)(const struct gl_texture_image *texImage,
  1353.                  GLint i, GLint j, GLint k, GLfloat *texel )
  1354. {
  1355.    const GLbyte *src = TEXEL_ADDR(GLbyte, texImage, i, j, k, 4);
  1356.    texel[RCOMP] = (GLfloat) src[0];
  1357.    texel[GCOMP] = (GLfloat) src[1];
  1358.    texel[BCOMP] = (GLfloat) src[2];
  1359.    texel[ACOMP] = (GLfloat) src[3];
  1360. }
  1361.  
  1362. #if DIM == 3
  1363. static void
  1364. store_texel_rgba_int8(struct gl_texture_image *texImage,
  1365.                       GLint i, GLint j, GLint k, const void *texel)
  1366. {
  1367.    const GLbyte *rgba = (const GLbyte *) texel;
  1368.    GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 4);
  1369.    dst[0] = rgba[RCOMP];
  1370.    dst[1] = rgba[GCOMP];
  1371.    dst[2] = rgba[BCOMP];
  1372.    dst[3] = rgba[ACOMP];
  1373. }
  1374. #endif
  1375.  
  1376.  
  1377. /* MESA_FORMAT_RGBA_INT16 **************************************************/
  1378.  
  1379. static void
  1380. FETCH(rgba_int16)(const struct gl_texture_image *texImage,
  1381.                   GLint i, GLint j, GLint k, GLfloat *texel )
  1382. {
  1383.    const GLshort *src = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
  1384.    texel[RCOMP] = (GLfloat) src[0];
  1385.    texel[GCOMP] = (GLfloat) src[1];
  1386.    texel[BCOMP] = (GLfloat) src[2];
  1387.    texel[ACOMP] = (GLfloat) src[3];
  1388. }
  1389.  
  1390. #if DIM == 3
  1391. static void
  1392. store_texel_rgba_int16(struct gl_texture_image *texImage,
  1393.                        GLint i, GLint j, GLint k, const void *texel)
  1394. {
  1395.    const GLshort *rgba = (const GLshort *) texel;
  1396.    GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
  1397.    dst[0] = rgba[RCOMP];
  1398.    dst[1] = rgba[GCOMP];
  1399.    dst[2] = rgba[BCOMP];
  1400.    dst[3] = rgba[ACOMP];
  1401. }
  1402. #endif
  1403.  
  1404.  
  1405. /* MESA_FORMAT_RGBA_INT32 **************************************************/
  1406.  
  1407. static void
  1408. FETCH(rgba_int32)(const struct gl_texture_image *texImage,
  1409.                   GLint i, GLint j, GLint k, GLfloat *texel )
  1410. {
  1411.    const GLint *src = TEXEL_ADDR(GLint, texImage, i, j, k, 4);
  1412.    texel[RCOMP] = (GLfloat) src[0];
  1413.    texel[GCOMP] = (GLfloat) src[1];
  1414.    texel[BCOMP] = (GLfloat) src[2];
  1415.    texel[ACOMP] = (GLfloat) src[3];
  1416. }
  1417.  
  1418. #if DIM == 3
  1419. static void
  1420. store_texel_rgba_int32(struct gl_texture_image *texImage,
  1421.                        GLint i, GLint j, GLint k, const void *texel)
  1422. {
  1423.    const GLint *rgba = (const GLint *) texel;
  1424.    GLint *dst = TEXEL_ADDR(GLint, texImage, i, j, k, 4);
  1425.    dst[0] = rgba[RCOMP];
  1426.    dst[1] = rgba[GCOMP];
  1427.    dst[2] = rgba[BCOMP];
  1428.    dst[3] = rgba[ACOMP];
  1429. }
  1430. #endif
  1431.  
  1432.  
  1433. /* MESA_FORMAT_RGBA_UINT8 **************************************************/
  1434.  
  1435. static void
  1436. FETCH(rgba_uint8)(const struct gl_texture_image *texImage,
  1437.                  GLint i, GLint j, GLint k, GLfloat *texel )
  1438. {
  1439.    const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 4);
  1440.    texel[RCOMP] = (GLfloat) src[0];
  1441.    texel[GCOMP] = (GLfloat) src[1];
  1442.    texel[BCOMP] = (GLfloat) src[2];
  1443.    texel[ACOMP] = (GLfloat) src[3];
  1444. }
  1445.  
  1446. #if DIM == 3
  1447. static void
  1448. store_texel_rgba_uint8(struct gl_texture_image *texImage,
  1449.                       GLint i, GLint j, GLint k, const void *texel)
  1450. {
  1451.    const GLubyte *rgba = (const GLubyte *) texel;
  1452.    GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 4);
  1453.    dst[0] = rgba[RCOMP];
  1454.    dst[1] = rgba[GCOMP];
  1455.    dst[2] = rgba[BCOMP];
  1456.    dst[3] = rgba[ACOMP];
  1457. }
  1458. #endif
  1459.  
  1460.  
  1461. /* MESA_FORMAT_RGBA_UINT16 **************************************************/
  1462.  
  1463. static void
  1464. FETCH(rgba_uint16)(const struct gl_texture_image *texImage,
  1465.                   GLint i, GLint j, GLint k, GLfloat *texel )
  1466. {
  1467.    const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
  1468.    texel[RCOMP] = (GLfloat) src[0];
  1469.    texel[GCOMP] = (GLfloat) src[1];
  1470.    texel[BCOMP] = (GLfloat) src[2];
  1471.    texel[ACOMP] = (GLfloat) src[3];
  1472. }
  1473.  
  1474. #if DIM == 3
  1475. static void
  1476. store_texel_rgba_uint16(struct gl_texture_image *texImage,
  1477.                        GLint i, GLint j, GLint k, const void *texel)
  1478. {
  1479.    const GLushort *rgba = (const GLushort *) texel;
  1480.    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
  1481.    dst[0] = rgba[RCOMP];
  1482.    dst[1] = rgba[GCOMP];
  1483.    dst[2] = rgba[BCOMP];
  1484.    dst[3] = rgba[ACOMP];
  1485. }
  1486. #endif
  1487.  
  1488.  
  1489. /* MESA_FORMAT_RGBA_UINT32 **************************************************/
  1490.  
  1491. static void
  1492. FETCH(rgba_uint32)(const struct gl_texture_image *texImage,
  1493.                   GLint i, GLint j, GLint k, GLfloat *texel )
  1494. {
  1495.    const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 4);
  1496.    texel[RCOMP] = (GLfloat) src[0];
  1497.    texel[GCOMP] = (GLfloat) src[1];
  1498.    texel[BCOMP] = (GLfloat) src[2];
  1499.    texel[ACOMP] = (GLfloat) src[3];
  1500. }
  1501.  
  1502. #if DIM == 3
  1503. static void
  1504. store_texel_rgba_uint32(struct gl_texture_image *texImage,
  1505.                        GLint i, GLint j, GLint k, const void *texel)
  1506. {
  1507.    const GLuint *rgba = (const GLuint *) texel;
  1508.    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 4);
  1509.    dst[0] = rgba[RCOMP];
  1510.    dst[1] = rgba[GCOMP];
  1511.    dst[2] = rgba[BCOMP];
  1512.    dst[3] = rgba[ACOMP];
  1513. }
  1514. #endif
  1515.  
  1516.  
  1517. /* MESA_FORMAT_DUDV8 ********************************************************/
  1518.  
  1519. /* this format by definition produces 0,0,0,1 as rgba values,
  1520.    however we'll return the dudv values as rg and fix up elsewhere */
  1521. static void FETCH(dudv8)(const struct gl_texture_image *texImage,
  1522.                          GLint i, GLint j, GLint k, GLfloat *texel )
  1523. {
  1524.    const GLbyte *src = TEXEL_ADDR(GLbyte, texImage, i, j, k, 2);
  1525.    texel[RCOMP] = BYTE_TO_FLOAT(src[0]);
  1526.    texel[GCOMP] = BYTE_TO_FLOAT(src[1]);
  1527.    texel[BCOMP] = 0;
  1528.    texel[ACOMP] = 0;
  1529. }
  1530.  
  1531.  
  1532. /* MESA_FORMAT_SIGNED_R8 ***********************************************/
  1533.  
  1534. static void FETCH(signed_r8)( const struct gl_texture_image *texImage,
  1535.                               GLint i, GLint j, GLint k, GLfloat *texel )
  1536. {
  1537.    const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
  1538.    texel[RCOMP] = BYTE_TO_FLOAT_TEX( s );
  1539.    texel[GCOMP] = 0.0F;
  1540.    texel[BCOMP] = 0.0F;
  1541.    texel[ACOMP] = 1.0F;
  1542. }
  1543.  
  1544. #if DIM == 3
  1545. static void store_texel_signed_r8(struct gl_texture_image *texImage,
  1546.                                   GLint i, GLint j, GLint k, const void *texel)
  1547. {
  1548.    const GLbyte *rgba = (const GLbyte *) texel;
  1549.    GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
  1550.    *dst = rgba[RCOMP];
  1551. }
  1552. #endif
  1553.  
  1554.  
  1555. /* MESA_FORMAT_SIGNED_RG88 ***********************************************/
  1556.  
  1557. static void FETCH(signed_rg88)( const struct gl_texture_image *texImage,
  1558.                                 GLint i, GLint j, GLint k, GLfloat *texel )
  1559. {
  1560.    const GLushort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
  1561.    texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
  1562.    texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) );
  1563.    texel[BCOMP] = 0.0F;
  1564.    texel[ACOMP] = 1.0F;
  1565. }
  1566.  
  1567. #if DIM == 3
  1568. static void store_texel_signed_rg88(struct gl_texture_image *texImage,
  1569.                                     GLint i, GLint j, GLint k, const void *texel)
  1570. {
  1571.    const GLbyte *rg = (const GLbyte *) texel;
  1572.    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 2);
  1573.    *dst = PACK_COLOR_88(rg[RCOMP], rg[GCOMP]);
  1574. }
  1575. #endif
  1576.  
  1577.  
  1578. /* MESA_FORMAT_SIGNED_RGBX8888 ***********************************************/
  1579.  
  1580. static void FETCH(signed_rgbx8888)( const struct gl_texture_image *texImage,
  1581.                                     GLint i, GLint j, GLint k, GLfloat *texel )
  1582. {
  1583.    const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  1584.    texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
  1585.    texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
  1586.    texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >>  8) );
  1587.    texel[ACOMP] = 1.0f;
  1588. }
  1589.  
  1590. #if DIM == 3
  1591. static void store_texel_signed_rgbx8888(struct gl_texture_image *texImage,
  1592.                                         GLint i, GLint j, GLint k, const void *texel)
  1593. {
  1594.    const GLbyte *rgba = (const GLbyte *) texel;
  1595.    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  1596.    *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], 255);
  1597. }
  1598. #endif
  1599.  
  1600.  
  1601. /* MESA_FORMAT_SIGNED_RGBA8888 ***********************************************/
  1602.  
  1603. static void FETCH(signed_rgba8888)( const struct gl_texture_image *texImage,
  1604.                                     GLint i, GLint j, GLint k, GLfloat *texel )
  1605. {
  1606.    const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  1607.    texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
  1608.    texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
  1609.    texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >>  8) );
  1610.    texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s      ) );
  1611. }
  1612.  
  1613. #if DIM == 3
  1614. static void store_texel_signed_rgba8888(struct gl_texture_image *texImage,
  1615.                                         GLint i, GLint j, GLint k, const void *texel)
  1616. {
  1617.    const GLbyte *rgba = (const GLbyte *) texel;
  1618.    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  1619.    *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
  1620. }
  1621. #endif
  1622.  
  1623. static void FETCH(signed_rgba8888_rev)( const struct gl_texture_image *texImage,
  1624.                                         GLint i, GLint j, GLint k, GLfloat *texel )
  1625. {
  1626.    const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  1627.    texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s      ) );
  1628.    texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >>  8) );
  1629.    texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
  1630.    texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
  1631. }
  1632.  
  1633. #if DIM == 3
  1634. static void store_texel_signed_rgba8888_rev(struct gl_texture_image *texImage,
  1635.                                             GLint i, GLint j, GLint k, const void *texel)
  1636. {
  1637.    const GLubyte *rgba = (const GLubyte *) texel;
  1638.    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  1639.    *dst = PACK_COLOR_8888_REV(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
  1640. }
  1641. #endif
  1642.  
  1643.  
  1644.  
  1645. /* MESA_FORMAT_SIGNED_R_16 ***********************************************/
  1646.  
  1647. static void
  1648. FETCH(signed_r_16)(const struct gl_texture_image *texImage,
  1649.                    GLint i, GLint j, GLint k, GLfloat *texel)
  1650. {
  1651.    const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
  1652.    texel[RCOMP] = SHORT_TO_FLOAT_TEX( s );
  1653.    texel[GCOMP] = 0.0F;
  1654.    texel[BCOMP] = 0.0F;
  1655.    texel[ACOMP] = 1.0F;
  1656. }
  1657.  
  1658. #if DIM == 3
  1659. static void
  1660. store_texel_signed_r_16(struct gl_texture_image *texImage,
  1661.                         GLint i, GLint j, GLint k, const void *texel)
  1662. {
  1663.    const GLshort *rgba = (const GLshort *) texel;
  1664.    GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
  1665.    *dst = rgba[0];
  1666. }
  1667. #endif
  1668.  
  1669.  
  1670. /* MESA_FORMAT_SIGNED_RG_16 ***********************************************/
  1671.  
  1672. static void
  1673. FETCH(signed_rg_16)(const struct gl_texture_image *texImage,
  1674.                     GLint i, GLint j, GLint k, GLfloat *texel)
  1675. {
  1676.    const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
  1677.    texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
  1678.    texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
  1679.    texel[BCOMP] = 0.0F;
  1680.    texel[ACOMP] = 1.0F;
  1681. }
  1682.  
  1683. #if DIM == 3
  1684. static void
  1685. store_texel_signed_rg_16(struct gl_texture_image *texImage,
  1686.                          GLint i, GLint j, GLint k, const void *texel)
  1687. {
  1688.    const GLshort *rgba = (const GLshort *) texel;
  1689.    GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
  1690.    dst[0] = rgba[RCOMP];
  1691.    dst[1] = rgba[GCOMP];
  1692. }
  1693. #endif
  1694.  
  1695.  
  1696. /* MESA_FORMAT_SIGNED_RGBA_16 ***********************************************/
  1697.  
  1698. static void
  1699. FETCH(signed_rgb_16)(const struct gl_texture_image *texImage,
  1700.                      GLint i, GLint j, GLint k, GLfloat *texel)
  1701. {
  1702.    const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 3);
  1703.    texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
  1704.    texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
  1705.    texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] );
  1706.    texel[ACOMP] = 1.0F;
  1707. }
  1708.  
  1709. #if DIM == 3
  1710. static void
  1711. store_texel_signed_rgb_16(struct gl_texture_image *texImage,
  1712.                           GLint i, GLint j, GLint k, const void *texel)
  1713. {
  1714.    const GLshort *rgba = (const GLshort *) texel;
  1715.    GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 3);
  1716.    dst[0] = rgba[RCOMP];
  1717.    dst[1] = rgba[GCOMP];
  1718.    dst[2] = rgba[BCOMP];
  1719. }
  1720. #endif
  1721.  
  1722.  
  1723. /* MESA_FORMAT_SIGNED_RGBA_16 ***********************************************/
  1724.  
  1725. static void
  1726. FETCH(signed_rgba_16)(const struct gl_texture_image *texImage,
  1727.                       GLint i, GLint j, GLint k, GLfloat *texel)
  1728. {
  1729.    const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
  1730.    texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
  1731.    texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
  1732.    texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] );
  1733.    texel[ACOMP] = SHORT_TO_FLOAT_TEX( s[3] );
  1734. }
  1735.  
  1736. #if DIM == 3
  1737. static void
  1738. store_texel_signed_rgba_16(struct gl_texture_image *texImage,
  1739.                            GLint i, GLint j, GLint k, const void *texel)
  1740. {
  1741.    const GLshort *rgba = (const GLshort *) texel;
  1742.    GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
  1743.    dst[0] = rgba[RCOMP];
  1744.    dst[1] = rgba[GCOMP];
  1745.    dst[2] = rgba[BCOMP];
  1746.    dst[3] = rgba[ACOMP];
  1747. }
  1748. #endif
  1749.  
  1750.  
  1751.  
  1752. /* MESA_FORMAT_RGBA_16 ***********************************************/
  1753.  
  1754. static void
  1755. FETCH(rgba_16)(const struct gl_texture_image *texImage,
  1756.                GLint i, GLint j, GLint k, GLfloat *texel)
  1757. {
  1758.    const GLushort *s = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
  1759.    texel[RCOMP] = USHORT_TO_FLOAT( s[0] );
  1760.    texel[GCOMP] = USHORT_TO_FLOAT( s[1] );
  1761.    texel[BCOMP] = USHORT_TO_FLOAT( s[2] );
  1762.    texel[ACOMP] = USHORT_TO_FLOAT( s[3] );
  1763. }
  1764.  
  1765. #if DIM == 3
  1766. static void
  1767. store_texel_rgba_16(struct gl_texture_image *texImage,
  1768.                     GLint i, GLint j, GLint k, const void *texel)
  1769. {
  1770.    const GLushort *rgba = (const GLushort *) texel;
  1771.    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
  1772.    dst[0] = rgba[RCOMP];
  1773.    dst[1] = rgba[GCOMP];
  1774.    dst[2] = rgba[BCOMP];
  1775.    dst[3] = rgba[ACOMP];
  1776. }
  1777. #endif
  1778.  
  1779.  
  1780.  
  1781. /* MESA_FORMAT_YCBCR *********************************************************/
  1782.  
  1783. /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats.
  1784.  * We convert YCbCr to RGB here.
  1785.  */
  1786. static void FETCH(f_ycbcr)( const struct gl_texture_image *texImage,
  1787.                             GLint i, GLint j, GLint k, GLfloat *texel )
  1788. {
  1789.    const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
  1790.    const GLushort *src1 = src0 + 1;                               /* odd */
  1791.    const GLubyte y0 = (*src0 >> 8) & 0xff;  /* luminance */
  1792.    const GLubyte cb = *src0 & 0xff;         /* chroma U */
  1793.    const GLubyte y1 = (*src1 >> 8) & 0xff;  /* luminance */
  1794.    const GLubyte cr = *src1 & 0xff;         /* chroma V */
  1795.    const GLubyte y = (i & 1) ? y1 : y0;     /* choose even/odd luminance */
  1796.    GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
  1797.    GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
  1798.    GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
  1799.    r *= (1.0F / 255.0F);
  1800.    g *= (1.0F / 255.0F);
  1801.    b *= (1.0F / 255.0F);
  1802.    texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
  1803.    texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
  1804.    texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
  1805.    texel[ACOMP] = 1.0F;
  1806. }
  1807.  
  1808. #if DIM == 3
  1809. static void store_texel_ycbcr(struct gl_texture_image *texImage,
  1810.                               GLint i, GLint j, GLint k, const void *texel)
  1811. {
  1812.    (void) texImage;
  1813.    (void) i;
  1814.    (void) j;
  1815.    (void) k;
  1816.    (void) texel;
  1817.    /* XXX to do */
  1818. }
  1819. #endif
  1820.  
  1821.  
  1822. /* MESA_FORMAT_YCBCR_REV *****************************************************/
  1823.  
  1824. /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats.
  1825.  * We convert YCbCr to RGB here.
  1826.  */
  1827. static void FETCH(f_ycbcr_rev)( const struct gl_texture_image *texImage,
  1828.                                 GLint i, GLint j, GLint k, GLfloat *texel )
  1829. {
  1830.    const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
  1831.    const GLushort *src1 = src0 + 1;                               /* odd */
  1832.    const GLubyte y0 = *src0 & 0xff;         /* luminance */
  1833.    const GLubyte cr = (*src0 >> 8) & 0xff;  /* chroma V */
  1834.    const GLubyte y1 = *src1 & 0xff;         /* luminance */
  1835.    const GLubyte cb = (*src1 >> 8) & 0xff;  /* chroma U */
  1836.    const GLubyte y = (i & 1) ? y1 : y0;     /* choose even/odd luminance */
  1837.    GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
  1838.    GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
  1839.    GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
  1840.    r *= (1.0F / 255.0F);
  1841.    g *= (1.0F / 255.0F);
  1842.    b *= (1.0F / 255.0F);
  1843.    texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
  1844.    texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
  1845.    texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
  1846.    texel[ACOMP] = 1.0F;
  1847. }
  1848.  
  1849. #if DIM == 3
  1850. static void store_texel_ycbcr_rev(struct gl_texture_image *texImage,
  1851.                                   GLint i, GLint j, GLint k, const void *texel)
  1852. {
  1853.    (void) texImage;
  1854.    (void) i;
  1855.    (void) j;
  1856.    (void) k;
  1857.    (void) texel;
  1858.    /* XXX to do */
  1859. }
  1860. #endif
  1861.  
  1862.  
  1863. /* MESA_TEXFORMAT_Z24_S8 ***************************************************/
  1864.  
  1865. static void FETCH(f_z24_s8)( const struct gl_texture_image *texImage,
  1866.                              GLint i, GLint j, GLint k, GLfloat *texel )
  1867. {
  1868.    /* only return Z, not stencil data */
  1869.    const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  1870.    const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
  1871.    texel[0] = ((*src) >> 8) * scale;
  1872.    ASSERT(texImage->TexFormat == MESA_FORMAT_Z24_S8);
  1873.    ASSERT(texel[0] >= 0.0F);
  1874.    ASSERT(texel[0] <= 1.0F);
  1875. }
  1876.  
  1877. #if DIM == 3
  1878. static void store_texel_z24_s8(struct gl_texture_image *texImage,
  1879.                                GLint i, GLint j, GLint k, const void *texel)
  1880. {
  1881.    /* only store Z, not stencil */
  1882.    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  1883.    GLfloat depth = *((GLfloat *) texel);
  1884.    GLuint zi = ((GLuint) (depth * 0xffffff)) << 8;
  1885.    *dst = zi | (*dst & 0xff);
  1886. }
  1887. #endif
  1888.  
  1889.  
  1890. /* MESA_TEXFORMAT_S8_Z24 ***************************************************/
  1891.  
  1892. static void FETCH(f_s8_z24)( const struct gl_texture_image *texImage,
  1893.                              GLint i, GLint j, GLint k, GLfloat *texel )
  1894. {
  1895.    /* only return Z, not stencil data */
  1896.    const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  1897.    const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
  1898.    texel[0] = ((*src) & 0x00ffffff) * scale;
  1899.    ASSERT(texImage->TexFormat == MESA_FORMAT_S8_Z24);
  1900.    ASSERT(texel[0] >= 0.0F);
  1901.    ASSERT(texel[0] <= 1.0F);
  1902. }
  1903.  
  1904. #if DIM == 3
  1905. static void store_texel_s8_z24(struct gl_texture_image *texImage,
  1906.                                GLint i, GLint j, GLint k, const void *texel)
  1907. {
  1908.    /* only store Z, not stencil */
  1909.    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
  1910.    GLfloat depth = *((GLfloat *) texel);
  1911.    GLuint zi = (GLuint) (depth * 0xffffff);
  1912.    *dst = zi | (*dst & 0xff000000);
  1913. }
  1914. #endif
  1915.  
  1916.  
  1917. #undef TEXEL_ADDR
  1918. #undef DIM
  1919. #undef FETCH
  1920.