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"
50 * Can the given type represent negative values?
52 static INLINE GLboolean
53 type_with_negative_values(GLenum type
)
60 case GL_HALF_FLOAT_ARB
:
69 * glGetTexImage for depth/Z pixels.
72 get_tex_depth(struct gl_context
*ctx
, GLuint dimensions
,
73 GLenum format
, GLenum type
, GLvoid
*pixels
,
74 const struct gl_texture_image
*texImage
)
76 const GLint width
= texImage
->Width
;
77 const GLint height
= texImage
->Height
;
78 const GLint depth
= texImage
->Depth
;
80 GLfloat
*depthRow
= (GLfloat
*) malloc(width
* sizeof(GLfloat
));
81 const GLint texelSize
= _mesa_get_format_bytes(texImage
->TexFormat
);
84 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glGetTexImage");
88 for (img
= 0; img
< depth
; img
++) {
89 for (row
= 0; row
< height
; row
++) {
90 void *dest
= _mesa_image_address(dimensions
, &ctx
->Pack
, pixels
,
91 width
, height
, format
, type
,
93 const GLubyte
*src
= (GLubyte
*) texImage
->Data
+
94 (texImage
->ImageOffsets
[img
] +
95 texImage
->RowStride
* row
) * texelSize
;
97 _mesa_unpack_float_z_row(texImage
->TexFormat
, width
, src
, depthRow
);
99 _mesa_pack_depth_span(ctx
, width
, dest
, type
, depthRow
, &ctx
->Pack
);
108 * glGetTexImage for depth/stencil pixels.
111 get_tex_depth_stencil(struct gl_context
*ctx
, GLuint dimensions
,
112 GLenum format
, GLenum type
, GLvoid
*pixels
,
113 const struct gl_texture_image
*texImage
)
115 const GLint width
= texImage
->Width
;
116 const GLint height
= texImage
->Height
;
117 const GLint depth
= texImage
->Depth
;
118 const GLint rowstride
= texImage
->RowStride
;
119 const GLuint
*src
= (const GLuint
*) texImage
->Data
;
122 for (img
= 0; img
< depth
; img
++) {
123 for (row
= 0; row
< height
; row
++) {
124 void *dest
= _mesa_image_address(dimensions
, &ctx
->Pack
, pixels
,
125 width
, height
, format
, type
,
127 memcpy(dest
, src
, width
* sizeof(GLuint
));
128 if (ctx
->Pack
.SwapBytes
) {
129 _mesa_swap4((GLuint
*) dest
, width
);
139 * glGetTexImage for YCbCr pixels.
142 get_tex_ycbcr(struct gl_context
*ctx
, GLuint dimensions
,
143 GLenum format
, GLenum type
, GLvoid
*pixels
,
144 const struct gl_texture_image
*texImage
)
146 const GLint width
= texImage
->Width
;
147 const GLint height
= texImage
->Height
;
148 const GLint depth
= texImage
->Depth
;
149 const GLint rowstride
= texImage
->RowStride
;
150 const GLushort
*src
= (const GLushort
*) texImage
->Data
;
153 for (img
= 0; img
< depth
; img
++) {
154 for (row
= 0; row
< height
; row
++) {
155 void *dest
= _mesa_image_address(dimensions
, &ctx
->Pack
, pixels
,
156 width
, height
, format
, type
,
158 memcpy(dest
, src
, width
* sizeof(GLushort
));
160 /* check for byte swapping */
161 if ((texImage
->TexFormat
== MESA_FORMAT_YCBCR
162 && type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
) ||
163 (texImage
->TexFormat
== MESA_FORMAT_YCBCR_REV
164 && type
== GL_UNSIGNED_SHORT_8_8_MESA
)) {
165 if (!ctx
->Pack
.SwapBytes
)
166 _mesa_swap2((GLushort
*) dest
, width
);
168 else if (ctx
->Pack
.SwapBytes
) {
169 _mesa_swap2((GLushort
*) dest
, width
);
179 * glGetTexImage for color formats (RGBA, RGB, alpha, LA, etc).
180 * Compressed textures are handled here as well.
183 get_tex_rgba(struct gl_context
*ctx
, GLuint dimensions
,
184 GLenum format
, GLenum type
, GLvoid
*pixels
,
185 struct gl_texture_image
*texImage
)
187 /* don't want to apply sRGB -> RGB conversion here so override the format */
188 const gl_format texFormat
= _mesa_get_srgb_format_linear(texImage
->TexFormat
);
189 const GLuint width
= texImage
->Width
;
190 const GLuint height
= texImage
->Height
;
191 const GLuint depth
= texImage
->Depth
;
192 const GLenum dataType
= _mesa_get_format_datatype(texFormat
);
193 const GLenum baseFormat
= _mesa_get_format_base_format(texFormat
);
194 /* Normally, no pixel transfer ops are performed during glGetTexImage.
195 * The only possible exception is component clamping to [0,1].
197 GLbitfield transferOps
= 0x0;
199 /* In general, clamping does not apply to glGetTexImage, except when
200 * the returned type of the image can't hold negative values.
202 if (!type_with_negative_values(type
)) {
203 /* the returned image type can't have negative values */
204 if (dataType
== GL_FLOAT
||
205 dataType
== GL_SIGNED_NORMALIZED
||
206 format
== GL_LUMINANCE
||
207 format
== GL_LUMINANCE_ALPHA
) {
208 transferOps
|= IMAGE_CLAMP_BIT
;
212 if (_mesa_is_format_compressed(texFormat
)) {
213 /* Decompress into temp buffer, then pack into user buffer */
214 GLfloat
*tempImage
, *srcRow
;
217 tempImage
= (GLfloat
*) malloc(texImage
->Width
* texImage
->Height
*
218 texImage
->Depth
* 4 * sizeof(GLfloat
));
220 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glGetTexImage()");
224 _mesa_decompress_image(texFormat
, texImage
->Width
, texImage
->Height
,
225 texImage
->Data
, texImage
->RowStride
, tempImage
);
227 if (baseFormat
== GL_LUMINANCE
||
228 baseFormat
== GL_LUMINANCE_ALPHA
) {
229 /* Set green and blue to zero since the pack function here will
233 for (i
= 0; i
< width
* height
; i
++) {
234 tempImage
[i
* 4 + GCOMP
] = tempImage
[i
* 4 + BCOMP
] = 0.0f
;
239 for (row
= 0; row
< height
; row
++) {
240 void *dest
= _mesa_image_address(dimensions
, &ctx
->Pack
, pixels
,
241 width
, height
, format
, type
,
244 _mesa_pack_rgba_span_float(ctx
, width
, (GLfloat (*)[4]) srcRow
,
245 format
, type
, dest
, &ctx
->Pack
, transferOps
);
252 /* No decompression needed */
253 const GLint texelSize
= _mesa_get_format_bytes(texFormat
);
257 rgba
= (GLfloat (*)[4]) malloc(4 * width
* sizeof(GLfloat
));
259 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glGetTexImage()");
263 for (img
= 0; img
< depth
; img
++) {
264 for (row
= 0; row
< height
; row
++) {
265 void *dest
= _mesa_image_address(dimensions
, &ctx
->Pack
, pixels
,
266 width
, height
, format
, type
,
268 const GLubyte
*src
= (const GLubyte
*) texImage
->Data
+
269 (texImage
->ImageOffsets
[img
] +
270 texImage
->RowStride
* row
) * texelSize
;
272 _mesa_unpack_rgba_row(texFormat
, width
, src
, rgba
);
274 if (texImage
->_BaseFormat
== GL_ALPHA
) {
276 for (col
= 0; col
< width
; col
++) {
277 rgba
[col
][RCOMP
] = 0.0F
;
278 rgba
[col
][GCOMP
] = 0.0F
;
279 rgba
[col
][BCOMP
] = 0.0F
;
282 else if (texImage
->_BaseFormat
== GL_LUMINANCE
) {
284 for (col
= 0; col
< width
; col
++) {
285 rgba
[col
][GCOMP
] = 0.0F
;
286 rgba
[col
][BCOMP
] = 0.0F
;
287 rgba
[col
][ACOMP
] = 1.0F
;
290 else if (texImage
->_BaseFormat
== GL_LUMINANCE_ALPHA
) {
292 for (col
= 0; col
< width
; col
++) {
293 rgba
[col
][GCOMP
] = 0.0F
;
294 rgba
[col
][BCOMP
] = 0.0F
;
297 else if (texImage
->_BaseFormat
== GL_INTENSITY
) {
299 for (col
= 0; col
< width
; col
++) {
300 rgba
[col
][GCOMP
] = 0.0F
;
301 rgba
[col
][BCOMP
] = 0.0F
;
302 rgba
[col
][ACOMP
] = 1.0F
;
306 _mesa_pack_rgba_span_float(ctx
, width
, (GLfloat (*)[4]) rgba
,
308 &ctx
->Pack
, transferOps
);
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 * We'll call ctx->Driver.MapTextureImage() to access the data, then
413 * unmap with ctx->Driver.UnmapTextureImage().
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
)
434 /* map dest buffer, if PBO */
435 if (_mesa_is_bufferobj(ctx
->Pack
.BufferObj
)) {
436 /* Packing texture image into a PBO.
437 * Map the (potentially) VRAM-based buffer into our process space so
438 * we can write into it with the code below.
439 * A hardware driver might use a sophisticated blit to move the
440 * texture data to the PBO if the PBO is in VRAM along with the texture.
442 GLubyte
*buf
= (GLubyte
*)
443 ctx
->Driver
.MapBufferRange(ctx
, 0, ctx
->Pack
.BufferObj
->Size
,
444 GL_MAP_WRITE_BIT
, ctx
->Pack
.BufferObj
);
446 /* out of memory or other unexpected error */
447 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glGetTexImage(map PBO failed)");
450 /* <pixels> was an offset into the PBO.
451 * Now make it a real, client-side pointer inside the mapped region.
453 pixels
= ADD_POINTERS(buf
, pixels
);
456 if (get_tex_memcpy(ctx
, format
, type
, pixels
, texObj
, texImage
)) {
459 else if (format
== GL_DEPTH_COMPONENT
) {
460 get_tex_depth(ctx
, dimensions
, format
, type
, pixels
, texImage
);
462 else if (format
== GL_DEPTH_STENCIL_EXT
) {
463 get_tex_depth_stencil(ctx
, dimensions
, format
, type
, pixels
, texImage
);
465 else if (format
== GL_YCBCR_MESA
) {
466 get_tex_ycbcr(ctx
, dimensions
, format
, type
, pixels
, texImage
);
469 get_tex_rgba(ctx
, dimensions
, format
, type
, pixels
, texImage
);
472 if (_mesa_is_bufferobj(ctx
->Pack
.BufferObj
)) {
473 ctx
->Driver
.UnmapBuffer(ctx
, ctx
->Pack
.BufferObj
);
480 * This is the software fallback for Driver.GetCompressedTexImage().
481 * All error checking will have been done before this routine is called.
484 _mesa_get_compressed_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
486 struct gl_texture_object
*texObj
,
487 struct gl_texture_image
*texImage
)
489 const GLuint row_stride
=
490 _mesa_format_row_stride(texImage
->TexFormat
, texImage
->Width
);
495 if (_mesa_is_bufferobj(ctx
->Pack
.BufferObj
)) {
496 /* pack texture image into a PBO */
497 GLubyte
*buf
= (GLubyte
*)
498 ctx
->Driver
.MapBufferRange(ctx
, 0, ctx
->Pack
.BufferObj
->Size
,
499 GL_MAP_WRITE_BIT
, ctx
->Pack
.BufferObj
);
501 /* out of memory or other unexpected error */
502 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
503 "glGetCompresssedTexImage(map PBO failed)");
506 img
= ADD_POINTERS(buf
, img
);
509 /* map src texture buffer */
510 ctx
->Driver
.MapTextureImage(ctx
, texImage
, 0,
511 0, 0, texImage
->Width
, texImage
->Height
,
512 GL_MAP_READ_BIT
, &src
, &srcRowStride
);
514 /* no pixelstore or pixel transfer, but respect stride */
516 if (row_stride
== srcRowStride
) {
517 const GLuint size
= _mesa_format_image_size(texImage
->TexFormat
,
521 memcpy(img
, src
, 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
*)src
+ i
* srcRowStride
,
533 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, 0);
535 if (_mesa_is_bufferobj(ctx
->Pack
.BufferObj
)) {
536 ctx
->Driver
.UnmapBuffer(ctx
, ctx
->Pack
.BufferObj
);
543 * Do error checking for a glGetTexImage() call.
544 * \return GL_TRUE if any error, GL_FALSE if no errors.
547 getteximage_error_check(struct gl_context
*ctx
, GLenum target
, GLint level
,
548 GLenum format
, GLenum type
, GLsizei clientMemSize
,
551 struct gl_texture_object
*texObj
;
552 struct gl_texture_image
*texImage
;
553 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
554 const GLuint dimensions
= (target
== GL_TEXTURE_3D
) ? 3 : 2;
557 if (maxLevels
== 0) {
558 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(target=0x%x)", target
);
562 if (level
< 0 || level
>= maxLevels
) {
563 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexImage(level)" );
567 if (_mesa_sizeof_packed_type(type
) <= 0) {
568 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(type)" );
572 if (_mesa_components_in_format(format
) <= 0 ||
573 format
== GL_STENCIL_INDEX
||
574 format
== GL_COLOR_INDEX
) {
575 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)" );
579 if (!ctx
->Extensions
.ARB_depth_texture
&& _mesa_is_depth_format(format
)) {
580 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
584 if (!ctx
->Extensions
.MESA_ycbcr_texture
&& _mesa_is_ycbcr_format(format
)) {
585 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
589 if (!ctx
->Extensions
.EXT_packed_depth_stencil
590 && _mesa_is_depthstencil_format(format
)) {
591 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
595 if (!ctx
->Extensions
.ATI_envmap_bumpmap
596 && _mesa_is_dudv_format(format
)) {
597 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
601 texObj
= _mesa_get_current_tex_object(ctx
, target
);
603 if (!texObj
|| _mesa_is_proxy_texture(target
)) {
604 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(target)");
608 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
614 baseFormat
= _mesa_get_format_base_format(texImage
->TexFormat
);
616 /* Make sure the requested image format is compatible with the
619 if (_mesa_is_color_format(format
)
620 && !_mesa_is_color_format(baseFormat
)) {
621 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
624 else if (_mesa_is_depth_format(format
)
625 && !_mesa_is_depth_format(baseFormat
)
626 && !_mesa_is_depthstencil_format(baseFormat
)) {
627 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
630 else if (_mesa_is_ycbcr_format(format
)
631 && !_mesa_is_ycbcr_format(baseFormat
)) {
632 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
635 else if (_mesa_is_depthstencil_format(format
)
636 && !_mesa_is_depthstencil_format(baseFormat
)) {
637 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
640 else if (_mesa_is_dudv_format(format
)
641 && !_mesa_is_dudv_format(baseFormat
)) {
642 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
646 if (!_mesa_validate_pbo_access(dimensions
, &ctx
->Pack
, texImage
->Width
,
647 texImage
->Height
, texImage
->Depth
,
648 format
, type
, clientMemSize
, pixels
)) {
649 if (_mesa_is_bufferobj(ctx
->Pack
.BufferObj
)) {
650 _mesa_error(ctx
, GL_INVALID_OPERATION
,
651 "glGetTexImage(out of bounds PBO access)");
653 _mesa_error(ctx
, GL_INVALID_OPERATION
,
654 "glGetnTexImageARB(out of bounds access:"
655 " bufSize (%d) is too small)", clientMemSize
);
660 if (_mesa_is_bufferobj(ctx
->Pack
.BufferObj
)) {
661 /* PBO should not be mapped */
662 if (_mesa_bufferobj_mapped(ctx
->Pack
.BufferObj
)) {
663 _mesa_error(ctx
, GL_INVALID_OPERATION
,
664 "glGetTexImage(PBO is mapped)");
675 * Get texture image. Called by glGetTexImage.
677 * \param target texture target.
678 * \param level image level.
679 * \param format pixel data format for returned image.
680 * \param type pixel data type for returned image.
681 * \param bufSize size of the pixels data buffer.
682 * \param pixels returned pixel data.
685 _mesa_GetnTexImageARB( GLenum target
, GLint level
, GLenum format
,
686 GLenum type
, GLsizei bufSize
, GLvoid
*pixels
)
688 struct gl_texture_object
*texObj
;
689 struct gl_texture_image
*texImage
;
690 GET_CURRENT_CONTEXT(ctx
);
691 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
693 if (getteximage_error_check(ctx
, target
, level
, format
, type
,
698 if (!_mesa_is_bufferobj(ctx
->Pack
.BufferObj
) && !pixels
) {
699 /* not an error, do nothing */
703 texObj
= _mesa_get_current_tex_object(ctx
, target
);
704 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
706 if (MESA_VERBOSE
& (VERBOSE_API
| VERBOSE_TEXTURE
)) {
707 _mesa_debug(ctx
, "glGetTexImage(tex %u) format = %s, w=%d, h=%d,"
708 " dstFmt=0x%x, dstType=0x%x\n",
710 _mesa_get_format_name(texImage
->TexFormat
),
711 texImage
->Width
, texImage
->Height
,
715 _mesa_lock_texture(ctx
, texObj
);
717 ctx
->Driver
.GetTexImage(ctx
, target
, level
, format
, type
, pixels
,
720 _mesa_unlock_texture(ctx
, texObj
);
725 _mesa_GetTexImage( GLenum target
, GLint level
, GLenum format
,
726 GLenum type
, GLvoid
*pixels
)
728 _mesa_GetnTexImageARB(target
, level
, format
, type
, INT_MAX
, pixels
);
733 * Do error checking for a glGetCompressedTexImage() call.
734 * \return GL_TRUE if any error, GL_FALSE if no errors.
737 getcompressedteximage_error_check(struct gl_context
*ctx
, GLenum target
,
738 GLint level
, GLsizei clientMemSize
, GLvoid
*img
)
740 struct gl_texture_object
*texObj
;
741 struct gl_texture_image
*texImage
;
742 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
743 GLuint compressedSize
;
745 if (maxLevels
== 0) {
746 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImage(target=0x%x)",
751 if (level
< 0 || level
>= maxLevels
) {
752 _mesa_error(ctx
, GL_INVALID_VALUE
,
753 "glGetCompressedTexImageARB(bad level = %d)", level
);
757 if (_mesa_is_proxy_texture(target
)) {
758 _mesa_error(ctx
, GL_INVALID_ENUM
,
759 "glGetCompressedTexImageARB(bad target = %s)",
760 _mesa_lookup_enum_by_nr(target
));
764 texObj
= _mesa_get_current_tex_object(ctx
, target
);
766 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB(target)");
770 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
773 /* probably invalid mipmap level */
774 _mesa_error(ctx
, GL_INVALID_VALUE
,
775 "glGetCompressedTexImageARB(level)");
779 if (!_mesa_is_format_compressed(texImage
->TexFormat
)) {
780 _mesa_error(ctx
, GL_INVALID_OPERATION
,
781 "glGetCompressedTexImageARB(texture is not compressed)");
785 compressedSize
= _mesa_format_image_size(texImage
->TexFormat
,
790 if (!_mesa_is_bufferobj(ctx
->Pack
.BufferObj
)) {
791 /* do bounds checking on writing to client memory */
792 if (clientMemSize
< compressedSize
) {
793 _mesa_error(ctx
, GL_INVALID_OPERATION
,
794 "glGetnCompressedTexImageARB(out of bounds access:"
795 " bufSize (%d) is too small)", clientMemSize
);
798 /* do bounds checking on PBO write */
799 if ((const GLubyte
*) img
+ compressedSize
>
800 (const GLubyte
*) ctx
->Pack
.BufferObj
->Size
) {
801 _mesa_error(ctx
, GL_INVALID_OPERATION
,
802 "glGetCompressedTexImage(out of bounds PBO access)");
806 /* make sure PBO is not mapped */
807 if (_mesa_bufferobj_mapped(ctx
->Pack
.BufferObj
)) {
808 _mesa_error(ctx
, GL_INVALID_OPERATION
,
809 "glGetCompressedTexImage(PBO is mapped)");
819 _mesa_GetnCompressedTexImageARB(GLenum target
, GLint level
, GLsizei bufSize
,
822 struct gl_texture_object
*texObj
;
823 struct gl_texture_image
*texImage
;
824 GET_CURRENT_CONTEXT(ctx
);
825 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
827 if (getcompressedteximage_error_check(ctx
, target
, level
, bufSize
, img
)) {
831 if (_mesa_is_bufferobj(ctx
->Pack
.BufferObj
) && !img
) {
832 /* not an error, do nothing */
836 texObj
= _mesa_get_current_tex_object(ctx
, target
);
837 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
839 if (MESA_VERBOSE
& (VERBOSE_API
| VERBOSE_TEXTURE
)) {
841 "glGetCompressedTexImage(tex %u) format = %s, w=%d, h=%d\n",
843 _mesa_get_format_name(texImage
->TexFormat
),
844 texImage
->Width
, texImage
->Height
);
847 _mesa_lock_texture(ctx
, texObj
);
849 ctx
->Driver
.GetCompressedTexImage(ctx
, target
, level
, img
,
852 _mesa_unlock_texture(ctx
, texObj
);
856 _mesa_GetCompressedTexImageARB(GLenum target
, GLint level
, GLvoid
*img
)
858 _mesa_GetnCompressedTexImageARB(target
, level
, INT_MAX
, img
);