| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame^] | 1 | /* $Id: teximage.c,v 1.76 2001/02/17 00:15:39 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 | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 736 | iformat = _mesa_base_tex_format( ctx, internalFormat ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 737 | if (iformat < 0) { |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 738 | if (!isProxy) { |
| 739 | char message[100]; |
| Brian Paul | ec15398 | 2000-12-08 18:09:33 +0000 | [diff] [blame] | 740 | sprintf(message, "glTexImage%dD(internalFormat=0x%x)", dimensions, |
| 741 | internalFormat); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 742 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 743 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 744 | return GL_TRUE; |
| 745 | } |
| 746 | |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 747 | if (!is_compressed_format(ctx, internalFormat)) { |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 748 | if (!_mesa_is_legal_format_and_type( format, type )) { |
| 749 | /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there |
| 750 | * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4. |
| 751 | */ |
| 752 | if (!isProxy) { |
| 753 | char message[100]; |
| 754 | sprintf(message, "glTexImage%dD(format or type)", dimensions); |
| 755 | gl_error(ctx, GL_INVALID_OPERATION, message); |
| 756 | } |
| 757 | return GL_TRUE; |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 758 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | /* if we get here, the parameters are OK */ |
| 762 | return GL_FALSE; |
| 763 | } |
| 764 | |
| 765 | |
| 766 | |
| 767 | /* |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 768 | * Test glTexSubImage[123]D() parameters for errors. |
| 769 | * Input: |
| 770 | * dimensions - must be 1 or 2 or 3 |
| 771 | * Return: GL_TRUE = an error was detected, GL_FALSE = no errors |
| 772 | */ |
| 773 | static GLboolean |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 774 | subtexture_error_check( GLcontext *ctx, GLuint dimensions, |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 775 | GLenum target, GLint level, |
| 776 | GLint xoffset, GLint yoffset, GLint zoffset, |
| 777 | GLint width, GLint height, GLint depth, |
| 778 | GLenum format, GLenum type ) |
| 779 | { |
| 780 | struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 781 | struct gl_texture_image *destTex; |
| 782 | |
| 783 | if (dimensions == 1) { |
| 784 | if (target != GL_TEXTURE_1D) { |
| 785 | gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage1D(target)" ); |
| 786 | return GL_TRUE; |
| 787 | } |
| 788 | } |
| 789 | else if (dimensions == 2) { |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 790 | if (ctx->Extensions.ARB_texture_cube_map) { |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 791 | if ((target < GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB || |
| 792 | target > GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) && |
| 793 | target != GL_TEXTURE_2D) { |
| 794 | gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" ); |
| 795 | return GL_TRUE; |
| 796 | } |
| 797 | } |
| 798 | else if (target != GL_TEXTURE_2D) { |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 799 | gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" ); |
| 800 | return GL_TRUE; |
| 801 | } |
| 802 | } |
| 803 | else if (dimensions == 3) { |
| 804 | if (target != GL_TEXTURE_3D) { |
| 805 | gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage3D(target)" ); |
| 806 | return GL_TRUE; |
| 807 | } |
| 808 | } |
| 809 | else { |
| 810 | gl_problem( ctx, "bad dims in texture_error_check" ); |
| 811 | return GL_TRUE; |
| 812 | } |
| 813 | |
| 814 | if (level < 0 || level >= ctx->Const.MaxTextureLevels) { |
| Brian Paul | ec15398 | 2000-12-08 18:09:33 +0000 | [diff] [blame] | 815 | char message[100]; |
| 816 | sprintf(message, "glTexSubImage2D(level=%d)", level); |
| 817 | gl_error(ctx, GL_INVALID_ENUM, message); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 818 | return GL_TRUE; |
| 819 | } |
| 820 | |
| 821 | if (width < 0) { |
| 822 | char message[100]; |
| Brian Paul | ec15398 | 2000-12-08 18:09:33 +0000 | [diff] [blame] | 823 | sprintf(message, "glTexSubImage%dD(width=%d)", dimensions, width); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 824 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 825 | return GL_TRUE; |
| 826 | } |
| 827 | if (height < 0 && dimensions > 1) { |
| 828 | char message[100]; |
| Brian Paul | ec15398 | 2000-12-08 18:09:33 +0000 | [diff] [blame] | 829 | sprintf(message, "glTexSubImage%dD(height=%d)", dimensions, height); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 830 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 831 | return GL_TRUE; |
| 832 | } |
| 833 | if (depth < 0 && dimensions > 2) { |
| 834 | char message[100]; |
| Brian Paul | ec15398 | 2000-12-08 18:09:33 +0000 | [diff] [blame] | 835 | sprintf(message, "glTexSubImage%dD(depth=%d)", dimensions, depth); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 836 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 837 | return GL_TRUE; |
| 838 | } |
| 839 | |
| Brian Paul | f2718b0 | 2001-01-23 23:35:23 +0000 | [diff] [blame] | 840 | destTex = _mesa_select_tex_image(ctx, texUnit, target, level); |
| 841 | |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 842 | if (!destTex) { |
| 843 | gl_error(ctx, GL_INVALID_OPERATION, "glTexSubImage2D"); |
| 844 | return GL_TRUE; |
| 845 | } |
| 846 | |
| 847 | if (xoffset < -((GLint)destTex->Border)) { |
| 848 | gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage1/2/3D(xoffset)"); |
| 849 | return GL_TRUE; |
| 850 | } |
| 851 | if (xoffset + width > (GLint) (destTex->Width + destTex->Border)) { |
| 852 | gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage1/2/3D(xoffset+width)"); |
| 853 | return GL_TRUE; |
| 854 | } |
| 855 | if (dimensions > 1) { |
| 856 | if (yoffset < -((GLint)destTex->Border)) { |
| 857 | gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage2/3D(yoffset)"); |
| 858 | return GL_TRUE; |
| 859 | } |
| 860 | if (yoffset + height > (GLint) (destTex->Height + destTex->Border)) { |
| 861 | gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage2/3D(yoffset+height)"); |
| 862 | return GL_TRUE; |
| 863 | } |
| 864 | } |
| 865 | if (dimensions > 2) { |
| 866 | if (zoffset < -((GLint)destTex->Border)) { |
| 867 | gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset)"); |
| 868 | return GL_TRUE; |
| 869 | } |
| 870 | if (zoffset + depth > (GLint) (destTex->Depth+destTex->Border)) { |
| 871 | gl_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset+depth)"); |
| 872 | return GL_TRUE; |
| 873 | } |
| 874 | } |
| 875 | |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 876 | if (!is_compressed_format(ctx, destTex->IntFormat)) { |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 877 | if (!_mesa_is_legal_format_and_type(format, type)) { |
| 878 | char message[100]; |
| 879 | sprintf(message, "glTexSubImage%dD(format or type)", dimensions); |
| 880 | gl_error(ctx, GL_INVALID_ENUM, message); |
| 881 | return GL_TRUE; |
| 882 | } |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | return GL_FALSE; |
| 886 | } |
| 887 | |
| 888 | |
| 889 | /* |
| 890 | * Test glCopyTexImage[12]D() parameters for errors. |
| 891 | * Input: dimensions - must be 1 or 2 or 3 |
| 892 | * Return: GL_TRUE = an error was detected, GL_FALSE = no errors |
| 893 | */ |
| 894 | static GLboolean |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 895 | copytexture_error_check( GLcontext *ctx, GLuint dimensions, |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 896 | GLenum target, GLint level, GLint internalFormat, |
| 897 | GLint width, GLint height, GLint border ) |
| 898 | { |
| 899 | GLint iformat; |
| 900 | |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 901 | if (dimensions == 1) { |
| 902 | if (target != GL_TEXTURE_1D) { |
| 903 | gl_error( ctx, GL_INVALID_ENUM, "glCopyTexImage1D(target)" ); |
| 904 | return GL_TRUE; |
| 905 | } |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 906 | } |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 907 | else if (dimensions == 2) { |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 908 | if (ctx->Extensions.ARB_texture_cube_map) { |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 909 | if ((target < GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB || |
| 910 | target > GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) && |
| 911 | target != GL_TEXTURE_2D) { |
| 912 | gl_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" ); |
| 913 | return GL_TRUE; |
| 914 | } |
| 915 | } |
| 916 | else if (target != GL_TEXTURE_2D) { |
| 917 | gl_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" ); |
| 918 | return GL_TRUE; |
| 919 | } |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | /* Border */ |
| 923 | if (border!=0 && border!=1) { |
| 924 | char message[100]; |
| 925 | sprintf(message, "glCopyTexImage%dD(border)", dimensions); |
| 926 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 927 | return GL_TRUE; |
| 928 | } |
| 929 | |
| 930 | /* Width */ |
| 931 | if (width < 2 * border || width > 2 + ctx->Const.MaxTextureSize |
| 932 | || logbase2( width - 2 * border ) < 0) { |
| 933 | char message[100]; |
| Brian Paul | ec15398 | 2000-12-08 18:09:33 +0000 | [diff] [blame] | 934 | sprintf(message, "glCopyTexImage%dD(width=%d)", dimensions, width); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 935 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 936 | return GL_TRUE; |
| 937 | } |
| 938 | |
| 939 | /* Height */ |
| 940 | if (dimensions >= 2) { |
| 941 | if (height < 2 * border || height > 2 + ctx->Const.MaxTextureSize |
| 942 | || logbase2( height - 2 * border ) < 0) { |
| 943 | char message[100]; |
| Brian Paul | ec15398 | 2000-12-08 18:09:33 +0000 | [diff] [blame] | 944 | sprintf(message, "glCopyTexImage%dD(height=%d)", dimensions, height); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 945 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 946 | return GL_TRUE; |
| 947 | } |
| 948 | } |
| 949 | |
| Brian Paul | ad81770 | 2000-05-30 00:27:24 +0000 | [diff] [blame] | 950 | /* For cube map, width must equal height */ |
| 951 | if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && |
| 952 | target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { |
| 953 | if (width != height) { |
| 954 | gl_error(ctx, GL_INVALID_VALUE, "glCopyTexImage2D(width != height)"); |
| 955 | return GL_TRUE; |
| 956 | } |
| 957 | } |
| 958 | |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 959 | /* Level */ |
| 960 | if (level<0 || level>=ctx->Const.MaxTextureLevels) { |
| 961 | char message[100]; |
| Brian Paul | ec15398 | 2000-12-08 18:09:33 +0000 | [diff] [blame] | 962 | sprintf(message, "glCopyTexImage%dD(level=%d)", dimensions, level); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 963 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 964 | return GL_TRUE; |
| 965 | } |
| 966 | |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 967 | iformat = _mesa_base_tex_format( ctx, internalFormat ); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 968 | if (iformat < 0) { |
| 969 | char message[100]; |
| 970 | sprintf(message, "glCopyTexImage%dD(internalFormat)", dimensions); |
| 971 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 972 | return GL_TRUE; |
| 973 | } |
| 974 | |
| 975 | /* if we get here, the parameters are OK */ |
| 976 | return GL_FALSE; |
| 977 | } |
| 978 | |
| 979 | |
| 980 | static GLboolean |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 981 | copytexsubimage_error_check( GLcontext *ctx, GLuint dimensions, |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 982 | GLenum target, GLint level, |
| 983 | GLint xoffset, GLint yoffset, GLint zoffset, |
| Brian Paul | 5b37c32 | 1999-11-05 06:43:10 +0000 | [diff] [blame] | 984 | GLsizei width, GLsizei height ) |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 985 | { |
| 986 | struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 987 | struct gl_texture_image *teximage; |
| 988 | |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 989 | if (dimensions == 1) { |
| 990 | if (target != GL_TEXTURE_1D) { |
| 991 | gl_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage1D(target)" ); |
| 992 | return GL_TRUE; |
| 993 | } |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 994 | } |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 995 | else if (dimensions == 2) { |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 996 | if (ctx->Extensions.ARB_texture_cube_map) { |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 997 | if ((target < GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB || |
| 998 | target > GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) && |
| 999 | target != GL_TEXTURE_2D) { |
| 1000 | gl_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" ); |
| 1001 | return GL_TRUE; |
| 1002 | } |
| 1003 | } |
| 1004 | else if (target != GL_TEXTURE_2D) { |
| 1005 | gl_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" ); |
| 1006 | return GL_TRUE; |
| 1007 | } |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1008 | } |
| Brian Paul | fc4b443 | 2000-05-23 15:17:12 +0000 | [diff] [blame] | 1009 | else if (dimensions == 3) { |
| 1010 | if (target != GL_TEXTURE_3D) { |
| 1011 | gl_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage3D(target)" ); |
| 1012 | return GL_TRUE; |
| 1013 | } |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | if (level < 0 || level >= ctx->Const.MaxTextureLevels) { |
| 1017 | char message[100]; |
| Brian Paul | ec15398 | 2000-12-08 18:09:33 +0000 | [diff] [blame] | 1018 | sprintf(message, "glCopyTexSubImage%dD(level=%d)", dimensions, level); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1019 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1020 | return GL_TRUE; |
| 1021 | } |
| 1022 | |
| 1023 | if (width < 0) { |
| 1024 | char message[100]; |
| Brian Paul | ec15398 | 2000-12-08 18:09:33 +0000 | [diff] [blame] | 1025 | sprintf(message, "glCopyTexSubImage%dD(width=%d)", dimensions, width); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1026 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1027 | return GL_TRUE; |
| 1028 | } |
| 1029 | if (dimensions > 1 && height < 0) { |
| 1030 | char message[100]; |
| Brian Paul | ec15398 | 2000-12-08 18:09:33 +0000 | [diff] [blame] | 1031 | sprintf(message, "glCopyTexSubImage%dD(height=%d)", dimensions, height); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1032 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1033 | return GL_TRUE; |
| 1034 | } |
| 1035 | |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 1036 | teximage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1037 | if (!teximage) { |
| 1038 | char message[100]; |
| 1039 | sprintf(message, "glCopyTexSubImage%dD(undefined texture)", dimensions); |
| 1040 | gl_error(ctx, GL_INVALID_OPERATION, message); |
| 1041 | return GL_TRUE; |
| 1042 | } |
| 1043 | |
| 1044 | if (xoffset < -((GLint)teximage->Border)) { |
| 1045 | char message[100]; |
| Brian Paul | ec15398 | 2000-12-08 18:09:33 +0000 | [diff] [blame] | 1046 | sprintf(message, "glCopyTexSubImage%dD(xoffset=%d)", dimensions, xoffset); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1047 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1048 | return GL_TRUE; |
| 1049 | } |
| 1050 | if (xoffset+width > (GLint) (teximage->Width+teximage->Border)) { |
| 1051 | char message[100]; |
| 1052 | sprintf(message, "glCopyTexSubImage%dD(xoffset+width)", dimensions); |
| 1053 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1054 | return GL_TRUE; |
| 1055 | } |
| 1056 | if (dimensions > 1) { |
| 1057 | if (yoffset < -((GLint)teximage->Border)) { |
| 1058 | char message[100]; |
| Brian Paul | ec15398 | 2000-12-08 18:09:33 +0000 | [diff] [blame] | 1059 | sprintf(message, "glCopyTexSubImage%dD(yoffset=%d)", dimensions, yoffset); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1060 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1061 | return GL_TRUE; |
| 1062 | } |
| 1063 | /* NOTE: we're adding the border here, not subtracting! */ |
| 1064 | if (yoffset+height > (GLint) (teximage->Height+teximage->Border)) { |
| 1065 | char message[100]; |
| 1066 | sprintf(message, "glCopyTexSubImage%dD(yoffset+height)", dimensions); |
| 1067 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1068 | return GL_TRUE; |
| 1069 | } |
| 1070 | } |
| 1071 | |
| 1072 | if (dimensions > 2) { |
| 1073 | if (zoffset < -((GLint)teximage->Border)) { |
| 1074 | char message[100]; |
| 1075 | sprintf(message, "glCopyTexSubImage%dD(zoffset)", dimensions); |
| 1076 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1077 | return GL_TRUE; |
| 1078 | } |
| 1079 | if (zoffset > (GLint) (teximage->Depth+teximage->Border)) { |
| 1080 | char message[100]; |
| 1081 | sprintf(message, "glCopyTexSubImage%dD(zoffset+depth)", dimensions); |
| 1082 | gl_error(ctx, GL_INVALID_VALUE, message); |
| 1083 | return GL_TRUE; |
| 1084 | } |
| 1085 | } |
| 1086 | |
| 1087 | /* if we get here, the parameters are OK */ |
| 1088 | return GL_FALSE; |
| 1089 | } |
| 1090 | |
| 1091 | |
| 1092 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1093 | void |
| 1094 | _mesa_GetTexImage( GLenum target, GLint level, GLenum format, |
| 1095 | GLenum type, GLvoid *pixels ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1096 | { |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1097 | GET_CURRENT_CONTEXT(ctx); |
| Brian Paul | 01e5475 | 2000-09-05 15:40:34 +0000 | [diff] [blame] | 1098 | const struct gl_texture_unit *texUnit; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1099 | const struct gl_texture_object *texObj; |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1100 | struct gl_texture_image *texImage; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1101 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1102 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1103 | |
| 1104 | if (level < 0 || level >= ctx->Const.MaxTextureLevels) { |
| 1105 | gl_error( ctx, GL_INVALID_VALUE, "glGetTexImage(level)" ); |
| 1106 | return; |
| 1107 | } |
| 1108 | |
| Brian Paul | b7d076f | 2000-03-21 01:03:40 +0000 | [diff] [blame] | 1109 | if (_mesa_sizeof_type(type) <= 0) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1110 | gl_error( ctx, GL_INVALID_ENUM, "glGetTexImage(type)" ); |
| 1111 | return; |
| 1112 | } |
| 1113 | |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame^] | 1114 | if (_mesa_components_in_format(format) <= 0 || |
| 1115 | format == GL_STENCIL_INDEX) { |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1116 | gl_error( ctx, GL_INVALID_ENUM, "glGetTexImage(format)" ); |
| 1117 | return; |
| 1118 | } |
| 1119 | |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame^] | 1120 | if (!ctx->Extensions.EXT_paletted_texture && is_index_format(format)) { |
| 1121 | gl_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)"); |
| 1122 | } |
| 1123 | |
| 1124 | if (!ctx->Extensions.SGIX_depth_texture && format == GL_DEPTH_COMPONENT) { |
| 1125 | gl_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)"); |
| 1126 | } |
| 1127 | |
| 1128 | /* XXX what if format/type doesn't match texture format/type? */ |
| 1129 | |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1130 | if (!pixels) |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1131 | return; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1132 | |
| Brian Paul | 01e5475 | 2000-09-05 15:40:34 +0000 | [diff] [blame] | 1133 | texUnit = &(ctx->Texture.Unit[ctx->Texture.CurrentUnit]); |
| 1134 | texObj = _mesa_select_tex_object(ctx, texUnit, target); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1135 | if (!texObj || is_proxy_target(target)) { |
| Brian Paul | 01e5475 | 2000-09-05 15:40:34 +0000 | [diff] [blame] | 1136 | gl_error(ctx, GL_INVALID_ENUM, "glGetTexImage(target)"); |
| 1137 | return; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1138 | } |
| 1139 | |
| Brian Paul | 8e3366f | 2000-11-10 15:32:07 +0000 | [diff] [blame] | 1140 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1141 | if (!texImage) { |
| Brian Paul | 7298e71 | 2000-11-07 16:40:37 +0000 | [diff] [blame] | 1142 | /* invalid mipmap level, not an error */ |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1143 | return; |
| 1144 | } |
| 1145 | |
| 1146 | if (!texImage->Data) { |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1147 | /* no image data, not an error */ |
| 1148 | return; |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1149 | } |
| 1150 | |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1151 | if (ctx->NewState & _NEW_PIXEL) |
| 1152 | gl_update_state(ctx); |
| 1153 | |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame^] | 1154 | if (is_color_format(format) && |
| 1155 | ctx->_ImageTransferState & IMAGE_CONVOLUTION_BIT) { |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1156 | /* convert texture image to GL_RGBA, GL_FLOAT */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1157 | GLint width = texImage->Width; |
| 1158 | GLint height = texImage->Height; |
| Brian Paul | f96ce6a | 2000-09-06 15:15:43 +0000 | [diff] [blame] | 1159 | GLint depth = texImage->Depth; |
| 1160 | GLint img, row; |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1161 | GLfloat *tmpImage, *convImage; |
| 1162 | tmpImage = (GLfloat *) MALLOC(width * height * 4 * sizeof(GLfloat)); |
| 1163 | if (!tmpImage) { |
| 1164 | gl_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage"); |
| 1165 | return; |
| 1166 | } |
| 1167 | convImage = (GLfloat *) MALLOC(width * height * 4 * sizeof(GLfloat)); |
| 1168 | if (!convImage) { |
| 1169 | FREE(tmpImage); |
| 1170 | gl_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage"); |
| 1171 | return; |
| 1172 | } |
| 1173 | |
| 1174 | for (img = 0; img < depth; img++) { |
| 1175 | GLint convWidth, convHeight; |
| 1176 | |
| 1177 | /* convert texture data to GLfloat/GL_RGBA */ |
| 1178 | for (row = 0; row < height; row++) { |
| 1179 | GLchan texels[1 << MAX_TEXTURE_LEVELS][4]; |
| 1180 | GLint col; |
| 1181 | GLfloat *dst = tmpImage + row * width * 4; |
| 1182 | for (col = 0; col < width; col++) { |
| 1183 | (*texImage->FetchTexel)(ctx, texObj, texImage, col, row, img, |
| 1184 | texels[col]); |
| 1185 | } |
| 1186 | _mesa_unpack_float_color_span(ctx, width, GL_RGBA, dst, |
| 1187 | GL_RGBA, CHAN_TYPE, texels, |
| 1188 | &_mesa_native_packing, |
| 1189 | ctx->_ImageTransferState & IMAGE_PRE_CONVOLUTION_BITS, |
| 1190 | GL_FALSE); |
| 1191 | } |
| 1192 | |
| 1193 | convWidth = width; |
| 1194 | convHeight = height; |
| 1195 | |
| 1196 | /* convolve */ |
| 1197 | if (target == GL_TEXTURE_1D) { |
| 1198 | if (ctx->Pixel.Convolution1DEnabled) { |
| 1199 | _mesa_convolve_1d_image(ctx, &convWidth, tmpImage, convImage); |
| 1200 | } |
| 1201 | } |
| 1202 | else { |
| 1203 | if (ctx->Pixel.Convolution2DEnabled) { |
| 1204 | _mesa_convolve_2d_image(ctx, &convWidth, &convHeight, |
| 1205 | tmpImage, convImage); |
| 1206 | } |
| 1207 | else if (ctx->Pixel.Separable2DEnabled) { |
| 1208 | _mesa_convolve_sep_image(ctx, &convWidth, &convHeight, |
| 1209 | tmpImage, convImage); |
| 1210 | } |
| 1211 | } |
| 1212 | |
| 1213 | /* pack convolved image */ |
| 1214 | for (row = 0; row < convHeight; row++) { |
| 1215 | const GLfloat *src = convImage + row * convWidth * 4; |
| 1216 | GLvoid *dest = _mesa_image_address(&ctx->Pack, pixels, |
| 1217 | convWidth, convHeight, |
| 1218 | format, type, img, row, 0); |
| 1219 | _mesa_pack_float_rgba_span(ctx, convWidth, |
| 1220 | (const GLfloat(*)[4]) src, |
| 1221 | format, type, dest, &ctx->Pack, |
| 1222 | ctx->_ImageTransferState & IMAGE_POST_CONVOLUTION_BITS); |
| 1223 | } |
| 1224 | } |
| 1225 | |
| 1226 | FREE(tmpImage); |
| 1227 | FREE(convImage); |
| 1228 | } |
| 1229 | else { |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame^] | 1230 | /* no convolution, or non-rgba image */ |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1231 | GLint width = texImage->Width; |
| 1232 | GLint height = texImage->Height; |
| 1233 | GLint depth = texImage->Depth; |
| 1234 | GLint img, row; |
| 1235 | for (img = 0; img < depth; img++) { |
| 1236 | for (row = 0; row < height; row++) { |
| 1237 | /* compute destination address in client memory */ |
| 1238 | GLvoid *dest = _mesa_image_address( &ctx->Unpack, pixels, |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame^] | 1239 | width, height, format, type, |
| 1240 | img, row, 0); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1241 | assert(dest); |
| 1242 | |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame^] | 1243 | if (format == GL_COLOR_INDEX) { |
| 1244 | GLuint indexRow[MAX_WIDTH]; |
| 1245 | GLint col; |
| 1246 | for (col = 0; col < width; col++) { |
| 1247 | GLchan rgba[1]; |
| 1248 | /* XXX this won't really work yet */ |
| 1249 | /*need (*texImage->FetchRawTexel)() */ |
| 1250 | (*texImage->FetchTexel)(ctx, texObj, texImage, |
| 1251 | col, row, img, rgba); |
| 1252 | indexRow[col] = rgba[0]; |
| 1253 | } |
| 1254 | _mesa_pack_index_span(ctx, width, type, dest, |
| 1255 | indexRow, &ctx->Pack, |
| 1256 | ctx->_ImageTransferState); |
| 1257 | } |
| 1258 | else if (format == GL_DEPTH_COMPONENT) { |
| 1259 | /* XXX finish this */ |
| 1260 | GLfloat depthRow[MAX_WIDTH]; |
| 1261 | GLint col; |
| 1262 | for (col = 0; col < width; col++) { |
| 1263 | GLchan rgba[1]; |
| 1264 | /* XXX this won't really work yet */ |
| 1265 | /*need (*texImage->FetchRawTexel)() */ |
| 1266 | (*texImage->FetchTexel)(ctx, texObj, texImage, |
| 1267 | col, row, img, rgba); |
| 1268 | depthRow[col] = (GLfloat) rgba[0]; |
| 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++) { |
| 1278 | (*texImage->FetchTexel)(ctx, texObj, texImage, |
| Brian Paul | 9a0b12a | 2001-02-07 18:59:45 +0000 | [diff] [blame] | 1279 | col, row, img, rgba[col]); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1280 | } |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1281 | _mesa_pack_rgba_span( ctx, width, (const GLchan (*)[4])rgba, |
| 1282 | format, type, dest, &ctx->Pack, |
| 1283 | ctx->_ImageTransferState ); |
| 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 | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame^] | 1640 | /* XXX should test internal format */ |
| 1641 | if (is_color_format(format)) { |
| 1642 | _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); |
| 1643 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1644 | |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1645 | if (subtexture_error_check(ctx, 1, target, level, xoffset, 0, 0, |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 1646 | postConvWidth, 1, 1, format, type)) { |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1647 | return; /* error was detected */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1648 | } |
| 1649 | |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1650 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1651 | texObj = _mesa_select_tex_object(ctx, texUnit, target); |
| 1652 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1653 | assert(texImage); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1654 | |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1655 | if (width == 0 || !pixels) |
| 1656 | return; /* no-op, not an error */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1657 | |
| Brian Paul | 9499e01 | 2000-10-30 16:32:42 +0000 | [diff] [blame] | 1658 | if (ctx->NewState & _NEW_PIXEL) |
| 1659 | gl_update_state(ctx); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +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 | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame^] | 1681 | /* XXX should test internal format */ |
| 1682 | if (is_color_format(format)) { |
| 1683 | _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, |
| 1684 | &postConvHeight); |
| 1685 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1686 | |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1687 | if (subtexture_error_check(ctx, 2, target, level, xoffset, yoffset, 0, |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 1688 | postConvWidth, postConvHeight, 1, format, type)) { |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1689 | return; /* error was detected */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1690 | } |
| 1691 | |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1692 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| Brian Paul | 35d5301 | 2000-05-23 17:14:49 +0000 | [diff] [blame] | 1693 | texObj = _mesa_select_tex_object(ctx, texUnit, target); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1694 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1695 | assert(texImage); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1696 | |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1697 | if (width == 0 || height == 0 || !pixels) |
| 1698 | return; /* no-op, not an error */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1699 | |
| Brian Paul | 9499e01 | 2000-10-30 16:32:42 +0000 | [diff] [blame] | 1700 | if (ctx->NewState & _NEW_PIXEL) |
| 1701 | gl_update_state(ctx); |
| Brian Paul | fa4525e | 2000-08-21 14:22:24 +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 | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1723 | if (subtexture_error_check(ctx, 3, target, level, xoffset, yoffset, zoffset, |
| 1724 | width, height, depth, format, type)) { |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1725 | return; /* error was detected */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1726 | } |
| 1727 | |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1728 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1729 | texObj = _mesa_select_tex_object(ctx, texUnit, target); |
| 1730 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 1731 | assert(texImage); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1732 | |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1733 | if (width == 0 || height == 0 || height == 0 || !pixels) |
| 1734 | return; /* no-op, not an error */ |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1735 | |
| Brian Paul | 9499e01 | 2000-10-30 16:32:42 +0000 | [diff] [blame] | 1736 | if (ctx->NewState & _NEW_PIXEL) |
| 1737 | gl_update_state(ctx); |
| Brian Paul | fa4525e | 2000-08-21 14:22:24 +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 | |
| 1749 | /* |
| 1750 | * Read an RGBA image from the frame buffer. |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 1751 | * This is used by glCopyTex[Sub]Image[12]D(). |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1752 | * Input: ctx - the context |
| 1753 | * x, y - lower left corner |
| 1754 | * width, height - size of region to read |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 1755 | * Return: pointer to block of GL_RGBA, GLchan data. |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1756 | */ |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 1757 | static GLchan * |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1758 | read_color_image( GLcontext *ctx, GLint x, GLint y, |
| 1759 | GLsizei width, GLsizei height ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1760 | { |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1761 | GLint stride, i; |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 1762 | GLchan *image, *dst; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1763 | |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 1764 | image = (GLchan *) MALLOC(width * height * 4 * sizeof(GLchan)); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1765 | if (!image) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1766 | return NULL; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1767 | |
| 1768 | /* Select buffer to read from */ |
| Brian Paul | cea0e8e | 1999-11-25 17:36:48 +0000 | [diff] [blame] | 1769 | (*ctx->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer, |
| 1770 | ctx->Pixel.DriverReadBuffer ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1771 | |
| Brian Paul | c34cea7 | 2000-11-21 23:25:40 +0000 | [diff] [blame] | 1772 | RENDER_START(ctx); |
| 1773 | |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1774 | dst = image; |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 1775 | stride = width * 4; |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1776 | for (i = 0; i < height; i++) { |
| Brian Paul | 3f02f90 | 1999-11-24 18:48:30 +0000 | [diff] [blame] | 1777 | gl_read_rgba_span( ctx, ctx->ReadBuffer, width, x, y + i, |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 1778 | (GLchan (*)[4]) dst ); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1779 | dst += stride; |
| 1780 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1781 | |
| Brian Paul | c34cea7 | 2000-11-21 23:25:40 +0000 | [diff] [blame] | 1782 | RENDER_FINISH(ctx); |
| 1783 | |
| Brian Paul | cea0e8e | 1999-11-25 17:36:48 +0000 | [diff] [blame] | 1784 | /* Read from draw buffer (the default) */ |
| 1785 | (*ctx->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer, |
| 1786 | ctx->Color.DriverDrawBuffer ); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1787 | |
| 1788 | return image; |
| 1789 | } |
| 1790 | |
| 1791 | |
| 1792 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1793 | void |
| 1794 | _mesa_CopyTexImage1D( GLenum target, GLint level, |
| 1795 | GLenum internalFormat, |
| 1796 | GLint x, GLint y, |
| 1797 | GLsizei width, GLint border ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1798 | { |
| Brian Paul | ab6e78f | 2000-12-09 21:30:43 +0000 | [diff] [blame] | 1799 | GLsizei postConvWidth = width; |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1800 | GET_CURRENT_CONTEXT(ctx); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1801 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1802 | |
| Brian Paul | 9499e01 | 2000-10-30 16:32:42 +0000 | [diff] [blame] | 1803 | if (ctx->NewState & _NEW_PIXEL) |
| 1804 | gl_update_state(ctx); |
| Brian Paul | fa4525e | 2000-08-21 14:22:24 +0000 | [diff] [blame] | 1805 | |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame^] | 1806 | if (is_color_format(internalFormat)) { |
| 1807 | _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); |
| 1808 | } |
| Brian Paul | ab6e78f | 2000-12-09 21:30:43 +0000 | [diff] [blame] | 1809 | |
| 1810 | if (copytexture_error_check(ctx, 1, target, level, internalFormat, |
| 1811 | postConvWidth, 1, border)) |
| 1812 | return; |
| 1813 | |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 1814 | if (ctx->_ImageTransferState || !ctx->Driver.CopyTexImage1D |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1815 | || !(*ctx->Driver.CopyTexImage1D)(ctx, target, level, |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 1816 | internalFormat, x, y, width, border)) { |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 1817 | struct gl_pixelstore_attrib unpackSave; |
| 1818 | |
| 1819 | /* get image from framebuffer */ |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 1820 | GLchan *image = read_color_image( ctx, x, y, width, 1 ); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1821 | if (!image) { |
| 1822 | gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexImage1D" ); |
| 1823 | return; |
| 1824 | } |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 1825 | |
| 1826 | /* call glTexImage1D to redefine the texture */ |
| 1827 | unpackSave = ctx->Unpack; |
| 1828 | ctx->Unpack = _mesa_native_packing; |
| Brian Paul | 3ab6bbe | 2000-02-12 17:26:15 +0000 | [diff] [blame] | 1829 | (*ctx->Exec->TexImage1D)( target, level, internalFormat, width, |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1830 | border, GL_RGBA, GL_UNSIGNED_BYTE, image ); |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 1831 | ctx->Unpack = unpackSave; |
| 1832 | |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1833 | FREE(image); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1834 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1835 | } |
| 1836 | |
| 1837 | |
| 1838 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1839 | void |
| 1840 | _mesa_CopyTexImage2D( GLenum target, GLint level, GLenum internalFormat, |
| 1841 | GLint x, GLint y, GLsizei width, GLsizei height, |
| 1842 | GLint border ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1843 | { |
| Brian Paul | ab6e78f | 2000-12-09 21:30:43 +0000 | [diff] [blame] | 1844 | GLsizei postConvWidth = width, postConvHeight = height; |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1845 | GET_CURRENT_CONTEXT(ctx); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1846 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1847 | |
| Brian Paul | 9499e01 | 2000-10-30 16:32:42 +0000 | [diff] [blame] | 1848 | if (ctx->NewState & _NEW_PIXEL) |
| 1849 | gl_update_state(ctx); |
| Brian Paul | fa4525e | 2000-08-21 14:22:24 +0000 | [diff] [blame] | 1850 | |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame^] | 1851 | if (is_color_format(internalFormat)) { |
| 1852 | _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, |
| 1853 | &postConvHeight); |
| 1854 | } |
| Brian Paul | ab6e78f | 2000-12-09 21:30:43 +0000 | [diff] [blame] | 1855 | |
| 1856 | if (copytexture_error_check(ctx, 2, target, level, internalFormat, |
| 1857 | postConvWidth, postConvHeight, border)) |
| 1858 | return; |
| 1859 | |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1860 | if (ctx->_ImageTransferState || !ctx->Driver.CopyTexImage2D |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1861 | || !(*ctx->Driver.CopyTexImage2D)(ctx, target, level, |
| Brian Paul | a805bb9 | 2000-09-02 17:52:21 +0000 | [diff] [blame] | 1862 | internalFormat, x, y, width, height, border)) { |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 1863 | struct gl_pixelstore_attrib unpackSave; |
| 1864 | |
| 1865 | /* get image from framebuffer */ |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 1866 | GLchan *image = read_color_image( ctx, x, y, width, height ); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1867 | if (!image) { |
| 1868 | gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexImage2D" ); |
| 1869 | return; |
| 1870 | } |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 1871 | |
| 1872 | /* call glTexImage2D to redefine the texture */ |
| 1873 | unpackSave = ctx->Unpack; |
| 1874 | ctx->Unpack = _mesa_native_packing; |
| Brian Paul | 3ab6bbe | 2000-02-12 17:26:15 +0000 | [diff] [blame] | 1875 | (ctx->Exec->TexImage2D)( target, level, internalFormat, width, |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1876 | height, border, GL_RGBA, GL_UNSIGNED_BYTE, image ); |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 1877 | ctx->Unpack = unpackSave; |
| 1878 | |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1879 | FREE(image); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1880 | } |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1881 | } |
| 1882 | |
| 1883 | |
| 1884 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1885 | void |
| 1886 | _mesa_CopyTexSubImage1D( GLenum target, GLint level, |
| 1887 | GLint xoffset, GLint x, GLint y, GLsizei width ) |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1888 | { |
| Brian Paul | ab6e78f | 2000-12-09 21:30:43 +0000 | [diff] [blame] | 1889 | GLsizei postConvWidth = width; |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1890 | GET_CURRENT_CONTEXT(ctx); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1891 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1892 | |
| Brian Paul | 9499e01 | 2000-10-30 16:32:42 +0000 | [diff] [blame] | 1893 | if (ctx->NewState & _NEW_PIXEL) |
| 1894 | gl_update_state(ctx); |
| Brian Paul | fa4525e | 2000-08-21 14:22:24 +0000 | [diff] [blame] | 1895 | |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame^] | 1896 | /* XXX should test internal format */ |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 1897 | _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL); |
| Brian Paul | ab6e78f | 2000-12-09 21:30:43 +0000 | [diff] [blame] | 1898 | |
| 1899 | if (copytexsubimage_error_check(ctx, 1, target, level, |
| 1900 | xoffset, 0, 0, postConvWidth, 1)) |
| 1901 | return; |
| 1902 | |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1903 | if (ctx->_ImageTransferState || !ctx->Driver.CopyTexSubImage1D |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1904 | || !(*ctx->Driver.CopyTexSubImage1D)(ctx, target, level, |
| 1905 | xoffset, x, y, width)) { |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1906 | struct gl_texture_unit *texUnit; |
| 1907 | struct gl_texture_image *teximage; |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 1908 | struct gl_pixelstore_attrib unpackSave; |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 1909 | GLchan *image; |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 1910 | |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1911 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 1912 | teximage = texUnit->Current1D->Image[level]; |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1913 | assert(teximage); |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 1914 | |
| 1915 | /* get image from frame buffer */ |
| 1916 | image = read_color_image(ctx, x, y, width, 1); |
| 1917 | if (!image) { |
| Brian Paul | ab6e78f | 2000-12-09 21:30:43 +0000 | [diff] [blame] | 1918 | gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexSubImage1D" ); |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 1919 | return; |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1920 | } |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 1921 | |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 1922 | /* now call glTexSubImage1D to do the real work */ |
| 1923 | unpackSave = ctx->Unpack; |
| 1924 | ctx->Unpack = _mesa_native_packing; |
| 1925 | _mesa_TexSubImage1D(target, level, xoffset, width, |
| 1926 | GL_RGBA, GL_UNSIGNED_BYTE, image); |
| 1927 | ctx->Unpack = unpackSave; |
| 1928 | |
| 1929 | FREE(image); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 1930 | } |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1931 | } |
| 1932 | |
| 1933 | |
| 1934 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1935 | void |
| 1936 | _mesa_CopyTexSubImage2D( GLenum target, GLint level, |
| 1937 | GLint xoffset, GLint yoffset, |
| 1938 | GLint x, GLint y, GLsizei width, GLsizei height ) |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1939 | { |
| Brian Paul | ab6e78f | 2000-12-09 21:30:43 +0000 | [diff] [blame] | 1940 | GLsizei postConvWidth = width, postConvHeight = height; |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1941 | GET_CURRENT_CONTEXT(ctx); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1942 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1943 | |
| Brian Paul | 9499e01 | 2000-10-30 16:32:42 +0000 | [diff] [blame] | 1944 | if (ctx->NewState & _NEW_PIXEL) |
| 1945 | gl_update_state(ctx); |
| Brian Paul | fa4525e | 2000-08-21 14:22:24 +0000 | [diff] [blame] | 1946 | |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame^] | 1947 | /* XXX should test internal format */ |
| 1948 | _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, &postConvHeight); |
| Brian Paul | ab6e78f | 2000-12-09 21:30:43 +0000 | [diff] [blame] | 1949 | |
| 1950 | if (copytexsubimage_error_check(ctx, 2, target, level, xoffset, yoffset, 0, |
| 1951 | postConvWidth, postConvHeight)) |
| 1952 | return; |
| 1953 | |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 1954 | if (ctx->_ImageTransferState || !ctx->Driver.CopyTexSubImage2D |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 1955 | || !(*ctx->Driver.CopyTexSubImage2D)(ctx, target, level, |
| 1956 | xoffset, yoffset, x, y, width, height )) { |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1957 | struct gl_texture_unit *texUnit; |
| 1958 | struct gl_texture_image *teximage; |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 1959 | struct gl_pixelstore_attrib unpackSave; |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 1960 | GLchan *image; |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 1961 | |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1962 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 1963 | teximage = texUnit->Current2D->Image[level]; |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1964 | assert(teximage); |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 1965 | |
| 1966 | /* get image from frame buffer */ |
| 1967 | image = read_color_image(ctx, x, y, width, height); |
| 1968 | if (!image) { |
| 1969 | gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexSubImage2D" ); |
| 1970 | return; |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1971 | } |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 1972 | |
| 1973 | /* now call glTexSubImage2D to do the real work */ |
| 1974 | unpackSave = ctx->Unpack; |
| 1975 | ctx->Unpack = _mesa_native_packing; |
| 1976 | _mesa_TexSubImage2D(target, level, xoffset, yoffset, width, height, |
| 1977 | GL_RGBA, GL_UNSIGNED_BYTE, image); |
| 1978 | ctx->Unpack = unpackSave; |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 1979 | |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 1980 | FREE(image); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1981 | } |
| 1982 | } |
| 1983 | |
| 1984 | |
| 1985 | |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1986 | void |
| 1987 | _mesa_CopyTexSubImage3D( GLenum target, GLint level, |
| 1988 | GLint xoffset, GLint yoffset, GLint zoffset, |
| 1989 | GLint x, GLint y, GLsizei width, GLsizei height ) |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1990 | { |
| Brian Paul | ab6e78f | 2000-12-09 21:30:43 +0000 | [diff] [blame] | 1991 | GLsizei postConvWidth = width, postConvHeight = height; |
| Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1992 | GET_CURRENT_CONTEXT(ctx); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1993 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 1994 | |
| Brian Paul | 9499e01 | 2000-10-30 16:32:42 +0000 | [diff] [blame] | 1995 | if (ctx->NewState & _NEW_PIXEL) |
| 1996 | gl_update_state(ctx); |
| Brian Paul | fa4525e | 2000-08-21 14:22:24 +0000 | [diff] [blame] | 1997 | |
| Brian Paul | f7e1dfe | 2001-02-17 00:15:39 +0000 | [diff] [blame^] | 1998 | /* XXX should test internal format */ |
| 1999 | _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, &postConvHeight); |
| Brian Paul | ab6e78f | 2000-12-09 21:30:43 +0000 | [diff] [blame] | 2000 | |
| 2001 | if (copytexsubimage_error_check(ctx, 3, target, level, xoffset, yoffset, |
| 2002 | zoffset, postConvWidth, postConvHeight)) |
| 2003 | return; |
| 2004 | |
| Keith Whitwell | 14940c4 | 2000-11-05 18:40:57 +0000 | [diff] [blame] | 2005 | if (ctx->_ImageTransferState || !ctx->Driver.CopyTexSubImage3D |
| Brian Paul | f7b5707 | 2000-03-20 14:37:52 +0000 | [diff] [blame] | 2006 | || !(*ctx->Driver.CopyTexSubImage3D)(ctx, target, level, |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 2007 | xoffset, yoffset, zoffset, x, y, width, height )) { |
| 2008 | struct gl_texture_unit *texUnit; |
| 2009 | struct gl_texture_image *teximage; |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 2010 | struct gl_pixelstore_attrib unpackSave; |
| Brian Paul | 699bc7b | 2000-10-29 18:12:14 +0000 | [diff] [blame] | 2011 | GLchan *image; |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 2012 | |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 2013 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 2014 | teximage = texUnit->Current3D->Image[level]; |
| Brian Paul | 0293878 | 2000-03-22 17:38:11 +0000 | [diff] [blame] | 2015 | assert(teximage); |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 2016 | |
| 2017 | /* get image from frame buffer */ |
| 2018 | image = read_color_image(ctx, x, y, width, height); |
| 2019 | if (!image) { |
| 2020 | gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexSubImage2D" ); |
| 2021 | return; |
| Brian Paul | c3f0a51 | 1999-11-03 17:27:05 +0000 | [diff] [blame] | 2022 | } |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 2023 | |
| 2024 | /* now call glTexSubImage2D to do the real work */ |
| 2025 | unpackSave = ctx->Unpack; |
| 2026 | ctx->Unpack = _mesa_native_packing; |
| 2027 | _mesa_TexSubImage3D(target, level, xoffset, yoffset, zoffset, |
| 2028 | width, height, 1, GL_RGBA, GL_UNSIGNED_BYTE, image); |
| 2029 | ctx->Unpack = unpackSave; |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 2030 | |
| Brian Paul | 7dac132 | 2000-06-15 19:57:14 +0000 | [diff] [blame] | 2031 | FREE(image); |
| jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 2032 | } |
| 2033 | } |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 2034 | |
| 2035 | |
| 2036 | |
| 2037 | void |
| 2038 | _mesa_CompressedTexImage1DARB(GLenum target, GLint level, |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2039 | GLenum internalFormat, GLsizei width, |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 2040 | GLint border, GLsizei imageSize, |
| 2041 | const GLvoid *data) |
| 2042 | { |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2043 | GET_CURRENT_CONTEXT(ctx); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 2044 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2045 | |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 2046 | switch (internalFormat) { |
| 2047 | case GL_COMPRESSED_ALPHA_ARB: |
| 2048 | case GL_COMPRESSED_LUMINANCE_ARB: |
| 2049 | case GL_COMPRESSED_LUMINANCE_ALPHA_ARB: |
| 2050 | case GL_COMPRESSED_INTENSITY_ARB: |
| 2051 | case GL_COMPRESSED_RGB_ARB: |
| 2052 | case GL_COMPRESSED_RGBA_ARB: |
| 2053 | gl_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage1DARB"); |
| 2054 | return; |
| 2055 | default: |
| 2056 | /* silence compiler warning */ |
| 2057 | ; |
| 2058 | } |
| 2059 | |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2060 | if (target == GL_TEXTURE_1D) { |
| 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, 1, 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, "glCompressedTexImage1DARB"); |
| 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, 1, 1, border, internalFormat); |
| 2088 | |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2089 | if (ctx->Extensions.ARB_texture_compression) { |
| 2090 | ASSERT(ctx->Driver.CompressedTexImage1D); |
| 2091 | (*ctx->Driver.CompressedTexImage1D)(ctx, target, level, |
| 2092 | internalFormat, width, border, |
| 2093 | imageSize, data, |
| 2094 | texObj, texImage); |
| 2095 | ASSERT(texImage->CompressedSize > 0); /* sanity */ |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2096 | } |
| 2097 | |
| 2098 | /* state update */ |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 2099 | texObj->Complete = GL_FALSE; |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 2100 | ctx->NewState |= _NEW_TEXTURE; |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2101 | } |
| 2102 | else if (target == GL_PROXY_TEXTURE_1D) { |
| 2103 | /* Proxy texture: check for errors and update proxy state */ |
| Brian Paul | 38d3f3d | 2000-09-07 15:38:49 +0000 | [diff] [blame] | 2104 | GLenum error = texture_error_check(ctx, target, level, internalFormat, |
| 2105 | GL_NONE, GL_NONE, 1, width, 1, 1, border); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2106 | if (!error) { |
| Brian Paul | a1f1586 | 2001-02-07 16:27:41 +0000 | [diff] [blame] | 2107 | struct gl_texture_unit *texUnit; |
| 2108 | struct gl_texture_image *texImage; |
| 2109 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 2110 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| 2111 | init_teximage_fields(ctx, texImage, width, 1, 1, |
| 2112 | border, internalFormat); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2113 | ASSERT(ctx->Driver.TestProxyTexImage); |
| Brian Paul | 38d3f3d | 2000-09-07 15:38:49 +0000 | [diff] [blame] | 2114 | error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, |
| 2115 | internalFormat, GL_NONE, GL_NONE, |
| 2116 | width, 1, 1, border); |
| 2117 | } |
| 2118 | if (error) { |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2119 | /* if error, clear all proxy texture image parameters */ |
| Brian Paul | f378ab8 | 2001-02-06 23:35:26 +0000 | [diff] [blame] | 2120 | if (level >= 0 && level < ctx->Const.MaxTextureLevels) { |
| 2121 | clear_teximage_fields(ctx->Texture.Proxy1D->Image[level]); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2122 | } |
| 2123 | } |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2124 | } |
| 2125 | else { |
| 2126 | gl_error( ctx, GL_INVALID_ENUM, "glCompressedTexImage1DARB(target)" ); |
| 2127 | return; |
| 2128 | } |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 2129 | } |
| 2130 | |
| 2131 | |
| 2132 | void |
| 2133 | _mesa_CompressedTexImage2DARB(GLenum target, GLint level, |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2134 | GLenum internalFormat, GLsizei width, |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 2135 | GLsizei height, GLint border, GLsizei imageSize, |
| 2136 | const GLvoid *data) |
| 2137 | { |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2138 | GET_CURRENT_CONTEXT(ctx); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 2139 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2140 | |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 2141 | switch (internalFormat) { |
| 2142 | case GL_COMPRESSED_ALPHA_ARB: |
| 2143 | case GL_COMPRESSED_LUMINANCE_ARB: |
| 2144 | case GL_COMPRESSED_LUMINANCE_ALPHA_ARB: |
| 2145 | case GL_COMPRESSED_INTENSITY_ARB: |
| 2146 | case GL_COMPRESSED_RGB_ARB: |
| 2147 | case GL_COMPRESSED_RGBA_ARB: |
| 2148 | gl_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage2DARB"); |
| 2149 | return; |
| 2150 | default: |
| 2151 | /* silence compiler warning */ |
| 2152 | ; |
| 2153 | } |
| 2154 | |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2155 | if (target == GL_TEXTURE_2D || |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 2156 | (ctx->Extensions.ARB_texture_cube_map && |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2157 | target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && |
| 2158 | target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)) { |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2159 | struct gl_texture_unit *texUnit; |
| 2160 | struct gl_texture_object *texObj; |
| 2161 | struct gl_texture_image *texImage; |
| 2162 | |
| 2163 | if (texture_error_check(ctx, target, level, internalFormat, |
| 2164 | GL_NONE, GL_NONE, 1, width, height, 1, border)) { |
| 2165 | return; /* error in texture image was detected */ |
| 2166 | } |
| 2167 | |
| 2168 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2169 | texObj = _mesa_select_tex_object(ctx, texUnit, target); |
| 2170 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2171 | |
| 2172 | if (!texImage) { |
| 2173 | texImage = _mesa_alloc_texture_image(); |
| 2174 | texObj->Image[level] = texImage; |
| 2175 | if (!texImage) { |
| 2176 | gl_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2DARB"); |
| 2177 | return; |
| 2178 | } |
| 2179 | } |
| 2180 | else if (texImage->Data) { |
| 2181 | FREE(texImage->Data); |
| 2182 | texImage->Data = NULL; |
| 2183 | } |
| 2184 | |
| Brian Paul | 6628bc9 | 2001-02-07 03:27:41 +0000 | [diff] [blame] | 2185 | init_teximage_fields(ctx, texImage, width, height, 1, border, |
| 2186 | internalFormat); |
| 2187 | |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2188 | if (ctx->Extensions.ARB_texture_compression) { |
| 2189 | ASSERT(ctx->Driver.CompressedTexImage2D); |
| 2190 | (*ctx->Driver.CompressedTexImage2D)(ctx, target, level, |
| 2191 | internalFormat, width, height, |
| 2192 | border, imageSize, data, |
| 2193 | texObj, texImage); |
| 2194 | ASSERT(texImage->CompressedSize > 0); /* sanity */ |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2195 | } |
| 2196 | |
| 2197 | /* state update */ |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 2198 | texObj->Complete = GL_FALSE; |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 2199 | ctx->NewState |= _NEW_TEXTURE; |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2200 | } |
| 2201 | else if (target == GL_PROXY_TEXTURE_2D) { |
| 2202 | /* Proxy texture: check for errors and update proxy state */ |
| Brian Paul | 38d3f3d | 2000-09-07 15:38:49 +0000 | [diff] [blame] | 2203 | GLenum error = texture_error_check(ctx, target, level, internalFormat, |
| 2204 | GL_NONE, GL_NONE, 2, width, height, 1, border); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2205 | if (!error) { |
| Brian Paul | a1f1586 | 2001-02-07 16:27:41 +0000 | [diff] [blame] | 2206 | struct gl_texture_unit *texUnit; |
| 2207 | struct gl_texture_image *texImage; |
| 2208 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 2209 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| 2210 | init_teximage_fields(ctx, texImage, width, height, 1, |
| 2211 | border, internalFormat); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2212 | ASSERT(ctx->Driver.TestProxyTexImage); |
| Brian Paul | 38d3f3d | 2000-09-07 15:38:49 +0000 | [diff] [blame] | 2213 | error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, |
| 2214 | internalFormat, GL_NONE, GL_NONE, |
| 2215 | width, height, 1, border); |
| 2216 | } |
| 2217 | if (error) { |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2218 | /* if error, clear all proxy texture image parameters */ |
| Brian Paul | f378ab8 | 2001-02-06 23:35:26 +0000 | [diff] [blame] | 2219 | if (level >= 0 && level < ctx->Const.MaxTextureLevels) { |
| 2220 | clear_teximage_fields(ctx->Texture.Proxy2D->Image[level]); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2221 | } |
| 2222 | } |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2223 | } |
| 2224 | else { |
| 2225 | gl_error( ctx, GL_INVALID_ENUM, "glCompressedTexImage2DARB(target)" ); |
| 2226 | return; |
| 2227 | } |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 2228 | } |
| 2229 | |
| 2230 | |
| 2231 | void |
| 2232 | _mesa_CompressedTexImage3DARB(GLenum target, GLint level, |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2233 | GLenum internalFormat, GLsizei width, |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 2234 | GLsizei height, GLsizei depth, GLint border, |
| 2235 | GLsizei imageSize, const GLvoid *data) |
| 2236 | { |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2237 | GET_CURRENT_CONTEXT(ctx); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 2238 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2239 | |
| Brian Paul | 289d47e | 2000-08-29 23:31:23 +0000 | [diff] [blame] | 2240 | switch (internalFormat) { |
| 2241 | case GL_COMPRESSED_ALPHA_ARB: |
| 2242 | case GL_COMPRESSED_LUMINANCE_ARB: |
| 2243 | case GL_COMPRESSED_LUMINANCE_ALPHA_ARB: |
| 2244 | case GL_COMPRESSED_INTENSITY_ARB: |
| 2245 | case GL_COMPRESSED_RGB_ARB: |
| 2246 | case GL_COMPRESSED_RGBA_ARB: |
| 2247 | gl_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage3DARB"); |
| 2248 | return; |
| 2249 | default: |
| 2250 | /* silence compiler warning */ |
| 2251 | ; |
| 2252 | } |
| 2253 | |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2254 | if (target == GL_TEXTURE_3D) { |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2255 | struct gl_texture_unit *texUnit; |
| 2256 | struct gl_texture_object *texObj; |
| 2257 | struct gl_texture_image *texImage; |
| 2258 | |
| 2259 | if (texture_error_check(ctx, target, level, internalFormat, |
| 2260 | GL_NONE, GL_NONE, 1, width, height, depth, border)) { |
| 2261 | return; /* error in texture image was detected */ |
| 2262 | } |
| 2263 | |
| 2264 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2265 | texObj = _mesa_select_tex_object(ctx, texUnit, target); |
| 2266 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2267 | |
| 2268 | if (!texImage) { |
| 2269 | texImage = _mesa_alloc_texture_image(); |
| 2270 | texObj->Image[level] = texImage; |
| 2271 | if (!texImage) { |
| 2272 | gl_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage3DARB"); |
| 2273 | return; |
| 2274 | } |
| 2275 | } |
| 2276 | else if (texImage->Data) { |
| 2277 | FREE(texImage->Data); |
| 2278 | texImage->Data = NULL; |
| 2279 | } |
| 2280 | |
| Brian Paul | 6628bc9 | 2001-02-07 03:27:41 +0000 | [diff] [blame] | 2281 | init_teximage_fields(ctx, texImage, width, height, depth, border, |
| 2282 | internalFormat); |
| 2283 | |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2284 | if (ctx->Extensions.ARB_texture_compression) { |
| 2285 | ASSERT(ctx->Driver.CompressedTexImage3D); |
| 2286 | (*ctx->Driver.CompressedTexImage3D)(ctx, target, level, |
| 2287 | internalFormat, |
| 2288 | width, height, depth, |
| 2289 | border, imageSize, data, |
| 2290 | texObj, texImage); |
| 2291 | ASSERT(texImage->CompressedSize > 0); /* sanity */ |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2292 | } |
| 2293 | |
| 2294 | /* state update */ |
| Brian Paul | a852378 | 2000-11-19 23:10:25 +0000 | [diff] [blame] | 2295 | texObj->Complete = GL_FALSE; |
| Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 2296 | ctx->NewState |= _NEW_TEXTURE; |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2297 | } |
| 2298 | else if (target == GL_PROXY_TEXTURE_3D) { |
| 2299 | /* Proxy texture: check for errors and update proxy state */ |
| Brian Paul | 38d3f3d | 2000-09-07 15:38:49 +0000 | [diff] [blame] | 2300 | GLenum error = texture_error_check(ctx, target, level, internalFormat, |
| 2301 | GL_NONE, GL_NONE, 1, width, height, depth, border); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2302 | if (!error) { |
| Brian Paul | a1f1586 | 2001-02-07 16:27:41 +0000 | [diff] [blame] | 2303 | struct gl_texture_unit *texUnit; |
| 2304 | struct gl_texture_image *texImage; |
| 2305 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 2306 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| 2307 | init_teximage_fields(ctx, texImage, width, height, depth, |
| 2308 | border, internalFormat); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2309 | ASSERT(ctx->Driver.TestProxyTexImage); |
| Brian Paul | 38d3f3d | 2000-09-07 15:38:49 +0000 | [diff] [blame] | 2310 | error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level, |
| 2311 | internalFormat, GL_NONE, GL_NONE, |
| 2312 | width, height, depth, border); |
| 2313 | } |
| 2314 | if (error) { |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2315 | /* if error, clear all proxy texture image parameters */ |
| Brian Paul | f378ab8 | 2001-02-06 23:35:26 +0000 | [diff] [blame] | 2316 | if (level >= 0 && level < ctx->Const.MaxTextureLevels) { |
| 2317 | clear_teximage_fields(ctx->Texture.Proxy3D->Image[level]); |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2318 | } |
| 2319 | } |
| Brian Paul | aea66b1 | 2000-05-24 14:04:06 +0000 | [diff] [blame] | 2320 | } |
| 2321 | else { |
| 2322 | gl_error( ctx, GL_INVALID_ENUM, "glCompressedTexImage3DARB(target)" ); |
| 2323 | return; |
| 2324 | } |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 2325 | } |
| 2326 | |
| 2327 | |
| 2328 | void |
| 2329 | _mesa_CompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset, |
| 2330 | GLsizei width, GLenum format, |
| 2331 | GLsizei imageSize, const GLvoid *data) |
| 2332 | { |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2333 | struct gl_texture_unit *texUnit; |
| 2334 | struct gl_texture_object *texObj; |
| 2335 | struct gl_texture_image *texImage; |
| Brian Paul | a1f1586 | 2001-02-07 16:27:41 +0000 | [diff] [blame] | 2336 | GET_CURRENT_CONTEXT(ctx); |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2337 | |
| 2338 | if (subtexture_error_check(ctx, 1, target, level, xoffset, 0, 0, |
| 2339 | width, 1, 1, format, GL_NONE)) { |
| 2340 | return; /* error was detected */ |
| 2341 | } |
| 2342 | |
| 2343 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 2344 | texObj = _mesa_select_tex_object(ctx, texUnit, target); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2345 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2346 | assert(texImage); |
| 2347 | |
| 2348 | if (width == 0 || !data) |
| 2349 | return; /* no-op, not an error */ |
| 2350 | |
| 2351 | if (ctx->Driver.CompressedTexSubImage1D) { |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2352 | (*ctx->Driver.CompressedTexSubImage1D)(ctx, target, level, |
| 2353 | xoffset, width, |
| 2354 | format, imageSize, data, |
| 2355 | texObj, texImage); |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2356 | } |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 2357 | } |
| 2358 | |
| 2359 | |
| 2360 | void |
| 2361 | _mesa_CompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset, |
| 2362 | GLint yoffset, GLsizei width, GLsizei height, |
| 2363 | GLenum format, GLsizei imageSize, |
| 2364 | const GLvoid *data) |
| 2365 | { |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2366 | struct gl_texture_unit *texUnit; |
| 2367 | struct gl_texture_object *texObj; |
| 2368 | struct gl_texture_image *texImage; |
| Brian Paul | a1f1586 | 2001-02-07 16:27:41 +0000 | [diff] [blame] | 2369 | GET_CURRENT_CONTEXT(ctx); |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2370 | |
| 2371 | if (subtexture_error_check(ctx, 2, target, level, xoffset, yoffset, 0, |
| 2372 | width, height, 1, format, GL_NONE)) { |
| 2373 | return; /* error was detected */ |
| 2374 | } |
| 2375 | |
| 2376 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 2377 | texObj = _mesa_select_tex_object(ctx, texUnit, target); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2378 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2379 | assert(texImage); |
| 2380 | |
| 2381 | if (width == 0 || height == 0 || !data) |
| 2382 | return; /* no-op, not an error */ |
| 2383 | |
| 2384 | if (ctx->Driver.CompressedTexSubImage2D) { |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2385 | (*ctx->Driver.CompressedTexSubImage2D)(ctx, target, level, |
| 2386 | xoffset, yoffset, width, height, |
| 2387 | format, imageSize, data, |
| 2388 | texObj, texImage); |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2389 | } |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 2390 | } |
| 2391 | |
| 2392 | |
| 2393 | void |
| 2394 | _mesa_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset, |
| 2395 | GLint yoffset, GLint zoffset, GLsizei width, |
| 2396 | GLsizei height, GLsizei depth, GLenum format, |
| 2397 | GLsizei imageSize, const GLvoid *data) |
| 2398 | { |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2399 | struct gl_texture_unit *texUnit; |
| 2400 | struct gl_texture_object *texObj; |
| 2401 | struct gl_texture_image *texImage; |
| Brian Paul | a1f1586 | 2001-02-07 16:27:41 +0000 | [diff] [blame] | 2402 | GET_CURRENT_CONTEXT(ctx); |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2403 | |
| 2404 | if (subtexture_error_check(ctx, 3, target, level, xoffset, yoffset, zoffset, |
| 2405 | width, height, depth, format, GL_NONE)) { |
| 2406 | return; /* error was detected */ |
| 2407 | } |
| 2408 | |
| 2409 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 2410 | texObj = _mesa_select_tex_object(ctx, texUnit, target); |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2411 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2412 | assert(texImage); |
| 2413 | |
| 2414 | if (width == 0 || height == 0 || depth == 0 || !data) |
| 2415 | return; /* no-op, not an error */ |
| 2416 | |
| 2417 | if (ctx->Driver.CompressedTexSubImage3D) { |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2418 | (*ctx->Driver.CompressedTexSubImage3D)(ctx, target, level, |
| 2419 | xoffset, yoffset, zoffset, |
| 2420 | width, height, depth, |
| 2421 | format, imageSize, data, |
| 2422 | texObj, texImage); |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2423 | } |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 2424 | } |
| 2425 | |
| 2426 | |
| 2427 | void |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2428 | _mesa_GetCompressedTexImageARB(GLenum target, GLint level, GLvoid *img) |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 2429 | { |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2430 | const struct gl_texture_unit *texUnit; |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2431 | const struct gl_texture_object *texObj; |
| 2432 | struct gl_texture_image *texImage; |
| Brian Paul | a1f1586 | 2001-02-07 16:27:41 +0000 | [diff] [blame] | 2433 | GET_CURRENT_CONTEXT(ctx); |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2434 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 2435 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2436 | |
| 2437 | if (level < 0 || level >= ctx->Const.MaxTextureLevels) { |
| 2438 | gl_error( ctx, GL_INVALID_VALUE, "glGetCompressedTexImageARB(level)" ); |
| 2439 | return; |
| 2440 | } |
| 2441 | |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2442 | if (is_proxy_target(target)) { |
| 2443 | gl_error(ctx, GL_INVALID_ENUM, "glGetCompressedTexImageARB(target)"); |
| 2444 | return; |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2445 | } |
| 2446 | |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2447 | texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
| 2448 | texObj = _mesa_select_tex_object(ctx, texUnit, target); |
| 2449 | texImage = _mesa_select_tex_image(ctx, texUnit, target, level); |
| 2450 | |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2451 | if (!texImage) { |
| 2452 | /* invalid mipmap level */ |
| 2453 | gl_error(ctx, GL_INVALID_VALUE, "glGetCompressedTexImageARB(level)"); |
| 2454 | return; |
| 2455 | } |
| 2456 | |
| 2457 | if (!texImage->IsCompressed) { |
| 2458 | gl_error(ctx, GL_INVALID_OPERATION, "glGetCompressedTexImageARB"); |
| 2459 | return; |
| 2460 | } |
| 2461 | |
| 2462 | if (!img) |
| 2463 | return; |
| 2464 | |
| Brian Paul | 8e39ad2 | 2001-02-06 21:42:48 +0000 | [diff] [blame] | 2465 | if (ctx->Extensions.ARB_texture_compression) { |
| 2466 | ASSERT(ctx->Driver.GetCompressedTexImage); |
| Brian Paul | 9540a1d | 2000-06-06 17:03:38 +0000 | [diff] [blame] | 2467 | (*ctx->Driver.GetCompressedTexImage)(ctx, target, level, img, texObj, |
| 2468 | texImage); |
| 2469 | } |
| Brian Paul | 1207bf0 | 2000-05-23 20:10:49 +0000 | [diff] [blame] | 2470 | } |