e98e9bbfc4678eadbf66709f9305d0a6a937f340
[mesa.git] / src / mesa / drivers / dri / i965 / intel_tex.c
1 /**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #include "mtypes.h"
29 #include "image.h"
30 #include "texstore.h"
31 #include "texformat.h"
32 #include "teximage.h"
33 #include "texobj.h"
34 #include "swrast/swrast.h"
35
36
37 #include "intel_context.h"
38 #include "intel_tex.h"
39 #include "intel_mipmap_tree.h"
40
41
42 static GLuint target_to_face( GLenum target )
43 {
44 switch (target) {
45 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
46 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
47 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
48 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
49 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
50 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
51 return ((GLuint) target -
52 (GLuint) GL_TEXTURE_CUBE_MAP_POSITIVE_X);
53 default:
54 return 0;
55 }
56 }
57
58 static void intelTexImage1D( GLcontext *ctx, GLenum target, GLint level,
59 GLint internalFormat,
60 GLint width, GLint border,
61 GLenum format, GLenum type, const GLvoid *pixels,
62 const struct gl_pixelstore_attrib *packing,
63 struct gl_texture_object *texObj,
64 struct gl_texture_image *texImage )
65 {
66 struct intel_texture_object *intelObj = intel_texture_object(texObj);
67
68 _mesa_store_teximage1d( ctx, target, level, internalFormat,
69 width, border, format, type,
70 pixels, packing, texObj, texImage );
71
72 intelObj->dirty_images[0] |= (1 << level);
73 intelObj->dirty |= 1;
74 }
75
76 static void intelTexSubImage1D( GLcontext *ctx,
77 GLenum target,
78 GLint level,
79 GLint xoffset,
80 GLsizei width,
81 GLenum format, GLenum type,
82 const GLvoid *pixels,
83 const struct gl_pixelstore_attrib *packing,
84 struct gl_texture_object *texObj,
85 struct gl_texture_image *texImage )
86 {
87 struct intel_texture_object *intelObj = intel_texture_object(texObj);
88
89 _mesa_store_texsubimage1d(ctx, target, level, xoffset, width,
90 format, type, pixels, packing, texObj,
91 texImage);
92
93 intelObj->dirty_images[0] |= (1 << level);
94 intelObj->dirty |= 1;
95 }
96
97
98 /* Handles 2D, CUBE, RECT:
99 */
100 static void intelTexImage2D( GLcontext *ctx, GLenum target, GLint level,
101 GLint internalFormat,
102 GLint width, GLint height, GLint border,
103 GLenum format, GLenum type, const GLvoid *pixels,
104 const struct gl_pixelstore_attrib *packing,
105 struct gl_texture_object *texObj,
106 struct gl_texture_image *texImage )
107 {
108 struct intel_texture_object *intelObj = intel_texture_object(texObj);
109 GLuint face = target_to_face(target);
110
111 _mesa_store_teximage2d( ctx, target, level, internalFormat,
112 width, height, border, format, type,
113 pixels, packing, texObj, texImage );
114
115 intelObj->dirty_images[face] |= (1 << level);
116 intelObj->dirty |= 1 << face;
117 }
118
119 static void intelTexSubImage2D( GLcontext *ctx,
120 GLenum target,
121 GLint level,
122 GLint xoffset, GLint yoffset,
123 GLsizei width, GLsizei height,
124 GLenum format, GLenum type,
125 const GLvoid *pixels,
126 const struct gl_pixelstore_attrib *packing,
127 struct gl_texture_object *texObj,
128 struct gl_texture_image *texImage )
129 {
130 struct intel_texture_object *intelObj = intel_texture_object(texObj);
131 GLuint face = target_to_face(target);
132
133 _mesa_store_texsubimage2d(ctx, target, level, xoffset, yoffset, width,
134 height, format, type, pixels, packing, texObj,
135 texImage);
136
137 intelObj->dirty_images[face] |= (1 << level);
138 intelObj->dirty |= 1 << face;
139 }
140
141 static void intelCompressedTexImage2D( GLcontext *ctx, GLenum target, GLint level,
142 GLint internalFormat,
143 GLint width, GLint height, GLint border,
144 GLsizei imageSize, const GLvoid *data,
145 struct gl_texture_object *texObj,
146 struct gl_texture_image *texImage )
147 {
148 struct intel_texture_object *intelObj = intel_texture_object(texObj);
149 GLuint face = target_to_face(target);
150
151 _mesa_store_compressed_teximage2d(ctx, target, level, internalFormat, width,
152 height, border, imageSize, data, texObj, texImage);
153
154 intelObj->dirty_images[face] |= (1 << level);
155 intelObj->dirty |= 1 << face;
156 }
157
158
159 static void intelCompressedTexSubImage2D( GLcontext *ctx, GLenum target, GLint level,
160 GLint xoffset, GLint yoffset,
161 GLsizei width, GLsizei height,
162 GLenum format,
163 GLsizei imageSize, const GLvoid *data,
164 struct gl_texture_object *texObj,
165 struct gl_texture_image *texImage )
166 {
167 struct intel_texture_object *intelObj = intel_texture_object(texObj);
168 GLuint face = target_to_face(target);
169
170 _mesa_store_compressed_texsubimage2d(ctx, target, level, xoffset, yoffset, width,
171 height, format, imageSize, data, texObj, texImage);
172
173 intelObj->dirty_images[face] |= (1 << level);
174 intelObj->dirty |= 1 << face;
175 }
176
177
178 static void intelTexImage3D( GLcontext *ctx, GLenum target, GLint level,
179 GLint internalFormat,
180 GLint width, GLint height, GLint depth,
181 GLint border,
182 GLenum format, GLenum type, const GLvoid *pixels,
183 const struct gl_pixelstore_attrib *packing,
184 struct gl_texture_object *texObj,
185 struct gl_texture_image *texImage )
186 {
187 struct intel_texture_object *intelObj = intel_texture_object(texObj);
188
189 _mesa_store_teximage3d(ctx, target, level, internalFormat,
190 width, height, depth, border,
191 format, type, pixels,
192 &ctx->Unpack, texObj, texImage);
193
194 intelObj->dirty_images[0] |= (1 << level);
195 intelObj->dirty |= 1 << 0;
196 }
197
198
199 static void
200 intelTexSubImage3D( GLcontext *ctx, GLenum target, GLint level,
201 GLint xoffset, GLint yoffset, GLint zoffset,
202 GLsizei width, GLsizei height, GLsizei depth,
203 GLenum format, GLenum type,
204 const GLvoid *pixels,
205 const struct gl_pixelstore_attrib *packing,
206 struct gl_texture_object *texObj,
207 struct gl_texture_image *texImage )
208 {
209 struct intel_texture_object *intelObj = intel_texture_object(texObj);
210
211 _mesa_store_texsubimage3d(ctx, target, level, xoffset, yoffset, zoffset,
212 width, height, depth,
213 format, type, pixels, packing, texObj, texImage);
214
215 intelObj->dirty_images[0] |= (1 << level);
216 intelObj->dirty |= 1 << 0;
217 }
218
219
220
221
222 static struct gl_texture_object *intelNewTextureObject( GLcontext *ctx,
223 GLuint name,
224 GLenum target )
225 {
226 struct intel_texture_object *obj = CALLOC_STRUCT(intel_texture_object);
227
228 _mesa_initialize_texture_object(&obj->base, name, target);
229
230 return &obj->base;
231 }
232
233 static GLboolean intelIsTextureResident(GLcontext *ctx,
234 struct gl_texture_object *texObj)
235 {
236 #if 0
237 struct intel_context *intel = intel_context(ctx);
238 struct intel_texture_object *intelObj = intel_texture_object(texObj);
239
240 return
241 intelObj->mt &&
242 intelObj->mt->region &&
243 intel_is_region_resident(intel, intelObj->mt->region);
244 #endif
245 return 1;
246 }
247
248
249
250 static void intelTexParameter( GLcontext *ctx,
251 GLenum target,
252 struct gl_texture_object *texObj,
253 GLenum pname,
254 const GLfloat *params )
255 {
256 struct intel_texture_object *intelObj = intel_texture_object(texObj);
257
258 switch (pname) {
259 /* Anything which can affect the calculation of firstLevel and
260 * lastLevel, as changes to these may invalidate the miptree.
261 */
262 case GL_TEXTURE_MIN_FILTER:
263 case GL_TEXTURE_MAG_FILTER:
264 case GL_TEXTURE_BASE_LEVEL:
265 case GL_TEXTURE_MAX_LEVEL:
266 case GL_TEXTURE_MIN_LOD:
267 case GL_TEXTURE_MAX_LOD:
268 intelObj->dirty |= 1;
269 break;
270
271 default:
272 break;
273 }
274 }
275
276
277 static void
278 intel_delete_texture_object( GLcontext *ctx, struct gl_texture_object *texObj )
279 {
280 struct intel_context *intel = intel_context(ctx);
281 struct intel_texture_object *intelObj = intel_texture_object(texObj);
282
283 if (intelObj->mt)
284 intel_miptree_destroy(intel, intelObj->mt);
285
286 _mesa_delete_texture_object( ctx, texObj );
287 }
288
289 void intelInitTextureFuncs( struct dd_function_table *functions )
290 {
291 functions->NewTextureObject = intelNewTextureObject;
292 functions->ChooseTextureFormat = intelChooseTextureFormat;
293 functions->TexImage1D = intelTexImage1D;
294 functions->TexImage2D = intelTexImage2D;
295 functions->TexImage3D = intelTexImage3D;
296 functions->TexSubImage1D = intelTexSubImage1D;
297 functions->TexSubImage2D = intelTexSubImage2D;
298 functions->TexSubImage3D = intelTexSubImage3D;
299 functions->CopyTexImage1D = _swrast_copy_teximage1d;
300 functions->CopyTexImage2D = _swrast_copy_teximage2d;
301 functions->CopyTexSubImage1D = _swrast_copy_texsubimage1d;
302 functions->CopyTexSubImage2D = _swrast_copy_texsubimage2d;
303 functions->CopyTexSubImage3D = _swrast_copy_texsubimage3d;
304 functions->DeleteTexture = intel_delete_texture_object;
305 functions->UpdateTexturePalette = NULL;
306 functions->IsTextureResident = intelIsTextureResident;
307 functions->TestProxyTexImage = _mesa_test_proxy_teximage;
308 functions->CompressedTexImage2D = intelCompressedTexImage2D;
309 functions->CompressedTexSubImage2D = intelCompressedTexSubImage2D;
310 functions->TexParameter = intelTexParameter;
311 }
312
313
314
315
316