Merge branch '7.8'
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_tex_getimage.c
1 /*
2 * Copyright (C) 2009 Maciej Cencora.
3 * Copyright (C) 2008 Nicolai Haehnle.
4 * Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
5 *
6 * The Weather Channel (TM) funded Tungsten Graphics to develop the
7 * initial release of the Radeon 8500 driver under the XFree86 license.
8 * This notice must be preserved.
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining
11 * a copy of this software and associated documentation files (the
12 * "Software"), to deal in the Software without restriction, including
13 * without limitation the rights to use, copy, modify, merge, publish,
14 * distribute, sublicense, and/or sell copies of the Software, and to
15 * permit persons to whom the Software is furnished to do so, subject to
16 * the following conditions:
17 *
18 * The above copyright notice and this permission notice (including the
19 * next paragraph) shall be included in all copies or substantial
20 * portions of the Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
26 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 *
30 */
31
32 #include "radeon_common_context.h"
33 #include "radeon_texture.h"
34
35 #include "main/texgetimage.h"
36
37 /**
38 * Need to map texture image into memory before copying image data,
39 * then unmap it.
40 */
41 static void
42 radeon_get_tex_image(GLcontext * ctx, GLenum target, GLint level,
43 GLenum format, GLenum type, GLvoid * pixels,
44 struct gl_texture_object *texObj,
45 struct gl_texture_image *texImage, int compressed)
46 {
47 radeon_texture_image *image = get_radeon_texture_image(texImage);
48
49 radeon_print(RADEON_TEXTURE, RADEON_NORMAL,
50 "%s(%p, tex %p, image %p) compressed %d.\n",
51 __func__, ctx, texObj, image, compressed);
52
53 if (image->mt) {
54 /* Map the texture image read-only */
55 radeon_teximage_map(image, GL_FALSE);
56 } else {
57 /* Image hasn't been uploaded to a miptree yet */
58 assert(image->base.Data);
59 }
60
61 if (compressed) {
62 /* FIXME: this can't work for small textures (mips) which
63 use different hw stride */
64 _mesa_get_compressed_teximage(ctx, target, level, pixels,
65 texObj, texImage);
66 } else {
67 _mesa_get_teximage(ctx, target, level, format, type, pixels,
68 texObj, texImage);
69 }
70
71 if (image->mt) {
72 radeon_teximage_unmap(image);
73 }
74 }
75
76 void
77 radeonGetTexImage(GLcontext * ctx, GLenum target, GLint level,
78 GLenum format, GLenum type, GLvoid * pixels,
79 struct gl_texture_object *texObj,
80 struct gl_texture_image *texImage)
81 {
82 radeon_get_tex_image(ctx, target, level, format, type, pixels,
83 texObj, texImage, 0);
84 }
85
86 void
87 radeonGetCompressedTexImage(GLcontext *ctx, GLenum target, GLint level,
88 GLvoid *pixels,
89 struct gl_texture_object *texObj,
90 struct gl_texture_image *texImage)
91 {
92 radeon_get_tex_image(ctx, target, level, 0, 0, pixels,
93 texObj, texImage, 1);
94 }