- const GLint width = texImage->Width;
- const GLint height = texImage->Height;
- const GLint depth = texImage->Depth;
- const GLenum dataType = _mesa_get_format_datatype(texImage->TexFormat);
- /* Normally, no pixel transfer ops are performed during glGetTexImage.
- * The only possible exception is component clamping to [0,1].
- */
- GLbitfield transferOps = 0x0;
- GLint img, row;
- GLfloat (*rgba)[4] = (GLfloat (*)[4]) malloc(4 * width * sizeof(GLfloat));
- const GLboolean is_sampler_srgb_decode =
- _mesa_get_format_color_encoding(texImage->TexFormat) == GL_SRGB &&
- texImage->TexObject->Sampler.sRGBDecode == GL_DECODE_EXT;
+ /* don't want to apply sRGB -> RGB conversion here so override the format */
+ const gl_format texFormat =
+ _mesa_get_srgb_format_linear(texImage->TexFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(texFormat);
+ const GLuint width = texImage->Width;
+ const GLuint height = texImage->Height;
+ const GLuint depth = texImage->Depth;
+ GLfloat *tempImage, *srcRow;
+ GLuint row;
+
+ /* Decompress into temp float buffer, then pack into user buffer */
+ tempImage = malloc(width * height * depth
+ * 4 * sizeof(GLfloat));
+ if (!tempImage) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage()");
+ return;
+ }
+
+ /* Decompress the texture image - results in 'tempImage' */
+ {
+ GLubyte *srcMap;
+ GLint srcRowStride;
+
+ ctx->Driver.MapTextureImage(ctx, texImage, 0,
+ 0, 0, width, height,
+ GL_MAP_READ_BIT,
+ &srcMap, &srcRowStride);
+ if (srcMap) {
+ _mesa_decompress_image(texFormat, width, height,
+ srcMap, srcRowStride, tempImage);
+
+ ctx->Driver.UnmapTextureImage(ctx, texImage, 0);
+ }
+ else {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage");
+ free(tempImage);
+ return;
+ }
+ }
+
+ if (baseFormat == GL_LUMINANCE ||
+ baseFormat == GL_LUMINANCE_ALPHA) {
+ _mesa_rebase_rgba_float(width * height, (GLfloat (*)[4]) tempImage,
+ baseFormat);
+ }
+
+ srcRow = tempImage;
+ for (row = 0; row < height; row++) {
+ void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels,
+ width, height, format, type,
+ 0, row, 0);
+
+ _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) srcRow,
+ format, type, dest, &ctx->Pack, transferOps);
+ srcRow += width * 4;
+ }