3 * Texture images manipulation functions.
7 * Mesa 3-D graphics library
9 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included
19 * in all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 * OTHER DEALINGS IN THE SOFTWARE.
42 /** Is the given value one of the 6 cube faces? */
43 static inline GLboolean
44 _mesa_is_cube_face(GLenum target
)
46 return (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
47 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
);
52 * Return number of faces for a texture target. This will be 6 for
53 * cube maps and 1 otherwise.
54 * NOTE: this function is not used for cube map arrays which operate
55 * more like 2D arrays than cube maps.
58 _mesa_num_tex_faces(GLenum target
)
61 case GL_TEXTURE_CUBE_MAP
:
62 case GL_PROXY_TEXTURE_CUBE_MAP
:
71 * If the target is GL_TEXTURE_CUBE_MAP, return one of the
72 * GL_TEXTURE_CUBE_MAP_POSITIVE/NEGATIVE_X/Y/Z targets corresponding to
74 * Else, return target as-is.
77 _mesa_cube_face_target(GLenum target
, unsigned face
)
79 if (target
== GL_TEXTURE_CUBE_MAP
) {
81 return GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ face
;
90 * For cube map faces, return a face index in [0,5].
91 * For other targets return 0;
94 _mesa_tex_target_to_face(GLenum target
)
96 if (_mesa_is_cube_face(target
))
97 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
103 /** Are any of the dimensions of given texture equal to zero? */
104 static inline GLboolean
105 _mesa_is_zero_size_texture(const struct gl_texture_image
*texImage
)
107 return (texImage
->Width
== 0 ||
108 texImage
->Height
== 0 ||
109 texImage
->Depth
== 0);
112 /** \name Internal functions */
116 _mesa_is_proxy_texture(GLenum target
);
119 _mesa_is_array_texture(GLenum target
);
121 extern struct gl_texture_image
*
122 _mesa_new_texture_image( struct gl_context
*ctx
);
126 _mesa_delete_texture_image( struct gl_context
*ctx
,
127 struct gl_texture_image
*teximage
);
131 _mesa_init_teximage_fields(struct gl_context
*ctx
,
132 struct gl_texture_image
*img
,
133 GLsizei width
, GLsizei height
, GLsizei depth
,
134 GLint border
, GLenum internalFormat
,
139 _mesa_choose_texture_format(struct gl_context
*ctx
,
140 struct gl_texture_object
*texObj
,
141 GLenum target
, GLint level
,
142 GLenum internalFormat
, GLenum format
, GLenum type
);
145 _mesa_update_fbo_texture(struct gl_context
*ctx
,
146 struct gl_texture_object
*texObj
,
147 GLuint face
, GLuint level
);
150 _mesa_clear_texture_image(struct gl_context
*ctx
,
151 struct gl_texture_image
*texImage
);
154 extern struct gl_texture_image
*
155 _mesa_select_tex_image(const struct gl_texture_object
*texObj
,
156 GLenum target
, GLint level
);
159 extern struct gl_texture_image
*
160 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
161 GLenum target
, GLint level
);
165 * Return the base-level texture image for the given texture object.
167 static inline const struct gl_texture_image
*
168 _mesa_base_tex_image(const struct gl_texture_object
*texObj
)
170 return texObj
->Image
[0][texObj
->BaseLevel
];
175 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
);
179 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
181 GLint width
, GLint height
, GLint depth
, GLint border
);
184 _mesa_target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
185 GLenum intFormat
, GLenum
*error
);
188 _mesa_get_texture_dimensions(GLenum target
);
191 _mesa_tex_target_is_layered(GLenum target
);
194 _mesa_get_texture_layers(const struct gl_texture_object
*texObj
, GLint level
);
197 _mesa_get_tex_max_num_levels(GLenum target
, GLsizei width
, GLsizei height
,
201 _mesa_legal_texture_dimensions(struct gl_context
*ctx
, GLenum target
,
202 GLint level
, GLint width
, GLint height
,
203 GLint depth
, GLint border
);
206 _mesa_validate_texbuffer_format(const struct gl_context
*ctx
,
207 GLenum internalFormat
);
211 _mesa_legal_texture_base_format_for_target(struct gl_context
*ctx
,
213 GLenum internalFormat
);
216 _mesa_format_no_online_compression(const struct gl_context
*ctx
, GLenum format
);
219 _mesa_is_renderable_texture_format(struct gl_context
*ctx
, GLenum internalformat
);
222 _mesa_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
223 struct gl_texture_object
*texObj
,
224 struct gl_texture_image
*texImage
,
225 GLenum target
, GLint level
,
226 GLint xoffset
, GLint yoffset
, GLint zoffset
,
227 GLsizei width
, GLsizei height
, GLsizei depth
,
228 GLenum format
, GLenum type
, const GLvoid
*pixels
,
232 _mesa_compressed_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
233 struct gl_texture_object
*texObj
,
234 struct gl_texture_image
*texImage
,
235 GLenum target
, GLint level
,
236 GLint xoffset
, GLint yoffset
,
238 GLsizei width
, GLsizei height
,
240 GLenum format
, GLsizei imageSize
,
244 _mesa_copy_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
245 struct gl_texture_object
*texObj
,
246 GLenum target
, GLint level
,
247 GLint xoffset
, GLint yoffset
, GLint zoffset
,
249 GLsizei width
, GLsizei height
,
253 _mesa_texture_buffer_range(struct gl_context
*ctx
,
254 struct gl_texture_object
*texObj
,
255 GLenum internalFormat
,
256 struct gl_buffer_object
*bufObj
,
257 GLintptr offset
, GLsizeiptr size
,
261 _mesa_is_cube_map_texture(GLenum target
);
266 /** \name API entry point functions */
269 extern void GLAPIENTRY
270 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalformat
,
271 GLsizei width
, GLint border
,
272 GLenum format
, GLenum type
, const GLvoid
*pixels
);
275 extern void GLAPIENTRY
276 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalformat
,
277 GLsizei width
, GLsizei height
, GLint border
,
278 GLenum format
, GLenum type
, const GLvoid
*pixels
);
281 extern void GLAPIENTRY
282 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalformat
,
283 GLsizei width
, GLsizei height
, GLsizei depth
, GLint border
,
284 GLenum format
, GLenum type
, const GLvoid
*pixels
);
287 extern void GLAPIENTRY
288 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalformat
,
289 GLsizei width
, GLsizei height
, GLsizei depth
,
290 GLint border
, GLenum format
, GLenum type
,
291 const GLvoid
*pixels
);
293 extern void GLAPIENTRY
294 _mesa_EGLImageTargetTexture2DOES( GLenum target
, GLeglImageOES image
);
296 extern void GLAPIENTRY
297 _mesa_TexSubImage1D( GLenum target
, GLint level
, GLint xoffset
,
299 GLenum format
, GLenum type
,
300 const GLvoid
*pixels
);
303 extern void GLAPIENTRY
304 _mesa_TexSubImage2D( GLenum target
, GLint level
,
305 GLint xoffset
, GLint yoffset
,
306 GLsizei width
, GLsizei height
,
307 GLenum format
, GLenum type
,
308 const GLvoid
*pixels
);
311 extern void GLAPIENTRY
312 _mesa_TexSubImage3D( GLenum target
, GLint level
,
313 GLint xoffset
, GLint yoffset
, GLint zoffset
,
314 GLsizei width
, GLsizei height
, GLsizei depth
,
315 GLenum format
, GLenum type
,
316 const GLvoid
*pixels
);
318 extern void GLAPIENTRY
319 _mesa_TextureSubImage1D(GLuint texture
, GLint level
, GLint xoffset
,
321 GLenum format
, GLenum type
,
322 const GLvoid
*pixels
);
325 extern void GLAPIENTRY
326 _mesa_TextureSubImage2D(GLuint texture
, GLint level
,
327 GLint xoffset
, GLint yoffset
,
328 GLsizei width
, GLsizei height
,
329 GLenum format
, GLenum type
,
330 const GLvoid
*pixels
);
332 extern void GLAPIENTRY
333 _mesa_TextureSubImage3D(GLuint texture
, GLint level
,
334 GLint xoffset
, GLint yoffset
, GLint zoffset
,
335 GLsizei width
, GLsizei height
, GLsizei depth
,
336 GLenum format
, GLenum type
,
337 const GLvoid
*pixels
);
340 extern void GLAPIENTRY
341 _mesa_CopyTexImage1D(GLenum target
, GLint level
, GLenum internalformat
,
342 GLint x
, GLint y
, GLsizei width
, GLint border
);
345 extern void GLAPIENTRY
346 _mesa_CopyTexImage2D( GLenum target
, GLint level
,
347 GLenum internalformat
, GLint x
, GLint y
,
348 GLsizei width
, GLsizei height
, GLint border
);
351 extern void GLAPIENTRY
352 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
, GLint xoffset
,
353 GLint x
, GLint y
, GLsizei width
);
356 extern void GLAPIENTRY
357 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
358 GLint xoffset
, GLint yoffset
,
359 GLint x
, GLint y
, GLsizei width
, GLsizei height
);
362 extern void GLAPIENTRY
363 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
364 GLint xoffset
, GLint yoffset
, GLint zoffset
,
365 GLint x
, GLint y
, GLsizei width
, GLsizei height
);
367 extern void GLAPIENTRY
368 _mesa_CopyTextureSubImage1D(GLuint texture
, GLint level
,
369 GLint xoffset
, GLint x
, GLint y
, GLsizei width
);
371 extern void GLAPIENTRY
372 _mesa_CopyTextureSubImage2D(GLuint texture
, GLint level
,
373 GLint xoffset
, GLint yoffset
,
375 GLsizei width
, GLsizei height
);
377 extern void GLAPIENTRY
378 _mesa_CopyTextureSubImage3D(GLuint texture
, GLint level
,
379 GLint xoffset
, GLint yoffset
, GLint zoffset
,
381 GLsizei width
, GLsizei height
);
383 extern void GLAPIENTRY
384 _mesa_ClearTexSubImage( GLuint texture
, GLint level
,
385 GLint xoffset
, GLint yoffset
, GLint zoffset
,
386 GLsizei width
, GLsizei height
, GLsizei depth
,
387 GLenum format
, GLenum type
, const void *data
);
389 extern void GLAPIENTRY
390 _mesa_ClearTexImage( GLuint texture
, GLint level
,
391 GLenum format
, GLenum type
, const void *data
);
393 extern void GLAPIENTRY
394 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
395 GLenum internalformat
, GLsizei width
,
396 GLint border
, GLsizei imageSize
,
399 extern void GLAPIENTRY
400 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
401 GLenum internalformat
, GLsizei width
,
402 GLsizei height
, GLint border
, GLsizei imageSize
,
405 extern void GLAPIENTRY
406 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
407 GLenum internalformat
, GLsizei width
,
408 GLsizei height
, GLsizei depth
, GLint border
,
409 GLsizei imageSize
, const GLvoid
*data
);
411 extern void GLAPIENTRY
412 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
413 GLsizei width
, GLenum format
,
414 GLsizei imageSize
, const GLvoid
*data
);
416 extern void GLAPIENTRY
417 _mesa_CompressedTextureSubImage1D(GLuint texture
, GLint level
, GLint xoffset
,
418 GLsizei width
, GLenum format
,
419 GLsizei imageSize
, const GLvoid
*data
);
421 extern void GLAPIENTRY
422 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
423 GLint yoffset
, GLsizei width
, GLsizei height
,
424 GLenum format
, GLsizei imageSize
,
427 extern void GLAPIENTRY
428 _mesa_CompressedTextureSubImage2D(GLuint texture
, GLint level
, GLint xoffset
,
430 GLsizei width
, GLsizei height
,
431 GLenum format
, GLsizei imageSize
,
434 extern void GLAPIENTRY
435 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
436 GLint yoffset
, GLint zoffset
, GLsizei width
,
437 GLsizei height
, GLsizei depth
, GLenum format
,
438 GLsizei imageSize
, const GLvoid
*data
);
440 extern void GLAPIENTRY
441 _mesa_CompressedTextureSubImage3D(GLuint texture
, GLint level
, GLint xoffset
,
442 GLint yoffset
, GLint zoffset
,
443 GLsizei width
, GLsizei height
,
445 GLenum format
, GLsizei imageSize
,
448 extern void GLAPIENTRY
449 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
);
451 extern void GLAPIENTRY
452 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
453 GLintptr offset
, GLsizeiptr size
);
455 extern void GLAPIENTRY
456 _mesa_TextureBuffer(GLuint texture
, GLenum internalFormat
, GLuint buffer
);
458 extern void GLAPIENTRY
459 _mesa_TextureBufferRange(GLuint texture
, GLenum internalFormat
, GLuint buffer
,
460 GLintptr offset
, GLsizeiptr size
);
463 extern void GLAPIENTRY
464 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
465 GLenum internalformat
, GLsizei width
,
466 GLsizei height
, GLboolean fixedsamplelocations
);
468 extern void GLAPIENTRY
469 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
470 GLenum internalformat
, GLsizei width
,
471 GLsizei height
, GLsizei depth
,
472 GLboolean fixedsamplelocations
);
474 extern void GLAPIENTRY
475 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
476 GLenum internalformat
, GLsizei width
,
477 GLsizei height
, GLboolean fixedsamplelocations
);
479 extern void GLAPIENTRY
480 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
481 GLenum internalformat
, GLsizei width
,
482 GLsizei height
, GLsizei depth
,
483 GLboolean fixedsamplelocations
);
486 _mesa_TextureStorage2DMultisample(GLuint texture
, GLsizei samples
,
487 GLenum internalformat
, GLsizei width
,
489 GLboolean fixedsamplelocations
);
492 _mesa_TextureStorage3DMultisample(GLuint texture
, GLsizei samples
,
493 GLenum internalformat
, GLsizei width
,
494 GLsizei height
, GLsizei depth
,
495 GLboolean fixedsamplelocations
);