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 "texgetimage.h"
43 #if FEATURE_EXT_texture_sRGB
46 * Convert a float value from linear space to a
47 * non-linear sRGB value in [0, 255].
48 * Not terribly efficient.
51 linear_to_nonlinear(GLfloat cl
)
53 /* can't have values outside [0, 1] */
55 if (cl
< 0.0031308f
) {
59 cs
= (GLfloat
)(1.055 * _mesa_pow(cl
, 0.41666) - 0.055);
64 #endif /* FEATURE_EXT_texture_sRGB */
68 * Can the given type represent negative values?
70 static INLINE GLboolean
71 type_with_negative_values(GLenum type
)
78 case GL_HALF_FLOAT_ARB
:
87 * glGetTexImage for color index pixels.
90 get_tex_color_index(GLcontext
*ctx
, GLuint dimensions
,
91 GLenum format
, GLenum type
, GLvoid
*pixels
,
92 const struct gl_texture_image
*texImage
)
94 const GLint width
= texImage
->Width
;
95 const GLint height
= texImage
->Height
;
96 const GLint depth
= texImage
->Depth
;
97 const GLuint indexBits
=
98 _mesa_get_format_bits(texImage
->TexFormat
, GL_TEXTURE_INDEX_SIZE_EXT
);
99 const GLbitfield transferOps
= 0x0;
102 for (img
= 0; img
< depth
; img
++) {
103 for (row
= 0; row
< height
; row
++) {
104 GLuint indexRow
[MAX_WIDTH
] = { 0 };
105 void *dest
= _mesa_image_address(dimensions
, &ctx
->Pack
, pixels
,
106 width
, height
, format
, type
,
110 if (indexBits
== 8) {
111 const GLubyte
*src
= (const GLubyte
*) texImage
->Data
;
112 src
+= width
* (img
* texImage
->Height
+ row
);
113 for (col
= 0; col
< width
; col
++) {
114 indexRow
[col
] = src
[col
];
117 else if (indexBits
== 16) {
118 const GLushort
*src
= (const GLushort
*) texImage
->Data
;
119 src
+= width
* (img
* texImage
->Height
+ row
);
120 for (col
= 0; col
< width
; col
++) {
121 indexRow
[col
] = src
[col
];
125 _mesa_problem(ctx
, "Color index problem in _mesa_GetTexImage");
127 _mesa_pack_index_span(ctx
, width
, type
, dest
,
128 indexRow
, &ctx
->Pack
, transferOps
);
135 * glGetTexImage for depth/Z pixels.
138 get_tex_depth(GLcontext
*ctx
, GLuint dimensions
,
139 GLenum format
, GLenum type
, GLvoid
*pixels
,
140 const struct gl_texture_image
*texImage
)
142 const GLint width
= texImage
->Width
;
143 const GLint height
= texImage
->Height
;
144 const GLint depth
= texImage
->Depth
;
147 for (img
= 0; img
< depth
; img
++) {
148 for (row
= 0; row
< height
; row
++) {
149 GLfloat depthRow
[MAX_WIDTH
];
150 void *dest
= _mesa_image_address(dimensions
, &ctx
->Pack
, pixels
,
151 width
, height
, format
, type
,
155 for (col
= 0; col
< width
; col
++) {
156 texImage
->FetchTexelf(texImage
, col
, row
, img
, depthRow
+ col
);
158 _mesa_pack_depth_span(ctx
, width
, dest
, type
, depthRow
, &ctx
->Pack
);
165 * glGetTexImage for depth/stencil pixels.
168 get_tex_depth_stencil(GLcontext
*ctx
, GLuint dimensions
,
169 GLenum format
, GLenum type
, GLvoid
*pixels
,
170 const struct gl_texture_image
*texImage
)
172 const GLint width
= texImage
->Width
;
173 const GLint height
= texImage
->Height
;
174 const GLint depth
= texImage
->Depth
;
175 const GLuint
*src
= (const GLuint
*) texImage
->Data
;
178 for (img
= 0; img
< depth
; img
++) {
179 for (row
= 0; row
< height
; row
++) {
180 void *dest
= _mesa_image_address(dimensions
, &ctx
->Pack
, pixels
,
181 width
, height
, format
, type
,
183 _mesa_memcpy(dest
, src
, width
* sizeof(GLuint
));
184 if (ctx
->Pack
.SwapBytes
) {
185 _mesa_swap4((GLuint
*) dest
, width
);
188 src
+= width
* row
+ width
* height
* img
;
195 * glGetTexImage for YCbCr pixels.
198 get_tex_ycbcr(GLcontext
*ctx
, GLuint dimensions
,
199 GLenum format
, GLenum type
, GLvoid
*pixels
,
200 const struct gl_texture_image
*texImage
)
202 const GLint width
= texImage
->Width
;
203 const GLint height
= texImage
->Height
;
204 const GLint depth
= texImage
->Depth
;
205 const GLint rowstride
= texImage
->RowStride
;
206 const GLushort
*src
= (const GLushort
*) texImage
->Data
;
209 for (img
= 0; img
< depth
; img
++) {
210 for (row
= 0; row
< height
; row
++) {
211 void *dest
= _mesa_image_address(dimensions
, &ctx
->Pack
, pixels
,
212 width
, height
, format
, type
,
214 _mesa_memcpy(dest
, src
, width
* sizeof(GLushort
));
216 /* check for byte swapping */
217 if ((texImage
->TexFormat
== MESA_FORMAT_YCBCR
218 && type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
) ||
219 (texImage
->TexFormat
== MESA_FORMAT_YCBCR_REV
220 && type
== GL_UNSIGNED_SHORT_8_8_MESA
)) {
221 if (!ctx
->Pack
.SwapBytes
)
222 _mesa_swap2((GLushort
*) dest
, width
);
224 else if (ctx
->Pack
.SwapBytes
) {
225 _mesa_swap2((GLushort
*) dest
, width
);
235 * glGetTexImagefor sRGB pixels;
238 get_tex_srgb(GLcontext
*ctx
, GLuint dimensions
,
239 GLenum format
, GLenum type
, GLvoid
*pixels
,
240 const struct gl_texture_image
*texImage
)
242 const GLint width
= texImage
->Width
;
243 const GLint height
= texImage
->Height
;
244 const GLint depth
= texImage
->Depth
;
245 const GLbitfield transferOps
= 0x0;
248 for (img
= 0; img
< depth
; img
++) {
249 for (row
= 0; row
< height
; row
++) {
250 void *dest
= _mesa_image_address(dimensions
, &ctx
->Pack
, pixels
,
251 width
, height
, format
, type
,
254 GLfloat rgba
[MAX_WIDTH
][4];
257 /* convert row to RGBA format */
258 for (col
= 0; col
< width
; col
++) {
259 texImage
->FetchTexelf(texImage
, col
, row
, img
, rgba
[col
]);
260 if (texImage
->_BaseFormat
== GL_LUMINANCE
) {
261 rgba
[col
][RCOMP
] = linear_to_nonlinear(rgba
[col
][RCOMP
]);
262 rgba
[col
][GCOMP
] = 0.0;
263 rgba
[col
][BCOMP
] = 0.0;
265 else if (texImage
->_BaseFormat
== GL_LUMINANCE_ALPHA
) {
266 rgba
[col
][RCOMP
] = linear_to_nonlinear(rgba
[col
][RCOMP
]);
267 rgba
[col
][GCOMP
] = 0.0;
268 rgba
[col
][BCOMP
] = 0.0;
270 else if (texImage
->_BaseFormat
== GL_RGB
||
271 texImage
->_BaseFormat
== GL_RGBA
) {
272 rgba
[col
][RCOMP
] = linear_to_nonlinear(rgba
[col
][RCOMP
]);
273 rgba
[col
][GCOMP
] = linear_to_nonlinear(rgba
[col
][GCOMP
]);
274 rgba
[col
][BCOMP
] = linear_to_nonlinear(rgba
[col
][BCOMP
]);
277 _mesa_pack_rgba_span_float(ctx
, width
, (GLfloat (*)[4]) rgba
,
279 &ctx
->Pack
, transferOps
);
286 * glGetTexImagefor RGBA, Luminance, etc. pixels.
287 * This is the slow way since we use texture sampling.
290 get_tex_rgba(GLcontext
*ctx
, GLuint dimensions
,
291 GLenum format
, GLenum type
, GLvoid
*pixels
,
292 const struct gl_texture_image
*texImage
)
294 const GLint width
= texImage
->Width
;
295 const GLint height
= texImage
->Height
;
296 const GLint depth
= texImage
->Depth
;
297 /* Normally, no pixel transfer ops are performed during glGetTexImage.
298 * The only possible exception is component clamping to [0,1].
300 GLbitfield transferOps
= 0x0;
303 for (img
= 0; img
< depth
; img
++) {
304 for (row
= 0; row
< height
; row
++) {
305 void *dest
= _mesa_image_address(dimensions
, &ctx
->Pack
, pixels
,
306 width
, height
, format
, type
,
308 GLfloat rgba
[MAX_WIDTH
][4];
310 GLenum dataType
= _mesa_get_format_datatype(texImage
->TexFormat
);
312 /* clamp does not apply to GetTexImage (final conversion)?
313 * Looks like we need clamp though when going from format
314 * containing negative values to unsigned format.
316 if (format
== GL_LUMINANCE
|| format
== GL_LUMINANCE_ALPHA
) {
317 transferOps
|= IMAGE_CLAMP_BIT
;
319 else if (!type_with_negative_values(type
) &&
320 (dataType
== GL_FLOAT
||
321 dataType
== GL_SIGNED_NORMALIZED
)) {
322 transferOps
|= IMAGE_CLAMP_BIT
;
325 for (col
= 0; col
< width
; col
++) {
326 texImage
->FetchTexelf(texImage
, col
, row
, img
, rgba
[col
]);
327 if (texImage
->_BaseFormat
== GL_ALPHA
) {
328 rgba
[col
][RCOMP
] = 0.0F
;
329 rgba
[col
][GCOMP
] = 0.0F
;
330 rgba
[col
][BCOMP
] = 0.0F
;
332 else if (texImage
->_BaseFormat
== GL_LUMINANCE
) {
333 rgba
[col
][GCOMP
] = 0.0F
;
334 rgba
[col
][BCOMP
] = 0.0F
;
335 rgba
[col
][ACOMP
] = 1.0F
;
337 else if (texImage
->_BaseFormat
== GL_LUMINANCE_ALPHA
) {
338 rgba
[col
][GCOMP
] = 0.0F
;
339 rgba
[col
][BCOMP
] = 0.0F
;
341 else if (texImage
->_BaseFormat
== GL_INTENSITY
) {
342 rgba
[col
][GCOMP
] = 0.0F
;
343 rgba
[col
][BCOMP
] = 0.0F
;
344 rgba
[col
][ACOMP
] = 1.0F
;
347 _mesa_pack_rgba_span_float(ctx
, width
, (GLfloat (*)[4]) rgba
,
349 &ctx
->Pack
, transferOps
);
356 * Try to do glGetTexImage() with simple memcpy().
357 * \return GL_TRUE if done, GL_FALSE otherwise
360 get_tex_memcpy(GLcontext
*ctx
, GLenum format
, GLenum type
, GLvoid
*pixels
,
361 const struct gl_texture_object
*texObj
,
362 const struct gl_texture_image
*texImage
)
364 GLboolean memCopy
= GL_FALSE
;
366 /* Texture image should have been mapped already */
367 assert(texImage
->Data
);
370 * Check if the src/dst formats are compatible.
371 * Also note that GL's pixel transfer ops don't apply to glGetTexImage()
372 * so we don't have to worry about those.
373 * XXX more format combinations could be supported here.
375 if ((texObj
->Target
== GL_TEXTURE_1D
||
376 texObj
->Target
== GL_TEXTURE_2D
||
377 texObj
->Target
== GL_TEXTURE_RECTANGLE
||
378 (texObj
->Target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
379 texObj
->Target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
))) {
380 if (texImage
->TexFormat
== MESA_FORMAT_ARGB8888
&&
382 type
== GL_UNSIGNED_BYTE
&&
383 !ctx
->Pack
.SwapBytes
&&
384 _mesa_little_endian()) {
387 else if (texImage
->TexFormat
== MESA_FORMAT_AL88
&&
388 format
== GL_LUMINANCE_ALPHA
&&
389 type
== GL_UNSIGNED_BYTE
&&
390 !ctx
->Pack
.SwapBytes
&&
391 _mesa_little_endian()) {
394 else if (texImage
->TexFormat
== MESA_FORMAT_L8
&&
395 format
== GL_LUMINANCE
&&
396 type
== GL_UNSIGNED_BYTE
) {
399 else if (texImage
->TexFormat
== MESA_FORMAT_A8
&&
400 format
== GL_ALPHA
&&
401 type
== GL_UNSIGNED_BYTE
) {
407 const GLuint bpp
= _mesa_get_format_bytes(texImage
->TexFormat
);
408 const GLuint bytesPerRow
= texImage
->Width
* bpp
;
410 _mesa_image_address2d(&ctx
->Pack
, pixels
, texImage
->Width
,
411 texImage
->Height
, format
, type
, 0, 0);
412 const GLint dstRowStride
=
413 _mesa_image_row_stride(&ctx
->Pack
, texImage
->Width
, format
, type
);
414 const GLubyte
*src
= texImage
->Data
;
415 const GLint srcRowStride
= texImage
->RowStride
* bpp
;
418 if (bytesPerRow
== dstRowStride
&& bytesPerRow
== srcRowStride
) {
419 memcpy(dst
, src
, bytesPerRow
* texImage
->Height
);
422 for (row
= 0; row
< texImage
->Height
; row
++) {
423 memcpy(dst
, src
, bytesPerRow
);
435 * This is the software fallback for Driver.GetTexImage().
436 * All error checking will have been done before this routine is called.
437 * The texture image must be mapped.
440 _mesa_get_teximage(GLcontext
*ctx
, GLenum target
, GLint level
,
441 GLenum format
, GLenum type
, GLvoid
*pixels
,
442 struct gl_texture_object
*texObj
,
443 struct gl_texture_image
*texImage
)
447 /* If we get here, the texture image should be mapped */
448 assert(texImage
->Data
);
461 if (_mesa_is_bufferobj(ctx
->Pack
.BufferObj
)) {
462 /* Packing texture image into a PBO.
463 * Map the (potentially) VRAM-based buffer into our process space so
464 * we can write into it with the code below.
465 * A hardware driver might use a sophisticated blit to move the
466 * texture data to the PBO if the PBO is in VRAM along with the texture.
468 GLubyte
*buf
= (GLubyte
*)
469 ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_PACK_BUFFER_EXT
,
470 GL_WRITE_ONLY_ARB
, ctx
->Pack
.BufferObj
);
472 /* out of memory or other unexpected error */
473 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glGetTexImage(map PBO failed)");
476 /* <pixels> was an offset into the PBO.
477 * Now make it a real, client-side pointer inside the mapped region.
479 pixels
= ADD_POINTERS(buf
, pixels
);
482 if (get_tex_memcpy(ctx
, format
, type
, pixels
, texObj
, texImage
)) {
485 else if (format
== GL_COLOR_INDEX
) {
486 get_tex_color_index(ctx
, dimensions
, format
, type
, pixels
, texImage
);
488 else if (format
== GL_DEPTH_COMPONENT
) {
489 get_tex_depth(ctx
, dimensions
, format
, type
, pixels
, texImage
);
491 else if (format
== GL_DEPTH_STENCIL_EXT
) {
492 get_tex_depth_stencil(ctx
, dimensions
, format
, type
, pixels
, texImage
);
494 else if (format
== GL_YCBCR_MESA
) {
495 get_tex_ycbcr(ctx
, dimensions
, format
, type
, pixels
, texImage
);
497 else if (_mesa_get_format_color_encoding(texImage
->TexFormat
) == GL_SRGB
) {
498 get_tex_srgb(ctx
, dimensions
, format
, type
, pixels
, texImage
);
501 get_tex_rgba(ctx
, dimensions
, format
, type
, pixels
, texImage
);
504 if (_mesa_is_bufferobj(ctx
->Pack
.BufferObj
)) {
505 ctx
->Driver
.UnmapBuffer(ctx
, GL_PIXEL_PACK_BUFFER_EXT
,
506 ctx
->Pack
.BufferObj
);
513 * This is the software fallback for Driver.GetCompressedTexImage().
514 * All error checking will have been done before this routine is called.
517 _mesa_get_compressed_teximage(GLcontext
*ctx
, GLenum target
, GLint level
,
519 struct gl_texture_object
*texObj
,
520 struct gl_texture_image
*texImage
)
522 const GLuint row_stride
= _mesa_format_row_stride(texImage
->TexFormat
,
524 const GLuint row_stride_stored
= _mesa_format_row_stride(texImage
->TexFormat
,
525 texImage
->RowStride
);
528 if (_mesa_is_bufferobj(ctx
->Pack
.BufferObj
)) {
529 /* pack texture image into a PBO */
530 GLubyte
*buf
= (GLubyte
*)
531 ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_PACK_BUFFER_EXT
,
532 GL_WRITE_ONLY_ARB
, ctx
->Pack
.BufferObj
);
534 /* out of memory or other unexpected error */
535 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
536 "glGetCompresssedTexImage(map PBO failed)");
539 img
= ADD_POINTERS(buf
, img
);
542 /* no pixelstore or pixel transfer, but respect stride */
544 if (row_stride
== row_stride_stored
) {
545 const GLuint size
= _mesa_format_image_size(texImage
->TexFormat
,
549 _mesa_memcpy(img
, texImage
->Data
, size
);
553 _mesa_get_format_block_size(texImage
->TexFormat
, &bw
, &bh
);
554 for (i
= 0; i
< (texImage
->Height
+ bh
- 1) / bh
; i
++) {
555 memcpy((GLubyte
*)img
+ i
* row_stride
,
556 (GLubyte
*)texImage
->Data
+ i
* row_stride_stored
, row_stride
);
560 if (_mesa_is_bufferobj(ctx
->Pack
.BufferObj
)) {
561 ctx
->Driver
.UnmapBuffer(ctx
, GL_PIXEL_PACK_BUFFER_EXT
,
562 ctx
->Pack
.BufferObj
);
569 * Do error checking for a glGetTexImage() call.
570 * \return GL_TRUE if any error, GL_FALSE if no errors.
573 getteximage_error_check(GLcontext
*ctx
, GLenum target
, GLint level
,
574 GLenum format
, GLenum type
, GLvoid
*pixels
)
576 struct gl_texture_object
*texObj
;
577 struct gl_texture_image
*texImage
;
578 const GLuint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
581 if (maxLevels
== 0) {
582 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(target=0x%x)", target
);
586 if (level
< 0 || level
>= maxLevels
) {
587 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexImage(level)" );
591 if (_mesa_sizeof_packed_type(type
) <= 0) {
592 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(type)" );
596 if (_mesa_components_in_format(format
) <= 0 ||
597 format
== GL_STENCIL_INDEX
) {
598 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)" );
602 if (!ctx
->Extensions
.EXT_paletted_texture
&& _mesa_is_index_format(format
)) {
603 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
607 if (!ctx
->Extensions
.ARB_depth_texture
&& _mesa_is_depth_format(format
)) {
608 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
612 if (!ctx
->Extensions
.MESA_ycbcr_texture
&& _mesa_is_ycbcr_format(format
)) {
613 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
617 if (!ctx
->Extensions
.EXT_packed_depth_stencil
618 && _mesa_is_depthstencil_format(format
)) {
619 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
623 if (!ctx
->Extensions
.ATI_envmap_bumpmap
624 && _mesa_is_dudv_format(format
)) {
625 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
629 texObj
= _mesa_get_current_tex_object(ctx
, target
);
631 if (!texObj
|| _mesa_is_proxy_texture(target
)) {
632 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(target)");
636 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
642 baseFormat
= _mesa_get_format_base_format(texImage
->TexFormat
);
644 /* Make sure the requested image format is compatible with the
645 * texture's format. Note that a color index texture can be converted
646 * to RGBA so that combo is allowed.
648 if (_mesa_is_color_format(format
)
649 && !_mesa_is_color_format(baseFormat
)
650 && !_mesa_is_index_format(baseFormat
)) {
651 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
654 else if (_mesa_is_index_format(format
)
655 && !_mesa_is_index_format(baseFormat
)) {
656 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
659 else if (_mesa_is_depth_format(format
)
660 && !_mesa_is_depth_format(baseFormat
)
661 && !_mesa_is_depthstencil_format(baseFormat
)) {
662 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
665 else if (_mesa_is_ycbcr_format(format
)
666 && !_mesa_is_ycbcr_format(baseFormat
)) {
667 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
670 else if (_mesa_is_depthstencil_format(format
)
671 && !_mesa_is_depthstencil_format(baseFormat
)) {
672 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
675 else if (_mesa_is_dudv_format(format
)
676 && !_mesa_is_dudv_format(baseFormat
)) {
677 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
681 if (_mesa_is_bufferobj(ctx
->Pack
.BufferObj
)) {
682 /* packing texture image into a PBO */
683 const GLuint dimensions
= (target
== GL_TEXTURE_3D
) ? 3 : 2;
684 if (!_mesa_validate_pbo_access(dimensions
, &ctx
->Pack
, texImage
->Width
,
685 texImage
->Height
, texImage
->Depth
,
686 format
, type
, pixels
)) {
687 _mesa_error(ctx
, GL_INVALID_OPERATION
,
688 "glGetTexImage(out of bounds PBO write)");
692 /* PBO should not be mapped */
693 if (_mesa_bufferobj_mapped(ctx
->Pack
.BufferObj
)) {
694 _mesa_error(ctx
, GL_INVALID_OPERATION
,
695 "glGetTexImage(PBO is mapped)");
706 * Get texture image. Called by glGetTexImage.
708 * \param target texture target.
709 * \param level image level.
710 * \param format pixel data format for returned image.
711 * \param type pixel data type for returned image.
712 * \param pixels returned pixel data.
715 _mesa_GetTexImage( GLenum target
, GLint level
, GLenum format
,
716 GLenum type
, GLvoid
*pixels
)
718 struct gl_texture_object
*texObj
;
719 struct gl_texture_image
*texImage
;
720 GET_CURRENT_CONTEXT(ctx
);
721 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
723 if (getteximage_error_check(ctx
, target
, level
, format
, type
, pixels
)) {
727 if (!_mesa_is_bufferobj(ctx
->Pack
.BufferObj
) && !pixels
) {
728 /* not an error, do nothing */
732 texObj
= _mesa_get_current_tex_object(ctx
, target
);
733 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
735 if (MESA_VERBOSE
& (VERBOSE_API
| VERBOSE_TEXTURE
)) {
736 _mesa_debug(ctx
, "glGetTexImage(tex %u) format = %s, w=%d, h=%d,"
737 " dstFmt=0x%x, dstType=0x%x\n",
739 _mesa_get_format_name(texImage
->TexFormat
),
740 texImage
->Width
, texImage
->Height
,
744 _mesa_lock_texture(ctx
, texObj
);
746 ctx
->Driver
.GetTexImage(ctx
, target
, level
, format
, type
, pixels
,
749 _mesa_unlock_texture(ctx
, texObj
);
755 * Do error checking for a glGetCompressedTexImage() call.
756 * \return GL_TRUE if any error, GL_FALSE if no errors.
759 getcompressedteximage_error_check(GLcontext
*ctx
, GLenum target
, GLint level
,
762 struct gl_texture_object
*texObj
;
763 struct gl_texture_image
*texImage
;
764 const GLuint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
766 if (maxLevels
== 0) {
767 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImage(target=0x%x)",
772 if (level
< 0 || level
>= maxLevels
) {
773 _mesa_error(ctx
, GL_INVALID_VALUE
,
774 "glGetCompressedTexImageARB(bad level = %d)", level
);
778 if (_mesa_is_proxy_texture(target
)) {
779 _mesa_error(ctx
, GL_INVALID_ENUM
,
780 "glGetCompressedTexImageARB(bad target = %s)",
781 _mesa_lookup_enum_by_nr(target
));
785 texObj
= _mesa_get_current_tex_object(ctx
, target
);
787 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB(target)");
791 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
794 /* probably invalid mipmap level */
795 _mesa_error(ctx
, GL_INVALID_VALUE
,
796 "glGetCompressedTexImageARB(level)");
800 if (!_mesa_is_format_compressed(texImage
->TexFormat
)) {
801 _mesa_error(ctx
, GL_INVALID_OPERATION
,
802 "glGetCompressedTexImageARB(texture is not compressed)");
806 if (_mesa_is_bufferobj(ctx
->Pack
.BufferObj
)) {
807 GLuint compressedSize
;
809 /* make sure PBO is not mapped */
810 if (_mesa_bufferobj_mapped(ctx
->Pack
.BufferObj
)) {
811 _mesa_error(ctx
, GL_INVALID_OPERATION
,
812 "glGetCompressedTexImage(PBO is mapped)");
816 compressedSize
= _mesa_format_image_size(texImage
->TexFormat
,
821 /* do bounds checking on PBO write */
822 if ((const GLubyte
*) img
+ compressedSize
>
823 (const GLubyte
*) ctx
->Pack
.BufferObj
->Size
) {
824 _mesa_error(ctx
, GL_INVALID_OPERATION
,
825 "glGetCompressedTexImage(out of bounds PBO write)");
835 _mesa_GetCompressedTexImageARB(GLenum target
, GLint level
, GLvoid
*img
)
837 struct gl_texture_object
*texObj
;
838 struct gl_texture_image
*texImage
;
839 GET_CURRENT_CONTEXT(ctx
);
840 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
842 if (getcompressedteximage_error_check(ctx
, target
, level
, img
)) {
846 if (_mesa_is_bufferobj(ctx
->Pack
.BufferObj
) && !img
) {
847 /* not an error, do nothing */
851 texObj
= _mesa_get_current_tex_object(ctx
, target
);
852 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
854 if (MESA_VERBOSE
& (VERBOSE_API
| VERBOSE_TEXTURE
)) {
856 "glGetCompressedTexImage(tex %u) format = %s, w=%d, h=%d\n",
858 _mesa_get_format_name(texImage
->TexFormat
),
859 texImage
->Width
, texImage
->Height
);
862 _mesa_lock_texture(ctx
, texObj
);
864 ctx
->Driver
.GetCompressedTexImage(ctx
, target
, level
, img
,
867 _mesa_unlock_texture(ctx
, texObj
);