home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mesa5.zip / mesa5src.zip / MesaDLL / texformat.cpp < prev    next >
C/C++ Source or Header  |  2002-10-29  |  25KB  |  791 lines

  1. /* $Id: texformat.c,v 1.18 2002/10/29 20:28:47 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  3.5
  6.  *
  7.  * Copyright (C) 1999-2001  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.  * Author:
  27.  *    Gareth Hughes
  28.  */
  29.  
  30. #include "glheader.h"
  31. #include "colormac.h"
  32. #include "context.h"
  33. #include "image.h"
  34. #include "imports.h"
  35. #include "mmath.h"
  36. #include "mtypes.h"
  37. #include "texformat.h"
  38. #include "teximage.h"
  39. #include "texstate.h"
  40.  
  41.  
  42. /* Texel fetch routines for all supported formats:
  43.  */
  44. #define DIM 1
  45. #include "texformat_tmp.h"
  46.  
  47. #define DIM 2
  48. #include "texformat_tmp.h"
  49.  
  50. #define DIM 3
  51. #include "texformat_tmp.h"
  52.  
  53. /* Have to have this so the FetchTexel function pointer is never NULL.
  54.  */
  55. static void fetch_null_texel( const struct gl_texture_image *texImage,
  56.                   GLint i, GLint j, GLint k, GLvoid *texel )
  57. {
  58.    GLchan *rgba = (GLchan *) texel;
  59.    rgba[RCOMP] = 0;
  60.    rgba[GCOMP] = 0;
  61.    rgba[BCOMP] = 0;
  62.    rgba[ACOMP] = 0;
  63. }
  64.  
  65.  
  66. /* =============================================================
  67.  * Default GLchan-based formats:
  68.  */
  69.  
  70. const struct gl_texture_format _mesa_texformat_rgba = {
  71.    MESA_FORMAT_RGBA,            /* MesaFormat */
  72.    GL_RGBA,                /* BaseFormat */
  73.    CHAN_BITS,                /* RedBits */
  74.    CHAN_BITS,                /* GreenBits */
  75.    CHAN_BITS,                /* BlueBits */
  76.    CHAN_BITS,                /* AlphaBits */
  77.    0,                    /* LuminanceBits */
  78.    0,                    /* IntensityBits */
  79.    0,                    /* IndexBits */
  80.    0,                    /* DepthBits */
  81.    4 * CHAN_BITS / 8,            /* TexelBytes */
  82.    fetch_1d_texel_rgba,            /* FetchTexel1D */
  83.    fetch_2d_texel_rgba,            /* FetchTexel2D */
  84.    fetch_3d_texel_rgba,            /* FetchTexel3D */
  85. };
  86.  
  87. const struct gl_texture_format _mesa_texformat_rgb = {
  88.    MESA_FORMAT_RGB,            /* MesaFormat */
  89.    GL_RGB,                /* BaseFormat */
  90.    CHAN_BITS,                /* RedBits */
  91.    CHAN_BITS,                /* GreenBits */
  92.    CHAN_BITS,                /* BlueBits */
  93.    0,                    /* AlphaBits */
  94.    0,                    /* LuminanceBits */
  95.    0,                    /* IntensityBits */
  96.    0,                    /* IndexBits */
  97.    0,                    /* DepthBits */
  98.    3 * CHAN_BITS / 8,            /* TexelBytes */
  99.    fetch_1d_texel_rgb,            /* FetchTexel1D */
  100.    fetch_2d_texel_rgb,            /* FetchTexel2D */
  101.    fetch_3d_texel_rgb,            /* FetchTexel3D */
  102. };
  103.  
  104. const struct gl_texture_format _mesa_texformat_alpha = {
  105.    MESA_FORMAT_ALPHA,            /* MesaFormat */
  106.    GL_ALPHA,                /* BaseFormat */
  107.    0,                    /* RedBits */
  108.    0,                    /* GreenBits */
  109.    0,                    /* BlueBits */
  110.    CHAN_BITS,                /* AlphaBits */
  111.    0,                    /* LuminanceBits */
  112.    0,                    /* IntensityBits */
  113.    0,                    /* IndexBits */
  114.    0,                    /* DepthBits */
  115.    CHAN_BITS / 8,            /* TexelBytes */
  116.    fetch_1d_texel_alpha,        /* FetchTexel1D */
  117.    fetch_2d_texel_alpha,        /* FetchTexel2D */
  118.    fetch_3d_texel_alpha,        /* FetchTexel3D */
  119. };
  120.  
  121. const struct gl_texture_format _mesa_texformat_luminance = {
  122.    MESA_FORMAT_LUMINANCE,        /* MesaFormat */
  123.    GL_LUMINANCE,            /* BaseFormat */
  124.    0,                    /* RedBits */
  125.    0,                    /* GreenBits */
  126.    0,                    /* BlueBits */
  127.    0,                    /* AlphaBits */
  128.    CHAN_BITS,                /* LuminanceBits */
  129.    0,                    /* IntensityBits */
  130.    0,                    /* IndexBits */
  131.    0,                    /* DepthBits */
  132.    CHAN_BITS / 8,            /* TexelBytes */
  133.    fetch_1d_texel_luminance,        /* FetchTexel1D */
  134.    fetch_2d_texel_luminance,        /* FetchTexel2D */
  135.    fetch_3d_texel_luminance,        /* FetchTexel3D */
  136. };
  137.  
  138. const struct gl_texture_format _mesa_texformat_luminance_alpha = {
  139.    MESA_FORMAT_LUMINANCE_ALPHA,        /* MesaFormat */
  140.    GL_LUMINANCE_ALPHA,            /* BaseFormat */
  141.    0,                    /* RedBits */
  142.    0,                    /* GreenBits */
  143.    0,                    /* BlueBits */
  144.    CHAN_BITS,                /* AlphaBits */
  145.    CHAN_BITS,                /* LuminanceBits */
  146.    0,                    /* IntensityBits */
  147.    0,                    /* IndexBits */
  148.    0,                    /* DepthBits */
  149.    2 * CHAN_BITS / 8,            /* TexelBytes */
  150.    fetch_1d_texel_luminance_alpha,    /* FetchTexel1D */
  151.    fetch_2d_texel_luminance_alpha,    /* FetchTexel2D */
  152.    fetch_3d_texel_luminance_alpha,    /* FetchTexel3D */
  153. };
  154.  
  155. const struct gl_texture_format _mesa_texformat_intensity = {
  156.    MESA_FORMAT_INTENSITY,        /* MesaFormat */
  157.    GL_INTENSITY,            /* BaseFormat */
  158.    0,                    /* RedBits */
  159.    0,                    /* GreenBits */
  160.    0,                    /* BlueBits */
  161.    0,                    /* AlphaBits */
  162.    0,                    /* LuminanceBits */
  163.    CHAN_BITS,                /* IntensityBits */
  164.    0,                    /* IndexBits */
  165.    0,                    /* DepthBits */
  166.    CHAN_BITS / 8,            /* TexelBytes */
  167.    fetch_1d_texel_intensity,        /* FetchTexel1D */
  168.    fetch_2d_texel_intensity,        /* FetchTexel2D */
  169.    fetch_3d_texel_intensity,        /* FetchTexel3D */
  170. };
  171.  
  172. const struct gl_texture_format _mesa_texformat_color_index = {
  173.    MESA_FORMAT_COLOR_INDEX,        /* MesaFormat */
  174.    GL_COLOR_INDEX,            /* BaseFormat */
  175.    0,                    /* RedBits */
  176.    0,                    /* GreenBits */
  177.    0,                    /* BlueBits */
  178.    0,                    /* AlphaBits */
  179.    0,                    /* LuminanceBits */
  180.    0,                    /* IntensityBits */
  181.    CHAN_BITS,                /* IndexBits */
  182.    0,                    /* DepthBits */
  183.    CHAN_BITS / 8,            /* TexelBytes */
  184.    fetch_1d_texel_color_index,        /* FetchTexel1D */
  185.    fetch_2d_texel_color_index,        /* FetchTexel2D */
  186.    fetch_3d_texel_color_index,        /* FetchTexel3D */
  187. };
  188.  
  189. const struct gl_texture_format _mesa_texformat_depth_component = {
  190.    MESA_FORMAT_DEPTH_COMPONENT,        /* MesaFormat */
  191.    GL_DEPTH_COMPONENT,            /* BaseFormat */
  192.    0,                    /* RedBits */
  193.    0,                    /* GreenBits */
  194.    0,                    /* BlueBits */
  195.    0,                    /* AlphaBits */
  196.    0,                    /* LuminanceBits */
  197.    0,                    /* IntensityBits */
  198.    0,                    /* IndexBits */
  199.    sizeof(GLfloat) * 8,            /* DepthBits */
  200.    sizeof(GLfloat),            /* TexelBytes */
  201.    fetch_1d_texel_depth_component,    /* FetchTexel1D */
  202.    fetch_2d_texel_depth_component,    /* FetchTexel2D */
  203.    fetch_3d_texel_depth_component,    /* FetchTexel3D */
  204. };
  205.  
  206.  
  207. /* =============================================================
  208.  * Hardware formats:
  209.  */
  210.  
  211. const struct gl_texture_format _mesa_texformat_rgba8888 = {
  212.    MESA_FORMAT_RGBA8888,        /* MesaFormat */
  213.    GL_RGBA,                /* BaseFormat */
  214.    8,                    /* RedBits */
  215.    8,                    /* GreenBits */
  216.    8,                    /* BlueBits */
  217.    8,                    /* AlphaBits */
  218.    0,                    /* LuminanceBits */
  219.    0,                    /* IntensityBits */
  220.    0,                    /* IndexBits */
  221.    0,                    /* DepthBits */
  222.    4,                    /* TexelBytes */
  223.    fetch_1d_texel_rgba8888,        /* FetchTexel1D */
  224.    fetch_2d_texel_rgba8888,        /* FetchTexel2D */
  225.    fetch_3d_texel_rgba8888,        /* FetchTexel3D */
  226. };
  227.  
  228. const struct gl_texture_format _mesa_texformat_argb8888 = {
  229.    MESA_FORMAT_ARGB8888,        /* MesaFormat */
  230.    GL_RGBA,                /* BaseFormat */
  231.    8,                    /* RedBits */
  232.    8,                    /* GreenBits */
  233.    8,                    /* BlueBits */
  234.    8,                    /* AlphaBits */
  235.    0,                    /* LuminanceBits */
  236.    0,                    /* IntensityBits */
  237.    0,                    /* IndexBits */
  238.    0,                    /* DepthBits */
  239.    4,                    /* TexelBytes */
  240.    fetch_1d_texel_argb8888,        /* FetchTexel1D */
  241.    fetch_2d_texel_argb8888,        /* FetchTexel2D */
  242.    fetch_3d_texel_argb8888,        /* FetchTexel3D */
  243. };
  244.  
  245. const struct gl_texture_format _mesa_texformat_rgb888 = {
  246.    MESA_FORMAT_RGB888,            /* MesaFormat */
  247.    GL_RGB,                /* BaseFormat */
  248.    8,                    /* RedBits */
  249.    8,                    /* GreenBits */
  250.    8,                    /* BlueBits */
  251.    0,                    /* AlphaBits */
  252.    0,                    /* LuminanceBits */
  253.    0,                    /* IntensityBits */
  254.    0,                    /* IndexBits */
  255.    0,                    /* DepthBits */
  256.    3,                    /* TexelBytes */
  257.    fetch_1d_texel_rgb888,        /* FetchTexel1D */
  258.    fetch_2d_texel_rgb888,        /* FetchTexel2D */
  259.    fetch_3d_texel_rgb888,        /* FetchTexel3D */
  260. };
  261.  
  262. const struct gl_texture_format _mesa_texformat_rgb565 = {
  263.    MESA_FORMAT_RGB565,            /* MesaFormat */
  264.    GL_RGB,                /* BaseFormat */
  265.    5,                    /* RedBits */
  266.    6,                    /* GreenBits */
  267.    5,                    /* BlueBits */
  268.    0,                    /* AlphaBits */
  269.    0,                    /* LuminanceBits */
  270.    0,                    /* IntensityBits */
  271.    0,                    /* IndexBits */
  272.    0,                    /* DepthBits */
  273.    2,                    /* TexelBytes */
  274.    fetch_1d_texel_rgb565,        /* FetchTexel1D */
  275.    fetch_2d_texel_rgb565,        /* FetchTexel2D */
  276.    fetch_3d_texel_rgb565,        /* FetchTexel3D */
  277. };
  278.  
  279. const struct gl_texture_format _mesa_texformat_argb4444 = {
  280.    MESA_FORMAT_ARGB4444,        /* MesaFormat */
  281.    GL_RGBA,                /* BaseFormat */
  282.    4,                    /* RedBits */
  283.    4,                    /* GreenBits */
  284.    4,                    /* BlueBits */
  285.    4,                    /* AlphaBits */
  286.    0,                    /* LuminanceBits */
  287.    0,                    /* IntensityBits */
  288.    0,                    /* IndexBits */
  289.    0,                    /* DepthBits */
  290.    2,                    /* TexelBytes */
  291.    fetch_1d_texel_argb4444,        /* FetchTexel1D */
  292.    fetch_2d_texel_argb4444,        /* FetchTexel2D */
  293.    fetch_3d_texel_argb4444,        /* FetchTexel3D */
  294. };
  295.  
  296. const struct gl_texture_format _mesa_texformat_argb1555 = {
  297.    MESA_FORMAT_ARGB1555,        /* MesaFormat */
  298.    GL_RGBA,                /* BaseFormat */
  299.    5,                    /* RedBits */
  300.    5,                    /* GreenBits */
  301.    5,                    /* BlueBits */
  302.    1,                    /* AlphaBits */
  303.    0,                    /* LuminanceBits */
  304.    0,                    /* IntensityBits */
  305.    0,                    /* IndexBits */
  306.    0,                    /* DepthBits */
  307.    2,                    /* TexelBytes */
  308.    fetch_1d_texel_argb1555,        /* FetchTexel1D */
  309.    fetch_2d_texel_argb1555,        /* FetchTexel2D */
  310.    fetch_3d_texel_argb1555,        /* FetchTexel3D */
  311. };
  312.  
  313. const struct gl_texture_format _mesa_texformat_al88 = {
  314.    MESA_FORMAT_AL88,            /* MesaFormat */
  315.    GL_LUMINANCE_ALPHA,            /* BaseFormat */
  316.    0,                    /* RedBits */
  317.    0,                    /* GreenBits */
  318.    0,                    /* BlueBits */
  319.    8,                    /* AlphaBits */
  320.    8,                    /* LuminanceBits */
  321.    0,                    /* IntensityBits */
  322.    0,                    /* IndexBits */
  323.    0,                    /* DepthBits */
  324.    2,                    /* TexelBytes */
  325.    fetch_1d_texel_al88,            /* FetchTexel1D */
  326.    fetch_2d_texel_al88,            /* FetchTexel2D */
  327.    fetch_3d_texel_al88,            /* FetchTexel3D */
  328. };
  329.  
  330. const struct gl_texture_format _mesa_texformat_rgb332 = {
  331.    MESA_FORMAT_RGB332,            /* MesaFormat */
  332.    GL_RGB,                /* BaseFormat */
  333.    3,                    /* RedBits */
  334.    3,                    /* GreenBits */
  335.    2,                    /* BlueBits */
  336.    0,                    /* AlphaBits */
  337.    0,                    /* LuminanceBits */
  338.    0,                    /* IntensityBits */
  339.    0,                    /* IndexBits */
  340.    0,                    /* DepthBits */
  341.    1,                    /* TexelBytes */
  342.    fetch_1d_texel_rgb332,        /* FetchTexel1D */
  343.    fetch_2d_texel_rgb332,        /* FetchTexel2D */
  344.    fetch_3d_texel_rgb332,        /* FetchTexel3D */
  345. };
  346.  
  347. const struct gl_texture_format _mesa_texformat_a8 = {
  348.    MESA_FORMAT_A8,            /* MesaFormat */
  349.    GL_ALPHA,                /* BaseFormat */
  350.    0,                    /* RedBits */
  351.    0,                    /* GreenBits */
  352.    0,                    /* BlueBits */
  353.    8,                    /* AlphaBits */
  354.    0,                    /* LuminanceBits */
  355.    0,                    /* IntensityBits */
  356.    0,                    /* IndexBits */
  357.    0,                    /* DepthBits */
  358.    1,                    /* TexelBytes */
  359.    fetch_1d_texel_a8,            /* FetchTexel1D */
  360.    fetch_2d_texel_a8,            /* FetchTexel2D */
  361.    fetch_3d_texel_a8,            /* FetchTexel3D */
  362. };
  363.  
  364. const struct gl_texture_format _mesa_texformat_l8 = {
  365.    MESA_FORMAT_L8,            /* MesaFormat */
  366.    GL_LUMINANCE,            /* BaseFormat */
  367.    0,                    /* RedBits */
  368.    0,                    /* GreenBits */
  369.    0,                    /* BlueBits */
  370.    0,                    /* AlphaBits */
  371.    8,                    /* LuminanceBits */
  372.    0,                    /* IntensityBits */
  373.    0,                    /* IndexBits */
  374.    0,                    /* DepthBits */
  375.    1,                    /* TexelBytes */
  376.    fetch_1d_texel_l8,            /* FetchTexel1D */
  377.    fetch_2d_texel_l8,            /* FetchTexel2D */
  378.    fetch_3d_texel_l8,            /* FetchTexel3D */
  379. };
  380.  
  381. const struct gl_texture_format _mesa_texformat_i8 = {
  382.    MESA_FORMAT_I8,            /* MesaFormat */
  383.    GL_INTENSITY,            /* BaseFormat */
  384.    0,                    /* RedBits */
  385.    0,                    /* GreenBits */
  386.    0,                    /* BlueBits */
  387.    0,                    /* AlphaBits */
  388.    0,                    /* LuminanceBits */
  389.    8,                    /* IntensityBits */
  390.    0,                    /* IndexBits */
  391.    0,                    /* DepthBits */
  392.    1,                    /* TexelBytes */
  393.    fetch_1d_texel_i8,            /* FetchTexel1D */
  394.    fetch_2d_texel_i8,            /* FetchTexel2D */
  395.    fetch_3d_texel_i8,            /* FetchTexel3D */
  396. };
  397.  
  398. const struct gl_texture_format _mesa_texformat_ci8 = {
  399.    MESA_FORMAT_CI8,            /* MesaFormat */
  400.    GL_COLOR_INDEX,            /* BaseFormat */
  401.    0,                    /* RedBits */
  402.    0,                    /* GreenBits */
  403.    0,                    /* BlueBits */
  404.    0,                    /* AlphaBits */
  405.    0,                    /* LuminanceBits */
  406.    0,                    /* IntensityBits */
  407.    8,                    /* IndexBits */
  408.    0,                    /* DepthBits */
  409.    1,                    /* TexelBytes */
  410.    fetch_1d_texel_ci8,            /* FetchTexel1D */
  411.    fetch_2d_texel_ci8,            /* FetchTexel2D */
  412.    fetch_3d_texel_ci8,            /* FetchTexel3D */
  413. };
  414.  
  415. const struct gl_texture_format _mesa_texformat_ycbcr = {
  416.    MESA_FORMAT_YCBCR,            /* MesaFormat */
  417.    GL_YCBCR_MESA,            /* BaseFormat */
  418.    0,                    /* RedBits */
  419.    0,                    /* GreenBits */
  420.    0,                    /* BlueBits */
  421.    0,                    /* AlphaBits */
  422.    0,                    /* LuminanceBits */
  423.    0,                    /* IntensityBits */
  424.    0,                    /* IndexBits */
  425.    0,                    /* DepthBits */
  426.    2,                    /* TexelBytes */
  427.    fetch_1d_texel_ycbcr,        /* FetchTexel1D */
  428.    fetch_2d_texel_ycbcr,        /* FetchTexel2D */
  429.    fetch_3d_texel_ycbcr,        /* FetchTexel3D */
  430. };
  431.  
  432.  
  433. const struct gl_texture_format _mesa_texformat_ycbcr_rev = {
  434.    MESA_FORMAT_YCBCR_REV,        /* MesaFormat */
  435.    GL_YCBCR_MESA,            /* BaseFormat */
  436.    0,                    /* RedBits */
  437.    0,                    /* GreenBits */
  438.    0,                    /* BlueBits */
  439.    0,                    /* AlphaBits */
  440.    0,                    /* LuminanceBits */
  441.    0,                    /* IntensityBits */
  442.    0,                    /* IndexBits */
  443.    0,                    /* DepthBits */
  444.    2,                    /* TexelBytes */
  445.    fetch_1d_texel_ycbcr_rev,        /* FetchTexel1D */
  446.    fetch_2d_texel_ycbcr_rev,        /* FetchTexel2D */
  447.    fetch_3d_texel_ycbcr_rev,        /* FetchTexel3D */
  448. };
  449.  
  450.  
  451. /* Big-endian */
  452. #if 0
  453. const struct gl_texture_format _mesa_texformat_abgr8888 = {
  454.    MESA_FORMAT_ABGR8888,        /* MesaFormat */
  455.    GL_RGBA,                /* BaseFormat */
  456.    GL_UNSIGNED_INT_8_8_8_8,        /* Type */
  457.    8,                    /* RedBits */
  458.    8,                    /* GreenBits */
  459.    8,                    /* BlueBits */
  460.    8,                    /* AlphaBits */
  461.    0,                    /* LuminanceBits */
  462.    0,                    /* IntensityBits */
  463.    0,                    /* IndexBits */
  464.    0,                    /* DepthBits */
  465.    4,                    /* TexelBytes */
  466.    fetch_1d_texel_abgr8888,        /* FetchTexel1D */
  467.    fetch_2d_texel_abgr8888,        /* FetchTexel2D */
  468.    fetch_3d_texel_abgr8888,        /* FetchTexel3D */
  469. };
  470.  
  471. const struct gl_texture_format _mesa_texformat_bgra8888 = {
  472.    MESA_FORMAT_BGRA8888,        /* MesaFormat */
  473.    GL_RGBA,                /* BaseFormat */
  474.    GL_UNSIGNED_INT_8_8_8_8,        /* Type */
  475.    8,                    /* RedBits */
  476.    8,                    /* GreenBits */
  477.    8,                    /* BlueBits */
  478.    8,                    /* AlphaBits */
  479.    0,                    /* LuminanceBits */
  480.    0,                    /* IntensityBits */
  481.    0,                    /* IndexBits */
  482.    0,                    /* DepthBits */
  483.    4,                    /* TexelBytes */
  484.    fetch_1d_texel_bgra8888,        /* FetchTexel1D */
  485.    fetch_2d_texel_bgra8888,        /* FetchTexel2D */
  486.    fetch_3d_texel_bgra8888,        /* FetchTexel3D */
  487. };
  488.  
  489. const struct gl_texture_format _mesa_texformat_bgr888 = {
  490.    MESA_FORMAT_BGR888,            /* MesaFormat */
  491.    GL_RGB,                /* BaseFormat */
  492.    GL_UNSIGNED_BYTE,            /* Type */
  493.    8,                    /* RedBits */
  494.    8,                    /* GreenBits */
  495.    8,                    /* BlueBits */
  496.    0,                    /* AlphaBits */
  497.    0,                    /* LuminanceBits */
  498.    0,                    /* IntensityBits */
  499.    0,                    /* IndexBits */
  500.    0,                    /* DepthBits */
  501.    3,                    /* TexelBytes */
  502.    fetch_1d_texel_bgr888,        /* FetchTexel1D */
  503.    fetch_2d_texel_bgr888,        /* FetchTexel2D */
  504.    fetch_3d_texel_bgr888,        /* FetchTexel3D */
  505. };
  506.  
  507. const struct gl_texture_format _mesa_texformat_bgr565 = {
  508.    MESA_FORMAT_BGR565,            /* MesaFormat */
  509.    GL_RGB,                /* BaseFormat */
  510.    GL_UNSIGNED_SHORT_5_6_5,        /* Type */
  511.    5,                    /* RedBits */
  512.    6,                    /* GreenBits */
  513.    5,                    /* BlueBits */
  514.    0,                    /* AlphaBits */
  515.    0,                    /* LuminanceBits */
  516.    0,                    /* IntensityBits */
  517.    0,                    /* IndexBits */
  518.    0,                    /* DepthBits */
  519.    2,                    /* TexelBytes */
  520.    fetch_1d_texel_bgr565,        /* FetchTexel1D */
  521.    fetch_2d_texel_bgr565,        /* FetchTexel2D */
  522.    fetch_3d_texel_bgr565,        /* FetchTexel3D */
  523. };
  524.  
  525. const struct gl_texture_format _mesa_texformat_bgra4444 = {
  526.    MESA_FORMAT_BGRA4444,        /* MesaFormat */
  527.    GL_RGBA,                /* BaseFormat */
  528.    GL_UNSIGNED_SHORT_4_4_4_4_REV,    /* Type */
  529.    4,                    /* RedBits */
  530.    4,                    /* GreenBits */
  531.    4,                    /* BlueBits */
  532.    4,                    /* AlphaBits */
  533.    0,                    /* LuminanceBits */
  534.    0,                    /* IntensityBits */
  535.    0,                    /* IndexBits */
  536.    0,                    /* DepthBits */
  537.    2,                    /* TexelBytes */
  538.    fetch_1d_texel_bgra4444,        /* FetchTexel1D */
  539.    fetch_2d_texel_bgra4444,        /* FetchTexel2D */
  540.    fetch_3d_texel_bgra4444,        /* FetchTexel3D */
  541. };
  542.  
  543. const struct gl_texture_format _mesa_texformat_bgra5551 = {
  544.    MESA_FORMAT_BGRA5551,        /* MesaFormat */
  545.    GL_RGBA,                /* BaseFormat */
  546.    GL_UNSIGNED_SHORT_1_5_5_5_REV,    /* Type */
  547.    5,                    /* RedBits */
  548.    5,                    /* GreenBits */
  549.    5,                    /* BlueBits */
  550.    1,                    /* AlphaBits */
  551.    0,                    /* LuminanceBits */
  552.    0,                    /* IntensityBits */
  553.    0,                    /* IndexBits */
  554.    0,                    /* DepthBits */
  555.    2,                    /* TexelBytes */
  556.    fetch_1d_texel_bgra1555,        /* FetchTexel1D */
  557.    fetch_2d_texel_bgra1555,        /* FetchTexel2D */
  558.    fetch_3d_texel_bgra1555,        /* FetchTexel3D */
  559. };
  560.  
  561. const struct gl_texture_format _mesa_texformat_la88 = {
  562.    MESA_FORMAT_LA88,            /* MesaFormat */
  563.    GL_LUMINANCE_ALPHA,            /* BaseFormat */
  564.    GL_UNSIGNED_BYTE,            /* Type */
  565.    0,                    /* RedBits */
  566.    0,                    /* GreenBits */
  567.    0,                    /* BlueBits */
  568.    8,                    /* AlphaBits */
  569.    8,                    /* LuminanceBits */
  570.    0,                    /* IntensityBits */
  571.    0,                    /* IndexBits */
  572.    0,                    /* DepthBits */
  573.    2,                    /* TexelBytes */
  574.    fetch_1d_texel_la88,            /* FetchTexel1D */
  575.    fetch_2d_texel_la88,            /* FetchTexel2D */
  576.    fetch_3d_texel_la88,            /* FetchTexel3D */
  577. };
  578.  
  579. const struct gl_texture_format _mesa_texformat_bgr233 = {
  580.    MESA_FORMAT_BGR233,            /* MesaFormat */
  581.    GL_RGB,                /* BaseFormat */
  582.    GL_UNSIGNED_BYTE_3_3_2,        /* Type */
  583.    3,                    /* RedBits */
  584.    3,                    /* GreenBits */
  585.    2,                    /* BlueBits */
  586.    0,                    /* AlphaBits */
  587.    0,                    /* LuminanceBits */
  588.    0,                    /* IntensityBits */
  589.    0,                    /* IndexBits */
  590.    0,                    /* DepthBits */
  591.    1,                    /* TexelBytes */
  592.    fetch_1d_texel_bgr233,        /* FetchTexel1D */
  593.    fetch_2d_texel_bgr233,        /* FetchTexel2D */
  594.    fetch_3d_texel_bgr233,        /* FetchTexel3D */
  595. };
  596. #endif
  597.  
  598. /* =============================================================
  599.  * Null format (useful for proxy textures):
  600.  */
  601.  
  602. const struct gl_texture_format _mesa_null_texformat = {
  603.    -1,                    /* MesaFormat */
  604.    0,                    /* BaseFormat */
  605.    0,                    /* RedBits */
  606.    0,                    /* GreenBits */
  607.    0,                    /* BlueBits */
  608.    0,                    /* AlphaBits */
  609.    0,                    /* LuminanceBits */
  610.    0,                    /* IntensityBits */
  611.    0,                    /* IndexBits */
  612.    0,                    /* DepthBits */
  613.    0,                    /* TexelBytes */
  614.    fetch_null_texel,            /* FetchTexel1D */
  615.    fetch_null_texel,            /* FetchTexel2D */
  616.    fetch_null_texel,            /* FetchTexel3D */
  617. };
  618.  
  619.  
  620. GLboolean
  621. _mesa_is_hardware_tex_format( const struct gl_texture_format *format )
  622. {
  623.    return (format->MesaFormat < MESA_FORMAT_RGBA);
  624. }
  625.  
  626.  
  627. /* Given an internal texture format (or 1, 2, 3, 4) return a pointer
  628.  * to a gl_texture_format which which to store the texture.
  629.  * This is called via ctx->Driver.ChooseTextureFormat().
  630.  * Hardware drivers typically override this function with a specialized
  631.  * version.
  632.  */
  633. const struct gl_texture_format *
  634. _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
  635.                          GLenum format, GLenum type )
  636. {
  637.    (void) format;
  638.    (void) type;
  639.  
  640.    switch ( internalFormat ) {
  641.       /* GH: Bias towards GL_RGB, GL_RGBA texture formats.  This has
  642.        * got to be better than sticking them way down the end of this
  643.        * huge list.
  644.        */
  645.    case 4:                /* Quake3 uses this... */
  646.    case GL_RGBA:
  647.       return &_mesa_texformat_rgba;
  648.  
  649.    case 3:                /* ... and this. */
  650.    case GL_RGB:
  651.       return &_mesa_texformat_rgb;
  652.  
  653.       /* GH: Okay, keep checking as normal.  Still test for GL_RGB,
  654.        * GL_RGBA formats first.
  655.        */
  656.    case GL_RGBA2:
  657.    case GL_RGBA4:
  658.    case GL_RGB5_A1:
  659.    case GL_RGBA8:
  660.    case GL_RGB10_A2:
  661.    case GL_RGBA12:
  662.    case GL_RGBA16:
  663.       return &_mesa_texformat_rgba;
  664.  
  665.    case GL_R3_G3_B2:
  666.    case GL_RGB4:
  667.    case GL_RGB5:
  668.    case GL_RGB8:
  669.    case GL_RGB10:
  670.    case GL_RGB12:
  671.    case GL_RGB16:
  672.       return &_mesa_texformat_rgb;
  673.  
  674.    case GL_ALPHA:
  675.    case GL_ALPHA4:
  676.    case GL_ALPHA8:
  677.    case GL_ALPHA12:
  678.    case GL_ALPHA16:
  679.       return &_mesa_texformat_alpha;
  680.  
  681.    case 1:
  682.    case GL_LUMINANCE:
  683.    case GL_LUMINANCE4:
  684.    case GL_LUMINANCE8:
  685.    case GL_LUMINANCE12:
  686.    case GL_LUMINANCE16:
  687.       return &_mesa_texformat_luminance;
  688.  
  689.    case 2:
  690.    case GL_LUMINANCE_ALPHA:
  691.    case GL_LUMINANCE4_ALPHA4:
  692.    case GL_LUMINANCE6_ALPHA2:
  693.    case GL_LUMINANCE8_ALPHA8:
  694.    case GL_LUMINANCE12_ALPHA4:
  695.    case GL_LUMINANCE12_ALPHA12:
  696.    case GL_LUMINANCE16_ALPHA16:
  697.       return &_mesa_texformat_luminance_alpha;
  698.  
  699.    case GL_INTENSITY:
  700.    case GL_INTENSITY4:
  701.    case GL_INTENSITY8:
  702.    case GL_INTENSITY12:
  703.    case GL_INTENSITY16:
  704.       return &_mesa_texformat_intensity;
  705.  
  706.    case GL_COLOR_INDEX:
  707.    case GL_COLOR_INDEX1_EXT:
  708.    case GL_COLOR_INDEX2_EXT:
  709.    case GL_COLOR_INDEX4_EXT:
  710.    case GL_COLOR_INDEX8_EXT:
  711.    case GL_COLOR_INDEX12_EXT:
  712.    case GL_COLOR_INDEX16_EXT:
  713.       return &_mesa_texformat_color_index;
  714.  
  715.    case GL_DEPTH_COMPONENT:
  716.    case GL_DEPTH_COMPONENT16_SGIX:
  717.    case GL_DEPTH_COMPONENT24_SGIX:
  718.    case GL_DEPTH_COMPONENT32_SGIX:
  719.       if (!ctx->Extensions.SGIX_depth_texture)
  720.      _mesa_problem(ctx, "depth format without GL_SGIX_depth_texture");
  721.       return &_mesa_texformat_depth_component;
  722.  
  723.    case GL_COMPRESSED_ALPHA_ARB:
  724.       if (!ctx->Extensions.ARB_texture_compression)
  725.      _mesa_problem(ctx, "texture compression extension not enabled");
  726.       return &_mesa_texformat_alpha;
  727.    case GL_COMPRESSED_LUMINANCE_ARB:
  728.       if (!ctx->Extensions.ARB_texture_compression)
  729.      _mesa_problem(ctx, "texture compression extension not enabled");
  730.       return &_mesa_texformat_luminance;
  731.    case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
  732.       if (!ctx->Extensions.ARB_texture_compression)
  733.      _mesa_problem(ctx, "texture compression extension not enabled");
  734.       return &_mesa_texformat_luminance_alpha;
  735.    case GL_COMPRESSED_INTENSITY_ARB:
  736.       if (!ctx->Extensions.ARB_texture_compression)
  737.      _mesa_problem(ctx, "texture compression extension not enabled");
  738.       return &_mesa_texformat_intensity;
  739.    case GL_COMPRESSED_RGB_ARB:
  740.       if (!ctx->Extensions.ARB_texture_compression)
  741.      _mesa_problem(ctx, "texture compression extension not enabled");
  742.       return &_mesa_texformat_rgb;
  743.    case GL_COMPRESSED_RGBA_ARB:
  744.       if (!ctx->Extensions.ARB_texture_compression)
  745.      _mesa_problem(ctx, "texture compression extension not enabled");
  746.       return &_mesa_texformat_rgba;
  747.  
  748.    /* GL_MESA_ycrcr_texture */
  749.    case GL_YCBCR_MESA:
  750.       if (type == GL_UNSIGNED_SHORT_8_8_MESA)
  751.          return &_mesa_texformat_ycbcr;
  752.       else
  753.          return &_mesa_texformat_ycbcr_rev;
  754.  
  755.    default:
  756.       _mesa_problem(ctx, "unexpected format in _mesa_choose_tex_format()");
  757.       return NULL;
  758.    }
  759. }
  760.  
  761.  
  762.  
  763.  
  764. /*
  765.  * Return the base texture format for the given compressed format
  766.  * Called via ctx->Driver.BaseCompressedTexFormat().
  767.  * This function is used by software rasterizers.  Hardware drivers
  768.  * which support texture compression should not use this function but
  769.  * a specialized function instead.
  770.  */
  771. GLint
  772. _mesa_base_compressed_texformat(GLcontext *ctx, GLint intFormat)
  773. {
  774.    switch (intFormat) {
  775.    case GL_COMPRESSED_ALPHA_ARB:
  776.       return GL_ALPHA;
  777.    case GL_COMPRESSED_LUMINANCE_ARB:
  778.       return GL_LUMINANCE;
  779.    case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
  780.       return GL_LUMINANCE_ALPHA;
  781.    case GL_COMPRESSED_INTENSITY_ARB:
  782.       return GL_INTENSITY;
  783.    case GL_COMPRESSED_RGB_ARB:
  784.       return GL_RGB;
  785.    case GL_COMPRESSED_RGBA_ARB:
  786.       return GL_RGBA;
  787.    default:
  788.       return -1;  /* not a recognized compressed format */
  789.    }
  790. }
  791.