1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
31 #include "texformat.h"
34 #include "swrast/swrast.h"
37 #include "intel_context.h"
38 #include "intel_tex.h"
39 #include "intel_mipmap_tree.h"
42 static GLuint
target_to_face( GLenum 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
);
58 static void intelTexImage1D( GLcontext
*ctx
, GLenum target
, GLint level
,
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
)
66 struct intel_texture_object
*intelObj
= intel_texture_object(texObj
);
68 _mesa_store_teximage1d( ctx
, target
, level
, internalFormat
,
69 width
, border
, format
, type
,
70 pixels
, packing
, texObj
, texImage
);
72 intelObj
->dirty_images
[0] |= (1 << level
);
76 static void intelTexSubImage1D( GLcontext
*ctx
,
81 GLenum format
, GLenum type
,
83 const struct gl_pixelstore_attrib
*packing
,
84 struct gl_texture_object
*texObj
,
85 struct gl_texture_image
*texImage
)
87 struct intel_texture_object
*intelObj
= intel_texture_object(texObj
);
89 _mesa_store_texsubimage1d(ctx
, target
, level
, xoffset
, width
,
90 format
, type
, pixels
, packing
, texObj
,
93 intelObj
->dirty_images
[0] |= (1 << level
);
98 /* Handles 2D, CUBE, RECT:
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
)
108 struct intel_texture_object
*intelObj
= intel_texture_object(texObj
);
109 GLuint face
= target_to_face(target
);
111 _mesa_store_teximage2d( ctx
, target
, level
, internalFormat
,
112 width
, height
, border
, format
, type
,
113 pixels
, packing
, texObj
, texImage
);
115 intelObj
->dirty_images
[face
] |= (1 << level
);
116 intelObj
->dirty
|= 1 << face
;
119 static void intelTexSubImage2D( GLcontext
*ctx
,
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
)
130 struct intel_texture_object
*intelObj
= intel_texture_object(texObj
);
131 GLuint face
= target_to_face(target
);
133 _mesa_store_texsubimage2d(ctx
, target
, level
, xoffset
, yoffset
, width
,
134 height
, format
, type
, pixels
, packing
, texObj
,
137 intelObj
->dirty_images
[face
] |= (1 << level
);
138 intelObj
->dirty
|= 1 << face
;
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
)
148 struct intel_texture_object
*intelObj
= intel_texture_object(texObj
);
149 GLuint face
= target_to_face(target
);
151 _mesa_store_compressed_teximage2d(ctx
, target
, level
, internalFormat
, width
,
152 height
, border
, imageSize
, data
, texObj
, texImage
);
154 intelObj
->dirty_images
[face
] |= (1 << level
);
155 intelObj
->dirty
|= 1 << face
;
159 static void intelCompressedTexSubImage2D( GLcontext
*ctx
, GLenum target
, GLint level
,
160 GLint xoffset
, GLint yoffset
,
161 GLsizei width
, GLsizei height
,
163 GLsizei imageSize
, const GLvoid
*data
,
164 struct gl_texture_object
*texObj
,
165 struct gl_texture_image
*texImage
)
167 struct intel_texture_object
*intelObj
= intel_texture_object(texObj
);
168 GLuint face
= target_to_face(target
);
170 _mesa_store_compressed_texsubimage2d(ctx
, target
, level
, xoffset
, yoffset
, width
,
171 height
, format
, imageSize
, data
, texObj
, texImage
);
173 intelObj
->dirty_images
[face
] |= (1 << level
);
174 intelObj
->dirty
|= 1 << face
;
178 static void intelTexImage3D( GLcontext
*ctx
, GLenum target
, GLint level
,
179 GLint internalFormat
,
180 GLint width
, GLint height
, GLint depth
,
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
)
187 struct intel_texture_object
*intelObj
= intel_texture_object(texObj
);
189 _mesa_store_teximage3d(ctx
, target
, level
, internalFormat
,
190 width
, height
, depth
, border
,
191 format
, type
, pixels
,
192 &ctx
->Unpack
, texObj
, texImage
);
194 intelObj
->dirty_images
[0] |= (1 << level
);
195 intelObj
->dirty
|= 1 << 0;
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
)
209 struct intel_texture_object
*intelObj
= intel_texture_object(texObj
);
211 _mesa_store_texsubimage3d(ctx
, target
, level
, xoffset
, yoffset
, zoffset
,
212 width
, height
, depth
,
213 format
, type
, pixels
, packing
, texObj
, texImage
);
215 intelObj
->dirty_images
[0] |= (1 << level
);
216 intelObj
->dirty
|= 1 << 0;
222 static struct gl_texture_object
*intelNewTextureObject( GLcontext
*ctx
,
226 struct intel_texture_object
*obj
= CALLOC_STRUCT(intel_texture_object
);
228 _mesa_initialize_texture_object(&obj
->base
, name
, target
);
233 static GLboolean
intelIsTextureResident(GLcontext
*ctx
,
234 struct gl_texture_object
*texObj
)
237 struct intel_context
*intel
= intel_context(ctx
);
238 struct intel_texture_object
*intelObj
= intel_texture_object(texObj
);
242 intelObj
->mt
->region
&&
243 intel_is_region_resident(intel
, intelObj
->mt
->region
);
250 static void intelTexParameter( GLcontext
*ctx
,
252 struct gl_texture_object
*texObj
,
254 const GLfloat
*params
)
256 struct intel_texture_object
*intelObj
= intel_texture_object(texObj
);
259 /* Anything which can affect the calculation of firstLevel and
260 * lastLevel, as changes to these may invalidate the miptree.
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;
278 intel_delete_texture_object( GLcontext
*ctx
, struct gl_texture_object
*texObj
)
280 struct intel_context
*intel
= intel_context(ctx
);
281 struct intel_texture_object
*intelObj
= intel_texture_object(texObj
);
284 intel_miptree_destroy(intel
, intelObj
->mt
);
286 _mesa_delete_texture_object( ctx
, texObj
);
289 void intelInitTextureFuncs( struct dd_function_table
*functions
)
291 functions
->NewTextureObject
= intelNewTextureObject
;
292 functions
->TexImage1D
= intelTexImage1D
;
293 functions
->TexImage2D
= intelTexImage2D
;
294 functions
->TexImage3D
= intelTexImage3D
;
295 functions
->TexSubImage1D
= intelTexSubImage1D
;
296 functions
->TexSubImage2D
= intelTexSubImage2D
;
297 functions
->TexSubImage3D
= intelTexSubImage3D
;
298 functions
->CopyTexImage1D
= _swrast_copy_teximage1d
;
299 functions
->CopyTexImage2D
= _swrast_copy_teximage2d
;
300 functions
->CopyTexSubImage1D
= _swrast_copy_texsubimage1d
;
301 functions
->CopyTexSubImage2D
= _swrast_copy_texsubimage2d
;
302 functions
->CopyTexSubImage3D
= _swrast_copy_texsubimage3d
;
303 functions
->DeleteTexture
= intel_delete_texture_object
;
304 functions
->UpdateTexturePalette
= NULL
;
305 functions
->IsTextureResident
= intelIsTextureResident
;
306 functions
->TestProxyTexImage
= _mesa_test_proxy_teximage
;
307 functions
->CompressedTexImage2D
= intelCompressedTexImage2D
;
308 functions
->CompressedTexSubImage2D
= intelCompressedTexSubImage2D
;
309 functions
->TexParameter
= intelTexParameter
;