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"
37 #include "format_unpack.h"
39 #include "mfeatures.h"
43 #include "texcompress.h"
44 #include "texgetimage.h"
51 * Can the given type represent negative values?
53 static INLINE GLboolean
54 type_with_negative_values(GLenum type
)
61 case GL_HALF_FLOAT_ARB
:
70 * glGetTexImage for depth/Z pixels.
73 get_tex_depth(struct gl_context
*ctx
, GLuint dimensions
,
74 GLenum format
, GLenum type
, GLvoid
*pixels
,
75 const struct gl_texture_image
*texImage
)
77 const GLint width
= texImage
->Width
;
78 const GLint height
= texImage
->Height
;
79 const GLint depth
= texImage
->Depth
;
81 GLfloat
*depthRow
= (GLfloat
*) malloc(width
* sizeof(GLfloat
));
82 const GLint texelSize
= _mesa_get_format_bytes(texImage
->TexFormat
);
85 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glGetTexImage");
89 for (img
= 0; img
< depth
; img
++) {
90 for (row
= 0; row
< height
; row
++) {
91 void *dest
= _mesa_image_address(dimensions
, &ctx
->Pack
, pixels
,
92 width
, height
, format
, type
,
94 const GLubyte
*src
= (GLubyte
*) texImage
->Data
+
95 (texImage
->ImageOffsets
[img
] +
96 texImage
->RowStride
* row
) * texelSize
;
98 _mesa_unpack_float_z_row(texImage
->TexFormat
, width
, src
, depthRow
);
100 _mesa_pack_depth_span(ctx
, width
, dest
, type
, depthRow
, &ctx
->Pack
);
109 * glGetTexImage for depth/stencil pixels.
112 get_tex_depth_stencil(struct gl_context
*ctx
, GLuint dimensions
,
113 GLenum format
, GLenum type
, GLvoid
*pixels
,
114 const struct gl_texture_image
*texImage
)
116 const GLint width
= texImage
->Width
;
117 const GLint height
= texImage
->Height
;
118 const GLint depth
= texImage
->Depth
;
119 const GLint rowstride
= texImage
->RowStride
;
120 const GLuint
*src
= (const GLuint
*) texImage
->Data
;
123 for (img
= 0; img
< depth
; img
++) {
124 for (row
= 0; row
< height
; row
++) {
125 void *dest
= _mesa_image_address(dimensions
, &ctx
->Pack
, pixels
,
126 width
, height
, format
, type
,
128 memcpy(dest
, src
, width
* sizeof(GLuint
));
129 if (ctx
->Pack
.SwapBytes
) {
130 _mesa_swap4((GLuint
*) dest
, width
);
140 * glGetTexImage for YCbCr pixels.
143 get_tex_ycbcr(struct gl_context
*ctx
, GLuint dimensions
,
144 GLenum format
, GLenum type
, GLvoid
*pixels
,
145 const struct gl_texture_image
*texImage
)
147 const GLint width
= texImage
->Width
;
148 const GLint height
= texImage
->Height
;
149 const GLint depth
= texImage
->Depth
;
150 const GLint rowstride
= texImage
->RowStride
;
151 const GLushort
*src
= (const GLushort
*) texImage
->Data
;
154 for (img
= 0; img
< depth
; img
++) {
155 for (row
= 0; row
< height
; row
++) {
156 void *dest
= _mesa_image_address(dimensions
, &ctx
->Pack
, pixels
,
157 width
, height
, format
, type
,
159 memcpy(dest
, src
, width
* sizeof(GLushort
));
161 /* check for byte swapping */
162 if ((texImage
->TexFormat
== MESA_FORMAT_YCBCR
163 && type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
) ||
164 (texImage
->TexFormat
== MESA_FORMAT_YCBCR_REV
165 && type
== GL_UNSIGNED_SHORT_8_8_MESA
)) {
166 if (!ctx
->Pack
.SwapBytes
)
167 _mesa_swap2((GLushort
*) dest
, width
);
169 else if (ctx
->Pack
.SwapBytes
) {
170 _mesa_swap2((GLushort
*) dest
, width
);
180 * glGetTexImage for color formats (RGBA, RGB, alpha, LA, etc).
181 * Compressed textures are handled here as well.
184 get_tex_rgba(struct gl_context
*ctx
, GLuint dimensions
,
185 GLenum format
, GLenum type
, GLvoid
*pixels
,
186 struct gl_texture_image
*texImage
)
188 /* don't want to apply sRGB -> RGB conversion here so override the format */
189 const gl_format texFormat
= _mesa_get_srgb_format_linear(texImage
->TexFormat
);
190 const GLuint width
= texImage
->Width
;
191 const GLuint height
= texImage
->Height
;
192 const GLuint depth
= texImage
->Depth
;
193 const GLenum dataType
= _mesa_get_format_datatype(texFormat
);
194 const GLenum baseFormat
= _mesa_get_format_base_format(texFormat
);
195 /* Normally, no pixel transfer ops are performed during glGetTexImage.
196 * The only possible exception is component clamping to [0,1].
198 GLbitfield transferOps
= 0x0;
200 /* In general, clamping does not apply to glGetTexImage, except when
201 * the returned type of the image can't hold negative values.
203 if (!type_with_negative_values(type
)) {
204 /* the returned image type can't have negative values */
205 if (dataType
== GL_FLOAT
||
206 dataType
== GL_SIGNED_NORMALIZED
||
207 format
== GL_LUMINANCE
||
208 format
== GL_LUMINANCE_ALPHA
) {
209 transferOps
|= IMAGE_CLAMP_BIT
;
213 if (_mesa_is_format_compressed(texFormat
)) {
214 /* Decompress into temp buffer, then pack into user buffer */
215 GLfloat
*tempImage
, *srcRow
;
218 tempImage
= (GLfloat
*) malloc(texImage
->Width
* texImage
->Height
*
219 texImage
->Depth
* 4 * sizeof(GLfloat
));
221 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glGetTexImage()");
225 _mesa_decompress_image(texFormat
, texImage
->Width
, texImage
->Height
,
226 texImage
->Data
, texImage
->RowStride
, tempImage
);
228 if (baseFormat
== GL_LUMINANCE
||
229 baseFormat
== GL_LUMINANCE_ALPHA
) {
230 /* Set green and blue to zero since the pack function here will
234 for (i
= 0; i
< width
* height
; i
++) {
235 tempImage
[i
* 4 + GCOMP
] = tempImage
[i
* 4 + BCOMP
] = 0.0f
;
240 for (row
= 0; row
< height
; row
++) {
241 void *dest
= _mesa_image_address(dimensions
, &ctx
->Pack
, pixels
,
242 width
, height
, format
, type
,
245 _mesa_pack_rgba_span_float(ctx
, width
, (GLfloat (*)[4]) srcRow
,
246 format
, type
, dest
, &ctx
->Pack
, transferOps
);
253 /* No decompression needed */
254 const GLint texelSize
= _mesa_get_format_bytes(texFormat
);
258 rgba
= (GLfloat (*)[4]) malloc(4 * width
* sizeof(GLfloat
));
260 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glGetTexImage()");
264 for (img
= 0; img
< depth
; img
++) {
265 for (row
= 0; row
< height
; row
++) {
266 void *dest
= _mesa_image_address(dimensions
, &ctx
->Pack
, pixels
,
267 width
, height
, format
, type
,
269 const GLubyte
*src
= (const GLubyte
*) texImage
->Data
+
270 (texImage
->ImageOffsets
[img
] +
271 texImage
->RowStride
* row
) * texelSize
;
273 _mesa_unpack_rgba_row(texFormat
, width
, src
, rgba
);
275 if (texImage
->_BaseFormat
== GL_ALPHA
) {
277 for (col
= 0; col
< width
; col
++) {
278 rgba
[col
][RCOMP
] = 0.0F
;
279 rgba
[col
][GCOMP
] = 0.0F
;
280 rgba
[col
][BCOMP
] = 0.0F
;
283 else if (texImage
->_BaseFormat
== GL_LUMINANCE
) {
285 for (col
= 0; col
< width
; col
++) {
286 rgba
[col
][GCOMP
] = 0.0F
;
287 rgba
[col
][BCOMP
] = 0.0F
;
288 rgba
[col
][ACOMP
] = 1.0F
;
291 else if (texImage
->_BaseFormat
== GL_LUMINANCE_ALPHA
) {
293 for (col
= 0; col
< width
; col
++) {
294 rgba
[col
][GCOMP
] = 0.0F
;
295 rgba
[col
][BCOMP
] = 0.0F
;
298 else if (texImage
->_BaseFormat
== GL_INTENSITY
) {
300 for (col
= 0; col
< width
; col
++) {
301 rgba
[col
][GCOMP
] = 0.0F
;
302 rgba
[col
][BCOMP
] = 0.0F
;
303 rgba
[col
][ACOMP
] = 1.0F
;
307 _mesa_pack_rgba_span_float(ctx
, width
, (GLfloat (*)[4]) rgba
,
309 &ctx
->Pack
, transferOps
);
319 * Try to do glGetTexImage() with simple memcpy().
320 * \return GL_TRUE if done, GL_FALSE otherwise
323 get_tex_memcpy(struct gl_context
*ctx
, GLenum format
, GLenum type
, GLvoid
*pixels
,
324 const struct gl_texture_object
*texObj
,
325 const struct gl_texture_image
*texImage
)
327 GLboolean memCopy
= GL_FALSE
;
329 /* Texture image should have been mapped already */
330 assert(texImage
->Data
);
333 * Check if the src/dst formats are compatible.
334 * Also note that GL's pixel transfer ops don't apply to glGetTexImage()
335 * so we don't have to worry about those.
336 * XXX more format combinations could be supported here.
338 if ((texObj
->Target
== GL_TEXTURE_1D
||
339 texObj
->Target
== GL_TEXTURE_2D
||
340 texObj
->Target
== GL_TEXTURE_RECTANGLE
||
341 (texObj
->Target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
342 texObj
->Target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
))) {
343 if ((texImage
->TexFormat
== MESA_FORMAT_ARGB8888
||
344 texImage
->TexFormat
== MESA_FORMAT_SARGB8
) &&
346 (type
== GL_UNSIGNED_BYTE
|| type
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
347 !ctx
->Pack
.SwapBytes
&&
348 _mesa_little_endian()) {
351 else if ((texImage
->TexFormat
== MESA_FORMAT_AL88
||
352 texImage
->TexFormat
== MESA_FORMAT_SLA8
) &&
353 format
== GL_LUMINANCE_ALPHA
&&
354 type
== GL_UNSIGNED_BYTE
&&
355 !ctx
->Pack
.SwapBytes
&&
356 _mesa_little_endian()) {
359 else if ((texImage
->TexFormat
== MESA_FORMAT_L8
||
360 texImage
->TexFormat
== MESA_FORMAT_SL8
) &&
361 format
== GL_LUMINANCE
&&
362 type
== GL_UNSIGNED_BYTE
) {
365 else if (texImage
->TexFormat
== MESA_FORMAT_L16
&&
366 format
== GL_LUMINANCE
&&
367 type
== GL_UNSIGNED_SHORT
) {
370 else if (texImage
->TexFormat
== MESA_FORMAT_A8
&&
371 format
== GL_ALPHA
&&
372 type
== GL_UNSIGNED_BYTE
) {
375 else if (texImage
->TexFormat
== MESA_FORMAT_A16
&&
376 format
== GL_ALPHA
&&
377 type
== GL_UNSIGNED_SHORT
) {
383 const GLuint bpp
= _mesa_get_format_bytes(texImage
->TexFormat
);
384 const GLuint bytesPerRow
= texImage
->Width
* bpp
;
386 _mesa_image_address2d(&ctx
->Pack
, pixels
, texImage
->Width
,
387 texImage
->Height
, format
, type
, 0, 0);
388 const GLint dstRowStride
=
389 _mesa_image_row_stride(&ctx
->Pack
, texImage
->Width
, format
, type
);
390 const GLubyte
*src
= texImage
->Data
;
391 const GLint srcRowStride
= texImage
->RowStride
* bpp
;
394 if (bytesPerRow
== dstRowStride
&& bytesPerRow
== srcRowStride
) {
395 memcpy(dst
, src
, bytesPerRow
* texImage
->Height
);
398 for (row
= 0; row
< texImage
->Height
; row
++) {
399 memcpy(dst
, src
, bytesPerRow
);
411 * This is the software fallback for Driver.GetTexImage().
412 * All error checking will have been done before this routine is called.
413 * The texture image must be mapped.
416 _mesa_get_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
417 GLenum format
, GLenum type
, GLvoid
*pixels
,
418 struct gl_texture_object
*texObj
,
419 struct gl_texture_image
*texImage
)
423 /* If we get here, the texture image should be mapped */
424 assert(texImage
->Data
);
437 if (_mesa_is_bufferobj(ctx
->Pack
.BufferObj
)) {
438 /* Packing texture image into a PBO.
439 * Map the (potentially) VRAM-based buffer into our process space so
440 * we can write into it with the code below.
441 * A hardware driver might use a sophisticated blit to move the
442 * texture data to the PBO if the PBO is in VRAM along with the texture.
444 GLubyte
*buf
= (GLubyte
*)
445 ctx
->Driver
.MapBufferRange(ctx
, 0, ctx
->Pack
.BufferObj
->Size
,
446 GL_MAP_WRITE_BIT
, ctx
->Pack
.BufferObj
);
448 /* out of memory or other unexpected error */
449 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glGetTexImage(map PBO failed)");
452 /* <pixels> was an offset into the PBO.
453 * Now make it a real, client-side pointer inside the mapped region.
455 pixels
= ADD_POINTERS(buf
, pixels
);
458 if (get_tex_memcpy(ctx
, format
, type
, pixels
, texObj
, texImage
)) {
461 else if (format
== GL_DEPTH_COMPONENT
) {
462 get_tex_depth(ctx
, dimensions
, format
, type
, pixels
, texImage
);
464 else if (format
== GL_DEPTH_STENCIL_EXT
) {
465 get_tex_depth_stencil(ctx
, dimensions
, format
, type
, pixels
, texImage
);
467 else if (format
== GL_YCBCR_MESA
) {
468 get_tex_ycbcr(ctx
, dimensions
, format
, type
, pixels
, texImage
);
471 get_tex_rgba(ctx
, dimensions
, format
, type
, pixels
, texImage
);
474 if (_mesa_is_bufferobj(ctx
->Pack
.BufferObj
)) {
475 ctx
->Driver
.UnmapBuffer(ctx
, ctx
->Pack
.BufferObj
);
482 * This is the software fallback for Driver.GetCompressedTexImage().
483 * All error checking will have been done before this routine is called.
486 _mesa_get_compressed_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
488 struct gl_texture_object
*texObj
,
489 struct gl_texture_image
*texImage
)
491 const GLuint row_stride
= _mesa_format_row_stride(texImage
->TexFormat
,
493 const GLuint row_stride_stored
= _mesa_format_row_stride(texImage
->TexFormat
,
494 texImage
->RowStride
);
497 if (_mesa_is_bufferobj(ctx
->Pack
.BufferObj
)) {
498 /* pack texture image into a PBO */
499 GLubyte
*buf
= (GLubyte
*)
500 ctx
->Driver
.MapBufferRange(ctx
, 0, ctx
->Pack
.BufferObj
->Size
,
501 GL_MAP_WRITE_BIT
, ctx
->Pack
.BufferObj
);
503 /* out of memory or other unexpected error */
504 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
505 "glGetCompresssedTexImage(map PBO failed)");
508 img
= ADD_POINTERS(buf
, img
);
511 /* no pixelstore or pixel transfer, but respect stride */
513 if (row_stride
== row_stride_stored
) {
514 const GLuint size
= _mesa_format_image_size(texImage
->TexFormat
,
518 memcpy(img
, texImage
->Data
, size
);
522 _mesa_get_format_block_size(texImage
->TexFormat
, &bw
, &bh
);
523 for (i
= 0; i
< (texImage
->Height
+ bh
- 1) / bh
; i
++) {
524 memcpy((GLubyte
*)img
+ i
* row_stride
,
525 (GLubyte
*)texImage
->Data
+ i
* row_stride_stored
,
530 if (_mesa_is_bufferobj(ctx
->Pack
.BufferObj
)) {
531 ctx
->Driver
.UnmapBuffer(ctx
, ctx
->Pack
.BufferObj
);
538 * Do error checking for a glGetTexImage() call.
539 * \return GL_TRUE if any error, GL_FALSE if no errors.
542 getteximage_error_check(struct gl_context
*ctx
, GLenum target
, GLint level
,
543 GLenum format
, GLenum type
, GLsizei clientMemSize
,
546 struct gl_texture_object
*texObj
;
547 struct gl_texture_image
*texImage
;
548 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
549 const GLuint dimensions
= (target
== GL_TEXTURE_3D
) ? 3 : 2;
552 if (maxLevels
== 0) {
553 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(target=0x%x)", target
);
557 if (level
< 0 || level
>= maxLevels
) {
558 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexImage(level)" );
562 if (_mesa_sizeof_packed_type(type
) <= 0) {
563 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(type)" );
567 if (_mesa_components_in_format(format
) <= 0 ||
568 format
== GL_STENCIL_INDEX
||
569 format
== GL_COLOR_INDEX
) {
570 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)" );
574 if (!ctx
->Extensions
.ARB_depth_texture
&& _mesa_is_depth_format(format
)) {
575 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
579 if (!ctx
->Extensions
.MESA_ycbcr_texture
&& _mesa_is_ycbcr_format(format
)) {
580 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
584 if (!ctx
->Extensions
.EXT_packed_depth_stencil
585 && _mesa_is_depthstencil_format(format
)) {
586 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
590 if (!ctx
->Extensions
.ATI_envmap_bumpmap
591 && _mesa_is_dudv_format(format
)) {
592 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
596 texObj
= _mesa_get_current_tex_object(ctx
, target
);
598 if (!texObj
|| _mesa_is_proxy_texture(target
)) {
599 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(target)");
603 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
609 baseFormat
= _mesa_get_format_base_format(texImage
->TexFormat
);
611 /* Make sure the requested image format is compatible with the
614 if (_mesa_is_color_format(format
)
615 && !_mesa_is_color_format(baseFormat
)) {
616 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
619 else if (_mesa_is_depth_format(format
)
620 && !_mesa_is_depth_format(baseFormat
)
621 && !_mesa_is_depthstencil_format(baseFormat
)) {
622 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
625 else if (_mesa_is_ycbcr_format(format
)
626 && !_mesa_is_ycbcr_format(baseFormat
)) {
627 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
630 else if (_mesa_is_depthstencil_format(format
)
631 && !_mesa_is_depthstencil_format(baseFormat
)) {
632 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
635 else if (_mesa_is_dudv_format(format
)
636 && !_mesa_is_dudv_format(baseFormat
)) {
637 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
641 if (!_mesa_validate_pbo_access(dimensions
, &ctx
->Pack
, texImage
->Width
,
642 texImage
->Height
, texImage
->Depth
,
643 format
, type
, clientMemSize
, pixels
)) {
644 if (_mesa_is_bufferobj(ctx
->Pack
.BufferObj
)) {
645 _mesa_error(ctx
, GL_INVALID_OPERATION
,
646 "glGetTexImage(out of bounds PBO access)");
648 _mesa_error(ctx
, GL_INVALID_OPERATION
,
649 "glGetnTexImageARB(out of bounds access:"
650 " bufSize (%d) is too small)", clientMemSize
);
655 if (_mesa_is_bufferobj(ctx
->Pack
.BufferObj
)) {
656 /* PBO should not be mapped */
657 if (_mesa_bufferobj_mapped(ctx
->Pack
.BufferObj
)) {
658 _mesa_error(ctx
, GL_INVALID_OPERATION
,
659 "glGetTexImage(PBO is mapped)");
670 * Get texture image. Called by glGetTexImage.
672 * \param target texture target.
673 * \param level image level.
674 * \param format pixel data format for returned image.
675 * \param type pixel data type for returned image.
676 * \param bufSize size of the pixels data buffer.
677 * \param pixels returned pixel data.
680 _mesa_GetnTexImageARB( GLenum target
, GLint level
, GLenum format
,
681 GLenum type
, GLsizei bufSize
, GLvoid
*pixels
)
683 struct gl_texture_object
*texObj
;
684 struct gl_texture_image
*texImage
;
685 GET_CURRENT_CONTEXT(ctx
);
686 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
688 if (getteximage_error_check(ctx
, target
, level
, format
, type
,
693 if (!_mesa_is_bufferobj(ctx
->Pack
.BufferObj
) && !pixels
) {
694 /* not an error, do nothing */
698 texObj
= _mesa_get_current_tex_object(ctx
, target
);
699 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
701 if (MESA_VERBOSE
& (VERBOSE_API
| VERBOSE_TEXTURE
)) {
702 _mesa_debug(ctx
, "glGetTexImage(tex %u) format = %s, w=%d, h=%d,"
703 " dstFmt=0x%x, dstType=0x%x\n",
705 _mesa_get_format_name(texImage
->TexFormat
),
706 texImage
->Width
, texImage
->Height
,
710 _mesa_lock_texture(ctx
, texObj
);
712 ctx
->Driver
.GetTexImage(ctx
, target
, level
, format
, type
, pixels
,
715 _mesa_unlock_texture(ctx
, texObj
);
720 _mesa_GetTexImage( GLenum target
, GLint level
, GLenum format
,
721 GLenum type
, GLvoid
*pixels
)
723 _mesa_GetnTexImageARB(target
, level
, format
, type
, INT_MAX
, pixels
);
728 * Do error checking for a glGetCompressedTexImage() call.
729 * \return GL_TRUE if any error, GL_FALSE if no errors.
732 getcompressedteximage_error_check(struct gl_context
*ctx
, GLenum target
,
733 GLint level
, GLsizei clientMemSize
, GLvoid
*img
)
735 struct gl_texture_object
*texObj
;
736 struct gl_texture_image
*texImage
;
737 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
738 GLuint compressedSize
;
740 if (maxLevels
== 0) {
741 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImage(target=0x%x)",
746 if (level
< 0 || level
>= maxLevels
) {
747 _mesa_error(ctx
, GL_INVALID_VALUE
,
748 "glGetCompressedTexImageARB(bad level = %d)", level
);
752 if (_mesa_is_proxy_texture(target
)) {
753 _mesa_error(ctx
, GL_INVALID_ENUM
,
754 "glGetCompressedTexImageARB(bad target = %s)",
755 _mesa_lookup_enum_by_nr(target
));
759 texObj
= _mesa_get_current_tex_object(ctx
, target
);
761 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB(target)");
765 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
768 /* probably invalid mipmap level */
769 _mesa_error(ctx
, GL_INVALID_VALUE
,
770 "glGetCompressedTexImageARB(level)");
774 if (!_mesa_is_format_compressed(texImage
->TexFormat
)) {
775 _mesa_error(ctx
, GL_INVALID_OPERATION
,
776 "glGetCompressedTexImageARB(texture is not compressed)");
780 compressedSize
= _mesa_format_image_size(texImage
->TexFormat
,
785 if (!_mesa_is_bufferobj(ctx
->Pack
.BufferObj
)) {
786 /* do bounds checking on writing to client memory */
787 if (clientMemSize
< compressedSize
) {
788 _mesa_error(ctx
, GL_INVALID_OPERATION
,
789 "glGetnCompressedTexImageARB(out of bounds access:"
790 " bufSize (%d) is too small)", clientMemSize
);
793 /* do bounds checking on PBO write */
794 if ((const GLubyte
*) img
+ compressedSize
>
795 (const GLubyte
*) ctx
->Pack
.BufferObj
->Size
) {
796 _mesa_error(ctx
, GL_INVALID_OPERATION
,
797 "glGetCompressedTexImage(out of bounds PBO access)");
801 /* make sure PBO is not mapped */
802 if (_mesa_bufferobj_mapped(ctx
->Pack
.BufferObj
)) {
803 _mesa_error(ctx
, GL_INVALID_OPERATION
,
804 "glGetCompressedTexImage(PBO is mapped)");
814 _mesa_GetnCompressedTexImageARB(GLenum target
, GLint level
, GLsizei bufSize
,
817 struct gl_texture_object
*texObj
;
818 struct gl_texture_image
*texImage
;
819 GET_CURRENT_CONTEXT(ctx
);
820 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
822 if (getcompressedteximage_error_check(ctx
, target
, level
, bufSize
, img
)) {
826 if (_mesa_is_bufferobj(ctx
->Pack
.BufferObj
) && !img
) {
827 /* not an error, do nothing */
831 texObj
= _mesa_get_current_tex_object(ctx
, target
);
832 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
834 if (MESA_VERBOSE
& (VERBOSE_API
| VERBOSE_TEXTURE
)) {
836 "glGetCompressedTexImage(tex %u) format = %s, w=%d, h=%d\n",
838 _mesa_get_format_name(texImage
->TexFormat
),
839 texImage
->Width
, texImage
->Height
);
842 _mesa_lock_texture(ctx
, texObj
);
844 ctx
->Driver
.GetCompressedTexImage(ctx
, target
, level
, img
,
847 _mesa_unlock_texture(ctx
, texObj
);
851 _mesa_GetCompressedTexImageARB(GLenum target
, GLint level
, GLvoid
*img
)
853 _mesa_GetnCompressedTexImageARB(target
, level
, INT_MAX
, img
);