| Brian Paul | e427666 | 2001-06-15 14:18:46 +0000 | [diff] [blame] | 1 | /* $Id: texformat.c,v 1.11 2001/06/15 14:18:46 brianp Exp $ */ |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 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 <gareth@valinux.com> |
| 28 | */ |
| 29 | |
| 30 | #ifdef PC_HEADER |
| 31 | #include "all.h" |
| 32 | #else |
| 33 | #include "glheader.h" |
| 34 | #include "colormac.h" |
| 35 | #include "context.h" |
| 36 | #include "image.h" |
| 37 | #include "mem.h" |
| 38 | #include "mmath.h" |
| 39 | #include "mtypes.h" |
| 40 | #include "texformat.h" |
| 41 | #include "teximage.h" |
| 42 | #include "texstate.h" |
| 43 | #include "swrast/s_span.h" |
| 44 | #endif |
| 45 | |
| 46 | |
| 47 | /* Texel fetch routines for all supported formats: |
| 48 | */ |
| 49 | #define DIM 1 |
| 50 | #include "texformat_tmp.h" |
| 51 | |
| 52 | #define DIM 2 |
| 53 | #include "texformat_tmp.h" |
| 54 | |
| 55 | #define DIM 3 |
| 56 | #include "texformat_tmp.h" |
| 57 | |
| 58 | /* Have to have this so the FetchTexel function pointer is never NULL. |
| 59 | */ |
| 60 | static void fetch_null_texel( const struct gl_texture_image *texImage, |
| 61 | GLint i, GLint j, GLint k, GLvoid *texel ) |
| 62 | { |
| 63 | GLchan *rgba = (GLchan *) texel; |
| 64 | rgba[RCOMP] = 0; |
| 65 | rgba[GCOMP] = 0; |
| 66 | rgba[BCOMP] = 0; |
| 67 | rgba[ACOMP] = 0; |
| 68 | } |
| 69 | |
| 70 | |
| Gareth Hughes | 5e23af2 | 2001-03-30 14:44:43 +0000 | [diff] [blame] | 71 | /* ============================================================= |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 72 | * Default GLchan-based formats: |
| 73 | */ |
| 74 | |
| 75 | const struct gl_texture_format _mesa_texformat_rgba = { |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 76 | MESA_FORMAT_RGBA, /* MesaFormat */ |
| Brian Paul | 1c85aa3 | 2001-04-20 16:46:04 +0000 | [diff] [blame] | 77 | GL_RGBA, /* BaseFormat */ |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 78 | CHAN_TYPE, /* Type */ |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 79 | CHAN_BITS, /* RedBits */ |
| 80 | CHAN_BITS, /* GreenBits */ |
| 81 | CHAN_BITS, /* BlueBits */ |
| 82 | CHAN_BITS, /* AlphaBits */ |
| 83 | 0, /* LuminanceBits */ |
| 84 | 0, /* IntensityBits */ |
| 85 | 0, /* IndexBits */ |
| 86 | 0, /* DepthBits */ |
| 87 | 4 * CHAN_BITS / 8, /* TexelBytes */ |
| 88 | fetch_1d_texel_rgba, /* FetchTexel1D */ |
| 89 | fetch_2d_texel_rgba, /* FetchTexel2D */ |
| 90 | fetch_3d_texel_rgba, /* FetchTexel3D */ |
| 91 | }; |
| 92 | |
| 93 | const struct gl_texture_format _mesa_texformat_rgb = { |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 94 | MESA_FORMAT_RGB, /* MesaFormat */ |
| Brian Paul | 1c85aa3 | 2001-04-20 16:46:04 +0000 | [diff] [blame] | 95 | GL_RGB, /* BaseFormat */ |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 96 | CHAN_TYPE, /* Type */ |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 97 | CHAN_BITS, /* RedBits */ |
| 98 | CHAN_BITS, /* GreenBits */ |
| 99 | CHAN_BITS, /* BlueBits */ |
| 100 | 0, /* AlphaBits */ |
| 101 | 0, /* LuminanceBits */ |
| 102 | 0, /* IntensityBits */ |
| 103 | 0, /* IndexBits */ |
| 104 | 0, /* DepthBits */ |
| 105 | 3 * CHAN_BITS / 8, /* TexelBytes */ |
| 106 | fetch_1d_texel_rgb, /* FetchTexel1D */ |
| 107 | fetch_2d_texel_rgb, /* FetchTexel2D */ |
| 108 | fetch_3d_texel_rgb, /* FetchTexel3D */ |
| 109 | }; |
| 110 | |
| 111 | const struct gl_texture_format _mesa_texformat_alpha = { |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 112 | MESA_FORMAT_ALPHA, /* MesaFormat */ |
| Brian Paul | 1c85aa3 | 2001-04-20 16:46:04 +0000 | [diff] [blame] | 113 | GL_ALPHA, /* BaseFormat */ |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 114 | CHAN_TYPE, /* Type */ |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 115 | 0, /* RedBits */ |
| 116 | 0, /* GreenBits */ |
| 117 | 0, /* BlueBits */ |
| 118 | CHAN_BITS, /* AlphaBits */ |
| 119 | 0, /* LuminanceBits */ |
| 120 | 0, /* IntensityBits */ |
| 121 | 0, /* IndexBits */ |
| 122 | 0, /* DepthBits */ |
| 123 | CHAN_BITS / 8, /* TexelBytes */ |
| 124 | fetch_1d_texel_alpha, /* FetchTexel1D */ |
| 125 | fetch_2d_texel_alpha, /* FetchTexel2D */ |
| 126 | fetch_3d_texel_alpha, /* FetchTexel3D */ |
| 127 | }; |
| 128 | |
| 129 | const struct gl_texture_format _mesa_texformat_luminance = { |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 130 | MESA_FORMAT_LUMINANCE, /* MesaFormat */ |
| Brian Paul | 1c85aa3 | 2001-04-20 16:46:04 +0000 | [diff] [blame] | 131 | GL_LUMINANCE, /* BaseFormat */ |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 132 | CHAN_TYPE, /* Type */ |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 133 | 0, /* RedBits */ |
| 134 | 0, /* GreenBits */ |
| 135 | 0, /* BlueBits */ |
| 136 | 0, /* AlphaBits */ |
| 137 | CHAN_BITS, /* LuminanceBits */ |
| 138 | 0, /* IntensityBits */ |
| 139 | 0, /* IndexBits */ |
| 140 | 0, /* DepthBits */ |
| 141 | CHAN_BITS / 8, /* TexelBytes */ |
| 142 | fetch_1d_texel_luminance, /* FetchTexel1D */ |
| 143 | fetch_2d_texel_luminance, /* FetchTexel2D */ |
| 144 | fetch_3d_texel_luminance, /* FetchTexel3D */ |
| 145 | }; |
| 146 | |
| 147 | const struct gl_texture_format _mesa_texformat_luminance_alpha = { |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 148 | MESA_FORMAT_LUMINANCE_ALPHA, /* MesaFormat */ |
| Brian Paul | 1c85aa3 | 2001-04-20 16:46:04 +0000 | [diff] [blame] | 149 | GL_LUMINANCE_ALPHA, /* BaseFormat */ |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 150 | CHAN_TYPE, /* Type */ |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 151 | 0, /* RedBits */ |
| 152 | 0, /* GreenBits */ |
| 153 | 0, /* BlueBits */ |
| 154 | CHAN_BITS, /* AlphaBits */ |
| 155 | CHAN_BITS, /* LuminanceBits */ |
| 156 | 0, /* IntensityBits */ |
| 157 | 0, /* IndexBits */ |
| 158 | 0, /* DepthBits */ |
| 159 | 2 * CHAN_BITS / 8, /* TexelBytes */ |
| 160 | fetch_1d_texel_luminance_alpha, /* FetchTexel1D */ |
| 161 | fetch_2d_texel_luminance_alpha, /* FetchTexel2D */ |
| 162 | fetch_3d_texel_luminance_alpha, /* FetchTexel3D */ |
| 163 | }; |
| 164 | |
| 165 | const struct gl_texture_format _mesa_texformat_intensity = { |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 166 | MESA_FORMAT_INTENSITY, /* MesaFormat */ |
| Brian Paul | 1c85aa3 | 2001-04-20 16:46:04 +0000 | [diff] [blame] | 167 | GL_INTENSITY, /* BaseFormat */ |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 168 | CHAN_TYPE, /* Type */ |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 169 | 0, /* RedBits */ |
| 170 | 0, /* GreenBits */ |
| 171 | 0, /* BlueBits */ |
| 172 | 0, /* AlphaBits */ |
| 173 | 0, /* LuminanceBits */ |
| 174 | CHAN_BITS, /* IntensityBits */ |
| 175 | 0, /* IndexBits */ |
| 176 | 0, /* DepthBits */ |
| 177 | CHAN_BITS / 8, /* TexelBytes */ |
| 178 | fetch_1d_texel_intensity, /* FetchTexel1D */ |
| 179 | fetch_2d_texel_intensity, /* FetchTexel2D */ |
| 180 | fetch_3d_texel_intensity, /* FetchTexel3D */ |
| 181 | }; |
| 182 | |
| 183 | const struct gl_texture_format _mesa_texformat_color_index = { |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 184 | MESA_FORMAT_COLOR_INDEX, /* MesaFormat */ |
| Brian Paul | 1c85aa3 | 2001-04-20 16:46:04 +0000 | [diff] [blame] | 185 | GL_COLOR_INDEX, /* BaseFormat */ |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 186 | CHAN_TYPE, /* Type */ |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 187 | 0, /* RedBits */ |
| 188 | 0, /* GreenBits */ |
| 189 | 0, /* BlueBits */ |
| 190 | 0, /* AlphaBits */ |
| 191 | 0, /* LuminanceBits */ |
| 192 | 0, /* IntensityBits */ |
| 193 | CHAN_BITS, /* IndexBits */ |
| 194 | 0, /* DepthBits */ |
| 195 | CHAN_BITS / 8, /* TexelBytes */ |
| 196 | fetch_1d_texel_color_index, /* FetchTexel1D */ |
| 197 | fetch_2d_texel_color_index, /* FetchTexel2D */ |
| 198 | fetch_3d_texel_color_index, /* FetchTexel3D */ |
| 199 | }; |
| 200 | |
| 201 | const struct gl_texture_format _mesa_texformat_depth_component = { |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 202 | MESA_FORMAT_DEPTH_COMPONENT, /* MesaFormat */ |
| Brian Paul | 1c85aa3 | 2001-04-20 16:46:04 +0000 | [diff] [blame] | 203 | GL_DEPTH_COMPONENT, /* BaseFormat */ |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 204 | GL_FLOAT, /* Type */ |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 205 | 0, /* RedBits */ |
| 206 | 0, /* GreenBits */ |
| 207 | 0, /* BlueBits */ |
| 208 | 0, /* AlphaBits */ |
| 209 | 0, /* LuminanceBits */ |
| 210 | 0, /* IntensityBits */ |
| 211 | 0, /* IndexBits */ |
| 212 | sizeof(GLfloat) * 8, /* DepthBits */ |
| 213 | sizeof(GLfloat), /* TexelBytes */ |
| 214 | fetch_1d_texel_depth_component, /* FetchTexel1D */ |
| 215 | fetch_2d_texel_depth_component, /* FetchTexel2D */ |
| 216 | fetch_3d_texel_depth_component, /* FetchTexel3D */ |
| 217 | }; |
| 218 | |
| 219 | |
| Gareth Hughes | 5e23af2 | 2001-03-30 14:44:43 +0000 | [diff] [blame] | 220 | /* ============================================================= |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 221 | * Hardware formats: |
| 222 | */ |
| 223 | |
| 224 | const struct gl_texture_format _mesa_texformat_rgba8888 = { |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 225 | MESA_FORMAT_RGBA8888, /* MesaFormat */ |
| Brian Paul | 1c85aa3 | 2001-04-20 16:46:04 +0000 | [diff] [blame] | 226 | GL_RGBA, /* BaseFormat */ |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 227 | GL_UNSIGNED_INT_8_8_8_8, /* Type */ |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 228 | 8, /* RedBits */ |
| 229 | 8, /* GreenBits */ |
| 230 | 8, /* BlueBits */ |
| 231 | 8, /* AlphaBits */ |
| 232 | 0, /* LuminanceBits */ |
| 233 | 0, /* IntensityBits */ |
| 234 | 0, /* IndexBits */ |
| 235 | 0, /* DepthBits */ |
| 236 | 4, /* TexelBytes */ |
| 237 | fetch_1d_texel_rgba8888, /* FetchTexel1D */ |
| 238 | fetch_2d_texel_rgba8888, /* FetchTexel2D */ |
| 239 | fetch_3d_texel_rgba8888, /* FetchTexel3D */ |
| 240 | }; |
| 241 | |
| 242 | const struct gl_texture_format _mesa_texformat_argb8888 = { |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 243 | MESA_FORMAT_ARGB8888, /* MesaFormat */ |
| Brian Paul | 1c85aa3 | 2001-04-20 16:46:04 +0000 | [diff] [blame] | 244 | GL_RGBA, /* BaseFormat */ |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 245 | GL_UNSIGNED_INT_8_8_8_8_REV, /* Type */ |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 246 | 8, /* RedBits */ |
| 247 | 8, /* GreenBits */ |
| 248 | 8, /* BlueBits */ |
| 249 | 8, /* AlphaBits */ |
| 250 | 0, /* LuminanceBits */ |
| 251 | 0, /* IntensityBits */ |
| 252 | 0, /* IndexBits */ |
| 253 | 0, /* DepthBits */ |
| 254 | 4, /* TexelBytes */ |
| 255 | fetch_1d_texel_argb8888, /* FetchTexel1D */ |
| 256 | fetch_2d_texel_argb8888, /* FetchTexel2D */ |
| 257 | fetch_3d_texel_argb8888, /* FetchTexel3D */ |
| 258 | }; |
| 259 | |
| 260 | const struct gl_texture_format _mesa_texformat_rgb888 = { |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 261 | MESA_FORMAT_RGB888, /* MesaFormat */ |
| Brian Paul | 1c85aa3 | 2001-04-20 16:46:04 +0000 | [diff] [blame] | 262 | GL_RGB, /* BaseFormat */ |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 263 | GL_UNSIGNED_BYTE, /* Type */ |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 264 | 8, /* RedBits */ |
| 265 | 8, /* GreenBits */ |
| 266 | 8, /* BlueBits */ |
| 267 | 0, /* AlphaBits */ |
| 268 | 0, /* LuminanceBits */ |
| 269 | 0, /* IntensityBits */ |
| 270 | 0, /* IndexBits */ |
| 271 | 0, /* DepthBits */ |
| 272 | 3, /* TexelBytes */ |
| 273 | fetch_1d_texel_rgb888, /* FetchTexel1D */ |
| 274 | fetch_2d_texel_rgb888, /* FetchTexel2D */ |
| 275 | fetch_3d_texel_rgb888, /* FetchTexel3D */ |
| 276 | }; |
| 277 | |
| 278 | const struct gl_texture_format _mesa_texformat_rgb565 = { |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 279 | MESA_FORMAT_RGB565, /* MesaFormat */ |
| Brian Paul | 1c85aa3 | 2001-04-20 16:46:04 +0000 | [diff] [blame] | 280 | GL_RGB, /* BaseFormat */ |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 281 | GL_UNSIGNED_SHORT_5_6_5, /* Type */ |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 282 | 5, /* RedBits */ |
| 283 | 6, /* GreenBits */ |
| 284 | 5, /* BlueBits */ |
| 285 | 0, /* AlphaBits */ |
| 286 | 0, /* LuminanceBits */ |
| 287 | 0, /* IntensityBits */ |
| 288 | 0, /* IndexBits */ |
| 289 | 0, /* DepthBits */ |
| 290 | 2, /* TexelBytes */ |
| 291 | fetch_1d_texel_rgb565, /* FetchTexel1D */ |
| 292 | fetch_2d_texel_rgb565, /* FetchTexel2D */ |
| 293 | fetch_3d_texel_rgb565, /* FetchTexel3D */ |
| 294 | }; |
| 295 | |
| 296 | const struct gl_texture_format _mesa_texformat_argb4444 = { |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 297 | MESA_FORMAT_ARGB4444, /* MesaFormat */ |
| Brian Paul | 1c85aa3 | 2001-04-20 16:46:04 +0000 | [diff] [blame] | 298 | GL_RGBA, /* BaseFormat */ |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 299 | GL_UNSIGNED_SHORT_4_4_4_4_REV, /* Type */ |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 300 | 4, /* RedBits */ |
| 301 | 4, /* GreenBits */ |
| 302 | 4, /* BlueBits */ |
| 303 | 4, /* AlphaBits */ |
| 304 | 0, /* LuminanceBits */ |
| 305 | 0, /* IntensityBits */ |
| 306 | 0, /* IndexBits */ |
| 307 | 0, /* DepthBits */ |
| 308 | 2, /* TexelBytes */ |
| 309 | fetch_1d_texel_argb4444, /* FetchTexel1D */ |
| 310 | fetch_2d_texel_argb4444, /* FetchTexel2D */ |
| 311 | fetch_3d_texel_argb4444, /* FetchTexel3D */ |
| 312 | }; |
| 313 | |
| 314 | const struct gl_texture_format _mesa_texformat_argb1555 = { |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 315 | MESA_FORMAT_ARGB1555, /* MesaFormat */ |
| Brian Paul | 1c85aa3 | 2001-04-20 16:46:04 +0000 | [diff] [blame] | 316 | GL_RGBA, /* BaseFormat */ |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 317 | GL_UNSIGNED_SHORT_1_5_5_5_REV, /* Type */ |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 318 | 5, /* RedBits */ |
| 319 | 5, /* GreenBits */ |
| 320 | 5, /* BlueBits */ |
| 321 | 1, /* AlphaBits */ |
| 322 | 0, /* LuminanceBits */ |
| 323 | 0, /* IntensityBits */ |
| 324 | 0, /* IndexBits */ |
| 325 | 0, /* DepthBits */ |
| 326 | 2, /* TexelBytes */ |
| 327 | fetch_1d_texel_argb1555, /* FetchTexel1D */ |
| 328 | fetch_2d_texel_argb1555, /* FetchTexel2D */ |
| 329 | fetch_3d_texel_argb1555, /* FetchTexel3D */ |
| 330 | }; |
| 331 | |
| 332 | const struct gl_texture_format _mesa_texformat_al88 = { |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 333 | MESA_FORMAT_AL88, /* MesaFormat */ |
| Brian Paul | 1c85aa3 | 2001-04-20 16:46:04 +0000 | [diff] [blame] | 334 | GL_LUMINANCE_ALPHA, /* BaseFormat */ |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 335 | GL_UNSIGNED_BYTE, /* Type */ |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 336 | 0, /* RedBits */ |
| 337 | 0, /* GreenBits */ |
| 338 | 0, /* BlueBits */ |
| 339 | 8, /* AlphaBits */ |
| 340 | 8, /* LuminanceBits */ |
| 341 | 0, /* IntensityBits */ |
| 342 | 0, /* IndexBits */ |
| 343 | 0, /* DepthBits */ |
| 344 | 2, /* TexelBytes */ |
| 345 | fetch_1d_texel_al88, /* FetchTexel1D */ |
| 346 | fetch_2d_texel_al88, /* FetchTexel2D */ |
| 347 | fetch_3d_texel_al88, /* FetchTexel3D */ |
| 348 | }; |
| 349 | |
| 350 | const struct gl_texture_format _mesa_texformat_rgb332 = { |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 351 | MESA_FORMAT_RGB332, /* MesaFormat */ |
| Brian Paul | 1c85aa3 | 2001-04-20 16:46:04 +0000 | [diff] [blame] | 352 | GL_RGB, /* BaseFormat */ |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 353 | GL_UNSIGNED_BYTE_3_3_2, /* Type */ |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 354 | 3, /* RedBits */ |
| 355 | 3, /* GreenBits */ |
| 356 | 2, /* BlueBits */ |
| 357 | 0, /* AlphaBits */ |
| 358 | 0, /* LuminanceBits */ |
| 359 | 0, /* IntensityBits */ |
| 360 | 0, /* IndexBits */ |
| 361 | 0, /* DepthBits */ |
| 362 | 1, /* TexelBytes */ |
| 363 | fetch_1d_texel_rgb332, /* FetchTexel1D */ |
| 364 | fetch_2d_texel_rgb332, /* FetchTexel2D */ |
| 365 | fetch_3d_texel_rgb332, /* FetchTexel3D */ |
| 366 | }; |
| 367 | |
| 368 | const struct gl_texture_format _mesa_texformat_a8 = { |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 369 | MESA_FORMAT_A8, /* MesaFormat */ |
| Brian Paul | 1c85aa3 | 2001-04-20 16:46:04 +0000 | [diff] [blame] | 370 | GL_ALPHA, /* BaseFormat */ |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 371 | GL_UNSIGNED_BYTE, /* Type */ |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 372 | 0, /* RedBits */ |
| 373 | 0, /* GreenBits */ |
| 374 | 0, /* BlueBits */ |
| 375 | 8, /* AlphaBits */ |
| 376 | 0, /* LuminanceBits */ |
| 377 | 0, /* IntensityBits */ |
| 378 | 0, /* IndexBits */ |
| 379 | 0, /* DepthBits */ |
| 380 | 1, /* TexelBytes */ |
| 381 | fetch_1d_texel_a8, /* FetchTexel1D */ |
| 382 | fetch_2d_texel_a8, /* FetchTexel2D */ |
| 383 | fetch_3d_texel_a8, /* FetchTexel3D */ |
| 384 | }; |
| 385 | |
| 386 | const struct gl_texture_format _mesa_texformat_l8 = { |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 387 | MESA_FORMAT_L8, /* MesaFormat */ |
| Brian Paul | 1c85aa3 | 2001-04-20 16:46:04 +0000 | [diff] [blame] | 388 | GL_LUMINANCE, /* BaseFormat */ |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 389 | GL_UNSIGNED_BYTE, /* Type */ |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 390 | 0, /* RedBits */ |
| 391 | 0, /* GreenBits */ |
| 392 | 0, /* BlueBits */ |
| 393 | 0, /* AlphaBits */ |
| 394 | 8, /* LuminanceBits */ |
| 395 | 0, /* IntensityBits */ |
| 396 | 0, /* IndexBits */ |
| 397 | 0, /* DepthBits */ |
| 398 | 1, /* TexelBytes */ |
| 399 | fetch_1d_texel_l8, /* FetchTexel1D */ |
| 400 | fetch_2d_texel_l8, /* FetchTexel2D */ |
| 401 | fetch_3d_texel_l8, /* FetchTexel3D */ |
| 402 | }; |
| 403 | |
| 404 | const struct gl_texture_format _mesa_texformat_i8 = { |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 405 | MESA_FORMAT_I8, /* MesaFormat */ |
| Brian Paul | 1c85aa3 | 2001-04-20 16:46:04 +0000 | [diff] [blame] | 406 | GL_INTENSITY, /* BaseFormat */ |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 407 | GL_UNSIGNED_BYTE, /* Type */ |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 408 | 0, /* RedBits */ |
| 409 | 0, /* GreenBits */ |
| 410 | 0, /* BlueBits */ |
| 411 | 0, /* AlphaBits */ |
| 412 | 0, /* LuminanceBits */ |
| 413 | 8, /* IntensityBits */ |
| 414 | 0, /* IndexBits */ |
| 415 | 0, /* DepthBits */ |
| 416 | 1, /* TexelBytes */ |
| 417 | fetch_1d_texel_i8, /* FetchTexel1D */ |
| 418 | fetch_2d_texel_i8, /* FetchTexel2D */ |
| 419 | fetch_3d_texel_i8, /* FetchTexel3D */ |
| 420 | }; |
| 421 | |
| 422 | const struct gl_texture_format _mesa_texformat_ci8 = { |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 423 | MESA_FORMAT_CI8, /* MesaFormat */ |
| Brian Paul | 1c85aa3 | 2001-04-20 16:46:04 +0000 | [diff] [blame] | 424 | GL_COLOR_INDEX, /* BaseFormat */ |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 425 | GL_UNSIGNED_BYTE, /* Type */ |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 426 | 0, /* RedBits */ |
| 427 | 0, /* GreenBits */ |
| 428 | 0, /* BlueBits */ |
| 429 | 0, /* AlphaBits */ |
| 430 | 0, /* LuminanceBits */ |
| 431 | 0, /* IntensityBits */ |
| 432 | 8, /* IndexBits */ |
| 433 | 0, /* DepthBits */ |
| 434 | 1, /* TexelBytes */ |
| 435 | fetch_1d_texel_ci8, /* FetchTexel1D */ |
| 436 | fetch_2d_texel_ci8, /* FetchTexel2D */ |
| 437 | fetch_3d_texel_ci8, /* FetchTexel3D */ |
| 438 | }; |
| 439 | |
| 440 | |
| Gareth Hughes | 5e23af2 | 2001-03-30 14:44:43 +0000 | [diff] [blame] | 441 | /* ============================================================= |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 442 | * Null format: |
| 443 | */ |
| 444 | |
| 445 | const struct gl_texture_format _mesa_null_texformat = { |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 446 | -1, /* MesaFormat */ |
| Brian Paul | 1c85aa3 | 2001-04-20 16:46:04 +0000 | [diff] [blame] | 447 | 0, /* BaseFormat */ |
| Gareth Hughes | 38f2866 | 2001-03-28 20:40:51 +0000 | [diff] [blame] | 448 | 0, /* Type */ |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 449 | 0, /* RedBits */ |
| 450 | 0, /* GreenBits */ |
| 451 | 0, /* BlueBits */ |
| 452 | 0, /* AlphaBits */ |
| 453 | 0, /* LuminanceBits */ |
| 454 | 0, /* IntensityBits */ |
| 455 | 0, /* IndexBits */ |
| 456 | 0, /* DepthBits */ |
| 457 | 0, /* TexelBytes */ |
| 458 | fetch_null_texel, /* FetchTexel1D */ |
| 459 | fetch_null_texel, /* FetchTexel2D */ |
| 460 | fetch_null_texel, /* FetchTexel3D */ |
| 461 | }; |
| 462 | |
| 463 | |
| 464 | |
| Brian Paul | 7d58f44 | 2001-04-04 21:54:20 +0000 | [diff] [blame] | 465 | GLboolean |
| 466 | _mesa_is_hardware_tex_format( const struct gl_texture_format *format ) |
| 467 | { |
| 468 | return (format->MesaFormat < MESA_FORMAT_RGBA); |
| 469 | } |
| 470 | |
| 471 | |
| Brian Paul | e427666 | 2001-06-15 14:18:46 +0000 | [diff] [blame] | 472 | /* Given an internal texture format (or 1, 2, 3, 4) return a pointer |
| 473 | * to a gl_texture_format which which to store the texture. |
| 474 | * This is called via ctx->Driver.ChooseTextureFormat(). |
| 475 | * Hardware drivers should not use this function, but instead a |
| 476 | * specialized function. |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 477 | */ |
| Brian Paul | 7d58f44 | 2001-04-04 21:54:20 +0000 | [diff] [blame] | 478 | const struct gl_texture_format * |
| 479 | _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat, |
| 480 | GLenum format, GLenum type ) |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 481 | { |
| Brian Paul | 7d58f44 | 2001-04-04 21:54:20 +0000 | [diff] [blame] | 482 | (void) format; |
| 483 | (void) type; |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 484 | |
| 485 | switch ( internalFormat ) { |
| 486 | /* GH: Bias towards GL_RGB, GL_RGBA texture formats. This has |
| 487 | * got to be better than sticking them way down the end of this |
| 488 | * huge list. |
| 489 | */ |
| 490 | case 4: /* Quake3 uses this... */ |
| 491 | case GL_RGBA: |
| Brian Paul | 7d58f44 | 2001-04-04 21:54:20 +0000 | [diff] [blame] | 492 | return &_mesa_texformat_rgba; |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 493 | |
| 494 | case 3: /* ... and this. */ |
| 495 | case GL_RGB: |
| Brian Paul | 7d58f44 | 2001-04-04 21:54:20 +0000 | [diff] [blame] | 496 | return &_mesa_texformat_rgb; |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 497 | |
| 498 | /* GH: Okay, keep checking as normal. Still test for GL_RGB, |
| 499 | * GL_RGBA formats first. |
| 500 | */ |
| 501 | case GL_RGBA2: |
| 502 | case GL_RGBA4: |
| 503 | case GL_RGB5_A1: |
| 504 | case GL_RGBA8: |
| 505 | case GL_RGB10_A2: |
| 506 | case GL_RGBA12: |
| 507 | case GL_RGBA16: |
| Brian Paul | 7d58f44 | 2001-04-04 21:54:20 +0000 | [diff] [blame] | 508 | return &_mesa_texformat_rgba; |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 509 | |
| 510 | case GL_R3_G3_B2: |
| 511 | case GL_RGB4: |
| 512 | case GL_RGB5: |
| 513 | case GL_RGB8: |
| 514 | case GL_RGB10: |
| 515 | case GL_RGB12: |
| 516 | case GL_RGB16: |
| Brian Paul | 7d58f44 | 2001-04-04 21:54:20 +0000 | [diff] [blame] | 517 | return &_mesa_texformat_rgb; |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 518 | |
| 519 | case GL_ALPHA: |
| 520 | case GL_ALPHA4: |
| 521 | case GL_ALPHA8: |
| 522 | case GL_ALPHA12: |
| 523 | case GL_ALPHA16: |
| Brian Paul | 7d58f44 | 2001-04-04 21:54:20 +0000 | [diff] [blame] | 524 | return &_mesa_texformat_alpha; |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 525 | |
| 526 | case 1: |
| 527 | case GL_LUMINANCE: |
| 528 | case GL_LUMINANCE4: |
| 529 | case GL_LUMINANCE8: |
| 530 | case GL_LUMINANCE12: |
| 531 | case GL_LUMINANCE16: |
| Brian Paul | 7d58f44 | 2001-04-04 21:54:20 +0000 | [diff] [blame] | 532 | return &_mesa_texformat_luminance; |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 533 | |
| 534 | case 2: |
| 535 | case GL_LUMINANCE_ALPHA: |
| 536 | case GL_LUMINANCE4_ALPHA4: |
| 537 | case GL_LUMINANCE6_ALPHA2: |
| 538 | case GL_LUMINANCE8_ALPHA8: |
| 539 | case GL_LUMINANCE12_ALPHA4: |
| 540 | case GL_LUMINANCE12_ALPHA12: |
| 541 | case GL_LUMINANCE16_ALPHA16: |
| Brian Paul | 7d58f44 | 2001-04-04 21:54:20 +0000 | [diff] [blame] | 542 | return &_mesa_texformat_luminance_alpha; |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 543 | |
| 544 | case GL_INTENSITY: |
| 545 | case GL_INTENSITY4: |
| 546 | case GL_INTENSITY8: |
| 547 | case GL_INTENSITY12: |
| 548 | case GL_INTENSITY16: |
| Brian Paul | 7d58f44 | 2001-04-04 21:54:20 +0000 | [diff] [blame] | 549 | return &_mesa_texformat_intensity; |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 550 | |
| 551 | case GL_COLOR_INDEX: |
| 552 | case GL_COLOR_INDEX1_EXT: |
| 553 | case GL_COLOR_INDEX2_EXT: |
| 554 | case GL_COLOR_INDEX4_EXT: |
| 555 | case GL_COLOR_INDEX8_EXT: |
| 556 | case GL_COLOR_INDEX12_EXT: |
| 557 | case GL_COLOR_INDEX16_EXT: |
| Brian Paul | 7d58f44 | 2001-04-04 21:54:20 +0000 | [diff] [blame] | 558 | return &_mesa_texformat_color_index; |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 559 | |
| 560 | case GL_DEPTH_COMPONENT: |
| 561 | case GL_DEPTH_COMPONENT16_SGIX: |
| 562 | case GL_DEPTH_COMPONENT24_SGIX: |
| 563 | case GL_DEPTH_COMPONENT32_SGIX: |
| Brian Paul | e427666 | 2001-06-15 14:18:46 +0000 | [diff] [blame] | 564 | if (!ctx->Extensions.SGIX_depth_texture) |
| 565 | _mesa_problem(ctx, "depth format without GL_SGIX_depth_texture"); |
| Brian Paul | 7d58f44 | 2001-04-04 21:54:20 +0000 | [diff] [blame] | 566 | return &_mesa_texformat_depth_component; |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 567 | |
| Brian Paul | e427666 | 2001-06-15 14:18:46 +0000 | [diff] [blame] | 568 | case GL_COMPRESSED_ALPHA_ARB: |
| 569 | if (!ctx->Extensions.ARB_texture_compression) |
| 570 | _mesa_problem(ctx, "texture compression extension not enabled"); |
| 571 | return &_mesa_texformat_alpha; |
| 572 | case GL_COMPRESSED_LUMINANCE_ARB: |
| 573 | if (!ctx->Extensions.ARB_texture_compression) |
| 574 | _mesa_problem(ctx, "texture compression extension not enabled"); |
| 575 | return &_mesa_texformat_luminance; |
| 576 | case GL_COMPRESSED_LUMINANCE_ALPHA_ARB: |
| 577 | if (!ctx->Extensions.ARB_texture_compression) |
| 578 | _mesa_problem(ctx, "texture compression extension not enabled"); |
| 579 | return &_mesa_texformat_luminance_alpha; |
| 580 | case GL_COMPRESSED_INTENSITY_ARB: |
| 581 | if (!ctx->Extensions.ARB_texture_compression) |
| 582 | _mesa_problem(ctx, "texture compression extension not enabled"); |
| 583 | return &_mesa_texformat_intensity; |
| 584 | case GL_COMPRESSED_RGB_ARB: |
| 585 | if (!ctx->Extensions.ARB_texture_compression) |
| 586 | _mesa_problem(ctx, "texture compression extension not enabled"); |
| 587 | return &_mesa_texformat_rgb; |
| 588 | case GL_COMPRESSED_RGBA_ARB: |
| 589 | if (!ctx->Extensions.ARB_texture_compression) |
| 590 | _mesa_problem(ctx, "texture compression extension not enabled"); |
| 591 | return &_mesa_texformat_rgba; |
| 592 | |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 593 | default: |
| Brian Paul | e427666 | 2001-06-15 14:18:46 +0000 | [diff] [blame] | 594 | _mesa_problem(ctx, "unexpected format in _mesa_choose_tex_format()"); |
| 595 | printf("intformat = %d %x\n", internalFormat, internalFormat); |
| Brian Paul | 7d58f44 | 2001-04-04 21:54:20 +0000 | [diff] [blame] | 596 | return NULL; |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 597 | } |
| Gareth Hughes | 2c3d34c | 2001-03-18 08:53:49 +0000 | [diff] [blame] | 598 | } |
| Brian Paul | e427666 | 2001-06-15 14:18:46 +0000 | [diff] [blame] | 599 | |
| 600 | |
| 601 | |
| 602 | |
| 603 | /* |
| 604 | * Return the base texture format for the given compressed format |
| 605 | * Called via ctx->Driver.BaseCompressedTexFormat(). |
| 606 | * This function is used by software rasterizers. Hardware drivers |
| 607 | * which support texture compression should not use this function but |
| 608 | * a specialized function instead. |
| 609 | */ |
| 610 | GLint |
| 611 | _mesa_base_compressed_texformat(GLcontext *ctx, GLint intFormat) |
| 612 | { |
| 613 | switch (intFormat) { |
| 614 | case GL_COMPRESSED_ALPHA_ARB: |
| 615 | return GL_ALPHA; |
| 616 | case GL_COMPRESSED_LUMINANCE_ARB: |
| 617 | return GL_LUMINANCE; |
| 618 | case GL_COMPRESSED_LUMINANCE_ALPHA_ARB: |
| 619 | return GL_LUMINANCE_ALPHA; |
| 620 | case GL_COMPRESSED_INTENSITY_ARB: |
| 621 | return GL_INTENSITY; |
| 622 | case GL_COMPRESSED_RGB_ARB: |
| 623 | return GL_RGB; |
| 624 | case GL_COMPRESSED_RGBA_ARB: |
| 625 | return GL_RGBA; |
| 626 | default: |
| 627 | return -1; /* not a recognized compressed format */ |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | |
| 632 | /* |
| 633 | * Called via ctx->Driver.CompressedTextureSize(). |
| 634 | * This function is only used by software rasterizers. |
| 635 | * Hardware drivers will have to implement a specialized function. |
| 636 | */ |
| 637 | GLint |
| 638 | _mesa_compressed_texture_size(GLcontext *ctx, |
| 639 | const struct gl_texture_image *texImage) |
| 640 | { |
| 641 | GLint b; |
| 642 | assert(texImage); |
| 643 | assert(texImage->TexFormat); |
| 644 | |
| 645 | b = texImage->Width * texImage->Height * texImage->Depth * |
| 646 | texImage->TexFormat->TexelBytes; |
| 647 | assert(b > 0); |
| 648 | return b; |
| 649 | } |