blend, logicop changes for intelEmitCopyBlit backported to i915
[mesa.git] / src / mesa / drivers / dri / i915tex / intel_tex_subimage.c
1
2 /**************************************************************************
3 *
4 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
27 **************************************************************************/
28
29 #include "mtypes.h"
30 #include "texobj.h"
31 #include "texstore.h"
32 #include "enums.h"
33
34 #include "intel_context.h"
35 #include "intel_tex.h"
36 #include "intel_mipmap_tree.h"
37
38 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
39
40 static void
41 intelTexSubimage(GLcontext * ctx,
42 GLint dims,
43 GLenum target, GLint level,
44 GLint xoffset, GLint yoffset, GLint zoffset,
45 GLint width, GLint height, GLint depth,
46 GLenum format, GLenum type, const void *pixels,
47 const struct gl_pixelstore_attrib *packing,
48 struct gl_texture_object *texObj,
49 struct gl_texture_image *texImage)
50 {
51 struct intel_context *intel = intel_context(ctx);
52 struct intel_texture_image *intelImage = intel_texture_image(texImage);
53 GLuint dstImageStride;
54 GLuint dstRowStride;
55
56 DBG("%s target %s level %d offset %d,%d %dx%d\n", __FUNCTION__,
57 _mesa_lookup_enum_by_nr(target),
58 level, xoffset, yoffset, width, height);
59
60 intelFlush(ctx);
61
62 pixels =
63 _mesa_validate_pbo_teximage(ctx, dims, width, height, depth, format,
64 type, pixels, packing, "glTexSubImage2D");
65 if (!pixels)
66 return;
67
68 if (intelImage->mt)
69 intel_region_idle(intel->intelScreen, intelImage->mt->region);
70
71 LOCK_HARDWARE(intel);
72
73 /* Map buffer if necessary. Need to lock to prevent other contexts
74 * from uploading the buffer under us.
75 */
76 if (intelImage->mt)
77 texImage->Data = intel_miptree_image_map(intel,
78 intelImage->mt,
79 intelImage->face,
80 intelImage->level,
81 &dstRowStride,
82 &dstImageStride);
83
84 assert(dstRowStride);
85
86 if (!texImage->TexFormat->StoreImage(ctx, dims, texImage->_BaseFormat,
87 texImage->TexFormat,
88 texImage->Data,
89 xoffset, yoffset, zoffset,
90 dstRowStride,
91 texImage->ImageOffsets,
92 width, height, depth,
93 format, type, pixels, packing)) {
94 _mesa_error(ctx, GL_OUT_OF_MEMORY, "intelTexSubImage");
95 }
96
97 #if 0
98 /* GL_SGIS_generate_mipmap */
99 if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
100 _mesa_generate_mipmap(ctx, target,
101 &ctx->Texture.Unit[ctx->Texture.CurrentUnit],
102 texObj);
103 }
104 #endif
105
106 _mesa_unmap_teximage_pbo(ctx, packing);
107
108 if (intelImage->mt) {
109 intel_miptree_image_unmap(intel, intelImage->mt);
110 texImage->Data = NULL;
111 }
112
113 UNLOCK_HARDWARE(intel);
114 }
115
116
117
118
119
120 void
121 intelTexSubImage3D(GLcontext * ctx,
122 GLenum target,
123 GLint level,
124 GLint xoffset, GLint yoffset, GLint zoffset,
125 GLsizei width, GLsizei height, GLsizei depth,
126 GLenum format, GLenum type,
127 const GLvoid * pixels,
128 const struct gl_pixelstore_attrib *packing,
129 struct gl_texture_object *texObj,
130 struct gl_texture_image *texImage)
131 {
132
133 intelTexSubimage(ctx, 3,
134 target, level,
135 xoffset, yoffset, zoffset,
136 width, height, depth,
137 format, type, pixels, packing, texObj, texImage);
138
139 }
140
141
142
143 void
144 intelTexSubImage2D(GLcontext * ctx,
145 GLenum target,
146 GLint level,
147 GLint xoffset, GLint yoffset,
148 GLsizei width, GLsizei height,
149 GLenum format, GLenum type,
150 const GLvoid * pixels,
151 const struct gl_pixelstore_attrib *packing,
152 struct gl_texture_object *texObj,
153 struct gl_texture_image *texImage)
154 {
155
156 intelTexSubimage(ctx, 2,
157 target, level,
158 xoffset, yoffset, 0,
159 width, height, 1,
160 format, type, pixels, packing, texObj, texImage);
161
162 }
163
164
165 void
166 intelTexSubImage1D(GLcontext * ctx,
167 GLenum target,
168 GLint level,
169 GLint xoffset,
170 GLsizei width,
171 GLenum format, GLenum type,
172 const GLvoid * pixels,
173 const struct gl_pixelstore_attrib *packing,
174 struct gl_texture_object *texObj,
175 struct gl_texture_image *texImage)
176 {
177 intelTexSubimage(ctx, 1,
178 target, level,
179 xoffset, 0, 0,
180 width, 1, 1,
181 format, type, pixels, packing, texObj, texImage);
182
183 }