i965: fix bugs in projective texture coordinates
[mesa.git] / src / mesa / drivers / dri / intel / 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 "main/mtypes.h"
30 #include "main/texobj.h"
31 #include "main/texstore.h"
32 #include "main/texcompress.h"
33 #include "main/enums.h"
34
35 #include "intel_context.h"
36 #include "intel_tex.h"
37 #include "intel_mipmap_tree.h"
38
39 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
40
41 static void
42 intelTexSubimage(GLcontext * ctx,
43 GLint dims,
44 GLenum target, GLint level,
45 GLint xoffset, GLint yoffset, GLint zoffset,
46 GLint width, GLint height, GLint depth,
47 GLenum format, GLenum type, const void *pixels,
48 const struct gl_pixelstore_attrib *packing,
49 struct gl_texture_object *texObj,
50 struct gl_texture_image *texImage)
51 {
52 struct intel_context *intel = intel_context(ctx);
53 struct intel_texture_image *intelImage = intel_texture_image(texImage);
54 GLuint dstRowStride = 0;
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 LOCK_HARDWARE(intel);
69
70 /* Map buffer if necessary. Need to lock to prevent other contexts
71 * from uploading the buffer under us.
72 */
73 if (intelImage->mt)
74 texImage->Data = intel_miptree_image_map(intel,
75 intelImage->mt,
76 intelImage->face,
77 intelImage->level,
78 &dstRowStride,
79 texImage->ImageOffsets);
80 else {
81 if (texImage->IsCompressed) {
82 dstRowStride =
83 _mesa_compressed_row_stride(texImage->TexFormat->MesaFormat, width);
84 assert(dims != 3);
85 }
86 else {
87 dstRowStride = texImage->RowStride * texImage->TexFormat->TexelBytes;
88 }
89 }
90
91 assert(dstRowStride);
92
93 if (!texImage->TexFormat->StoreImage(ctx, dims, texImage->_BaseFormat,
94 texImage->TexFormat,
95 texImage->Data,
96 xoffset, yoffset, zoffset,
97 dstRowStride,
98 texImage->ImageOffsets,
99 width, height, depth,
100 format, type, pixels, packing)) {
101 _mesa_error(ctx, GL_OUT_OF_MEMORY, "intelTexSubImage");
102 }
103
104 /* GL_SGIS_generate_mipmap */
105 if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
106 intel_generate_mipmap(ctx, target, texObj);
107 }
108
109 _mesa_unmap_teximage_pbo(ctx, packing);
110
111 if (intelImage->mt) {
112 intel_miptree_image_unmap(intel, intelImage->mt);
113 texImage->Data = NULL;
114 }
115
116 UNLOCK_HARDWARE(intel);
117 }
118
119
120
121
122
123 void
124 intelTexSubImage3D(GLcontext * ctx,
125 GLenum target,
126 GLint level,
127 GLint xoffset, GLint yoffset, GLint zoffset,
128 GLsizei width, GLsizei height, GLsizei depth,
129 GLenum format, GLenum type,
130 const GLvoid * pixels,
131 const struct gl_pixelstore_attrib *packing,
132 struct gl_texture_object *texObj,
133 struct gl_texture_image *texImage)
134 {
135
136 intelTexSubimage(ctx, 3,
137 target, level,
138 xoffset, yoffset, zoffset,
139 width, height, depth,
140 format, type, pixels, packing, texObj, texImage);
141
142 }
143
144
145
146 void
147 intelTexSubImage2D(GLcontext * ctx,
148 GLenum target,
149 GLint level,
150 GLint xoffset, GLint yoffset,
151 GLsizei width, GLsizei height,
152 GLenum format, GLenum type,
153 const GLvoid * pixels,
154 const struct gl_pixelstore_attrib *packing,
155 struct gl_texture_object *texObj,
156 struct gl_texture_image *texImage)
157 {
158
159 intelTexSubimage(ctx, 2,
160 target, level,
161 xoffset, yoffset, 0,
162 width, height, 1,
163 format, type, pixels, packing, texObj, texImage);
164
165 }
166
167
168 void
169 intelTexSubImage1D(GLcontext * ctx,
170 GLenum target,
171 GLint level,
172 GLint xoffset,
173 GLsizei width,
174 GLenum format, GLenum type,
175 const GLvoid * pixels,
176 const struct gl_pixelstore_attrib *packing,
177 struct gl_texture_object *texObj,
178 struct gl_texture_image *texImage)
179 {
180 intelTexSubimage(ctx, 1,
181 target, level,
182 xoffset, 0, 0,
183 width, 1, 1,
184 format, type, pixels, packing, texObj, texImage);
185
186 }
187
188 void
189 intelCompressedTexSubImage2D(GLcontext * ctx,
190 GLenum target,
191 GLint level,
192 GLint xoffset, GLint yoffset,
193 GLsizei width, GLsizei height,
194 GLenum format, GLsizei imageSize,
195 const GLvoid * pixels,
196 struct gl_texture_object *texObj,
197 struct gl_texture_image *texImage)
198 {
199 fprintf(stderr, "stubbed CompressedTexSubImage2D: %dx%d@%dx%d\n",
200 width, height, xoffset, yoffset);
201 }