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 depth/Z pixels.
71 get_tex_depth(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
;
79 GLfloat
*depthRow
= (GLfloat
*) malloc(width
* sizeof(GLfloat
));
82 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glGetTexImage");
86 for (img
= 0; img
< depth
; img
++) {
87 for (row
= 0; row
< height
; row
++) {
88 void *dest
= _mesa_image_address(dimensions
, &ctx
->Pack
, pixels
,
89 width
, height
, format
, type
,
93 for (col
= 0; col
< width
; col
++) {
94 texImage
->FetchTexelf(texImage
, col
, row
, img
, depthRow
+ col
);
96 _mesa_pack_depth_span(ctx
, width
, dest
, type
, depthRow
, &ctx
->Pack
);
105 * glGetTexImage for depth/stencil pixels.
108 get_tex_depth_stencil(struct gl_context
*ctx
, GLuint dimensions
,
109 GLenum format
, GLenum type
, GLvoid
*pixels
,
110 const struct gl_texture_image
*texImage
)
112 const GLint width
= texImage
->Width
;
113 const GLint height
= texImage
->Height
;
114 const GLint depth
= texImage
->Depth
;
115 const GLint rowstride
= texImage
->RowStride
;
116 const GLuint
*src
= (const GLuint
*) texImage
->Data
;
119 for (img
= 0; img
< depth
; img
++) {
120 for (row
= 0; row
< height
; row
++) {
121 void *dest
= _mesa_image_address(dimensions
, &ctx
->Pack
, pixels
,
122 width
, height
, format
, type
,
124 memcpy(dest
, src
, width
* sizeof(GLuint
));
125 if (ctx
->Pack
.SwapBytes
) {
126 _mesa_swap4((GLuint
*) dest
, width
);
136 * glGetTexImage for YCbCr pixels.
139 get_tex_ycbcr(struct gl_context
*ctx
, GLuint dimensions
,
140 GLenum format
, GLenum type
, GLvoid
*pixels
,
141 const struct gl_texture_image
*texImage
)
143 const GLint width
= texImage
->Width
;
144 const GLint height
= texImage
->Height
;
145 const GLint depth
= texImage
->Depth
;
146 const GLint rowstride
= texImage
->RowStride
;
147 const GLushort
*src
= (const GLushort
*) texImage
->Data
;
150 for (img
= 0; img
< depth
; img
++) {
151 for (row
= 0; row
< height
; row
++) {
152 void *dest
= _mesa_image_address(dimensions
, &ctx
->Pack
, pixels
,
153 width
, height
, format
, type
,
155 memcpy(dest
, src
, width
* sizeof(GLushort
));
157 /* check for byte swapping */
158 if ((texImage
->TexFormat
== MESA_FORMAT_YCBCR
159 && type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
) ||
160 (texImage
->TexFormat
== MESA_FORMAT_YCBCR_REV
161 && type
== GL_UNSIGNED_SHORT_8_8_MESA
)) {
162 if (!ctx
->Pack
.SwapBytes
)
163 _mesa_swap2((GLushort
*) dest
, width
);
165 else if (ctx
->Pack
.SwapBytes
) {
166 _mesa_swap2((GLushort
*) dest
, width
);
176 * glGetTexImage for (s)RGBA, Luminance, etc. pixels.
177 * This is the slow way since we use texture sampling.
180 get_tex_rgba(struct gl_context
*ctx
, GLuint dimensions
,
181 GLenum format
, GLenum type
, GLvoid
*pixels
,
182 struct gl_texture_image
*texImage
)
184 const GLint width
= texImage
->Width
;
185 const GLint height
= texImage
->Height
;
186 const GLint depth
= texImage
->Depth
;
187 const GLenum dataType
= _mesa_get_format_datatype(texImage
->TexFormat
);
188 /* Normally, no pixel transfer ops are performed during glGetTexImage.
189 * The only possible exception is component clamping to [0,1].
191 GLbitfield transferOps
= 0x0;
193 GLfloat (*rgba
)[4] = (GLfloat (*)[4]) malloc(4 * width
* sizeof(GLfloat
));
194 const GLboolean is_sampler_srgb_decode
=
195 _mesa_get_format_color_encoding(texImage
->TexFormat
) == GL_SRGB
&&
196 texImage
->TexObject
->Sampler
.sRGBDecode
== GL_DECODE_EXT
;
199 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glGetTexImage");
203 /* Clamping does not apply to GetTexImage (final conversion)?
204 * Looks like we need clamp though when going from format
205 * containing negative values to unsigned format.
207 if (format
== GL_LUMINANCE
|| format
== GL_LUMINANCE_ALPHA
) {
208 transferOps
|= IMAGE_CLAMP_BIT
;
210 else if (!type_with_negative_values(type
) &&
211 (dataType
== GL_FLOAT
||
212 dataType
== GL_SIGNED_NORMALIZED
)) {
213 transferOps
|= IMAGE_CLAMP_BIT
;
216 /* glGetTexImage always returns sRGB data for sRGB textures. Make sure the
217 * fetch functions return sRGB data without linearizing it.
219 if (is_sampler_srgb_decode
) {
220 texImage
->TexObject
->Sampler
.sRGBDecode
= GL_SKIP_DECODE_EXT
;
221 _mesa_set_fetch_functions(texImage
, dimensions
);
224 for (img
= 0; img
< depth
; img
++) {
225 for (row
= 0; row
< height
; row
++) {
226 void *dest
= _mesa_image_address(dimensions
, &ctx
->Pack
, pixels
,
227 width
, height
, format
, type
,
231 for (col
= 0; col
< width
; col
++) {
232 texImage
->FetchTexelf(texImage
, col
, row
, img
, rgba
[col
]);
233 if (texImage
->_BaseFormat
== GL_ALPHA
) {
234 rgba
[col
][RCOMP
] = 0.0F
;
235 rgba
[col
][GCOMP
] = 0.0F
;
236 rgba
[col
][BCOMP
] = 0.0F
;
238 else if (texImage
->_BaseFormat
== GL_LUMINANCE
) {
239 rgba
[col
][GCOMP
] = 0.0F
;
240 rgba
[col
][BCOMP
] = 0.0F
;
241 rgba
[col
][ACOMP
] = 1.0F
;
243 else if (texImage
->_BaseFormat
== GL_LUMINANCE_ALPHA
) {
244 rgba
[col
][GCOMP
] = 0.0F
;
245 rgba
[col
][BCOMP
] = 0.0F
;
247 else if (texImage
->_BaseFormat
== GL_INTENSITY
) {
248 rgba
[col
][GCOMP
] = 0.0F
;
249 rgba
[col
][BCOMP
] = 0.0F
;
250 rgba
[col
][ACOMP
] = 1.0F
;
253 _mesa_pack_rgba_span_float(ctx
, width
, (GLfloat (*)[4]) rgba
,
255 &ctx
->Pack
, transferOps
);
259 if (is_sampler_srgb_decode
) {
260 texImage
->TexObject
->Sampler
.sRGBDecode
= GL_DECODE_EXT
;
261 _mesa_set_fetch_functions(texImage
, dimensions
);
269 * Try to do glGetTexImage() with simple memcpy().
270 * \return GL_TRUE if done, GL_FALSE otherwise
273 get_tex_memcpy(struct gl_context
*ctx
, GLenum format
, GLenum type
, GLvoid
*pixels
,
274 const struct gl_texture_object
*texObj
,
275 const struct gl_texture_image
*texImage
)
277 GLboolean memCopy
= GL_FALSE
;
279 /* Texture image should have been mapped already */
280 assert(texImage
->Data
);
283 * Check if the src/dst formats are compatible.
284 * Also note that GL's pixel transfer ops don't apply to glGetTexImage()
285 * so we don't have to worry about those.
286 * XXX more format combinations could be supported here.
288 if ((texObj
->Target
== GL_TEXTURE_1D
||
289 texObj
->Target
== GL_TEXTURE_2D
||
290 texObj
->Target
== GL_TEXTURE_RECTANGLE
||
291 (texObj
->Target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
292 texObj
->Target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
))) {
293 if ((texImage
->TexFormat
== MESA_FORMAT_ARGB8888
||
294 texImage
->TexFormat
== MESA_FORMAT_SARGB8
) &&
296 (type
== GL_UNSIGNED_BYTE
|| type
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
297 !ctx
->Pack
.SwapBytes
&&
298 _mesa_little_endian()) {
301 else if ((texImage
->TexFormat
== MESA_FORMAT_AL88
||
302 texImage
->TexFormat
== MESA_FORMAT_SLA8
) &&
303 format
== GL_LUMINANCE_ALPHA
&&
304 type
== GL_UNSIGNED_BYTE
&&
305 !ctx
->Pack
.SwapBytes
&&
306 _mesa_little_endian()) {
309 else if ((texImage
->TexFormat
== MESA_FORMAT_L8
||
310 texImage
->TexFormat
== MESA_FORMAT_SL8
) &&
311 format
== GL_LUMINANCE
&&
312 type
== GL_UNSIGNED_BYTE
) {
315 else if (texImage
->TexFormat
== MESA_FORMAT_L16
&&
316 format
== GL_LUMINANCE
&&
317 type
== GL_UNSIGNED_SHORT
) {
320 else if (texImage
->TexFormat
== MESA_FORMAT_A8
&&
321 format
== GL_ALPHA
&&
322 type
== GL_UNSIGNED_BYTE
) {
325 else if (texImage
->TexFormat
== MESA_FORMAT_A16
&&
326 format
== GL_ALPHA
&&
327 type
== GL_UNSIGNED_SHORT
) {
333 const GLuint bpp
= _mesa_get_format_bytes(texImage
->TexFormat
);
334 const GLuint bytesPerRow
= texImage
->Width
* bpp
;
336 _mesa_image_address2d(&ctx
->Pack
, pixels
, texImage
->Width
,
337 texImage
->Height
, format
, type
, 0, 0);
338 const GLint dstRowStride
=
339 _mesa_image_row_stride(&ctx
->Pack
, texImage
->Width
, format
, type
);
340 const GLubyte
*src
= texImage
->Data
;
341 const GLint srcRowStride
= texImage
->RowStride
* bpp
;
344 if (bytesPerRow
== dstRowStride
&& bytesPerRow
== srcRowStride
) {
345 memcpy(dst
, src
, bytesPerRow
* texImage
->Height
);
348 for (row
= 0; row
< texImage
->Height
; row
++) {
349 memcpy(dst
, src
, bytesPerRow
);
361 * This is the software fallback for Driver.GetTexImage().
362 * All error checking will have been done before this routine is called.
363 * The texture image must be mapped.
366 _mesa_get_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
367 GLenum format
, GLenum type
, GLvoid
*pixels
,
368 struct gl_texture_object
*texObj
,
369 struct gl_texture_image
*texImage
)
373 /* If we get here, the texture image should be mapped */
374 assert(texImage
->Data
);
387 if (_mesa_is_bufferobj(ctx
->Pack
.BufferObj
)) {
388 /* Packing texture image into a PBO.
389 * Map the (potentially) VRAM-based buffer into our process space so
390 * we can write into it with the code below.
391 * A hardware driver might use a sophisticated blit to move the
392 * texture data to the PBO if the PBO is in VRAM along with the texture.
394 GLubyte
*buf
= (GLubyte
*)
395 ctx
->Driver
.MapBufferRange(ctx
, 0, ctx
->Pack
.BufferObj
->Size
,
396 GL_MAP_WRITE_BIT
, ctx
->Pack
.BufferObj
);
398 /* out of memory or other unexpected error */
399 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glGetTexImage(map PBO failed)");
402 /* <pixels> was an offset into the PBO.
403 * Now make it a real, client-side pointer inside the mapped region.
405 pixels
= ADD_POINTERS(buf
, pixels
);
408 if (get_tex_memcpy(ctx
, format
, type
, pixels
, texObj
, texImage
)) {
411 else if (format
== GL_DEPTH_COMPONENT
) {
412 get_tex_depth(ctx
, dimensions
, format
, type
, pixels
, texImage
);
414 else if (format
== GL_DEPTH_STENCIL_EXT
) {
415 get_tex_depth_stencil(ctx
, dimensions
, format
, type
, pixels
, texImage
);
417 else if (format
== GL_YCBCR_MESA
) {
418 get_tex_ycbcr(ctx
, dimensions
, format
, type
, pixels
, texImage
);
421 get_tex_rgba(ctx
, dimensions
, format
, type
, pixels
, texImage
);
424 if (_mesa_is_bufferobj(ctx
->Pack
.BufferObj
)) {
425 ctx
->Driver
.UnmapBuffer(ctx
, ctx
->Pack
.BufferObj
);
432 * This is the software fallback for Driver.GetCompressedTexImage().
433 * All error checking will have been done before this routine is called.
436 _mesa_get_compressed_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
438 struct gl_texture_object
*texObj
,
439 struct gl_texture_image
*texImage
)
441 const GLuint row_stride
= _mesa_format_row_stride(texImage
->TexFormat
,
443 const GLuint row_stride_stored
= _mesa_format_row_stride(texImage
->TexFormat
,
444 texImage
->RowStride
);
447 if (_mesa_is_bufferobj(ctx
->Pack
.BufferObj
)) {
448 /* pack texture image into a PBO */
449 GLubyte
*buf
= (GLubyte
*)
450 ctx
->Driver
.MapBufferRange(ctx
, 0, ctx
->Pack
.BufferObj
->Size
,
451 GL_MAP_WRITE_BIT
, ctx
->Pack
.BufferObj
);
453 /* out of memory or other unexpected error */
454 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
455 "glGetCompresssedTexImage(map PBO failed)");
458 img
= ADD_POINTERS(buf
, img
);
461 /* no pixelstore or pixel transfer, but respect stride */
463 if (row_stride
== row_stride_stored
) {
464 const GLuint size
= _mesa_format_image_size(texImage
->TexFormat
,
468 memcpy(img
, texImage
->Data
, size
);
472 _mesa_get_format_block_size(texImage
->TexFormat
, &bw
, &bh
);
473 for (i
= 0; i
< (texImage
->Height
+ bh
- 1) / bh
; i
++) {
474 memcpy((GLubyte
*)img
+ i
* row_stride
,
475 (GLubyte
*)texImage
->Data
+ i
* row_stride_stored
,
480 if (_mesa_is_bufferobj(ctx
->Pack
.BufferObj
)) {
481 ctx
->Driver
.UnmapBuffer(ctx
, ctx
->Pack
.BufferObj
);
488 * Do error checking for a glGetTexImage() call.
489 * \return GL_TRUE if any error, GL_FALSE if no errors.
492 getteximage_error_check(struct gl_context
*ctx
, GLenum target
, GLint level
,
493 GLenum format
, GLenum type
, GLsizei clientMemSize
,
496 struct gl_texture_object
*texObj
;
497 struct gl_texture_image
*texImage
;
498 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
499 const GLuint dimensions
= (target
== GL_TEXTURE_3D
) ? 3 : 2;
502 if (maxLevels
== 0) {
503 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(target=0x%x)", target
);
507 if (level
< 0 || level
>= maxLevels
) {
508 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexImage(level)" );
512 if (_mesa_sizeof_packed_type(type
) <= 0) {
513 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(type)" );
517 if (_mesa_components_in_format(format
) <= 0 ||
518 format
== GL_STENCIL_INDEX
) {
519 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)" );
523 if (_mesa_is_index_format(format
)) {
524 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
528 if (!ctx
->Extensions
.ARB_depth_texture
&& _mesa_is_depth_format(format
)) {
529 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
533 if (!ctx
->Extensions
.MESA_ycbcr_texture
&& _mesa_is_ycbcr_format(format
)) {
534 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
538 if (!ctx
->Extensions
.EXT_packed_depth_stencil
539 && _mesa_is_depthstencil_format(format
)) {
540 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
544 if (!ctx
->Extensions
.ATI_envmap_bumpmap
545 && _mesa_is_dudv_format(format
)) {
546 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
550 texObj
= _mesa_get_current_tex_object(ctx
, target
);
552 if (!texObj
|| _mesa_is_proxy_texture(target
)) {
553 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(target)");
557 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
563 baseFormat
= _mesa_get_format_base_format(texImage
->TexFormat
);
565 /* Make sure the requested image format is compatible with the
568 if (_mesa_is_color_format(format
)
569 && !_mesa_is_color_format(baseFormat
)) {
570 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
573 else if (_mesa_is_depth_format(format
)
574 && !_mesa_is_depth_format(baseFormat
)
575 && !_mesa_is_depthstencil_format(baseFormat
)) {
576 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
579 else if (_mesa_is_ycbcr_format(format
)
580 && !_mesa_is_ycbcr_format(baseFormat
)) {
581 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
584 else if (_mesa_is_depthstencil_format(format
)
585 && !_mesa_is_depthstencil_format(baseFormat
)) {
586 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
589 else if (_mesa_is_dudv_format(format
)
590 && !_mesa_is_dudv_format(baseFormat
)) {
591 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
595 if (!_mesa_validate_pbo_access(dimensions
, &ctx
->Pack
, texImage
->Width
,
596 texImage
->Height
, texImage
->Depth
,
597 format
, type
, clientMemSize
, pixels
)) {
598 if (_mesa_is_bufferobj(ctx
->Pack
.BufferObj
)) {
599 _mesa_error(ctx
, GL_INVALID_OPERATION
,
600 "glGetTexImage(out of bounds PBO access)");
602 _mesa_error(ctx
, GL_INVALID_OPERATION
,
603 "glGetnTexImageARB(out of bounds access:"
604 " bufSize (%d) is too small)", clientMemSize
);
609 if (_mesa_is_bufferobj(ctx
->Pack
.BufferObj
)) {
610 /* PBO should not be mapped */
611 if (_mesa_bufferobj_mapped(ctx
->Pack
.BufferObj
)) {
612 _mesa_error(ctx
, GL_INVALID_OPERATION
,
613 "glGetTexImage(PBO is mapped)");
624 * Get texture image. Called by glGetTexImage.
626 * \param target texture target.
627 * \param level image level.
628 * \param format pixel data format for returned image.
629 * \param type pixel data type for returned image.
630 * \param bufSize size of the pixels data buffer.
631 * \param pixels returned pixel data.
634 _mesa_GetnTexImageARB( GLenum target
, GLint level
, GLenum format
,
635 GLenum type
, GLsizei bufSize
, GLvoid
*pixels
)
637 struct gl_texture_object
*texObj
;
638 struct gl_texture_image
*texImage
;
639 GET_CURRENT_CONTEXT(ctx
);
640 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
642 if (getteximage_error_check(ctx
, target
, level
, format
, type
,
647 if (!_mesa_is_bufferobj(ctx
->Pack
.BufferObj
) && !pixels
) {
648 /* not an error, do nothing */
652 texObj
= _mesa_get_current_tex_object(ctx
, target
);
653 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
655 if (MESA_VERBOSE
& (VERBOSE_API
| VERBOSE_TEXTURE
)) {
656 _mesa_debug(ctx
, "glGetTexImage(tex %u) format = %s, w=%d, h=%d,"
657 " dstFmt=0x%x, dstType=0x%x\n",
659 _mesa_get_format_name(texImage
->TexFormat
),
660 texImage
->Width
, texImage
->Height
,
664 _mesa_lock_texture(ctx
, texObj
);
666 ctx
->Driver
.GetTexImage(ctx
, target
, level
, format
, type
, pixels
,
669 _mesa_unlock_texture(ctx
, texObj
);
674 _mesa_GetTexImage( GLenum target
, GLint level
, GLenum format
,
675 GLenum type
, GLvoid
*pixels
)
677 _mesa_GetnTexImageARB(target
, level
, format
, type
, INT_MAX
, pixels
);
682 * Do error checking for a glGetCompressedTexImage() call.
683 * \return GL_TRUE if any error, GL_FALSE if no errors.
686 getcompressedteximage_error_check(struct gl_context
*ctx
, GLenum target
,
687 GLint level
, GLsizei clientMemSize
, GLvoid
*img
)
689 struct gl_texture_object
*texObj
;
690 struct gl_texture_image
*texImage
;
691 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
692 GLuint compressedSize
;
694 if (maxLevels
== 0) {
695 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImage(target=0x%x)",
700 if (level
< 0 || level
>= maxLevels
) {
701 _mesa_error(ctx
, GL_INVALID_VALUE
,
702 "glGetCompressedTexImageARB(bad level = %d)", level
);
706 if (_mesa_is_proxy_texture(target
)) {
707 _mesa_error(ctx
, GL_INVALID_ENUM
,
708 "glGetCompressedTexImageARB(bad target = %s)",
709 _mesa_lookup_enum_by_nr(target
));
713 texObj
= _mesa_get_current_tex_object(ctx
, target
);
715 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB(target)");
719 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
722 /* probably invalid mipmap level */
723 _mesa_error(ctx
, GL_INVALID_VALUE
,
724 "glGetCompressedTexImageARB(level)");
728 if (!_mesa_is_format_compressed(texImage
->TexFormat
)) {
729 _mesa_error(ctx
, GL_INVALID_OPERATION
,
730 "glGetCompressedTexImageARB(texture is not compressed)");
734 compressedSize
= _mesa_format_image_size(texImage
->TexFormat
,
739 if (!_mesa_is_bufferobj(ctx
->Pack
.BufferObj
)) {
740 /* do bounds checking on writing to client memory */
741 if (clientMemSize
< compressedSize
) {
742 _mesa_error(ctx
, GL_INVALID_OPERATION
,
743 "glGetnCompressedTexImageARB(out of bounds access:"
744 " bufSize (%d) is too small)", clientMemSize
);
747 /* do bounds checking on PBO write */
748 if ((const GLubyte
*) img
+ compressedSize
>
749 (const GLubyte
*) ctx
->Pack
.BufferObj
->Size
) {
750 _mesa_error(ctx
, GL_INVALID_OPERATION
,
751 "glGetCompressedTexImage(out of bounds PBO access)");
755 /* make sure PBO is not mapped */
756 if (_mesa_bufferobj_mapped(ctx
->Pack
.BufferObj
)) {
757 _mesa_error(ctx
, GL_INVALID_OPERATION
,
758 "glGetCompressedTexImage(PBO is mapped)");
768 _mesa_GetnCompressedTexImageARB(GLenum target
, GLint level
, GLsizei bufSize
,
771 struct gl_texture_object
*texObj
;
772 struct gl_texture_image
*texImage
;
773 GET_CURRENT_CONTEXT(ctx
);
774 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
776 if (getcompressedteximage_error_check(ctx
, target
, level
, bufSize
, img
)) {
780 if (_mesa_is_bufferobj(ctx
->Pack
.BufferObj
) && !img
) {
781 /* not an error, do nothing */
785 texObj
= _mesa_get_current_tex_object(ctx
, target
);
786 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
788 if (MESA_VERBOSE
& (VERBOSE_API
| VERBOSE_TEXTURE
)) {
790 "glGetCompressedTexImage(tex %u) format = %s, w=%d, h=%d\n",
792 _mesa_get_format_name(texImage
->TexFormat
),
793 texImage
->Width
, texImage
->Height
);
796 _mesa_lock_texture(ctx
, texObj
);
798 ctx
->Driver
.GetCompressedTexImage(ctx
, target
, level
, img
,
801 _mesa_unlock_texture(ctx
, texObj
);
805 _mesa_GetCompressedTexImageARB(GLenum target
, GLint level
, GLvoid
*img
)
807 _mesa_GetnCompressedTexImageARB(target
, level
, INT_MAX
, img
);