2a6c358e41487e9779ee4ed9e44aebf9e8475a0d
[mesa.git] / src / mesa / main / texgetimage.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.7
4 *
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (c) 2009 VMware, Inc.
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 * Code for glGetTexImage() and glGetCompressedTexImage().
29 */
30
31
32 #include "glheader.h"
33 #include "bufferobj.h"
34 #include "enums.h"
35 #include "context.h"
36 #include "formats.h"
37 #include "image.h"
38 #include "texcompress.h"
39 #include "texgetimage.h"
40 #include "teximage.h"
41 #include "texstate.h"
42
43
44
45 #if FEATURE_EXT_texture_sRGB
46
47 /**
48 * Convert a float value from linear space to a
49 * non-linear sRGB value in [0, 255].
50 * Not terribly efficient.
51 */
52 static INLINE GLfloat
53 linear_to_nonlinear(GLfloat cl)
54 {
55 /* can't have values outside [0, 1] */
56 GLfloat cs;
57 if (cl < 0.0031308f) {
58 cs = 12.92f * cl;
59 }
60 else {
61 cs = (GLfloat)(1.055 * _mesa_pow(cl, 0.41666) - 0.055);
62 }
63 return cs;
64 }
65
66 #endif /* FEATURE_EXT_texture_sRGB */
67
68
69 /**
70 * Can the given type represent negative values?
71 */
72 static INLINE GLboolean
73 type_with_negative_values(GLenum type)
74 {
75 switch (type) {
76 case GL_BYTE:
77 case GL_SHORT:
78 case GL_INT:
79 case GL_FLOAT:
80 case GL_HALF_FLOAT_ARB:
81 return GL_TRUE;
82 default:
83 return GL_FALSE;
84 }
85 }
86
87
88 /**
89 * This is the software fallback for Driver.GetTexImage().
90 * All error checking will have been done before this routine is called.
91 */
92 void
93 _mesa_get_teximage(GLcontext *ctx, GLenum target, GLint level,
94 GLenum format, GLenum type, GLvoid *pixels,
95 struct gl_texture_object *texObj,
96 struct gl_texture_image *texImage)
97 {
98 const GLuint dimensions = (target == GL_TEXTURE_3D) ? 3 : 2;
99
100 if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
101 /* Packing texture image into a PBO.
102 * Map the (potentially) VRAM-based buffer into our process space so
103 * we can write into it with the code below.
104 * A hardware driver might use a sophisticated blit to move the
105 * texture data to the PBO if the PBO is in VRAM along with the texture.
106 */
107 GLubyte *buf = (GLubyte *)
108 ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
109 GL_WRITE_ONLY_ARB, ctx->Pack.BufferObj);
110 if (!buf) {
111 /* out of memory or other unexpected error */
112 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage(map PBO failed)");
113 return;
114
115 }
116 /* <pixels> was an offset into the PBO.
117 * Now make it a real, client-side pointer inside the mapped region.
118 */
119 pixels = ADD_POINTERS(buf, pixels);
120 }
121 else if (!pixels) {
122 /* not an error */
123 return;
124 }
125
126 {
127 const GLint width = texImage->Width;
128 const GLint height = texImage->Height;
129 const GLint depth = texImage->Depth;
130 GLint img, row;
131 for (img = 0; img < depth; img++) {
132 for (row = 0; row < height; row++) {
133 /* compute destination address in client memory */
134 GLvoid *dest = _mesa_image_address( dimensions, &ctx->Pack, pixels,
135 width, height, format, type,
136 img, row, 0);
137 assert(dest);
138
139 if (format == GL_COLOR_INDEX) {
140 GLuint indexRow[MAX_WIDTH];
141 GLint col;
142 GLuint indexBits = _mesa_get_format_bits(texImage->TexFormat, GL_TEXTURE_INDEX_SIZE_EXT);
143 /* Can't use FetchTexel here because that returns RGBA */
144 if (indexBits == 8) {
145 const GLubyte *src = (const GLubyte *) texImage->Data;
146 src += width * (img * texImage->Height + row);
147 for (col = 0; col < width; col++) {
148 indexRow[col] = src[col];
149 }
150 }
151 else if (indexBits == 16) {
152 const GLushort *src = (const GLushort *) texImage->Data;
153 src += width * (img * texImage->Height + row);
154 for (col = 0; col < width; col++) {
155 indexRow[col] = src[col];
156 }
157 }
158 else {
159 _mesa_problem(ctx,
160 "Color index problem in _mesa_GetTexImage");
161 }
162 _mesa_pack_index_span(ctx, width, type, dest,
163 indexRow, &ctx->Pack,
164 0 /* no image transfer */);
165 }
166 else if (format == GL_DEPTH_COMPONENT) {
167 GLfloat depthRow[MAX_WIDTH];
168 GLint col;
169 for (col = 0; col < width; col++) {
170 (*texImage->FetchTexelf)(texImage, col, row, img,
171 depthRow + col);
172 }
173 _mesa_pack_depth_span(ctx, width, dest, type,
174 depthRow, &ctx->Pack);
175 }
176 else if (format == GL_DEPTH_STENCIL_EXT) {
177 /* XXX Note: we're bypassing texImage->FetchTexel()! */
178 const GLuint *src = (const GLuint *) texImage->Data;
179 src += width * row + width * height * img;
180 _mesa_memcpy(dest, src, width * sizeof(GLuint));
181 if (ctx->Pack.SwapBytes) {
182 _mesa_swap4((GLuint *) dest, width);
183 }
184 }
185 else if (format == GL_YCBCR_MESA) {
186 /* No pixel transfer */
187 const GLint rowstride = texImage->RowStride;
188 MEMCPY(dest,
189 (const GLushort *) texImage->Data + row * rowstride,
190 width * sizeof(GLushort));
191 /* check for byte swapping */
192 if ((texImage->TexFormat == MESA_FORMAT_YCBCR
193 && type == GL_UNSIGNED_SHORT_8_8_REV_MESA) ||
194 (texImage->TexFormat == MESA_FORMAT_YCBCR_REV
195 && type == GL_UNSIGNED_SHORT_8_8_MESA)) {
196 if (!ctx->Pack.SwapBytes)
197 _mesa_swap2((GLushort *) dest, width);
198 }
199 else if (ctx->Pack.SwapBytes) {
200 _mesa_swap2((GLushort *) dest, width);
201 }
202 }
203 #if FEATURE_EXT_texture_sRGB
204 else if (_mesa_get_format_color_encoding(texImage->TexFormat)
205 == GL_SRGB) {
206 /* special case this since need to backconvert values */
207 /* convert row to RGBA format */
208 GLfloat rgba[MAX_WIDTH][4];
209 GLint col;
210 GLbitfield transferOps = 0x0;
211
212 for (col = 0; col < width; col++) {
213 (*texImage->FetchTexelf)(texImage, col, row, img, rgba[col]);
214 if (texImage->_BaseFormat == GL_LUMINANCE) {
215 rgba[col][RCOMP] = linear_to_nonlinear(rgba[col][RCOMP]);
216 rgba[col][GCOMP] = 0.0;
217 rgba[col][BCOMP] = 0.0;
218 }
219 else if (texImage->_BaseFormat == GL_LUMINANCE_ALPHA) {
220 rgba[col][RCOMP] = linear_to_nonlinear(rgba[col][RCOMP]);
221 rgba[col][GCOMP] = 0.0;
222 rgba[col][BCOMP] = 0.0;
223 }
224 else if (texImage->_BaseFormat == GL_RGB ||
225 texImage->_BaseFormat == GL_RGBA) {
226 rgba[col][RCOMP] = linear_to_nonlinear(rgba[col][RCOMP]);
227 rgba[col][GCOMP] = linear_to_nonlinear(rgba[col][GCOMP]);
228 rgba[col][BCOMP] = linear_to_nonlinear(rgba[col][BCOMP]);
229 }
230 }
231 _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba,
232 format, type, dest,
233 &ctx->Pack, transferOps);
234 }
235 #endif /* FEATURE_EXT_texture_sRGB */
236 else {
237 /* general case: convert row to RGBA format */
238 GLfloat rgba[MAX_WIDTH][4];
239 GLint col;
240 GLbitfield transferOps = 0x0;
241 GLenum dataType =
242 _mesa_get_format_datatype(texImage->TexFormat);
243
244 /* clamp does not apply to GetTexImage (final conversion)?
245 * Looks like we need clamp though when going from format
246 * containing negative values to unsigned format.
247 */
248 if (format == GL_LUMINANCE || format == GL_LUMINANCE_ALPHA)
249 transferOps |= IMAGE_CLAMP_BIT;
250 else if (!type_with_negative_values(type) &&
251 (dataType == GL_FLOAT ||
252 dataType == GL_SIGNED_NORMALIZED))
253 transferOps |= IMAGE_CLAMP_BIT;
254
255 for (col = 0; col < width; col++) {
256 (*texImage->FetchTexelf)(texImage, col, row, img, rgba[col]);
257 if (texImage->_BaseFormat == GL_ALPHA) {
258 rgba[col][RCOMP] = 0.0;
259 rgba[col][GCOMP] = 0.0;
260 rgba[col][BCOMP] = 0.0;
261 }
262 else if (texImage->_BaseFormat == GL_LUMINANCE) {
263 rgba[col][GCOMP] = 0.0;
264 rgba[col][BCOMP] = 0.0;
265 rgba[col][ACOMP] = 1.0;
266 }
267 else if (texImage->_BaseFormat == GL_LUMINANCE_ALPHA) {
268 rgba[col][GCOMP] = 0.0;
269 rgba[col][BCOMP] = 0.0;
270 }
271 else if (texImage->_BaseFormat == GL_INTENSITY) {
272 rgba[col][GCOMP] = 0.0;
273 rgba[col][BCOMP] = 0.0;
274 rgba[col][ACOMP] = 1.0;
275 }
276 }
277 _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba,
278 format, type, dest,
279 &ctx->Pack, transferOps);
280 } /* format */
281 } /* row */
282 } /* img */
283 }
284
285 if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
286 ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
287 ctx->Pack.BufferObj);
288 }
289 }
290
291
292
293 /**
294 * This is the software fallback for Driver.GetCompressedTexImage().
295 * All error checking will have been done before this routine is called.
296 */
297 void
298 _mesa_get_compressed_teximage(GLcontext *ctx, GLenum target, GLint level,
299 GLvoid *img,
300 struct gl_texture_object *texObj,
301 struct gl_texture_image *texImage)
302 {
303 const GLuint size = _mesa_format_image_size(texImage->TexFormat,
304 texImage->Width,
305 texImage->Height,
306 texImage->Depth);
307
308 if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
309 /* pack texture image into a PBO */
310 GLubyte *buf = (GLubyte *)
311 ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
312 GL_WRITE_ONLY_ARB, ctx->Pack.BufferObj);
313 if (!buf) {
314 /* out of memory or other unexpected error */
315 _mesa_error(ctx, GL_OUT_OF_MEMORY,
316 "glGetCompresssedTexImage(map PBO failed)");
317 return;
318 }
319 img = ADD_POINTERS(buf, img);
320 }
321 else if (!img) {
322 /* not an error */
323 return;
324 }
325
326 /* just memcpy, no pixelstore or pixel transfer */
327 _mesa_memcpy(img, texImage->Data, size);
328
329 if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
330 ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
331 ctx->Pack.BufferObj);
332 }
333 }
334
335
336
337 /**
338 * Do error checking for a glGetTexImage() call.
339 * \return GL_TRUE if any error, GL_FALSE if no errors.
340 */
341 static GLboolean
342 getteximage_error_check(GLcontext *ctx, GLenum target, GLint level,
343 GLenum format, GLenum type, GLvoid *pixels )
344 {
345 const struct gl_texture_unit *texUnit;
346 struct gl_texture_object *texObj;
347 struct gl_texture_image *texImage;
348 const GLuint maxLevels = _mesa_max_texture_levels(ctx, target);
349 GLenum baseFormat;
350
351 if (maxLevels == 0) {
352 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(target=0x%x)", target);
353 return GL_TRUE;
354 }
355
356 if (level < 0 || level >= maxLevels) {
357 _mesa_error( ctx, GL_INVALID_VALUE, "glGetTexImage(level)" );
358 return GL_TRUE;
359 }
360
361 if (_mesa_sizeof_packed_type(type) <= 0) {
362 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexImage(type)" );
363 return GL_TRUE;
364 }
365
366 if (_mesa_components_in_format(format) <= 0 ||
367 format == GL_STENCIL_INDEX) {
368 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexImage(format)" );
369 return GL_TRUE;
370 }
371
372 if (!ctx->Extensions.EXT_paletted_texture && _mesa_is_index_format(format)) {
373 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)");
374 return GL_TRUE;
375 }
376
377 if (!ctx->Extensions.ARB_depth_texture && _mesa_is_depth_format(format)) {
378 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)");
379 return GL_TRUE;
380 }
381
382 if (!ctx->Extensions.MESA_ycbcr_texture && _mesa_is_ycbcr_format(format)) {
383 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)");
384 return GL_TRUE;
385 }
386
387 if (!ctx->Extensions.EXT_packed_depth_stencil
388 && _mesa_is_depthstencil_format(format)) {
389 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)");
390 return GL_TRUE;
391 }
392
393 if (!ctx->Extensions.ATI_envmap_bumpmap
394 && _mesa_is_dudv_format(format)) {
395 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)");
396 return GL_TRUE;
397 }
398
399 texUnit = _mesa_get_current_tex_unit(ctx);
400 texObj = _mesa_select_tex_object(ctx, texUnit, target);
401
402 if (!texObj || _mesa_is_proxy_texture(target)) {
403 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(target)");
404 return GL_TRUE;
405 }
406
407 texImage = _mesa_select_tex_image(ctx, texObj, target, level);
408 if (!texImage) {
409 /* out of memory */
410 return GL_TRUE;
411 }
412
413 baseFormat = _mesa_get_format_base_format(texImage->TexFormat);
414
415 /* Make sure the requested image format is compatible with the
416 * texture's format. Note that a color index texture can be converted
417 * to RGBA so that combo is allowed.
418 */
419 if (_mesa_is_color_format(format)
420 && !_mesa_is_color_format(baseFormat)
421 && !_mesa_is_index_format(baseFormat)) {
422 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
423 return GL_TRUE;
424 }
425 else if (_mesa_is_index_format(format)
426 && !_mesa_is_index_format(baseFormat)) {
427 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
428 return GL_TRUE;
429 }
430 else if (_mesa_is_depth_format(format)
431 && !_mesa_is_depth_format(baseFormat)
432 && !_mesa_is_depthstencil_format(baseFormat)) {
433 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
434 return GL_TRUE;
435 }
436 else if (_mesa_is_ycbcr_format(format)
437 && !_mesa_is_ycbcr_format(baseFormat)) {
438 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
439 return GL_TRUE;
440 }
441 else if (_mesa_is_depthstencil_format(format)
442 && !_mesa_is_depthstencil_format(baseFormat)) {
443 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
444 return GL_TRUE;
445 }
446 else if (_mesa_is_dudv_format(format)
447 && !_mesa_is_dudv_format(baseFormat)) {
448 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
449 return GL_TRUE;
450 }
451
452 if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
453 /* packing texture image into a PBO */
454 const GLuint dimensions = (target == GL_TEXTURE_3D) ? 3 : 2;
455 if (!_mesa_validate_pbo_access(dimensions, &ctx->Pack, texImage->Width,
456 texImage->Height, texImage->Depth,
457 format, type, pixels)) {
458 _mesa_error(ctx, GL_INVALID_OPERATION,
459 "glGetTexImage(out of bounds PBO write)");
460 return GL_TRUE;
461 }
462
463 /* PBO should not be mapped */
464 if (_mesa_bufferobj_mapped(ctx->Pack.BufferObj)) {
465 _mesa_error(ctx, GL_INVALID_OPERATION,
466 "glGetTexImage(PBO is mapped)");
467 return GL_TRUE;
468 }
469 }
470
471 return GL_FALSE;
472 }
473
474
475
476 /**
477 * Get texture image. Called by glGetTexImage.
478 *
479 * \param target texture target.
480 * \param level image level.
481 * \param format pixel data format for returned image.
482 * \param type pixel data type for returned image.
483 * \param pixels returned pixel data.
484 */
485 void GLAPIENTRY
486 _mesa_GetTexImage( GLenum target, GLint level, GLenum format,
487 GLenum type, GLvoid *pixels )
488 {
489 const struct gl_texture_unit *texUnit;
490 struct gl_texture_object *texObj;
491 struct gl_texture_image *texImage;
492 GET_CURRENT_CONTEXT(ctx);
493 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
494
495 if (getteximage_error_check(ctx, target, level, format, type, pixels)) {
496 return;
497 }
498
499 texUnit = _mesa_get_current_tex_unit(ctx);
500 texObj = _mesa_select_tex_object(ctx, texUnit, target);
501 texImage = _mesa_select_tex_image(ctx, texObj, target, level);
502
503 if (MESA_VERBOSE & (VERBOSE_API | VERBOSE_TEXTURE)) {
504 _mesa_debug(ctx, "glGetTexImage(tex %u) format = %s, w=%d, h=%d,"
505 " dstFmt=0x%x, dstType=0x%x\n",
506 texObj->Name,
507 _mesa_get_format_name(texImage->TexFormat),
508 texImage->Width, texImage->Height,
509 format, type);
510 }
511
512 _mesa_lock_texture(ctx, texObj);
513 {
514 ctx->Driver.GetTexImage(ctx, target, level, format, type, pixels,
515 texObj, texImage);
516 }
517 _mesa_unlock_texture(ctx, texObj);
518 }
519
520
521
522 /**
523 * Do error checking for a glGetCompressedTexImage() call.
524 * \return GL_TRUE if any error, GL_FALSE if no errors.
525 */
526 static GLboolean
527 getcompressedteximage_error_check(GLcontext *ctx, GLenum target, GLint level,
528 GLvoid *img)
529 {
530 const struct gl_texture_unit *texUnit;
531 struct gl_texture_object *texObj;
532 struct gl_texture_image *texImage;
533 const GLuint maxLevels = _mesa_max_texture_levels(ctx, target);
534
535 if (maxLevels == 0) {
536 _mesa_error(ctx, GL_INVALID_ENUM, "glGetCompressedTexImage(target=0x%x)",
537 target);
538 return GL_TRUE;
539 }
540
541 if (level < 0 || level >= maxLevels) {
542 _mesa_error(ctx, GL_INVALID_VALUE,
543 "glGetCompressedTexImageARB(bad level = %d)", level);
544 return GL_TRUE;
545 }
546
547 if (_mesa_is_proxy_texture(target)) {
548 _mesa_error(ctx, GL_INVALID_ENUM,
549 "glGetCompressedTexImageARB(bad target = %s)",
550 _mesa_lookup_enum_by_nr(target));
551 return GL_TRUE;
552 }
553
554 texUnit = _mesa_get_current_tex_unit(ctx);
555 texObj = _mesa_select_tex_object(ctx, texUnit, target);
556
557 if (!texObj) {
558 _mesa_error(ctx, GL_INVALID_ENUM, "glGetCompressedTexImageARB(target)");
559 return GL_TRUE;
560 }
561
562 texImage = _mesa_select_tex_image(ctx, texObj, target, level);
563
564 if (!texImage) {
565 /* probably invalid mipmap level */
566 _mesa_error(ctx, GL_INVALID_VALUE,
567 "glGetCompressedTexImageARB(level)");
568 return GL_TRUE;
569 }
570
571 if (!_mesa_is_format_compressed(texImage->TexFormat)) {
572 _mesa_error(ctx, GL_INVALID_OPERATION,
573 "glGetCompressedTexImageARB(texture is not compressed)");
574 return GL_TRUE;
575 }
576
577 if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
578 GLuint compressedSize;
579
580 /* make sure PBO is not mapped */
581 if (_mesa_bufferobj_mapped(ctx->Pack.BufferObj)) {
582 _mesa_error(ctx, GL_INVALID_OPERATION,
583 "glGetCompressedTexImage(PBO is mapped)");
584 return GL_TRUE;
585 }
586
587 compressedSize = _mesa_format_image_size(texImage->TexFormat,
588 texImage->Width,
589 texImage->Height,
590 texImage->Depth);
591
592 /* do bounds checking on PBO write */
593 if ((const GLubyte *) img + compressedSize >
594 (const GLubyte *) ctx->Pack.BufferObj->Size) {
595 _mesa_error(ctx, GL_INVALID_OPERATION,
596 "glGetCompressedTexImage(out of bounds PBO write)");
597 return GL_TRUE;
598 }
599 }
600
601 return GL_FALSE;
602 }
603
604
605 void GLAPIENTRY
606 _mesa_GetCompressedTexImageARB(GLenum target, GLint level, GLvoid *img)
607 {
608 const struct gl_texture_unit *texUnit;
609 struct gl_texture_object *texObj;
610 GET_CURRENT_CONTEXT(ctx);
611 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
612
613 if (getcompressedteximage_error_check(ctx, target, level, img)) {
614 return;
615 }
616
617 texUnit = _mesa_get_current_tex_unit(ctx);
618 texObj = _mesa_select_tex_object(ctx, texUnit, target);
619
620 if (MESA_VERBOSE & (VERBOSE_API | VERBOSE_TEXTURE)) {
621 struct gl_texture_image *texImage =
622 _mesa_select_tex_image(ctx, texObj, target, level);
623 _mesa_debug(ctx,
624 "glGetCompressedTexImage(tex %u) format = %s, w=%d, h=%d\n",
625 texObj->Name,
626 _mesa_get_format_name(texImage->TexFormat),
627 texImage->Width, texImage->Height);
628 }
629
630 _mesa_lock_texture(ctx, texObj);
631 {
632 struct gl_texture_image *texImage =
633 _mesa_select_tex_image(ctx, texObj, target, level);
634
635 /* this typically calls _mesa_get_compressed_teximage() */
636 ctx->Driver.GetCompressedTexImage(ctx, target, level, img,
637 texObj, texImage);
638 }
639 _mesa_unlock_texture(ctx, texObj);
640 }