| Brian Paul | 7298e71 | 2000-11-07 16:40:37 +0000 | [diff] [blame^] | 1 | /* $Id: teximage.c,v 1.60 2000/11/07 16:40:37 brianp Exp $ */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2 | |
| 3 | /* |
| 4 | * Mesa 3-D graphics library |
| Brian Paul | 01e5475 | 2000-09-05 15:40:34 +0000 | [diff] [blame] | 5 | * Version: 3.5 |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 6 | * |
| Brian Paul | 663049a | 2000-01-31 23:10:16 +0000 | [diff] [blame] | 7 | * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 8 | * |
| 9 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 10 | * copy of this software and associated documentation files (the "Software"), |
| 11 | * to deal in the Software without restriction, including without limitation |
| 12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 13 | * and/or sell copies of the Software, and to permit persons to whom the |
| 14 | * Software is furnished to do so, subject to the following conditions: |
| 15 | * |
| 16 | * The above copyright notice and this permission notice shall be included |
| 17 | * in all copies or substantial portions of the Software. |
| 18 | * |
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 20 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 22 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 23 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 24 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 25 | */ |
| 26 | |
| 27 | |
| 28 | #ifdef PC_HEADER |
| 29 | #include "all.h" |
| 30 | #else |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 31 | #include "glheader.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 32 | #include "context.h" |
| Brian Paul | f93b3dd | 2000-08-30 18:22:28 +0000 | [diff] [blame] | 33 | #include "convolve.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 34 | #include "image.h" |
| Brian Paul | ebb248a | 2000-10-29 18:23:16 +0000 | [diff] [blame] | 35 | #include "macros.h" |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 36 | #include "mem.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 37 | #include "mmath.h" |
| Brian Paul | fa4525e | 2000-08-21 14:22:24 +0000 | [diff] [blame] | 38 | #include "state.h" |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 39 | #include "teximage.h" |
| 40 | #include "texstate.h" |
| 41 | #include "types.h" |
| Brian Paul | 7298e71 | 2000-11-07 16:40:37 +0000 | [diff] [blame^] | 42 | #include "swrast/s_span.h" /* XXX SWRAST hack */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 43 | #endif |
| 44 | |
| 45 | |
| 46 | /* |
| 47 | * NOTES: |
| 48 | * |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 49 | * Mesa's native texture datatype is GLchan. Native formats are |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 50 | * GL_ALPHA, GL_LUMINANCE, GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, GL_RGBA, |
| 51 | * and GL_COLOR_INDEX. |
| 52 | * Device drivers are free to implement any internal format they want. |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 53 | */ |
| 54 | |
| 55 | |
| Brian Paul | 4827179 | 2000-03-29 18:13:59 +0000 | [diff] [blame] | 56 | #ifdef DEBUG |
| Brian Paul | e5d68a2 | 2000-03-30 18:37:51 +0000 | [diff] [blame] | 57 | static void PrintTexture(const struct gl_texture_image *img) |
| Brian Paul | 4827179 | 2000-03-29 18:13:59 +0000 | [diff] [blame] | 58 | { |
| Brian Paul | e5d68a2 | 2000-03-30 18:37:51 +0000 | [diff] [blame] | 59 | int i, j, c; |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 60 | GLchan *data = img->Data; |
| Brian Paul | e5d68a2 | 2000-03-30 18:37:51 +0000 | [diff] [blame] | 61 | |
| 62 | if (!data) { |
| 63 | printf("No texture data\n"); |
| 64 | return; |
| 65 | } |
| 66 | |
| 67 | switch (img->Format) { |
| 68 | case GL_ALPHA: |
| 69 | case GL_LUMINANCE: |
| 70 | case GL_INTENSITY: |
| 71 | case GL_COLOR_INDEX: |
| 72 | c = 1; |
| 73 | break; |
| 74 | case GL_LUMINANCE_ALPHA: |
| 75 | c = 2; |
| 76 | break; |
| 77 | case GL_RGB: |
| 78 | c = 3; |
| 79 | break; |
| 80 | case GL_RGBA: |
| 81 | c = 4; |
| 82 | break; |
| 83 | default: |
| 84 | gl_problem(NULL, "error in PrintTexture\n"); |
| 85 | return; |
| 86 | } |
| 87 | |
| 88 | |
| 89 | for (i = 0; i < img->Height; i++) { |
| 90 | for (j = 0; j < img->Width; j++) { |
| Brian Paul | 4827179 | 2000-03-29 18:13:59 +0000 | [diff] [blame] | 91 | if (c==1) |
| 92 | printf("%02x ", data[0]); |
| 93 | else if (c==2) |
| Brian Paul | e5d68a2 | 2000-03-30 18:37:51 +0000 | [diff] [blame] | 94 | printf("%02x%02x ", data[0], data[1]); |
| Brian Paul | 4827179 | 2000-03-29 18:13:59 +0000 | [diff] [blame] | 95 | else if (c==3) |
| Brian Paul | e5d68a2 | 2000-03-30 18:37:51 +0000 | [diff] [blame] | 96 | printf("%02x%02x%02x ", data[0], data[1], data[2]); |
| Brian Paul | 4827179 | 2000-03-29 18:13:59 +0000 | [diff] [blame] | 97 | else if (c==4) |
| Brian Paul | e5d68a2 | 2000-03-30 18:37:51 +0000 | [diff] [blame] | 98 | printf("%02x%02x%02x%02x ", data[0], data[1], data[2], data[3]); |
| Brian Paul | 4827179 | 2000-03-29 18:13:59 +0000 | [diff] [blame] | 99 | data += c; |
| 100 | } |
| 101 | printf("\n"); |
| 102 | } |
| 103 | } |
| 104 | #endif |
| 105 | |
| 106 | |
| 107 | |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 108 | /* |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 109 | * Compute log base 2 of n. |
| 110 | * If n isn't an exact power of two return -1. |
| 111 | * If n<0 return -1. |
| 112 | */ |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 113 | static int |
| 114 | logbase2( int n ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 115 | { |
| 116 | GLint i = 1; |
| 117 | GLint log2 = 0; |
| 118 | |
| 119 | if (n<0) { |
| 120 | return -1; |
| 121 | } |
| 122 | |
| 123 | while ( n > i ) { |
| 124 | i *= 2; |
| 125 | log2++; |
| 126 | } |
| 127 | if (i != n) { |
| 128 | return -1; |
| 129 | } |
| 130 | else { |
| 131 | return log2; |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | |
| 136 | |
| 137 | /* |
| 138 | * Given an internal texture format enum or 1, 2, 3, 4 return the |
| 139 | * corresponding _base_ internal format: GL_ALPHA, GL_LUMINANCE, |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 140 | * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA. |
| 141 | * Return -1 if invalid enum. |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 142 | */ |
| Brian Paul | b132e8d | 2000-03-23 16:23:14 +0000 | [diff] [blame] | 143 | GLint |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 144 | _mesa_base_tex_format( GLcontext *ctx, GLint format ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 145 | { |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 146 | /* |
| 147 | * Ask the driver for the base format, if it doesn't |
| 148 | * know, it will return -1; |
| 149 | */ |
| 150 | if (ctx->Driver.BaseCompressedTexFormat) { |
| 151 | GLint ifmt = (*ctx->Driver.BaseCompressedTexFormat)(ctx, format); |
| 152 | if (ifmt >= 0) { |
| 153 | return ifmt; |
| 154 | } |
| 155 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 156 | switch (format) { |
| 157 | case GL_ALPHA: |
| 158 | case GL_ALPHA4: |
| 159 | case GL_ALPHA8: |
| 160 | case GL_ALPHA12: |
| 161 | case GL_ALPHA16: |
| 162 | return GL_ALPHA; |
| 163 | case 1: |
| 164 | case GL_LUMINANCE: |
| 165 | case GL_LUMINANCE4: |
| 166 | case GL_LUMINANCE8: |
| 167 | case GL_LUMINANCE12: |
| 168 | case GL_LUMINANCE16: |
| 169 | return GL_LUMINANCE; |
| 170 | case 2: |
| 171 | case GL_LUMINANCE_ALPHA: |
| 172 | case GL_LUMINANCE4_ALPHA4: |
| 173 | case GL_LUMINANCE6_ALPHA2: |
| 174 | case GL_LUMINANCE8_ALPHA8: |
| 175 | case GL_LUMINANCE12_ALPHA4: |
| 176 | case GL_LUMINANCE12_ALPHA12: |
| 177 | case GL_LUMINANCE16_ALPHA16: |
| 178 | return GL_LUMINANCE_ALPHA; |
| 179 | case GL_INTENSITY: |
| 180 | case GL_INTENSITY4: |
| 181 | case GL_INTENSITY8: |
| 182 | case GL_INTENSITY12: |
| 183 | case GL_INTENSITY16: |
| 184 | return GL_INTENSITY; |
| 185 | case 3: |
| 186 | case GL_RGB: |
| 187 | case GL_R3_G3_B2: |
| 188 | case GL_RGB4: |
| 189 | case GL_RGB5: |
| 190 | case GL_RGB8: |
| 191 | case GL_RGB10: |
| 192 | case GL_RGB12: |
| 193 | case GL_RGB16: |
| 194 | return GL_RGB; |
| 195 | case 4: |
| 196 | case GL_RGBA: |
| 197 | case GL_RGBA2: |
| 198 | case GL_RGBA4: |
| 199 | case GL_RGB5_A1: |
| 200 | case GL_RGBA8: |
| 201 | case GL_RGB10_A2: |
| 202 | case GL_RGBA12: |
| 203 | case GL_RGBA16: |
| 204 | return GL_RGBA; |
| 205 | case GL_COLOR_INDEX: |
| 206 | case GL_COLOR_INDEX1_EXT: |
| 207 | case GL_COLOR_INDEX2_EXT: |
| 208 | case GL_COLOR_INDEX4_EXT: |
| 209 | case GL_COLOR_INDEX8_EXT: |
| 210 | case GL_COLOR_INDEX12_EXT: |
| 211 | case GL_COLOR_INDEX16_EXT: |
| 212 | return GL_COLOR_INDEX; |
| 213 | default: |
| 214 | return -1; /* error */ |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | |
| 219 | |
| 220 | /* |
| 221 | * Given an internal texture format enum or 1, 2, 3, 4 return the |
| 222 | * corresponding _base_ internal format: GL_ALPHA, GL_LUMINANCE, |
| 223 | * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA. Return the |
| 224 | * number of components for the format. Return -1 if invalid enum. |
| 225 | */ |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 226 | static GLint |
| 227 | components_in_intformat( GLint format ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 228 | { |
| 229 | switch (format) { |
| 230 | case GL_ALPHA: |
| 231 | case GL_ALPHA4: |
| 232 | case GL_ALPHA8: |
| 233 | case GL_ALPHA12: |
| 234 | case GL_ALPHA16: |
| 235 | return 1; |
| 236 | case 1: |
| 237 | case GL_LUMINANCE: |
| 238 | case GL_LUMINANCE4: |
| 239 | case GL_LUMINANCE8: |
| 240 | case GL_LUMINANCE12: |
| 241 | case GL_LUMINANCE16: |
| 242 | return 1; |
| 243 | case 2: |
| 244 | case GL_LUMINANCE_ALPHA: |
| 245 | case GL_LUMINANCE4_ALPHA4: |
| 246 | case GL_LUMINANCE6_ALPHA2: |
| 247 | case GL_LUMINANCE8_ALPHA8: |
| 248 | case GL_LUMINANCE12_ALPHA4: |
| 249 | case GL_LUMINANCE12_ALPHA12: |
| 250 | case GL_LUMINANCE16_ALPHA16: |
| 251 | return 2; |
| 252 | case GL_INTENSITY: |
| 253 | case GL_INTENSITY4: |
| 254 | case GL_INTENSITY8: |
| 255 | case GL_INTENSITY12: |
| 256 | case GL_INTENSITY16: |
| 257 | return 1; |
| 258 | case 3: |
| 259 | case GL_RGB: |
| 260 | case GL_R3_G3_B2: |
| 261 | case GL_RGB4: |
| 262 | case GL_RGB5: |
| 263 | case GL_RGB8: |
| 264 | case GL_RGB10: |
| 265 | case GL_RGB12: |
| 266 | case GL_RGB16: |
| 267 | return 3; |
| 268 | case 4: |
| 269 | case GL_RGBA: |
| 270 | case GL_RGBA2: |
| 271 | case GL_RGBA4: |
| 272 | case GL_RGB5_A1: |
| 273 | case GL_RGBA8: |
| 274 | case GL_RGB10_A2: |
| 275 | case GL_RGBA12: |
| 276 | case GL_RGBA16: |
| 277 | return 4; |
| 278 | case GL_COLOR_INDEX: |
| 279 | case GL_COLOR_INDEX1_EXT: |
| 280 | case GL_COLOR_INDEX2_EXT: |
| 281 | case GL_COLOR_INDEX4_EXT: |
| 282 | case GL_COLOR_INDEX8_EXT: |
| 283 | case GL_COLOR_INDEX12_EXT: |
| 284 | case GL_COLOR_INDEX16_EXT: |
| 285 | return 1; |
| 286 | default: |
| 287 | return -1; /* error */ |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 292 | /* |
| 293 | * Return GL_TRUE if internalFormat is a compressed format, return GL_FALSE |
| 294 | * otherwise. |
| 295 | */ |
| 296 | static GLboolean |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 297 | is_compressed_format(GLcontext *ctx, GLenum internalFormat) |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 298 | { |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 299 | if (ctx->Driver.IsCompressedFormat) { |
| 300 | return (*ctx->Driver.IsCompressedFormat)(ctx, internalFormat); |
| 301 | } |
| 302 | return GL_FALSE; |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 306 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 307 | /* |
| 308 | * Examine the texImage->Format field and set the Red, Green, Blue, etc |
| 309 | * texel component sizes to default values. |
| 310 | * These fields are set only here by core Mesa but device drivers may |
| 311 | * overwritting these fields to indicate true texel resolution. |
| 312 | */ |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 313 | static void |
| 314 | set_teximage_component_sizes( struct gl_texture_image *texImage ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 315 | { |
| 316 | switch (texImage->Format) { |
| 317 | case GL_ALPHA: |
| 318 | texImage->RedBits = 0; |
| 319 | texImage->GreenBits = 0; |
| 320 | texImage->BlueBits = 0; |
| 321 | texImage->AlphaBits = 8; |
| 322 | texImage->IntensityBits = 0; |
| 323 | texImage->LuminanceBits = 0; |
| 324 | texImage->IndexBits = 0; |
| 325 | break; |
| 326 | case GL_LUMINANCE: |
| 327 | texImage->RedBits = 0; |
| 328 | texImage->GreenBits = 0; |
| 329 | texImage->BlueBits = 0; |
| 330 | texImage->AlphaBits = 0; |
| 331 | texImage->IntensityBits = 0; |
| 332 | texImage->LuminanceBits = 8; |
| 333 | texImage->IndexBits = 0; |
| 334 | break; |
| 335 | case GL_LUMINANCE_ALPHA: |
| 336 | texImage->RedBits = 0; |
| 337 | texImage->GreenBits = 0; |
| 338 | texImage->BlueBits = 0; |
| 339 | texImage->AlphaBits = 8; |
| 340 | texImage->IntensityBits = 0; |
| 341 | texImage->LuminanceBits = 8; |
| 342 | texImage->IndexBits = 0; |
| 343 | break; |
| 344 | case GL_INTENSITY: |
| 345 | texImage->RedBits = 0; |
| 346 | texImage->GreenBits = 0; |
| 347 | texImage->BlueBits = 0; |
| 348 | texImage->AlphaBits = 0; |
| 349 | texImage->IntensityBits = 8; |
| 350 | texImage->LuminanceBits = 0; |
| 351 | texImage->IndexBits = 0; |
| 352 | break; |
| Brian Paul | 91baaa3 | 1999-10-17 23:24:16 +0000 | [diff] [blame] | 353 | case GL_RED: |
| 354 | texImage->RedBits = 8; |
| 355 | texImage->GreenBits = 0; |
| 356 | texImage->BlueBits = 0; |
| 357 | texImage->AlphaBits = 0; |
| 358 | texImage->IntensityBits = 0; |
| 359 | texImage->LuminanceBits = 0; |
| 360 | texImage->IndexBits = 0; |
| 361 | break; |
| 362 | case GL_GREEN: |
| 363 | texImage->RedBits = 0; |
| 364 | texImage->GreenBits = 8; |
| 365 | texImage->BlueBits = 0; |
| 366 | texImage->AlphaBits = 0; |
| 367 | texImage->IntensityBits = 0; |
| 368 | texImage->LuminanceBits = 0; |
| 369 | texImage->IndexBits = 0; |
| 370 | break; |
| 371 | case GL_BLUE: |
| 372 | texImage->RedBits = 0; |
| 373 | texImage->GreenBits = 0; |
| 374 | texImage->BlueBits = 8; |
| 375 | texImage->AlphaBits = 0; |
| 376 | texImage->IntensityBits = 0; |
| 377 | texImage->LuminanceBits = 0; |
| 378 | texImage->IndexBits = 0; |
| 379 | break; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 380 | case GL_RGB: |
| Brian Paul | d53573d | 1999-10-19 20:36:20 +0000 | [diff] [blame] | 381 | case GL_BGR: |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 382 | texImage->RedBits = 8; |
| 383 | texImage->GreenBits = 8; |
| 384 | texImage->BlueBits = 8; |
| 385 | texImage->AlphaBits = 0; |
| 386 | texImage->IntensityBits = 0; |
| 387 | texImage->LuminanceBits = 0; |
| 388 | texImage->IndexBits = 0; |
| 389 | break; |
| 390 | case GL_RGBA: |
| Brian Paul | d53573d | 1999-10-19 20:36:20 +0000 | [diff] [blame] | 391 | case GL_BGRA: |
| 392 | case GL_ABGR_EXT: |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 393 | texImage->RedBits = 8; |
| 394 | texImage->GreenBits = 8; |
| 395 | texImage->BlueBits = 8; |
| 396 | texImage->AlphaBits = 8; |
| 397 | texImage->IntensityBits = 0; |
| 398 | texImage->LuminanceBits = 0; |
| 399 | texImage->IndexBits = 0; |
| 400 | break; |
| 401 | case GL_COLOR_INDEX: |
| 402 | texImage->RedBits = 0; |
| 403 | texImage->GreenBits = 0; |
| 404 | texImage->BlueBits = 0; |
| 405 | texImage->AlphaBits = 0; |
| 406 | texImage->IntensityBits = 0; |
| 407 | texImage->LuminanceBits = 0; |
| 408 | texImage->IndexBits = 8; |
| 409 | break; |
| 410 | default: |
| 411 | gl_problem(NULL, "unexpected format in set_teximage_component_sizes"); |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 416 | static void |
| 417 | set_tex_image(struct gl_texture_object *tObj, |
| 418 | GLenum target, GLint level, |
| 419 | struct gl_texture_image *texImage) |
| 420 | { |
| 421 | ASSERT(tObj); |
| 422 | ASSERT(texImage); |
| 423 | switch (target) { |
| 424 | case GL_TEXTURE_2D: |
| 425 | tObj->Image[level] = texImage; |
| 426 | return; |
| 427 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: |
| Brian Paul | 413d6a2 | 2000-05-26 14:44:59 +0000 | [diff] [blame] | 428 | tObj->Image[level] = texImage; |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 429 | return; |
| 430 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: |
| 431 | tObj->NegX[level] = texImage; |
| 432 | return; |
| 433 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: |
| 434 | tObj->PosY[level] = texImage; |
| 435 | return; |
| 436 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: |
| 437 | tObj->NegY[level] = texImage; |
| 438 | return; |
| 439 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: |
| 440 | tObj->PosZ[level] = texImage; |
| 441 | return; |
| 442 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: |
| 443 | tObj->NegZ[level] = texImage; |
| 444 | return; |
| 445 | default: |
| 446 | gl_problem(NULL, "bad target in set_tex_image()"); |
| 447 | return; |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | |
| Brian Paul | 77ce6da | 2000-03-20 23:40:12 +0000 | [diff] [blame] | 452 | /* |
| 453 | * Return new gl_texture_image struct with all fields initialized to zero. |
| 454 | */ |
| 455 | struct gl_texture_image * |
| Brian Paul | 021a525 | 2000-03-27 17:54:17 +0000 | [diff] [blame] | 456 | _mesa_alloc_texture_image( void ) |
| Brian Paul | 77ce6da | 2000-03-20 23:40:12 +0000 | [diff] [blame] | 457 | { |
| 458 | return CALLOC_STRUCT(gl_texture_image); |
| 459 | } |
| 460 | |
| 461 | |
| 462 | |
| 463 | /* |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 464 | * Initialize most fields of a gl_texture_image struct. |
| Brian Paul | 77ce6da | 2000-03-20 23:40:12 +0000 | [diff] [blame] | 465 | */ |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 466 | static void |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 467 | init_texture_image( GLcontext *ctx, |
| 468 | struct gl_texture_image *img, |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 469 | GLsizei width, GLsizei height, GLsizei depth, |
| 470 | GLint border, GLenum internalFormat ) |
| Brian Paul | 77ce6da | 2000-03-20 23:40:12 +0000 | [diff] [blame] | 471 | { |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 472 | ASSERT(img); |
| 473 | ASSERT(!img->Data); |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 474 | img->Format = (GLenum) _mesa_base_tex_format(ctx, internalFormat); |
| Brian Paul | 77ce6da | 2000-03-20 23:40:12 +0000 | [diff] [blame] | 475 | set_teximage_component_sizes( img ); |
| 476 | img->IntFormat = (GLenum) internalFormat; |
| 477 | img->Border = border; |
| 478 | img->Width = width; |
| 479 | img->Height = height; |
| 480 | img->Depth = depth; |
| 481 | img->WidthLog2 = logbase2(width - 2 * border); |
| 482 | if (height == 1) /* 1-D texture */ |
| 483 | img->HeightLog2 = 0; |
| 484 | else |
| 485 | img->HeightLog2 = logbase2(height - 2 * border); |
| 486 | if (depth == 1) /* 2-D texture */ |
| 487 | img->DepthLog2 = 0; |
| 488 | else |
| 489 | img->DepthLog2 = logbase2(depth - 2 * border); |
| 490 | img->Width2 = 1 << img->WidthLog2; |
| 491 | img->Height2 = 1 << img->HeightLog2; |
| 492 | img->Depth2 = 1 << img->DepthLog2; |
| 493 | img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2); |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 494 | img->IsCompressed = is_compressed_format(ctx, internalFormat); |
| Brian Paul | 77ce6da | 2000-03-20 23:40:12 +0000 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | |
| 498 | |
| 499 | void |
| Brian Paul | 021a525 | 2000-03-27 17:54:17 +0000 | [diff] [blame] | 500 | _mesa_free_texture_image( struct gl_texture_image *teximage ) |
| Brian Paul | 77ce6da | 2000-03-20 23:40:12 +0000 | [diff] [blame] | 501 | { |
| 502 | if (teximage->Data) { |
| 503 | FREE( teximage->Data ); |
| 504 | teximage->Data = NULL; |
| 505 | } |
| 506 | FREE( teximage ); |
| 507 | } |
| 508 | |
| 509 | |
| 510 | |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 511 | /* |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 512 | * Return number of bytes of storage needed to store a compressed texture |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 513 | * image. Only the driver knows for sure. If the driver can't help us, |
| 514 | * we must return 0. |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 515 | */ |
| 516 | GLuint |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 517 | _mesa_compressed_image_size(GLcontext *ctx, |
| 518 | GLenum internalFormat, |
| 519 | GLint numDimensions, |
| 520 | GLint width, |
| 521 | GLint height, |
| 522 | GLint depth) |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 523 | { |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 524 | if (ctx->Driver.CompressedImageSize) { |
| 525 | return (*ctx->Driver.CompressedImageSize)(ctx, internalFormat, |
| 526 | numDimensions, |
| 527 | width, height, depth); |
| 528 | } |
| 529 | else { |
| 530 | /* Shouldn't this be an internal error of some sort? */ |
| 531 | return 0; |
| 532 | } |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | |
| 536 | |
| 537 | /* |
| Brian Paul | 35d5301 | 2000-05-23 17:14:49 +0000 | [diff] [blame] | 538 | * Given a texture unit and a texture target, return the corresponding |
| 539 | * texture object. |
| 540 | */ |
| 541 | struct gl_texture_object * |
| Brian Paul | 01e5475 | 2000-09-05 15:40:34 +0000 | [diff] [blame] | 542 | _mesa_select_tex_object(GLcontext *ctx, const struct gl_texture_unit *texUnit, |
| Brian Paul | 35d5301 | 2000-05-23 17:14:49 +0000 | [diff] [blame] | 543 | GLenum target) |
| 544 | { |
| 545 | switch (target) { |
| 546 | case GL_TEXTURE_1D: |
| 547 | return texUnit->CurrentD[1]; |
| 548 | case GL_PROXY_TEXTURE_1D: |
| 549 | return ctx->Texture.Proxy1D; |
| 550 | case GL_TEXTURE_2D: |
| 551 | return texUnit->CurrentD[2]; |
| 552 | case GL_PROXY_TEXTURE_2D: |
| 553 | return ctx->Texture.Proxy2D; |
| 554 | case GL_TEXTURE_3D: |
| 555 | return texUnit->CurrentD[3]; |
| 556 | case GL_PROXY_TEXTURE_3D: |
| 557 | return ctx->Texture.Proxy3D; |
| 558 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: |
| 559 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: |
| 560 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: |
| 561 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: |
| 562 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: |
| 563 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 564 | return ctx->Extensions.ARB_texture_cube_map |
| Brian Paul | 35d5301 | 2000-05-23 17:14:49 +0000 | [diff] [blame] | 565 | ? texUnit->CurrentCubeMap : NULL; |
| 566 | case GL_PROXY_TEXTURE_CUBE_MAP_ARB: |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 567 | return ctx->Extensions.ARB_texture_cube_map |
| Brian Paul | 35d5301 | 2000-05-23 17:14:49 +0000 | [diff] [blame] | 568 | ? ctx->Texture.ProxyCubeMap : NULL; |
| 569 | default: |
| 570 | gl_problem(NULL, "bad target in _mesa_select_tex_object()"); |
| 571 | return NULL; |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | |
| 576 | /* |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 577 | * Return the texture image struct which corresponds to target and level |
| 578 | * for the given texture unit. |
| 579 | */ |
| 580 | struct gl_texture_image * |
| 581 | _mesa_select_tex_image(GLcontext *ctx, const struct gl_texture_unit *texUnit, |
| 582 | GLenum target, GLint level) |
| 583 | { |
| 584 | ASSERT(texUnit); |
| 585 | switch (target) { |
| 586 | case GL_TEXTURE_1D: |
| 587 | return texUnit->CurrentD[1]->Image[level]; |
| 588 | case GL_PROXY_TEXTURE_1D: |
| 589 | return ctx->Texture.Proxy1D->Image[level]; |
| 590 | case GL_TEXTURE_2D: |
| 591 | return texUnit->CurrentD[2]->Image[level]; |
| 592 | case GL_PROXY_TEXTURE_2D: |
| 593 | return ctx->Texture.Proxy2D->Image[level]; |
| 594 | case GL_TEXTURE_3D: |
| 595 | return texUnit->CurrentD[3]->Image[level]; |
| 596 | case GL_PROXY_TEXTURE_3D: |
| 597 | return ctx->Texture.Proxy3D->Image[level]; |
| 598 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 599 | if (ctx->Extensions.ARB_texture_cube_map) |
| Brian Paul | 413d6a2 | 2000-05-26 14:44:59 +0000 | [diff] [blame] | 600 | return texUnit->CurrentCubeMap->Image[level]; |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 601 | else |
| 602 | return NULL; |
| 603 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 604 | if (ctx->Extensions.ARB_texture_cube_map) |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 605 | return texUnit->CurrentCubeMap->NegX[level]; |
| 606 | else |
| 607 | return NULL; |
| 608 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 609 | if (ctx->Extensions.ARB_texture_cube_map) |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 610 | return texUnit->CurrentCubeMap->PosY[level]; |
| 611 | else |
| 612 | return NULL; |
| 613 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 614 | if (ctx->Extensions.ARB_texture_cube_map) |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 615 | return texUnit->CurrentCubeMap->NegY[level]; |
| 616 | else |
| 617 | return NULL; |
| 618 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 619 | if (ctx->Extensions.ARB_texture_cube_map) |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 620 | return texUnit->CurrentCubeMap->PosZ[level]; |
| 621 | else |
| 622 | return NULL; |
| 623 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 624 | if (ctx->Extensions.ARB_texture_cube_map) |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 625 | return texUnit->CurrentCubeMap->NegZ[level]; |
| 626 | else |
| 627 | return NULL; |
| 628 | case GL_PROXY_TEXTURE_CUBE_MAP_ARB: |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 629 | if (ctx->Extensions.ARB_texture_cube_map) |
| Brian Paul | 413d6a2 | 2000-05-26 14:44:59 +0000 | [diff] [blame] | 630 | return ctx->Texture.ProxyCubeMap->Image[level]; |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 631 | else |
| 632 | return NULL; |
| 633 | default: |
| 634 | gl_problem(ctx, "bad target in _mesa_select_tex_image()"); |
| 635 | return NULL; |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | |
| 640 | |
| Brian Paul | f93b3dd | 2000-08-30 18:22:28 +0000 | [diff] [blame] | 641 | /* |
| 642 | * Calling glTexImage and related functions when convolution is enabled |
| 643 | * with GL_REDUCE border mode causes some complications. |
| 644 | * The incoming image must be extra large so that the post-convolution |
| 645 | * image size is reduced to a power of two size (plus 2 * border). |
| 646 | * This function adjusts a texture width and height accordingly if |
| 647 | * convolution with GL_REDUCE is enabled. |
| 648 | */ |
| 649 | static void |
| 650 | adjust_texture_size_for_convolution(const GLcontext *ctx, GLuint dimensions, |
| 651 | GLsizei *width, GLsizei *height) |
| 652 | { |
| 653 | if (ctx->Pixel.Convolution1DEnabled |
| 654 | && dimensions == 1 |
| 655 | && ctx->Pixel.ConvolutionBorderMode[0] == GL_REDUCE) { |
| 656 | *width = *width - (MAX2(ctx->Convolution1D.Width, 1) - 1); |
| 657 | } |
| 658 | else if (ctx->Pixel.Convolution2DEnabled |
| 659 | && dimensions > 1 |
| 660 | && ctx->Pixel.ConvolutionBorderMode[1] == GL_REDUCE) { |
| 661 | *width = *width - (MAX2(ctx->Convolution2D.Width, 1) - 1); |
| 662 | *height = *height - (MAX2(ctx->Convolution2D.Height, 1) - 1); |
| 663 | } |
| 664 | else if (ctx->Pixel.Separable2DEnabled |
| 665 | && dimensions > 1 |
| 666 | && ctx->Pixel.ConvolutionBorderMode[2] == GL_REDUCE) { |
| 667 | *width = *width - (MAX2(ctx->Separable2D.Width, 1) - 1); |
| 668 | *height = *height - (MAX2(ctx->Separable2D.Height, 1) - 1); |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | |
| 673 | |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 674 | /* |
| 675 | * This function is used to move user image data into a texture image. |
| 676 | * We handle full texture images and subtexture images. We also take |
| 677 | * care of all image transfer operations here, including convolution. |
| 678 | * Input: |
| 679 | * dstXoffset, dstYoffset, dstZoffset - offsets in pixels |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 680 | * dstRowStride, dstImageStride - strides in GLchan's |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 681 | */ |
| 682 | static void |
| 683 | fill_texture_image( GLcontext *ctx, GLuint dimensions, |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 684 | GLenum texFormat, GLchan *texAddr, |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 685 | GLint srcWidth, GLint srcHeight, GLint srcDepth, |
| 686 | GLint dstXoffset, GLint dstYoffset, GLint dstZoffset, |
| 687 | GLint dstRowStride, GLint dstImageStride, |
| 688 | GLenum srcFormat, GLenum srcType, const GLvoid *srcAddr, |
| 689 | const struct gl_pixelstore_attrib *srcPacking) |
| 690 | { |
| 691 | GLint texComponents; |
| 692 | |
| 693 | ASSERT(ctx); |
| 694 | ASSERT(dimensions >= 1 && dimensions <= 3); |
| 695 | ASSERT(texAddr); |
| 696 | ASSERT(srcWidth >= 1); |
| 697 | ASSERT(srcHeight >= 1); |
| 698 | ASSERT(srcDepth >= 1); |
| 699 | ASSERT(dstXoffset >= 0); |
| 700 | ASSERT(dstYoffset >= 0); |
| 701 | ASSERT(dstZoffset >= 0); |
| 702 | ASSERT(dstRowStride >= 0); |
| 703 | ASSERT(dstImageStride >= 0); |
| 704 | ASSERT(srcAddr); |
| 705 | ASSERT(srcPacking); |
| 706 | |
| 707 | texComponents = components_in_intformat(texFormat); |
| 708 | |
| 709 | /* try common 2D texture cases first */ |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 710 | if (!ctx->_ImageTransferState && dimensions == 2 |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 711 | && srcType == GL_UNSIGNED_BYTE) { |
| 712 | |
| 713 | if (srcFormat == texFormat) { |
| 714 | /* This will cover the common GL_RGB, GL_RGBA, GL_ALPHA, |
| 715 | * GL_LUMINANCE_ALPHA, etc. texture formats. Use memcpy(). |
| 716 | */ |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 717 | const GLchan *src = (const GLchan *) _mesa_image_address( |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 718 | srcPacking, srcAddr, srcWidth, srcHeight, |
| 719 | srcFormat, srcType, 0, 0, 0); |
| 720 | const GLint srcRowStride = _mesa_image_row_stride(srcPacking, |
| 721 | srcWidth, srcFormat, srcType); |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 722 | const GLint widthInBytes = srcWidth * texComponents * sizeof(GLchan); |
| 723 | GLchan *dst = texAddr + dstYoffset * dstRowStride |
| 724 | + dstXoffset * texComponents; |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 725 | if (srcRowStride == widthInBytes && dstRowStride == widthInBytes) { |
| 726 | MEMCPY(dst, src, srcHeight * widthInBytes); |
| 727 | } |
| 728 | else { |
| 729 | GLint i; |
| 730 | for (i = 0; i < srcHeight; i++) { |
| 731 | MEMCPY(dst, src, widthInBytes); |
| 732 | src += srcRowStride; |
| 733 | dst += dstRowStride; |
| 734 | } |
| 735 | } |
| 736 | return; /* all done */ |
| 737 | } |
| 738 | else if (srcFormat == GL_RGBA && texFormat == GL_RGB) { |
| 739 | /* commonly used by Quake */ |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 740 | const GLchan *src = (const GLchan *) _mesa_image_address( |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 741 | srcPacking, srcAddr, srcWidth, srcHeight, |
| 742 | srcFormat, srcType, 0, 0, 0); |
| 743 | const GLint srcRowStride = _mesa_image_row_stride(srcPacking, |
| 744 | srcWidth, srcFormat, srcType); |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 745 | GLchan *dst = texAddr + dstYoffset * dstRowStride |
| 746 | + dstXoffset * texComponents; |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 747 | GLint i, j; |
| 748 | for (i = 0; i < srcHeight; i++) { |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 749 | const GLchan *s = src; |
| 750 | GLchan *d = dst; |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 751 | for (j = 0; j < srcWidth; j++) { |
| 752 | *d++ = *s++; /*red*/ |
| 753 | *d++ = *s++; /*green*/ |
| 754 | *d++ = *s++; /*blue*/ |
| 755 | s++; /*alpha*/ |
| 756 | } |
| 757 | src += srcRowStride; |
| 758 | dst += dstRowStride; |
| 759 | } |
| 760 | return; /* all done */ |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | /* |
| 765 | * General case solutions |
| 766 | */ |
| 767 | if (texFormat == GL_COLOR_INDEX) { |
| 768 | /* color index texture */ |
| 769 | const GLenum texType = GL_UNSIGNED_BYTE; |
| 770 | GLint img, row; |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 771 | GLchan *dest = texAddr + dstZoffset * dstImageStride |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 772 | + dstYoffset * dstRowStride |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 773 | + dstXoffset * texComponents; |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 774 | for (img = 0; img < srcDepth; img++) { |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 775 | GLchan *destRow = dest; |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 776 | for (row = 0; row < srcHeight; row++) { |
| 777 | const GLvoid *src = _mesa_image_address(srcPacking, |
| 778 | srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0); |
| 779 | _mesa_unpack_index_span(ctx, srcWidth, texType, destRow, |
| 780 | srcType, src, srcPacking, |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 781 | ctx->_ImageTransferState); |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 782 | destRow += dstRowStride; |
| 783 | } |
| 784 | dest += dstImageStride; |
| 785 | } |
| 786 | } |
| 787 | else { |
| 788 | /* regular, color texture */ |
| 789 | if ((dimensions == 1 && ctx->Pixel.Convolution1DEnabled) || |
| 790 | (dimensions >= 2 && ctx->Pixel.Convolution2DEnabled) || |
| 791 | (dimensions >= 2 && ctx->Pixel.Separable2DEnabled)) { |
| 792 | /* |
| 793 | * Fill texture image with convolution |
| 794 | */ |
| 795 | GLint img, row; |
| 796 | GLint convWidth = srcWidth, convHeight = srcHeight; |
| 797 | GLfloat *tmpImage, *convImage; |
| 798 | tmpImage = (GLfloat *) MALLOC(srcWidth * srcHeight * 4 * sizeof(GLfloat)); |
| 799 | if (!tmpImage) { |
| 800 | gl_error(ctx, GL_OUT_OF_MEMORY, "glTexImage"); |
| 801 | return; |
| 802 | } |
| 803 | convImage = (GLfloat *) MALLOC(srcWidth * srcHeight * 4 * sizeof(GLfloat)); |
| 804 | if (!convImage) { |
| 805 | gl_error(ctx, GL_OUT_OF_MEMORY, "glTexImage"); |
| 806 | FREE(tmpImage); |
| 807 | return; |
| 808 | } |
| 809 | |
| 810 | for (img = 0; img < srcDepth; img++) { |
| 811 | const GLfloat *srcf; |
| 812 | GLfloat *dstf = tmpImage; |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 813 | GLchan *dest; |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 814 | |
| 815 | /* unpack and do transfer ops up to convolution */ |
| 816 | for (row = 0; row < srcHeight; row++) { |
| 817 | const GLvoid *src = _mesa_image_address(srcPacking, |
| 818 | srcAddr, srcWidth, srcHeight, |
| 819 | srcFormat, srcType, img, row, 0); |
| 820 | _mesa_unpack_float_color_span(ctx, srcWidth, GL_RGBA, dstf, |
| 821 | srcFormat, srcType, src, srcPacking, |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 822 | ctx->_ImageTransferState & IMAGE_PRE_CONVOLUTION_BITS, |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 823 | GL_TRUE); |
| 824 | dstf += srcWidth * 4; |
| 825 | } |
| 826 | |
| 827 | /* convolve */ |
| 828 | if (dimensions == 1) { |
| 829 | ASSERT(ctx->Pixel.Convolution1DEnabled); |
| 830 | _mesa_convolve_1d_image(ctx, &convWidth, tmpImage, convImage); |
| 831 | } |
| 832 | else { |
| 833 | if (ctx->Pixel.Convolution2DEnabled) { |
| 834 | _mesa_convolve_2d_image(ctx, &convWidth, &convHeight, |
| 835 | tmpImage, convImage); |
| 836 | } |
| 837 | else { |
| 838 | ASSERT(ctx->Pixel.Separable2DEnabled); |
| 839 | _mesa_convolve_sep_image(ctx, &convWidth, &convHeight, |
| 840 | tmpImage, convImage); |
| 841 | } |
| 842 | } |
| 843 | |
| 844 | /* packing and transfer ops after convolution */ |
| 845 | srcf = convImage; |
| 846 | dest = texAddr + (dstZoffset + img) * dstImageStride |
| 847 | + dstYoffset * dstRowStride; |
| 848 | for (row = 0; row < convHeight; row++) { |
| 849 | _mesa_pack_float_rgba_span(ctx, convWidth, |
| 850 | (const GLfloat (*)[4]) srcf, |
| 851 | texFormat, GL_UNSIGNED_BYTE, |
| 852 | dest, &_mesa_native_packing, |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 853 | ctx->_ImageTransferState |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 854 | & IMAGE_POST_CONVOLUTION_BITS); |
| 855 | srcf += convWidth * 4; |
| 856 | dest += dstRowStride; |
| 857 | } |
| 858 | } |
| 859 | |
| 860 | FREE(convImage); |
| 861 | FREE(tmpImage); |
| 862 | } |
| 863 | else { |
| 864 | /* |
| 865 | * no convolution |
| 866 | */ |
| 867 | GLint img, row; |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 868 | GLchan *dest = texAddr + dstZoffset * dstImageStride |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 869 | + dstYoffset * dstRowStride |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 870 | + dstXoffset * texComponents; |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 871 | for (img = 0; img < srcDepth; img++) { |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 872 | GLchan *destRow = dest; |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 873 | for (row = 0; row < srcHeight; row++) { |
| Brian Paul | 01e5475 | 2000-09-05 15:40:34 +0000 | [diff] [blame] | 874 | const GLvoid *srcRow = _mesa_image_address(srcPacking, |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 875 | srcAddr, srcWidth, srcHeight, |
| 876 | srcFormat, srcType, img, row, 0); |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 877 | _mesa_unpack_chan_color_span(ctx, srcWidth, texFormat, destRow, |
| Brian Paul | 01e5475 | 2000-09-05 15:40:34 +0000 | [diff] [blame] | 878 | srcFormat, srcType, srcRow, srcPacking, |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 879 | ctx->_ImageTransferState); |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 880 | destRow += dstRowStride; |
| 881 | } |
| 882 | dest += dstImageStride; |
| 883 | } |
| 884 | } |
| 885 | } |
| 886 | } |
| 887 | |
| 888 | |
| 889 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 890 | /* Need this to prevent an out-of-bounds memory access when using |
| 891 | * X86 optimized code. |
| 892 | */ |
| 893 | #ifdef USE_X86_ASM |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 894 | # define EXTRA_BYTE sizeof(GLchan) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 895 | #else |
| 896 | # define EXTRA_BYTE 0 |
| 897 | #endif |
| 898 | |
| 899 | |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 900 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 901 | /* |
| Brian Paul | 43911c8 | 2000-03-21 00:49:33 +0000 | [diff] [blame] | 902 | * Called by glTexImage[123]D. Fill in a texture image with data given |
| 903 | * by the client. All pixel transfer and unpack modes are handled here. |
| Brian Paul | 5a0d3dc | 2000-08-31 15:24:39 +0000 | [diff] [blame] | 904 | * Input: dimensions (1, 2, or 3) |
| 905 | * texImage - destination texture image (we'll malloc the memory) |
| 906 | * width, height, depth - size of source image |
| 907 | * srcFormat, srcType - source image format and type |
| 908 | * pixels - source image data |
| 909 | * srcPacking - source image packing parameters |
| 910 | * |
| Brian Paul | 43911c8 | 2000-03-21 00:49:33 +0000 | [diff] [blame] | 911 | * NOTE: All texture image parameters should have already been error checked. |
| Brian Paul | 5a0d3dc | 2000-08-31 15:24:39 +0000 | [diff] [blame] | 912 | * |
| 913 | * NOTE: the texImage dimensions and source image dimensions must be correct |
| 914 | * with respect to convolution with border mode = reduce. |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 915 | */ |
| Brian Paul | 43911c8 | 2000-03-21 00:49:33 +0000 | [diff] [blame] | 916 | static void |
| Brian Paul | f93b3dd | 2000-08-30 18:22:28 +0000 | [diff] [blame] | 917 | make_texture_image( GLcontext *ctx, GLuint dimensions, |
| Brian Paul | 43911c8 | 2000-03-21 00:49:33 +0000 | [diff] [blame] | 918 | struct gl_texture_image *texImage, |
| Brian Paul | 5a0d3dc | 2000-08-31 15:24:39 +0000 | [diff] [blame] | 919 | GLint width, GLint height, GLint depth, |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 920 | GLenum srcFormat, GLenum srcType, const GLvoid *pixels, |
| Brian Paul | f93b3dd | 2000-08-30 18:22:28 +0000 | [diff] [blame] | 921 | const struct gl_pixelstore_attrib *srcPacking) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 922 | { |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 923 | const GLint internalFormat = texImage->IntFormat; |
| 924 | const GLint components = components_in_intformat(internalFormat); |
| 925 | GLint convWidth = width, convHeight = height; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 926 | |
| Brian Paul | 9499e01 | 2000-10-30 16:32:42 +0000 | [diff] [blame] | 927 | if (ctx->NewState & _NEW_PIXEL) |
| 928 | gl_update_state(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 929 | |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 930 | if (ctx->_ImageTransferState & IMAGE_CONVOLUTION_BIT) { |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 931 | adjust_texture_size_for_convolution(ctx, dimensions, |
| 932 | &convWidth, &convHeight); |
| 933 | } |
| Brian Paul | 43911c8 | 2000-03-21 00:49:33 +0000 | [diff] [blame] | 934 | |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 935 | texImage->Data = (GLchan *) MALLOC(convWidth * convHeight * depth |
| 936 | * components * sizeof(GLchan) + EXTRA_BYTE); |
| Brian Paul | 43911c8 | 2000-03-21 00:49:33 +0000 | [diff] [blame] | 937 | if (!texImage->Data) |
| 938 | return; /* out of memory */ |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 939 | |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 940 | fill_texture_image(ctx, dimensions, texImage->Format, texImage->Data, |
| 941 | width, height, depth, 0, 0, 0, |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 942 | convWidth * components * sizeof(GLchan), |
| 943 | convWidth * convHeight * components * sizeof(GLchan), |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 944 | srcFormat, srcType, pixels, srcPacking); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | |
| 948 | |
| 949 | /* |
| 950 | * glTexImage[123]D can accept a NULL image pointer. In this case we |
| 951 | * create a texture image with unspecified image contents per the OpenGL |
| Brian Paul | 43911c8 | 2000-03-21 00:49:33 +0000 | [diff] [blame] | 952 | * spec. This function creates an empty image for the given texture image. |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 953 | */ |
| Brian Paul | 43911c8 | 2000-03-21 00:49:33 +0000 | [diff] [blame] | 954 | static void |
| 955 | make_null_texture( struct gl_texture_image *texImage ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 956 | { |
| 957 | GLint components; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 958 | GLint numPixels; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 959 | |
| Brian Paul | 43911c8 | 2000-03-21 00:49:33 +0000 | [diff] [blame] | 960 | ASSERT(texImage); |
| 961 | ASSERT(!texImage->Data); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 962 | |
| Brian Paul | 43911c8 | 2000-03-21 00:49:33 +0000 | [diff] [blame] | 963 | components = components_in_intformat(texImage->IntFormat); |
| 964 | numPixels = texImage->Width * texImage->Height * texImage->Depth; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 965 | |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 966 | texImage->Data = (GLchan *) MALLOC( numPixels * components * sizeof(GLchan) |
| 967 | + EXTRA_BYTE ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 968 | |
| 969 | /* |
| 970 | * Let's see if anyone finds this. If glTexImage2D() is called with |
| 971 | * a NULL image pointer then load the texture image with something |
| 972 | * interesting instead of leaving it indeterminate. |
| 973 | */ |
| 974 | if (texImage->Data) { |
| Brian Paul | 65d5460 | 2000-03-01 23:28:20 +0000 | [diff] [blame] | 975 | static const char message[8][32] = { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 976 | " X X XXXXX XXX X ", |
| 977 | " XX XX X X X X X ", |
| 978 | " X X X X X X X ", |
| 979 | " X X XXXX XXX XXXXX ", |
| 980 | " X X X X X X ", |
| 981 | " X X X X X X X ", |
| 982 | " X X XXXXX XXX X X ", |
| 983 | " " |
| 984 | }; |
| 985 | |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 986 | GLchan *imgPtr = texImage->Data; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 987 | GLint i, j, k; |
| Brian Paul | 43911c8 | 2000-03-21 00:49:33 +0000 | [diff] [blame] | 988 | for (i = 0; i < texImage->Height; i++) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 989 | GLint srcRow = 7 - i % 8; |
| Brian Paul | 43911c8 | 2000-03-21 00:49:33 +0000 | [diff] [blame] | 990 | for (j = 0; j < texImage->Width; j++) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 991 | GLint srcCol = j % 32; |
| Brian Paul | ba643a2 | 2000-10-28 18:34:48 +0000 | [diff] [blame] | 992 | GLint texel = (message[srcRow][srcCol]=='X') ? CHAN_MAX : 70; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 993 | for (k=0;k<components;k++) { |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 994 | *imgPtr++ = (GLchan) texel; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 995 | } |
| 996 | } |
| 997 | } |
| 998 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | |
| 1002 | |
| 1003 | /* |
| Brian Paul | 9c27278 | 2000-09-05 22:04:30 +0000 | [diff] [blame] | 1004 | * This is called when a proxy texture test fails, we set all the |
| 1005 | * image members (except DriverData) to zero. |
| 1006 | */ |
| 1007 | static void |
| 1008 | clear_proxy_teximage(struct gl_texture_image *img) |
| 1009 | { |
| 1010 | ASSERT(img); |
| 1011 | img->Format = 0; |
| 1012 | img->IntFormat = 0; |
| 1013 | img->RedBits = 0; |
| 1014 | img->GreenBits = 0; |
| 1015 | img->BlueBits = 0; |
| 1016 | img->AlphaBits = 0; |
| 1017 | img->IntensityBits = 0; |
| 1018 | img->LuminanceBits = 0; |
| 1019 | img->IndexBits = 0; |
| 1020 | img->Border = 0; |
| 1021 | img->Width = 0; |
| 1022 | img->Height = 0; |
| 1023 | img->Depth = 0; |
| 1024 | img->Width2 = 0; |
| 1025 | img->Height2 = 0; |
| 1026 | img->Depth2 = 0; |
| 1027 | img->WidthLog2 = 0; |
| 1028 | img->HeightLog2 = 0; |
| 1029 | img->DepthLog2 = 0; |
| 1030 | img->Data = NULL; |
| 1031 | img->IsCompressed = 0; |
| 1032 | img->CompressedSize = 0; |
| 1033 | } |
| 1034 | |
| 1035 | |
| 1036 | |
| 1037 | /* |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1038 | * Test glTexImage[123]D() parameters for errors. |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1039 | * Input: |
| 1040 | * dimensions - must be 1 or 2 or 3 |
| 1041 | * Return: GL_TRUE = an error was detected, GL_FALSE = no errors |
| 1042 | */ |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1043 | static GLboolean |
| 1044 | texture_error_check( GLcontext *ctx, GLenum target, |
| 1045 | GLint level, GLint internalFormat, |
| 1046 | GLenum format, GLenum type, |
| Brian Paul | 5b37c32 | 1999-11-05 06:43:10 +0000 | [diff] [blame] | 1047 | GLuint dimensions, |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1048 | GLint width, GLint height, |
| 1049 | GLint depth, GLint border ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1050 | { |
| 1051 | GLboolean isProxy; |
| 1052 | GLint iformat; |
| 1053 | |
| 1054 | if (dimensions == 1) { |
| Brian Paul | 5b37c32 | 1999-11-05 06:43:10 +0000 | [diff] [blame] | 1055 | isProxy = (GLboolean) (target == GL_PROXY_TEXTURE_1D); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1056 | if (target != GL_TEXTURE_1D && !isProxy) { |
| 1057 | gl_error( ctx, GL_INVALID_ENUM, "glTexImage1D(target)" ); |
| 1058 | return GL_TRUE; |
| 1059 | } |
| 1060 | } |
| 1061 | else if (dimensions == 2) { |
| Brian Paul | 5b37c32 | 1999-11-05 06:43:10 +0000 | [diff] [blame] | 1062 | isProxy = (GLboolean) (target == GL_PROXY_TEXTURE_2D); |
| Brian Paul | 413d6a2 | 2000-05-26 14:44:59 +0000 | [diff] [blame] | 1063 | if (target != GL_TEXTURE_2D && !isProxy && |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 1064 | !(ctx->Extensions.ARB_texture_cube_map && |
| Brian Paul | 413d6a2 | 2000-05-26 14:44:59 +0000 | [diff] [blame] | 1065 | target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && |
| 1066 | target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1067 | gl_error( ctx, GL_INVALID_ENUM, "glTexImage2D(target)" ); |
| 1068 | return GL_TRUE; |
| 1069 | } |
| 1070 | } |
| 1071 | else if (dimensions == 3) { |
| Brian Paul | 5b37c32 | 1999-11-05 06:43:10 +0000 | [diff] [blame] | 1072 | isProxy = (GLboolean) (target == GL_PROXY_TEXTURE_3D); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1073 | if (target != GL_TEXTURE_3D && !isProxy) { |
| 1074 | gl_error( ctx, GL_INVALID_ENUM, "glTexImage3D(target)" ); |
| 1075 | return GL_TRUE; |
| 1076 | } |
| 1077 | } |
| 1078 | else { |
| 1079 | gl_problem( ctx, "bad dims in texture_error_check" ); |
| 1080 | return GL_TRUE; |
| 1081 | } |
| 1082 | |
| 1083 | /* Border */ |
| Brian Paul | 9fd2b0a | 2000-03-24 23:59:06 +0000 | [diff] [blame] | 1084 | if (border != 0 && border != 1) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1085 | if (!isProxy) { |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1086 | char message[100]; |
| 1087 | sprintf(message, "glTexImage%dD(border)", dimensions); |
| 1088 | gl_error(ctx, GL_INVALID_VALUE, message); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1089 | } |
| 1090 | return GL_TRUE; |
| 1091 | } |
| 1092 | |
| 1093 | /* Width */ |
| 1094 | if (width < 2 * border || width > 2 + ctx->Const.MaxTextureSize |
| 1095 | || logbase2( width - 2 * border ) < 0) { |
| 1096 | if (!isProxy) { |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1097 | char message[100]; |
| 1098 | sprintf(message, "glTexImage%dD(width)", dimensions); |
| 1099 | gl_error(ctx, GL_INVALID_VALUE, message); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1100 | } |
| 1101 | return GL_TRUE; |
| 1102 | } |
| 1103 | |
| 1104 | /* Height */ |
| 1105 | if (dimensions >= 2) { |
| 1106 | if (height < 2 * border || height > 2 + ctx->Const.MaxTextureSize |
| 1107 | || logbase2( height - 2 * border ) < 0) { |
| 1108 | if (!isProxy) { |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1109 | char message[100]; |
| 1110 | sprintf(message, "glTexImage%dD(height)", dimensions); |
| 1111 | gl_error(ctx, GL_INVALID_VALUE, message); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1112 | } |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1113 | return GL_TRUE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1114 | } |
| 1115 | } |
| 1116 | |
| Brian Paul | ad81770 | 2000-05-30 00:27:24 +0000 | [diff] [blame] | 1117 | /* For cube map, width must equal height */ |
| 1118 | if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && |
| 1119 | target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { |
| 1120 | if (width != height) { |
| 1121 | if (!isProxy) { |
| 1122 | gl_error(ctx, GL_INVALID_VALUE, "glTexImage2D(width != height)"); |
| 1123 | } |
| 1124 | return GL_TRUE; |
| 1125 | } |
| 1126 | } |
| 1127 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1128 | /* Depth */ |
| 1129 | if (dimensions >= 3) { |
| 1130 | if (depth < 2 * border || depth > 2 + ctx->Const.MaxTextureSize |
| 1131 | || logbase2( depth - 2 * border ) < 0) { |
| 1132 | if (!isProxy) { |
| 1133 | gl_error( ctx, GL_INVALID_VALUE, "glTexImage3D(depth)" ); |
| 1134 | } |
| 1135 | return GL_TRUE; |
| 1136 | } |
| 1137 | } |
| 1138 | |
| 1139 | /* Level */ |
| Brian Paul | 9fd2b0a | 2000-03-24 23:59:06 +0000 | [diff] [blame] | 1140 | if (level < 0 || level >= ctx->Const.MaxTextureLevels) { |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1141 | if (!isProxy) { |
| 1142 | char message[100]; |
| 1143 | sprintf(message, "glTexImage%dD(level)", dimensions); |
| 1144 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1145 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1146 | return GL_TRUE; |
| 1147 | } |
| 1148 | |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 1149 | iformat = _mesa_base_tex_format( ctx, internalFormat ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1150 | if (iformat < 0) { |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1151 | if (!isProxy) { |
| 1152 | char message[100]; |
| 1153 | sprintf(message, "glTexImage%dD(internalFormat)", dimensions); |
| 1154 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1155 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1156 | return GL_TRUE; |
| 1157 | } |
| 1158 | |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 1159 | if (!is_compressed_format(ctx, internalFormat)) { |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 1160 | if (!_mesa_is_legal_format_and_type( format, type )) { |
| 1161 | /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there |
| 1162 | * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4. |
| 1163 | */ |
| 1164 | if (!isProxy) { |
| 1165 | char message[100]; |
| 1166 | sprintf(message, "glTexImage%dD(format or type)", dimensions); |
| 1167 | gl_error(ctx, GL_INVALID_OPERATION, message); |
| 1168 | } |
| 1169 | return GL_TRUE; |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1170 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | /* if we get here, the parameters are OK */ |
| 1174 | return GL_FALSE; |
| 1175 | } |
| 1176 | |
| 1177 | |
| 1178 | |
| 1179 | /* |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1180 | * Test glTexSubImage[123]D() parameters for errors. |
| 1181 | * Input: |
| 1182 | * dimensions - must be 1 or 2 or 3 |
| 1183 | * Return: GL_TRUE = an error was detected, GL_FALSE = no errors |
| 1184 | */ |
| 1185 | static GLboolean |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1186 | subtexture_error_check( GLcontext *ctx, GLuint dimensions, |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1187 | GLenum target, GLint level, |
| 1188 | GLint xoffset, GLint yoffset, GLint zoffset, |
| 1189 | GLint width, GLint height, GLint depth, |
| 1190 | GLenum format, GLenum type ) |
| 1191 | { |
| 1192 | struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 1193 | struct gl_texture_image *destTex; |
| 1194 | |
| 1195 | if (dimensions == 1) { |
| 1196 | if (target != GL_TEXTURE_1D) { |
| 1197 | gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage1D(target)" ); |
| 1198 | return GL_TRUE; |
| 1199 | } |
| 1200 | } |
| 1201 | else if (dimensions == 2) { |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 1202 | if (ctx->Extensions.ARB_texture_cube_map) { |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 1203 | if ((target < GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB || |
| 1204 | target > GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) && |
| 1205 | target != GL_TEXTURE_2D) { |
| 1206 | gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" ); |
| 1207 | return GL_TRUE; |
| 1208 | } |
| 1209 | } |
| 1210 | else if (target != GL_TEXTURE_2D) { |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1211 | gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" ); |
| 1212 | return GL_TRUE; |
| 1213 | } |
| 1214 | } |
| 1215 | else if (dimensions == 3) { |
| 1216 | if (target != GL_TEXTURE_3D) { |
| 1217 | gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage3D(target)" ); |
| 1218 | return GL_TRUE; |
| 1219 | } |
| 1220 | } |
| 1221 | else { |
| 1222 | gl_problem( ctx, "bad dims in texture_error_check" ); |
| 1223 | return GL_TRUE; |
| 1224 | } |
| 1225 | |
| 1226 | if (level < 0 || level >= ctx->Const.MaxTextureLevels) { |
| 1227 | gl_error(ctx, GL_INVALID_ENUM, "glTexSubImage2D(level)"); |
| 1228 | return GL_TRUE; |
| 1229 | } |
| 1230 | |
| 1231 | if (width < 0) { |
| 1232 | char message[100]; |
| 1233 | sprintf(message, "glTexSubImage%dD(width)", dimensions); |
| 1234 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1235 | return GL_TRUE; |
| 1236 | } |
| 1237 | if (height < 0 && dimensions > 1) { |
| 1238 | char message[100]; |
| 1239 | sprintf(message, "glTexSubImage%dD(height)", dimensions); |
| 1240 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1241 | return GL_TRUE; |
| 1242 | } |
| 1243 | if (depth < 0 && dimensions > 2) { |
| 1244 | char message[100]; |
| 1245 | sprintf(message, "glTexSubImage%dD(depth)", dimensions); |
| 1246 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1247 | return GL_TRUE; |
| 1248 | } |
| 1249 | |
| 1250 | destTex = texUnit->CurrentD[2]->Image[level]; |
| 1251 | if (!destTex) { |
| 1252 | gl_error(ctx, GL_INVALID_OPERATION, "glTexSubImage2D"); |
| 1253 | return GL_TRUE; |
| 1254 | } |
| 1255 | |
| 1256 | if (xoffset < -((GLint)destTex->Border)) { |
| 1257 | gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage1/2/3D(xoffset)"); |
| 1258 | return GL_TRUE; |
| 1259 | } |
| 1260 | if (xoffset + width > (GLint) (destTex->Width + destTex->Border)) { |
| 1261 | gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage1/2/3D(xoffset+width)"); |
| 1262 | return GL_TRUE; |
| 1263 | } |
| 1264 | if (dimensions > 1) { |
| 1265 | if (yoffset < -((GLint)destTex->Border)) { |
| 1266 | gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage2/3D(yoffset)"); |
| 1267 | return GL_TRUE; |
| 1268 | } |
| 1269 | if (yoffset + height > (GLint) (destTex->Height + destTex->Border)) { |
| 1270 | gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage2/3D(yoffset+height)"); |
| 1271 | return GL_TRUE; |
| 1272 | } |
| 1273 | } |
| 1274 | if (dimensions > 2) { |
| 1275 | if (zoffset < -((GLint)destTex->Border)) { |
| 1276 | gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset)"); |
| 1277 | return GL_TRUE; |
| 1278 | } |
| 1279 | if (zoffset + depth > (GLint) (destTex->Depth+destTex->Border)) { |
| 1280 | gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset+depth)"); |
| 1281 | return GL_TRUE; |
| 1282 | } |
| 1283 | } |
| 1284 | |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 1285 | if (!is_compressed_format(ctx, destTex->IntFormat)) { |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 1286 | if (!_mesa_is_legal_format_and_type(format, type)) { |
| 1287 | char message[100]; |
| 1288 | sprintf(message, "glTexSubImage%dD(format or type)", dimensions); |
| 1289 | gl_error(ctx, GL_INVALID_ENUM, message); |
| 1290 | return GL_TRUE; |
| 1291 | } |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1292 | } |
| 1293 | |
| 1294 | return GL_FALSE; |
| 1295 | } |
| 1296 | |
| 1297 | |
| 1298 | /* |
| 1299 | * Test glCopyTexImage[12]D() parameters for errors. |
| 1300 | * Input: dimensions - must be 1 or 2 or 3 |
| 1301 | * Return: GL_TRUE = an error was detected, GL_FALSE = no errors |
| 1302 | */ |
| 1303 | static GLboolean |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1304 | copytexture_error_check( GLcontext *ctx, GLuint dimensions, |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1305 | GLenum target, GLint level, GLint internalFormat, |
| 1306 | GLint width, GLint height, GLint border ) |
| 1307 | { |
| 1308 | GLint iformat; |
| 1309 | |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 1310 | if (dimensions == 1) { |
| 1311 | if (target != GL_TEXTURE_1D) { |
| 1312 | gl_error( ctx, GL_INVALID_ENUM, "glCopyTexImage1D(target)" ); |
| 1313 | return GL_TRUE; |
| 1314 | } |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1315 | } |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 1316 | else if (dimensions == 2) { |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 1317 | if (ctx->Extensions.ARB_texture_cube_map) { |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 1318 | if ((target < GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB || |
| 1319 | target > GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) && |
| 1320 | target != GL_TEXTURE_2D) { |
| 1321 | gl_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" ); |
| 1322 | return GL_TRUE; |
| 1323 | } |
| 1324 | } |
| 1325 | else if (target != GL_TEXTURE_2D) { |
| 1326 | gl_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" ); |
| 1327 | return GL_TRUE; |
| 1328 | } |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | /* Border */ |
| 1332 | if (border!=0 && border!=1) { |
| 1333 | char message[100]; |
| 1334 | sprintf(message, "glCopyTexImage%dD(border)", dimensions); |
| 1335 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1336 | return GL_TRUE; |
| 1337 | } |
| 1338 | |
| 1339 | /* Width */ |
| 1340 | if (width < 2 * border || width > 2 + ctx->Const.MaxTextureSize |
| 1341 | || logbase2( width - 2 * border ) < 0) { |
| 1342 | char message[100]; |
| 1343 | sprintf(message, "glCopyTexImage%dD(width)", dimensions); |
| 1344 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1345 | return GL_TRUE; |
| 1346 | } |
| 1347 | |
| 1348 | /* Height */ |
| 1349 | if (dimensions >= 2) { |
| 1350 | if (height < 2 * border || height > 2 + ctx->Const.MaxTextureSize |
| 1351 | || logbase2( height - 2 * border ) < 0) { |
| 1352 | char message[100]; |
| 1353 | sprintf(message, "glCopyTexImage%dD(height)", dimensions); |
| 1354 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1355 | return GL_TRUE; |
| 1356 | } |
| 1357 | } |
| 1358 | |
| Brian Paul | ad81770 | 2000-05-30 00:27:24 +0000 | [diff] [blame] | 1359 | /* For cube map, width must equal height */ |
| 1360 | if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && |
| 1361 | target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { |
| 1362 | if (width != height) { |
| 1363 | gl_error(ctx, GL_INVALID_VALUE, "glCopyTexImage2D(width != height)"); |
| 1364 | return GL_TRUE; |
| 1365 | } |
| 1366 | } |
| 1367 | |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1368 | /* Level */ |
| 1369 | if (level<0 || level>=ctx->Const.MaxTextureLevels) { |
| 1370 | char message[100]; |
| 1371 | sprintf(message, "glCopyTexImage%dD(level)", dimensions); |
| 1372 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1373 | return GL_TRUE; |
| 1374 | } |
| 1375 | |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 1376 | iformat = _mesa_base_tex_format( ctx, internalFormat ); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1377 | if (iformat < 0) { |
| 1378 | char message[100]; |
| 1379 | sprintf(message, "glCopyTexImage%dD(internalFormat)", dimensions); |
| 1380 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1381 | return GL_TRUE; |
| 1382 | } |
| 1383 | |
| 1384 | /* if we get here, the parameters are OK */ |
| 1385 | return GL_FALSE; |
| 1386 | } |
| 1387 | |
| 1388 | |
| 1389 | static GLboolean |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1390 | copytexsubimage_error_check( GLcontext *ctx, GLuint dimensions, |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1391 | GLenum target, GLint level, |
| 1392 | GLint xoffset, GLint yoffset, GLint zoffset, |
| Brian Paul | 5b37c32 | 1999-11-05 06:43:10 +0000 | [diff] [blame] | 1393 | GLsizei width, GLsizei height ) |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1394 | { |
| 1395 | struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 1396 | struct gl_texture_image *teximage; |
| 1397 | |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 1398 | if (dimensions == 1) { |
| 1399 | if (target != GL_TEXTURE_1D) { |
| 1400 | gl_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage1D(target)" ); |
| 1401 | return GL_TRUE; |
| 1402 | } |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1403 | } |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 1404 | else if (dimensions == 2) { |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 1405 | if (ctx->Extensions.ARB_texture_cube_map) { |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 1406 | if ((target < GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB || |
| 1407 | target > GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) && |
| 1408 | target != GL_TEXTURE_2D) { |
| 1409 | gl_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" ); |
| 1410 | return GL_TRUE; |
| 1411 | } |
| 1412 | } |
| 1413 | else if (target != GL_TEXTURE_2D) { |
| 1414 | gl_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" ); |
| 1415 | return GL_TRUE; |
| 1416 | } |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1417 | } |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 1418 | else if (dimensions == 3) { |
| 1419 | if (target != GL_TEXTURE_3D) { |
| 1420 | gl_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage3D(target)" ); |
| 1421 | return GL_TRUE; |
| 1422 | } |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1423 | } |
| 1424 | |
| 1425 | if (level < 0 || level >= ctx->Const.MaxTextureLevels) { |
| 1426 | char message[100]; |
| 1427 | sprintf(message, "glCopyTexSubImage%dD(level)", dimensions); |
| 1428 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1429 | return GL_TRUE; |
| 1430 | } |
| 1431 | |
| 1432 | if (width < 0) { |
| 1433 | char message[100]; |
| 1434 | sprintf(message, "glCopyTexSubImage%dD(width)", dimensions ); |
| 1435 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1436 | return GL_TRUE; |
| 1437 | } |
| 1438 | if (dimensions > 1 && height < 0) { |
| 1439 | char message[100]; |
| 1440 | sprintf(message, "glCopyTexSubImage%dD(height)", dimensions ); |
| 1441 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1442 | return GL_TRUE; |
| 1443 | } |
| 1444 | |
| Brian Paul | df6a28d | 2000-02-21 16:34:21 +0000 | [diff] [blame] | 1445 | teximage = texUnit->CurrentD[dimensions]->Image[level]; |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1446 | if (!teximage) { |
| 1447 | char message[100]; |
| 1448 | sprintf(message, "glCopyTexSubImage%dD(undefined texture)", dimensions); |
| 1449 | gl_error(ctx, GL_INVALID_OPERATION, message); |
| 1450 | return GL_TRUE; |
| 1451 | } |
| 1452 | |
| 1453 | if (xoffset < -((GLint)teximage->Border)) { |
| 1454 | char message[100]; |
| 1455 | sprintf(message, "glCopyTexSubImage%dD(xoffset)", dimensions); |
| 1456 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1457 | return GL_TRUE; |
| 1458 | } |
| 1459 | if (xoffset+width > (GLint) (teximage->Width+teximage->Border)) { |
| 1460 | char message[100]; |
| 1461 | sprintf(message, "glCopyTexSubImage%dD(xoffset+width)", dimensions); |
| 1462 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1463 | return GL_TRUE; |
| 1464 | } |
| 1465 | if (dimensions > 1) { |
| 1466 | if (yoffset < -((GLint)teximage->Border)) { |
| 1467 | char message[100]; |
| 1468 | sprintf(message, "glCopyTexSubImage%dD(yoffset)", dimensions); |
| 1469 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1470 | return GL_TRUE; |
| 1471 | } |
| 1472 | /* NOTE: we're adding the border here, not subtracting! */ |
| 1473 | if (yoffset+height > (GLint) (teximage->Height+teximage->Border)) { |
| 1474 | char message[100]; |
| 1475 | sprintf(message, "glCopyTexSubImage%dD(yoffset+height)", dimensions); |
| 1476 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1477 | return GL_TRUE; |
| 1478 | } |
| 1479 | } |
| 1480 | |
| 1481 | if (dimensions > 2) { |
| 1482 | if (zoffset < -((GLint)teximage->Border)) { |
| 1483 | char message[100]; |
| 1484 | sprintf(message, "glCopyTexSubImage%dD(zoffset)", dimensions); |
| 1485 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1486 | return GL_TRUE; |
| 1487 | } |
| 1488 | if (zoffset > (GLint) (teximage->Depth+teximage->Border)) { |
| 1489 | char message[100]; |
| 1490 | sprintf(message, "glCopyTexSubImage%dD(zoffset+depth)", dimensions); |
| 1491 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1492 | return GL_TRUE; |
| 1493 | } |
| 1494 | } |
| 1495 | |
| 1496 | /* if we get here, the parameters are OK */ |
| 1497 | return GL_FALSE; |
| 1498 | } |
| 1499 | |
| 1500 | |
| 1501 | |
| 1502 | |
| 1503 | /* |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 1504 | * Turn generic compressed formats into specific compressed format. |
| 1505 | * Some of the compressed formats we don't support, so we |
| 1506 | * fall back to the uncompressed format. (See issue 15 of |
| 1507 | * the GL_ARB_texture_compression specification.) |
| 1508 | */ |
| 1509 | static GLint |
| 1510 | get_specific_compressed_tex_format(GLcontext *ctx, |
| Brian Paul | 37a6211 | 2000-09-28 18:30:39 +0000 | [diff] [blame] | 1511 | GLint ifmt, GLint numDimensions, |
| 1512 | GLint *levelp, |
| 1513 | GLsizei *widthp, |
| 1514 | GLsizei *heightp, |
| 1515 | GLsizei *depthp, |
| 1516 | GLint *borderp, |
| 1517 | GLenum *formatp, |
| 1518 | GLenum *typep) |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 1519 | { |
| 1520 | char message[100]; |
| 1521 | GLint internalFormat = ifmt; |
| 1522 | |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 1523 | if (ctx->Extensions.ARB_texture_compression |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 1524 | && ctx->Driver.SpecificCompressedTexFormat) { |
| 1525 | /* |
| 1526 | * First, ask the driver for the specific format. |
| Brian Paul | 37a6211 | 2000-09-28 18:30:39 +0000 | [diff] [blame] | 1527 | * We do this for all formats, since we may want to |
| 1528 | * fake one compressed format for another. |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 1529 | */ |
| Brian Paul | 37a6211 | 2000-09-28 18:30:39 +0000 | [diff] [blame] | 1530 | internalFormat = (*ctx->Driver.SpecificCompressedTexFormat) |
| 1531 | (ctx, internalFormat, numDimensions, |
| 1532 | levelp, |
| 1533 | widthp, heightp, depthp, |
| 1534 | borderp, formatp, typep); |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 1535 | } |
| 1536 | |
| 1537 | /* |
| 1538 | * Now, convert any generic format left to an uncompressed |
| 1539 | * specific format. If the driver does not support compression |
| 1540 | * of the format, we must drop back to the uncompressed format. |
| 1541 | * See issue 15 of the GL_ARB_texture_compression specification. |
| 1542 | */ |
| 1543 | switch (internalFormat) { |
| 1544 | case GL_COMPRESSED_ALPHA_ARB: |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 1545 | if (ctx && !ctx->Extensions.ARB_texture_compression) { |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 1546 | sprintf(message, "glTexImage%dD(internalFormat)", numDimensions); |
| 1547 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1548 | return -1; |
| 1549 | } |
| 1550 | internalFormat = GL_ALPHA; |
| 1551 | break; |
| 1552 | case GL_COMPRESSED_LUMINANCE_ARB: |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 1553 | if (ctx && !ctx->Extensions.ARB_texture_compression) { |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 1554 | sprintf(message, "glTexImage%dD(internalFormat)", numDimensions); |
| 1555 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1556 | return -1; |
| 1557 | } |
| 1558 | internalFormat = GL_LUMINANCE; |
| 1559 | break; |
| 1560 | case GL_COMPRESSED_LUMINANCE_ALPHA_ARB: |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 1561 | if (ctx && !ctx->Extensions.ARB_texture_compression) { |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 1562 | sprintf(message, "glTexImage%dD(internalFormat)", numDimensions); |
| 1563 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1564 | return -1; |
| 1565 | } |
| 1566 | internalFormat = GL_LUMINANCE_ALPHA; |
| 1567 | break; |
| 1568 | case GL_COMPRESSED_INTENSITY_ARB: |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 1569 | if (ctx && !ctx->Extensions.ARB_texture_compression) { |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 1570 | sprintf(message, "glTexImage%dD(internalFormat)", numDimensions); |
| 1571 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1572 | return -1; |
| 1573 | } |
| 1574 | internalFormat = GL_INTENSITY; |
| 1575 | break; |
| 1576 | case GL_COMPRESSED_RGB_ARB: |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 1577 | if (ctx && !ctx->Extensions.ARB_texture_compression) { |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 1578 | sprintf(message, "glTexImage%dD(internalFormat)", numDimensions); |
| 1579 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1580 | return -1; |
| 1581 | } |
| 1582 | internalFormat = GL_RGB; |
| 1583 | break; |
| 1584 | case GL_COMPRESSED_RGBA_ARB: |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 1585 | if (ctx && !ctx->Extensions.ARB_texture_compression) { |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 1586 | sprintf(message, "glTexImage%dD(internalFormat)", numDimensions); |
| 1587 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1588 | return -1; |
| 1589 | } |
| 1590 | internalFormat = GL_RGBA; |
| 1591 | break; |
| 1592 | default: |
| Brian Paul | f93b3dd | 2000-08-30 18:22:28 +0000 | [diff] [blame] | 1593 | /* silence compiler warning */ |
| 1594 | ; |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 1595 | } |
| 1596 | return internalFormat; |
| 1597 | } |
| 1598 | |
| 1599 | |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 1600 | /* |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1601 | * Called from the API. Note that width includes the border. |
| 1602 | */ |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1603 | void |
| Brian Paul | 43911c8 | 2000-03-21 00:49:33 +0000 | [diff] [blame] | 1604 | _mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat, |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1605 | GLsizei width, GLint border, GLenum format, |
| 1606 | GLenum type, const GLvoid *pixels ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1607 | { |
| Brian Paul | f93b3dd | 2000-08-30 18:22:28 +0000 | [diff] [blame] | 1608 | GLsizei postConvWidth; |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1609 | GET_CURRENT_CONTEXT(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1610 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glTexImage1D"); |
| 1611 | |
| Brian Paul | f93b3dd | 2000-08-30 18:22:28 +0000 | [diff] [blame] | 1612 | postConvWidth = width; |
| 1613 | adjust_texture_size_for_convolution(ctx, 1, &postConvWidth, NULL); |
| 1614 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1615 | if (target==GL_TEXTURE_1D) { |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1616 | struct gl_texture_unit *texUnit; |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1617 | struct gl_texture_object *texObj; |
| 1618 | struct gl_texture_image *texImage; |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 1619 | GLint ifmt; |
| 1620 | |
| Brian Paul | 37a6211 | 2000-09-28 18:30:39 +0000 | [diff] [blame] | 1621 | ifmt = get_specific_compressed_tex_format(ctx, internalFormat, 1, |
| 1622 | &level, |
| 1623 | &width, 0, 0, |
| 1624 | &border, &format, &type); |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 1625 | if (ifmt < 0) { |
| 1626 | /* |
| 1627 | * The error here is that we were sent a generic compressed |
| 1628 | * format, but the extension is not supported. |
| 1629 | */ |
| 1630 | return; |
| 1631 | } |
| 1632 | else { |
| 1633 | internalFormat = ifmt; |
| 1634 | } |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1635 | |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 1636 | if (texture_error_check(ctx, target, level, internalFormat, |
| Brian Paul | f93b3dd | 2000-08-30 18:22:28 +0000 | [diff] [blame] | 1637 | format, type, 1, postConvWidth, 1, 1, border)) { |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1638 | return; /* error in texture image was detected */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1639 | } |
| 1640 | |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1641 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1642 | texObj = texUnit->CurrentD[1]; |
| 1643 | texImage = texObj->Image[level]; |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1644 | |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1645 | if (!texImage) { |
| Brian Paul | 021a525 | 2000-03-27 17:54:17 +0000 | [diff] [blame] | 1646 | texImage = _mesa_alloc_texture_image(); |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1647 | texObj->Image[level] = texImage; |
| 1648 | if (!texImage) { |
| 1649 | gl_error(ctx, GL_OUT_OF_MEMORY, "glTexImage1D"); |
| 1650 | return; |
| 1651 | } |
| 1652 | } |
| 1653 | else if (texImage->Data) { |
| 1654 | FREE(texImage->Data); |
| 1655 | texImage->Data = NULL; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1656 | } |
| 1657 | |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1658 | /* setup the teximage struct's fields */ |
| Brian Paul | f93b3dd | 2000-08-30 18:22:28 +0000 | [diff] [blame] | 1659 | init_texture_image(ctx, texImage, postConvWidth, 1, 1, border, internalFormat); |
| Brian Paul | 43911c8 | 2000-03-21 00:49:33 +0000 | [diff] [blame] | 1660 | |
| Brian Paul | 9499e01 | 2000-10-30 16:32:42 +0000 | [diff] [blame] | 1661 | if (ctx->NewState & _NEW_PIXEL) |
| 1662 | gl_update_state(ctx); |
| Brian Paul | fa4525e | 2000-08-21 14:22:24 +0000 | [diff] [blame] | 1663 | |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1664 | /* process the texture image */ |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1665 | if (pixels) { |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1666 | GLboolean retain = GL_TRUE; |
| 1667 | GLboolean success = GL_FALSE; |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1668 | if (!ctx->_ImageTransferState && ctx->Driver.TexImage1D) { |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1669 | /* let device driver try to use raw image */ |
| 1670 | success = (*ctx->Driver.TexImage1D)( ctx, target, level, format, |
| 1671 | type, pixels, &ctx->Unpack, |
| 1672 | texObj, texImage, &retain); |
| 1673 | } |
| 1674 | if (retain || !success) { |
| 1675 | /* make internal copy of the texture image */ |
| Brian Paul | 5a0d3dc | 2000-08-31 15:24:39 +0000 | [diff] [blame] | 1676 | make_texture_image(ctx, 1, texImage, width, 1, 1, |
| 1677 | format, type, pixels, &ctx->Unpack); |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1678 | if (!success && ctx->Driver.TexImage1D) { |
| 1679 | /* let device driver try to use unpacked image */ |
| 1680 | (*ctx->Driver.TexImage1D)( ctx, target, level, texImage->Format, |
| 1681 | GL_UNSIGNED_BYTE, texImage->Data, |
| 1682 | &_mesa_native_packing, |
| 1683 | texObj, texImage, &retain); |
| 1684 | } |
| 1685 | } |
| 1686 | if (!retain && texImage->Data) { |
| 1687 | FREE(texImage->Data); |
| 1688 | texImage->Data = NULL; |
| 1689 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1690 | } |
| 1691 | else { |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1692 | make_null_texture(texImage); |
| 1693 | if (ctx->Driver.TexImage1D) { |
| 1694 | GLboolean retain; |
| 1695 | (*ctx->Driver.TexImage1D)( ctx, target, level, texImage->Format, |
| 1696 | GL_UNSIGNED_BYTE, texImage->Data, |
| 1697 | &_mesa_native_packing, |
| 1698 | texObj, texImage, &retain); |
| 1699 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1700 | } |
| 1701 | |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1702 | /* state update */ |
| 1703 | gl_put_texobj_on_dirty_list( ctx, texObj ); |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 1704 | ctx->NewState |= _NEW_TEXTURE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1705 | } |
| Brian Paul | 38d3f3d | 2000-09-07 15:38:49 +0000 | [diff] [blame] | 1706 | else if (target == GL_PROXY_TEXTURE_1D) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1707 | /* Proxy texture: check for errors and update proxy state */ |
| Brian Paul | 38d3f3d | 2000-09-07 15:38:49 +0000 | [diff] [blame] | 1708 | GLenum error = texture_error_check(ctx, target, level, internalFormat, |
| 1709 | format, type, 1, width, 1, 1, border); |
| 1710 | if (!error && ctx->Driver.TestProxyTexImage) { |
| 1711 | error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, |
| 1712 | internalFormat, format, type, |
| 1713 | width, 1, 1, border); |
| 1714 | } |
| 1715 | if (error) { |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 1716 | /* if error, clear all proxy texture image parameters */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1717 | if (level>=0 && level<ctx->Const.MaxTextureLevels) { |
| Brian Paul | 9c27278 | 2000-09-05 22:04:30 +0000 | [diff] [blame] | 1718 | clear_proxy_teximage(ctx->Texture.Proxy1D->Image[level]); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1719 | } |
| 1720 | } |
| 1721 | else { |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 1722 | /* if no error, update proxy texture image parameters */ |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 1723 | init_texture_image(ctx, ctx->Texture.Proxy1D->Image[level], |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 1724 | width, 1, 1, border, internalFormat); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1725 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1726 | } |
| 1727 | else { |
| 1728 | gl_error( ctx, GL_INVALID_ENUM, "glTexImage1D(target)" ); |
| 1729 | return; |
| 1730 | } |
| 1731 | } |
| 1732 | |
| 1733 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1734 | void |
| Brian Paul | 43911c8 | 2000-03-21 00:49:33 +0000 | [diff] [blame] | 1735 | _mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat, |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1736 | GLsizei width, GLsizei height, GLint border, |
| 1737 | GLenum format, GLenum type, |
| 1738 | const GLvoid *pixels ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1739 | { |
| Brian Paul | f93b3dd | 2000-08-30 18:22:28 +0000 | [diff] [blame] | 1740 | GLsizei postConvWidth, postConvHeight; |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1741 | GET_CURRENT_CONTEXT(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1742 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glTexImage2D"); |
| 1743 | |
| Brian Paul | f93b3dd | 2000-08-30 18:22:28 +0000 | [diff] [blame] | 1744 | postConvWidth = width; |
| 1745 | postConvHeight = height; |
| 1746 | adjust_texture_size_for_convolution(ctx, 2, &postConvWidth,&postConvHeight); |
| 1747 | |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 1748 | if (target==GL_TEXTURE_2D || |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 1749 | (ctx->Extensions.ARB_texture_cube_map && |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 1750 | target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && |
| 1751 | target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)) { |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1752 | struct gl_texture_unit *texUnit; |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1753 | struct gl_texture_object *texObj; |
| 1754 | struct gl_texture_image *texImage; |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 1755 | GLint ifmt; |
| 1756 | |
| Brian Paul | 37a6211 | 2000-09-28 18:30:39 +0000 | [diff] [blame] | 1757 | ifmt = get_specific_compressed_tex_format(ctx, internalFormat, 2, |
| 1758 | &level, |
| 1759 | &width, &height, 0, |
| 1760 | &border, &format, &type); |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 1761 | if (ifmt < 0) { |
| 1762 | /* |
| 1763 | * The error here is that we were sent a generic compressed |
| 1764 | * format, but the extension is not supported. |
| 1765 | */ |
| 1766 | return; |
| 1767 | } |
| 1768 | else { |
| 1769 | internalFormat = ifmt; |
| 1770 | } |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1771 | |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 1772 | if (texture_error_check(ctx, target, level, internalFormat, |
| Brian Paul | f93b3dd | 2000-08-30 18:22:28 +0000 | [diff] [blame] | 1773 | format, type, 2, postConvWidth, postConvHeight, |
| 1774 | 1, border)) { |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1775 | return; /* error in texture image was detected */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1776 | } |
| 1777 | |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1778 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| Brian Paul | 35d5301 | 2000-05-23 17:14:49 +0000 | [diff] [blame] | 1779 | texObj = _mesa_select_tex_object(ctx, texUnit, target); |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 1780 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1781 | |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1782 | if (!texImage) { |
| Brian Paul | 021a525 | 2000-03-27 17:54:17 +0000 | [diff] [blame] | 1783 | texImage = _mesa_alloc_texture_image(); |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 1784 | set_tex_image(texObj, target, level, texImage); |
| 1785 | /*texObj->Image[level] = texImage;*/ |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1786 | if (!texImage) { |
| 1787 | gl_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D"); |
| 1788 | return; |
| 1789 | } |
| 1790 | } |
| 1791 | else if (texImage->Data) { |
| 1792 | FREE(texImage->Data); |
| 1793 | texImage->Data = NULL; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1794 | } |
| 1795 | |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1796 | /* setup the teximage struct's fields */ |
| Brian Paul | f93b3dd | 2000-08-30 18:22:28 +0000 | [diff] [blame] | 1797 | init_texture_image(ctx, texImage, postConvWidth, postConvHeight, |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 1798 | 1, border, internalFormat); |
| Brian Paul | 43911c8 | 2000-03-21 00:49:33 +0000 | [diff] [blame] | 1799 | |
| Brian Paul | 9499e01 | 2000-10-30 16:32:42 +0000 | [diff] [blame] | 1800 | if (ctx->NewState & _NEW_PIXEL) |
| 1801 | gl_update_state(ctx); |
| Brian Paul | fa4525e | 2000-08-21 14:22:24 +0000 | [diff] [blame] | 1802 | |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1803 | /* process the texture image */ |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1804 | if (pixels) { |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1805 | GLboolean retain = GL_TRUE; |
| 1806 | GLboolean success = GL_FALSE; |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1807 | if (!ctx->_ImageTransferState && ctx->Driver.TexImage2D) { |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1808 | /* let device driver try to use raw image */ |
| 1809 | success = (*ctx->Driver.TexImage2D)( ctx, target, level, format, |
| 1810 | type, pixels, &ctx->Unpack, |
| 1811 | texObj, texImage, &retain); |
| 1812 | } |
| 1813 | if (retain || !success) { |
| 1814 | /* make internal copy of the texture image */ |
| Brian Paul | 5a0d3dc | 2000-08-31 15:24:39 +0000 | [diff] [blame] | 1815 | make_texture_image(ctx, 2, texImage, width, height, 1, |
| 1816 | format, type, pixels, &ctx->Unpack); |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1817 | if (!success && ctx->Driver.TexImage2D) { |
| 1818 | /* let device driver try to use unpacked image */ |
| 1819 | (*ctx->Driver.TexImage2D)( ctx, target, level, texImage->Format, |
| 1820 | GL_UNSIGNED_BYTE, texImage->Data, |
| 1821 | &_mesa_native_packing, |
| 1822 | texObj, texImage, &retain); |
| 1823 | } |
| 1824 | } |
| 1825 | if (!retain && texImage->Data) { |
| 1826 | FREE(texImage->Data); |
| 1827 | texImage->Data = NULL; |
| 1828 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1829 | } |
| 1830 | else { |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1831 | make_null_texture(texImage); |
| 1832 | if (ctx->Driver.TexImage2D) { |
| 1833 | GLboolean retain; |
| 1834 | (*ctx->Driver.TexImage2D)( ctx, target, level, texImage->Format, |
| 1835 | GL_UNSIGNED_BYTE, texImage->Data, |
| 1836 | &_mesa_native_packing, |
| 1837 | texObj, texImage, &retain); |
| 1838 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1839 | } |
| 1840 | |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1841 | #define OLD_DD_TEXTURE |
| 1842 | #ifdef OLD_DD_TEXTURE |
| 1843 | /* XXX this will be removed in the future */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1844 | if (ctx->Driver.TexImage) { |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1845 | (*ctx->Driver.TexImage)( ctx, target, texObj, level, internalFormat, |
| 1846 | texImage ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1847 | } |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1848 | #endif |
| 1849 | |
| 1850 | /* state update */ |
| 1851 | gl_put_texobj_on_dirty_list( ctx, texObj ); |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 1852 | ctx->NewState |= _NEW_TEXTURE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1853 | } |
| Brian Paul | 38d3f3d | 2000-09-07 15:38:49 +0000 | [diff] [blame] | 1854 | else if (target == GL_PROXY_TEXTURE_2D) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1855 | /* Proxy texture: check for errors and update proxy state */ |
| Brian Paul | 38d3f3d | 2000-09-07 15:38:49 +0000 | [diff] [blame] | 1856 | GLenum error = texture_error_check(ctx, target, level, internalFormat, |
| 1857 | format, type, 2, width, height, 1, border); |
| 1858 | if (!error && ctx->Driver.TestProxyTexImage) { |
| 1859 | error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, |
| 1860 | internalFormat, format, type, |
| 1861 | width, height, 1, border); |
| 1862 | } |
| 1863 | if (error) { |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 1864 | /* if error, clear all proxy texture image parameters */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1865 | if (level>=0 && level<ctx->Const.MaxTextureLevels) { |
| Brian Paul | 9c27278 | 2000-09-05 22:04:30 +0000 | [diff] [blame] | 1866 | clear_proxy_teximage(ctx->Texture.Proxy2D->Image[level]); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1867 | } |
| 1868 | } |
| 1869 | else { |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 1870 | /* if no error, update proxy texture image parameters */ |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 1871 | init_texture_image(ctx, |
| 1872 | ctx->Texture.Proxy2D->Image[level], |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 1873 | width, height, 1, border, internalFormat); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1874 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1875 | } |
| 1876 | else { |
| 1877 | gl_error( ctx, GL_INVALID_ENUM, "glTexImage2D(target)" ); |
| 1878 | return; |
| 1879 | } |
| 1880 | } |
| 1881 | |
| 1882 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1883 | /* |
| 1884 | * Called by the API or display list executor. |
| 1885 | * Note that width and height include the border. |
| 1886 | */ |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1887 | void |
| Brian Paul | 43911c8 | 2000-03-21 00:49:33 +0000 | [diff] [blame] | 1888 | _mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat, |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1889 | GLsizei width, GLsizei height, GLsizei depth, |
| 1890 | GLint border, GLenum format, GLenum type, |
| 1891 | const GLvoid *pixels ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1892 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1893 | GET_CURRENT_CONTEXT(ctx); |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1894 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glTexImage3D"); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1895 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1896 | if (target==GL_TEXTURE_3D_EXT) { |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1897 | struct gl_texture_unit *texUnit; |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1898 | struct gl_texture_object *texObj; |
| 1899 | struct gl_texture_image *texImage; |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 1900 | GLint ifmt; |
| 1901 | |
| Brian Paul | 37a6211 | 2000-09-28 18:30:39 +0000 | [diff] [blame] | 1902 | ifmt = get_specific_compressed_tex_format(ctx, internalFormat, 3, |
| 1903 | &level, |
| 1904 | &width, &height, &depth, |
| 1905 | &border, &format, &type); |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 1906 | if (ifmt < 0) { |
| 1907 | /* |
| 1908 | * The error here is that we were sent a generic compressed |
| 1909 | * format, but the extension is not supported. |
| 1910 | */ |
| 1911 | return; |
| 1912 | } |
| 1913 | else { |
| 1914 | internalFormat = ifmt; |
| 1915 | } |
| 1916 | |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 1917 | if (texture_error_check(ctx, target, level, internalFormat, |
| 1918 | format, type, 3, width, height, depth, border)) { |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1919 | return; /* error in texture image was detected */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1920 | } |
| 1921 | |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1922 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1923 | texObj = texUnit->CurrentD[3]; |
| 1924 | texImage = texObj->Image[level]; |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1925 | |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1926 | if (!texImage) { |
| Brian Paul | 021a525 | 2000-03-27 17:54:17 +0000 | [diff] [blame] | 1927 | texImage = _mesa_alloc_texture_image(); |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1928 | texObj->Image[level] = texImage; |
| 1929 | if (!texImage) { |
| 1930 | gl_error(ctx, GL_OUT_OF_MEMORY, "glTexImage3D"); |
| 1931 | return; |
| 1932 | } |
| 1933 | } |
| 1934 | else if (texImage->Data) { |
| 1935 | FREE(texImage->Data); |
| 1936 | texImage->Data = NULL; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1937 | } |
| 1938 | |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1939 | /* setup the teximage struct's fields */ |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 1940 | init_texture_image(ctx, texImage, width, height, depth, |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1941 | border, internalFormat); |
| Brian Paul | 43911c8 | 2000-03-21 00:49:33 +0000 | [diff] [blame] | 1942 | |
| Brian Paul | 9499e01 | 2000-10-30 16:32:42 +0000 | [diff] [blame] | 1943 | if (ctx->NewState & _NEW_PIXEL) |
| 1944 | gl_update_state(ctx); |
| Brian Paul | fa4525e | 2000-08-21 14:22:24 +0000 | [diff] [blame] | 1945 | |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1946 | /* process the texture image */ |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1947 | if (pixels) { |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1948 | GLboolean retain = GL_TRUE; |
| 1949 | GLboolean success = GL_FALSE; |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1950 | if (!ctx->_ImageTransferState && ctx->Driver.TexImage3D) { |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1951 | /* let device driver try to use raw image */ |
| 1952 | success = (*ctx->Driver.TexImage3D)( ctx, target, level, format, |
| 1953 | type, pixels, &ctx->Unpack, |
| 1954 | texObj, texImage, &retain); |
| 1955 | } |
| 1956 | if (retain || !success) { |
| 1957 | /* make internal copy of the texture image */ |
| Brian Paul | 5a0d3dc | 2000-08-31 15:24:39 +0000 | [diff] [blame] | 1958 | make_texture_image(ctx, 3, texImage, width, height, depth, |
| 1959 | format, type, pixels, &ctx->Unpack); |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1960 | if (!success && ctx->Driver.TexImage3D) { |
| 1961 | /* let device driver try to use unpacked image */ |
| 1962 | (*ctx->Driver.TexImage3D)( ctx, target, level, texImage->Format, |
| 1963 | GL_UNSIGNED_BYTE, texImage->Data, |
| 1964 | &_mesa_native_packing, |
| 1965 | texObj, texImage, &retain); |
| 1966 | } |
| 1967 | } |
| 1968 | if (!retain && texImage->Data) { |
| 1969 | FREE(texImage->Data); |
| 1970 | texImage->Data = NULL; |
| 1971 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1972 | } |
| 1973 | else { |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1974 | make_null_texture(texImage); |
| 1975 | if (ctx->Driver.TexImage3D) { |
| 1976 | GLboolean retain; |
| 1977 | (*ctx->Driver.TexImage3D)( ctx, target, level, texImage->Format, |
| 1978 | GL_UNSIGNED_BYTE, texImage->Data, |
| 1979 | &_mesa_native_packing, |
| 1980 | texObj, texImage, &retain); |
| 1981 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1982 | } |
| 1983 | |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1984 | /* state update */ |
| 1985 | gl_put_texobj_on_dirty_list( ctx, texObj ); |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 1986 | ctx->NewState |= _NEW_TEXTURE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1987 | } |
| Brian Paul | 38d3f3d | 2000-09-07 15:38:49 +0000 | [diff] [blame] | 1988 | else if (target == GL_PROXY_TEXTURE_3D) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1989 | /* Proxy texture: check for errors and update proxy state */ |
| Brian Paul | 38d3f3d | 2000-09-07 15:38:49 +0000 | [diff] [blame] | 1990 | GLenum error = texture_error_check(ctx, target, level, internalFormat, |
| 1991 | format, type, 3, width, height, depth, border); |
| 1992 | if (!error && ctx->Driver.TestProxyTexImage) { |
| 1993 | error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, |
| 1994 | internalFormat, format, type, |
| 1995 | width, height, depth, border); |
| 1996 | } |
| 1997 | if (error) { |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 1998 | /* if error, clear all proxy texture image parameters */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1999 | if (level>=0 && level<ctx->Const.MaxTextureLevels) { |
| Brian Paul | 9c27278 | 2000-09-05 22:04:30 +0000 | [diff] [blame] | 2000 | clear_proxy_teximage(ctx->Texture.Proxy3D->Image[level]); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2001 | } |
| 2002 | } |
| 2003 | else { |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2004 | /* if no error, update proxy texture image parameters */ |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 2005 | init_texture_image(ctx, ctx->Texture.Proxy3D->Image[level], |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2006 | width, height, depth, border, internalFormat); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2007 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2008 | } |
| 2009 | else { |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 2010 | gl_error( ctx, GL_INVALID_ENUM, "glTexImage3D(target)" ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2011 | return; |
| 2012 | } |
| 2013 | } |
| 2014 | |
| 2015 | |
| Brian Paul | 663049a | 2000-01-31 23:10:16 +0000 | [diff] [blame] | 2016 | void |
| Brian Paul | 43911c8 | 2000-03-21 00:49:33 +0000 | [diff] [blame] | 2017 | _mesa_TexImage3DEXT( GLenum target, GLint level, GLenum internalFormat, |
| Brian Paul | 663049a | 2000-01-31 23:10:16 +0000 | [diff] [blame] | 2018 | GLsizei width, GLsizei height, GLsizei depth, |
| 2019 | GLint border, GLenum format, GLenum type, |
| 2020 | const GLvoid *pixels ) |
| 2021 | { |
| Brian Paul | 43911c8 | 2000-03-21 00:49:33 +0000 | [diff] [blame] | 2022 | _mesa_TexImage3D(target, level, (GLint) internalFormat, width, height, |
| Brian Paul | 663049a | 2000-01-31 23:10:16 +0000 | [diff] [blame] | 2023 | depth, border, format, type, pixels); |
| 2024 | } |
| 2025 | |
| 2026 | |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 2027 | /* |
| 2028 | * Fetch a texture image from the device driver. |
| 2029 | * Store the results in the given texture object at the given mipmap level. |
| 2030 | */ |
| Brian Paul | 021a525 | 2000-03-27 17:54:17 +0000 | [diff] [blame] | 2031 | void |
| 2032 | _mesa_get_teximage_from_driver( GLcontext *ctx, GLenum target, GLint level, |
| 2033 | const struct gl_texture_object *texObj ) |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 2034 | { |
| 2035 | GLvoid *image; |
| 2036 | GLenum imgFormat, imgType; |
| 2037 | GLboolean freeImage; |
| 2038 | struct gl_texture_image *texImage; |
| 2039 | GLint destComponents, numPixels, srcBytesPerTexel; |
| 2040 | |
| 2041 | if (!ctx->Driver.GetTexImage) |
| 2042 | return; |
| 2043 | |
| Brian Paul | 4827179 | 2000-03-29 18:13:59 +0000 | [diff] [blame] | 2044 | image = (*ctx->Driver.GetTexImage)( ctx, target, level, texObj, |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 2045 | &imgFormat, &imgType, &freeImage); |
| 2046 | if (!image) |
| 2047 | return; |
| 2048 | |
| 2049 | texImage = texObj->Image[level]; |
| 2050 | ASSERT(texImage); |
| 2051 | if (!texImage) |
| 2052 | return; |
| 2053 | |
| 2054 | destComponents = components_in_intformat(texImage->Format); |
| 2055 | assert(destComponents > 0); |
| 2056 | numPixels = texImage->Width * texImage->Height * texImage->Depth; |
| 2057 | assert(numPixels > 0); |
| Brian Paul | b7d076f | 2000-03-21 01:03:40 +0000 | [diff] [blame] | 2058 | srcBytesPerTexel = _mesa_bytes_per_pixel(imgFormat, imgType); |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 2059 | assert(srcBytesPerTexel > 0); |
| 2060 | |
| 2061 | if (!texImage->Data) { |
| 2062 | /* Allocate memory for the texture image data */ |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 2063 | texImage->Data = (GLchan *) MALLOC(numPixels * destComponents |
| 2064 | * sizeof(GLchan) + EXTRA_BYTE); |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 2065 | } |
| 2066 | |
| 2067 | if (imgFormat == texImage->Format && imgType == GL_UNSIGNED_BYTE) { |
| 2068 | /* We got lucky! The driver's format and type match Mesa's format. */ |
| 2069 | if (texImage->Data) { |
| 2070 | MEMCPY(texImage->Data, image, numPixels * destComponents); |
| 2071 | } |
| 2072 | } |
| 2073 | else { |
| 2074 | /* Convert the texture image from the driver's format to Mesa's |
| 2075 | * internal format. |
| 2076 | */ |
| 2077 | const GLint width = texImage->Width; |
| 2078 | const GLint height = texImage->Height; |
| 2079 | const GLint depth = texImage->Depth; |
| 2080 | const GLint destBytesPerRow = width * destComponents * sizeof(GLchan); |
| 2081 | const GLint srcBytesPerRow = width * srcBytesPerTexel; |
| 2082 | const GLenum dstType = GL_UNSIGNED_BYTE; |
| 2083 | const GLenum dstFormat = texImage->Format; |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 2084 | const GLchan *srcPtr = (const GLchan *) image; |
| 2085 | GLchan *destPtr = texImage->Data; |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 2086 | |
| 2087 | if (texImage->Format == GL_COLOR_INDEX) { |
| 2088 | /* color index texture */ |
| 2089 | GLint img, row; |
| 2090 | assert(imgFormat == GL_COLOR_INDEX); |
| 2091 | for (img = 0; img < depth; img++) { |
| 2092 | for (row = 0; row < height; row++) { |
| 2093 | _mesa_unpack_index_span(ctx, width, dstType, destPtr, |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 2094 | imgType, srcPtr, &_mesa_native_packing, GL_FALSE); |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 2095 | destPtr += destBytesPerRow; |
| 2096 | srcPtr += srcBytesPerRow; |
| 2097 | } |
| 2098 | } |
| 2099 | } |
| 2100 | else { |
| 2101 | /* color texture */ |
| 2102 | GLint img, row; |
| 2103 | for (img = 0; img < depth; img++) { |
| 2104 | for (row = 0; row < height; row++) { |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 2105 | _mesa_unpack_chan_color_span(ctx, width, dstFormat, destPtr, |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 2106 | imgFormat, imgType, srcPtr, &_mesa_native_packing, GL_FALSE); |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 2107 | destPtr += destBytesPerRow; |
| 2108 | srcPtr += srcBytesPerRow; |
| 2109 | } |
| 2110 | } |
| 2111 | } |
| 2112 | } |
| 2113 | |
| 2114 | if (freeImage) |
| 2115 | FREE(image); |
| 2116 | } |
| 2117 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2118 | |
| Brian Paul | 1873b56 | 2000-10-16 23:43:12 +0000 | [diff] [blame] | 2119 | /* |
| 2120 | * Get all the mipmap images for a texture object from the device driver. |
| 2121 | * Actually, only get mipmap images if we're using a mipmap filter. |
| 2122 | */ |
| 2123 | GLboolean |
| 2124 | _mesa_get_teximages_from_driver(GLcontext *ctx, |
| 2125 | struct gl_texture_object *texObj) |
| 2126 | { |
| 2127 | if (ctx->Driver.GetTexImage) { |
| 2128 | static const GLenum targets[] = { |
| 2129 | GL_TEXTURE_1D, |
| 2130 | GL_TEXTURE_2D, |
| 2131 | GL_TEXTURE_3D, |
| 2132 | GL_TEXTURE_CUBE_MAP_ARB, |
| 2133 | GL_TEXTURE_CUBE_MAP_ARB, |
| 2134 | GL_TEXTURE_CUBE_MAP_ARB |
| 2135 | }; |
| 2136 | GLboolean needLambda = (texObj->MinFilter != texObj->MagFilter); |
| 2137 | GLenum target = targets[texObj->Dimensions - 1]; |
| 2138 | if (needLambda) { |
| 2139 | GLint level; |
| 2140 | /* Get images for all mipmap levels. We might not need them |
| 2141 | * all but this is easier. We're on a (slow) software path |
| 2142 | * anyway. |
| 2143 | */ |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 2144 | for (level = 0; level <= texObj->_P; level++) { |
| Brian Paul | 1873b56 | 2000-10-16 23:43:12 +0000 | [diff] [blame] | 2145 | struct gl_texture_image *texImg = texObj->Image[level]; |
| 2146 | if (texImg && !texImg->Data) { |
| 2147 | _mesa_get_teximage_from_driver(ctx, target, level, texObj); |
| 2148 | if (!texImg->Data) |
| 2149 | return GL_FALSE; /* out of memory */ |
| 2150 | } |
| 2151 | } |
| 2152 | } |
| 2153 | else { |
| 2154 | GLint level = texObj->BaseLevel; |
| 2155 | struct gl_texture_image *texImg = texObj->Image[level]; |
| 2156 | if (texImg && !texImg->Data) { |
| 2157 | _mesa_get_teximage_from_driver(ctx, target, level, texObj); |
| 2158 | if (!texImg->Data) |
| 2159 | return GL_FALSE; /* out of memory */ |
| 2160 | } |
| 2161 | } |
| 2162 | return GL_TRUE; |
| 2163 | } |
| 2164 | return GL_FALSE; |
| 2165 | } |
| 2166 | |
| 2167 | |
| 2168 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 2169 | void |
| 2170 | _mesa_GetTexImage( GLenum target, GLint level, GLenum format, |
| 2171 | GLenum type, GLvoid *pixels ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2172 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 2173 | GET_CURRENT_CONTEXT(ctx); |
| Brian Paul | 01e5475 | 2000-09-05 15:40:34 +0000 | [diff] [blame] | 2174 | const struct gl_texture_unit *texUnit; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2175 | const struct gl_texture_object *texObj; |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 2176 | struct gl_texture_image *texImage; |
| 2177 | GLboolean discardImage; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2178 | |
| 2179 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexImage"); |
| 2180 | |
| 2181 | if (level < 0 || level >= ctx->Const.MaxTextureLevels) { |
| 2182 | gl_error( ctx, GL_INVALID_VALUE, "glGetTexImage(level)" ); |
| 2183 | return; |
| 2184 | } |
| 2185 | |
| Brian Paul | b7d076f | 2000-03-21 01:03:40 +0000 | [diff] [blame] | 2186 | if (_mesa_sizeof_type(type) <= 0) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2187 | gl_error( ctx, GL_INVALID_ENUM, "glGetTexImage(type)" ); |
| 2188 | return; |
| 2189 | } |
| 2190 | |
| Brian Paul | b7d076f | 2000-03-21 01:03:40 +0000 | [diff] [blame] | 2191 | if (_mesa_components_in_format(format) <= 0) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2192 | gl_error( ctx, GL_INVALID_ENUM, "glGetTexImage(format)" ); |
| 2193 | return; |
| 2194 | } |
| 2195 | |
| 2196 | if (!pixels) |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 2197 | return; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2198 | |
| Brian Paul | 01e5475 | 2000-09-05 15:40:34 +0000 | [diff] [blame] | 2199 | texUnit = &(ctx->Texture.Unit[ctx->Texture.CurrentUnit]); |
| 2200 | texObj = _mesa_select_tex_object(ctx, texUnit, target); |
| Brian Paul | c52fc9b | 2000-09-05 22:11:38 +0000 | [diff] [blame] | 2201 | if (!texObj || !texImage || |
| 2202 | target == GL_PROXY_TEXTURE_1D || |
| 2203 | target == GL_PROXY_TEXTURE_2D || |
| 2204 | target == GL_PROXY_TEXTURE_3D) { |
| Brian Paul | 01e5475 | 2000-09-05 15:40:34 +0000 | [diff] [blame] | 2205 | gl_error(ctx, GL_INVALID_ENUM, "glGetTexImage(target)"); |
| 2206 | return; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2207 | } |
| 2208 | |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 2209 | if (!texImage) { |
| Brian Paul | 7298e71 | 2000-11-07 16:40:37 +0000 | [diff] [blame^] | 2210 | /* invalid mipmap level, not an error */ |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 2211 | return; |
| 2212 | } |
| 2213 | |
| 2214 | if (!texImage->Data) { |
| 2215 | /* try to get the texture image from the device driver */ |
| Brian Paul | 021a525 | 2000-03-27 17:54:17 +0000 | [diff] [blame] | 2216 | _mesa_get_teximage_from_driver(ctx, target, level, texObj); |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 2217 | discardImage = GL_TRUE; |
| 2218 | } |
| 2219 | else { |
| 2220 | discardImage = GL_FALSE; |
| 2221 | } |
| 2222 | |
| 2223 | if (texImage->Data) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2224 | GLint width = texImage->Width; |
| 2225 | GLint height = texImage->Height; |
| Brian Paul | f96ce6a | 2000-09-06 15:15:43 +0000 | [diff] [blame] | 2226 | GLint depth = texImage->Depth; |
| 2227 | GLint img, row; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2228 | |
| Brian Paul | 9499e01 | 2000-10-30 16:32:42 +0000 | [diff] [blame] | 2229 | if (ctx->NewState & _NEW_PIXEL) |
| 2230 | gl_update_state(ctx); |
| Brian Paul | fa4525e | 2000-08-21 14:22:24 +0000 | [diff] [blame] | 2231 | |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 2232 | if (ctx->_ImageTransferState & IMAGE_CONVOLUTION_BIT) { |
| Brian Paul | f96ce6a | 2000-09-06 15:15:43 +0000 | [diff] [blame] | 2233 | /* convert texture image to GL_RGBA, GL_FLOAT */ |
| 2234 | GLfloat *tmpImage, *convImage; |
| 2235 | const GLint comps = components_in_intformat(texImage->Format); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2236 | |
| Brian Paul | f96ce6a | 2000-09-06 15:15:43 +0000 | [diff] [blame] | 2237 | tmpImage = (GLfloat *) MALLOC(width * height * 4 * sizeof(GLfloat)); |
| 2238 | if (!tmpImage) { |
| 2239 | gl_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage"); |
| 2240 | return; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2241 | } |
| Brian Paul | f96ce6a | 2000-09-06 15:15:43 +0000 | [diff] [blame] | 2242 | convImage = (GLfloat *) MALLOC(width * height * 4 * sizeof(GLfloat)); |
| 2243 | if (!convImage) { |
| 2244 | FREE(tmpImage); |
| 2245 | gl_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage"); |
| 2246 | return; |
| 2247 | } |
| 2248 | |
| 2249 | for (img = 0; img < depth; img++) { |
| 2250 | GLint convWidth, convHeight; |
| 2251 | |
| 2252 | /* convert to GL_RGBA */ |
| 2253 | for (row = 0; row < height; row++) { |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 2254 | const GLchan *src = texImage->Data |
| Brian Paul | f96ce6a | 2000-09-06 15:15:43 +0000 | [diff] [blame] | 2255 | + (img * height + row ) * width * comps; |
| 2256 | GLfloat *dst = tmpImage + row * width * 4; |
| 2257 | _mesa_unpack_float_color_span(ctx, width, GL_RGBA, dst, |
| 2258 | texImage->Format, GL_UNSIGNED_BYTE, |
| 2259 | src, &_mesa_native_packing, |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 2260 | ctx->_ImageTransferState & IMAGE_PRE_CONVOLUTION_BITS, |
| Brian Paul | f96ce6a | 2000-09-06 15:15:43 +0000 | [diff] [blame] | 2261 | GL_FALSE); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2262 | } |
| Brian Paul | f96ce6a | 2000-09-06 15:15:43 +0000 | [diff] [blame] | 2263 | |
| 2264 | convWidth = width; |
| 2265 | convHeight = height; |
| 2266 | |
| 2267 | /* convolve */ |
| 2268 | if (target == GL_TEXTURE_1D) { |
| 2269 | if (ctx->Pixel.Convolution1DEnabled) { |
| 2270 | _mesa_convolve_1d_image(ctx, &convWidth, tmpImage, convImage); |
| 2271 | } |
| 2272 | } |
| 2273 | else { |
| 2274 | if (ctx->Pixel.Convolution2DEnabled) { |
| 2275 | _mesa_convolve_2d_image(ctx, &convWidth, &convHeight, |
| 2276 | tmpImage, convImage); |
| 2277 | } |
| 2278 | else if (ctx->Pixel.Separable2DEnabled) { |
| 2279 | _mesa_convolve_sep_image(ctx, &convWidth, &convHeight, |
| 2280 | tmpImage, convImage); |
| 2281 | } |
| 2282 | } |
| 2283 | |
| 2284 | /* pack convolved image */ |
| 2285 | for (row = 0; row < convHeight; row++) { |
| 2286 | const GLfloat *src = convImage + row * convWidth * 4; |
| 2287 | GLvoid *dest = _mesa_image_address(&ctx->Pack, pixels, |
| 2288 | convWidth, convHeight, |
| 2289 | format, type, img, row, 0); |
| 2290 | _mesa_pack_float_rgba_span(ctx, convWidth, |
| 2291 | (const GLfloat(*)[4]) src, |
| 2292 | format, type, dest, &ctx->Pack, |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 2293 | ctx->_ImageTransferState & IMAGE_POST_CONVOLUTION_BITS); |
| Brian Paul | f96ce6a | 2000-09-06 15:15:43 +0000 | [diff] [blame] | 2294 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2295 | } |
| Brian Paul | f96ce6a | 2000-09-06 15:15:43 +0000 | [diff] [blame] | 2296 | |
| 2297 | FREE(tmpImage); |
| 2298 | FREE(convImage); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2299 | } |
| Brian Paul | f96ce6a | 2000-09-06 15:15:43 +0000 | [diff] [blame] | 2300 | else { |
| 2301 | /* no convolution */ |
| 2302 | for (img = 0; img < depth; img++) { |
| 2303 | for (row = 0; row < height; row++) { |
| 2304 | /* compute destination address in client memory */ |
| 2305 | GLvoid *dest = _mesa_image_address( &ctx->Unpack, pixels, |
| 2306 | width, height, format, type, img, row, 0); |
| 2307 | assert(dest); |
| 2308 | if (texImage->Format == GL_RGBA) { |
| 2309 | /* simple case */ |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 2310 | const GLchan *src = texImage->Data |
| Brian Paul | f96ce6a | 2000-09-06 15:15:43 +0000 | [diff] [blame] | 2311 | + (img * height + row ) * width * 4; |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 2312 | _mesa_pack_rgba_span( ctx, width, (CONST GLchan (*)[4]) src, |
| Brian Paul | f96ce6a | 2000-09-06 15:15:43 +0000 | [diff] [blame] | 2313 | format, type, dest, &ctx->Pack, |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 2314 | ctx->_ImageTransferState ); |
| Brian Paul | f96ce6a | 2000-09-06 15:15:43 +0000 | [diff] [blame] | 2315 | } |
| 2316 | else { |
| 2317 | /* general case: convert row to RGBA format */ |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 2318 | GLchan rgba[MAX_WIDTH][4]; |
| Brian Paul | f96ce6a | 2000-09-06 15:15:43 +0000 | [diff] [blame] | 2319 | GLint i; |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 2320 | const GLchan *src; |
| Brian Paul | f96ce6a | 2000-09-06 15:15:43 +0000 | [diff] [blame] | 2321 | switch (texImage->Format) { |
| 2322 | case GL_ALPHA: |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 2323 | src = texImage->Data + row * width; |
| Brian Paul | f96ce6a | 2000-09-06 15:15:43 +0000 | [diff] [blame] | 2324 | for (i = 0; i < width; i++) { |
| Brian Paul | ba643a2 | 2000-10-28 18:34:48 +0000 | [diff] [blame] | 2325 | rgba[i][RCOMP] = CHAN_MAX; |
| 2326 | rgba[i][GCOMP] = CHAN_MAX; |
| 2327 | rgba[i][BCOMP] = CHAN_MAX; |
| Brian Paul | f96ce6a | 2000-09-06 15:15:43 +0000 | [diff] [blame] | 2328 | rgba[i][ACOMP] = src[i]; |
| 2329 | } |
| 2330 | break; |
| 2331 | case GL_LUMINANCE: |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 2332 | src = texImage->Data + row * width; |
| Brian Paul | f96ce6a | 2000-09-06 15:15:43 +0000 | [diff] [blame] | 2333 | for (i = 0; i < width; i++) { |
| 2334 | rgba[i][RCOMP] = src[i]; |
| 2335 | rgba[i][GCOMP] = src[i]; |
| 2336 | rgba[i][BCOMP] = src[i]; |
| Brian Paul | ba643a2 | 2000-10-28 18:34:48 +0000 | [diff] [blame] | 2337 | rgba[i][ACOMP] = CHAN_MAX; |
| Brian Paul | f96ce6a | 2000-09-06 15:15:43 +0000 | [diff] [blame] | 2338 | } |
| 2339 | break; |
| 2340 | case GL_LUMINANCE_ALPHA: |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 2341 | src = texImage->Data + row * 2 * width; |
| Brian Paul | f96ce6a | 2000-09-06 15:15:43 +0000 | [diff] [blame] | 2342 | for (i = 0; i < width; i++) { |
| 2343 | rgba[i][RCOMP] = src[i*2+0]; |
| 2344 | rgba[i][GCOMP] = src[i*2+0]; |
| 2345 | rgba[i][BCOMP] = src[i*2+0]; |
| 2346 | rgba[i][ACOMP] = src[i*2+1]; |
| 2347 | } |
| 2348 | break; |
| 2349 | case GL_INTENSITY: |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 2350 | src = texImage->Data + row * width; |
| Brian Paul | f96ce6a | 2000-09-06 15:15:43 +0000 | [diff] [blame] | 2351 | for (i = 0; i < width; i++) { |
| 2352 | rgba[i][RCOMP] = src[i]; |
| 2353 | rgba[i][GCOMP] = src[i]; |
| 2354 | rgba[i][BCOMP] = src[i]; |
| Brian Paul | ba643a2 | 2000-10-28 18:34:48 +0000 | [diff] [blame] | 2355 | rgba[i][ACOMP] = CHAN_MAX; |
| Brian Paul | f96ce6a | 2000-09-06 15:15:43 +0000 | [diff] [blame] | 2356 | } |
| 2357 | break; |
| 2358 | case GL_RGB: |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 2359 | src = texImage->Data + row * 3 * width; |
| Brian Paul | f96ce6a | 2000-09-06 15:15:43 +0000 | [diff] [blame] | 2360 | for (i = 0; i < width; i++) { |
| 2361 | rgba[i][RCOMP] = src[i*3+0]; |
| 2362 | rgba[i][GCOMP] = src[i*3+1]; |
| 2363 | rgba[i][BCOMP] = src[i*3+2]; |
| Brian Paul | ba643a2 | 2000-10-28 18:34:48 +0000 | [diff] [blame] | 2364 | rgba[i][ACOMP] = CHAN_MAX; |
| Brian Paul | f96ce6a | 2000-09-06 15:15:43 +0000 | [diff] [blame] | 2365 | } |
| 2366 | break; |
| 2367 | case GL_COLOR_INDEX: |
| 2368 | gl_problem( ctx, "GL_COLOR_INDEX not implemented in gl_GetTexImage" ); |
| 2369 | break; |
| 2370 | case GL_RGBA: |
| 2371 | default: |
| 2372 | gl_problem( ctx, "bad format in gl_GetTexImage" ); |
| 2373 | } |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 2374 | _mesa_pack_rgba_span( ctx, width, (const GLchan (*)[4])rgba, |
| Brian Paul | f96ce6a | 2000-09-06 15:15:43 +0000 | [diff] [blame] | 2375 | format, type, dest, &ctx->Pack, |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 2376 | ctx->_ImageTransferState ); |
| Brian Paul | f96ce6a | 2000-09-06 15:15:43 +0000 | [diff] [blame] | 2377 | } /* format */ |
| 2378 | } /* row */ |
| 2379 | } /* img */ |
| 2380 | } /* convolution */ |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 2381 | |
| 2382 | /* if we got the teximage from the device driver we'll discard it now */ |
| 2383 | if (discardImage) { |
| 2384 | FREE(texImage->Data); |
| 2385 | texImage->Data = NULL; |
| 2386 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2387 | } |
| 2388 | } |
| 2389 | |
| 2390 | |
| 2391 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 2392 | void |
| 2393 | _mesa_TexSubImage1D( GLenum target, GLint level, |
| 2394 | GLint xoffset, GLsizei width, |
| 2395 | GLenum format, GLenum type, |
| 2396 | const GLvoid *pixels ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2397 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 2398 | GET_CURRENT_CONTEXT(ctx); |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 2399 | struct gl_texture_unit *texUnit; |
| 2400 | struct gl_texture_object *texObj; |
| 2401 | struct gl_texture_image *texImage; |
| 2402 | GLboolean success = GL_FALSE; |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 2403 | GLsizei postConvWidth; |
| 2404 | |
| 2405 | postConvWidth = width; |
| 2406 | adjust_texture_size_for_convolution(ctx, 1, &postConvWidth, NULL); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2407 | |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 2408 | if (subtexture_error_check(ctx, 1, target, level, xoffset, 0, 0, |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 2409 | postConvWidth, 1, 1, format, type)) { |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 2410 | return; /* error was detected */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2411 | } |
| 2412 | |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 2413 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 2414 | texObj = texUnit->CurrentD[1]; |
| 2415 | texImage = texObj->Image[level]; |
| 2416 | assert(texImage); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2417 | |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 2418 | if (width == 0 || !pixels) |
| 2419 | return; /* no-op, not an error */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2420 | |
| Brian Paul | 9499e01 | 2000-10-30 16:32:42 +0000 | [diff] [blame] | 2421 | if (ctx->NewState & _NEW_PIXEL) |
| 2422 | gl_update_state(ctx); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 2423 | |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 2424 | if (!ctx->_ImageTransferState && ctx->Driver.TexSubImage1D) { |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 2425 | success = (*ctx->Driver.TexSubImage1D)( ctx, target, level, xoffset, |
| 2426 | width, format, type, pixels, |
| 2427 | &ctx->Unpack, texObj, texImage ); |
| 2428 | } |
| 2429 | if (!success) { |
| 2430 | /* XXX if Driver.TexSubImage1D, unpack image and try again? */ |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 2431 | GLboolean retain = GL_TRUE; |
| 2432 | if (!texImage->Data) { |
| Brian Paul | 021a525 | 2000-03-27 17:54:17 +0000 | [diff] [blame] | 2433 | _mesa_get_teximage_from_driver( ctx, target, level, texObj ); |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 2434 | if (!texImage->Data) { |
| 2435 | make_null_texture(texImage); |
| 2436 | } |
| 2437 | if (!texImage->Data) |
| 2438 | return; /* we're really out of luck! */ |
| 2439 | } |
| 2440 | |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 2441 | fill_texture_image(ctx, 1, texImage->Format, texImage->Data, |
| Brian Paul | 7298e71 | 2000-11-07 16:40:37 +0000 | [diff] [blame^] | 2442 | width, 1, 1, xoffset + texImage->Border, 0, 0, /* size and offsets */ |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 2443 | 0, 0, /* strides */ |
| 2444 | format, type, pixels, &ctx->Unpack); |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 2445 | |
| 2446 | if (ctx->Driver.TexImage1D) { |
| 2447 | (*ctx->Driver.TexImage1D)( ctx, target, level, texImage->Format, |
| 2448 | GL_UNSIGNED_BYTE, texImage->Data, |
| 2449 | &_mesa_native_packing, texObj, texImage, |
| 2450 | &retain ); |
| 2451 | } |
| 2452 | |
| 2453 | if (!retain && texImage->Data) { |
| 2454 | FREE(texImage->Data); |
| 2455 | texImage->Data = NULL; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2456 | } |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 2457 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2458 | } |
| 2459 | |
| 2460 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 2461 | void |
| 2462 | _mesa_TexSubImage2D( GLenum target, GLint level, |
| 2463 | GLint xoffset, GLint yoffset, |
| 2464 | GLsizei width, GLsizei height, |
| 2465 | GLenum format, GLenum type, |
| 2466 | const GLvoid *pixels ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2467 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 2468 | GET_CURRENT_CONTEXT(ctx); |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 2469 | struct gl_texture_unit *texUnit; |
| 2470 | struct gl_texture_object *texObj; |
| 2471 | struct gl_texture_image *texImage; |
| 2472 | GLboolean success = GL_FALSE; |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 2473 | GLsizei postConvWidth, postConvHeight; |
| 2474 | |
| 2475 | postConvWidth = width; |
| 2476 | postConvHeight = height; |
| 2477 | adjust_texture_size_for_convolution(ctx, 2, &postConvWidth,&postConvHeight); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2478 | |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 2479 | if (subtexture_error_check(ctx, 2, target, level, xoffset, yoffset, 0, |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 2480 | postConvWidth, postConvHeight, 1, format, type)) { |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 2481 | return; /* error was detected */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2482 | } |
| 2483 | |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 2484 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| Brian Paul | 35d5301 | 2000-05-23 17:14:49 +0000 | [diff] [blame] | 2485 | texObj = _mesa_select_tex_object(ctx, texUnit, target); |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 2486 | texImage = texObj->Image[level]; |
| 2487 | assert(texImage); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2488 | |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 2489 | if (width == 0 || height == 0 || !pixels) |
| 2490 | return; /* no-op, not an error */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2491 | |
| Brian Paul | 9499e01 | 2000-10-30 16:32:42 +0000 | [diff] [blame] | 2492 | if (ctx->NewState & _NEW_PIXEL) |
| 2493 | gl_update_state(ctx); |
| Brian Paul | fa4525e | 2000-08-21 14:22:24 +0000 | [diff] [blame] | 2494 | |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 2495 | if (!ctx->_ImageTransferState && ctx->Driver.TexSubImage2D) { |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 2496 | success = (*ctx->Driver.TexSubImage2D)( ctx, target, level, xoffset, |
| 2497 | yoffset, width, height, format, type, |
| 2498 | pixels, &ctx->Unpack, texObj, texImage ); |
| 2499 | } |
| 2500 | if (!success) { |
| 2501 | /* XXX if Driver.TexSubImage2D, unpack image and try again? */ |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 2502 | const GLint texComps = components_in_intformat(texImage->Format); |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 2503 | const GLint texRowStride = texImage->Width * texComps; |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 2504 | GLboolean retain = GL_TRUE; |
| 2505 | |
| 2506 | if (!texImage->Data) { |
| Brian Paul | 021a525 | 2000-03-27 17:54:17 +0000 | [diff] [blame] | 2507 | _mesa_get_teximage_from_driver( ctx, target, level, texObj ); |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 2508 | if (!texImage->Data) { |
| 2509 | make_null_texture(texImage); |
| 2510 | } |
| 2511 | if (!texImage->Data) |
| 2512 | return; /* we're really out of luck! */ |
| 2513 | } |
| 2514 | |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 2515 | fill_texture_image(ctx, 2, texImage->Format, texImage->Data, |
| Brian Paul | 7298e71 | 2000-11-07 16:40:37 +0000 | [diff] [blame^] | 2516 | width, height, 1, xoffset + texImage->Border, |
| 2517 | yoffset + texImage->Border, 0, texRowStride, 0, |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 2518 | format, type, pixels, &ctx->Unpack); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2519 | |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 2520 | if (ctx->Driver.TexImage2D) { |
| 2521 | (*ctx->Driver.TexImage2D)(ctx, target, level, texImage->Format, |
| 2522 | GL_UNSIGNED_BYTE, texImage->Data, |
| 2523 | &_mesa_native_packing, texObj, texImage, |
| 2524 | &retain); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2525 | } |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 2526 | |
| 2527 | if (!retain && texImage->Data) { |
| 2528 | FREE(texImage->Data); |
| 2529 | texImage->Data = NULL; |
| 2530 | } |
| 2531 | |
| 2532 | #ifdef OLD_DD_TEXTURE |
| 2533 | /* XXX this will be removed in the future */ |
| 2534 | if (ctx->Driver.TexSubImage) { |
| 2535 | (*ctx->Driver.TexSubImage)(ctx, target, texObj, level, |
| 2536 | xoffset, yoffset, width, height, |
| 2537 | texImage->IntFormat, texImage); |
| 2538 | } |
| 2539 | else if (ctx->Driver.TexImage) { |
| Brian Paul | 9fd2b0a | 2000-03-24 23:59:06 +0000 | [diff] [blame] | 2540 | (*ctx->Driver.TexImage)(ctx, GL_TEXTURE_2D, texObj, |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 2541 | level, texImage->IntFormat, texImage ); |
| 2542 | } |
| 2543 | #endif |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2544 | } |
| 2545 | } |
| 2546 | |
| 2547 | |
| 2548 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 2549 | void |
| 2550 | _mesa_TexSubImage3D( GLenum target, GLint level, |
| 2551 | GLint xoffset, GLint yoffset, GLint zoffset, |
| 2552 | GLsizei width, GLsizei height, GLsizei depth, |
| 2553 | GLenum format, GLenum type, |
| 2554 | const GLvoid *pixels ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2555 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 2556 | GET_CURRENT_CONTEXT(ctx); |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 2557 | struct gl_texture_unit *texUnit; |
| 2558 | struct gl_texture_object *texObj; |
| 2559 | struct gl_texture_image *texImage; |
| 2560 | GLboolean success = GL_FALSE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2561 | |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 2562 | if (subtexture_error_check(ctx, 3, target, level, xoffset, yoffset, zoffset, |
| 2563 | width, height, depth, format, type)) { |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 2564 | return; /* error was detected */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2565 | } |
| 2566 | |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 2567 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 2568 | texObj = texUnit->CurrentD[3]; |
| 2569 | texImage = texObj->Image[level]; |
| 2570 | assert(texImage); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2571 | |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 2572 | if (width == 0 || height == 0 || height == 0 || !pixels) |
| 2573 | return; /* no-op, not an error */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2574 | |
| Brian Paul | 9499e01 | 2000-10-30 16:32:42 +0000 | [diff] [blame] | 2575 | if (ctx->NewState & _NEW_PIXEL) |
| 2576 | gl_update_state(ctx); |
| Brian Paul | fa4525e | 2000-08-21 14:22:24 +0000 | [diff] [blame] | 2577 | |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 2578 | if (!ctx->_ImageTransferState && ctx->Driver.TexSubImage3D) { |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 2579 | success = (*ctx->Driver.TexSubImage3D)( ctx, target, level, xoffset, |
| 2580 | yoffset, zoffset, width, height, depth, format, |
| 2581 | type, pixels, &ctx->Unpack, texObj, texImage ); |
| 2582 | } |
| 2583 | if (!success) { |
| 2584 | /* XXX if Driver.TexSubImage3D, unpack image and try again? */ |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 2585 | const GLint texComps = components_in_intformat(texImage->Format); |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 2586 | const GLint texRowStride = texImage->Width * texComps; |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 2587 | const GLint texImgStride = texRowStride * texImage->Height; |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 2588 | GLboolean retain = GL_TRUE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2589 | |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 2590 | if (!texImage->Data) { |
| 2591 | _mesa_get_teximage_from_driver( ctx, target, level, texObj ); |
| 2592 | if (!texImage->Data) { |
| 2593 | make_null_texture(texImage); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2594 | } |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 2595 | if (!texImage->Data) |
| 2596 | return; /* we're really out of luck! */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2597 | } |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 2598 | |
| 2599 | fill_texture_image(ctx, 3, texImage->Format, texImage->Data, |
| Brian Paul | 7298e71 | 2000-11-07 16:40:37 +0000 | [diff] [blame^] | 2600 | width, height, depth, xoffset + texImage->Border, |
| 2601 | yoffset + texImage->Border, |
| 2602 | zoffset + texImage->Border, texRowStride, |
| 2603 | texImgStride, format, type, pixels, &ctx->Unpack); |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 2604 | |
| 2605 | if (ctx->Driver.TexImage3D) { |
| 2606 | (*ctx->Driver.TexImage3D)(ctx, target, level, texImage->Format, |
| 2607 | GL_UNSIGNED_BYTE, texImage->Data, |
| 2608 | &_mesa_native_packing, texObj, texImage, |
| 2609 | &retain); |
| 2610 | } |
| 2611 | |
| 2612 | if (!retain && texImage->Data) { |
| 2613 | FREE(texImage->Data); |
| 2614 | texImage->Data = NULL; |
| 2615 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2616 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2617 | } |
| 2618 | |
| 2619 | |
| 2620 | |
| 2621 | /* |
| 2622 | * Read an RGBA image from the frame buffer. |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 2623 | * This is used by glCopyTex[Sub]Image[12]D(). |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2624 | * Input: ctx - the context |
| 2625 | * x, y - lower left corner |
| 2626 | * width, height - size of region to read |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 2627 | * Return: pointer to block of GL_RGBA, GLchan data. |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2628 | */ |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 2629 | static GLchan * |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 2630 | read_color_image( GLcontext *ctx, GLint x, GLint y, |
| 2631 | GLsizei width, GLsizei height ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2632 | { |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 2633 | GLint stride, i; |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 2634 | GLchan *image, *dst; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2635 | |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 2636 | image = (GLchan *) MALLOC(width * height * 4 * sizeof(GLchan)); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 2637 | if (!image) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2638 | return NULL; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2639 | |
| 2640 | /* Select buffer to read from */ |
| Brian Paul | cea0e8e | 1999-11-25 17:36:48 +0000 | [diff] [blame] | 2641 | (*ctx->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer, |
| 2642 | ctx->Pixel.DriverReadBuffer ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2643 | |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 2644 | dst = image; |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 2645 | stride = width * 4; |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 2646 | for (i = 0; i < height; i++) { |
| Brian Paul | 3f02f90 | 1999-11-24 18:48:30 +0000 | [diff] [blame] | 2647 | gl_read_rgba_span( ctx, ctx->ReadBuffer, width, x, y + i, |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 2648 | (GLchan (*)[4]) dst ); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 2649 | dst += stride; |
| 2650 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2651 | |
| Brian Paul | cea0e8e | 1999-11-25 17:36:48 +0000 | [diff] [blame] | 2652 | /* Read from draw buffer (the default) */ |
| 2653 | (*ctx->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer, |
| 2654 | ctx->Color.DriverDrawBuffer ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2655 | |
| 2656 | return image; |
| 2657 | } |
| 2658 | |
| 2659 | |
| 2660 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 2661 | void |
| 2662 | _mesa_CopyTexImage1D( GLenum target, GLint level, |
| 2663 | GLenum internalFormat, |
| 2664 | GLint x, GLint y, |
| 2665 | GLsizei width, GLint border ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2666 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 2667 | GET_CURRENT_CONTEXT(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2668 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCopyTexImage1D"); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2669 | |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 2670 | if (copytexture_error_check(ctx, 1, target, level, internalFormat, |
| 2671 | width, 1, border)) |
| 2672 | return; |
| 2673 | |
| Brian Paul | 9499e01 | 2000-10-30 16:32:42 +0000 | [diff] [blame] | 2674 | if (ctx->NewState & _NEW_PIXEL) |
| 2675 | gl_update_state(ctx); |
| Brian Paul | fa4525e | 2000-08-21 14:22:24 +0000 | [diff] [blame] | 2676 | |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 2677 | if (ctx->_ImageTransferState || !ctx->Driver.CopyTexImage1D |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 2678 | || !(*ctx->Driver.CopyTexImage1D)(ctx, target, level, |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 2679 | internalFormat, x, y, width, border)) { |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 2680 | struct gl_pixelstore_attrib unpackSave; |
| 2681 | |
| 2682 | /* get image from framebuffer */ |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 2683 | GLchan *image = read_color_image( ctx, x, y, width, 1 ); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 2684 | if (!image) { |
| 2685 | gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexImage1D" ); |
| 2686 | return; |
| 2687 | } |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 2688 | |
| 2689 | /* call glTexImage1D to redefine the texture */ |
| 2690 | unpackSave = ctx->Unpack; |
| 2691 | ctx->Unpack = _mesa_native_packing; |
| Brian Paul | 3ab6bbe | 2000-02-12 17:26:15 +0000 | [diff] [blame] | 2692 | (*ctx->Exec->TexImage1D)( target, level, internalFormat, width, |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 2693 | border, GL_RGBA, GL_UNSIGNED_BYTE, image ); |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 2694 | ctx->Unpack = unpackSave; |
| 2695 | |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 2696 | FREE(image); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2697 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2698 | } |
| 2699 | |
| 2700 | |
| 2701 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 2702 | void |
| 2703 | _mesa_CopyTexImage2D( GLenum target, GLint level, GLenum internalFormat, |
| 2704 | GLint x, GLint y, GLsizei width, GLsizei height, |
| 2705 | GLint border ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2706 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 2707 | GET_CURRENT_CONTEXT(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2708 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCopyTexImage2D"); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2709 | |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 2710 | if (copytexture_error_check(ctx, 2, target, level, internalFormat, |
| 2711 | width, height, border)) |
| 2712 | return; |
| 2713 | |
| Brian Paul | 9499e01 | 2000-10-30 16:32:42 +0000 | [diff] [blame] | 2714 | if (ctx->NewState & _NEW_PIXEL) |
| 2715 | gl_update_state(ctx); |
| Brian Paul | fa4525e | 2000-08-21 14:22:24 +0000 | [diff] [blame] | 2716 | |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 2717 | if (ctx->_ImageTransferState || !ctx->Driver.CopyTexImage2D |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 2718 | || !(*ctx->Driver.CopyTexImage2D)(ctx, target, level, |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 2719 | internalFormat, x, y, width, height, border)) { |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 2720 | struct gl_pixelstore_attrib unpackSave; |
| 2721 | |
| 2722 | /* get image from framebuffer */ |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 2723 | GLchan *image = read_color_image( ctx, x, y, width, height ); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 2724 | if (!image) { |
| 2725 | gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexImage2D" ); |
| 2726 | return; |
| 2727 | } |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 2728 | |
| 2729 | /* call glTexImage2D to redefine the texture */ |
| 2730 | unpackSave = ctx->Unpack; |
| 2731 | ctx->Unpack = _mesa_native_packing; |
| Brian Paul | 3ab6bbe | 2000-02-12 17:26:15 +0000 | [diff] [blame] | 2732 | (ctx->Exec->TexImage2D)( target, level, internalFormat, width, |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 2733 | height, border, GL_RGBA, GL_UNSIGNED_BYTE, image ); |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 2734 | ctx->Unpack = unpackSave; |
| 2735 | |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 2736 | FREE(image); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2737 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2738 | } |
| 2739 | |
| 2740 | |
| 2741 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 2742 | void |
| 2743 | _mesa_CopyTexSubImage1D( GLenum target, GLint level, |
| 2744 | GLint xoffset, GLint x, GLint y, GLsizei width ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2745 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 2746 | GET_CURRENT_CONTEXT(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2747 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCopyTexSubImage1D"); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2748 | |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 2749 | if (copytexsubimage_error_check(ctx, 1, target, level, |
| 2750 | xoffset, 0, 0, width, 1)) |
| 2751 | return; |
| 2752 | |
| Brian Paul | 9499e01 | 2000-10-30 16:32:42 +0000 | [diff] [blame] | 2753 | if (ctx->NewState & _NEW_PIXEL) |
| 2754 | gl_update_state(ctx); |
| Brian Paul | fa4525e | 2000-08-21 14:22:24 +0000 | [diff] [blame] | 2755 | |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 2756 | if (ctx->_ImageTransferState || !ctx->Driver.CopyTexSubImage1D |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 2757 | || !(*ctx->Driver.CopyTexSubImage1D)(ctx, target, level, |
| 2758 | xoffset, x, y, width)) { |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 2759 | struct gl_texture_unit *texUnit; |
| 2760 | struct gl_texture_image *teximage; |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 2761 | struct gl_pixelstore_attrib unpackSave; |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 2762 | GLchan *image; |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 2763 | |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 2764 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 2765 | teximage = texUnit->CurrentD[1]->Image[level]; |
| 2766 | assert(teximage); |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 2767 | |
| 2768 | /* get image from frame buffer */ |
| 2769 | image = read_color_image(ctx, x, y, width, 1); |
| 2770 | if (!image) { |
| 2771 | gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexSubImage2D" ); |
| 2772 | return; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2773 | } |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 2774 | |
| 2775 | /* now call glTexSubImage1D to do the real work */ |
| 2776 | unpackSave = ctx->Unpack; |
| 2777 | ctx->Unpack = _mesa_native_packing; |
| 2778 | _mesa_TexSubImage1D(target, level, xoffset, width, |
| 2779 | GL_RGBA, GL_UNSIGNED_BYTE, image); |
| 2780 | ctx->Unpack = unpackSave; |
| 2781 | |
| 2782 | FREE(image); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2783 | } |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 2784 | } |
| 2785 | |
| 2786 | |
| 2787 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 2788 | void |
| 2789 | _mesa_CopyTexSubImage2D( GLenum target, GLint level, |
| 2790 | GLint xoffset, GLint yoffset, |
| 2791 | GLint x, GLint y, GLsizei width, GLsizei height ) |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 2792 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 2793 | GET_CURRENT_CONTEXT(ctx); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 2794 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCopyTexSubImage2D"); |
| 2795 | |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 2796 | if (copytexsubimage_error_check(ctx, 2, target, level, |
| 2797 | xoffset, yoffset, 0, width, height)) |
| 2798 | return; |
| 2799 | |
| Brian Paul | 9499e01 | 2000-10-30 16:32:42 +0000 | [diff] [blame] | 2800 | if (ctx->NewState & _NEW_PIXEL) |
| 2801 | gl_update_state(ctx); |
| Brian Paul | fa4525e | 2000-08-21 14:22:24 +0000 | [diff] [blame] | 2802 | |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 2803 | if (ctx->_ImageTransferState || !ctx->Driver.CopyTexSubImage2D |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 2804 | || !(*ctx->Driver.CopyTexSubImage2D)(ctx, target, level, |
| 2805 | xoffset, yoffset, x, y, width, height )) { |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 2806 | struct gl_texture_unit *texUnit; |
| 2807 | struct gl_texture_image *teximage; |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 2808 | struct gl_pixelstore_attrib unpackSave; |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 2809 | GLchan *image; |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 2810 | |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 2811 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 2812 | teximage = texUnit->CurrentD[2]->Image[level]; |
| 2813 | assert(teximage); |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 2814 | |
| 2815 | /* get image from frame buffer */ |
| 2816 | image = read_color_image(ctx, x, y, width, height); |
| 2817 | if (!image) { |
| 2818 | gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexSubImage2D" ); |
| 2819 | return; |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 2820 | } |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 2821 | |
| 2822 | /* now call glTexSubImage2D to do the real work */ |
| 2823 | unpackSave = ctx->Unpack; |
| 2824 | ctx->Unpack = _mesa_native_packing; |
| 2825 | _mesa_TexSubImage2D(target, level, xoffset, yoffset, width, height, |
| 2826 | GL_RGBA, GL_UNSIGNED_BYTE, image); |
| 2827 | ctx->Unpack = unpackSave; |
| 2828 | |
| 2829 | FREE(image); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 2830 | } |
| 2831 | } |
| 2832 | |
| 2833 | |
| 2834 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 2835 | void |
| 2836 | _mesa_CopyTexSubImage3D( GLenum target, GLint level, |
| 2837 | GLint xoffset, GLint yoffset, GLint zoffset, |
| 2838 | GLint x, GLint y, GLsizei width, GLsizei height ) |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 2839 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 2840 | GET_CURRENT_CONTEXT(ctx); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 2841 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCopyTexSubImage3D"); |
| 2842 | |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 2843 | if (copytexsubimage_error_check(ctx, 3, target, level, |
| 2844 | xoffset, yoffset, zoffset, width, height)) |
| 2845 | return; |
| 2846 | |
| Brian Paul | 9499e01 | 2000-10-30 16:32:42 +0000 | [diff] [blame] | 2847 | if (ctx->NewState & _NEW_PIXEL) |
| 2848 | gl_update_state(ctx); |
| Brian Paul | fa4525e | 2000-08-21 14:22:24 +0000 | [diff] [blame] | 2849 | |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 2850 | if (ctx->_ImageTransferState || !ctx->Driver.CopyTexSubImage3D |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 2851 | || !(*ctx->Driver.CopyTexSubImage3D)(ctx, target, level, |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 2852 | xoffset, yoffset, zoffset, x, y, width, height )) { |
| 2853 | struct gl_texture_unit *texUnit; |
| 2854 | struct gl_texture_image *teximage; |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 2855 | struct gl_pixelstore_attrib unpackSave; |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 2856 | GLchan *image; |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 2857 | |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 2858 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 2859 | teximage = texUnit->CurrentD[3]->Image[level]; |
| 2860 | assert(teximage); |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 2861 | |
| 2862 | /* get image from frame buffer */ |
| 2863 | image = read_color_image(ctx, x, y, width, height); |
| 2864 | if (!image) { |
| 2865 | gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexSubImage2D" ); |
| 2866 | return; |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 2867 | } |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 2868 | |
| 2869 | /* now call glTexSubImage2D to do the real work */ |
| 2870 | unpackSave = ctx->Unpack; |
| 2871 | ctx->Unpack = _mesa_native_packing; |
| 2872 | _mesa_TexSubImage3D(target, level, xoffset, yoffset, zoffset, |
| 2873 | width, height, 1, GL_RGBA, GL_UNSIGNED_BYTE, image); |
| 2874 | ctx->Unpack = unpackSave; |
| 2875 | |
| 2876 | FREE(image); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2877 | } |
| 2878 | } |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 2879 | |
| 2880 | |
| 2881 | |
| 2882 | void |
| 2883 | _mesa_CompressedTexImage1DARB(GLenum target, GLint level, |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2884 | GLenum internalFormat, GLsizei width, |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 2885 | GLint border, GLsizei imageSize, |
| 2886 | const GLvoid *data) |
| 2887 | { |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2888 | GET_CURRENT_CONTEXT(ctx); |
| 2889 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCompressedTexImage1DARB"); |
| 2890 | |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 2891 | switch (internalFormat) { |
| 2892 | case GL_COMPRESSED_ALPHA_ARB: |
| 2893 | case GL_COMPRESSED_LUMINANCE_ARB: |
| 2894 | case GL_COMPRESSED_LUMINANCE_ALPHA_ARB: |
| 2895 | case GL_COMPRESSED_INTENSITY_ARB: |
| 2896 | case GL_COMPRESSED_RGB_ARB: |
| 2897 | case GL_COMPRESSED_RGBA_ARB: |
| 2898 | gl_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage1DARB"); |
| 2899 | return; |
| 2900 | default: |
| 2901 | /* silence compiler warning */ |
| 2902 | ; |
| 2903 | } |
| 2904 | |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2905 | if (target == GL_TEXTURE_1D) { |
| 2906 | struct gl_texture_unit *texUnit; |
| 2907 | struct gl_texture_object *texObj; |
| 2908 | struct gl_texture_image *texImage; |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 2909 | GLsizei computedImageSize; |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2910 | |
| 2911 | if (texture_error_check(ctx, target, level, internalFormat, |
| 2912 | GL_NONE, GL_NONE, 1, width, 1, 1, border)) { |
| 2913 | return; /* error in texture image was detected */ |
| 2914 | } |
| 2915 | |
| 2916 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 2917 | texObj = texUnit->CurrentD[1]; |
| 2918 | texImage = texObj->Image[level]; |
| 2919 | |
| 2920 | if (!texImage) { |
| 2921 | texImage = _mesa_alloc_texture_image(); |
| 2922 | texObj->Image[level] = texImage; |
| 2923 | if (!texImage) { |
| 2924 | gl_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage1DARB"); |
| 2925 | return; |
| 2926 | } |
| 2927 | } |
| 2928 | else if (texImage->Data) { |
| 2929 | FREE(texImage->Data); |
| 2930 | texImage->Data = NULL; |
| 2931 | } |
| 2932 | |
| 2933 | /* setup the teximage struct's fields */ |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 2934 | init_texture_image(ctx, texImage, width, 1, 1, |
| 2935 | border, internalFormat); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2936 | |
| 2937 | /* process the texture image */ |
| 2938 | if (data) { |
| 2939 | GLboolean retain = GL_TRUE; |
| 2940 | GLboolean success = GL_FALSE; |
| 2941 | if (ctx->Driver.CompressedTexImage1D) { |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 2942 | success = (*ctx->Driver.CompressedTexImage1D)(ctx, target, level, |
| 2943 | imageSize, data, texObj, texImage, &retain); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2944 | } |
| 2945 | if (retain || !success) { |
| 2946 | /* make internal copy of the texture image */ |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 2947 | computedImageSize = _mesa_compressed_image_size(ctx, |
| 2948 | internalFormat, |
| 2949 | 1, /* num dims */ |
| 2950 | width, |
| 2951 | 1, /* height */ |
| 2952 | 1); /* depth */ |
| 2953 | if (computedImageSize != imageSize) { |
| 2954 | gl_error(ctx, GL_INVALID_VALUE, "glCompressedTexImage1DARB(imageSize)"); |
| 2955 | return; |
| 2956 | } |
| 2957 | texImage->Data = MALLOC(computedImageSize); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2958 | if (texImage->Data) { |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 2959 | MEMCPY(texImage->Data, data, computedImageSize); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2960 | } |
| 2961 | } |
| 2962 | if (!retain && texImage->Data) { |
| 2963 | FREE(texImage->Data); |
| 2964 | texImage->Data = NULL; |
| 2965 | } |
| 2966 | } |
| 2967 | else { |
| 2968 | make_null_texture(texImage); |
| 2969 | if (ctx->Driver.CompressedTexImage1D) { |
| 2970 | GLboolean retain; |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 2971 | (*ctx->Driver.CompressedTexImage1D)(ctx, target, level, 0, |
| 2972 | texImage->Data, texObj, |
| 2973 | texImage, &retain); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2974 | } |
| 2975 | } |
| 2976 | |
| 2977 | /* state update */ |
| 2978 | gl_put_texobj_on_dirty_list( ctx, texObj ); |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 2979 | ctx->NewState |= _NEW_TEXTURE; |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2980 | } |
| 2981 | else if (target == GL_PROXY_TEXTURE_1D) { |
| 2982 | /* Proxy texture: check for errors and update proxy state */ |
| Brian Paul | 38d3f3d | 2000-09-07 15:38:49 +0000 | [diff] [blame] | 2983 | GLenum error = texture_error_check(ctx, target, level, internalFormat, |
| 2984 | GL_NONE, GL_NONE, 1, width, 1, 1, border); |
| 2985 | if (!error && ctx->Driver.TestProxyTexImage) { |
| 2986 | error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, |
| 2987 | internalFormat, GL_NONE, GL_NONE, |
| 2988 | width, 1, 1, border); |
| 2989 | } |
| 2990 | if (error) { |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2991 | /* if error, clear all proxy texture image parameters */ |
| 2992 | if (level>=0 && level<ctx->Const.MaxTextureLevels) { |
| Brian Paul | 9c27278 | 2000-09-05 22:04:30 +0000 | [diff] [blame] | 2993 | clear_proxy_teximage(ctx->Texture.Proxy1D->Image[level]); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2994 | } |
| 2995 | } |
| 2996 | else { |
| 2997 | /* if no error, update proxy texture image parameters */ |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 2998 | init_texture_image(ctx, ctx->Texture.Proxy1D->Image[level], |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2999 | width, 1, 1, border, internalFormat); |
| 3000 | } |
| 3001 | } |
| 3002 | else { |
| 3003 | gl_error( ctx, GL_INVALID_ENUM, "glCompressedTexImage1DARB(target)" ); |
| 3004 | return; |
| 3005 | } |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 3006 | } |
| 3007 | |
| 3008 | |
| 3009 | void |
| 3010 | _mesa_CompressedTexImage2DARB(GLenum target, GLint level, |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 3011 | GLenum internalFormat, GLsizei width, |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 3012 | GLsizei height, GLint border, GLsizei imageSize, |
| 3013 | const GLvoid *data) |
| 3014 | { |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 3015 | GET_CURRENT_CONTEXT(ctx); |
| 3016 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCompressedTexImage2DARB"); |
| 3017 | |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 3018 | switch (internalFormat) { |
| 3019 | case GL_COMPRESSED_ALPHA_ARB: |
| 3020 | case GL_COMPRESSED_LUMINANCE_ARB: |
| 3021 | case GL_COMPRESSED_LUMINANCE_ALPHA_ARB: |
| 3022 | case GL_COMPRESSED_INTENSITY_ARB: |
| 3023 | case GL_COMPRESSED_RGB_ARB: |
| 3024 | case GL_COMPRESSED_RGBA_ARB: |
| 3025 | gl_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage2DARB"); |
| 3026 | return; |
| 3027 | default: |
| 3028 | /* silence compiler warning */ |
| 3029 | ; |
| 3030 | } |
| 3031 | |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 3032 | if (target==GL_TEXTURE_2D || |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 3033 | (ctx->Extensions.ARB_texture_cube_map && |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 3034 | target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && |
| 3035 | target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)) { |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 3036 | struct gl_texture_unit *texUnit; |
| 3037 | struct gl_texture_object *texObj; |
| 3038 | struct gl_texture_image *texImage; |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 3039 | GLsizei computedImageSize; |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 3040 | |
| 3041 | if (texture_error_check(ctx, target, level, internalFormat, |
| 3042 | GL_NONE, GL_NONE, 1, width, height, 1, border)) { |
| 3043 | return; /* error in texture image was detected */ |
| 3044 | } |
| 3045 | |
| 3046 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 3047 | texObj = texUnit->CurrentD[2]; |
| 3048 | texImage = texObj->Image[level]; |
| 3049 | |
| 3050 | if (!texImage) { |
| 3051 | texImage = _mesa_alloc_texture_image(); |
| 3052 | texObj->Image[level] = texImage; |
| 3053 | if (!texImage) { |
| 3054 | gl_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2DARB"); |
| 3055 | return; |
| 3056 | } |
| 3057 | } |
| 3058 | else if (texImage->Data) { |
| 3059 | FREE(texImage->Data); |
| 3060 | texImage->Data = NULL; |
| 3061 | } |
| 3062 | |
| 3063 | /* setup the teximage struct's fields */ |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 3064 | init_texture_image(ctx, texImage, width, height, 1, border, internalFormat); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 3065 | |
| 3066 | /* process the texture image */ |
| 3067 | if (data) { |
| 3068 | GLboolean retain = GL_TRUE; |
| 3069 | GLboolean success = GL_FALSE; |
| 3070 | if (ctx->Driver.CompressedTexImage2D) { |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 3071 | success = (*ctx->Driver.CompressedTexImage2D)( ctx, |
| 3072 | target, |
| 3073 | level, |
| 3074 | imageSize, |
| 3075 | data, |
| 3076 | texObj, |
| 3077 | texImage, |
| 3078 | &retain); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 3079 | } |
| 3080 | if (retain || !success) { |
| 3081 | /* make internal copy of the texture image */ |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 3082 | computedImageSize = _mesa_compressed_image_size(ctx, |
| 3083 | internalFormat, |
| 3084 | 2, /* num dims */ |
| 3085 | width, |
| 3086 | height, |
| 3087 | 1); /* depth */ |
| 3088 | if (computedImageSize != imageSize) { |
| 3089 | gl_error(ctx, GL_INVALID_VALUE, "glCompressedTexImage2DARB(imageSize)"); |
| 3090 | return; |
| 3091 | } |
| 3092 | texImage->Data = MALLOC(computedImageSize); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 3093 | if (texImage->Data) { |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 3094 | MEMCPY(texImage->Data, data, computedImageSize); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 3095 | } |
| 3096 | } |
| 3097 | if (!retain && texImage->Data) { |
| 3098 | FREE(texImage->Data); |
| 3099 | texImage->Data = NULL; |
| 3100 | } |
| 3101 | } |
| 3102 | else { |
| 3103 | make_null_texture(texImage); |
| 3104 | if (ctx->Driver.CompressedTexImage2D) { |
| 3105 | GLboolean retain; |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 3106 | (*ctx->Driver.CompressedTexImage2D)( ctx, target, level, 0, |
| 3107 | texImage->Data, texObj, |
| 3108 | texImage, &retain); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 3109 | } |
| 3110 | } |
| 3111 | |
| 3112 | /* state update */ |
| 3113 | gl_put_texobj_on_dirty_list( ctx, texObj ); |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 3114 | ctx->NewState |= _NEW_TEXTURE; |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 3115 | } |
| 3116 | else if (target == GL_PROXY_TEXTURE_2D) { |
| 3117 | /* Proxy texture: check for errors and update proxy state */ |
| Brian Paul | 38d3f3d | 2000-09-07 15:38:49 +0000 | [diff] [blame] | 3118 | GLenum error = texture_error_check(ctx, target, level, internalFormat, |
| 3119 | GL_NONE, GL_NONE, 2, width, height, 1, border); |
| 3120 | if (!error && ctx->Driver.TestProxyTexImage) { |
| 3121 | error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, |
| 3122 | internalFormat, GL_NONE, GL_NONE, |
| 3123 | width, height, 1, border); |
| 3124 | } |
| 3125 | if (error) { |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 3126 | /* if error, clear all proxy texture image parameters */ |
| 3127 | if (level>=0 && level<ctx->Const.MaxTextureLevels) { |
| Brian Paul | 9c27278 | 2000-09-05 22:04:30 +0000 | [diff] [blame] | 3128 | clear_proxy_teximage(ctx->Texture.Proxy2D->Image[level]); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 3129 | } |
| 3130 | } |
| 3131 | else { |
| 3132 | /* if no error, update proxy texture image parameters */ |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 3133 | init_texture_image(ctx, ctx->Texture.Proxy2D->Image[level], |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 3134 | width, 1, 1, border, internalFormat); |
| 3135 | } |
| 3136 | } |
| 3137 | else { |
| 3138 | gl_error( ctx, GL_INVALID_ENUM, "glCompressedTexImage2DARB(target)" ); |
| 3139 | return; |
| 3140 | } |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 3141 | } |
| 3142 | |
| 3143 | |
| 3144 | void |
| 3145 | _mesa_CompressedTexImage3DARB(GLenum target, GLint level, |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 3146 | GLenum internalFormat, GLsizei width, |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 3147 | GLsizei height, GLsizei depth, GLint border, |
| 3148 | GLsizei imageSize, const GLvoid *data) |
| 3149 | { |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 3150 | GET_CURRENT_CONTEXT(ctx); |
| 3151 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCompressedTexImage3DARB"); |
| 3152 | |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 3153 | switch (internalFormat) { |
| 3154 | case GL_COMPRESSED_ALPHA_ARB: |
| 3155 | case GL_COMPRESSED_LUMINANCE_ARB: |
| 3156 | case GL_COMPRESSED_LUMINANCE_ALPHA_ARB: |
| 3157 | case GL_COMPRESSED_INTENSITY_ARB: |
| 3158 | case GL_COMPRESSED_RGB_ARB: |
| 3159 | case GL_COMPRESSED_RGBA_ARB: |
| 3160 | gl_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage3DARB"); |
| 3161 | return; |
| 3162 | default: |
| 3163 | /* silence compiler warning */ |
| 3164 | ; |
| 3165 | } |
| 3166 | |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 3167 | if (target == GL_TEXTURE_3D) { |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 3168 | struct gl_texture_unit *texUnit; |
| 3169 | struct gl_texture_object *texObj; |
| 3170 | struct gl_texture_image *texImage; |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 3171 | GLsizei computedImageSize; |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 3172 | |
| 3173 | if (texture_error_check(ctx, target, level, internalFormat, |
| 3174 | GL_NONE, GL_NONE, 1, width, height, depth, border)) { |
| 3175 | return; /* error in texture image was detected */ |
| 3176 | } |
| 3177 | |
| 3178 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 3179 | texObj = texUnit->CurrentD[3]; |
| 3180 | texImage = texObj->Image[level]; |
| 3181 | |
| 3182 | if (!texImage) { |
| 3183 | texImage = _mesa_alloc_texture_image(); |
| 3184 | texObj->Image[level] = texImage; |
| 3185 | if (!texImage) { |
| 3186 | gl_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage3DARB"); |
| 3187 | return; |
| 3188 | } |
| 3189 | } |
| 3190 | else if (texImage->Data) { |
| 3191 | FREE(texImage->Data); |
| 3192 | texImage->Data = NULL; |
| 3193 | } |
| 3194 | |
| 3195 | /* setup the teximage struct's fields */ |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 3196 | init_texture_image(ctx, texImage, width, height, depth, |
| 3197 | border, internalFormat); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 3198 | |
| 3199 | /* process the texture image */ |
| 3200 | if (data) { |
| 3201 | GLboolean retain = GL_TRUE; |
| 3202 | GLboolean success = GL_FALSE; |
| 3203 | if (ctx->Driver.CompressedTexImage3D) { |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 3204 | success = (*ctx->Driver.CompressedTexImage3D)(ctx, target, level, |
| 3205 | imageSize, data, |
| 3206 | texObj, texImage, |
| 3207 | &retain); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 3208 | } |
| 3209 | if (retain || !success) { |
| 3210 | /* make internal copy of the texture image */ |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 3211 | computedImageSize = _mesa_compressed_image_size(ctx, |
| 3212 | internalFormat, |
| 3213 | 3, /* num dims */ |
| 3214 | width, |
| 3215 | height, |
| 3216 | depth); |
| 3217 | if (computedImageSize != imageSize) { |
| 3218 | gl_error(ctx, GL_INVALID_VALUE, "glCompressedTexImage3DARB(imageSize)"); |
| 3219 | return; |
| 3220 | } |
| 3221 | texImage->Data = MALLOC(computedImageSize); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 3222 | if (texImage->Data) { |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 3223 | MEMCPY(texImage->Data, data, computedImageSize); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 3224 | } |
| 3225 | } |
| 3226 | if (!retain && texImage->Data) { |
| 3227 | FREE(texImage->Data); |
| 3228 | texImage->Data = NULL; |
| 3229 | } |
| 3230 | } |
| 3231 | else { |
| 3232 | make_null_texture(texImage); |
| 3233 | if (ctx->Driver.CompressedTexImage3D) { |
| 3234 | GLboolean retain; |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 3235 | (*ctx->Driver.CompressedTexImage3D)( ctx, target, level, 0, |
| 3236 | texImage->Data, texObj, |
| 3237 | texImage, &retain); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 3238 | } |
| 3239 | } |
| 3240 | |
| 3241 | /* state update */ |
| 3242 | gl_put_texobj_on_dirty_list( ctx, texObj ); |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 3243 | ctx->NewState |= _NEW_TEXTURE; |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 3244 | } |
| 3245 | else if (target == GL_PROXY_TEXTURE_3D) { |
| 3246 | /* Proxy texture: check for errors and update proxy state */ |
| Brian Paul | 38d3f3d | 2000-09-07 15:38:49 +0000 | [diff] [blame] | 3247 | GLenum error = texture_error_check(ctx, target, level, internalFormat, |
| 3248 | GL_NONE, GL_NONE, 1, width, height, depth, border); |
| 3249 | if (!error && ctx->Driver.TestProxyTexImage) { |
| 3250 | error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, |
| 3251 | internalFormat, GL_NONE, GL_NONE, |
| 3252 | width, height, depth, border); |
| 3253 | } |
| 3254 | if (error) { |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 3255 | /* if error, clear all proxy texture image parameters */ |
| 3256 | if (level>=0 && level<ctx->Const.MaxTextureLevels) { |
| Brian Paul | 9c27278 | 2000-09-05 22:04:30 +0000 | [diff] [blame] | 3257 | clear_proxy_teximage(ctx->Texture.Proxy3D->Image[level]); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 3258 | } |
| 3259 | } |
| 3260 | else { |
| 3261 | /* if no error, update proxy texture image parameters */ |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 3262 | init_texture_image(ctx, ctx->Texture.Proxy3D->Image[level], |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 3263 | width, 1, 1, border, internalFormat); |
| 3264 | } |
| 3265 | } |
| 3266 | else { |
| 3267 | gl_error( ctx, GL_INVALID_ENUM, "glCompressedTexImage3DARB(target)" ); |
| 3268 | return; |
| 3269 | } |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 3270 | } |
| 3271 | |
| 3272 | |
| 3273 | void |
| 3274 | _mesa_CompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset, |
| 3275 | GLsizei width, GLenum format, |
| 3276 | GLsizei imageSize, const GLvoid *data) |
| 3277 | { |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 3278 | GET_CURRENT_CONTEXT(ctx); |
| 3279 | struct gl_texture_unit *texUnit; |
| 3280 | struct gl_texture_object *texObj; |
| 3281 | struct gl_texture_image *texImage; |
| 3282 | GLboolean success = GL_FALSE; |
| 3283 | |
| 3284 | if (subtexture_error_check(ctx, 1, target, level, xoffset, 0, 0, |
| 3285 | width, 1, 1, format, GL_NONE)) { |
| 3286 | return; /* error was detected */ |
| 3287 | } |
| 3288 | |
| 3289 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 3290 | texObj = _mesa_select_tex_object(ctx, texUnit, target); |
| 3291 | texImage = texObj->Image[level]; |
| 3292 | assert(texImage); |
| 3293 | |
| 3294 | if (width == 0 || !data) |
| 3295 | return; /* no-op, not an error */ |
| 3296 | |
| 3297 | if (ctx->Driver.CompressedTexSubImage1D) { |
| 3298 | success = (*ctx->Driver.CompressedTexSubImage1D)(ctx, target, level, |
| 3299 | xoffset, width, format, imageSize, data, texObj, texImage); |
| 3300 | } |
| 3301 | if (!success) { |
| 3302 | /* XXX what else can we do? */ |
| 3303 | gl_problem(ctx, "glCompressedTexSubImage1DARB failed!"); |
| 3304 | return; |
| 3305 | } |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 3306 | } |
| 3307 | |
| 3308 | |
| 3309 | void |
| 3310 | _mesa_CompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset, |
| 3311 | GLint yoffset, GLsizei width, GLsizei height, |
| 3312 | GLenum format, GLsizei imageSize, |
| 3313 | const GLvoid *data) |
| 3314 | { |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 3315 | GET_CURRENT_CONTEXT(ctx); |
| 3316 | struct gl_texture_unit *texUnit; |
| 3317 | struct gl_texture_object *texObj; |
| 3318 | struct gl_texture_image *texImage; |
| 3319 | GLboolean success = GL_FALSE; |
| 3320 | |
| 3321 | if (subtexture_error_check(ctx, 2, target, level, xoffset, yoffset, 0, |
| 3322 | width, height, 1, format, GL_NONE)) { |
| 3323 | return; /* error was detected */ |
| 3324 | } |
| 3325 | |
| 3326 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 3327 | texObj = _mesa_select_tex_object(ctx, texUnit, target); |
| 3328 | texImage = texObj->Image[level]; |
| 3329 | assert(texImage); |
| 3330 | |
| 3331 | if (width == 0 || height == 0 || !data) |
| 3332 | return; /* no-op, not an error */ |
| 3333 | |
| 3334 | if (ctx->Driver.CompressedTexSubImage2D) { |
| 3335 | success = (*ctx->Driver.CompressedTexSubImage2D)(ctx, target, level, |
| 3336 | xoffset, yoffset, width, height, format, |
| 3337 | imageSize, data, texObj, texImage); |
| 3338 | } |
| 3339 | if (!success) { |
| 3340 | /* XXX what else can we do? */ |
| 3341 | gl_problem(ctx, "glCompressedTexSubImage2DARB failed!"); |
| 3342 | return; |
| 3343 | } |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 3344 | } |
| 3345 | |
| 3346 | |
| 3347 | void |
| 3348 | _mesa_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset, |
| 3349 | GLint yoffset, GLint zoffset, GLsizei width, |
| 3350 | GLsizei height, GLsizei depth, GLenum format, |
| 3351 | GLsizei imageSize, const GLvoid *data) |
| 3352 | { |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 3353 | GET_CURRENT_CONTEXT(ctx); |
| 3354 | struct gl_texture_unit *texUnit; |
| 3355 | struct gl_texture_object *texObj; |
| 3356 | struct gl_texture_image *texImage; |
| 3357 | GLboolean success = GL_FALSE; |
| 3358 | |
| 3359 | if (subtexture_error_check(ctx, 3, target, level, xoffset, yoffset, zoffset, |
| 3360 | width, height, depth, format, GL_NONE)) { |
| 3361 | return; /* error was detected */ |
| 3362 | } |
| 3363 | |
| 3364 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 3365 | texObj = _mesa_select_tex_object(ctx, texUnit, target); |
| 3366 | texImage = texObj->Image[level]; |
| 3367 | assert(texImage); |
| 3368 | |
| 3369 | if (width == 0 || height == 0 || depth == 0 || !data) |
| 3370 | return; /* no-op, not an error */ |
| 3371 | |
| 3372 | if (ctx->Driver.CompressedTexSubImage3D) { |
| 3373 | success = (*ctx->Driver.CompressedTexSubImage3D)(ctx, target, level, |
| 3374 | xoffset, yoffset, zoffset, width, height, depth, |
| 3375 | format, imageSize, data, texObj, texImage); |
| 3376 | } |
| 3377 | if (!success) { |
| 3378 | /* XXX what else can we do? */ |
| 3379 | gl_problem(ctx, "glCompressedTexSubImage3DARB failed!"); |
| 3380 | return; |
| 3381 | } |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 3382 | } |
| 3383 | |
| 3384 | |
| 3385 | void |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 3386 | _mesa_GetCompressedTexImageARB(GLenum target, GLint level, GLvoid *img) |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 3387 | { |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 3388 | GET_CURRENT_CONTEXT(ctx); |
| 3389 | const struct gl_texture_object *texObj; |
| 3390 | struct gl_texture_image *texImage; |
| 3391 | |
| 3392 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetCompressedTexImageARB"); |
| 3393 | |
| 3394 | if (level < 0 || level >= ctx->Const.MaxTextureLevels) { |
| 3395 | gl_error( ctx, GL_INVALID_VALUE, "glGetCompressedTexImageARB(level)" ); |
| 3396 | return; |
| 3397 | } |
| 3398 | |
| 3399 | switch (target) { |
| 3400 | case GL_TEXTURE_1D: |
| 3401 | texObj = ctx->Texture.Unit[ctx->Texture.CurrentUnit].CurrentD[1]; |
| 3402 | texImage = texObj->Image[level]; |
| 3403 | break; |
| 3404 | case GL_TEXTURE_2D: |
| 3405 | texObj = ctx->Texture.Unit[ctx->Texture.CurrentUnit].CurrentD[2]; |
| 3406 | texImage = texObj->Image[level]; |
| 3407 | break; |
| 3408 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: |
| 3409 | texObj = ctx->Texture.Unit[ctx->Texture.CurrentUnit].CurrentCubeMap; |
| 3410 | texImage = texObj->Image[level]; |
| 3411 | break; |
| 3412 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: |
| 3413 | texObj = ctx->Texture.Unit[ctx->Texture.CurrentUnit].CurrentCubeMap; |
| 3414 | texImage = texObj->NegX[level]; |
| 3415 | break; |
| 3416 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: |
| 3417 | texObj = ctx->Texture.Unit[ctx->Texture.CurrentUnit].CurrentCubeMap; |
| 3418 | texImage = texObj->PosY[level]; |
| 3419 | break; |
| 3420 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: |
| 3421 | texObj = ctx->Texture.Unit[ctx->Texture.CurrentUnit].CurrentCubeMap; |
| 3422 | texImage = texObj->NegY[level]; |
| 3423 | break; |
| 3424 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: |
| 3425 | texObj = ctx->Texture.Unit[ctx->Texture.CurrentUnit].CurrentCubeMap; |
| 3426 | texImage = texObj->PosZ[level]; |
| 3427 | break; |
| 3428 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: |
| 3429 | texObj = ctx->Texture.Unit[ctx->Texture.CurrentUnit].CurrentCubeMap; |
| 3430 | texImage = texObj->NegZ[level]; |
| 3431 | break; |
| 3432 | case GL_TEXTURE_3D: |
| 3433 | texObj = ctx->Texture.Unit[ctx->Texture.CurrentUnit].CurrentD[3]; |
| 3434 | texImage = texObj->Image[level]; |
| 3435 | break; |
| 3436 | default: |
| 3437 | gl_error(ctx, GL_INVALID_ENUM, "glGetCompressedTexImageARB(target)"); |
| 3438 | return; |
| 3439 | } |
| 3440 | |
| 3441 | if (!texImage) { |
| 3442 | /* invalid mipmap level */ |
| 3443 | gl_error(ctx, GL_INVALID_VALUE, "glGetCompressedTexImageARB(level)"); |
| 3444 | return; |
| 3445 | } |
| 3446 | |
| 3447 | if (!texImage->IsCompressed) { |
| 3448 | gl_error(ctx, GL_INVALID_OPERATION, "glGetCompressedTexImageARB"); |
| 3449 | return; |
| 3450 | } |
| 3451 | |
| 3452 | if (!img) |
| 3453 | return; |
| 3454 | |
| 3455 | if (ctx->Driver.GetCompressedTexImage) { |
| 3456 | (*ctx->Driver.GetCompressedTexImage)(ctx, target, level, img, texObj, |
| 3457 | texImage); |
| 3458 | } |
| 3459 | else { |
| 3460 | gl_problem(ctx, "Driver doesn't implement GetCompressedTexImage"); |
| 3461 | } |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 3462 | } |