mesa: better error message
[mesa.git] / src / mesa / main / teximage.c
1 /*
2 * mesa 3-D graphics library
3 * Version: 7.6
4 *
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26
27 /**
28 * \file teximage.c
29 * Texture image-related functions.
30 */
31
32
33 #include "glheader.h"
34 #include "bufferobj.h"
35 #include "context.h"
36 #include "convolve.h"
37 #include "enums.h"
38 #include "fbobject.h"
39 #include "framebuffer.h"
40 #include "hash.h"
41 #include "image.h"
42 #include "imports.h"
43 #include "macros.h"
44 #include "state.h"
45 #include "texcompress.h"
46 #include "texfetch.h"
47 #include "teximage.h"
48 #include "texstate.h"
49 #include "texstore.h"
50 #include "mtypes.h"
51
52
53 /**
54 * State changes which we care about for glCopyTex[Sub]Image() calls.
55 * In particular, we care about pixel transfer state and buffer state
56 * (such as glReadBuffer to make sure we read from the right renderbuffer).
57 */
58 #define NEW_COPY_TEX_STATE (_MESA_NEW_TRANSFER_STATE | \
59 _NEW_BUFFERS | \
60 _NEW_PIXEL)
61
62
63
64 /**
65 * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE
66 * elsewhere.
67 */
68 void *
69 _mesa_alloc_texmemory(GLsizei bytes)
70 {
71 return _mesa_align_malloc(bytes, 512);
72 }
73
74
75 /**
76 * Free texture memory allocated with _mesa_alloc_texmemory()
77 */
78 void
79 _mesa_free_texmemory(void *m)
80 {
81 _mesa_align_free(m);
82 }
83
84
85 /*
86 * Compute floor(log_base_2(n)).
87 * If n < 0 return -1.
88 */
89 static int
90 logbase2( int n )
91 {
92 GLint i = 1;
93 GLint log2 = 0;
94
95 if (n < 0)
96 return -1;
97
98 if (n == 0)
99 return 0;
100
101 while ( n > i ) {
102 i *= 2;
103 log2++;
104 }
105 if (i != n) {
106 return log2 - 1;
107 }
108 else {
109 return log2;
110 }
111 }
112
113
114
115 /**
116 * Return the simple base format for a given internal texture format.
117 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
118 *
119 * \param ctx GL context.
120 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
121 *
122 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
123 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
124 *
125 * This is the format which is used during texture application (i.e. the
126 * texture format and env mode determine the arithmetic used.
127 *
128 * XXX this could be static
129 */
130 GLint
131 _mesa_base_tex_format( GLcontext *ctx, GLint internalFormat )
132 {
133 switch (internalFormat) {
134 case GL_ALPHA:
135 case GL_ALPHA4:
136 case GL_ALPHA8:
137 case GL_ALPHA12:
138 case GL_ALPHA16:
139 return GL_ALPHA;
140 case 1:
141 case GL_LUMINANCE:
142 case GL_LUMINANCE4:
143 case GL_LUMINANCE8:
144 case GL_LUMINANCE12:
145 case GL_LUMINANCE16:
146 return GL_LUMINANCE;
147 case 2:
148 case GL_LUMINANCE_ALPHA:
149 case GL_LUMINANCE4_ALPHA4:
150 case GL_LUMINANCE6_ALPHA2:
151 case GL_LUMINANCE8_ALPHA8:
152 case GL_LUMINANCE12_ALPHA4:
153 case GL_LUMINANCE12_ALPHA12:
154 case GL_LUMINANCE16_ALPHA16:
155 return GL_LUMINANCE_ALPHA;
156 case GL_INTENSITY:
157 case GL_INTENSITY4:
158 case GL_INTENSITY8:
159 case GL_INTENSITY12:
160 case GL_INTENSITY16:
161 return GL_INTENSITY;
162 case 3:
163 case GL_RGB:
164 case GL_R3_G3_B2:
165 case GL_RGB4:
166 case GL_RGB5:
167 case GL_RGB8:
168 case GL_RGB10:
169 case GL_RGB12:
170 case GL_RGB16:
171 return GL_RGB;
172 case 4:
173 case GL_RGBA:
174 case GL_RGBA2:
175 case GL_RGBA4:
176 case GL_RGB5_A1:
177 case GL_RGBA8:
178 case GL_RGB10_A2:
179 case GL_RGBA12:
180 case GL_RGBA16:
181 return GL_RGBA;
182 default:
183 ; /* fallthrough */
184 }
185
186 if (ctx->Extensions.EXT_paletted_texture) {
187 switch (internalFormat) {
188 case GL_COLOR_INDEX:
189 case GL_COLOR_INDEX1_EXT:
190 case GL_COLOR_INDEX2_EXT:
191 case GL_COLOR_INDEX4_EXT:
192 case GL_COLOR_INDEX8_EXT:
193 case GL_COLOR_INDEX12_EXT:
194 case GL_COLOR_INDEX16_EXT:
195 return GL_COLOR_INDEX;
196 default:
197 ; /* fallthrough */
198 }
199 }
200
201 if (ctx->Extensions.ARB_depth_texture) {
202 switch (internalFormat) {
203 case GL_DEPTH_COMPONENT:
204 case GL_DEPTH_COMPONENT16:
205 case GL_DEPTH_COMPONENT24:
206 case GL_DEPTH_COMPONENT32:
207 return GL_DEPTH_COMPONENT;
208 default:
209 ; /* fallthrough */
210 }
211 }
212
213 switch (internalFormat) {
214 case GL_COMPRESSED_ALPHA:
215 return GL_ALPHA;
216 case GL_COMPRESSED_LUMINANCE:
217 return GL_LUMINANCE;
218 case GL_COMPRESSED_LUMINANCE_ALPHA:
219 return GL_LUMINANCE_ALPHA;
220 case GL_COMPRESSED_INTENSITY:
221 return GL_INTENSITY;
222 case GL_COMPRESSED_RGB:
223 return GL_RGB;
224 case GL_COMPRESSED_RGBA:
225 return GL_RGBA;
226 default:
227 ; /* fallthrough */
228 }
229
230 if (ctx->Extensions.TDFX_texture_compression_FXT1) {
231 switch (internalFormat) {
232 case GL_COMPRESSED_RGB_FXT1_3DFX:
233 return GL_RGB;
234 case GL_COMPRESSED_RGBA_FXT1_3DFX:
235 return GL_RGBA;
236 default:
237 ; /* fallthrough */
238 }
239 }
240
241 if (ctx->Extensions.EXT_texture_compression_s3tc) {
242 switch (internalFormat) {
243 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
244 return GL_RGB;
245 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
246 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
247 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
248 return GL_RGBA;
249 default:
250 ; /* fallthrough */
251 }
252 }
253
254 if (ctx->Extensions.S3_s3tc) {
255 switch (internalFormat) {
256 case GL_RGB_S3TC:
257 case GL_RGB4_S3TC:
258 return GL_RGB;
259 case GL_RGBA_S3TC:
260 case GL_RGBA4_S3TC:
261 return GL_RGBA;
262 default:
263 ; /* fallthrough */
264 }
265 }
266
267 if (ctx->Extensions.MESA_ycbcr_texture) {
268 if (internalFormat == GL_YCBCR_MESA)
269 return GL_YCBCR_MESA;
270 }
271
272 if (ctx->Extensions.ARB_texture_float) {
273 switch (internalFormat) {
274 case GL_ALPHA16F_ARB:
275 case GL_ALPHA32F_ARB:
276 return GL_ALPHA;
277 case GL_RGBA16F_ARB:
278 case GL_RGBA32F_ARB:
279 return GL_RGBA;
280 case GL_RGB16F_ARB:
281 case GL_RGB32F_ARB:
282 return GL_RGB;
283 case GL_INTENSITY16F_ARB:
284 case GL_INTENSITY32F_ARB:
285 return GL_INTENSITY;
286 case GL_LUMINANCE16F_ARB:
287 case GL_LUMINANCE32F_ARB:
288 return GL_LUMINANCE;
289 case GL_LUMINANCE_ALPHA16F_ARB:
290 case GL_LUMINANCE_ALPHA32F_ARB:
291 return GL_LUMINANCE_ALPHA;
292 default:
293 ; /* fallthrough */
294 }
295 }
296
297 if (ctx->Extensions.ATI_envmap_bumpmap) {
298 switch (internalFormat) {
299 case GL_DUDV_ATI:
300 case GL_DU8DV8_ATI:
301 return GL_DUDV_ATI;
302 default:
303 ; /* fallthrough */
304 }
305 }
306
307 if (ctx->Extensions.MESA_texture_signed_rgba) {
308 switch (internalFormat) {
309 case GL_RGBA_SNORM:
310 case GL_RGBA8_SNORM:
311 return GL_RGBA;
312 default:
313 ; /* fallthrough */
314 }
315 }
316
317 if (ctx->Extensions.EXT_packed_depth_stencil) {
318 switch (internalFormat) {
319 case GL_DEPTH_STENCIL_EXT:
320 case GL_DEPTH24_STENCIL8_EXT:
321 return GL_DEPTH_STENCIL_EXT;
322 default:
323 ; /* fallthrough */
324 }
325 }
326
327 #if FEATURE_EXT_texture_sRGB
328 if (ctx->Extensions.EXT_texture_sRGB) {
329 switch (internalFormat) {
330 case GL_SRGB_EXT:
331 case GL_SRGB8_EXT:
332 case GL_COMPRESSED_SRGB_EXT:
333 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
334 return GL_RGB;
335 case GL_SRGB_ALPHA_EXT:
336 case GL_SRGB8_ALPHA8_EXT:
337 case GL_COMPRESSED_SRGB_ALPHA_EXT:
338 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
339 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
340 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
341 return GL_RGBA;
342 case GL_SLUMINANCE_ALPHA_EXT:
343 case GL_SLUMINANCE8_ALPHA8_EXT:
344 case GL_COMPRESSED_SLUMINANCE_EXT:
345 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT:
346 return GL_LUMINANCE_ALPHA;
347 case GL_SLUMINANCE_EXT:
348 case GL_SLUMINANCE8_EXT:
349 return GL_LUMINANCE;
350 default:
351 ; /* fallthrough */
352 }
353 }
354
355 #endif /* FEATURE_EXT_texture_sRGB */
356
357 return -1; /* error */
358 }
359
360
361 /**
362 * Test if it is a supported compressed format.
363 *
364 * \param internalFormat the internal format token provided by the user.
365 *
366 * \ret GL_TRUE if \p internalFormat is a supported compressed format, or
367 * GL_FALSE otherwise.
368 *
369 * Currently only GL_COMPRESSED_RGB_FXT1_3DFX and GL_COMPRESSED_RGBA_FXT1_3DFX
370 * are supported.
371 */
372 static GLboolean
373 is_compressed_format(GLcontext *ctx, GLenum internalFormat)
374 {
375 GLint supported[100]; /* 100 should be plenty */
376 GLuint i, n;
377
378 n = _mesa_get_compressed_formats(ctx, supported, GL_TRUE);
379 ASSERT(n < 100);
380 for (i = 0; i < n; i++) {
381 if ((GLint) internalFormat == supported[i]) {
382 return GL_TRUE;
383 }
384 }
385 return GL_FALSE;
386 }
387
388
389 /**
390 * For cube map faces, return a face index in [0,5].
391 * For other targets return 0;
392 */
393 GLuint
394 _mesa_tex_target_to_face(GLenum target)
395 {
396 if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
397 target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)
398 return (GLuint) target - (GLuint) GL_TEXTURE_CUBE_MAP_POSITIVE_X;
399 else
400 return 0;
401 }
402
403
404
405 /**
406 * Store a gl_texture_image pointer in a gl_texture_object structure
407 * according to the target and level parameters.
408 *
409 * \param tObj texture object.
410 * \param target texture target.
411 * \param level image level.
412 * \param texImage texture image.
413 *
414 * This was basically prompted by the introduction of cube maps.
415 */
416 void
417 _mesa_set_tex_image(struct gl_texture_object *tObj,
418 GLenum target, GLint level,
419 struct gl_texture_image *texImage)
420 {
421 const GLuint face = _mesa_tex_target_to_face(target);
422
423 ASSERT(tObj);
424 ASSERT(texImage);
425 ASSERT(target != GL_TEXTURE_RECTANGLE_NV || level == 0);
426
427 tObj->Image[face][level] = texImage;
428
429 /* Set the 'back' pointer */
430 texImage->TexObject = tObj;
431 }
432
433
434 /**
435 * Allocate a texture image structure.
436 *
437 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
438 * driver.
439 *
440 * \return a pointer to gl_texture_image struct with all fields initialized to
441 * zero.
442 */
443 struct gl_texture_image *
444 _mesa_new_texture_image( GLcontext *ctx )
445 {
446 (void) ctx;
447 return CALLOC_STRUCT(gl_texture_image);
448 }
449
450
451 /**
452 * Free texture image data.
453 * This function is a fallback called via ctx->Driver.FreeTexImageData().
454 *
455 * \param texImage texture image.
456 *
457 * Free the texture image data if it's not marked as client data.
458 */
459 void
460 _mesa_free_texture_image_data(GLcontext *ctx,
461 struct gl_texture_image *texImage)
462 {
463 (void) ctx;
464
465 if (texImage->Data && !texImage->IsClientData) {
466 /* free the old texture data */
467 _mesa_free_texmemory(texImage->Data);
468 }
469
470 texImage->Data = NULL;
471 }
472
473
474 /**
475 * Free texture image.
476 *
477 * \param texImage texture image.
478 *
479 * Free the texture image structure and the associated image data.
480 */
481 void
482 _mesa_delete_texture_image( GLcontext *ctx, struct gl_texture_image *texImage )
483 {
484 /* Free texImage->Data and/or any other driver-specific texture
485 * image storage.
486 */
487 ASSERT(ctx->Driver.FreeTexImageData);
488 ctx->Driver.FreeTexImageData( ctx, texImage );
489
490 ASSERT(texImage->Data == NULL);
491 if (texImage->ImageOffsets)
492 _mesa_free(texImage->ImageOffsets);
493 _mesa_free(texImage);
494 }
495
496
497 /**
498 * Test if a target is a proxy target.
499 *
500 * \param target texture target.
501 *
502 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
503 */
504 GLboolean
505 _mesa_is_proxy_texture(GLenum target)
506 {
507 /* NUM_TEXTURE_TARGETS should match number of terms below */
508 assert(NUM_TEXTURE_TARGETS == 7);
509
510 return (target == GL_PROXY_TEXTURE_1D ||
511 target == GL_PROXY_TEXTURE_2D ||
512 target == GL_PROXY_TEXTURE_3D ||
513 target == GL_PROXY_TEXTURE_CUBE_MAP_ARB ||
514 target == GL_PROXY_TEXTURE_RECTANGLE_NV ||
515 target == GL_PROXY_TEXTURE_1D_ARRAY_EXT ||
516 target == GL_PROXY_TEXTURE_2D_ARRAY_EXT);
517 }
518
519
520 /**
521 * Get the texture object that corresponds to the target of the given texture unit.
522 *
523 * \param ctx GL context.
524 * \param texUnit texture unit.
525 * \param target texture target.
526 *
527 * \return pointer to the texture object on success, or NULL on failure.
528 *
529 * \sa gl_texture_unit.
530 */
531 struct gl_texture_object *
532 _mesa_select_tex_object(GLcontext *ctx, const struct gl_texture_unit *texUnit,
533 GLenum target)
534 {
535 switch (target) {
536 case GL_TEXTURE_1D:
537 return texUnit->CurrentTex[TEXTURE_1D_INDEX];
538 case GL_PROXY_TEXTURE_1D:
539 return ctx->Texture.ProxyTex[TEXTURE_1D_INDEX];
540 case GL_TEXTURE_2D:
541 return texUnit->CurrentTex[TEXTURE_2D_INDEX];
542 case GL_PROXY_TEXTURE_2D:
543 return ctx->Texture.ProxyTex[TEXTURE_2D_INDEX];
544 case GL_TEXTURE_3D:
545 return texUnit->CurrentTex[TEXTURE_3D_INDEX];
546 case GL_PROXY_TEXTURE_3D:
547 return ctx->Texture.ProxyTex[TEXTURE_3D_INDEX];
548 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
549 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
550 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
551 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
552 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
553 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
554 case GL_TEXTURE_CUBE_MAP_ARB:
555 return ctx->Extensions.ARB_texture_cube_map
556 ? texUnit->CurrentTex[TEXTURE_CUBE_INDEX] : NULL;
557 case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
558 return ctx->Extensions.ARB_texture_cube_map
559 ? ctx->Texture.ProxyTex[TEXTURE_CUBE_INDEX] : NULL;
560 case GL_TEXTURE_RECTANGLE_NV:
561 return ctx->Extensions.NV_texture_rectangle
562 ? texUnit->CurrentTex[TEXTURE_RECT_INDEX] : NULL;
563 case GL_PROXY_TEXTURE_RECTANGLE_NV:
564 return ctx->Extensions.NV_texture_rectangle
565 ? ctx->Texture.ProxyTex[TEXTURE_RECT_INDEX] : NULL;
566 case GL_TEXTURE_1D_ARRAY_EXT:
567 return ctx->Extensions.MESA_texture_array
568 ? texUnit->CurrentTex[TEXTURE_1D_ARRAY_INDEX] : NULL;
569 case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
570 return ctx->Extensions.MESA_texture_array
571 ? ctx->Texture.ProxyTex[TEXTURE_1D_ARRAY_INDEX] : NULL;
572 case GL_TEXTURE_2D_ARRAY_EXT:
573 return ctx->Extensions.MESA_texture_array
574 ? texUnit->CurrentTex[TEXTURE_2D_ARRAY_INDEX] : NULL;
575 case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
576 return ctx->Extensions.MESA_texture_array
577 ? ctx->Texture.ProxyTex[TEXTURE_2D_ARRAY_INDEX] : NULL;
578 default:
579 _mesa_problem(NULL, "bad target in _mesa_select_tex_object()");
580 return NULL;
581 }
582 }
583
584
585 /**
586 * Get a texture image pointer from a texture object, given a texture
587 * target and mipmap level. The target and level parameters should
588 * have already been error-checked.
589 *
590 * \param ctx GL context.
591 * \param texObj texture unit.
592 * \param target texture target.
593 * \param level image level.
594 *
595 * \return pointer to the texture image structure, or NULL on failure.
596 */
597 struct gl_texture_image *
598 _mesa_select_tex_image(GLcontext *ctx, const struct gl_texture_object *texObj,
599 GLenum target, GLint level)
600 {
601 const GLuint face = _mesa_tex_target_to_face(target);
602
603 ASSERT(texObj);
604 ASSERT(level >= 0);
605 ASSERT(level < MAX_TEXTURE_LEVELS);
606
607 return texObj->Image[face][level];
608 }
609
610
611 /**
612 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
613 * it and install it. Only return NULL if passed a bad parameter or run
614 * out of memory.
615 */
616 struct gl_texture_image *
617 _mesa_get_tex_image(GLcontext *ctx, struct gl_texture_object *texObj,
618 GLenum target, GLint level)
619 {
620 struct gl_texture_image *texImage;
621
622 if (!texObj)
623 return NULL;
624
625 texImage = _mesa_select_tex_image(ctx, texObj, target, level);
626 if (!texImage) {
627 texImage = ctx->Driver.NewTextureImage(ctx);
628 if (!texImage) {
629 _mesa_error(ctx, GL_OUT_OF_MEMORY, "texture image allocation");
630 return NULL;
631 }
632
633 _mesa_set_tex_image(texObj, target, level, texImage);
634 }
635
636 return texImage;
637 }
638
639
640 /**
641 * Return pointer to the specified proxy texture image.
642 * Note that proxy textures are per-context, not per-texture unit.
643 * \return pointer to texture image or NULL if invalid target, invalid
644 * level, or out of memory.
645 */
646 struct gl_texture_image *
647 _mesa_get_proxy_tex_image(GLcontext *ctx, GLenum target, GLint level)
648 {
649 struct gl_texture_image *texImage;
650 GLuint texIndex;
651
652 if (level < 0 )
653 return NULL;
654
655 switch (target) {
656 case GL_PROXY_TEXTURE_1D:
657 if (level >= ctx->Const.MaxTextureLevels)
658 return NULL;
659 texIndex = TEXTURE_1D_INDEX;
660 break;
661 case GL_PROXY_TEXTURE_2D:
662 if (level >= ctx->Const.MaxTextureLevels)
663 return NULL;
664 texIndex = TEXTURE_2D_INDEX;
665 break;
666 case GL_PROXY_TEXTURE_3D:
667 if (level >= ctx->Const.Max3DTextureLevels)
668 return NULL;
669 texIndex = TEXTURE_3D_INDEX;
670 break;
671 case GL_PROXY_TEXTURE_CUBE_MAP:
672 if (level >= ctx->Const.MaxCubeTextureLevels)
673 return NULL;
674 texIndex = TEXTURE_CUBE_INDEX;
675 break;
676 case GL_PROXY_TEXTURE_RECTANGLE_NV:
677 if (level > 0)
678 return NULL;
679 texIndex = TEXTURE_RECT_INDEX;
680 break;
681 case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
682 if (level >= ctx->Const.MaxTextureLevels)
683 return NULL;
684 texIndex = TEXTURE_1D_ARRAY_INDEX;
685 break;
686 case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
687 if (level >= ctx->Const.MaxTextureLevels)
688 return NULL;
689 texIndex = TEXTURE_2D_ARRAY_INDEX;
690 break;
691 default:
692 return NULL;
693 }
694
695 texImage = ctx->Texture.ProxyTex[texIndex]->Image[0][level];
696 if (!texImage) {
697 texImage = ctx->Driver.NewTextureImage(ctx);
698 if (!texImage) {
699 _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation");
700 return NULL;
701 }
702 ctx->Texture.ProxyTex[texIndex]->Image[0][level] = texImage;
703 /* Set the 'back' pointer */
704 texImage->TexObject = ctx->Texture.ProxyTex[texIndex];
705 }
706 return texImage;
707 }
708
709
710 /**
711 * Get the maximum number of allowed mipmap levels.
712 *
713 * \param ctx GL context.
714 * \param target texture target.
715 *
716 * \return the maximum number of allowed mipmap levels for the given
717 * texture target, or zero if passed a bad target.
718 *
719 * \sa gl_constants.
720 */
721 GLint
722 _mesa_max_texture_levels(GLcontext *ctx, GLenum target)
723 {
724 switch (target) {
725 case GL_TEXTURE_1D:
726 case GL_PROXY_TEXTURE_1D:
727 case GL_TEXTURE_2D:
728 case GL_PROXY_TEXTURE_2D:
729 return ctx->Const.MaxTextureLevels;
730 case GL_TEXTURE_3D:
731 case GL_PROXY_TEXTURE_3D:
732 return ctx->Const.Max3DTextureLevels;
733 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
734 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
735 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
736 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
737 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
738 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
739 case GL_TEXTURE_CUBE_MAP_ARB:
740 case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
741 return ctx->Extensions.ARB_texture_cube_map
742 ? ctx->Const.MaxCubeTextureLevels : 0;
743 case GL_TEXTURE_RECTANGLE_NV:
744 case GL_PROXY_TEXTURE_RECTANGLE_NV:
745 return ctx->Extensions.NV_texture_rectangle ? 1 : 0;
746 case GL_TEXTURE_1D_ARRAY_EXT:
747 case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
748 case GL_TEXTURE_2D_ARRAY_EXT:
749 case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
750 return ctx->Extensions.MESA_texture_array
751 ? ctx->Const.MaxTextureLevels : 0;
752 default:
753 return 0; /* bad target */
754 }
755 }
756
757
758
759 #if 000 /* not used anymore */
760 /*
761 * glTexImage[123]D can accept a NULL image pointer. In this case we
762 * create a texture image with unspecified image contents per the OpenGL
763 * spec.
764 */
765 static GLubyte *
766 make_null_texture(GLint width, GLint height, GLint depth, GLenum format)
767 {
768 const GLint components = _mesa_components_in_format(format);
769 const GLint numPixels = width * height * depth;
770 GLubyte *data = (GLubyte *) MALLOC(numPixels * components * sizeof(GLubyte));
771
772 #ifdef DEBUG
773 /*
774 * Let's see if anyone finds this. If glTexImage2D() is called with
775 * a NULL image pointer then load the texture image with something
776 * interesting instead of leaving it indeterminate.
777 */
778 if (data) {
779 static const char message[8][32] = {
780 " X X XXXXX XXX X ",
781 " XX XX X X X X X ",
782 " X X X X X X X ",
783 " X X XXXX XXX XXXXX ",
784 " X X X X X X ",
785 " X X X X X X X ",
786 " X X XXXXX XXX X X ",
787 " "
788 };
789
790 GLubyte *imgPtr = data;
791 GLint h, i, j, k;
792 for (h = 0; h < depth; h++) {
793 for (i = 0; i < height; i++) {
794 GLint srcRow = 7 - (i % 8);
795 for (j = 0; j < width; j++) {
796 GLint srcCol = j % 32;
797 GLubyte texel = (message[srcRow][srcCol]=='X') ? 255 : 70;
798 for (k = 0; k < components; k++) {
799 *imgPtr++ = texel;
800 }
801 }
802 }
803 }
804 }
805 #endif
806
807 return data;
808 }
809 #endif
810
811
812
813 /**
814 * Reset the fields of a gl_texture_image struct to zero.
815 *
816 * \param img texture image structure.
817 *
818 * This is called when a proxy texture test fails, we set all the
819 * image members (except DriverData) to zero.
820 * It's also used in glTexImage[123]D as a safeguard to be sure all
821 * required fields get initialized properly by the Driver.TexImage[123]D
822 * functions.
823 */
824 static void
825 clear_teximage_fields(struct gl_texture_image *img)
826 {
827 ASSERT(img);
828 img->_BaseFormat = 0;
829 img->InternalFormat = 0;
830 img->Border = 0;
831 img->Width = 0;
832 img->Height = 0;
833 img->Depth = 0;
834 img->RowStride = 0;
835 if (img->ImageOffsets) {
836 _mesa_free(img->ImageOffsets);
837 img->ImageOffsets = NULL;
838 }
839 img->Width2 = 0;
840 img->Height2 = 0;
841 img->Depth2 = 0;
842 img->WidthLog2 = 0;
843 img->HeightLog2 = 0;
844 img->DepthLog2 = 0;
845 img->Data = NULL;
846 img->TexFormat = MESA_FORMAT_NONE;
847 img->FetchTexelc = NULL;
848 img->FetchTexelf = NULL;
849 }
850
851
852 /**
853 * Initialize basic fields of the gl_texture_image struct.
854 *
855 * \param ctx GL context.
856 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
857 * \param img texture image structure to be initialized.
858 * \param width image width.
859 * \param height image height.
860 * \param depth image depth.
861 * \param border image border.
862 * \param internalFormat internal format.
863 *
864 * Fills in the fields of \p img with the given information.
865 * Note: width, height and depth include the border.
866 */
867 void
868 _mesa_init_teximage_fields(GLcontext *ctx, GLenum target,
869 struct gl_texture_image *img,
870 GLsizei width, GLsizei height, GLsizei depth,
871 GLint border, GLenum internalFormat)
872 {
873 GLint i;
874
875 ASSERT(img);
876 ASSERT(width >= 0);
877 ASSERT(height >= 0);
878 ASSERT(depth >= 0);
879
880 img->_BaseFormat = _mesa_base_tex_format( ctx, internalFormat );
881 ASSERT(img->_BaseFormat > 0);
882 img->InternalFormat = internalFormat;
883 img->Border = border;
884 img->Width = width;
885 img->Height = height;
886 img->Depth = depth;
887
888 img->Width2 = width - 2 * border; /* == 1 << img->WidthLog2; */
889 img->WidthLog2 = logbase2(img->Width2);
890
891 if (height == 1) { /* 1-D texture */
892 img->Height2 = 1;
893 img->HeightLog2 = 0;
894 }
895 else {
896 img->Height2 = height - 2 * border; /* == 1 << img->HeightLog2; */
897 img->HeightLog2 = logbase2(img->Height2);
898 }
899
900 if (depth == 1) { /* 2-D texture */
901 img->Depth2 = 1;
902 img->DepthLog2 = 0;
903 }
904 else {
905 img->Depth2 = depth - 2 * border; /* == 1 << img->DepthLog2; */
906 img->DepthLog2 = logbase2(img->Depth2);
907 }
908
909 img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2);
910
911 if ((width == 1 || _mesa_is_pow_two(img->Width2)) &&
912 (height == 1 || _mesa_is_pow_two(img->Height2)) &&
913 (depth == 1 || _mesa_is_pow_two(img->Depth2)))
914 img->_IsPowerOfTwo = GL_TRUE;
915 else
916 img->_IsPowerOfTwo = GL_FALSE;
917
918 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
919 img->RowStride = width;
920 /* Allocate the ImageOffsets array and initialize to typical values.
921 * We allocate the array for 1D/2D textures too in order to avoid special-
922 * case code in the texstore routines.
923 */
924 if (img->ImageOffsets)
925 _mesa_free(img->ImageOffsets);
926 img->ImageOffsets = (GLuint *) _mesa_malloc(depth * sizeof(GLuint));
927 for (i = 0; i < depth; i++) {
928 img->ImageOffsets[i] = i * width * height;
929 }
930
931 /* Compute Width/Height/DepthScale for mipmap lod computation */
932 if (target == GL_TEXTURE_RECTANGLE_NV) {
933 /* scale = 1.0 since texture coords directly map to texels */
934 img->WidthScale = 1.0;
935 img->HeightScale = 1.0;
936 img->DepthScale = 1.0;
937 }
938 else {
939 img->WidthScale = (GLfloat) img->Width;
940 img->HeightScale = (GLfloat) img->Height;
941 img->DepthScale = (GLfloat) img->Depth;
942 }
943
944 img->FetchTexelc = NULL;
945 img->FetchTexelf = NULL;
946 }
947
948
949 /**
950 * Free and clear fields of the gl_texture_image struct.
951 *
952 * \param ctx GL context.
953 * \param texImage texture image structure to be cleared.
954 *
955 * After the call, \p texImage will have no data associated with it. Its
956 * fields are cleared so that its parent object will test incomplete.
957 */
958 void
959 _mesa_clear_texture_image(GLcontext *ctx, struct gl_texture_image *texImage)
960 {
961 ctx->Driver.FreeTexImageData(ctx, texImage);
962 clear_teximage_fields(texImage);
963 }
964
965
966 /**
967 * Return pointer to texture object for given target on current texture unit.
968 */
969 static struct gl_texture_object *
970 get_current_tex_object(GLcontext *ctx, GLenum target)
971 {
972 struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
973 return _mesa_select_tex_object(ctx, texUnit, target);
974 }
975
976
977
978 /**
979 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
980 * level, width, height and depth against the ctx->Const limits for textures.
981 *
982 * A hardware driver might override this function if, for example, the
983 * max 3D texture size is 512x512x64 (i.e. not a cube).
984 *
985 * Note that width, height, depth == 0 is not an error. However, a
986 * texture with zero width/height/depth will be considered "incomplete"
987 * and texturing will effectively be disabled.
988 *
989 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
990 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
991 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
992 * \param level as passed to glTexImage
993 * \param internalFormat as passed to glTexImage
994 * \param format as passed to glTexImage
995 * \param type as passed to glTexImage
996 * \param width as passed to glTexImage
997 * \param height as passed to glTexImage
998 * \param depth as passed to glTexImage
999 * \param border as passed to glTexImage
1000 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1001 */
1002 GLboolean
1003 _mesa_test_proxy_teximage(GLcontext *ctx, GLenum target, GLint level,
1004 GLint internalFormat, GLenum format, GLenum type,
1005 GLint width, GLint height, GLint depth, GLint border)
1006 {
1007 GLint maxSize;
1008
1009 (void) internalFormat;
1010 (void) format;
1011 (void) type;
1012
1013 switch (target) {
1014 case GL_PROXY_TEXTURE_1D:
1015 maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
1016 if (width < 2 * border || width > 2 + maxSize ||
1017 (!ctx->Extensions.ARB_texture_non_power_of_two &&
1018 width >0 && !_mesa_is_pow_two(width - 2 * border)) ||
1019 level >= ctx->Const.MaxTextureLevels) {
1020 /* bad width or level */
1021 return GL_FALSE;
1022 }
1023 return GL_TRUE;
1024 case GL_PROXY_TEXTURE_2D:
1025 maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
1026 if (width < 2 * border || width > 2 + maxSize ||
1027 (!ctx->Extensions.ARB_texture_non_power_of_two &&
1028 width > 0 && !_mesa_is_pow_two(width - 2 * border)) ||
1029 height < 2 * border || height > 2 + maxSize ||
1030 (!ctx->Extensions.ARB_texture_non_power_of_two &&
1031 height > 0 && !_mesa_is_pow_two(height - 2 * border)) ||
1032 level >= ctx->Const.MaxTextureLevels) {
1033 /* bad width or height or level */
1034 return GL_FALSE;
1035 }
1036 return GL_TRUE;
1037 case GL_PROXY_TEXTURE_3D:
1038 maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1);
1039 if (width < 2 * border || width > 2 + maxSize ||
1040 (!ctx->Extensions.ARB_texture_non_power_of_two &&
1041 width > 0 && !_mesa_is_pow_two(width - 2 * border)) ||
1042 height < 2 * border || height > 2 + maxSize ||
1043 (!ctx->Extensions.ARB_texture_non_power_of_two &&
1044 height > 0 && !_mesa_is_pow_two(height - 2 * border)) ||
1045 depth < 2 * border || depth > 2 + maxSize ||
1046 (!ctx->Extensions.ARB_texture_non_power_of_two &&
1047 depth > 0 && !_mesa_is_pow_two(depth - 2 * border)) ||
1048 level >= ctx->Const.Max3DTextureLevels) {
1049 /* bad width or height or depth or level */
1050 return GL_FALSE;
1051 }
1052 return GL_TRUE;
1053 case GL_PROXY_TEXTURE_RECTANGLE_NV:
1054 if (width < 0 || width > ctx->Const.MaxTextureRectSize ||
1055 height < 0 || height > ctx->Const.MaxTextureRectSize ||
1056 level != 0) {
1057 /* bad width or height or level */
1058 return GL_FALSE;
1059 }
1060 return GL_TRUE;
1061 case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
1062 maxSize = 1 << (ctx->Const.MaxCubeTextureLevels - 1);
1063 if (width < 2 * border || width > 2 + maxSize ||
1064 (!ctx->Extensions.ARB_texture_non_power_of_two &&
1065 width > 0 && !_mesa_is_pow_two(width - 2 * border)) ||
1066 height < 2 * border || height > 2 + maxSize ||
1067 (!ctx->Extensions.ARB_texture_non_power_of_two &&
1068 height > 0 && !_mesa_is_pow_two(height - 2 * border)) ||
1069 level >= ctx->Const.MaxCubeTextureLevels) {
1070 /* bad width or height */
1071 return GL_FALSE;
1072 }
1073 return GL_TRUE;
1074 case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
1075 maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
1076 if (width < 2 * border || width > 2 + maxSize ||
1077 (!ctx->Extensions.ARB_texture_non_power_of_two &&
1078 width > 0 && !_mesa_is_pow_two(width - 2 * border)) ||
1079 level >= ctx->Const.MaxTextureLevels) {
1080 /* bad width or level */
1081 return GL_FALSE;
1082 }
1083
1084 if (height < 1 || height > ctx->Const.MaxArrayTextureLayers) {
1085 return GL_FALSE;
1086 }
1087 return GL_TRUE;
1088 case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
1089 maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
1090 if (width < 2 * border || width > 2 + maxSize ||
1091 (!ctx->Extensions.ARB_texture_non_power_of_two &&
1092 width > 0 && !_mesa_is_pow_two(width - 2 * border)) ||
1093 height < 2 * border || height > 2 + maxSize ||
1094 (!ctx->Extensions.ARB_texture_non_power_of_two &&
1095 height > 0 && !_mesa_is_pow_two(height - 2 * border)) ||
1096 level >= ctx->Const.MaxTextureLevels) {
1097 /* bad width or height or level */
1098 return GL_FALSE;
1099 }
1100 if (depth < 1 || depth > ctx->Const.MaxArrayTextureLayers) {
1101 return GL_FALSE;
1102 }
1103 return GL_TRUE;
1104 default:
1105 _mesa_problem(ctx, "Invalid target in _mesa_test_proxy_teximage");
1106 return GL_FALSE;
1107 }
1108 }
1109
1110
1111 /**
1112 * Helper function to determine whether a target supports compressed textures
1113 */
1114 static GLboolean
1115 target_can_be_compressed(GLcontext *ctx, GLenum target)
1116 {
1117 return (((target == GL_TEXTURE_2D || target == GL_PROXY_TEXTURE_2D))
1118 || ((ctx->Extensions.ARB_texture_cube_map &&
1119 (target == GL_PROXY_TEXTURE_CUBE_MAP ||
1120 (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X &&
1121 target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z))))
1122 || ((ctx->Extensions.MESA_texture_array &&
1123 ((target == GL_PROXY_TEXTURE_2D_ARRAY_EXT) ||
1124 (target == GL_TEXTURE_2D_ARRAY_EXT)))));
1125 }
1126
1127
1128 /**
1129 * Test the glTexImage[123]D() parameters for errors.
1130 *
1131 * \param ctx GL context.
1132 * \param target texture target given by the user.
1133 * \param level image level given by the user.
1134 * \param internalFormat internal format given by the user.
1135 * \param format pixel data format given by the user.
1136 * \param type pixel data type given by the user.
1137 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1138 * \param width image width given by the user.
1139 * \param height image height given by the user.
1140 * \param depth image depth given by the user.
1141 * \param border image border given by the user.
1142 *
1143 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1144 *
1145 * Verifies each of the parameters against the constants specified in
1146 * __GLcontextRec::Const and the supported extensions, and according to the
1147 * OpenGL specification.
1148 */
1149 static GLboolean
1150 texture_error_check( GLcontext *ctx, GLenum target,
1151 GLint level, GLint internalFormat,
1152 GLenum format, GLenum type,
1153 GLuint dimensions,
1154 GLint width, GLint height,
1155 GLint depth, GLint border )
1156 {
1157 const GLboolean isProxy = _mesa_is_proxy_texture(target);
1158 GLboolean sizeOK = GL_TRUE;
1159 GLboolean colorFormat, indexFormat;
1160 GLenum proxy_target;
1161
1162 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1163 if (level < 0 || level >= MAX_TEXTURE_LEVELS) {
1164 if (!isProxy) {
1165 _mesa_error(ctx, GL_INVALID_VALUE,
1166 "glTexImage%dD(level=%d)", dimensions, level);
1167 }
1168 return GL_TRUE;
1169 }
1170
1171 /* Check border */
1172 if (border < 0 || border > 1 ||
1173 ((target == GL_TEXTURE_RECTANGLE_NV ||
1174 target == GL_PROXY_TEXTURE_RECTANGLE_NV) && border != 0)) {
1175 if (!isProxy) {
1176 _mesa_error(ctx, GL_INVALID_VALUE,
1177 "glTexImage%dD(border=%d)", dimensions, border);
1178 }
1179 return GL_TRUE;
1180 }
1181
1182 if (width < 0 || height < 0 || depth < 0) {
1183 if (!isProxy) {
1184 _mesa_error(ctx, GL_INVALID_VALUE,
1185 "glTexImage%dD(width, height or depth < 0)", dimensions);
1186 }
1187 return GL_TRUE;
1188 }
1189
1190 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1191 * level, width, height and depth.
1192 */
1193 if (dimensions == 1) {
1194 if (target == GL_PROXY_TEXTURE_1D || target == GL_TEXTURE_1D) {
1195 proxy_target = GL_PROXY_TEXTURE_1D;
1196 height = 1;
1197 depth = 1;
1198 }
1199 else {
1200 _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage1D(target)" );
1201 return GL_TRUE;
1202 }
1203 }
1204 else if (dimensions == 2) {
1205 depth = 1;
1206 if (target == GL_PROXY_TEXTURE_2D || target == GL_TEXTURE_2D) {
1207 proxy_target = GL_PROXY_TEXTURE_2D;
1208 }
1209 else if (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB ||
1210 (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
1211 target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)) {
1212 if (!ctx->Extensions.ARB_texture_cube_map) {
1213 _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage2D(target)");
1214 return GL_TRUE;
1215 }
1216 proxy_target = GL_PROXY_TEXTURE_CUBE_MAP_ARB;
1217 sizeOK = (width == height);
1218 }
1219 else if (target == GL_PROXY_TEXTURE_RECTANGLE_NV ||
1220 target == GL_TEXTURE_RECTANGLE_NV) {
1221 if (!ctx->Extensions.NV_texture_rectangle) {
1222 _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage2D(target)");
1223 return GL_TRUE;
1224 }
1225 proxy_target = GL_PROXY_TEXTURE_RECTANGLE_NV;
1226 }
1227 else if (target == GL_PROXY_TEXTURE_1D_ARRAY_EXT ||
1228 target == GL_TEXTURE_1D_ARRAY_EXT) {
1229 proxy_target = GL_PROXY_TEXTURE_1D_ARRAY_EXT;
1230 }
1231 else {
1232 _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage2D(target)");
1233 return GL_TRUE;
1234 }
1235 }
1236 else if (dimensions == 3) {
1237 if (target == GL_PROXY_TEXTURE_3D || target == GL_TEXTURE_3D) {
1238 proxy_target = GL_PROXY_TEXTURE_3D;
1239 }
1240 else if (target == GL_PROXY_TEXTURE_2D_ARRAY_EXT ||
1241 target == GL_TEXTURE_2D_ARRAY_EXT) {
1242 proxy_target = GL_PROXY_TEXTURE_2D_ARRAY_EXT;
1243 }
1244 else {
1245 _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage3D(target)" );
1246 return GL_TRUE;
1247 }
1248 }
1249 else {
1250 _mesa_problem( ctx, "bad dims in texture_error_check" );
1251 return GL_TRUE;
1252 }
1253
1254 sizeOK = sizeOK && ctx->Driver.TestProxyTexImage(ctx, proxy_target, level,
1255 internalFormat, format,
1256 type, width, height,
1257 depth, border);
1258 if (!sizeOK) {
1259 if (!isProxy) {
1260 _mesa_error(ctx, GL_INVALID_VALUE,
1261 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1262 dimensions, level, width, height, depth);
1263 }
1264 return GL_TRUE;
1265 }
1266
1267 /* Check internalFormat */
1268 if (_mesa_base_tex_format(ctx, internalFormat) < 0) {
1269 if (!isProxy) {
1270 _mesa_error(ctx, GL_INVALID_VALUE,
1271 "glTexImage%dD(internalFormat=%s)",
1272 dimensions, _mesa_lookup_enum_by_nr(internalFormat));
1273 }
1274 return GL_TRUE;
1275 }
1276
1277 /* Check incoming image format and type */
1278 if (!_mesa_is_legal_format_and_type(ctx, format, type)) {
1279 /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there
1280 * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4.
1281 */
1282 if (!isProxy) {
1283 _mesa_error(ctx, GL_INVALID_OPERATION,
1284 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1285 dimensions, format, type);
1286 }
1287 return GL_TRUE;
1288 }
1289
1290 /* make sure internal format and format basically agree */
1291 colorFormat = _mesa_is_color_format(format);
1292 indexFormat = _mesa_is_index_format(format);
1293 if ((_mesa_is_color_format(internalFormat) && !colorFormat && !indexFormat) ||
1294 (_mesa_is_index_format(internalFormat) && !indexFormat) ||
1295 (_mesa_is_depth_format(internalFormat) != _mesa_is_depth_format(format)) ||
1296 (_mesa_is_ycbcr_format(internalFormat) != _mesa_is_ycbcr_format(format)) ||
1297 (_mesa_is_depthstencil_format(internalFormat) != _mesa_is_depthstencil_format(format)) ||
1298 (_mesa_is_dudv_format(internalFormat) != _mesa_is_dudv_format(format))) {
1299 if (!isProxy)
1300 _mesa_error(ctx, GL_INVALID_OPERATION,
1301 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1302 dimensions, internalFormat, format);
1303 return GL_TRUE;
1304 }
1305
1306 /* additional checks for ycbcr textures */
1307 if (internalFormat == GL_YCBCR_MESA) {
1308 ASSERT(ctx->Extensions.MESA_ycbcr_texture);
1309 if (type != GL_UNSIGNED_SHORT_8_8_MESA &&
1310 type != GL_UNSIGNED_SHORT_8_8_REV_MESA) {
1311 char message[100];
1312 _mesa_sprintf(message,
1313 "glTexImage%d(format/type YCBCR mismatch", dimensions);
1314 _mesa_error(ctx, GL_INVALID_ENUM, message);
1315 return GL_TRUE; /* error */
1316 }
1317 if (target != GL_TEXTURE_2D &&
1318 target != GL_PROXY_TEXTURE_2D &&
1319 target != GL_TEXTURE_RECTANGLE_NV &&
1320 target != GL_PROXY_TEXTURE_RECTANGLE_NV) {
1321 if (!isProxy)
1322 _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage(target)");
1323 return GL_TRUE;
1324 }
1325 if (border != 0) {
1326 if (!isProxy) {
1327 char message[100];
1328 _mesa_sprintf(message,
1329 "glTexImage%d(format=GL_YCBCR_MESA and border=%d)",
1330 dimensions, border);
1331 _mesa_error(ctx, GL_INVALID_VALUE, message);
1332 }
1333 return GL_TRUE;
1334 }
1335 }
1336
1337 /* additional checks for depth textures */
1338 if (_mesa_base_tex_format(ctx, internalFormat) == GL_DEPTH_COMPONENT) {
1339 /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
1340 if (target != GL_TEXTURE_1D &&
1341 target != GL_PROXY_TEXTURE_1D &&
1342 target != GL_TEXTURE_2D &&
1343 target != GL_PROXY_TEXTURE_2D &&
1344 target != GL_TEXTURE_RECTANGLE_ARB &&
1345 target != GL_PROXY_TEXTURE_RECTANGLE_ARB) {
1346 if (!isProxy)
1347 _mesa_error(ctx, GL_INVALID_ENUM,
1348 "glTexImage(target/internalFormat)");
1349 return GL_TRUE;
1350 }
1351 }
1352
1353 /* additional checks for compressed textures */
1354 if (is_compressed_format(ctx, internalFormat)) {
1355 if (!target_can_be_compressed(ctx, target) && !isProxy) {
1356 _mesa_error(ctx, GL_INVALID_ENUM,
1357 "glTexImage%d(target)", dimensions);
1358 return GL_TRUE;
1359 }
1360 if (border != 0) {
1361 if (!isProxy) {
1362 _mesa_error(ctx, GL_INVALID_OPERATION,
1363 "glTexImage%D(border!=0)", dimensions);
1364 }
1365 return GL_TRUE;
1366 }
1367 }
1368
1369 /* if we get here, the parameters are OK */
1370 return GL_FALSE;
1371 }
1372
1373
1374 /**
1375 * Test glTexSubImage[123]D() parameters for errors.
1376 *
1377 * \param ctx GL context.
1378 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1379 * \param target texture target given by the user.
1380 * \param level image level given by the user.
1381 * \param xoffset sub-image x offset given by the user.
1382 * \param yoffset sub-image y offset given by the user.
1383 * \param zoffset sub-image z offset given by the user.
1384 * \param format pixel data format given by the user.
1385 * \param type pixel data type given by the user.
1386 * \param width image width given by the user.
1387 * \param height image height given by the user.
1388 * \param depth image depth given by the user.
1389 *
1390 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1391 *
1392 * Verifies each of the parameters against the constants specified in
1393 * __GLcontextRec::Const and the supported extensions, and according to the
1394 * OpenGL specification.
1395 */
1396 static GLboolean
1397 subtexture_error_check( GLcontext *ctx, GLuint dimensions,
1398 GLenum target, GLint level,
1399 GLint xoffset, GLint yoffset, GLint zoffset,
1400 GLint width, GLint height, GLint depth,
1401 GLenum format, GLenum type )
1402 {
1403 /* Check target */
1404 if (dimensions == 1) {
1405 if (target != GL_TEXTURE_1D) {
1406 _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage1D(target)" );
1407 return GL_TRUE;
1408 }
1409 }
1410 else if (dimensions == 2) {
1411 if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
1412 target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) {
1413 if (!ctx->Extensions.ARB_texture_cube_map) {
1414 _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" );
1415 return GL_TRUE;
1416 }
1417 }
1418 else if (target == GL_TEXTURE_RECTANGLE_NV) {
1419 if (!ctx->Extensions.NV_texture_rectangle) {
1420 _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" );
1421 return GL_TRUE;
1422 }
1423 }
1424 else if (target == GL_TEXTURE_1D_ARRAY_EXT) {
1425 if (!ctx->Extensions.MESA_texture_array) {
1426 _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" );
1427 return GL_TRUE;
1428 }
1429 }
1430 else if (target != GL_TEXTURE_2D) {
1431 _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" );
1432 return GL_TRUE;
1433 }
1434 }
1435 else if (dimensions == 3) {
1436 if (target == GL_TEXTURE_2D_ARRAY_EXT) {
1437 if (!ctx->Extensions.MESA_texture_array) {
1438 _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage3D(target)" );
1439 return GL_TRUE;
1440 }
1441 }
1442 else if (target != GL_TEXTURE_3D) {
1443 _mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage3D(target)" );
1444 return GL_TRUE;
1445 }
1446 }
1447 else {
1448 _mesa_problem( ctx, "invalid dims in texture_error_check" );
1449 return GL_TRUE;
1450 }
1451
1452 /* Basic level check */
1453 if (level < 0 || level >= MAX_TEXTURE_LEVELS) {
1454 _mesa_error(ctx, GL_INVALID_ENUM, "glTexSubImage2D(level=%d)", level);
1455 return GL_TRUE;
1456 }
1457
1458 if (width < 0) {
1459 _mesa_error(ctx, GL_INVALID_VALUE,
1460 "glTexSubImage%dD(width=%d)", dimensions, width);
1461 return GL_TRUE;
1462 }
1463 if (height < 0 && dimensions > 1) {
1464 _mesa_error(ctx, GL_INVALID_VALUE,
1465 "glTexSubImage%dD(height=%d)", dimensions, height);
1466 return GL_TRUE;
1467 }
1468 if (depth < 0 && dimensions > 2) {
1469 _mesa_error(ctx, GL_INVALID_VALUE,
1470 "glTexSubImage%dD(depth=%d)", dimensions, depth);
1471 return GL_TRUE;
1472 }
1473
1474 if (!_mesa_is_legal_format_and_type(ctx, format, type)) {
1475 _mesa_error(ctx, GL_INVALID_ENUM,
1476 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1477 dimensions, format, type);
1478 return GL_TRUE;
1479 }
1480
1481 return GL_FALSE;
1482 }
1483
1484
1485 /**
1486 * Do second part of glTexSubImage which depends on the destination texture.
1487 * \return GL_TRUE if error recorded, GL_FALSE otherwise
1488 */
1489 static GLboolean
1490 subtexture_error_check2( GLcontext *ctx, GLuint dimensions,
1491 GLenum target, GLint level,
1492 GLint xoffset, GLint yoffset, GLint zoffset,
1493 GLint width, GLint height, GLint depth,
1494 GLenum format, GLenum type,
1495 const struct gl_texture_image *destTex )
1496 {
1497 if (!destTex) {
1498 /* undefined image level */
1499 _mesa_error(ctx, GL_INVALID_OPERATION, "glTexSubImage%dD", dimensions);
1500 return GL_TRUE;
1501 }
1502
1503 if (xoffset < -((GLint)destTex->Border)) {
1504 _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(xoffset)",
1505 dimensions);
1506 return GL_TRUE;
1507 }
1508 if (xoffset + width > (GLint) (destTex->Width + destTex->Border)) {
1509 _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(xoffset+width)",
1510 dimensions);
1511 return GL_TRUE;
1512 }
1513 if (dimensions > 1) {
1514 if (yoffset < -((GLint)destTex->Border)) {
1515 _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(yoffset)",
1516 dimensions);
1517 return GL_TRUE;
1518 }
1519 if (yoffset + height > (GLint) (destTex->Height + destTex->Border)) {
1520 _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage%dD(yoffset+height)",
1521 dimensions);
1522 return GL_TRUE;
1523 }
1524 }
1525 if (dimensions > 2) {
1526 if (zoffset < -((GLint)destTex->Border)) {
1527 _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset)");
1528 return GL_TRUE;
1529 }
1530 if (zoffset + depth > (GLint) (destTex->Depth + destTex->Border)) {
1531 _mesa_error(ctx, GL_INVALID_VALUE, "glTexSubImage3D(zoffset+depth)");
1532 return GL_TRUE;
1533 }
1534 }
1535
1536 if (_mesa_is_format_compressed(destTex->TexFormat)) {
1537 GLuint bw, bh;
1538
1539 if (!target_can_be_compressed(ctx, target)) {
1540 _mesa_error(ctx, GL_INVALID_ENUM,
1541 "glTexSubImage%D(target=%s)", dimensions,
1542 _mesa_lookup_enum_by_nr(target));
1543 return GL_TRUE;
1544 }
1545
1546 /* do tests which depend on compression block size */
1547 _mesa_get_format_block_size(destTex->TexFormat, &bw, &bh);
1548
1549 /* offset must be multiple of block size */
1550 if ((xoffset % bw != 0) || (yoffset % bh != 0)) {
1551 _mesa_error(ctx, GL_INVALID_OPERATION,
1552 "glTexSubImage%D(xoffset = %d, yoffset = %d)",
1553 dimensions, xoffset, yoffset);
1554 return GL_TRUE;
1555 }
1556 /* size must be multiple of bw by bh or equal to whole texture size */
1557 if ((width % bw != 0) && (GLuint) width != destTex->Width) {
1558 _mesa_error(ctx, GL_INVALID_OPERATION,
1559 "glTexSubImage%D(width = %d)", dimensions, width);
1560 return GL_TRUE;
1561 }
1562 if ((height % bh != 0) && (GLuint) height != destTex->Height) {
1563 _mesa_error(ctx, GL_INVALID_OPERATION,
1564 "glTexSubImage%D(height = %d)", dimensions, height);
1565 return GL_TRUE;
1566 }
1567 }
1568
1569 return GL_FALSE;
1570 }
1571
1572
1573 /**
1574 * Test glCopyTexImage[12]D() parameters for errors.
1575 *
1576 * \param ctx GL context.
1577 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1578 * \param target texture target given by the user.
1579 * \param level image level given by the user.
1580 * \param internalFormat internal format given by the user.
1581 * \param width image width given by the user.
1582 * \param height image height given by the user.
1583 * \param border texture border.
1584 *
1585 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1586 *
1587 * Verifies each of the parameters against the constants specified in
1588 * __GLcontextRec::Const and the supported extensions, and according to the
1589 * OpenGL specification.
1590 */
1591 static GLboolean
1592 copytexture_error_check( GLcontext *ctx, GLuint dimensions,
1593 GLenum target, GLint level, GLint internalFormat,
1594 GLint width, GLint height, GLint border )
1595 {
1596 GLenum type;
1597 GLboolean sizeOK;
1598 GLint format;
1599
1600 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1601 if (level < 0 || level >= MAX_TEXTURE_LEVELS) {
1602 _mesa_error(ctx, GL_INVALID_VALUE,
1603 "glCopyTexImage%dD(level=%d)", dimensions, level);
1604 return GL_TRUE;
1605 }
1606
1607 /* Check that the source buffer is complete */
1608 if (ctx->ReadBuffer->Name) {
1609 _mesa_test_framebuffer_completeness(ctx, ctx->ReadBuffer);
1610 if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
1611 _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
1612 "glCopyTexImage%dD(invalid readbuffer)", dimensions);
1613 return GL_TRUE;
1614 }
1615 }
1616
1617 /* Check border */
1618 if (border < 0 || border > 1 ||
1619 ((target == GL_TEXTURE_RECTANGLE_NV ||
1620 target == GL_PROXY_TEXTURE_RECTANGLE_NV) && border != 0)) {
1621 return GL_TRUE;
1622 }
1623
1624 format = _mesa_base_tex_format(ctx, internalFormat);
1625 if (format < 0) {
1626 _mesa_error(ctx, GL_INVALID_VALUE,
1627 "glCopyTexImage%dD(internalFormat)", dimensions);
1628 return GL_TRUE;
1629 }
1630
1631 if (!_mesa_source_buffer_exists(ctx, format)) {
1632 _mesa_error(ctx, GL_INVALID_OPERATION,
1633 "glCopyTexImage%dD(missing readbuffer)", dimensions);
1634 return GL_TRUE;
1635 }
1636
1637 /* NOTE: the format and type aren't really significant for
1638 * TestProxyTexImage(). Only the internalformat really matters.
1639 */
1640 type = GL_FLOAT;
1641
1642 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1643 * level, width, height and depth.
1644 */
1645 if (dimensions == 1) {
1646 if (target == GL_TEXTURE_1D) {
1647 sizeOK = ctx->Driver.TestProxyTexImage(ctx, GL_PROXY_TEXTURE_1D,
1648 level, internalFormat,
1649 format, type,
1650 width, 1, 1, border);
1651 }
1652 else {
1653 _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexImage1D(target)" );
1654 return GL_TRUE;
1655 }
1656 }
1657 else if (dimensions == 2) {
1658 if (target == GL_TEXTURE_2D) {
1659 sizeOK = ctx->Driver.TestProxyTexImage(ctx, GL_PROXY_TEXTURE_2D,
1660 level, internalFormat,
1661 format, type,
1662 width, height, 1, border);
1663 }
1664 else if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
1665 target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) {
1666 if (!ctx->Extensions.ARB_texture_cube_map) {
1667 _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" );
1668 return GL_TRUE;
1669 }
1670 sizeOK = (width == height) &&
1671 ctx->Driver.TestProxyTexImage(ctx, GL_PROXY_TEXTURE_CUBE_MAP_ARB,
1672 level, internalFormat, format, type,
1673 width, height, 1, border);
1674 }
1675 else if (target == GL_TEXTURE_RECTANGLE_NV) {
1676 if (!ctx->Extensions.NV_texture_rectangle) {
1677 _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" );
1678 return GL_TRUE;
1679 }
1680 sizeOK = ctx->Driver.TestProxyTexImage(ctx,
1681 GL_PROXY_TEXTURE_RECTANGLE_NV,
1682 level, internalFormat,
1683 format, type,
1684 width, height, 1, border);
1685 }
1686 else if (target == GL_TEXTURE_1D_ARRAY_EXT) {
1687 if (!ctx->Extensions.MESA_texture_array) {
1688 _mesa_error(ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)");
1689 return GL_TRUE;
1690 }
1691 sizeOK = ctx->Driver.TestProxyTexImage(ctx,
1692 GL_PROXY_TEXTURE_1D_ARRAY_EXT,
1693 level, internalFormat,
1694 format, type,
1695 width, height, 1, border);
1696 }
1697 else {
1698 _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" );
1699 return GL_TRUE;
1700 }
1701 }
1702 else {
1703 _mesa_problem(ctx, "invalid dimensions in copytexture_error_check");
1704 return GL_TRUE;
1705 }
1706
1707 if (!sizeOK) {
1708 if (dimensions == 1) {
1709 _mesa_error(ctx, GL_INVALID_VALUE,
1710 "glCopyTexImage1D(width=%d)", width);
1711 }
1712 else {
1713 ASSERT(dimensions == 2);
1714 _mesa_error(ctx, GL_INVALID_VALUE,
1715 "glCopyTexImage2D(width=%d, height=%d)", width, height);
1716 }
1717 return GL_TRUE;
1718 }
1719
1720 if (is_compressed_format(ctx, internalFormat)) {
1721 if (!target_can_be_compressed(ctx, target)) {
1722 _mesa_error(ctx, GL_INVALID_ENUM,
1723 "glCopyTexImage%d(target)", dimensions);
1724 return GL_TRUE;
1725 }
1726 if (border != 0) {
1727 _mesa_error(ctx, GL_INVALID_OPERATION,
1728 "glCopyTexImage%D(border!=0)", dimensions);
1729 return GL_TRUE;
1730 }
1731 }
1732 else if (_mesa_is_depth_format(internalFormat)) {
1733 /* make sure we have depth/stencil buffers */
1734 if (!ctx->ReadBuffer->_DepthBuffer) {
1735 _mesa_error(ctx, GL_INVALID_OPERATION,
1736 "glCopyTexImage%D(no depth)", dimensions);
1737 return GL_TRUE;
1738 }
1739 }
1740 else if (_mesa_is_depthstencil_format(internalFormat)) {
1741 /* make sure we have depth/stencil buffers */
1742 if (!ctx->ReadBuffer->_DepthBuffer || !ctx->ReadBuffer->_StencilBuffer) {
1743 _mesa_error(ctx, GL_INVALID_OPERATION,
1744 "glCopyTexImage%D(no depth/stencil buffer)", dimensions);
1745 return GL_TRUE;
1746 }
1747 }
1748
1749 /* if we get here, the parameters are OK */
1750 return GL_FALSE;
1751 }
1752
1753
1754 /**
1755 * Test glCopyTexSubImage[12]D() parameters for errors.
1756 * Note that this is the first part of error checking.
1757 * See also copytexsubimage_error_check2() below for the second part.
1758 *
1759 * \param ctx GL context.
1760 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1761 * \param target texture target given by the user.
1762 * \param level image level given by the user.
1763 *
1764 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1765 */
1766 static GLboolean
1767 copytexsubimage_error_check1( GLcontext *ctx, GLuint dimensions,
1768 GLenum target, GLint level)
1769 {
1770 /* Check that the source buffer is complete */
1771 if (ctx->ReadBuffer->Name) {
1772 _mesa_test_framebuffer_completeness(ctx, ctx->ReadBuffer);
1773 if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
1774 _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
1775 "glCopyTexImage%dD(invalid readbuffer)", dimensions);
1776 return GL_TRUE;
1777 }
1778 }
1779
1780 /* Check target */
1781 if (dimensions == 1) {
1782 if (target != GL_TEXTURE_1D) {
1783 _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage1D(target)" );
1784 return GL_TRUE;
1785 }
1786 }
1787 else if (dimensions == 2) {
1788 if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
1789 target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) {
1790 if (!ctx->Extensions.ARB_texture_cube_map) {
1791 _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" );
1792 return GL_TRUE;
1793 }
1794 }
1795 else if (target == GL_TEXTURE_RECTANGLE_NV) {
1796 if (!ctx->Extensions.NV_texture_rectangle) {
1797 _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" );
1798 return GL_TRUE;
1799 }
1800 }
1801 else if (target == GL_TEXTURE_1D_ARRAY_EXT) {
1802 if (!ctx->Extensions.MESA_texture_array) {
1803 _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" );
1804 return GL_TRUE;
1805 }
1806 }
1807 else if (target != GL_TEXTURE_2D) {
1808 _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" );
1809 return GL_TRUE;
1810 }
1811 }
1812 else if (dimensions == 3) {
1813 if (((target != GL_TEXTURE_2D_ARRAY_EXT) ||
1814 (!ctx->Extensions.MESA_texture_array))
1815 && (target != GL_TEXTURE_3D)) {
1816 _mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage3D(target)" );
1817 return GL_TRUE;
1818 }
1819 }
1820
1821 /* Check level */
1822 if (level < 0 || level >= MAX_TEXTURE_LEVELS) {
1823 _mesa_error(ctx, GL_INVALID_VALUE,
1824 "glCopyTexSubImage%dD(level=%d)", dimensions, level);
1825 return GL_TRUE;
1826 }
1827
1828 return GL_FALSE;
1829 }
1830
1831
1832 /**
1833 * Second part of error checking for glCopyTexSubImage[12]D().
1834 * \param xoffset sub-image x offset given by the user.
1835 * \param yoffset sub-image y offset given by the user.
1836 * \param zoffset sub-image z offset given by the user.
1837 * \param width image width given by the user.
1838 * \param height image height given by the user.
1839 */
1840 static GLboolean
1841 copytexsubimage_error_check2( GLcontext *ctx, GLuint dimensions,
1842 GLenum target, GLint level,
1843 GLint xoffset, GLint yoffset, GLint zoffset,
1844 GLsizei width, GLsizei height,
1845 const struct gl_texture_image *teximage )
1846 {
1847 /* check that dest tex image exists */
1848 if (!teximage) {
1849 _mesa_error(ctx, GL_INVALID_OPERATION,
1850 "glCopyTexSubImage%dD(undefined texture level: %d)",
1851 dimensions, level);
1852 return GL_TRUE;
1853 }
1854
1855 /* Check size */
1856 if (width < 0) {
1857 _mesa_error(ctx, GL_INVALID_VALUE,
1858 "glCopyTexSubImage%dD(width=%d)", dimensions, width);
1859 return GL_TRUE;
1860 }
1861 if (dimensions > 1 && height < 0) {
1862 _mesa_error(ctx, GL_INVALID_VALUE,
1863 "glCopyTexSubImage%dD(height=%d)", dimensions, height);
1864 return GL_TRUE;
1865 }
1866
1867 /* check x/y offsets */
1868 if (xoffset < -((GLint)teximage->Border)) {
1869 _mesa_error(ctx, GL_INVALID_VALUE,
1870 "glCopyTexSubImage%dD(xoffset=%d)", dimensions, xoffset);
1871 return GL_TRUE;
1872 }
1873 if (xoffset + width > (GLint) (teximage->Width + teximage->Border)) {
1874 _mesa_error(ctx, GL_INVALID_VALUE,
1875 "glCopyTexSubImage%dD(xoffset+width)", dimensions);
1876 return GL_TRUE;
1877 }
1878 if (dimensions > 1) {
1879 if (yoffset < -((GLint)teximage->Border)) {
1880 _mesa_error(ctx, GL_INVALID_VALUE,
1881 "glCopyTexSubImage%dD(yoffset=%d)", dimensions, yoffset);
1882 return GL_TRUE;
1883 }
1884 /* NOTE: we're adding the border here, not subtracting! */
1885 if (yoffset + height > (GLint) (teximage->Height + teximage->Border)) {
1886 _mesa_error(ctx, GL_INVALID_VALUE,
1887 "glCopyTexSubImage%dD(yoffset+height)", dimensions);
1888 return GL_TRUE;
1889 }
1890 }
1891
1892 /* check z offset */
1893 if (dimensions > 2) {
1894 if (zoffset < -((GLint)teximage->Border)) {
1895 _mesa_error(ctx, GL_INVALID_VALUE,
1896 "glCopyTexSubImage%dD(zoffset)", dimensions);
1897 return GL_TRUE;
1898 }
1899 if (zoffset > (GLint) (teximage->Depth + teximage->Border)) {
1900 _mesa_error(ctx, GL_INVALID_VALUE,
1901 "glCopyTexSubImage%dD(zoffset+depth)", dimensions);
1902 return GL_TRUE;
1903 }
1904 }
1905
1906 if (_mesa_is_format_compressed(teximage->TexFormat)) {
1907 if (!target_can_be_compressed(ctx, target)) {
1908 _mesa_error(ctx, GL_INVALID_ENUM,
1909 "glCopyTexSubImage%d(target)", dimensions);
1910 return GL_TRUE;
1911 }
1912 /* offset must be multiple of 4 */
1913 if ((xoffset & 3) || (yoffset & 3)) {
1914 _mesa_error(ctx, GL_INVALID_VALUE,
1915 "glCopyTexSubImage%D(xoffset or yoffset)", dimensions);
1916 return GL_TRUE;
1917 }
1918 /* size must be multiple of 4 */
1919 if ((width & 3) != 0 && (GLuint) width != teximage->Width) {
1920 _mesa_error(ctx, GL_INVALID_VALUE,
1921 "glCopyTexSubImage%D(width)", dimensions);
1922 return GL_TRUE;
1923 }
1924 if ((height & 3) != 0 && (GLuint) height != teximage->Height) {
1925 _mesa_error(ctx, GL_INVALID_VALUE,
1926 "glCopyTexSubImage%D(height)", dimensions);
1927 return GL_TRUE;
1928 }
1929 }
1930
1931 if (teximage->InternalFormat == GL_YCBCR_MESA) {
1932 _mesa_error(ctx, GL_INVALID_OPERATION, "glCopyTexSubImage2D");
1933 return GL_TRUE;
1934 }
1935
1936 if (!_mesa_source_buffer_exists(ctx, teximage->_BaseFormat)) {
1937 _mesa_error(ctx, GL_INVALID_OPERATION,
1938 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
1939 dimensions, teximage->_BaseFormat);
1940 return GL_TRUE;
1941 }
1942
1943 if (teximage->_BaseFormat == GL_DEPTH_COMPONENT) {
1944 if (!ctx->ReadBuffer->_DepthBuffer) {
1945 _mesa_error(ctx, GL_INVALID_OPERATION,
1946 "glCopyTexSubImage%D(no depth buffer)",
1947 dimensions);
1948 return GL_TRUE;
1949 }
1950 }
1951 else if (teximage->_BaseFormat == GL_DEPTH_STENCIL_EXT) {
1952 if (!ctx->ReadBuffer->_DepthBuffer || !ctx->ReadBuffer->_StencilBuffer) {
1953 _mesa_error(ctx, GL_INVALID_OPERATION,
1954 "glCopyTexSubImage%D(no depth/stencil buffer)",
1955 dimensions);
1956 return GL_TRUE;
1957 }
1958 }
1959
1960 /* if we get here, the parameters are OK */
1961 return GL_FALSE;
1962 }
1963
1964
1965 /** Callback info for walking over FBO hash table */
1966 struct cb_info
1967 {
1968 GLcontext *ctx;
1969 struct gl_texture_object *texObj;
1970 GLuint level, face;
1971 };
1972
1973
1974 /**
1975 * Check render to texture callback. Called from _mesa_HashWalk().
1976 */
1977 static void
1978 check_rtt_cb(GLuint key, void *data, void *userData)
1979 {
1980 struct gl_framebuffer *fb = (struct gl_framebuffer *) data;
1981 const struct cb_info *info = (struct cb_info *) userData;
1982 GLcontext *ctx = info->ctx;
1983 const struct gl_texture_object *texObj = info->texObj;
1984 const GLuint level = info->level, face = info->face;
1985
1986 /* If this is a user-created FBO */
1987 if (fb->Name) {
1988 GLuint i;
1989 /* check if any of the FBO's attachments point to 'texObj' */
1990 for (i = 0; i < BUFFER_COUNT; i++) {
1991 struct gl_renderbuffer_attachment *att = fb->Attachment + i;
1992 if (att->Type == GL_TEXTURE &&
1993 att->Texture == texObj &&
1994 att->TextureLevel == level &&
1995 att->CubeMapFace == face) {
1996 ASSERT(att->Texture->Image[att->CubeMapFace][att->TextureLevel]);
1997 /* Tell driver about the new renderbuffer texture */
1998 ctx->Driver.RenderTexture(ctx, ctx->DrawBuffer, att);
1999 /* Mark fb status as indeterminate to force re-validation */
2000 fb->_Status = 0;
2001 }
2002 }
2003 }
2004 }
2005
2006
2007 /**
2008 * When a texture image is specified we have to check if it's bound to
2009 * any framebuffer objects (render to texture) in order to detect changes
2010 * in size or format since that effects FBO completeness.
2011 * Any FBOs rendering into the texture must be re-validated.
2012 */
2013 static void
2014 update_fbo_texture(GLcontext *ctx, struct gl_texture_object *texObj,
2015 GLuint face, GLuint level)
2016 {
2017 /* Only check this texture if it's been marked as RenderToTexture */
2018 if (texObj->_RenderToTexture) {
2019 struct cb_info info;
2020 info.ctx = ctx;
2021 info.texObj = texObj;
2022 info.level = level;
2023 info.face = face;
2024 _mesa_HashWalk(ctx->Shared->FrameBuffers, check_rtt_cb, &info);
2025 }
2026 }
2027
2028
2029 /**
2030 * If the texture object's GenerateMipmap flag is set and we've
2031 * changed the texture base level image, regenerate the rest of the
2032 * mipmap levels now.
2033 */
2034 static INLINE void
2035 check_gen_mipmap(GLcontext *ctx, GLenum target,
2036 struct gl_texture_object *texObj, GLint level)
2037 {
2038 ASSERT(target != GL_TEXTURE_CUBE_MAP);
2039 if (texObj->GenerateMipmap && level == texObj->BaseLevel) {
2040 ASSERT(ctx->Driver.GenerateMipmap);
2041 ctx->Driver.GenerateMipmap(ctx, target, texObj);
2042 }
2043 }
2044
2045
2046 /** Debug helper: override the user-requested internal format */
2047 static GLenum
2048 override_internal_format(GLenum internalFormat, GLint width, GLint height)
2049 {
2050 #if 0
2051 if (internalFormat == GL_RGBA16F_ARB ||
2052 internalFormat == GL_RGBA32F_ARB) {
2053 printf("Convert rgba float tex to int %d x %d\n", width, height);
2054 return GL_RGBA;
2055 }
2056 else if (internalFormat == GL_RGB16F_ARB ||
2057 internalFormat == GL_RGB32F_ARB) {
2058 printf("Convert rgb float tex to int %d x %d\n", width, height);
2059 return GL_RGB;
2060 }
2061 else if (internalFormat == GL_LUMINANCE_ALPHA16F_ARB ||
2062 internalFormat == GL_LUMINANCE_ALPHA32F_ARB) {
2063 printf("Convert luminance float tex to int %d x %d\n", width, height);
2064 return GL_LUMINANCE_ALPHA;
2065 }
2066 else if (internalFormat == GL_LUMINANCE16F_ARB ||
2067 internalFormat == GL_LUMINANCE32F_ARB) {
2068 printf("Convert luminance float tex to int %d x %d\n", width, height);
2069 return GL_LUMINANCE;
2070 }
2071 else if (internalFormat == GL_ALPHA16F_ARB ||
2072 internalFormat == GL_ALPHA32F_ARB) {
2073 printf("Convert luminance float tex to int %d x %d\n", width, height);
2074 return GL_ALPHA;
2075 }
2076 /*
2077 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2078 internalFormat = GL_RGBA;
2079 }
2080 */
2081 else {
2082 return internalFormat;
2083 }
2084 #else
2085 return internalFormat;
2086 #endif
2087 }
2088
2089
2090 /*
2091 * Called from the API. Note that width includes the border.
2092 */
2093 void GLAPIENTRY
2094 _mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat,
2095 GLsizei width, GLint border, GLenum format,
2096 GLenum type, const GLvoid *pixels )
2097 {
2098 GLsizei postConvWidth = width;
2099 GET_CURRENT_CONTEXT(ctx);
2100 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
2101
2102 if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
2103 _mesa_debug(ctx, "glTexImage1D %s %d %s %d %d %s %s %p\n",
2104 _mesa_lookup_enum_by_nr(target), level,
2105 _mesa_lookup_enum_by_nr(internalFormat), width, border,
2106 _mesa_lookup_enum_by_nr(format),
2107 _mesa_lookup_enum_by_nr(type), pixels);
2108
2109 internalFormat = override_internal_format(internalFormat, width, 1);
2110
2111 #if FEATURE_convolve
2112 if (_mesa_is_color_format(internalFormat)) {
2113 _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL);
2114 }
2115 #endif
2116
2117 if (target == GL_TEXTURE_1D) {
2118 /* non-proxy target */
2119 struct gl_texture_object *texObj;
2120 struct gl_texture_image *texImage;
2121 const GLuint face = _mesa_tex_target_to_face(target);
2122
2123 if (texture_error_check(ctx, target, level, internalFormat,
2124 format, type, 1, postConvWidth, 1, 1, border)) {
2125 return; /* error was recorded */
2126 }
2127
2128 if (ctx->NewState & _MESA_NEW_TRANSFER_STATE)
2129 _mesa_update_state(ctx);
2130
2131 texObj = get_current_tex_object(ctx, target);
2132 _mesa_lock_texture(ctx, texObj);
2133 {
2134 texImage = _mesa_get_tex_image(ctx, texObj, target, level);
2135 if (!texImage) {
2136 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage1D");
2137 }
2138 else {
2139 if (texImage->Data) {
2140 ctx->Driver.FreeTexImageData( ctx, texImage );
2141 }
2142
2143 ASSERT(texImage->Data == NULL);
2144
2145 clear_teximage_fields(texImage); /* not really needed, but helpful */
2146 _mesa_init_teximage_fields(ctx, target, texImage,
2147 postConvWidth, 1, 1,
2148 border, internalFormat);
2149
2150 /* Choose actual texture format */
2151 texImage->TexFormat =
2152 ctx->Driver.ChooseTextureFormat(ctx, internalFormat,
2153 format, type);
2154 ASSERT(texImage->TexFormat != MESA_FORMAT_NONE);
2155
2156 /* Give the texture to the driver. <pixels> may be null. */
2157 ASSERT(ctx->Driver.TexImage1D);
2158 ctx->Driver.TexImage1D(ctx, target, level, internalFormat,
2159 width, border, format, type, pixels,
2160 &ctx->Unpack, texObj, texImage);
2161
2162 ASSERT(texImage->TexFormat);
2163
2164 _mesa_set_fetch_functions(texImage, 1);
2165
2166 check_gen_mipmap(ctx, target, texObj, level);
2167
2168 update_fbo_texture(ctx, texObj, face, level);
2169
2170 /* state update */
2171 texObj->_Complete = GL_FALSE;
2172 ctx->NewState |= _NEW_TEXTURE;
2173 }
2174 }
2175 _mesa_unlock_texture(ctx, texObj);
2176 }
2177 else if (target == GL_PROXY_TEXTURE_1D) {
2178 /* Proxy texture: check for errors and update proxy state */
2179 struct gl_texture_image *texImage;
2180 texImage = _mesa_get_proxy_tex_image(ctx, target, level);
2181 if (texture_error_check(ctx, target, level, internalFormat,
2182 format, type, 1, postConvWidth, 1, 1, border)) {
2183 /* when error, clear all proxy texture image parameters */
2184 if (texImage)
2185 clear_teximage_fields(texImage);
2186 }
2187 else {
2188 /* no error, set the tex image parameters */
2189 ASSERT(texImage);
2190 _mesa_init_teximage_fields(ctx, target, texImage,
2191 postConvWidth, 1, 1,
2192 border, internalFormat);
2193 texImage->TexFormat =
2194 ctx->Driver.ChooseTextureFormat(ctx, internalFormat, format, type);
2195 }
2196 }
2197 else {
2198 _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage1D(target)" );
2199 return;
2200 }
2201 }
2202
2203
2204 void GLAPIENTRY
2205 _mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat,
2206 GLsizei width, GLsizei height, GLint border,
2207 GLenum format, GLenum type,
2208 const GLvoid *pixels )
2209 {
2210 GLsizei postConvWidth = width, postConvHeight = height;
2211 GET_CURRENT_CONTEXT(ctx);
2212 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
2213
2214 if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
2215 _mesa_debug(ctx, "glTexImage2D %s %d %s %d %d %d %s %s %p\n",
2216 _mesa_lookup_enum_by_nr(target), level,
2217 _mesa_lookup_enum_by_nr(internalFormat), width, height,
2218 border, _mesa_lookup_enum_by_nr(format),
2219 _mesa_lookup_enum_by_nr(type), pixels);
2220
2221 internalFormat = override_internal_format(internalFormat, width, height);
2222
2223 #if FEATURE_convolve
2224 if (_mesa_is_color_format(internalFormat)) {
2225 _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth,
2226 &postConvHeight);
2227 }
2228 #endif
2229
2230 if (target == GL_TEXTURE_2D ||
2231 (ctx->Extensions.ARB_texture_cube_map &&
2232 target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
2233 target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) ||
2234 (ctx->Extensions.NV_texture_rectangle &&
2235 target == GL_TEXTURE_RECTANGLE_NV) ||
2236 (ctx->Extensions.MESA_texture_array &&
2237 target == GL_TEXTURE_1D_ARRAY_EXT)) {
2238 /* non-proxy target */
2239 struct gl_texture_object *texObj;
2240 struct gl_texture_image *texImage;
2241 const GLuint face = _mesa_tex_target_to_face(target);
2242
2243 if (texture_error_check(ctx, target, level, internalFormat,
2244 format, type, 2, postConvWidth, postConvHeight,
2245 1, border)) {
2246 return; /* error was recorded */
2247 }
2248
2249 if (ctx->NewState & _MESA_NEW_TRANSFER_STATE)
2250 _mesa_update_state(ctx);
2251
2252 texObj = get_current_tex_object(ctx, target);
2253 _mesa_lock_texture(ctx, texObj);
2254 {
2255 texImage = _mesa_get_tex_image(ctx, texObj, target, level);
2256 if (!texImage) {
2257 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
2258 }
2259 else {
2260 if (texImage->Data) {
2261 ctx->Driver.FreeTexImageData( ctx, texImage );
2262 }
2263
2264 ASSERT(texImage->Data == NULL);
2265 clear_teximage_fields(texImage); /* not really needed, but helpful */
2266 _mesa_init_teximage_fields(ctx, target, texImage,
2267 postConvWidth, postConvHeight, 1,
2268 border, internalFormat);
2269
2270 /* Choose actual texture format */
2271 texImage->TexFormat =
2272 ctx->Driver.ChooseTextureFormat(ctx, internalFormat,
2273 format, type);
2274 ASSERT(texImage->TexFormat != MESA_FORMAT_NONE);
2275
2276 /* Give the texture to the driver. <pixels> may be null. */
2277 ASSERT(ctx->Driver.TexImage2D);
2278 ctx->Driver.TexImage2D(ctx, target, level, internalFormat,
2279 width, height, border, format, type,
2280 pixels, &ctx->Unpack, texObj, texImage);
2281
2282 ASSERT(texImage->TexFormat);
2283
2284 _mesa_set_fetch_functions(texImage, 2);
2285
2286 check_gen_mipmap(ctx, target, texObj, level);
2287
2288 update_fbo_texture(ctx, texObj, face, level);
2289
2290 /* state update */
2291 texObj->_Complete = GL_FALSE;
2292 ctx->NewState |= _NEW_TEXTURE;
2293 }
2294 }
2295 _mesa_unlock_texture(ctx, texObj);
2296 }
2297 else if (target == GL_PROXY_TEXTURE_2D ||
2298 (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB &&
2299 ctx->Extensions.ARB_texture_cube_map) ||
2300 (target == GL_PROXY_TEXTURE_RECTANGLE_NV &&
2301 ctx->Extensions.NV_texture_rectangle) ||
2302 (ctx->Extensions.MESA_texture_array &&
2303 target == GL_PROXY_TEXTURE_1D_ARRAY_EXT)) {
2304 /* Proxy texture: check for errors and update proxy state */
2305 struct gl_texture_image *texImage;
2306 texImage = _mesa_get_proxy_tex_image(ctx, target, level);
2307 if (texture_error_check(ctx, target, level, internalFormat,
2308 format, type, 2, postConvWidth, postConvHeight,
2309 1, border)) {
2310 /* when error, clear all proxy texture image parameters */
2311 if (texImage)
2312 clear_teximage_fields(texImage);
2313 }
2314 else {
2315 /* no error, set the tex image parameters */
2316 _mesa_init_teximage_fields(ctx, target, texImage,
2317 postConvWidth, postConvHeight, 1,
2318 border, internalFormat);
2319 texImage->TexFormat =
2320 ctx->Driver.ChooseTextureFormat(ctx, internalFormat, format, type);
2321 }
2322 }
2323 else {
2324 _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage2D(target)" );
2325 return;
2326 }
2327 }
2328
2329
2330 /*
2331 * Called by the API or display list executor.
2332 * Note that width and height include the border.
2333 */
2334 void GLAPIENTRY
2335 _mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat,
2336 GLsizei width, GLsizei height, GLsizei depth,
2337 GLint border, GLenum format, GLenum type,
2338 const GLvoid *pixels )
2339 {
2340 GET_CURRENT_CONTEXT(ctx);
2341 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
2342
2343 if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
2344 _mesa_debug(ctx, "glTexImage3D %s %d %s %d %d %d %d %s %s %p\n",
2345 _mesa_lookup_enum_by_nr(target), level,
2346 _mesa_lookup_enum_by_nr(internalFormat), width, height,
2347 depth, border, _mesa_lookup_enum_by_nr(format),
2348 _mesa_lookup_enum_by_nr(type), pixels);
2349
2350 internalFormat = override_internal_format(internalFormat, width, height);
2351
2352 if (target == GL_TEXTURE_3D ||
2353 (ctx->Extensions.MESA_texture_array &&
2354 target == GL_TEXTURE_2D_ARRAY_EXT)) {
2355 /* non-proxy target */
2356 struct gl_texture_object *texObj;
2357 struct gl_texture_image *texImage;
2358 const GLuint face = _mesa_tex_target_to_face(target);
2359
2360 if (texture_error_check(ctx, target, level, (GLint) internalFormat,
2361 format, type, 3, width, height, depth, border)) {
2362 return; /* error was recorded */
2363 }
2364
2365 if (ctx->NewState & _MESA_NEW_TRANSFER_STATE)
2366 _mesa_update_state(ctx);
2367
2368 texObj = get_current_tex_object(ctx, target);
2369 _mesa_lock_texture(ctx, texObj);
2370 {
2371 texImage = _mesa_get_tex_image(ctx, texObj, target, level);
2372 if (!texImage) {
2373 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage3D");
2374 }
2375 else {
2376 if (texImage->Data) {
2377 ctx->Driver.FreeTexImageData( ctx, texImage );
2378 }
2379
2380 ASSERT(texImage->Data == NULL);
2381 clear_teximage_fields(texImage); /* not really needed, but helpful */
2382 _mesa_init_teximage_fields(ctx, target, texImage,
2383 width, height, depth,
2384 border, internalFormat);
2385
2386 /* Choose actual texture format */
2387 texImage->TexFormat =
2388 ctx->Driver.ChooseTextureFormat(ctx, internalFormat,
2389 format, type);
2390 ASSERT(texImage->TexFormat != MESA_FORMAT_NONE);
2391
2392 /* Give the texture to the driver. <pixels> may be null. */
2393 ASSERT(ctx->Driver.TexImage3D);
2394 ctx->Driver.TexImage3D(ctx, target, level, internalFormat,
2395 width, height, depth, border, format, type,
2396 pixels, &ctx->Unpack, texObj, texImage);
2397
2398 ASSERT(texImage->TexFormat);
2399
2400 _mesa_set_fetch_functions(texImage, 3);
2401
2402 check_gen_mipmap(ctx, target, texObj, level);
2403
2404 update_fbo_texture(ctx, texObj, face, level);
2405
2406 /* state update */
2407 texObj->_Complete = GL_FALSE;
2408 ctx->NewState |= _NEW_TEXTURE;
2409 }
2410 }
2411 _mesa_unlock_texture(ctx, texObj);
2412 }
2413 else if (target == GL_PROXY_TEXTURE_3D ||
2414 (ctx->Extensions.MESA_texture_array &&
2415 target == GL_PROXY_TEXTURE_2D_ARRAY_EXT)) {
2416 /* Proxy texture: check for errors and update proxy state */
2417 struct gl_texture_image *texImage;
2418 texImage = _mesa_get_proxy_tex_image(ctx, target, level);
2419 if (texture_error_check(ctx, target, level, internalFormat,
2420 format, type, 3, width, height, depth, border)) {
2421 /* when error, clear all proxy texture image parameters */
2422 if (texImage)
2423 clear_teximage_fields(texImage);
2424 }
2425 else {
2426 /* no error, set the tex image parameters */
2427 _mesa_init_teximage_fields(ctx, target, texImage, width, height,
2428 depth, border, internalFormat);
2429 texImage->TexFormat =
2430 ctx->Driver.ChooseTextureFormat(ctx, internalFormat, format, type);
2431 }
2432 }
2433 else {
2434 _mesa_error( ctx, GL_INVALID_ENUM, "glTexImage3D(target)" );
2435 return;
2436 }
2437 }
2438
2439
2440 void GLAPIENTRY
2441 _mesa_TexImage3DEXT( GLenum target, GLint level, GLenum internalFormat,
2442 GLsizei width, GLsizei height, GLsizei depth,
2443 GLint border, GLenum format, GLenum type,
2444 const GLvoid *pixels )
2445 {
2446 _mesa_TexImage3D(target, level, (GLint) internalFormat, width, height,
2447 depth, border, format, type, pixels);
2448 }
2449
2450
2451
2452 void GLAPIENTRY
2453 _mesa_TexSubImage1D( GLenum target, GLint level,
2454 GLint xoffset, GLsizei width,
2455 GLenum format, GLenum type,
2456 const GLvoid *pixels )
2457 {
2458 GLsizei postConvWidth = width;
2459 struct gl_texture_object *texObj;
2460 struct gl_texture_image *texImage = NULL;
2461 GET_CURRENT_CONTEXT(ctx);
2462 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
2463
2464 if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
2465 _mesa_debug(ctx, "glTexSubImage1D %s %d %d %d %s %s %p\n",
2466 _mesa_lookup_enum_by_nr(target), level,
2467 xoffset, width, _mesa_lookup_enum_by_nr(format),
2468 _mesa_lookup_enum_by_nr(type), pixels);
2469
2470 if (ctx->NewState & _MESA_NEW_TRANSFER_STATE)
2471 _mesa_update_state(ctx);
2472
2473 #if FEATURE_convolve
2474 /* XXX should test internal format */
2475 if (_mesa_is_color_format(format)) {
2476 _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL);
2477 }
2478 #endif
2479
2480 if (subtexture_error_check(ctx, 1, target, level, xoffset, 0, 0,
2481 postConvWidth, 1, 1, format, type)) {
2482 return; /* error was detected */
2483 }
2484
2485
2486 texObj = get_current_tex_object(ctx, target);
2487 assert(texObj);
2488
2489 _mesa_lock_texture(ctx, texObj);
2490 {
2491 texImage = _mesa_select_tex_image(ctx, texObj, target, level);
2492
2493 if (subtexture_error_check2(ctx, 1, target, level, xoffset, 0, 0,
2494 postConvWidth, 1, 1,
2495 format, type, texImage)) {
2496 /* error was recorded */
2497 }
2498 else if (width > 0) {
2499 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2500 xoffset += texImage->Border;
2501
2502 ASSERT(ctx->Driver.TexSubImage1D);
2503 ctx->Driver.TexSubImage1D(ctx, target, level, xoffset, width,
2504 format, type, pixels, &ctx->Unpack,
2505 texObj, texImage);
2506
2507 check_gen_mipmap(ctx, target, texObj, level);
2508
2509 ctx->NewState |= _NEW_TEXTURE;
2510 }
2511 }
2512 _mesa_unlock_texture(ctx, texObj);
2513 }
2514
2515
2516 void GLAPIENTRY
2517 _mesa_TexSubImage2D( GLenum target, GLint level,
2518 GLint xoffset, GLint yoffset,
2519 GLsizei width, GLsizei height,
2520 GLenum format, GLenum type,
2521 const GLvoid *pixels )
2522 {
2523 GLsizei postConvWidth = width, postConvHeight = height;
2524 struct gl_texture_object *texObj;
2525 struct gl_texture_image *texImage;
2526 GET_CURRENT_CONTEXT(ctx);
2527 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
2528
2529 if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
2530 _mesa_debug(ctx, "glTexSubImage2D %s %d %d %d %d %d %s %s %p\n",
2531 _mesa_lookup_enum_by_nr(target), level,
2532 xoffset, yoffset, width, height,
2533 _mesa_lookup_enum_by_nr(format),
2534 _mesa_lookup_enum_by_nr(type), pixels);
2535
2536 if (ctx->NewState & _MESA_NEW_TRANSFER_STATE)
2537 _mesa_update_state(ctx);
2538
2539 #if FEATURE_convolve
2540 /* XXX should test internal format */
2541 if (_mesa_is_color_format(format)) {
2542 _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth,
2543 &postConvHeight);
2544 }
2545 #endif
2546
2547 if (subtexture_error_check(ctx, 2, target, level, xoffset, yoffset, 0,
2548 postConvWidth, postConvHeight, 1, format, type)) {
2549 return; /* error was detected */
2550 }
2551
2552 texObj = get_current_tex_object(ctx, target);
2553
2554 _mesa_lock_texture(ctx, texObj);
2555 {
2556 texImage = _mesa_select_tex_image(ctx, texObj, target, level);
2557
2558 if (subtexture_error_check2(ctx, 2, target, level, xoffset, yoffset, 0,
2559 postConvWidth, postConvHeight, 1,
2560 format, type, texImage)) {
2561 /* error was recorded */
2562 }
2563 else if (width > 0 && height >= 0) {
2564 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2565 xoffset += texImage->Border;
2566 yoffset += texImage->Border;
2567
2568 ASSERT(ctx->Driver.TexSubImage2D);
2569 ctx->Driver.TexSubImage2D(ctx, target, level, xoffset, yoffset,
2570 width, height, format, type, pixels,
2571 &ctx->Unpack, texObj, texImage);
2572
2573 check_gen_mipmap(ctx, target, texObj, level);
2574
2575 ctx->NewState |= _NEW_TEXTURE;
2576 }
2577 }
2578 _mesa_unlock_texture(ctx, texObj);
2579 }
2580
2581
2582
2583 void GLAPIENTRY
2584 _mesa_TexSubImage3D( GLenum target, GLint level,
2585 GLint xoffset, GLint yoffset, GLint zoffset,
2586 GLsizei width, GLsizei height, GLsizei depth,
2587 GLenum format, GLenum type,
2588 const GLvoid *pixels )
2589 {
2590 struct gl_texture_object *texObj;
2591 struct gl_texture_image *texImage;
2592 GET_CURRENT_CONTEXT(ctx);
2593 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
2594
2595 if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
2596 _mesa_debug(ctx, "glTexSubImage3D %s %d %d %d %d %d %d %d %s %s %p\n",
2597 _mesa_lookup_enum_by_nr(target), level,
2598 xoffset, yoffset, zoffset, width, height, depth,
2599 _mesa_lookup_enum_by_nr(format),
2600 _mesa_lookup_enum_by_nr(type), pixels);
2601
2602 if (ctx->NewState & _MESA_NEW_TRANSFER_STATE)
2603 _mesa_update_state(ctx);
2604
2605 if (subtexture_error_check(ctx, 3, target, level, xoffset, yoffset, zoffset,
2606 width, height, depth, format, type)) {
2607 return; /* error was detected */
2608 }
2609
2610 texObj = get_current_tex_object(ctx, target);
2611
2612 _mesa_lock_texture(ctx, texObj);
2613 {
2614 texImage = _mesa_select_tex_image(ctx, texObj, target, level);
2615
2616 if (subtexture_error_check2(ctx, 3, target, level,
2617 xoffset, yoffset, zoffset,
2618 width, height, depth,
2619 format, type, texImage)) {
2620 /* error was recorded */
2621 }
2622 else if (width > 0 && height > 0 && height > 0) {
2623 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2624 xoffset += texImage->Border;
2625 yoffset += texImage->Border;
2626 zoffset += texImage->Border;
2627
2628 ASSERT(ctx->Driver.TexSubImage3D);
2629 ctx->Driver.TexSubImage3D(ctx, target, level,
2630 xoffset, yoffset, zoffset,
2631 width, height, depth,
2632 format, type, pixels,
2633 &ctx->Unpack, texObj, texImage );
2634
2635 check_gen_mipmap(ctx, target, texObj, level);
2636
2637 ctx->NewState |= _NEW_TEXTURE;
2638 }
2639 }
2640 _mesa_unlock_texture(ctx, texObj);
2641 }
2642
2643
2644
2645 void GLAPIENTRY
2646 _mesa_CopyTexImage1D( GLenum target, GLint level,
2647 GLenum internalFormat,
2648 GLint x, GLint y,
2649 GLsizei width, GLint border )
2650 {
2651 struct gl_texture_object *texObj;
2652 struct gl_texture_image *texImage;
2653 GLsizei postConvWidth = width;
2654 const GLuint face = _mesa_tex_target_to_face(target);
2655 GET_CURRENT_CONTEXT(ctx);
2656 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
2657
2658 if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
2659 _mesa_debug(ctx, "glCopyTexImage1D %s %d %s %d %d %d %d\n",
2660 _mesa_lookup_enum_by_nr(target), level,
2661 _mesa_lookup_enum_by_nr(internalFormat),
2662 x, y, width, border);
2663
2664 if (ctx->NewState & NEW_COPY_TEX_STATE)
2665 _mesa_update_state(ctx);
2666
2667 #if FEATURE_convolve
2668 if (_mesa_is_color_format(internalFormat)) {
2669 _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL);
2670 }
2671 #endif
2672
2673 if (copytexture_error_check(ctx, 1, target, level, internalFormat,
2674 postConvWidth, 1, border))
2675 return;
2676
2677 texObj = get_current_tex_object(ctx, target);
2678
2679 _mesa_lock_texture(ctx, texObj);
2680 {
2681 texImage = _mesa_get_tex_image(ctx, texObj, target, level);
2682 if (!texImage) {
2683 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage1D");
2684 }
2685 else {
2686 if (texImage->Data) {
2687 ctx->Driver.FreeTexImageData( ctx, texImage );
2688 }
2689
2690 ASSERT(texImage->Data == NULL);
2691
2692 clear_teximage_fields(texImage); /* not really needed, but helpful */
2693 _mesa_init_teximage_fields(ctx, target, texImage, postConvWidth, 1, 1,
2694 border, internalFormat);
2695
2696 /* Choose actual texture format */
2697 texImage->TexFormat =
2698 ctx->Driver.ChooseTextureFormat(ctx, internalFormat,
2699 GL_NONE, GL_NONE);
2700 ASSERT(texImage->TexFormat != MESA_FORMAT_NONE);
2701
2702 ASSERT(ctx->Driver.CopyTexImage1D);
2703 ctx->Driver.CopyTexImage1D(ctx, target, level, internalFormat,
2704 x, y, width, border);
2705
2706 ASSERT(texImage->TexFormat);
2707
2708 _mesa_set_fetch_functions(texImage, 1);
2709
2710 check_gen_mipmap(ctx, target, texObj, level);
2711
2712 update_fbo_texture(ctx, texObj, face, level);
2713
2714 /* state update */
2715 texObj->_Complete = GL_FALSE;
2716 ctx->NewState |= _NEW_TEXTURE;
2717 }
2718 }
2719 _mesa_unlock_texture(ctx, texObj);
2720 }
2721
2722
2723
2724 void GLAPIENTRY
2725 _mesa_CopyTexImage2D( GLenum target, GLint level, GLenum internalFormat,
2726 GLint x, GLint y, GLsizei width, GLsizei height,
2727 GLint border )
2728 {
2729 struct gl_texture_object *texObj;
2730 struct gl_texture_image *texImage;
2731 GLsizei postConvWidth = width, postConvHeight = height;
2732 const GLuint face = _mesa_tex_target_to_face(target);
2733 GET_CURRENT_CONTEXT(ctx);
2734 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
2735
2736 if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
2737 _mesa_debug(ctx, "glCopyTexImage2D %s %d %s %d %d %d %d %d\n",
2738 _mesa_lookup_enum_by_nr(target), level,
2739 _mesa_lookup_enum_by_nr(internalFormat),
2740 x, y, width, height, border);
2741
2742 if (ctx->NewState & NEW_COPY_TEX_STATE)
2743 _mesa_update_state(ctx);
2744
2745 #if FEATURE_convolve
2746 if (_mesa_is_color_format(internalFormat)) {
2747 _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth,
2748 &postConvHeight);
2749 }
2750 #endif
2751
2752 if (copytexture_error_check(ctx, 2, target, level, internalFormat,
2753 postConvWidth, postConvHeight, border))
2754 return;
2755
2756 texObj = get_current_tex_object(ctx, target);
2757
2758 _mesa_lock_texture(ctx, texObj);
2759 {
2760 texImage = _mesa_get_tex_image(ctx, texObj, target, level);
2761
2762 if (!texImage) {
2763 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyTexImage2D");
2764 }
2765 else {
2766 if (texImage->Data) {
2767 ctx->Driver.FreeTexImageData( ctx, texImage );
2768 }
2769
2770 ASSERT(texImage->Data == NULL);
2771
2772 clear_teximage_fields(texImage); /* not really needed, but helpful */
2773 _mesa_init_teximage_fields(ctx, target, texImage,
2774 postConvWidth, postConvHeight, 1,
2775 border, internalFormat);
2776
2777 /* Choose actual texture format */
2778 texImage->TexFormat =
2779 ctx->Driver.ChooseTextureFormat(ctx, internalFormat,
2780 GL_NONE, GL_NONE);
2781 ASSERT(texImage->TexFormat != MESA_FORMAT_NONE);
2782
2783 ASSERT(ctx->Driver.CopyTexImage2D);
2784 ctx->Driver.CopyTexImage2D(ctx, target, level, internalFormat,
2785 x, y, width, height, border);
2786
2787 ASSERT(texImage->TexFormat);
2788
2789 _mesa_set_fetch_functions(texImage, 2);
2790
2791 check_gen_mipmap(ctx, target, texObj, level);
2792
2793 update_fbo_texture(ctx, texObj, face, level);
2794
2795 /* state update */
2796 texObj->_Complete = GL_FALSE;
2797 ctx->NewState |= _NEW_TEXTURE;
2798 }
2799 }
2800 _mesa_unlock_texture(ctx, texObj);
2801 }
2802
2803
2804 void GLAPIENTRY
2805 _mesa_CopyTexSubImage1D( GLenum target, GLint level,
2806 GLint xoffset, GLint x, GLint y, GLsizei width )
2807 {
2808 struct gl_texture_object *texObj;
2809 struct gl_texture_image *texImage;
2810 GLsizei postConvWidth = width;
2811 GLint yoffset = 0;
2812 GLsizei height = 1;
2813
2814 GET_CURRENT_CONTEXT(ctx);
2815 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
2816
2817 if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
2818 _mesa_debug(ctx, "glCopyTexSubImage1D %s %d %d %d %d %d\n",
2819 _mesa_lookup_enum_by_nr(target),
2820 level, xoffset, x, y, width);
2821
2822 if (ctx->NewState & NEW_COPY_TEX_STATE)
2823 _mesa_update_state(ctx);
2824
2825 if (copytexsubimage_error_check1(ctx, 1, target, level))
2826 return;
2827
2828 texObj = get_current_tex_object(ctx, target);
2829
2830 _mesa_lock_texture(ctx, texObj);
2831 {
2832 texImage = _mesa_select_tex_image(ctx, texObj, target, level);
2833
2834 #if FEATURE_convolve
2835 if (texImage && _mesa_is_color_format(texImage->InternalFormat)) {
2836 _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL);
2837 }
2838 #endif
2839
2840 if (copytexsubimage_error_check2(ctx, 1, target, level,
2841 xoffset, 0, 0, postConvWidth, 1,
2842 texImage)) {
2843 /* error was recorded */
2844 }
2845 else {
2846 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2847 xoffset += texImage->Border;
2848
2849 if (_mesa_clip_copytexsubimage(ctx, &xoffset, &yoffset, &x, &y,
2850 &width, &height)) {
2851 ASSERT(ctx->Driver.CopyTexSubImage1D);
2852 ctx->Driver.CopyTexSubImage1D(ctx, target, level,
2853 xoffset, x, y, width);
2854
2855 check_gen_mipmap(ctx, target, texObj, level);
2856
2857 ctx->NewState |= _NEW_TEXTURE;
2858 }
2859 }
2860 }
2861 _mesa_unlock_texture(ctx, texObj);
2862 }
2863
2864
2865
2866 void GLAPIENTRY
2867 _mesa_CopyTexSubImage2D( GLenum target, GLint level,
2868 GLint xoffset, GLint yoffset,
2869 GLint x, GLint y, GLsizei width, GLsizei height )
2870 {
2871 struct gl_texture_object *texObj;
2872 struct gl_texture_image *texImage;
2873 GLsizei postConvWidth = width, postConvHeight = height;
2874 GET_CURRENT_CONTEXT(ctx);
2875 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
2876
2877 if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
2878 _mesa_debug(ctx, "glCopyTexSubImage2D %s %d %d %d %d %d %d %d\n",
2879 _mesa_lookup_enum_by_nr(target),
2880 level, xoffset, yoffset, x, y, width, height);
2881
2882 if (ctx->NewState & NEW_COPY_TEX_STATE)
2883 _mesa_update_state(ctx);
2884
2885 if (copytexsubimage_error_check1(ctx, 2, target, level))
2886 return;
2887
2888 texObj = get_current_tex_object(ctx, target);
2889
2890 _mesa_lock_texture(ctx, texObj);
2891 {
2892 texImage = _mesa_select_tex_image(ctx, texObj, target, level);
2893
2894 #if FEATURE_convolve
2895 if (texImage && _mesa_is_color_format(texImage->InternalFormat)) {
2896 _mesa_adjust_image_for_convolution(ctx, 2,
2897 &postConvWidth, &postConvHeight);
2898 }
2899 #endif
2900
2901 if (copytexsubimage_error_check2(ctx, 2, target, level,
2902 xoffset, yoffset, 0,
2903 postConvWidth, postConvHeight,
2904 texImage)) {
2905 /* error was recorded */
2906 }
2907 else {
2908 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2909 xoffset += texImage->Border;
2910 yoffset += texImage->Border;
2911
2912 if (_mesa_clip_copytexsubimage(ctx, &xoffset, &yoffset, &x, &y,
2913 &width, &height)) {
2914 ASSERT(ctx->Driver.CopyTexSubImage2D);
2915 ctx->Driver.CopyTexSubImage2D(ctx, target, level, xoffset, yoffset,
2916 x, y, width, height);
2917
2918 check_gen_mipmap(ctx, target, texObj, level);
2919
2920 ctx->NewState |= _NEW_TEXTURE;
2921 }
2922 }
2923 }
2924 _mesa_unlock_texture(ctx, texObj);
2925 }
2926
2927
2928
2929 void GLAPIENTRY
2930 _mesa_CopyTexSubImage3D( GLenum target, GLint level,
2931 GLint xoffset, GLint yoffset, GLint zoffset,
2932 GLint x, GLint y, GLsizei width, GLsizei height )
2933 {
2934 struct gl_texture_object *texObj;
2935 struct gl_texture_image *texImage;
2936 GLsizei postConvWidth = width, postConvHeight = height;
2937 GET_CURRENT_CONTEXT(ctx);
2938 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
2939
2940 if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
2941 _mesa_debug(ctx, "glCopyTexSubImage3D %s %d %d %d %d %d %d %d %d\n",
2942 _mesa_lookup_enum_by_nr(target),
2943 level, xoffset, yoffset, zoffset, x, y, width, height);
2944
2945 if (ctx->NewState & NEW_COPY_TEX_STATE)
2946 _mesa_update_state(ctx);
2947
2948 if (copytexsubimage_error_check1(ctx, 3, target, level))
2949 return;
2950
2951 texObj = get_current_tex_object(ctx, target);
2952
2953 _mesa_lock_texture(ctx, texObj);
2954 {
2955 texImage = _mesa_select_tex_image(ctx, texObj, target, level);
2956
2957 #if FEATURE_convolve
2958 if (texImage && _mesa_is_color_format(texImage->InternalFormat)) {
2959 _mesa_adjust_image_for_convolution(ctx, 2,
2960 &postConvWidth, &postConvHeight);
2961 }
2962 #endif
2963
2964 if (copytexsubimage_error_check2(ctx, 3, target, level, xoffset, yoffset,
2965 zoffset, postConvWidth, postConvHeight,
2966 texImage)) {
2967 /* error was recored */
2968 }
2969 else {
2970 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2971 xoffset += texImage->Border;
2972 yoffset += texImage->Border;
2973 zoffset += texImage->Border;
2974
2975 if (_mesa_clip_copytexsubimage(ctx, &xoffset, &yoffset, &x, &y,
2976 &width, &height)) {
2977 ASSERT(ctx->Driver.CopyTexSubImage3D);
2978 ctx->Driver.CopyTexSubImage3D(ctx, target, level,
2979 xoffset, yoffset, zoffset,
2980 x, y, width, height);
2981
2982 check_gen_mipmap(ctx, target, texObj, level);
2983
2984 ctx->NewState |= _NEW_TEXTURE;
2985 }
2986 }
2987 }
2988 _mesa_unlock_texture(ctx, texObj);
2989 }
2990
2991
2992
2993
2994 /**********************************************************************/
2995 /****** Compressed Textures ******/
2996 /**********************************************************************/
2997
2998
2999 /**
3000 * Return expected size of a compressed texture.
3001 */
3002 static GLuint
3003 compressed_tex_size(GLsizei width, GLsizei height, GLsizei depth,
3004 GLenum glformat)
3005 {
3006 gl_format mesaFormat = _mesa_glenum_to_compressed_format(glformat);
3007 return _mesa_format_image_size(mesaFormat, width, height, depth);
3008 }
3009
3010
3011 /*
3012 * Return compressed texture block size, in pixels.
3013 */
3014 static void
3015 get_compressed_block_size(GLenum glformat, GLuint *bw, GLuint *bh)
3016 {
3017 gl_format mesaFormat = _mesa_glenum_to_compressed_format(glformat);
3018 _mesa_get_format_block_size(mesaFormat, bw, bh);
3019 }
3020
3021
3022 /**
3023 * Error checking for glCompressedTexImage[123]D().
3024 * \return error code or GL_NO_ERROR.
3025 */
3026 static GLenum
3027 compressed_texture_error_check(GLcontext *ctx, GLint dimensions,
3028 GLenum target, GLint level,
3029 GLenum internalFormat, GLsizei width,
3030 GLsizei height, GLsizei depth, GLint border,
3031 GLsizei imageSize)
3032 {
3033 GLint expectedSize, maxLevels = 0, maxTextureSize;
3034
3035 if (dimensions == 1) {
3036 /* 1D compressed textures not allowed */
3037 return GL_INVALID_ENUM;
3038 }
3039 else if (dimensions == 2) {
3040 if (target == GL_PROXY_TEXTURE_2D) {
3041 maxLevels = ctx->Const.MaxTextureLevels;
3042 }
3043 else if (target == GL_TEXTURE_2D) {
3044 maxLevels = ctx->Const.MaxTextureLevels;
3045 }
3046 else if (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB) {
3047 if (!ctx->Extensions.ARB_texture_cube_map)
3048 return GL_INVALID_ENUM; /*target*/
3049 maxLevels = ctx->Const.MaxCubeTextureLevels;
3050 }
3051 else if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
3052 target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) {
3053 if (!ctx->Extensions.ARB_texture_cube_map)
3054 return GL_INVALID_ENUM; /*target*/
3055 maxLevels = ctx->Const.MaxCubeTextureLevels;
3056 }
3057 else {
3058 return GL_INVALID_ENUM; /*target*/
3059 }
3060 }
3061 else if (dimensions == 3) {
3062 /* 3D compressed textures not allowed */
3063 return GL_INVALID_ENUM;
3064 }
3065
3066 maxTextureSize = 1 << (maxLevels - 1);
3067
3068 /* This will detect any invalid internalFormat value */
3069 if (!is_compressed_format(ctx, internalFormat))
3070 return GL_INVALID_ENUM;
3071
3072 /* This should really never fail */
3073 if (_mesa_base_tex_format(ctx, internalFormat) < 0)
3074 return GL_INVALID_ENUM;
3075
3076 if (border != 0)
3077 return GL_INVALID_VALUE;
3078
3079 /*
3080 * XXX We should probably use the proxy texture error check function here.
3081 */
3082 if (width < 1 || width > maxTextureSize ||
3083 (!ctx->Extensions.ARB_texture_non_power_of_two && !_mesa_is_pow_two(width)))
3084 return GL_INVALID_VALUE;
3085
3086 if ((height < 1 || height > maxTextureSize ||
3087 (!ctx->Extensions.ARB_texture_non_power_of_two && !_mesa_is_pow_two(height)))
3088 && dimensions > 1)
3089 return GL_INVALID_VALUE;
3090
3091 if ((depth < 1 || depth > maxTextureSize ||
3092 (!ctx->Extensions.ARB_texture_non_power_of_two && !_mesa_is_pow_two(depth)))
3093 && dimensions > 2)
3094 return GL_INVALID_VALUE;
3095
3096 /* For cube map, width must equal height */
3097 if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
3098 target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB && width != height)
3099 return GL_INVALID_VALUE;
3100
3101 if (level < 0 || level >= maxLevels)
3102 return GL_INVALID_VALUE;
3103
3104 expectedSize = compressed_tex_size(width, height, depth, internalFormat);
3105 if (expectedSize != imageSize)
3106 return GL_INVALID_VALUE;
3107
3108 #if FEATURE_EXT_texture_sRGB
3109 if ((internalFormat == GL_COMPRESSED_SRGB_S3TC_DXT1_EXT ||
3110 internalFormat == GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT ||
3111 internalFormat == GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT ||
3112 internalFormat == GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT)
3113 && border != 0) {
3114 return GL_INVALID_OPERATION;
3115 }
3116 #endif
3117
3118 return GL_NO_ERROR;
3119 }
3120
3121
3122 /**
3123 * Error checking for glCompressedTexSubImage[123]D().
3124 * \warning There are some bad assumptions here about the size of compressed
3125 * texture tiles (multiple of 4) used to test the validity of the
3126 * offset and size parameters.
3127 * \return error code or GL_NO_ERROR.
3128 */
3129 static GLenum
3130 compressed_subtexture_error_check(GLcontext *ctx, GLint dimensions,
3131 GLenum target, GLint level,
3132 GLint xoffset, GLint yoffset, GLint zoffset,
3133 GLsizei width, GLsizei height, GLsizei depth,
3134 GLenum format, GLsizei imageSize)
3135 {
3136 GLint expectedSize, maxLevels = 0, maxTextureSize;
3137 GLuint bw, bh;
3138 (void) zoffset;
3139
3140 if (dimensions == 1) {
3141 /* 1D compressed textures not allowed */
3142 return GL_INVALID_ENUM;
3143 }
3144 else if (dimensions == 2) {
3145 if (target == GL_PROXY_TEXTURE_2D) {
3146 maxLevels = ctx->Const.MaxTextureLevels;
3147 }
3148 else if (target == GL_TEXTURE_2D) {
3149 maxLevels = ctx->Const.MaxTextureLevels;
3150 }
3151 else if (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB) {
3152 if (!ctx->Extensions.ARB_texture_cube_map)
3153 return GL_INVALID_ENUM; /*target*/
3154 maxLevels = ctx->Const.MaxCubeTextureLevels;
3155 }
3156 else if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
3157 target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) {
3158 if (!ctx->Extensions.ARB_texture_cube_map)
3159 return GL_INVALID_ENUM; /*target*/
3160 maxLevels = ctx->Const.MaxCubeTextureLevels;
3161 }
3162 else {
3163 return GL_INVALID_ENUM; /*target*/
3164 }
3165 }
3166 else if (dimensions == 3) {
3167 /* 3D compressed textures not allowed */
3168 return GL_INVALID_ENUM;
3169 }
3170
3171 maxTextureSize = 1 << (maxLevels - 1);
3172
3173 /* this will catch any invalid compressed format token */
3174 if (!is_compressed_format(ctx, format))
3175 return GL_INVALID_ENUM;
3176
3177 if (width < 1 || width > maxTextureSize)
3178 return GL_INVALID_VALUE;
3179
3180 if ((height < 1 || height > maxTextureSize)
3181 && dimensions > 1)
3182 return GL_INVALID_VALUE;
3183
3184 if (level < 0 || level >= maxLevels)
3185 return GL_INVALID_VALUE;
3186
3187 /*
3188 * do checks which depend on compression block size
3189 */
3190 get_compressed_block_size(format, &bw, &bh);
3191
3192 if ((xoffset % bw != 0) || (yoffset % bh != 0))
3193 return GL_INVALID_VALUE;
3194
3195 if ((width % bw != 0) && width != 2 && width != 1)
3196 return GL_INVALID_VALUE;
3197
3198 if ((height % bh != 0) && height != 2 && height != 1)
3199 return GL_INVALID_VALUE;
3200
3201 expectedSize = compressed_tex_size(width, height, depth, format);
3202 if (expectedSize != imageSize)
3203 return GL_INVALID_VALUE;
3204
3205 return GL_NO_ERROR;
3206 }
3207
3208
3209 /**
3210 * Do second part of glCompressedTexSubImage error checking.
3211 * \return GL_TRUE if error found, GL_FALSE otherwise.
3212 */
3213 static GLboolean
3214 compressed_subtexture_error_check2(GLcontext *ctx, GLuint dims,
3215 GLsizei width, GLsizei height,
3216 GLsizei depth, GLenum format,
3217 struct gl_texture_image *texImage)
3218 {
3219
3220 if ((GLint) format != texImage->InternalFormat) {
3221 _mesa_error(ctx, GL_INVALID_OPERATION,
3222 "glCompressedTexSubImage%uD(format=0x%x)", dims, format);
3223 return GL_TRUE;
3224 }
3225
3226 if (((width == 1 || width == 2) &&
3227 (GLuint) width != texImage->Width) ||
3228 (width > texImage->Width)) {
3229 _mesa_error(ctx, GL_INVALID_VALUE,
3230 "glCompressedTexSubImage%uD(width=%d)", dims, width);
3231 return GL_TRUE;
3232 }
3233
3234 if (dims >= 2) {
3235 if (((height == 1 || height == 2) &&
3236 (GLuint) height != texImage->Height) ||
3237 (height > texImage->Height)) {
3238 _mesa_error(ctx, GL_INVALID_VALUE,
3239 "glCompressedTexSubImage%uD(height=%d)", dims, height);
3240 return GL_TRUE;
3241 }
3242 }
3243
3244 if (dims >= 3) {
3245 if (((depth == 1 || depth == 2) &&
3246 (GLuint) depth != texImage->Depth) ||
3247 (depth > texImage->Depth)) {
3248 _mesa_error(ctx, GL_INVALID_VALUE,
3249 "glCompressedTexSubImage%uD(depth=%d)", dims, depth);
3250 return GL_TRUE;
3251 }
3252 }
3253
3254 return GL_FALSE;
3255 }
3256
3257
3258
3259 void GLAPIENTRY
3260 _mesa_CompressedTexImage1DARB(GLenum target, GLint level,
3261 GLenum internalFormat, GLsizei width,
3262 GLint border, GLsizei imageSize,
3263 const GLvoid *data)
3264 {
3265 GET_CURRENT_CONTEXT(ctx);
3266 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
3267
3268 if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
3269 _mesa_debug(ctx, "glCompressedTexImage1DARB %s %d %s %d %d %d %p\n",
3270 _mesa_lookup_enum_by_nr(target), level,
3271 _mesa_lookup_enum_by_nr(internalFormat),
3272 width, border, imageSize, data);
3273
3274 if (target == GL_TEXTURE_1D) {
3275 /* non-proxy target */
3276 struct gl_texture_object *texObj;
3277 struct gl_texture_image *texImage;
3278 GLenum error = compressed_texture_error_check(ctx, 1, target, level,
3279 internalFormat, width, 1, 1, border, imageSize);
3280 if (error) {
3281 _mesa_error(ctx, error, "glCompressedTexImage1D");
3282 return;
3283 }
3284
3285 texObj = get_current_tex_object(ctx, target);
3286
3287 _mesa_lock_texture(ctx, texObj);
3288 {
3289 texImage = _mesa_get_tex_image(ctx, texObj, target, level);
3290 if (!texImage) {
3291 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage1D");
3292 }
3293 else {
3294 if (texImage->Data) {
3295 ctx->Driver.FreeTexImageData( ctx, texImage );
3296 }
3297 ASSERT(texImage->Data == NULL);
3298
3299 _mesa_init_teximage_fields(ctx, target, texImage, width, 1, 1,
3300 border, internalFormat);
3301
3302 /* Choose actual texture format */
3303 texImage->TexFormat =
3304 ctx->Driver.ChooseTextureFormat(ctx, internalFormat,
3305 GL_NONE, GL_NONE);
3306 ASSERT(texImage->TexFormat != MESA_FORMAT_NONE);
3307
3308 ASSERT(ctx->Driver.CompressedTexImage1D);
3309 ctx->Driver.CompressedTexImage1D(ctx, target, level,
3310 internalFormat, width, border,
3311 imageSize, data,
3312 texObj, texImage);
3313
3314 _mesa_set_fetch_functions(texImage, 1);
3315
3316 check_gen_mipmap(ctx, target, texObj, level);
3317
3318 /* state update */
3319 texObj->_Complete = GL_FALSE;
3320 ctx->NewState |= _NEW_TEXTURE;
3321 }
3322 }
3323 _mesa_unlock_texture(ctx, texObj);
3324 }
3325 else if (target == GL_PROXY_TEXTURE_1D) {
3326 /* Proxy texture: check for errors and update proxy state */
3327 GLenum error = compressed_texture_error_check(ctx, 1, target, level,
3328 internalFormat, width, 1, 1, border, imageSize);
3329 if (!error) {
3330 ASSERT(ctx->Driver.TestProxyTexImage);
3331 error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level,
3332 internalFormat, GL_NONE, GL_NONE,
3333 width, 1, 1, border);
3334 }
3335 if (error) {
3336 /* if error, clear all proxy texture image parameters */
3337 struct gl_texture_image *texImage;
3338 texImage = _mesa_get_proxy_tex_image(ctx, target, level);
3339 if (texImage)
3340 clear_teximage_fields(texImage);
3341 }
3342 else {
3343 /* store the teximage parameters */
3344 struct gl_texture_object *texObj;
3345 struct gl_texture_image *texImage;
3346
3347 texObj = get_current_tex_object(ctx, target);
3348
3349 _mesa_lock_texture(ctx, texObj);
3350 {
3351 texImage = _mesa_select_tex_image(ctx, texObj, target, level);
3352 _mesa_init_teximage_fields(ctx, target, texImage, width, 1, 1,
3353 border, internalFormat);
3354 }
3355 _mesa_unlock_texture(ctx, texObj);
3356 }
3357 }
3358 else {
3359 _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage1D(target)");
3360 return;
3361 }
3362 }
3363
3364
3365 void GLAPIENTRY
3366 _mesa_CompressedTexImage2DARB(GLenum target, GLint level,
3367 GLenum internalFormat, GLsizei width,
3368 GLsizei height, GLint border, GLsizei imageSize,
3369 const GLvoid *data)
3370 {
3371 GET_CURRENT_CONTEXT(ctx);
3372 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
3373
3374 if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
3375 _mesa_debug(ctx, "glCompressedTexImage2DARB %s %d %s %d %d %d %d %p\n",
3376 _mesa_lookup_enum_by_nr(target), level,
3377 _mesa_lookup_enum_by_nr(internalFormat),
3378 width, height, border, imageSize, data);
3379
3380 if (target == GL_TEXTURE_2D ||
3381 (ctx->Extensions.ARB_texture_cube_map &&
3382 target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
3383 target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)) {
3384 /* non-proxy target */
3385 struct gl_texture_object *texObj;
3386 struct gl_texture_image *texImage;
3387
3388 GLenum error = compressed_texture_error_check(ctx, 2, target, level,
3389 internalFormat, width, height, 1, border, imageSize);
3390 if (error) {
3391 _mesa_error(ctx, error, "glCompressedTexImage2D");
3392 return;
3393 }
3394
3395 texObj = get_current_tex_object(ctx, target);
3396
3397 _mesa_lock_texture(ctx, texObj);
3398 {
3399 texImage = _mesa_get_tex_image(ctx, texObj, target, level);
3400 if (!texImage) {
3401 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2D");
3402 }
3403 else {
3404 if (texImage->Data) {
3405 ctx->Driver.FreeTexImageData( ctx, texImage );
3406 }
3407 ASSERT(texImage->Data == NULL);
3408
3409 _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1,
3410 border, internalFormat);
3411
3412 /* Choose actual texture format */
3413 texImage->TexFormat =
3414 ctx->Driver.ChooseTextureFormat(ctx, internalFormat,
3415 GL_NONE, GL_NONE);
3416 ASSERT(texImage->TexFormat != MESA_FORMAT_NONE);
3417
3418 ASSERT(ctx->Driver.CompressedTexImage2D);
3419 ctx->Driver.CompressedTexImage2D(ctx, target, level,
3420 internalFormat, width, height,
3421 border, imageSize, data,
3422 texObj, texImage);
3423
3424 _mesa_set_fetch_functions(texImage, 2);
3425
3426 check_gen_mipmap(ctx, target, texObj, level);
3427
3428 /* state update */
3429 texObj->_Complete = GL_FALSE;
3430 ctx->NewState |= _NEW_TEXTURE;
3431 }
3432 }
3433 _mesa_unlock_texture(ctx, texObj);
3434 }
3435 else if (target == GL_PROXY_TEXTURE_2D ||
3436 (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB &&
3437 ctx->Extensions.ARB_texture_cube_map)) {
3438 /* Proxy texture: check for errors and update proxy state */
3439 GLenum error = compressed_texture_error_check(ctx, 2, target, level,
3440 internalFormat, width, height, 1, border, imageSize);
3441 if (!error) {
3442 ASSERT(ctx->Driver.TestProxyTexImage);
3443 error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level,
3444 internalFormat, GL_NONE, GL_NONE,
3445 width, height, 1, border);
3446 }
3447 if (error) {
3448 /* if error, clear all proxy texture image parameters */
3449 struct gl_texture_image *texImage;
3450 texImage = _mesa_get_proxy_tex_image(ctx, target, level);
3451 if (texImage)
3452 clear_teximage_fields(texImage);
3453 }
3454 else {
3455 /* store the teximage parameters */
3456 struct gl_texture_object *texObj;
3457 struct gl_texture_image *texImage;
3458
3459 texObj = get_current_tex_object(ctx, target);
3460
3461 _mesa_lock_texture(ctx, texObj);
3462 {
3463 texImage = _mesa_select_tex_image(ctx, texObj, target, level);
3464 _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1,
3465 border, internalFormat);
3466 }
3467 _mesa_unlock_texture(ctx, texObj);
3468 }
3469 }
3470 else {
3471 _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage2D(target)");
3472 return;
3473 }
3474 }
3475
3476
3477 void GLAPIENTRY
3478 _mesa_CompressedTexImage3DARB(GLenum target, GLint level,
3479 GLenum internalFormat, GLsizei width,
3480 GLsizei height, GLsizei depth, GLint border,
3481 GLsizei imageSize, const GLvoid *data)
3482 {
3483 GET_CURRENT_CONTEXT(ctx);
3484 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
3485
3486 if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
3487 _mesa_debug(ctx, "glCompressedTexImage3DARB %s %d %s %d %d %d %d %d %p\n",
3488 _mesa_lookup_enum_by_nr(target), level,
3489 _mesa_lookup_enum_by_nr(internalFormat),
3490 width, height, depth, border, imageSize, data);
3491
3492 if (target == GL_TEXTURE_3D) {
3493 /* non-proxy target */
3494 struct gl_texture_object *texObj;
3495 struct gl_texture_image *texImage;
3496 GLenum error = compressed_texture_error_check(ctx, 3, target, level,
3497 internalFormat, width, height, depth, border, imageSize);
3498 if (error) {
3499 _mesa_error(ctx, error, "glCompressedTexImage3D");
3500 return;
3501 }
3502
3503 texObj = get_current_tex_object(ctx, target);
3504
3505 _mesa_lock_texture(ctx, texObj);
3506 {
3507 texImage = _mesa_get_tex_image(ctx, texObj, target, level);
3508 if (!texImage) {
3509 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage3D");
3510 }
3511 else {
3512 if (texImage->Data) {
3513 ctx->Driver.FreeTexImageData( ctx, texImage );
3514 }
3515 ASSERT(texImage->Data == NULL);
3516
3517 _mesa_init_teximage_fields(ctx, target, texImage,
3518 width, height, depth,
3519 border, internalFormat);
3520
3521 /* Choose actual texture format */
3522 texImage->TexFormat =
3523 ctx->Driver.ChooseTextureFormat(ctx, internalFormat,
3524 GL_NONE, GL_NONE);
3525 ASSERT(texImage->TexFormat != MESA_FORMAT_NONE);
3526
3527 ASSERT(ctx->Driver.CompressedTexImage3D);
3528 ctx->Driver.CompressedTexImage3D(ctx, target, level,
3529 internalFormat,
3530 width, height, depth,
3531 border, imageSize, data,
3532 texObj, texImage);
3533
3534 _mesa_set_fetch_functions(texImage, 3);
3535
3536 check_gen_mipmap(ctx, target, texObj, level);
3537
3538 /* state update */
3539 texObj->_Complete = GL_FALSE;
3540 ctx->NewState |= _NEW_TEXTURE;
3541 }
3542 }
3543 _mesa_unlock_texture(ctx, texObj);
3544 }
3545 else if (target == GL_PROXY_TEXTURE_3D) {
3546 /* Proxy texture: check for errors and update proxy state */
3547 GLenum error = compressed_texture_error_check(ctx, 3, target, level,
3548 internalFormat, width, height, depth, border, imageSize);
3549 if (!error) {
3550 ASSERT(ctx->Driver.TestProxyTexImage);
3551 error = !(*ctx->Driver.TestProxyTexImage)(ctx, target, level,
3552 internalFormat, GL_NONE, GL_NONE,
3553 width, height, depth, border);
3554 }
3555 if (error) {
3556 /* if error, clear all proxy texture image parameters */
3557 struct gl_texture_image *texImage;
3558 texImage = _mesa_get_proxy_tex_image(ctx, target, level);
3559 if (texImage)
3560 clear_teximage_fields(texImage);
3561 }
3562 else {
3563 /* store the teximage parameters */
3564 struct gl_texture_object *texObj;
3565 struct gl_texture_image *texImage;
3566
3567 texObj = get_current_tex_object(ctx, target);
3568
3569 _mesa_lock_texture(ctx, texObj);
3570 {
3571 texImage = _mesa_select_tex_image(ctx, texObj, target, level);
3572 _mesa_init_teximage_fields(ctx, target, texImage, width, height,
3573 depth, border, internalFormat);
3574 }
3575 _mesa_unlock_texture(ctx, texObj);
3576 }
3577 }
3578 else {
3579 _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage3D(target)");
3580 return;
3581 }
3582 }
3583
3584
3585 /**
3586 * Common helper for glCompressedTexSubImage1/2/3D().
3587 */
3588 static void
3589 compressed_tex_sub_image(GLuint dims, GLenum target, GLint level,
3590 GLint xoffset, GLint yoffset, GLint zoffset,
3591 GLsizei width, GLsizei height, GLsizei depth,
3592 GLenum format, GLsizei imageSize, const GLvoid *data)
3593 {
3594 struct gl_texture_object *texObj;
3595 struct gl_texture_image *texImage;
3596 GLenum error;
3597 GET_CURRENT_CONTEXT(ctx);
3598 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
3599
3600 error = compressed_subtexture_error_check(ctx, dims, target, level,
3601 xoffset, 0, 0, /* pos */
3602 width, height, depth, /* size */
3603 format, imageSize);
3604 if (error) {
3605 _mesa_error(ctx, error, "glCompressedTexSubImage%uD", dims);
3606 return;
3607 }
3608
3609 texObj = get_current_tex_object(ctx, target);
3610
3611 _mesa_lock_texture(ctx, texObj);
3612 {
3613 texImage = _mesa_select_tex_image(ctx, texObj, target, level);
3614 assert(texImage);
3615
3616 if (compressed_subtexture_error_check2(ctx, dims, width, height, depth,
3617 format, texImage)) {
3618 /* error was recorded */
3619 }
3620 else if (width > 0 && height > 0 && depth > 0) {
3621 switch (dims) {
3622 case 1:
3623 if (ctx->Driver.CompressedTexSubImage1D) {
3624 ctx->Driver.CompressedTexSubImage1D(ctx, target, level,
3625 xoffset, width,
3626 format, imageSize, data,
3627 texObj, texImage);
3628 }
3629 break;
3630 case 2:
3631 if (ctx->Driver.CompressedTexSubImage2D) {
3632 ctx->Driver.CompressedTexSubImage2D(ctx, target, level,
3633 xoffset, yoffset,
3634 width, height,
3635 format, imageSize, data,
3636 texObj, texImage);
3637 }
3638 break;
3639 case 3:
3640 if (ctx->Driver.CompressedTexSubImage3D) {
3641 ctx->Driver.CompressedTexSubImage3D(ctx, target, level,
3642 xoffset, yoffset, zoffset,
3643 width, height, depth,
3644 format, imageSize, data,
3645 texObj, texImage);
3646 }
3647 break;
3648 default:
3649 ;
3650 }
3651
3652 check_gen_mipmap(ctx, target, texObj, level);
3653
3654 ctx->NewState |= _NEW_TEXTURE;
3655 }
3656 }
3657 _mesa_unlock_texture(ctx, texObj);
3658 }
3659
3660
3661 void GLAPIENTRY
3662 _mesa_CompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset,
3663 GLsizei width, GLenum format,
3664 GLsizei imageSize, const GLvoid *data)
3665 {
3666 compressed_tex_sub_image(1, target, level, xoffset, 0, 0, width, 1, 1,
3667 format, imageSize, data);
3668 }
3669
3670
3671 void GLAPIENTRY
3672 _mesa_CompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset,
3673 GLint yoffset, GLsizei width, GLsizei height,
3674 GLenum format, GLsizei imageSize,
3675 const GLvoid *data)
3676 {
3677 compressed_tex_sub_image(2, target, level, xoffset, yoffset, 0,
3678 width, height, 1, format, imageSize, data);
3679 }
3680
3681
3682 void GLAPIENTRY
3683 _mesa_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset,
3684 GLint yoffset, GLint zoffset, GLsizei width,
3685 GLsizei height, GLsizei depth, GLenum format,
3686 GLsizei imageSize, const GLvoid *data)
3687 {
3688 compressed_tex_sub_image(3, target, level, xoffset, yoffset, zoffset,
3689 width, height, depth, format, imageSize, data);
3690 }
3691
3692