2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (c) 2009 VMware, Inc.
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:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
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.
28 * Code for glGetTexImage() and glGetCompressedTexImage().
33 #include "bufferobj.h"
38 #include "mfeatures.h"
42 #include "texgetimage.h"
49 * Can the given type represent negative values?
51 static INLINE GLboolean
52 type_with_negative_values(GLenum type)
59 case GL_HALF_FLOAT_ARB:
68 * glGetTexImage for color index pixels.
71 get_tex_color_index(struct gl_context *ctx, GLuint dimensions,
72 GLenum format, GLenum type, GLvoid *pixels,
73 const struct gl_texture_image *texImage)
75 const GLint width = texImage->Width;
76 const GLint height = texImage->Height;
77 const GLint depth = texImage->Depth;
78 const GLint rowstride = texImage->RowStride;
79 const GLuint indexBits =
80 _mesa_get_format_bits(texImage->TexFormat, GL_TEXTURE_INDEX_SIZE_EXT);
81 const GLbitfield transferOps = 0x0;
84 for (img = 0; img < depth; img++) {
85 for (row = 0; row < height; row++) {
86 GLuint indexRow[MAX_WIDTH] = { 0 };
87 void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels,
88 width, height, format, type,
93 const GLubyte *src = (const GLubyte *) texImage->Data;
94 src += rowstride * (img * height + row);
95 for (col = 0; col < width; col++) {
96 indexRow[col] = src[col];
99 else if (indexBits == 16) {
100 const GLushort *src = (const GLushort *) texImage->Data;
101 src += rowstride * (img * height + row);
102 for (col = 0; col < width; col++) {
103 indexRow[col] = src[col];
107 _mesa_problem(ctx, "Color index problem in _mesa_GetTexImage");
109 _mesa_pack_index_span(ctx, width, type, dest,
110 indexRow, &ctx->Pack, transferOps);
117 * glGetTexImage for depth/Z pixels.
120 get_tex_depth(struct gl_context *ctx, GLuint dimensions,
121 GLenum format, GLenum type, GLvoid *pixels,
122 const struct gl_texture_image *texImage)
124 const GLint width = texImage->Width;
125 const GLint height = texImage->Height;
126 const GLint depth = texImage->Depth;
128 GLfloat *depthRow = (GLfloat *) malloc(width * sizeof(GLfloat));
131 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage");
135 for (img = 0; img < depth; img++) {
136 for (row = 0; row < height; row++) {
137 void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels,
138 width, height, format, type,
142 for (col = 0; col < width; col++) {
143 texImage->FetchTexelf(texImage, col, row, img, depthRow + col);
145 _mesa_pack_depth_span(ctx, width, dest, type, depthRow, &ctx->Pack);
154 * glGetTexImage for depth/stencil pixels.
157 get_tex_depth_stencil(struct gl_context *ctx, GLuint dimensions,
158 GLenum format, GLenum type, GLvoid *pixels,
159 const struct gl_texture_image *texImage)
161 const GLint width = texImage->Width;
162 const GLint height = texImage->Height;
163 const GLint depth = texImage->Depth;
164 const GLint rowstride = texImage->RowStride;
165 const GLuint *src = (const GLuint *) texImage->Data;
168 for (img = 0; img < depth; img++) {
169 for (row = 0; row < height; row++) {
170 void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels,
171 width, height, format, type,
173 memcpy(dest, src, width * sizeof(GLuint));
174 if (ctx->Pack.SwapBytes) {
175 _mesa_swap4((GLuint *) dest, width);
185 * glGetTexImage for YCbCr pixels.
188 get_tex_ycbcr(struct gl_context *ctx, GLuint dimensions,
189 GLenum format, GLenum type, GLvoid *pixels,
190 const struct gl_texture_image *texImage)
192 const GLint width = texImage->Width;
193 const GLint height = texImage->Height;
194 const GLint depth = texImage->Depth;
195 const GLint rowstride = texImage->RowStride;
196 const GLushort *src = (const GLushort *) texImage->Data;
199 for (img = 0; img < depth; img++) {
200 for (row = 0; row < height; row++) {
201 void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels,
202 width, height, format, type,
204 memcpy(dest, src, width * sizeof(GLushort));
206 /* check for byte swapping */
207 if ((texImage->TexFormat == MESA_FORMAT_YCBCR
208 && type == GL_UNSIGNED_SHORT_8_8_REV_MESA) ||
209 (texImage->TexFormat == MESA_FORMAT_YCBCR_REV
210 && type == GL_UNSIGNED_SHORT_8_8_MESA)) {
211 if (!ctx->Pack.SwapBytes)
212 _mesa_swap2((GLushort *) dest, width);
214 else if (ctx->Pack.SwapBytes) {
215 _mesa_swap2((GLushort *) dest, width);
225 * glGetTexImage for (s)RGBA, Luminance, etc. pixels.
226 * This is the slow way since we use texture sampling.
229 get_tex_rgba(struct gl_context *ctx, GLuint dimensions,
230 GLenum format, GLenum type, GLvoid *pixels,
231 struct gl_texture_image *texImage)
233 const GLint width = texImage->Width;
234 const GLint height = texImage->Height;
235 const GLint depth = texImage->Depth;
236 const GLenum dataType = _mesa_get_format_datatype(texImage->TexFormat);
237 /* Normally, no pixel transfer ops are performed during glGetTexImage.
238 * The only possible exception is component clamping to [0,1].
240 GLbitfield transferOps = 0x0;
242 GLfloat (*rgba)[4] = (GLfloat (*)[4]) malloc(4 * width * sizeof(GLfloat));
243 const GLboolean is_sampler_srgb_decode =
244 _mesa_get_format_color_encoding(texImage->TexFormat) == GL_SRGB &&
245 texImage->TexObject->Sampler.sRGBDecode == GL_DECODE_EXT;
248 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage");
252 /* Clamping does not apply to GetTexImage (final conversion)?
253 * Looks like we need clamp though when going from format
254 * containing negative values to unsigned format.
256 if (format == GL_LUMINANCE || format == GL_LUMINANCE_ALPHA) {
257 transferOps |= IMAGE_CLAMP_BIT;
259 else if (!type_with_negative_values(type) &&
260 (dataType == GL_FLOAT ||
261 dataType == GL_SIGNED_NORMALIZED)) {
262 transferOps |= IMAGE_CLAMP_BIT;
265 /* glGetTexImage always returns sRGB data for sRGB textures. Make sure the
266 * fetch functions return sRGB data without linearizing it.
268 if (is_sampler_srgb_decode) {
269 texImage->TexObject->Sampler.sRGBDecode = GL_SKIP_DECODE_EXT;
270 _mesa_set_fetch_functions(texImage, dimensions);
273 for (img = 0; img < depth; img++) {
274 for (row = 0; row < height; row++) {
275 void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels,
276 width, height, format, type,
280 for (col = 0; col < width; col++) {
281 texImage->FetchTexelf(texImage, col, row, img, rgba[col]);
282 if (texImage->_BaseFormat == GL_ALPHA) {
283 rgba[col][RCOMP] = 0.0F;
284 rgba[col][GCOMP] = 0.0F;
285 rgba[col][BCOMP] = 0.0F;
287 else if (texImage->_BaseFormat == GL_LUMINANCE) {
288 rgba[col][GCOMP] = 0.0F;
289 rgba[col][BCOMP] = 0.0F;
290 rgba[col][ACOMP] = 1.0F;
292 else if (texImage->_BaseFormat == GL_LUMINANCE_ALPHA) {
293 rgba[col][GCOMP] = 0.0F;
294 rgba[col][BCOMP] = 0.0F;
296 else if (texImage->_BaseFormat == GL_INTENSITY) {
297 rgba[col][GCOMP] = 0.0F;
298 rgba[col][BCOMP] = 0.0F;
299 rgba[col][ACOMP] = 1.0F;
302 _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba,
304 &ctx->Pack, transferOps);
308 if (is_sampler_srgb_decode) {
309 texImage->TexObject->Sampler.sRGBDecode = GL_DECODE_EXT;
310 _mesa_set_fetch_functions(texImage, dimensions);
318 * Try to do glGetTexImage() with simple memcpy().
319 * \return GL_TRUE if done, GL_FALSE otherwise
322 get_tex_memcpy(struct gl_context *ctx, GLenum format, GLenum type, GLvoid *pixels,
323 const struct gl_texture_object *texObj,
324 const struct gl_texture_image *texImage)
326 GLboolean memCopy = GL_FALSE;
328 /* Texture image should have been mapped already */
329 assert(texImage->Data);
332 * Check if the src/dst formats are compatible.
333 * Also note that GL's pixel transfer ops don't apply to glGetTexImage()
334 * so we don't have to worry about those.
335 * XXX more format combinations could be supported here.
337 if ((texObj->Target == GL_TEXTURE_1D ||
338 texObj->Target == GL_TEXTURE_2D ||
339 texObj->Target == GL_TEXTURE_RECTANGLE ||
340 (texObj->Target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X &&
341 texObj->Target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z))) {
342 if ((texImage->TexFormat == MESA_FORMAT_ARGB8888 ||
343 texImage->TexFormat == MESA_FORMAT_SARGB8) &&
345 (type == GL_UNSIGNED_BYTE || type == GL_UNSIGNED_INT_8_8_8_8_REV) &&
346 !ctx->Pack.SwapBytes &&
347 _mesa_little_endian()) {
350 else if ((texImage->TexFormat == MESA_FORMAT_AL88 ||
351 texImage->TexFormat == MESA_FORMAT_SLA8) &&
352 format == GL_LUMINANCE_ALPHA &&
353 type == GL_UNSIGNED_BYTE &&
354 !ctx->Pack.SwapBytes &&
355 _mesa_little_endian()) {
358 else if ((texImage->TexFormat == MESA_FORMAT_L8 ||
359 texImage->TexFormat == MESA_FORMAT_SL8) &&
360 format == GL_LUMINANCE &&
361 type == GL_UNSIGNED_BYTE) {
364 else if (texImage->TexFormat == MESA_FORMAT_L16 &&
365 format == GL_LUMINANCE &&
366 type == GL_UNSIGNED_SHORT) {
369 else if (texImage->TexFormat == MESA_FORMAT_A8 &&
370 format == GL_ALPHA &&
371 type == GL_UNSIGNED_BYTE) {
374 else if (texImage->TexFormat == MESA_FORMAT_A16 &&
375 format == GL_ALPHA &&
376 type == GL_UNSIGNED_SHORT) {
382 const GLuint bpp = _mesa_get_format_bytes(texImage->TexFormat);
383 const GLuint bytesPerRow = texImage->Width * bpp;
385 _mesa_image_address2d(&ctx->Pack, pixels, texImage->Width,
386 texImage->Height, format, type, 0, 0);
387 const GLint dstRowStride =
388 _mesa_image_row_stride(&ctx->Pack, texImage->Width, format, type);
389 const GLubyte *src = texImage->Data;
390 const GLint srcRowStride = texImage->RowStride * bpp;
393 if (bytesPerRow == dstRowStride && bytesPerRow == srcRowStride) {
394 memcpy(dst, src, bytesPerRow * texImage->Height);
397 for (row = 0; row < texImage->Height; row++) {
398 memcpy(dst, src, bytesPerRow);
410 * This is the software fallback for Driver.GetTexImage().
411 * All error checking will have been done before this routine is called.
412 * The texture image must be mapped.
415 _mesa_get_teximage(struct gl_context *ctx, GLenum target, GLint level,
416 GLenum format, GLenum type, GLvoid *pixels,
417 struct gl_texture_object *texObj,
418 struct gl_texture_image *texImage)
422 /* If we get here, the texture image should be mapped */
423 assert(texImage->Data);
436 if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
437 /* Packing texture image into a PBO.
438 * Map the (potentially) VRAM-based buffer into our process space so
439 * we can write into it with the code below.
440 * A hardware driver might use a sophisticated blit to move the
441 * texture data to the PBO if the PBO is in VRAM along with the texture.
443 GLubyte *buf = (GLubyte *)
444 ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
445 GL_WRITE_ONLY_ARB, ctx->Pack.BufferObj);
447 /* out of memory or other unexpected error */
448 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage(map PBO failed)");
451 /* <pixels> was an offset into the PBO.
452 * Now make it a real, client-side pointer inside the mapped region.
454 pixels = ADD_POINTERS(buf, pixels);
457 if (get_tex_memcpy(ctx, format, type, pixels, texObj, texImage)) {
460 else if (format == GL_COLOR_INDEX) {
461 get_tex_color_index(ctx, dimensions, format, type, pixels, texImage);
463 else if (format == GL_DEPTH_COMPONENT) {
464 get_tex_depth(ctx, dimensions, format, type, pixels, texImage);
466 else if (format == GL_DEPTH_STENCIL_EXT) {
467 get_tex_depth_stencil(ctx, dimensions, format, type, pixels, texImage);
469 else if (format == GL_YCBCR_MESA) {
470 get_tex_ycbcr(ctx, dimensions, format, type, pixels, texImage);
473 get_tex_rgba(ctx, dimensions, format, type, pixels, texImage);
476 if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
477 ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
478 ctx->Pack.BufferObj);
485 * This is the software fallback for Driver.GetCompressedTexImage().
486 * All error checking will have been done before this routine is called.
489 _mesa_get_compressed_teximage(struct gl_context *ctx, GLenum target, GLint level,
491 struct gl_texture_object *texObj,
492 struct gl_texture_image *texImage)
494 const GLuint row_stride = _mesa_format_row_stride(texImage->TexFormat,
496 const GLuint row_stride_stored = _mesa_format_row_stride(texImage->TexFormat,
497 texImage->RowStride);
500 if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
501 /* pack texture image into a PBO */
502 GLubyte *buf = (GLubyte *)
503 ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
504 GL_WRITE_ONLY_ARB, ctx->Pack.BufferObj);
506 /* out of memory or other unexpected error */
507 _mesa_error(ctx, GL_OUT_OF_MEMORY,
508 "glGetCompresssedTexImage(map PBO failed)");
511 img = ADD_POINTERS(buf, img);
514 /* no pixelstore or pixel transfer, but respect stride */
516 if (row_stride == row_stride_stored) {
517 const GLuint size = _mesa_format_image_size(texImage->TexFormat,
521 memcpy(img, texImage->Data, size);
525 _mesa_get_format_block_size(texImage->TexFormat, &bw, &bh);
526 for (i = 0; i < (texImage->Height + bh - 1) / bh; i++) {
527 memcpy((GLubyte *)img + i * row_stride,
528 (GLubyte *)texImage->Data + i * row_stride_stored,
533 if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
534 ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
535 ctx->Pack.BufferObj);
542 * Do error checking for a glGetTexImage() call.
543 * \return GL_TRUE if any error, GL_FALSE if no errors.
546 getteximage_error_check(struct gl_context *ctx, GLenum target, GLint level,
547 GLenum format, GLenum type, GLsizei clientMemSize,
550 struct gl_texture_object *texObj;
551 struct gl_texture_image *texImage;
552 const GLint maxLevels = _mesa_max_texture_levels(ctx, target);
553 const GLuint dimensions = (target == GL_TEXTURE_3D) ? 3 : 2;
556 if (maxLevels == 0) {
557 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(target=0x%x)", target);
561 if (level < 0 || level >= maxLevels) {
562 _mesa_error( ctx, GL_INVALID_VALUE, "glGetTexImage(level)" );
566 if (_mesa_sizeof_packed_type(type) <= 0) {
567 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexImage(type)" );
571 if (_mesa_components_in_format(format) <= 0 ||
572 format == GL_STENCIL_INDEX) {
573 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexImage(format)" );
577 if (!ctx->Extensions.EXT_paletted_texture && _mesa_is_index_format(format)) {
578 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)");
582 if (!ctx->Extensions.ARB_depth_texture && _mesa_is_depth_format(format)) {
583 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)");
587 if (!ctx->Extensions.MESA_ycbcr_texture && _mesa_is_ycbcr_format(format)) {
588 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)");
592 if (!ctx->Extensions.EXT_packed_depth_stencil
593 && _mesa_is_depthstencil_format(format)) {
594 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)");
598 if (!ctx->Extensions.ATI_envmap_bumpmap
599 && _mesa_is_dudv_format(format)) {
600 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)");
604 texObj = _mesa_get_current_tex_object(ctx, target);
606 if (!texObj || _mesa_is_proxy_texture(target)) {
607 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(target)");
611 texImage = _mesa_select_tex_image(ctx, texObj, target, level);
617 baseFormat = _mesa_get_format_base_format(texImage->TexFormat);
619 /* Make sure the requested image format is compatible with the
620 * texture's format. Note that a color index texture can be converted
621 * to RGBA so that combo is allowed.
623 if (_mesa_is_color_format(format)
624 && !_mesa_is_color_format(baseFormat)
625 && !_mesa_is_index_format(baseFormat)) {
626 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
629 else if (_mesa_is_index_format(format)
630 && !_mesa_is_index_format(baseFormat)) {
631 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
634 else if (_mesa_is_depth_format(format)
635 && !_mesa_is_depth_format(baseFormat)
636 && !_mesa_is_depthstencil_format(baseFormat)) {
637 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
640 else if (_mesa_is_ycbcr_format(format)
641 && !_mesa_is_ycbcr_format(baseFormat)) {
642 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
645 else if (_mesa_is_depthstencil_format(format)
646 && !_mesa_is_depthstencil_format(baseFormat)) {
647 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
650 else if (_mesa_is_dudv_format(format)
651 && !_mesa_is_dudv_format(baseFormat)) {
652 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
656 if (!_mesa_validate_pbo_access(dimensions, &ctx->Pack, texImage->Width,
657 texImage->Height, texImage->Depth,
658 format, type, clientMemSize, pixels)) {
659 if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
660 _mesa_error(ctx, GL_INVALID_OPERATION,
661 "glGetTexImage(out of bounds PBO access)");
663 _mesa_error(ctx, GL_INVALID_OPERATION,
664 "glGetnTexImageARB(out of bounds access:"
665 " bufSize (%d) is too small)", clientMemSize);
670 if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
671 /* PBO should not be mapped */
672 if (_mesa_bufferobj_mapped(ctx->Pack.BufferObj)) {
673 _mesa_error(ctx, GL_INVALID_OPERATION,
674 "glGetTexImage(PBO is mapped)");
685 * Get texture image. Called by glGetTexImage.
687 * \param target texture target.
688 * \param level image level.
689 * \param format pixel data format for returned image.
690 * \param type pixel data type for returned image.
691 * \param bufSize size of the pixels data buffer.
692 * \param pixels returned pixel data.
695 _mesa_GetnTexImageARB( GLenum target, GLint level, GLenum format,
696 GLenum type, GLsizei bufSize, GLvoid *pixels )
698 struct gl_texture_object *texObj;
699 struct gl_texture_image *texImage;
700 GET_CURRENT_CONTEXT(ctx);
701 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
703 if (getteximage_error_check(ctx, target, level, format, type,
708 if (!_mesa_is_bufferobj(ctx->Pack.BufferObj) && !pixels) {
709 /* not an error, do nothing */
713 texObj = _mesa_get_current_tex_object(ctx, target);
714 texImage = _mesa_select_tex_image(ctx, texObj, target, level);
716 if (MESA_VERBOSE & (VERBOSE_API | VERBOSE_TEXTURE)) {
717 _mesa_debug(ctx, "glGetTexImage(tex %u) format = %s, w=%d, h=%d,"
718 " dstFmt=0x%x, dstType=0x%x\n",
720 _mesa_get_format_name(texImage->TexFormat),
721 texImage->Width, texImage->Height,
725 _mesa_lock_texture(ctx, texObj);
727 ctx->Driver.GetTexImage(ctx, target, level, format, type, pixels,
730 _mesa_unlock_texture(ctx, texObj);
735 _mesa_GetTexImage( GLenum target, GLint level, GLenum format,
736 GLenum type, GLvoid *pixels )
738 _mesa_GetnTexImageARB(target, level, format, type, INT_MAX, pixels);
743 * Do error checking for a glGetCompressedTexImage() call.
744 * \return GL_TRUE if any error, GL_FALSE if no errors.
747 getcompressedteximage_error_check(struct gl_context *ctx, GLenum target,
748 GLint level, GLsizei clientMemSize, GLvoid *img)
750 struct gl_texture_object *texObj;
751 struct gl_texture_image *texImage;
752 const GLint maxLevels = _mesa_max_texture_levels(ctx, target);
753 GLuint compressedSize;
755 if (maxLevels == 0) {
756 _mesa_error(ctx, GL_INVALID_ENUM, "glGetCompressedTexImage(target=0x%x)",
761 if (level < 0 || level >= maxLevels) {
762 _mesa_error(ctx, GL_INVALID_VALUE,
763 "glGetCompressedTexImageARB(bad level = %d)", level);
767 if (_mesa_is_proxy_texture(target)) {
768 _mesa_error(ctx, GL_INVALID_ENUM,
769 "glGetCompressedTexImageARB(bad target = %s)",
770 _mesa_lookup_enum_by_nr(target));
774 texObj = _mesa_get_current_tex_object(ctx, target);
776 _mesa_error(ctx, GL_INVALID_ENUM, "glGetCompressedTexImageARB(target)");
780 texImage = _mesa_select_tex_image(ctx, texObj, target, level);
783 /* probably invalid mipmap level */
784 _mesa_error(ctx, GL_INVALID_VALUE,
785 "glGetCompressedTexImageARB(level)");
789 if (!_mesa_is_format_compressed(texImage->TexFormat)) {
790 _mesa_error(ctx, GL_INVALID_OPERATION,
791 "glGetCompressedTexImageARB(texture is not compressed)");
795 compressedSize = _mesa_format_image_size(texImage->TexFormat,
800 if (!_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
801 /* do bounds checking on writing to client memory */
802 if (clientMemSize < compressedSize) {
803 _mesa_error(ctx, GL_INVALID_OPERATION,
804 "glGetnCompressedTexImageARB(out of bounds access:"
805 " bufSize (%d) is too small)", clientMemSize);
808 /* do bounds checking on PBO write */
809 if ((const GLubyte *) img + compressedSize >
810 (const GLubyte *) ctx->Pack.BufferObj->Size) {
811 _mesa_error(ctx, GL_INVALID_OPERATION,
812 "glGetCompressedTexImage(out of bounds PBO access)");
816 /* make sure PBO is not mapped */
817 if (_mesa_bufferobj_mapped(ctx->Pack.BufferObj)) {
818 _mesa_error(ctx, GL_INVALID_OPERATION,
819 "glGetCompressedTexImage(PBO is mapped)");
829 _mesa_GetnCompressedTexImageARB(GLenum target, GLint level, GLsizei bufSize,
832 struct gl_texture_object *texObj;
833 struct gl_texture_image *texImage;
834 GET_CURRENT_CONTEXT(ctx);
835 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
837 if (getcompressedteximage_error_check(ctx, target, level, bufSize, img)) {
841 if (!_mesa_is_bufferobj(ctx->Pack.BufferObj) && !img) {
842 /* not an error, do nothing */
846 texObj = _mesa_get_current_tex_object(ctx, target);
847 texImage = _mesa_select_tex_image(ctx, texObj, target, level);
849 if (MESA_VERBOSE & (VERBOSE_API | VERBOSE_TEXTURE)) {
851 "glGetCompressedTexImage(tex %u) format = %s, w=%d, h=%d\n",
853 _mesa_get_format_name(texImage->TexFormat),
854 texImage->Width, texImage->Height);
857 _mesa_lock_texture(ctx, texObj);
859 ctx->Driver.GetCompressedTexImage(ctx, target, level, img,
862 _mesa_unlock_texture(ctx, texObj);
866 _mesa_GetCompressedTexImageARB(GLenum target, GLint level, GLvoid *img)
868 _mesa_GetnCompressedTexImageARB(target, level, INT_MAX, img);