| Brian Paul | 1f57563 | 2001-02-26 18:24:55 +0000 | [diff] [blame^] | 1 | /* $Id: teximage.c,v 1.79 2001/02/26 18:24:55 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 |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +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. |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 8 | * |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 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: |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 15 | * |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 16 | * The above copyright notice and this permission notice shall be included |
| 17 | * in all copies or substantial portions of the Software. |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 18 | * |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 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" |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 41 | #include "mtypes.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; |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame] | 213 | case GL_DEPTH_COMPONENT: |
| 214 | case GL_DEPTH_COMPONENT16_SGIX: |
| 215 | case GL_DEPTH_COMPONENT24_SGIX: |
| 216 | case GL_DEPTH_COMPONENT32_SGIX: |
| 217 | if (ctx->Extensions.SGIX_depth_texture) |
| 218 | return GL_DEPTH_COMPONENT; |
| 219 | else |
| 220 | return -1; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 221 | default: |
| 222 | return -1; /* error */ |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame] | 227 | /* |
| 228 | * Test if the given image format is a color/rgba format. That is, |
| 229 | * not color index, depth, stencil, etc. |
| 230 | */ |
| 231 | static GLboolean |
| 232 | is_color_format(GLenum format) |
| 233 | { |
| 234 | switch (format) { |
| 235 | case GL_ALPHA: |
| 236 | case GL_ALPHA4: |
| 237 | case GL_ALPHA8: |
| 238 | case GL_ALPHA12: |
| 239 | case GL_ALPHA16: |
| 240 | case 1: |
| 241 | case GL_LUMINANCE: |
| 242 | case GL_LUMINANCE4: |
| 243 | case GL_LUMINANCE8: |
| 244 | case GL_LUMINANCE12: |
| 245 | case GL_LUMINANCE16: |
| 246 | case 2: |
| 247 | case GL_LUMINANCE_ALPHA: |
| 248 | case GL_LUMINANCE4_ALPHA4: |
| 249 | case GL_LUMINANCE6_ALPHA2: |
| 250 | case GL_LUMINANCE8_ALPHA8: |
| 251 | case GL_LUMINANCE12_ALPHA4: |
| 252 | case GL_LUMINANCE12_ALPHA12: |
| 253 | case GL_LUMINANCE16_ALPHA16: |
| 254 | case GL_INTENSITY: |
| 255 | case GL_INTENSITY4: |
| 256 | case GL_INTENSITY8: |
| 257 | case GL_INTENSITY12: |
| 258 | case GL_INTENSITY16: |
| 259 | case 3: |
| 260 | case GL_RGB: |
| 261 | case GL_R3_G3_B2: |
| 262 | case GL_RGB4: |
| 263 | case GL_RGB5: |
| 264 | case GL_RGB8: |
| 265 | case GL_RGB10: |
| 266 | case GL_RGB12: |
| 267 | case GL_RGB16: |
| 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 GL_TRUE; |
| 278 | default: |
| 279 | return GL_FALSE; |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | |
| 284 | static GLboolean |
| 285 | is_index_format(GLenum format) |
| 286 | { |
| 287 | switch (format) { |
| 288 | case GL_COLOR_INDEX: |
| 289 | case GL_COLOR_INDEX1_EXT: |
| 290 | case GL_COLOR_INDEX2_EXT: |
| 291 | case GL_COLOR_INDEX4_EXT: |
| 292 | case GL_COLOR_INDEX8_EXT: |
| 293 | case GL_COLOR_INDEX12_EXT: |
| 294 | case GL_COLOR_INDEX16_EXT: |
| 295 | return GL_TRUE; |
| 296 | default: |
| 297 | return GL_FALSE; |
| 298 | } |
| 299 | } |
| 300 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 301 | |
| 302 | /* |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 303 | * Return GL_TRUE if internalFormat is a compressed format, return GL_FALSE |
| 304 | * otherwise. |
| 305 | */ |
| 306 | static GLboolean |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 307 | is_compressed_format(GLcontext *ctx, GLenum internalFormat) |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 308 | { |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 309 | if (ctx->Driver.IsCompressedFormat) { |
| 310 | return (*ctx->Driver.IsCompressedFormat)(ctx, internalFormat); |
| 311 | } |
| 312 | return GL_FALSE; |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 316 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 317 | /* |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 318 | * Store a gl_texture_image pointer in a gl_texture_object structure |
| 319 | * according to the target and level parameters. |
| 320 | * This was basically prompted by the introduction of cube maps. |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 321 | */ |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 322 | static void |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 323 | set_tex_image(struct gl_texture_object *tObj, |
| 324 | GLenum target, GLint level, |
| 325 | struct gl_texture_image *texImage) |
| 326 | { |
| 327 | ASSERT(tObj); |
| 328 | ASSERT(texImage); |
| 329 | switch (target) { |
| 330 | case GL_TEXTURE_2D: |
| 331 | tObj->Image[level] = texImage; |
| 332 | return; |
| 333 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: |
| Brian Paul | 413d6a2 | 2000-05-26 14:44:59 +0000 | [diff] [blame] | 334 | tObj->Image[level] = texImage; |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 335 | return; |
| 336 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: |
| 337 | tObj->NegX[level] = texImage; |
| 338 | return; |
| 339 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: |
| 340 | tObj->PosY[level] = texImage; |
| 341 | return; |
| 342 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: |
| 343 | tObj->NegY[level] = texImage; |
| 344 | return; |
| 345 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: |
| 346 | tObj->PosZ[level] = texImage; |
| 347 | return; |
| 348 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: |
| 349 | tObj->NegZ[level] = texImage; |
| 350 | return; |
| 351 | default: |
| 352 | gl_problem(NULL, "bad target in set_tex_image()"); |
| 353 | return; |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 358 | |
| Brian Paul | 77ce6da | 2000-03-20 23:40:12 +0000 | [diff] [blame] | 359 | /* |
| 360 | * Return new gl_texture_image struct with all fields initialized to zero. |
| 361 | */ |
| 362 | struct gl_texture_image * |
| Brian Paul | 021a525 | 2000-03-27 17:54:17 +0000 | [diff] [blame] | 363 | _mesa_alloc_texture_image( void ) |
| Brian Paul | 77ce6da | 2000-03-20 23:40:12 +0000 | [diff] [blame] | 364 | { |
| 365 | return CALLOC_STRUCT(gl_texture_image); |
| 366 | } |
| 367 | |
| 368 | |
| 369 | |
| Brian Paul | 77ce6da | 2000-03-20 23:40:12 +0000 | [diff] [blame] | 370 | void |
| Brian Paul | 021a525 | 2000-03-27 17:54:17 +0000 | [diff] [blame] | 371 | _mesa_free_texture_image( struct gl_texture_image *teximage ) |
| Brian Paul | 77ce6da | 2000-03-20 23:40:12 +0000 | [diff] [blame] | 372 | { |
| 373 | if (teximage->Data) { |
| 374 | FREE( teximage->Data ); |
| 375 | teximage->Data = NULL; |
| 376 | } |
| 377 | FREE( teximage ); |
| 378 | } |
| 379 | |
| 380 | |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 381 | /* |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 382 | * Return GL_TRUE if the target is a proxy target. |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 383 | */ |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 384 | static GLboolean |
| 385 | is_proxy_target(GLenum target) |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 386 | { |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 387 | return (target == GL_PROXY_TEXTURE_1D || |
| 388 | target == GL_PROXY_TEXTURE_2D || |
| 389 | target == GL_PROXY_TEXTURE_3D || |
| 390 | target == GL_PROXY_TEXTURE_CUBE_MAP_ARB); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 394 | /* |
| Brian Paul | 35d5301 | 2000-05-23 17:14:49 +0000 | [diff] [blame] | 395 | * Given a texture unit and a texture target, return the corresponding |
| 396 | * texture object. |
| 397 | */ |
| 398 | struct gl_texture_object * |
| Brian Paul | 01e5475 | 2000-09-05 15:40:34 +0000 | [diff] [blame] | 399 | _mesa_select_tex_object(GLcontext *ctx, const struct gl_texture_unit *texUnit, |
| Brian Paul | 35d5301 | 2000-05-23 17:14:49 +0000 | [diff] [blame] | 400 | GLenum target) |
| 401 | { |
| 402 | switch (target) { |
| 403 | case GL_TEXTURE_1D: |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 404 | return texUnit->Current1D; |
| Brian Paul | 35d5301 | 2000-05-23 17:14:49 +0000 | [diff] [blame] | 405 | case GL_PROXY_TEXTURE_1D: |
| 406 | return ctx->Texture.Proxy1D; |
| 407 | case GL_TEXTURE_2D: |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 408 | return texUnit->Current2D; |
| Brian Paul | 35d5301 | 2000-05-23 17:14:49 +0000 | [diff] [blame] | 409 | case GL_PROXY_TEXTURE_2D: |
| 410 | return ctx->Texture.Proxy2D; |
| 411 | case GL_TEXTURE_3D: |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 412 | return texUnit->Current3D; |
| Brian Paul | 35d5301 | 2000-05-23 17:14:49 +0000 | [diff] [blame] | 413 | case GL_PROXY_TEXTURE_3D: |
| 414 | return ctx->Texture.Proxy3D; |
| 415 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: |
| 416 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: |
| 417 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: |
| 418 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: |
| 419 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: |
| 420 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 421 | return ctx->Extensions.ARB_texture_cube_map |
| Brian Paul | 35d5301 | 2000-05-23 17:14:49 +0000 | [diff] [blame] | 422 | ? texUnit->CurrentCubeMap : NULL; |
| 423 | case GL_PROXY_TEXTURE_CUBE_MAP_ARB: |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 424 | return ctx->Extensions.ARB_texture_cube_map |
| Brian Paul | 35d5301 | 2000-05-23 17:14:49 +0000 | [diff] [blame] | 425 | ? ctx->Texture.ProxyCubeMap : NULL; |
| 426 | default: |
| 427 | gl_problem(NULL, "bad target in _mesa_select_tex_object()"); |
| 428 | return NULL; |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | |
| 433 | /* |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 434 | * Return the texture image struct which corresponds to target and level |
| 435 | * for the given texture unit. |
| 436 | */ |
| 437 | struct gl_texture_image * |
| 438 | _mesa_select_tex_image(GLcontext *ctx, const struct gl_texture_unit *texUnit, |
| 439 | GLenum target, GLint level) |
| 440 | { |
| 441 | ASSERT(texUnit); |
| 442 | switch (target) { |
| 443 | case GL_TEXTURE_1D: |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 444 | return texUnit->Current1D->Image[level]; |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 445 | case GL_PROXY_TEXTURE_1D: |
| 446 | return ctx->Texture.Proxy1D->Image[level]; |
| 447 | case GL_TEXTURE_2D: |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 448 | return texUnit->Current2D->Image[level]; |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 449 | case GL_PROXY_TEXTURE_2D: |
| 450 | return ctx->Texture.Proxy2D->Image[level]; |
| 451 | case GL_TEXTURE_3D: |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 452 | return texUnit->Current3D->Image[level]; |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 453 | case GL_PROXY_TEXTURE_3D: |
| 454 | return ctx->Texture.Proxy3D->Image[level]; |
| 455 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 456 | if (ctx->Extensions.ARB_texture_cube_map) |
| Brian Paul | 413d6a2 | 2000-05-26 14:44:59 +0000 | [diff] [blame] | 457 | return texUnit->CurrentCubeMap->Image[level]; |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 458 | else |
| 459 | return NULL; |
| 460 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 461 | if (ctx->Extensions.ARB_texture_cube_map) |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 462 | return texUnit->CurrentCubeMap->NegX[level]; |
| 463 | else |
| 464 | return NULL; |
| 465 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 466 | if (ctx->Extensions.ARB_texture_cube_map) |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 467 | return texUnit->CurrentCubeMap->PosY[level]; |
| 468 | else |
| 469 | return NULL; |
| 470 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 471 | if (ctx->Extensions.ARB_texture_cube_map) |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 472 | return texUnit->CurrentCubeMap->NegY[level]; |
| 473 | else |
| 474 | return NULL; |
| 475 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 476 | if (ctx->Extensions.ARB_texture_cube_map) |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 477 | return texUnit->CurrentCubeMap->PosZ[level]; |
| 478 | else |
| 479 | return NULL; |
| 480 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 481 | if (ctx->Extensions.ARB_texture_cube_map) |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 482 | return texUnit->CurrentCubeMap->NegZ[level]; |
| 483 | else |
| 484 | return NULL; |
| 485 | case GL_PROXY_TEXTURE_CUBE_MAP_ARB: |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 486 | if (ctx->Extensions.ARB_texture_cube_map) |
| Brian Paul | 413d6a2 | 2000-05-26 14:44:59 +0000 | [diff] [blame] | 487 | return ctx->Texture.ProxyCubeMap->Image[level]; |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 488 | else |
| 489 | return NULL; |
| 490 | default: |
| 491 | gl_problem(ctx, "bad target in _mesa_select_tex_image()"); |
| 492 | return NULL; |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | |
| 497 | |
| Brian Paul | f93b3dd | 2000-08-30 18:22:28 +0000 | [diff] [blame] | 498 | /* |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 499 | * glTexImage[123]D can accept a NULL image pointer. In this case we |
| 500 | * create a texture image with unspecified image contents per the OpenGL |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 501 | * spec. |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 502 | */ |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 503 | static GLubyte * |
| 504 | make_null_texture(GLint width, GLint height, GLint depth, GLenum format) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 505 | { |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 506 | const GLint components = _mesa_components_in_format(format); |
| 507 | const GLint numPixels = width * height * depth; |
| 508 | GLubyte *data = (GLubyte *) MALLOC(numPixels * components * sizeof(GLubyte)); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 509 | |
| 510 | /* |
| 511 | * Let's see if anyone finds this. If glTexImage2D() is called with |
| 512 | * a NULL image pointer then load the texture image with something |
| 513 | * interesting instead of leaving it indeterminate. |
| 514 | */ |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 515 | if (data) { |
| Brian Paul | 65d5460 | 2000-03-01 23:28:20 +0000 | [diff] [blame] | 516 | static const char message[8][32] = { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 517 | " X X XXXXX XXX X ", |
| 518 | " XX XX X X X X X ", |
| 519 | " X X X X X X X ", |
| 520 | " X X XXXX XXX XXXXX ", |
| 521 | " X X X X X X ", |
| 522 | " X X X X X X X ", |
| 523 | " X X XXXXX XXX X X ", |
| 524 | " " |
| 525 | }; |
| 526 | |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 527 | GLubyte *imgPtr = data; |
| 528 | GLint h, i, j, k; |
| 529 | for (h = 0; h < depth; h++) { |
| 530 | for (i = 0; i < height; i++) { |
| 531 | GLint srcRow = 7 - (i % 8); |
| 532 | for (j = 0; j < width; j++) { |
| 533 | GLint srcCol = j % 32; |
| 534 | GLubyte texel = (message[srcRow][srcCol]=='X') ? 255 : 70; |
| 535 | for (k = 0; k < components; k++) { |
| 536 | *imgPtr++ = texel; |
| 537 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 538 | } |
| 539 | } |
| 540 | } |
| 541 | } |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 542 | |
| 543 | return data; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | |
| 547 | |
| 548 | /* |
| Brian Paul | f378ab8 | 2001-02-06 23:35:26 +0000 | [diff] [blame] | 549 | * Reset the fields of a gl_texture_image struct to zero. |
| Brian Paul | 9c27278 | 2000-09-05 22:04:30 +0000 | [diff] [blame] | 550 | * This is called when a proxy texture test fails, we set all the |
| 551 | * image members (except DriverData) to zero. |
| Brian Paul | f378ab8 | 2001-02-06 23:35:26 +0000 | [diff] [blame] | 552 | * It's also used in glTexImage[123]D as a safeguard to be sure all |
| 553 | * required fields get initialized properly by the Driver.TexImage[123]D |
| 554 | * functions. |
| Brian Paul | 9c27278 | 2000-09-05 22:04:30 +0000 | [diff] [blame] | 555 | */ |
| 556 | static void |
| Brian Paul | f378ab8 | 2001-02-06 23:35:26 +0000 | [diff] [blame] | 557 | clear_teximage_fields(struct gl_texture_image *img) |
| Brian Paul | 9c27278 | 2000-09-05 22:04:30 +0000 | [diff] [blame] | 558 | { |
| 559 | ASSERT(img); |
| 560 | img->Format = 0; |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame] | 561 | img->Type = 0; |
| Brian Paul | 9c27278 | 2000-09-05 22:04:30 +0000 | [diff] [blame] | 562 | img->IntFormat = 0; |
| 563 | img->RedBits = 0; |
| 564 | img->GreenBits = 0; |
| 565 | img->BlueBits = 0; |
| 566 | img->AlphaBits = 0; |
| 567 | img->IntensityBits = 0; |
| 568 | img->LuminanceBits = 0; |
| 569 | img->IndexBits = 0; |
| 570 | img->Border = 0; |
| 571 | img->Width = 0; |
| 572 | img->Height = 0; |
| 573 | img->Depth = 0; |
| 574 | img->Width2 = 0; |
| 575 | img->Height2 = 0; |
| 576 | img->Depth2 = 0; |
| 577 | img->WidthLog2 = 0; |
| 578 | img->HeightLog2 = 0; |
| 579 | img->DepthLog2 = 0; |
| 580 | img->Data = NULL; |
| 581 | img->IsCompressed = 0; |
| 582 | img->CompressedSize = 0; |
| Brian Paul | f378ab8 | 2001-02-06 23:35:26 +0000 | [diff] [blame] | 583 | img->FetchTexel = NULL; |
| Brian Paul | 9c27278 | 2000-09-05 22:04:30 +0000 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | |
| Brian Paul | 6628bc9 | 2001-02-07 03:27:41 +0000 | [diff] [blame] | 587 | /* |
| 588 | * Initialize basic fields of the gl_texture_image struct. |
| 589 | */ |
| 590 | static void |
| 591 | init_teximage_fields(GLcontext *ctx, |
| 592 | struct gl_texture_image *img, |
| 593 | GLsizei width, GLsizei height, GLsizei depth, |
| 594 | GLint border, GLenum internalFormat) |
| 595 | { |
| 596 | ASSERT(img); |
| 597 | |
| 598 | img->IntFormat = internalFormat; |
| 599 | img->Border = border; |
| 600 | img->Width = width; |
| 601 | img->Height = height; |
| 602 | img->Depth = depth; |
| 603 | img->WidthLog2 = logbase2(width - 2 * border); |
| 604 | if (height == 1) /* 1-D texture */ |
| 605 | img->HeightLog2 = 0; |
| 606 | else |
| 607 | img->HeightLog2 = logbase2(height - 2 * border); |
| 608 | if (depth == 1) /* 2-D texture */ |
| 609 | img->DepthLog2 = 0; |
| 610 | else |
| 611 | img->DepthLog2 = logbase2(depth - 2 * border); |
| 612 | img->Width2 = 1 << img->WidthLog2; |
| 613 | img->Height2 = 1 << img->HeightLog2; |
| 614 | img->Depth2 = 1 << img->DepthLog2; |
| 615 | img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2); |
| 616 | img->IsCompressed = is_compressed_format(ctx, internalFormat); |
| 617 | } |
| 618 | |
| 619 | |
| Brian Paul | 9c27278 | 2000-09-05 22:04:30 +0000 | [diff] [blame] | 620 | |
| 621 | /* |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 622 | * Test glTexImage[123]D() parameters for errors. |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 623 | * Input: |
| 624 | * dimensions - must be 1 or 2 or 3 |
| 625 | * Return: GL_TRUE = an error was detected, GL_FALSE = no errors |
| 626 | */ |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 627 | static GLboolean |
| 628 | texture_error_check( GLcontext *ctx, GLenum target, |
| 629 | GLint level, GLint internalFormat, |
| 630 | GLenum format, GLenum type, |
| Brian Paul | 5b37c32 | 1999-11-05 06:43:10 +0000 | [diff] [blame] | 631 | GLuint dimensions, |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 632 | GLint width, GLint height, |
| 633 | GLint depth, GLint border ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 634 | { |
| 635 | GLboolean isProxy; |
| 636 | GLint iformat; |
| 637 | |
| 638 | if (dimensions == 1) { |
| Brian Paul | 5b37c32 | 1999-11-05 06:43:10 +0000 | [diff] [blame] | 639 | isProxy = (GLboolean) (target == GL_PROXY_TEXTURE_1D); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 640 | if (target != GL_TEXTURE_1D && !isProxy) { |
| 641 | gl_error( ctx, GL_INVALID_ENUM, "glTexImage1D(target)" ); |
| 642 | return GL_TRUE; |
| 643 | } |
| 644 | } |
| 645 | else if (dimensions == 2) { |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 646 | isProxy = (GLboolean) (target == GL_PROXY_TEXTURE_2D || |
| 647 | target == GL_PROXY_TEXTURE_CUBE_MAP_ARB); |
| Brian Paul | 413d6a2 | 2000-05-26 14:44:59 +0000 | [diff] [blame] | 648 | if (target != GL_TEXTURE_2D && !isProxy && |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 649 | !(ctx->Extensions.ARB_texture_cube_map && |
| Brian Paul | 413d6a2 | 2000-05-26 14:44:59 +0000 | [diff] [blame] | 650 | target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && |
| 651 | target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 652 | gl_error( ctx, GL_INVALID_ENUM, "glTexImage2D(target)" ); |
| 653 | return GL_TRUE; |
| 654 | } |
| 655 | } |
| 656 | else if (dimensions == 3) { |
| Brian Paul | 5b37c32 | 1999-11-05 06:43:10 +0000 | [diff] [blame] | 657 | isProxy = (GLboolean) (target == GL_PROXY_TEXTURE_3D); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 658 | if (target != GL_TEXTURE_3D && !isProxy) { |
| 659 | gl_error( ctx, GL_INVALID_ENUM, "glTexImage3D(target)" ); |
| 660 | return GL_TRUE; |
| 661 | } |
| 662 | } |
| 663 | else { |
| 664 | gl_problem( ctx, "bad dims in texture_error_check" ); |
| 665 | return GL_TRUE; |
| 666 | } |
| 667 | |
| 668 | /* Border */ |
| Brian Paul | 9fd2b0a | 2000-03-24 23:59:06 +0000 | [diff] [blame] | 669 | if (border != 0 && border != 1) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 670 | if (!isProxy) { |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 671 | char message[100]; |
| Brian Paul | ec15398 | 2000-12-08 18:09:33 +0000 | [diff] [blame] | 672 | sprintf(message, "glTexImage%dD(border=%d)", dimensions, border); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 673 | gl_error(ctx, GL_INVALID_VALUE, message); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 674 | } |
| 675 | return GL_TRUE; |
| 676 | } |
| 677 | |
| 678 | /* Width */ |
| 679 | if (width < 2 * border || width > 2 + ctx->Const.MaxTextureSize |
| 680 | || logbase2( width - 2 * border ) < 0) { |
| 681 | if (!isProxy) { |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 682 | char message[100]; |
| Brian Paul | ec15398 | 2000-12-08 18:09:33 +0000 | [diff] [blame] | 683 | sprintf(message, "glTexImage%dD(width=%d)", dimensions, width); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 684 | gl_error(ctx, GL_INVALID_VALUE, message); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 685 | } |
| 686 | return GL_TRUE; |
| 687 | } |
| 688 | |
| 689 | /* Height */ |
| 690 | if (dimensions >= 2) { |
| 691 | if (height < 2 * border || height > 2 + ctx->Const.MaxTextureSize |
| 692 | || logbase2( height - 2 * border ) < 0) { |
| 693 | if (!isProxy) { |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 694 | char message[100]; |
| Brian Paul | ec15398 | 2000-12-08 18:09:33 +0000 | [diff] [blame] | 695 | sprintf(message, "glTexImage%dD(height=%d)", dimensions, height); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 696 | gl_error(ctx, GL_INVALID_VALUE, message); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 697 | } |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 698 | return GL_TRUE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 699 | } |
| 700 | } |
| 701 | |
| Brian Paul | ad81770 | 2000-05-30 00:27:24 +0000 | [diff] [blame] | 702 | /* For cube map, width must equal height */ |
| 703 | if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && |
| 704 | target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { |
| 705 | if (width != height) { |
| 706 | if (!isProxy) { |
| 707 | gl_error(ctx, GL_INVALID_VALUE, "glTexImage2D(width != height)"); |
| 708 | } |
| 709 | return GL_TRUE; |
| 710 | } |
| 711 | } |
| 712 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 713 | /* Depth */ |
| 714 | if (dimensions >= 3) { |
| 715 | if (depth < 2 * border || depth > 2 + ctx->Const.MaxTextureSize |
| 716 | || logbase2( depth - 2 * border ) < 0) { |
| 717 | if (!isProxy) { |
| Brian Paul | ec15398 | 2000-12-08 18:09:33 +0000 | [diff] [blame] | 718 | char message[100]; |
| 719 | sprintf(message, "glTexImage3D(depth=%d)", depth ); |
| 720 | gl_error( ctx, GL_INVALID_VALUE, message ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 721 | } |
| 722 | return GL_TRUE; |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | /* Level */ |
| Brian Paul | 9fd2b0a | 2000-03-24 23:59:06 +0000 | [diff] [blame] | 727 | if (level < 0 || level >= ctx->Const.MaxTextureLevels) { |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 728 | if (!isProxy) { |
| 729 | char message[100]; |
| Brian Paul | ec15398 | 2000-12-08 18:09:33 +0000 | [diff] [blame] | 730 | sprintf(message, "glTexImage%dD(level=%d)", dimensions, level); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 731 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 732 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 733 | return GL_TRUE; |
| 734 | } |
| 735 | |
| Brian Paul | 1f57563 | 2001-02-26 18:24:55 +0000 | [diff] [blame^] | 736 | /* For cube map, width must equal height */ |
| 737 | if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && |
| 738 | target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { |
| 739 | if (width != height) { |
| 740 | gl_error(ctx, GL_INVALID_VALUE, "glTexImage2D(width != height)"); |
| 741 | return GL_TRUE; |
| 742 | } |
| 743 | } |
| 744 | |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 745 | iformat = _mesa_base_tex_format( ctx, internalFormat ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 746 | if (iformat < 0) { |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 747 | if (!isProxy) { |
| 748 | char message[100]; |
| Brian Paul | ec15398 | 2000-12-08 18:09:33 +0000 | [diff] [blame] | 749 | sprintf(message, "glTexImage%dD(internalFormat=0x%x)", dimensions, |
| 750 | internalFormat); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 751 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 752 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 753 | return GL_TRUE; |
| 754 | } |
| 755 | |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 756 | if (!is_compressed_format(ctx, internalFormat)) { |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 757 | if (!_mesa_is_legal_format_and_type( format, type )) { |
| 758 | /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there |
| 759 | * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4. |
| 760 | */ |
| 761 | if (!isProxy) { |
| 762 | char message[100]; |
| 763 | sprintf(message, "glTexImage%dD(format or type)", dimensions); |
| 764 | gl_error(ctx, GL_INVALID_OPERATION, message); |
| 765 | } |
| 766 | return GL_TRUE; |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 767 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | /* if we get here, the parameters are OK */ |
| 771 | return GL_FALSE; |
| 772 | } |
| 773 | |
| 774 | |
| 775 | |
| 776 | /* |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 777 | * Test glTexSubImage[123]D() parameters for errors. |
| 778 | * Input: |
| 779 | * dimensions - must be 1 or 2 or 3 |
| 780 | * Return: GL_TRUE = an error was detected, GL_FALSE = no errors |
| 781 | */ |
| 782 | static GLboolean |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 783 | subtexture_error_check( GLcontext *ctx, GLuint dimensions, |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 784 | GLenum target, GLint level, |
| 785 | GLint xoffset, GLint yoffset, GLint zoffset, |
| 786 | GLint width, GLint height, GLint depth, |
| 787 | GLenum format, GLenum type ) |
| 788 | { |
| 789 | struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 790 | struct gl_texture_image *destTex; |
| 791 | |
| 792 | if (dimensions == 1) { |
| 793 | if (target != GL_TEXTURE_1D) { |
| 794 | gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage1D(target)" ); |
| 795 | return GL_TRUE; |
| 796 | } |
| 797 | } |
| 798 | else if (dimensions == 2) { |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 799 | if (ctx->Extensions.ARB_texture_cube_map) { |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 800 | if ((target < GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB || |
| 801 | target > GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) && |
| 802 | target != GL_TEXTURE_2D) { |
| 803 | gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" ); |
| 804 | return GL_TRUE; |
| 805 | } |
| 806 | } |
| 807 | else if (target != GL_TEXTURE_2D) { |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 808 | gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" ); |
| 809 | return GL_TRUE; |
| 810 | } |
| 811 | } |
| 812 | else if (dimensions == 3) { |
| 813 | if (target != GL_TEXTURE_3D) { |
| 814 | gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage3D(target)" ); |
| 815 | return GL_TRUE; |
| 816 | } |
| 817 | } |
| 818 | else { |
| 819 | gl_problem( ctx, "bad dims in texture_error_check" ); |
| 820 | return GL_TRUE; |
| 821 | } |
| 822 | |
| 823 | if (level < 0 || level >= ctx->Const.MaxTextureLevels) { |
| Brian Paul | ec15398 | 2000-12-08 18:09:33 +0000 | [diff] [blame] | 824 | char message[100]; |
| 825 | sprintf(message, "glTexSubImage2D(level=%d)", level); |
| 826 | gl_error(ctx, GL_INVALID_ENUM, message); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 827 | return GL_TRUE; |
| 828 | } |
| 829 | |
| 830 | if (width < 0) { |
| 831 | char message[100]; |
| Brian Paul | ec15398 | 2000-12-08 18:09:33 +0000 | [diff] [blame] | 832 | sprintf(message, "glTexSubImage%dD(width=%d)", dimensions, width); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 833 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 834 | return GL_TRUE; |
| 835 | } |
| 836 | if (height < 0 && dimensions > 1) { |
| 837 | char message[100]; |
| Brian Paul | ec15398 | 2000-12-08 18:09:33 +0000 | [diff] [blame] | 838 | sprintf(message, "glTexSubImage%dD(height=%d)", dimensions, height); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 839 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 840 | return GL_TRUE; |
| 841 | } |
| 842 | if (depth < 0 && dimensions > 2) { |
| 843 | char message[100]; |
| Brian Paul | ec15398 | 2000-12-08 18:09:33 +0000 | [diff] [blame] | 844 | sprintf(message, "glTexSubImage%dD(depth=%d)", dimensions, depth); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 845 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 846 | return GL_TRUE; |
| 847 | } |
| 848 | |
| Brian Paul | f2718b0 | 2001-01-23 23:35:23 +0000 | [diff] [blame] | 849 | destTex = _mesa_select_tex_image(ctx, texUnit, target, level); |
| 850 | |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 851 | if (!destTex) { |
| 852 | gl_error(ctx, GL_INVALID_OPERATION, "glTexSubImage2D"); |
| 853 | return GL_TRUE; |
| 854 | } |
| 855 | |
| 856 | if (xoffset < -((GLint)destTex->Border)) { |
| 857 | gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage1/2/3D(xoffset)"); |
| 858 | return GL_TRUE; |
| 859 | } |
| 860 | if (xoffset + width > (GLint) (destTex->Width + destTex->Border)) { |
| 861 | gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage1/2/3D(xoffset+width)"); |
| 862 | return GL_TRUE; |
| 863 | } |
| 864 | if (dimensions > 1) { |
| 865 | if (yoffset < -((GLint)destTex->Border)) { |
| 866 | gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage2/3D(yoffset)"); |
| 867 | return GL_TRUE; |
| 868 | } |
| 869 | if (yoffset + height > (GLint) (destTex->Height + destTex->Border)) { |
| 870 | gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage2/3D(yoffset+height)"); |
| 871 | return GL_TRUE; |
| 872 | } |
| 873 | } |
| 874 | if (dimensions > 2) { |
| 875 | if (zoffset < -((GLint)destTex->Border)) { |
| 876 | gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset)"); |
| 877 | return GL_TRUE; |
| 878 | } |
| 879 | if (zoffset + depth > (GLint) (destTex->Depth+destTex->Border)) { |
| 880 | gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset+depth)"); |
| 881 | return GL_TRUE; |
| 882 | } |
| 883 | } |
| 884 | |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 885 | if (!is_compressed_format(ctx, destTex->IntFormat)) { |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 886 | if (!_mesa_is_legal_format_and_type(format, type)) { |
| 887 | char message[100]; |
| 888 | sprintf(message, "glTexSubImage%dD(format or type)", dimensions); |
| 889 | gl_error(ctx, GL_INVALID_ENUM, message); |
| 890 | return GL_TRUE; |
| 891 | } |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | return GL_FALSE; |
| 895 | } |
| 896 | |
| 897 | |
| 898 | /* |
| 899 | * Test glCopyTexImage[12]D() parameters for errors. |
| 900 | * Input: dimensions - must be 1 or 2 or 3 |
| 901 | * Return: GL_TRUE = an error was detected, GL_FALSE = no errors |
| 902 | */ |
| 903 | static GLboolean |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 904 | copytexture_error_check( GLcontext *ctx, GLuint dimensions, |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 905 | GLenum target, GLint level, GLint internalFormat, |
| 906 | GLint width, GLint height, GLint border ) |
| 907 | { |
| 908 | GLint iformat; |
| 909 | |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 910 | if (dimensions == 1) { |
| 911 | if (target != GL_TEXTURE_1D) { |
| 912 | gl_error( ctx, GL_INVALID_ENUM, "glCopyTexImage1D(target)" ); |
| 913 | return GL_TRUE; |
| 914 | } |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 915 | } |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 916 | else if (dimensions == 2) { |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 917 | if (ctx->Extensions.ARB_texture_cube_map) { |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 918 | if ((target < GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB || |
| 919 | target > GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) && |
| 920 | target != GL_TEXTURE_2D) { |
| 921 | gl_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" ); |
| 922 | return GL_TRUE; |
| 923 | } |
| 924 | } |
| 925 | else if (target != GL_TEXTURE_2D) { |
| 926 | gl_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" ); |
| 927 | return GL_TRUE; |
| 928 | } |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | /* Border */ |
| 932 | if (border!=0 && border!=1) { |
| 933 | char message[100]; |
| 934 | sprintf(message, "glCopyTexImage%dD(border)", dimensions); |
| 935 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 936 | return GL_TRUE; |
| 937 | } |
| 938 | |
| 939 | /* Width */ |
| 940 | if (width < 2 * border || width > 2 + ctx->Const.MaxTextureSize |
| 941 | || logbase2( width - 2 * border ) < 0) { |
| 942 | char message[100]; |
| Brian Paul | ec15398 | 2000-12-08 18:09:33 +0000 | [diff] [blame] | 943 | sprintf(message, "glCopyTexImage%dD(width=%d)", dimensions, width); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 944 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 945 | return GL_TRUE; |
| 946 | } |
| 947 | |
| 948 | /* Height */ |
| 949 | if (dimensions >= 2) { |
| 950 | if (height < 2 * border || height > 2 + ctx->Const.MaxTextureSize |
| 951 | || logbase2( height - 2 * border ) < 0) { |
| 952 | char message[100]; |
| Brian Paul | ec15398 | 2000-12-08 18:09:33 +0000 | [diff] [blame] | 953 | sprintf(message, "glCopyTexImage%dD(height=%d)", dimensions, height); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 954 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 955 | return GL_TRUE; |
| 956 | } |
| 957 | } |
| 958 | |
| Brian Paul | ad81770 | 2000-05-30 00:27:24 +0000 | [diff] [blame] | 959 | /* For cube map, width must equal height */ |
| 960 | if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && |
| 961 | target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { |
| 962 | if (width != height) { |
| 963 | gl_error(ctx, GL_INVALID_VALUE, "glCopyTexImage2D(width != height)"); |
| 964 | return GL_TRUE; |
| 965 | } |
| 966 | } |
| 967 | |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 968 | /* Level */ |
| 969 | if (level<0 || level>=ctx->Const.MaxTextureLevels) { |
| 970 | char message[100]; |
| Brian Paul | ec15398 | 2000-12-08 18:09:33 +0000 | [diff] [blame] | 971 | sprintf(message, "glCopyTexImage%dD(level=%d)", dimensions, level); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 972 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 973 | return GL_TRUE; |
| 974 | } |
| 975 | |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 976 | iformat = _mesa_base_tex_format( ctx, internalFormat ); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 977 | if (iformat < 0) { |
| 978 | char message[100]; |
| 979 | sprintf(message, "glCopyTexImage%dD(internalFormat)", dimensions); |
| 980 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 981 | return GL_TRUE; |
| 982 | } |
| 983 | |
| 984 | /* if we get here, the parameters are OK */ |
| 985 | return GL_FALSE; |
| 986 | } |
| 987 | |
| 988 | |
| 989 | static GLboolean |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 990 | copytexsubimage_error_check( GLcontext *ctx, GLuint dimensions, |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 991 | GLenum target, GLint level, |
| 992 | GLint xoffset, GLint yoffset, GLint zoffset, |
| Brian Paul | 5b37c32 | 1999-11-05 06:43:10 +0000 | [diff] [blame] | 993 | GLsizei width, GLsizei height ) |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 994 | { |
| 995 | struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 996 | struct gl_texture_image *teximage; |
| 997 | |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 998 | if (dimensions == 1) { |
| 999 | if (target != GL_TEXTURE_1D) { |
| 1000 | gl_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage1D(target)" ); |
| 1001 | return GL_TRUE; |
| 1002 | } |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1003 | } |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 1004 | else if (dimensions == 2) { |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 1005 | if (ctx->Extensions.ARB_texture_cube_map) { |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 1006 | if ((target < GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB || |
| 1007 | target > GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) && |
| 1008 | target != GL_TEXTURE_2D) { |
| 1009 | gl_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" ); |
| 1010 | return GL_TRUE; |
| 1011 | } |
| 1012 | } |
| 1013 | else if (target != GL_TEXTURE_2D) { |
| 1014 | gl_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" ); |
| 1015 | return GL_TRUE; |
| 1016 | } |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1017 | } |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 1018 | else if (dimensions == 3) { |
| 1019 | if (target != GL_TEXTURE_3D) { |
| 1020 | gl_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage3D(target)" ); |
| 1021 | return GL_TRUE; |
| 1022 | } |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1023 | } |
| 1024 | |
| 1025 | if (level < 0 || level >= ctx->Const.MaxTextureLevels) { |
| 1026 | char message[100]; |
| Brian Paul | ec15398 | 2000-12-08 18:09:33 +0000 | [diff] [blame] | 1027 | sprintf(message, "glCopyTexSubImage%dD(level=%d)", dimensions, level); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1028 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1029 | return GL_TRUE; |
| 1030 | } |
| 1031 | |
| 1032 | if (width < 0) { |
| 1033 | char message[100]; |
| Brian Paul | ec15398 | 2000-12-08 18:09:33 +0000 | [diff] [blame] | 1034 | sprintf(message, "glCopyTexSubImage%dD(width=%d)", dimensions, width); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1035 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1036 | return GL_TRUE; |
| 1037 | } |
| 1038 | if (dimensions > 1 && height < 0) { |
| 1039 | char message[100]; |
| Brian Paul | ec15398 | 2000-12-08 18:09:33 +0000 | [diff] [blame] | 1040 | sprintf(message, "glCopyTexSubImage%dD(height=%d)", dimensions, height); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1041 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1042 | return GL_TRUE; |
| 1043 | } |
| 1044 | |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 1045 | teximage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1046 | if (!teximage) { |
| 1047 | char message[100]; |
| 1048 | sprintf(message, "glCopyTexSubImage%dD(undefined texture)", dimensions); |
| 1049 | gl_error(ctx, GL_INVALID_OPERATION, message); |
| 1050 | return GL_TRUE; |
| 1051 | } |
| 1052 | |
| 1053 | if (xoffset < -((GLint)teximage->Border)) { |
| 1054 | char message[100]; |
| Brian Paul | ec15398 | 2000-12-08 18:09:33 +0000 | [diff] [blame] | 1055 | sprintf(message, "glCopyTexSubImage%dD(xoffset=%d)", dimensions, xoffset); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1056 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1057 | return GL_TRUE; |
| 1058 | } |
| 1059 | if (xoffset+width > (GLint) (teximage->Width+teximage->Border)) { |
| 1060 | char message[100]; |
| 1061 | sprintf(message, "glCopyTexSubImage%dD(xoffset+width)", dimensions); |
| 1062 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1063 | return GL_TRUE; |
| 1064 | } |
| 1065 | if (dimensions > 1) { |
| 1066 | if (yoffset < -((GLint)teximage->Border)) { |
| 1067 | char message[100]; |
| Brian Paul | ec15398 | 2000-12-08 18:09:33 +0000 | [diff] [blame] | 1068 | sprintf(message, "glCopyTexSubImage%dD(yoffset=%d)", dimensions, yoffset); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1069 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1070 | return GL_TRUE; |
| 1071 | } |
| 1072 | /* NOTE: we're adding the border here, not subtracting! */ |
| 1073 | if (yoffset+height > (GLint) (teximage->Height+teximage->Border)) { |
| 1074 | char message[100]; |
| 1075 | sprintf(message, "glCopyTexSubImage%dD(yoffset+height)", dimensions); |
| 1076 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1077 | return GL_TRUE; |
| 1078 | } |
| 1079 | } |
| 1080 | |
| 1081 | if (dimensions > 2) { |
| 1082 | if (zoffset < -((GLint)teximage->Border)) { |
| 1083 | char message[100]; |
| 1084 | sprintf(message, "glCopyTexSubImage%dD(zoffset)", dimensions); |
| 1085 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1086 | return GL_TRUE; |
| 1087 | } |
| 1088 | if (zoffset > (GLint) (teximage->Depth+teximage->Border)) { |
| 1089 | char message[100]; |
| 1090 | sprintf(message, "glCopyTexSubImage%dD(zoffset+depth)", dimensions); |
| 1091 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1092 | return GL_TRUE; |
| 1093 | } |
| 1094 | } |
| 1095 | |
| 1096 | /* if we get here, the parameters are OK */ |
| 1097 | return GL_FALSE; |
| 1098 | } |
| 1099 | |
| 1100 | |
| 1101 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1102 | void |
| 1103 | _mesa_GetTexImage( GLenum target, GLint level, GLenum format, |
| 1104 | GLenum type, GLvoid *pixels ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1105 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1106 | GET_CURRENT_CONTEXT(ctx); |
| Brian Paul | 01e5475 | 2000-09-05 15:40:34 +0000 | [diff] [blame] | 1107 | const struct gl_texture_unit *texUnit; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1108 | const struct gl_texture_object *texObj; |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1109 | struct gl_texture_image *texImage; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1110 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1111 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1112 | |
| 1113 | if (level < 0 || level >= ctx->Const.MaxTextureLevels) { |
| 1114 | gl_error( ctx, GL_INVALID_VALUE, "glGetTexImage(level)" ); |
| 1115 | return; |
| 1116 | } |
| 1117 | |
| Brian Paul | b7d076f | 2000-03-21 01:03:40 +0000 | [diff] [blame] | 1118 | if (_mesa_sizeof_type(type) <= 0) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1119 | gl_error( ctx, GL_INVALID_ENUM, "glGetTexImage(type)" ); |
| 1120 | return; |
| 1121 | } |
| 1122 | |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame] | 1123 | if (_mesa_components_in_format(format) <= 0 || |
| 1124 | format == GL_STENCIL_INDEX) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1125 | gl_error( ctx, GL_INVALID_ENUM, "glGetTexImage(format)" ); |
| 1126 | return; |
| 1127 | } |
| 1128 | |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame] | 1129 | if (!ctx->Extensions.EXT_paletted_texture && is_index_format(format)) { |
| 1130 | gl_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)"); |
| 1131 | } |
| 1132 | |
| 1133 | if (!ctx->Extensions.SGIX_depth_texture && format == GL_DEPTH_COMPONENT) { |
| 1134 | gl_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)"); |
| 1135 | } |
| 1136 | |
| 1137 | /* XXX what if format/type doesn't match texture format/type? */ |
| 1138 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1139 | if (!pixels) |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1140 | return; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1141 | |
| Brian Paul | 01e5475 | 2000-09-05 15:40:34 +0000 | [diff] [blame] | 1142 | texUnit = &(ctx->Texture.Unit[ctx->Texture.CurrentUnit]); |
| 1143 | texObj = _mesa_select_tex_object(ctx, texUnit, target); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1144 | if (!texObj || is_proxy_target(target)) { |
| Brian Paul | 01e5475 | 2000-09-05 15:40:34 +0000 | [diff] [blame] | 1145 | gl_error(ctx, GL_INVALID_ENUM, "glGetTexImage(target)"); |
| 1146 | return; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1147 | } |
| 1148 | |
| Brian Paul | 8e3366f | 2000-11-10 15:32:07 +0000 | [diff] [blame] | 1149 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1150 | if (!texImage) { |
| Brian Paul | 7298e71 | 2000-11-07 16:40:37 +0000 | [diff] [blame] | 1151 | /* invalid mipmap level, not an error */ |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1152 | return; |
| 1153 | } |
| 1154 | |
| 1155 | if (!texImage->Data) { |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1156 | /* no image data, not an error */ |
| 1157 | return; |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1158 | } |
| 1159 | |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1160 | if (ctx->NewState & _NEW_PIXEL) |
| 1161 | gl_update_state(ctx); |
| 1162 | |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame] | 1163 | if (is_color_format(format) && |
| 1164 | ctx->_ImageTransferState & IMAGE_CONVOLUTION_BIT) { |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1165 | /* convert texture image to GL_RGBA, GL_FLOAT */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1166 | GLint width = texImage->Width; |
| 1167 | GLint height = texImage->Height; |
| Brian Paul | f96ce6a | 2000-09-06 15:15:43 +0000 | [diff] [blame] | 1168 | GLint depth = texImage->Depth; |
| 1169 | GLint img, row; |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1170 | GLfloat *tmpImage, *convImage; |
| 1171 | tmpImage = (GLfloat *) MALLOC(width * height * 4 * sizeof(GLfloat)); |
| 1172 | if (!tmpImage) { |
| 1173 | gl_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage"); |
| 1174 | return; |
| 1175 | } |
| 1176 | convImage = (GLfloat *) MALLOC(width * height * 4 * sizeof(GLfloat)); |
| 1177 | if (!convImage) { |
| 1178 | FREE(tmpImage); |
| 1179 | gl_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage"); |
| 1180 | return; |
| 1181 | } |
| 1182 | |
| 1183 | for (img = 0; img < depth; img++) { |
| 1184 | GLint convWidth, convHeight; |
| 1185 | |
| 1186 | /* convert texture data to GLfloat/GL_RGBA */ |
| 1187 | for (row = 0; row < height; row++) { |
| 1188 | GLchan texels[1 << MAX_TEXTURE_LEVELS][4]; |
| 1189 | GLint col; |
| 1190 | GLfloat *dst = tmpImage + row * width * 4; |
| 1191 | for (col = 0; col < width; col++) { |
| Brian Paul | e75d242 | 2001-02-17 18:41:01 +0000 | [diff] [blame] | 1192 | (*texImage->FetchTexel)(texImage, col, row, img, |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1193 | texels[col]); |
| 1194 | } |
| 1195 | _mesa_unpack_float_color_span(ctx, width, GL_RGBA, dst, |
| 1196 | GL_RGBA, CHAN_TYPE, texels, |
| 1197 | &_mesa_native_packing, |
| 1198 | ctx->_ImageTransferState & IMAGE_PRE_CONVOLUTION_BITS, |
| 1199 | GL_FALSE); |
| 1200 | } |
| 1201 | |
| 1202 | convWidth = width; |
| 1203 | convHeight = height; |
| 1204 | |
| 1205 | /* convolve */ |
| 1206 | if (target == GL_TEXTURE_1D) { |
| 1207 | if (ctx->Pixel.Convolution1DEnabled) { |
| 1208 | _mesa_convolve_1d_image(ctx, &convWidth, tmpImage, convImage); |
| 1209 | } |
| 1210 | } |
| 1211 | else { |
| 1212 | if (ctx->Pixel.Convolution2DEnabled) { |
| 1213 | _mesa_convolve_2d_image(ctx, &convWidth, &convHeight, |
| 1214 | tmpImage, convImage); |
| 1215 | } |
| 1216 | else if (ctx->Pixel.Separable2DEnabled) { |
| 1217 | _mesa_convolve_sep_image(ctx, &convWidth, &convHeight, |
| 1218 | tmpImage, convImage); |
| 1219 | } |
| 1220 | } |
| 1221 | |
| 1222 | /* pack convolved image */ |
| 1223 | for (row = 0; row < convHeight; row++) { |
| 1224 | const GLfloat *src = convImage + row * convWidth * 4; |
| 1225 | GLvoid *dest = _mesa_image_address(&ctx->Pack, pixels, |
| 1226 | convWidth, convHeight, |
| 1227 | format, type, img, row, 0); |
| 1228 | _mesa_pack_float_rgba_span(ctx, convWidth, |
| 1229 | (const GLfloat(*)[4]) src, |
| 1230 | format, type, dest, &ctx->Pack, |
| 1231 | ctx->_ImageTransferState & IMAGE_POST_CONVOLUTION_BITS); |
| 1232 | } |
| 1233 | } |
| 1234 | |
| 1235 | FREE(tmpImage); |
| 1236 | FREE(convImage); |
| 1237 | } |
| 1238 | else { |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame] | 1239 | /* no convolution, or non-rgba image */ |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1240 | GLint width = texImage->Width; |
| 1241 | GLint height = texImage->Height; |
| 1242 | GLint depth = texImage->Depth; |
| 1243 | GLint img, row; |
| 1244 | for (img = 0; img < depth; img++) { |
| 1245 | for (row = 0; row < height; row++) { |
| 1246 | /* compute destination address in client memory */ |
| 1247 | GLvoid *dest = _mesa_image_address( &ctx->Unpack, pixels, |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame] | 1248 | width, height, format, type, |
| 1249 | img, row, 0); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1250 | assert(dest); |
| 1251 | |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame] | 1252 | if (format == GL_COLOR_INDEX) { |
| 1253 | GLuint indexRow[MAX_WIDTH]; |
| 1254 | GLint col; |
| 1255 | for (col = 0; col < width; col++) { |
| Brian Paul | e75d242 | 2001-02-17 18:41:01 +0000 | [diff] [blame] | 1256 | (*texImage->FetchTexel)(texImage, col, row, img, |
| 1257 | (GLvoid *) &indexRow[col]); |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame] | 1258 | } |
| 1259 | _mesa_pack_index_span(ctx, width, type, dest, |
| 1260 | indexRow, &ctx->Pack, |
| 1261 | ctx->_ImageTransferState); |
| 1262 | } |
| 1263 | else if (format == GL_DEPTH_COMPONENT) { |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame] | 1264 | GLfloat depthRow[MAX_WIDTH]; |
| 1265 | GLint col; |
| 1266 | for (col = 0; col < width; col++) { |
| Brian Paul | e75d242 | 2001-02-17 18:41:01 +0000 | [diff] [blame] | 1267 | (*texImage->FetchTexel)(texImage, col, row, img, |
| 1268 | (GLvoid *) &depthRow[col]); |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame] | 1269 | } |
| 1270 | _mesa_pack_depth_span(ctx, width, dest, type, |
| 1271 | depthRow, &ctx->Pack); |
| 1272 | } |
| 1273 | else { |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1274 | /* general case: convert row to RGBA format */ |
| 1275 | GLchan rgba[MAX_WIDTH][4]; |
| 1276 | GLint col; |
| 1277 | for (col = 0; col < width; col++) { |
| Brian Paul | e75d242 | 2001-02-17 18:41:01 +0000 | [diff] [blame] | 1278 | (*texImage->FetchTexel)(texImage, col, row, img, |
| 1279 | (GLvoid *) rgba[col]); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1280 | } |
| Brian Paul | e75d242 | 2001-02-17 18:41:01 +0000 | [diff] [blame] | 1281 | _mesa_pack_rgba_span(ctx, width, (const GLchan (*)[4])rgba, |
| 1282 | format, type, dest, &ctx->Pack, |
| 1283 | ctx->_ImageTransferState); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1284 | } /* format */ |
| 1285 | } /* row */ |
| 1286 | } /* img */ |
| 1287 | } /* convolution */ |
| 1288 | } |
| 1289 | |
| 1290 | |
| 1291 | |
| 1292 | /* |
| 1293 | * Called from the API. Note that width includes the border. |
| 1294 | */ |
| 1295 | void |
| 1296 | _mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat, |
| 1297 | GLsizei width, GLint border, GLenum format, |
| 1298 | GLenum type, const GLvoid *pixels ) |
| 1299 | { |
| 1300 | GLsizei postConvWidth = width; |
| 1301 | GET_CURRENT_CONTEXT(ctx); |
| 1302 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
| 1303 | |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame] | 1304 | if (is_color_format(internalFormat)) { |
| 1305 | _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); |
| 1306 | } |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1307 | |
| 1308 | if (target == GL_TEXTURE_1D) { |
| 1309 | struct gl_texture_unit *texUnit; |
| 1310 | struct gl_texture_object *texObj; |
| 1311 | struct gl_texture_image *texImage; |
| 1312 | |
| 1313 | if (texture_error_check(ctx, target, level, internalFormat, |
| 1314 | format, type, 1, postConvWidth, 1, 1, border)) { |
| 1315 | return; /* error was recorded */ |
| 1316 | } |
| 1317 | |
| 1318 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 1319 | texObj = _mesa_select_tex_object(ctx, texUnit, target); |
| 1320 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| 1321 | |
| 1322 | if (!texImage) { |
| 1323 | texImage = _mesa_alloc_texture_image(); |
| 1324 | texObj->Image[level] = texImage; |
| 1325 | if (!texImage) { |
| 1326 | gl_error(ctx, GL_OUT_OF_MEMORY, "glTexImage1D"); |
| 1327 | return; |
| 1328 | } |
| 1329 | } |
| 1330 | else if (texImage->Data) { |
| 1331 | /* free the old texture data */ |
| 1332 | FREE(texImage->Data); |
| 1333 | texImage->Data = NULL; |
| 1334 | } |
| Brian Paul | f378ab8 | 2001-02-06 23:35:26 +0000 | [diff] [blame] | 1335 | clear_teximage_fields(texImage); /* not really needed, but helpful */ |
| Brian Paul | 6628bc9 | 2001-02-07 03:27:41 +0000 | [diff] [blame] | 1336 | init_teximage_fields(ctx, texImage, postConvWidth, 1, 1, |
| 1337 | border, internalFormat); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1338 | |
| Brian Paul | 9499e01 | 2000-10-30 16:32:42 +0000 | [diff] [blame] | 1339 | if (ctx->NewState & _NEW_PIXEL) |
| 1340 | gl_update_state(ctx); |
| Brian Paul | fa4525e | 2000-08-21 14:22:24 +0000 | [diff] [blame] | 1341 | |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1342 | ASSERT(ctx->Driver.TexImage1D); |
| 1343 | if (pixels) { |
| 1344 | (*ctx->Driver.TexImage1D)(ctx, target, level, internalFormat, |
| 1345 | width, border, format, type, pixels, |
| 1346 | &ctx->Unpack, texObj, texImage); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1347 | } |
| Brian Paul | f96ce6a | 2000-09-06 15:15:43 +0000 | [diff] [blame] | 1348 | else { |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1349 | GLubyte *dummy = make_null_texture(width, 1, 1, format); |
| 1350 | if (dummy) { |
| 1351 | (*ctx->Driver.TexImage1D)(ctx, target, level, internalFormat, |
| 1352 | width, border, |
| 1353 | format, GL_UNSIGNED_BYTE, dummy, |
| 1354 | &_mesa_native_packing, texObj, texImage); |
| 1355 | FREE(dummy); |
| 1356 | } |
| 1357 | } |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1358 | |
| Brian Paul | f378ab8 | 2001-02-06 23:35:26 +0000 | [diff] [blame] | 1359 | /* one of these has to be non-zero! */ |
| 1360 | ASSERT(texImage->RedBits || texImage->IndexBits || texImage->AlphaBits || |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame] | 1361 | texImage->LuminanceBits || texImage->IntensityBits || |
| 1362 | texImage->DepthBits); |
| Brian Paul | f378ab8 | 2001-02-06 23:35:26 +0000 | [diff] [blame] | 1363 | ASSERT(texImage->FetchTexel); |
| 1364 | |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1365 | /* state update */ |
| 1366 | texObj->Complete = GL_FALSE; |
| 1367 | ctx->NewState |= _NEW_TEXTURE; |
| 1368 | } |
| 1369 | else if (target == GL_PROXY_TEXTURE_1D) { |
| 1370 | /* Proxy texture: check for errors and update proxy state */ |
| 1371 | GLenum error = texture_error_check(ctx, target, level, internalFormat, |
| 1372 | format, type, 1, |
| 1373 | postConvWidth, 1, 1, border); |
| 1374 | if (!error) { |
| Brian Paul | a1f1586 | 2001-02-07 16:27:41 +0000 | [diff] [blame] | 1375 | struct gl_texture_unit *texUnit; |
| 1376 | struct gl_texture_image *texImage; |
| 1377 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 1378 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| 1379 | init_teximage_fields(ctx, texImage, postConvWidth, 1, 1, |
| 1380 | border, internalFormat); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1381 | ASSERT(ctx->Driver.TestProxyTexImage); |
| 1382 | error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, |
| 1383 | internalFormat, format, type, |
| 1384 | postConvWidth, 1, 1, border); |
| 1385 | } |
| 1386 | if (error) { |
| 1387 | /* if error, clear all proxy texture image parameters */ |
| 1388 | if (level >= 0 && level < ctx->Const.MaxTextureLevels) { |
| Brian Paul | f378ab8 | 2001-02-06 23:35:26 +0000 | [diff] [blame] | 1389 | clear_teximage_fields(ctx->Texture.Proxy1D->Image[level]); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1390 | } |
| 1391 | } |
| 1392 | } |
| 1393 | else { |
| 1394 | gl_error( ctx, GL_INVALID_ENUM, "glTexImage1D(target)" ); |
| 1395 | return; |
| 1396 | } |
| 1397 | } |
| 1398 | |
| 1399 | |
| 1400 | void |
| 1401 | _mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat, |
| 1402 | GLsizei width, GLsizei height, GLint border, |
| 1403 | GLenum format, GLenum type, |
| 1404 | const GLvoid *pixels ) |
| 1405 | { |
| 1406 | GLsizei postConvWidth = width, postConvHeight = height; |
| 1407 | GET_CURRENT_CONTEXT(ctx); |
| 1408 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
| 1409 | |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame] | 1410 | if (is_color_format(internalFormat)) { |
| 1411 | _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, |
| 1412 | &postConvHeight); |
| 1413 | } |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1414 | |
| 1415 | if (target == GL_TEXTURE_2D || |
| 1416 | (ctx->Extensions.ARB_texture_cube_map && |
| 1417 | target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && |
| 1418 | target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)) { |
| 1419 | /* non-proxy target */ |
| 1420 | struct gl_texture_unit *texUnit; |
| 1421 | struct gl_texture_object *texObj; |
| 1422 | struct gl_texture_image *texImage; |
| 1423 | |
| 1424 | if (texture_error_check(ctx, target, level, internalFormat, |
| 1425 | format, type, 2, postConvWidth, postConvHeight, |
| 1426 | 1, border)) { |
| 1427 | return; /* error was recorded */ |
| 1428 | } |
| 1429 | |
| 1430 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 1431 | texObj = _mesa_select_tex_object(ctx, texUnit, target); |
| 1432 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| 1433 | |
| 1434 | if (!texImage) { |
| 1435 | texImage = _mesa_alloc_texture_image(); |
| 1436 | set_tex_image(texObj, target, level, texImage); |
| 1437 | if (!texImage) { |
| 1438 | gl_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D"); |
| 1439 | return; |
| 1440 | } |
| 1441 | } |
| 1442 | else if (texImage->Data) { |
| 1443 | /* free the old texture data */ |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1444 | FREE(texImage->Data); |
| 1445 | texImage->Data = NULL; |
| 1446 | } |
| Brian Paul | f378ab8 | 2001-02-06 23:35:26 +0000 | [diff] [blame] | 1447 | clear_teximage_fields(texImage); /* not really needed, but helpful */ |
| Brian Paul | 6628bc9 | 2001-02-07 03:27:41 +0000 | [diff] [blame] | 1448 | init_teximage_fields(ctx, texImage, postConvWidth, postConvHeight, 1, |
| 1449 | border, internalFormat); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1450 | |
| 1451 | if (ctx->NewState & _NEW_PIXEL) |
| 1452 | gl_update_state(ctx); |
| 1453 | |
| 1454 | ASSERT(ctx->Driver.TexImage2D); |
| 1455 | if (pixels) { |
| 1456 | (*ctx->Driver.TexImage2D)(ctx, target, level, internalFormat, |
| 1457 | width, height, border, format, type, pixels, |
| 1458 | &ctx->Unpack, texObj, texImage); |
| 1459 | } |
| 1460 | else { |
| 1461 | GLubyte *dummy = make_null_texture(width, height, 1, format); |
| 1462 | if (dummy) { |
| 1463 | (*ctx->Driver.TexImage2D)(ctx, target, level, internalFormat, |
| 1464 | width, height, border, |
| 1465 | format, GL_UNSIGNED_BYTE, dummy, |
| 1466 | &_mesa_native_packing, texObj, texImage); |
| 1467 | FREE(dummy); |
| 1468 | } |
| 1469 | } |
| 1470 | |
| Brian Paul | f378ab8 | 2001-02-06 23:35:26 +0000 | [diff] [blame] | 1471 | /* one of these has to be non-zero! */ |
| 1472 | ASSERT(texImage->RedBits || texImage->IndexBits || texImage->AlphaBits || |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame] | 1473 | texImage->LuminanceBits || texImage->IntensityBits || |
| 1474 | texImage->DepthBits); |
| Brian Paul | f378ab8 | 2001-02-06 23:35:26 +0000 | [diff] [blame] | 1475 | ASSERT(texImage->FetchTexel); |
| 1476 | |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1477 | /* state update */ |
| 1478 | texObj->Complete = GL_FALSE; |
| 1479 | ctx->NewState |= _NEW_TEXTURE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1480 | } |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1481 | else if (target == GL_PROXY_TEXTURE_2D) { |
| 1482 | /* Proxy texture: check for errors and update proxy state */ |
| 1483 | GLenum error = texture_error_check(ctx, target, level, internalFormat, |
| 1484 | format, type, 2, |
| 1485 | postConvWidth, postConvHeight, 1, border); |
| 1486 | if (!error) { |
| Brian Paul | a1f1586 | 2001-02-07 16:27:41 +0000 | [diff] [blame] | 1487 | struct gl_texture_unit *texUnit; |
| 1488 | struct gl_texture_image *texImage; |
| 1489 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 1490 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| 1491 | init_teximage_fields(ctx, texImage, postConvWidth, postConvHeight, 1, |
| 1492 | border, internalFormat); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1493 | ASSERT(ctx->Driver.TestProxyTexImage); |
| 1494 | error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, |
| 1495 | internalFormat, format, type, |
| 1496 | postConvWidth, postConvHeight, 1, border); |
| 1497 | } |
| 1498 | if (error) { |
| 1499 | /* if error, clear all proxy texture image parameters */ |
| 1500 | if (level >= 0 && level < ctx->Const.MaxTextureLevels) { |
| Brian Paul | f378ab8 | 2001-02-06 23:35:26 +0000 | [diff] [blame] | 1501 | clear_teximage_fields(ctx->Texture.Proxy2D->Image[level]); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1502 | } |
| 1503 | } |
| 1504 | } |
| 1505 | else { |
| 1506 | gl_error( ctx, GL_INVALID_ENUM, "glTexImage2D(target)" ); |
| 1507 | return; |
| 1508 | } |
| 1509 | } |
| 1510 | |
| 1511 | |
| 1512 | /* |
| 1513 | * Called by the API or display list executor. |
| 1514 | * Note that width and height include the border. |
| 1515 | */ |
| 1516 | void |
| 1517 | _mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat, |
| 1518 | GLsizei width, GLsizei height, GLsizei depth, |
| 1519 | GLint border, GLenum format, GLenum type, |
| 1520 | const GLvoid *pixels ) |
| 1521 | { |
| 1522 | GET_CURRENT_CONTEXT(ctx); |
| 1523 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
| 1524 | |
| 1525 | if (target == GL_TEXTURE_3D) { |
| 1526 | struct gl_texture_unit *texUnit; |
| 1527 | struct gl_texture_object *texObj; |
| 1528 | struct gl_texture_image *texImage; |
| 1529 | |
| 1530 | if (texture_error_check(ctx, target, level, internalFormat, |
| 1531 | format, type, 3, width, height, depth, border)) { |
| 1532 | return; /* error was recorded */ |
| 1533 | } |
| 1534 | |
| 1535 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 1536 | texObj = _mesa_select_tex_object(ctx, texUnit, target); |
| 1537 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| 1538 | |
| 1539 | if (!texImage) { |
| 1540 | texImage = _mesa_alloc_texture_image(); |
| 1541 | texObj->Image[level] = texImage; |
| 1542 | if (!texImage) { |
| 1543 | gl_error(ctx, GL_OUT_OF_MEMORY, "glTexImage3D"); |
| 1544 | return; |
| 1545 | } |
| 1546 | } |
| 1547 | else if (texImage->Data) { |
| 1548 | FREE(texImage->Data); |
| 1549 | texImage->Data = NULL; |
| 1550 | } |
| Brian Paul | f378ab8 | 2001-02-06 23:35:26 +0000 | [diff] [blame] | 1551 | clear_teximage_fields(texImage); /* not really needed, but helpful */ |
| Brian Paul | 6628bc9 | 2001-02-07 03:27:41 +0000 | [diff] [blame] | 1552 | init_teximage_fields(ctx, texImage, width, height, depth, border, |
| 1553 | internalFormat); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1554 | |
| 1555 | if (ctx->NewState & _NEW_PIXEL) |
| 1556 | gl_update_state(ctx); |
| 1557 | |
| 1558 | ASSERT(ctx->Driver.TexImage3D); |
| 1559 | if (pixels) { |
| 1560 | (*ctx->Driver.TexImage3D)(ctx, target, level, internalFormat, |
| 1561 | width, height, depth, border, |
| 1562 | format, type, pixels, |
| 1563 | &ctx->Unpack, texObj, texImage); |
| 1564 | } |
| 1565 | else { |
| 1566 | GLubyte *dummy = make_null_texture(width, height, depth, format); |
| 1567 | if (dummy) { |
| 1568 | (*ctx->Driver.TexImage3D)(ctx, target, level, internalFormat, |
| 1569 | width, height, depth, border, |
| 1570 | format, GL_UNSIGNED_BYTE, dummy, |
| 1571 | &_mesa_native_packing, texObj, texImage); |
| 1572 | FREE(dummy); |
| 1573 | } |
| 1574 | } |
| 1575 | |
| Brian Paul | f378ab8 | 2001-02-06 23:35:26 +0000 | [diff] [blame] | 1576 | /* one of these has to be non-zero! */ |
| 1577 | ASSERT(texImage->RedBits || texImage->IndexBits || texImage->AlphaBits || |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame] | 1578 | texImage->LuminanceBits || texImage->IntensityBits || |
| 1579 | texImage->DepthBits); |
| Brian Paul | f378ab8 | 2001-02-06 23:35:26 +0000 | [diff] [blame] | 1580 | ASSERT(texImage->FetchTexel); |
| 1581 | |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1582 | /* state update */ |
| 1583 | texObj->Complete = GL_FALSE; |
| 1584 | ctx->NewState |= _NEW_TEXTURE; |
| 1585 | } |
| 1586 | else if (target == GL_PROXY_TEXTURE_3D) { |
| 1587 | /* Proxy texture: check for errors and update proxy state */ |
| 1588 | GLenum error = texture_error_check(ctx, target, level, internalFormat, |
| 1589 | format, type, 3, width, height, depth, border); |
| 1590 | if (!error) { |
| Brian Paul | a1f1586 | 2001-02-07 16:27:41 +0000 | [diff] [blame] | 1591 | struct gl_texture_unit *texUnit; |
| 1592 | struct gl_texture_image *texImage; |
| 1593 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 1594 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| 1595 | init_teximage_fields(ctx, texImage, width, height, 1, |
| 1596 | border, internalFormat); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1597 | ASSERT(ctx->Driver.TestProxyTexImage); |
| 1598 | error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, |
| 1599 | internalFormat, format, type, |
| 1600 | width, height, depth, border); |
| 1601 | } |
| 1602 | if (error) { |
| 1603 | /* if error, clear all proxy texture image parameters */ |
| Brian Paul | f378ab8 | 2001-02-06 23:35:26 +0000 | [diff] [blame] | 1604 | if (level >= 0 && level < ctx->Const.MaxTextureLevels) { |
| 1605 | clear_teximage_fields(ctx->Texture.Proxy3D->Image[level]); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1606 | } |
| 1607 | } |
| 1608 | } |
| 1609 | else { |
| 1610 | gl_error( ctx, GL_INVALID_ENUM, "glTexImage3D(target)" ); |
| 1611 | return; |
| 1612 | } |
| 1613 | } |
| 1614 | |
| 1615 | |
| 1616 | void |
| 1617 | _mesa_TexImage3DEXT( GLenum target, GLint level, GLenum internalFormat, |
| 1618 | GLsizei width, GLsizei height, GLsizei depth, |
| 1619 | GLint border, GLenum format, GLenum type, |
| 1620 | const GLvoid *pixels ) |
| 1621 | { |
| 1622 | _mesa_TexImage3D(target, level, (GLint) internalFormat, width, height, |
| 1623 | depth, border, format, type, pixels); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1624 | } |
| 1625 | |
| 1626 | |
| 1627 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1628 | void |
| 1629 | _mesa_TexSubImage1D( GLenum target, GLint level, |
| 1630 | GLint xoffset, GLsizei width, |
| 1631 | GLenum format, GLenum type, |
| 1632 | const GLvoid *pixels ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1633 | { |
| Brian Paul | ab6e78f | 2000-12-09 21:30:43 +0000 | [diff] [blame] | 1634 | GLsizei postConvWidth = width; |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1635 | GET_CURRENT_CONTEXT(ctx); |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1636 | struct gl_texture_unit *texUnit; |
| 1637 | struct gl_texture_object *texObj; |
| 1638 | struct gl_texture_image *texImage; |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 1639 | |
| Brian Paul | 2aadbf4 | 2001-02-19 20:01:41 +0000 | [diff] [blame] | 1640 | if (ctx->NewState & _NEW_PIXEL) |
| 1641 | gl_update_state(ctx); |
| 1642 | |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame] | 1643 | /* XXX should test internal format */ |
| 1644 | if (is_color_format(format)) { |
| 1645 | _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); |
| 1646 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1647 | |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1648 | if (subtexture_error_check(ctx, 1, target, level, xoffset, 0, 0, |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 1649 | postConvWidth, 1, 1, format, type)) { |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1650 | return; /* error was detected */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1651 | } |
| 1652 | |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1653 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1654 | texObj = _mesa_select_tex_object(ctx, texUnit, target); |
| 1655 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1656 | assert(texImage); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1657 | |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1658 | if (width == 0 || !pixels) |
| 1659 | return; /* no-op, not an error */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1660 | |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1661 | ASSERT(ctx->Driver.TexSubImage1D); |
| 1662 | (*ctx->Driver.TexSubImage1D)(ctx, target, level, xoffset, width, |
| 1663 | format, type, pixels, &ctx->Unpack, |
| 1664 | texObj, texImage); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1668 | void |
| 1669 | _mesa_TexSubImage2D( GLenum target, GLint level, |
| 1670 | GLint xoffset, GLint yoffset, |
| 1671 | GLsizei width, GLsizei height, |
| 1672 | GLenum format, GLenum type, |
| 1673 | const GLvoid *pixels ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1674 | { |
| Brian Paul | ab6e78f | 2000-12-09 21:30:43 +0000 | [diff] [blame] | 1675 | GLsizei postConvWidth = width, postConvHeight = height; |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1676 | GET_CURRENT_CONTEXT(ctx); |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1677 | struct gl_texture_unit *texUnit; |
| 1678 | struct gl_texture_object *texObj; |
| 1679 | struct gl_texture_image *texImage; |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 1680 | |
| Brian Paul | 2aadbf4 | 2001-02-19 20:01:41 +0000 | [diff] [blame] | 1681 | if (ctx->NewState & _NEW_PIXEL) |
| 1682 | gl_update_state(ctx); |
| 1683 | |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame] | 1684 | /* XXX should test internal format */ |
| 1685 | if (is_color_format(format)) { |
| 1686 | _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, |
| 1687 | &postConvHeight); |
| 1688 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1689 | |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1690 | if (subtexture_error_check(ctx, 2, target, level, xoffset, yoffset, 0, |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 1691 | postConvWidth, postConvHeight, 1, format, type)) { |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1692 | return; /* error was detected */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1693 | } |
| 1694 | |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1695 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| Brian Paul | 35d5301 | 2000-05-23 17:14:49 +0000 | [diff] [blame] | 1696 | texObj = _mesa_select_tex_object(ctx, texUnit, target); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1697 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1698 | assert(texImage); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1699 | |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1700 | if (width == 0 || height == 0 || !pixels) |
| 1701 | return; /* no-op, not an error */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1702 | |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1703 | ASSERT(ctx->Driver.TexSubImage2D); |
| 1704 | (*ctx->Driver.TexSubImage2D)(ctx, target, level, xoffset, yoffset, |
| 1705 | width, height, format, type, pixels, |
| 1706 | &ctx->Unpack, texObj, texImage); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1707 | } |
| 1708 | |
| 1709 | |
| 1710 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1711 | void |
| 1712 | _mesa_TexSubImage3D( GLenum target, GLint level, |
| 1713 | GLint xoffset, GLint yoffset, GLint zoffset, |
| 1714 | GLsizei width, GLsizei height, GLsizei depth, |
| 1715 | GLenum format, GLenum type, |
| 1716 | const GLvoid *pixels ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1717 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1718 | GET_CURRENT_CONTEXT(ctx); |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1719 | struct gl_texture_unit *texUnit; |
| 1720 | struct gl_texture_object *texObj; |
| 1721 | struct gl_texture_image *texImage; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1722 | |
| Brian Paul | 2aadbf4 | 2001-02-19 20:01:41 +0000 | [diff] [blame] | 1723 | if (ctx->NewState & _NEW_PIXEL) |
| 1724 | gl_update_state(ctx); |
| 1725 | |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1726 | if (subtexture_error_check(ctx, 3, target, level, xoffset, yoffset, zoffset, |
| 1727 | width, height, depth, format, type)) { |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1728 | return; /* error was detected */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1729 | } |
| 1730 | |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1731 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1732 | texObj = _mesa_select_tex_object(ctx, texUnit, target); |
| 1733 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1734 | assert(texImage); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1735 | |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1736 | if (width == 0 || height == 0 || height == 0 || !pixels) |
| 1737 | return; /* no-op, not an error */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1738 | |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1739 | ASSERT(ctx->Driver.TexSubImage3D); |
| 1740 | (*ctx->Driver.TexSubImage3D)(ctx, target, level, |
| 1741 | xoffset, yoffset, zoffset, |
| 1742 | width, height, depth, |
| 1743 | format, type, pixels, |
| 1744 | &ctx->Unpack, texObj, texImage ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1745 | } |
| 1746 | |
| 1747 | |
| 1748 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1749 | void |
| 1750 | _mesa_CopyTexImage1D( GLenum target, GLint level, |
| 1751 | GLenum internalFormat, |
| 1752 | GLint x, GLint y, |
| 1753 | GLsizei width, GLint border ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1754 | { |
| Brian Paul | 2aadbf4 | 2001-02-19 20:01:41 +0000 | [diff] [blame] | 1755 | struct gl_texture_unit *texUnit; |
| 1756 | struct gl_texture_object *texObj; |
| 1757 | struct gl_texture_image *texImage; |
| Brian Paul | ab6e78f | 2000-12-09 21:30:43 +0000 | [diff] [blame] | 1758 | GLsizei postConvWidth = width; |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1759 | GET_CURRENT_CONTEXT(ctx); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1760 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1761 | |
| Brian Paul | 9499e01 | 2000-10-30 16:32:42 +0000 | [diff] [blame] | 1762 | if (ctx->NewState & _NEW_PIXEL) |
| 1763 | gl_update_state(ctx); |
| Brian Paul | fa4525e | 2000-08-21 14:22:24 +0000 | [diff] [blame] | 1764 | |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame] | 1765 | if (is_color_format(internalFormat)) { |
| 1766 | _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); |
| 1767 | } |
| Brian Paul | ab6e78f | 2000-12-09 21:30:43 +0000 | [diff] [blame] | 1768 | |
| 1769 | if (copytexture_error_check(ctx, 1, target, level, internalFormat, |
| 1770 | postConvWidth, 1, border)) |
| 1771 | return; |
| 1772 | |
| Brian Paul | 2aadbf4 | 2001-02-19 20:01:41 +0000 | [diff] [blame] | 1773 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 1774 | texObj = _mesa_select_tex_object(ctx, texUnit, target); |
| 1775 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| 1776 | if (!texImage) { |
| 1777 | texImage = _mesa_alloc_texture_image(); |
| 1778 | set_tex_image(texObj, target, level, texImage); |
| 1779 | if (!texImage) { |
| 1780 | gl_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage1D"); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1781 | return; |
| 1782 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1783 | } |
| Brian Paul | 2aadbf4 | 2001-02-19 20:01:41 +0000 | [diff] [blame] | 1784 | else if (texImage->Data) { |
| 1785 | /* free the old texture data */ |
| 1786 | FREE(texImage->Data); |
| 1787 | texImage->Data = NULL; |
| 1788 | } |
| 1789 | |
| 1790 | clear_teximage_fields(texImage); /* not really needed, but helpful */ |
| 1791 | init_teximage_fields(ctx, texImage, postConvWidth, 1, 1, |
| 1792 | border, internalFormat); |
| 1793 | |
| 1794 | |
| 1795 | ASSERT(ctx->Driver.CopyTexImage1D); |
| 1796 | (*ctx->Driver.CopyTexImage1D)(ctx, target, level, internalFormat, |
| 1797 | x, y, width, border); |
| 1798 | |
| 1799 | /* state update */ |
| 1800 | texObj->Complete = GL_FALSE; |
| 1801 | ctx->NewState |= _NEW_TEXTURE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1802 | } |
| 1803 | |
| 1804 | |
| 1805 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1806 | void |
| 1807 | _mesa_CopyTexImage2D( GLenum target, GLint level, GLenum internalFormat, |
| 1808 | GLint x, GLint y, GLsizei width, GLsizei height, |
| 1809 | GLint border ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1810 | { |
| Brian Paul | 2aadbf4 | 2001-02-19 20:01:41 +0000 | [diff] [blame] | 1811 | struct gl_texture_unit *texUnit; |
| 1812 | struct gl_texture_object *texObj; |
| 1813 | struct gl_texture_image *texImage; |
| Brian Paul | ab6e78f | 2000-12-09 21:30:43 +0000 | [diff] [blame] | 1814 | GLsizei postConvWidth = width, postConvHeight = height; |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1815 | GET_CURRENT_CONTEXT(ctx); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1816 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1817 | |
| Brian Paul | 9499e01 | 2000-10-30 16:32:42 +0000 | [diff] [blame] | 1818 | if (ctx->NewState & _NEW_PIXEL) |
| 1819 | gl_update_state(ctx); |
| Brian Paul | fa4525e | 2000-08-21 14:22:24 +0000 | [diff] [blame] | 1820 | |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame] | 1821 | if (is_color_format(internalFormat)) { |
| 1822 | _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, |
| 1823 | &postConvHeight); |
| 1824 | } |
| Brian Paul | ab6e78f | 2000-12-09 21:30:43 +0000 | [diff] [blame] | 1825 | |
| 1826 | if (copytexture_error_check(ctx, 2, target, level, internalFormat, |
| 1827 | postConvWidth, postConvHeight, border)) |
| 1828 | return; |
| 1829 | |
| Brian Paul | 2aadbf4 | 2001-02-19 20:01:41 +0000 | [diff] [blame] | 1830 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 1831 | texObj = _mesa_select_tex_object(ctx, texUnit, target); |
| 1832 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| 1833 | if (!texImage) { |
| 1834 | texImage = _mesa_alloc_texture_image(); |
| 1835 | set_tex_image(texObj, target, level, texImage); |
| 1836 | if (!texImage) { |
| 1837 | gl_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage2D"); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1838 | return; |
| 1839 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1840 | } |
| Brian Paul | 2aadbf4 | 2001-02-19 20:01:41 +0000 | [diff] [blame] | 1841 | else if (texImage->Data) { |
| 1842 | /* free the old texture data */ |
| 1843 | FREE(texImage->Data); |
| 1844 | texImage->Data = NULL; |
| 1845 | } |
| 1846 | |
| 1847 | clear_teximage_fields(texImage); /* not really needed, but helpful */ |
| 1848 | init_teximage_fields(ctx, texImage, postConvWidth, postConvHeight, 1, |
| 1849 | border, internalFormat); |
| 1850 | |
| 1851 | ASSERT(ctx->Driver.CopyTexImage2D); |
| 1852 | (*ctx->Driver.CopyTexImage2D)(ctx, target, level, internalFormat, |
| 1853 | x, y, width, height, border); |
| 1854 | |
| 1855 | /* state update */ |
| 1856 | texObj->Complete = GL_FALSE; |
| 1857 | ctx->NewState |= _NEW_TEXTURE; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1858 | } |
| 1859 | |
| 1860 | |
| 1861 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1862 | void |
| 1863 | _mesa_CopyTexSubImage1D( GLenum target, GLint level, |
| 1864 | GLint xoffset, GLint x, GLint y, GLsizei width ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1865 | { |
| Brian Paul | ab6e78f | 2000-12-09 21:30:43 +0000 | [diff] [blame] | 1866 | GLsizei postConvWidth = width; |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1867 | GET_CURRENT_CONTEXT(ctx); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1868 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1869 | |
| Brian Paul | 9499e01 | 2000-10-30 16:32:42 +0000 | [diff] [blame] | 1870 | if (ctx->NewState & _NEW_PIXEL) |
| 1871 | gl_update_state(ctx); |
| Brian Paul | fa4525e | 2000-08-21 14:22:24 +0000 | [diff] [blame] | 1872 | |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame] | 1873 | /* XXX should test internal format */ |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1874 | _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); |
| Brian Paul | ab6e78f | 2000-12-09 21:30:43 +0000 | [diff] [blame] | 1875 | |
| 1876 | if (copytexsubimage_error_check(ctx, 1, target, level, |
| 1877 | xoffset, 0, 0, postConvWidth, 1)) |
| 1878 | return; |
| 1879 | |
| Brian Paul | 2aadbf4 | 2001-02-19 20:01:41 +0000 | [diff] [blame] | 1880 | ASSERT(ctx->Driver.CopyTexSubImage1D); |
| 1881 | (*ctx->Driver.CopyTexSubImage1D)(ctx, target, level, xoffset, x, y, width); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1882 | } |
| 1883 | |
| 1884 | |
| 1885 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1886 | void |
| 1887 | _mesa_CopyTexSubImage2D( GLenum target, GLint level, |
| 1888 | GLint xoffset, GLint yoffset, |
| 1889 | GLint x, GLint y, GLsizei width, GLsizei height ) |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1890 | { |
| Brian Paul | ab6e78f | 2000-12-09 21:30:43 +0000 | [diff] [blame] | 1891 | GLsizei postConvWidth = width, postConvHeight = height; |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1892 | GET_CURRENT_CONTEXT(ctx); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1893 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1894 | |
| Brian Paul | 9499e01 | 2000-10-30 16:32:42 +0000 | [diff] [blame] | 1895 | if (ctx->NewState & _NEW_PIXEL) |
| 1896 | gl_update_state(ctx); |
| Brian Paul | fa4525e | 2000-08-21 14:22:24 +0000 | [diff] [blame] | 1897 | |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame] | 1898 | /* XXX should test internal format */ |
| 1899 | _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, &postConvHeight); |
| Brian Paul | ab6e78f | 2000-12-09 21:30:43 +0000 | [diff] [blame] | 1900 | |
| 1901 | if (copytexsubimage_error_check(ctx, 2, target, level, xoffset, yoffset, 0, |
| 1902 | postConvWidth, postConvHeight)) |
| 1903 | return; |
| 1904 | |
| Brian Paul | 2aadbf4 | 2001-02-19 20:01:41 +0000 | [diff] [blame] | 1905 | ASSERT(ctx->Driver.CopyTexSubImage2D); |
| 1906 | (*ctx->Driver.CopyTexSubImage2D)(ctx, target, level, |
| 1907 | xoffset, yoffset, x, y, width, height); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1908 | } |
| 1909 | |
| 1910 | |
| 1911 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1912 | void |
| 1913 | _mesa_CopyTexSubImage3D( GLenum target, GLint level, |
| 1914 | GLint xoffset, GLint yoffset, GLint zoffset, |
| 1915 | GLint x, GLint y, GLsizei width, GLsizei height ) |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1916 | { |
| Brian Paul | ab6e78f | 2000-12-09 21:30:43 +0000 | [diff] [blame] | 1917 | GLsizei postConvWidth = width, postConvHeight = height; |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1918 | GET_CURRENT_CONTEXT(ctx); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1919 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1920 | |
| Brian Paul | 9499e01 | 2000-10-30 16:32:42 +0000 | [diff] [blame] | 1921 | if (ctx->NewState & _NEW_PIXEL) |
| 1922 | gl_update_state(ctx); |
| Brian Paul | fa4525e | 2000-08-21 14:22:24 +0000 | [diff] [blame] | 1923 | |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame] | 1924 | /* XXX should test internal format */ |
| 1925 | _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, &postConvHeight); |
| Brian Paul | ab6e78f | 2000-12-09 21:30:43 +0000 | [diff] [blame] | 1926 | |
| 1927 | if (copytexsubimage_error_check(ctx, 3, target, level, xoffset, yoffset, |
| 1928 | zoffset, postConvWidth, postConvHeight)) |
| 1929 | return; |
| 1930 | |
| Brian Paul | 2aadbf4 | 2001-02-19 20:01:41 +0000 | [diff] [blame] | 1931 | ASSERT(ctx->Driver.CopyTexSubImage3D); |
| 1932 | (*ctx->Driver.CopyTexSubImage3D)(ctx, target, level, |
| 1933 | xoffset, yoffset, zoffset, |
| 1934 | x, y, width, height); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1935 | } |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 1936 | |
| 1937 | |
| 1938 | |
| 1939 | void |
| 1940 | _mesa_CompressedTexImage1DARB(GLenum target, GLint level, |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 1941 | GLenum internalFormat, GLsizei width, |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 1942 | GLint border, GLsizei imageSize, |
| 1943 | const GLvoid *data) |
| 1944 | { |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 1945 | GET_CURRENT_CONTEXT(ctx); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1946 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 1947 | |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 1948 | switch (internalFormat) { |
| 1949 | case GL_COMPRESSED_ALPHA_ARB: |
| 1950 | case GL_COMPRESSED_LUMINANCE_ARB: |
| 1951 | case GL_COMPRESSED_LUMINANCE_ALPHA_ARB: |
| 1952 | case GL_COMPRESSED_INTENSITY_ARB: |
| 1953 | case GL_COMPRESSED_RGB_ARB: |
| 1954 | case GL_COMPRESSED_RGBA_ARB: |
| 1955 | gl_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage1DARB"); |
| 1956 | return; |
| 1957 | default: |
| 1958 | /* silence compiler warning */ |
| 1959 | ; |
| 1960 | } |
| 1961 | |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 1962 | if (target == GL_TEXTURE_1D) { |
| 1963 | struct gl_texture_unit *texUnit; |
| 1964 | struct gl_texture_object *texObj; |
| 1965 | struct gl_texture_image *texImage; |
| 1966 | |
| 1967 | if (texture_error_check(ctx, target, level, internalFormat, |
| 1968 | GL_NONE, GL_NONE, 1, width, 1, 1, border)) { |
| 1969 | return; /* error in texture image was detected */ |
| 1970 | } |
| 1971 | |
| 1972 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1973 | texObj = _mesa_select_tex_object(ctx, texUnit, target); |
| 1974 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 1975 | |
| 1976 | if (!texImage) { |
| 1977 | texImage = _mesa_alloc_texture_image(); |
| 1978 | texObj->Image[level] = texImage; |
| 1979 | if (!texImage) { |
| 1980 | gl_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage1DARB"); |
| 1981 | return; |
| 1982 | } |
| 1983 | } |
| 1984 | else if (texImage->Data) { |
| 1985 | FREE(texImage->Data); |
| 1986 | texImage->Data = NULL; |
| 1987 | } |
| 1988 | |
| Brian Paul | 6628bc9 | 2001-02-07 03:27:41 +0000 | [diff] [blame] | 1989 | init_teximage_fields(ctx, texImage, width, 1, 1, border, internalFormat); |
| 1990 | |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1991 | if (ctx->Extensions.ARB_texture_compression) { |
| 1992 | ASSERT(ctx->Driver.CompressedTexImage1D); |
| 1993 | (*ctx->Driver.CompressedTexImage1D)(ctx, target, level, |
| 1994 | internalFormat, width, border, |
| 1995 | imageSize, data, |
| 1996 | texObj, texImage); |
| 1997 | ASSERT(texImage->CompressedSize > 0); /* sanity */ |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 1998 | } |
| 1999 | |
| 2000 | /* state update */ |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 2001 | texObj->Complete = GL_FALSE; |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 2002 | ctx->NewState |= _NEW_TEXTURE; |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2003 | } |
| 2004 | else if (target == GL_PROXY_TEXTURE_1D) { |
| 2005 | /* Proxy texture: check for errors and update proxy state */ |
| Brian Paul | 38d3f3d | 2000-09-07 15:38:49 +0000 | [diff] [blame] | 2006 | GLenum error = texture_error_check(ctx, target, level, internalFormat, |
| 2007 | GL_NONE, GL_NONE, 1, width, 1, 1, border); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2008 | if (!error) { |
| Brian Paul | a1f1586 | 2001-02-07 16:27:41 +0000 | [diff] [blame] | 2009 | struct gl_texture_unit *texUnit; |
| 2010 | struct gl_texture_image *texImage; |
| 2011 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 2012 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| 2013 | init_teximage_fields(ctx, texImage, width, 1, 1, |
| 2014 | border, internalFormat); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2015 | ASSERT(ctx->Driver.TestProxyTexImage); |
| Brian Paul | 38d3f3d | 2000-09-07 15:38:49 +0000 | [diff] [blame] | 2016 | error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, |
| 2017 | internalFormat, GL_NONE, GL_NONE, |
| 2018 | width, 1, 1, border); |
| 2019 | } |
| 2020 | if (error) { |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2021 | /* if error, clear all proxy texture image parameters */ |
| Brian Paul | f378ab8 | 2001-02-06 23:35:26 +0000 | [diff] [blame] | 2022 | if (level >= 0 && level < ctx->Const.MaxTextureLevels) { |
| 2023 | clear_teximage_fields(ctx->Texture.Proxy1D->Image[level]); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2024 | } |
| 2025 | } |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2026 | } |
| 2027 | else { |
| 2028 | gl_error( ctx, GL_INVALID_ENUM, "glCompressedTexImage1DARB(target)" ); |
| 2029 | return; |
| 2030 | } |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 2031 | } |
| 2032 | |
| 2033 | |
| 2034 | void |
| 2035 | _mesa_CompressedTexImage2DARB(GLenum target, GLint level, |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2036 | GLenum internalFormat, GLsizei width, |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 2037 | GLsizei height, GLint border, GLsizei imageSize, |
| 2038 | const GLvoid *data) |
| 2039 | { |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2040 | GET_CURRENT_CONTEXT(ctx); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 2041 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2042 | |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 2043 | switch (internalFormat) { |
| 2044 | case GL_COMPRESSED_ALPHA_ARB: |
| 2045 | case GL_COMPRESSED_LUMINANCE_ARB: |
| 2046 | case GL_COMPRESSED_LUMINANCE_ALPHA_ARB: |
| 2047 | case GL_COMPRESSED_INTENSITY_ARB: |
| 2048 | case GL_COMPRESSED_RGB_ARB: |
| 2049 | case GL_COMPRESSED_RGBA_ARB: |
| 2050 | gl_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage2DARB"); |
| 2051 | return; |
| 2052 | default: |
| 2053 | /* silence compiler warning */ |
| 2054 | ; |
| 2055 | } |
| 2056 | |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2057 | if (target == GL_TEXTURE_2D || |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 2058 | (ctx->Extensions.ARB_texture_cube_map && |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2059 | target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && |
| 2060 | target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)) { |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2061 | struct gl_texture_unit *texUnit; |
| 2062 | struct gl_texture_object *texObj; |
| 2063 | struct gl_texture_image *texImage; |
| 2064 | |
| 2065 | if (texture_error_check(ctx, target, level, internalFormat, |
| 2066 | GL_NONE, GL_NONE, 1, width, height, 1, border)) { |
| 2067 | return; /* error in texture image was detected */ |
| 2068 | } |
| 2069 | |
| 2070 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2071 | texObj = _mesa_select_tex_object(ctx, texUnit, target); |
| 2072 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2073 | |
| 2074 | if (!texImage) { |
| 2075 | texImage = _mesa_alloc_texture_image(); |
| 2076 | texObj->Image[level] = texImage; |
| 2077 | if (!texImage) { |
| 2078 | gl_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2DARB"); |
| 2079 | return; |
| 2080 | } |
| 2081 | } |
| 2082 | else if (texImage->Data) { |
| 2083 | FREE(texImage->Data); |
| 2084 | texImage->Data = NULL; |
| 2085 | } |
| 2086 | |
| Brian Paul | 6628bc9 | 2001-02-07 03:27:41 +0000 | [diff] [blame] | 2087 | init_teximage_fields(ctx, texImage, width, height, 1, border, |
| 2088 | internalFormat); |
| 2089 | |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2090 | if (ctx->Extensions.ARB_texture_compression) { |
| 2091 | ASSERT(ctx->Driver.CompressedTexImage2D); |
| 2092 | (*ctx->Driver.CompressedTexImage2D)(ctx, target, level, |
| 2093 | internalFormat, width, height, |
| 2094 | border, imageSize, data, |
| 2095 | texObj, texImage); |
| 2096 | ASSERT(texImage->CompressedSize > 0); /* sanity */ |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2097 | } |
| 2098 | |
| 2099 | /* state update */ |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 2100 | texObj->Complete = GL_FALSE; |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 2101 | ctx->NewState |= _NEW_TEXTURE; |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2102 | } |
| 2103 | else if (target == GL_PROXY_TEXTURE_2D) { |
| 2104 | /* Proxy texture: check for errors and update proxy state */ |
| Brian Paul | 38d3f3d | 2000-09-07 15:38:49 +0000 | [diff] [blame] | 2105 | GLenum error = texture_error_check(ctx, target, level, internalFormat, |
| 2106 | GL_NONE, GL_NONE, 2, width, height, 1, border); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2107 | if (!error) { |
| Brian Paul | a1f1586 | 2001-02-07 16:27:41 +0000 | [diff] [blame] | 2108 | struct gl_texture_unit *texUnit; |
| 2109 | struct gl_texture_image *texImage; |
| 2110 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 2111 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| 2112 | init_teximage_fields(ctx, texImage, width, height, 1, |
| 2113 | border, internalFormat); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2114 | ASSERT(ctx->Driver.TestProxyTexImage); |
| Brian Paul | 38d3f3d | 2000-09-07 15:38:49 +0000 | [diff] [blame] | 2115 | error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, |
| 2116 | internalFormat, GL_NONE, GL_NONE, |
| 2117 | width, height, 1, border); |
| 2118 | } |
| 2119 | if (error) { |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2120 | /* if error, clear all proxy texture image parameters */ |
| Brian Paul | f378ab8 | 2001-02-06 23:35:26 +0000 | [diff] [blame] | 2121 | if (level >= 0 && level < ctx->Const.MaxTextureLevels) { |
| 2122 | clear_teximage_fields(ctx->Texture.Proxy2D->Image[level]); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2123 | } |
| 2124 | } |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2125 | } |
| 2126 | else { |
| 2127 | gl_error( ctx, GL_INVALID_ENUM, "glCompressedTexImage2DARB(target)" ); |
| 2128 | return; |
| 2129 | } |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 2130 | } |
| 2131 | |
| 2132 | |
| 2133 | void |
| 2134 | _mesa_CompressedTexImage3DARB(GLenum target, GLint level, |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2135 | GLenum internalFormat, GLsizei width, |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 2136 | GLsizei height, GLsizei depth, GLint border, |
| 2137 | GLsizei imageSize, const GLvoid *data) |
| 2138 | { |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2139 | GET_CURRENT_CONTEXT(ctx); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 2140 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2141 | |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 2142 | switch (internalFormat) { |
| 2143 | case GL_COMPRESSED_ALPHA_ARB: |
| 2144 | case GL_COMPRESSED_LUMINANCE_ARB: |
| 2145 | case GL_COMPRESSED_LUMINANCE_ALPHA_ARB: |
| 2146 | case GL_COMPRESSED_INTENSITY_ARB: |
| 2147 | case GL_COMPRESSED_RGB_ARB: |
| 2148 | case GL_COMPRESSED_RGBA_ARB: |
| 2149 | gl_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage3DARB"); |
| 2150 | return; |
| 2151 | default: |
| 2152 | /* silence compiler warning */ |
| 2153 | ; |
| 2154 | } |
| 2155 | |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2156 | if (target == GL_TEXTURE_3D) { |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2157 | struct gl_texture_unit *texUnit; |
| 2158 | struct gl_texture_object *texObj; |
| 2159 | struct gl_texture_image *texImage; |
| 2160 | |
| 2161 | if (texture_error_check(ctx, target, level, internalFormat, |
| 2162 | GL_NONE, GL_NONE, 1, width, height, depth, border)) { |
| 2163 | return; /* error in texture image was detected */ |
| 2164 | } |
| 2165 | |
| 2166 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2167 | texObj = _mesa_select_tex_object(ctx, texUnit, target); |
| 2168 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2169 | |
| 2170 | if (!texImage) { |
| 2171 | texImage = _mesa_alloc_texture_image(); |
| 2172 | texObj->Image[level] = texImage; |
| 2173 | if (!texImage) { |
| 2174 | gl_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage3DARB"); |
| 2175 | return; |
| 2176 | } |
| 2177 | } |
| 2178 | else if (texImage->Data) { |
| 2179 | FREE(texImage->Data); |
| 2180 | texImage->Data = NULL; |
| 2181 | } |
| 2182 | |
| Brian Paul | 6628bc9 | 2001-02-07 03:27:41 +0000 | [diff] [blame] | 2183 | init_teximage_fields(ctx, texImage, width, height, depth, border, |
| 2184 | internalFormat); |
| 2185 | |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2186 | if (ctx->Extensions.ARB_texture_compression) { |
| 2187 | ASSERT(ctx->Driver.CompressedTexImage3D); |
| 2188 | (*ctx->Driver.CompressedTexImage3D)(ctx, target, level, |
| 2189 | internalFormat, |
| 2190 | width, height, depth, |
| 2191 | border, imageSize, data, |
| 2192 | texObj, texImage); |
| 2193 | ASSERT(texImage->CompressedSize > 0); /* sanity */ |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2194 | } |
| 2195 | |
| 2196 | /* state update */ |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 2197 | texObj->Complete = GL_FALSE; |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 2198 | ctx->NewState |= _NEW_TEXTURE; |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2199 | } |
| 2200 | else if (target == GL_PROXY_TEXTURE_3D) { |
| 2201 | /* Proxy texture: check for errors and update proxy state */ |
| Brian Paul | 38d3f3d | 2000-09-07 15:38:49 +0000 | [diff] [blame] | 2202 | GLenum error = texture_error_check(ctx, target, level, internalFormat, |
| 2203 | GL_NONE, GL_NONE, 1, width, height, depth, border); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2204 | if (!error) { |
| Brian Paul | a1f1586 | 2001-02-07 16:27:41 +0000 | [diff] [blame] | 2205 | struct gl_texture_unit *texUnit; |
| 2206 | struct gl_texture_image *texImage; |
| 2207 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 2208 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| 2209 | init_teximage_fields(ctx, texImage, width, height, depth, |
| 2210 | border, internalFormat); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2211 | ASSERT(ctx->Driver.TestProxyTexImage); |
| Brian Paul | 38d3f3d | 2000-09-07 15:38:49 +0000 | [diff] [blame] | 2212 | error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, |
| 2213 | internalFormat, GL_NONE, GL_NONE, |
| 2214 | width, height, depth, border); |
| 2215 | } |
| 2216 | if (error) { |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2217 | /* if error, clear all proxy texture image parameters */ |
| Brian Paul | f378ab8 | 2001-02-06 23:35:26 +0000 | [diff] [blame] | 2218 | if (level >= 0 && level < ctx->Const.MaxTextureLevels) { |
| 2219 | clear_teximage_fields(ctx->Texture.Proxy3D->Image[level]); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2220 | } |
| 2221 | } |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2222 | } |
| 2223 | else { |
| 2224 | gl_error( ctx, GL_INVALID_ENUM, "glCompressedTexImage3DARB(target)" ); |
| 2225 | return; |
| 2226 | } |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 2227 | } |
| 2228 | |
| 2229 | |
| 2230 | void |
| 2231 | _mesa_CompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset, |
| 2232 | GLsizei width, GLenum format, |
| 2233 | GLsizei imageSize, const GLvoid *data) |
| 2234 | { |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2235 | struct gl_texture_unit *texUnit; |
| 2236 | struct gl_texture_object *texObj; |
| 2237 | struct gl_texture_image *texImage; |
| Brian Paul | a1f1586 | 2001-02-07 16:27:41 +0000 | [diff] [blame] | 2238 | GET_CURRENT_CONTEXT(ctx); |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2239 | |
| 2240 | if (subtexture_error_check(ctx, 1, target, level, xoffset, 0, 0, |
| 2241 | width, 1, 1, format, GL_NONE)) { |
| 2242 | return; /* error was detected */ |
| 2243 | } |
| 2244 | |
| 2245 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 2246 | texObj = _mesa_select_tex_object(ctx, texUnit, target); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2247 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2248 | assert(texImage); |
| 2249 | |
| 2250 | if (width == 0 || !data) |
| 2251 | return; /* no-op, not an error */ |
| 2252 | |
| 2253 | if (ctx->Driver.CompressedTexSubImage1D) { |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2254 | (*ctx->Driver.CompressedTexSubImage1D)(ctx, target, level, |
| 2255 | xoffset, width, |
| 2256 | format, imageSize, data, |
| 2257 | texObj, texImage); |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2258 | } |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 2259 | } |
| 2260 | |
| 2261 | |
| 2262 | void |
| 2263 | _mesa_CompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset, |
| 2264 | GLint yoffset, GLsizei width, GLsizei height, |
| 2265 | GLenum format, GLsizei imageSize, |
| 2266 | const GLvoid *data) |
| 2267 | { |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2268 | struct gl_texture_unit *texUnit; |
| 2269 | struct gl_texture_object *texObj; |
| 2270 | struct gl_texture_image *texImage; |
| Brian Paul | a1f1586 | 2001-02-07 16:27:41 +0000 | [diff] [blame] | 2271 | GET_CURRENT_CONTEXT(ctx); |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2272 | |
| 2273 | if (subtexture_error_check(ctx, 2, target, level, xoffset, yoffset, 0, |
| 2274 | width, height, 1, format, GL_NONE)) { |
| 2275 | return; /* error was detected */ |
| 2276 | } |
| 2277 | |
| 2278 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 2279 | texObj = _mesa_select_tex_object(ctx, texUnit, target); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2280 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2281 | assert(texImage); |
| 2282 | |
| 2283 | if (width == 0 || height == 0 || !data) |
| 2284 | return; /* no-op, not an error */ |
| 2285 | |
| 2286 | if (ctx->Driver.CompressedTexSubImage2D) { |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2287 | (*ctx->Driver.CompressedTexSubImage2D)(ctx, target, level, |
| 2288 | xoffset, yoffset, width, height, |
| 2289 | format, imageSize, data, |
| 2290 | texObj, texImage); |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2291 | } |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 2292 | } |
| 2293 | |
| 2294 | |
| 2295 | void |
| 2296 | _mesa_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset, |
| 2297 | GLint yoffset, GLint zoffset, GLsizei width, |
| 2298 | GLsizei height, GLsizei depth, GLenum format, |
| 2299 | GLsizei imageSize, const GLvoid *data) |
| 2300 | { |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2301 | struct gl_texture_unit *texUnit; |
| 2302 | struct gl_texture_object *texObj; |
| 2303 | struct gl_texture_image *texImage; |
| Brian Paul | a1f1586 | 2001-02-07 16:27:41 +0000 | [diff] [blame] | 2304 | GET_CURRENT_CONTEXT(ctx); |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2305 | |
| 2306 | if (subtexture_error_check(ctx, 3, target, level, xoffset, yoffset, zoffset, |
| 2307 | width, height, depth, format, GL_NONE)) { |
| 2308 | return; /* error was detected */ |
| 2309 | } |
| 2310 | |
| 2311 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 2312 | texObj = _mesa_select_tex_object(ctx, texUnit, target); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2313 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2314 | assert(texImage); |
| 2315 | |
| 2316 | if (width == 0 || height == 0 || depth == 0 || !data) |
| 2317 | return; /* no-op, not an error */ |
| 2318 | |
| 2319 | if (ctx->Driver.CompressedTexSubImage3D) { |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2320 | (*ctx->Driver.CompressedTexSubImage3D)(ctx, target, level, |
| 2321 | xoffset, yoffset, zoffset, |
| 2322 | width, height, depth, |
| 2323 | format, imageSize, data, |
| 2324 | texObj, texImage); |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2325 | } |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 2326 | } |
| 2327 | |
| 2328 | |
| 2329 | void |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2330 | _mesa_GetCompressedTexImageARB(GLenum target, GLint level, GLvoid *img) |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 2331 | { |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2332 | const struct gl_texture_unit *texUnit; |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2333 | const struct gl_texture_object *texObj; |
| 2334 | struct gl_texture_image *texImage; |
| Brian Paul | a1f1586 | 2001-02-07 16:27:41 +0000 | [diff] [blame] | 2335 | GET_CURRENT_CONTEXT(ctx); |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2336 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 2337 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2338 | |
| 2339 | if (level < 0 || level >= ctx->Const.MaxTextureLevels) { |
| 2340 | gl_error( ctx, GL_INVALID_VALUE, "glGetCompressedTexImageARB(level)" ); |
| 2341 | return; |
| 2342 | } |
| 2343 | |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2344 | if (is_proxy_target(target)) { |
| 2345 | gl_error(ctx, GL_INVALID_ENUM, "glGetCompressedTexImageARB(target)"); |
| 2346 | return; |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2347 | } |
| 2348 | |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2349 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 2350 | texObj = _mesa_select_tex_object(ctx, texUnit, target); |
| 2351 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| 2352 | |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2353 | if (!texImage) { |
| 2354 | /* invalid mipmap level */ |
| 2355 | gl_error(ctx, GL_INVALID_VALUE, "glGetCompressedTexImageARB(level)"); |
| 2356 | return; |
| 2357 | } |
| 2358 | |
| 2359 | if (!texImage->IsCompressed) { |
| 2360 | gl_error(ctx, GL_INVALID_OPERATION, "glGetCompressedTexImageARB"); |
| 2361 | return; |
| 2362 | } |
| 2363 | |
| 2364 | if (!img) |
| 2365 | return; |
| 2366 | |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2367 | if (ctx->Extensions.ARB_texture_compression) { |
| 2368 | ASSERT(ctx->Driver.GetCompressedTexImage); |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2369 | (*ctx->Driver.GetCompressedTexImage)(ctx, target, level, img, texObj, |
| 2370 | texImage); |
| 2371 | } |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 2372 | } |