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
);
123 _mesa_delete_texture_image( struct gl_context
*ctx
,
124 struct gl_texture_image
*teximage
);
128 _mesa_init_teximage_fields(struct gl_context
*ctx
,
129 struct gl_texture_image
*img
,
130 GLsizei width
, GLsizei height
, GLsizei depth
,
131 GLint border
, GLenum internalFormat
,
136 _mesa_choose_texture_format(struct gl_context
*ctx
,
137 struct gl_texture_object
*texObj
,
138 GLenum target
, GLint level
,
139 GLenum internalFormat
, GLenum format
, GLenum type
);
142 _mesa_update_fbo_texture(struct gl_context
*ctx
,
143 struct gl_texture_object
*texObj
,
144 GLuint face
, GLuint level
);
147 _mesa_clear_texture_image(struct gl_context
*ctx
,
148 struct gl_texture_image
*texImage
);
151 extern struct gl_texture_image
*
152 _mesa_select_tex_image(const struct gl_texture_object
*texObj
,
153 GLenum target
, GLint level
);
156 extern struct gl_texture_image
*
157 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
158 GLenum target
, GLint level
);
161 _mesa_get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
);
164 * Return the base-level texture image for the given texture object.
166 static inline const struct gl_texture_image
*
167 _mesa_base_tex_image(const struct gl_texture_object
*texObj
)
169 return texObj
->Image
[0][texObj
->BaseLevel
];
174 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
);
178 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
,
179 GLuint numLevels
, GLint level
,
180 mesa_format format
, GLuint numSamples
,
181 GLint width
, GLint height
, GLint depth
);
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_is_cube_map_texture(GLenum target
);
237 /** \name API entry point functions */
240 extern void GLAPIENTRY
241 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalformat
,
242 GLsizei width
, GLint border
,
243 GLenum format
, GLenum type
, const GLvoid
*pixels
);
246 extern void GLAPIENTRY
247 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalformat
,
248 GLsizei width
, GLsizei height
, GLint border
,
249 GLenum format
, GLenum type
, const GLvoid
*pixels
);
252 extern void GLAPIENTRY
253 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalformat
,
254 GLsizei width
, GLsizei height
, GLsizei depth
, GLint border
,
255 GLenum format
, GLenum type
, const GLvoid
*pixels
);
258 extern void GLAPIENTRY
259 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalformat
,
260 GLsizei width
, GLsizei height
, GLsizei depth
,
261 GLint border
, GLenum format
, GLenum type
,
262 const GLvoid
*pixels
);
264 extern void GLAPIENTRY
265 _mesa_TexImage1D_no_error(GLenum target
, GLint level
, GLint internalformat
,
266 GLsizei width
, GLint border
,
267 GLenum format
, GLenum type
, const GLvoid
*pixels
);
269 extern void GLAPIENTRY
270 _mesa_TexImage2D_no_error(GLenum target
, GLint level
, GLint internalformat
,
271 GLsizei width
, GLsizei height
, GLint border
,
272 GLenum format
, GLenum type
, const GLvoid
*pixels
);
274 extern void GLAPIENTRY
275 _mesa_TexImage3D_no_error(GLenum target
, GLint level
, GLint internalformat
,
276 GLsizei width
, GLsizei height
, GLsizei depth
,
277 GLint border
, GLenum format
, GLenum type
,
278 const GLvoid
*pixels
);
280 extern void GLAPIENTRY
281 _mesa_EGLImageTargetTexture2DOES( GLenum target
, GLeglImageOES image
);
284 _mesa_TexSubImage1D_no_error(GLenum target
, GLint level
, GLint xoffset
,
286 GLenum format
, GLenum type
,
287 const GLvoid
*pixels
);
289 extern void GLAPIENTRY
290 _mesa_TexSubImage1D( GLenum target
, GLint level
, GLint xoffset
,
292 GLenum format
, GLenum type
,
293 const GLvoid
*pixels
);
296 _mesa_TexSubImage2D_no_error(GLenum target
, GLint level
,
297 GLint xoffset
, GLint yoffset
,
298 GLsizei width
, GLsizei height
,
299 GLenum format
, GLenum type
,
300 const GLvoid
*pixels
);
302 extern void GLAPIENTRY
303 _mesa_TexSubImage2D( GLenum target
, GLint level
,
304 GLint xoffset
, GLint yoffset
,
305 GLsizei width
, GLsizei height
,
306 GLenum format
, GLenum type
,
307 const GLvoid
*pixels
);
310 _mesa_TexSubImage3D_no_error(GLenum target
, GLint level
,
311 GLint xoffset
, GLint yoffset
, GLint zoffset
,
312 GLsizei width
, GLsizei height
, GLsizei depth
,
313 GLenum format
, GLenum type
,
314 const GLvoid
*pixels
);
316 extern void GLAPIENTRY
317 _mesa_TexSubImage3D( GLenum target
, GLint level
,
318 GLint xoffset
, GLint yoffset
, GLint zoffset
,
319 GLsizei width
, GLsizei height
, GLsizei depth
,
320 GLenum format
, GLenum type
,
321 const GLvoid
*pixels
);
324 _mesa_TextureSubImage1D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
325 GLsizei width
, GLenum format
, GLenum type
,
326 const GLvoid
*pixels
);
328 extern void GLAPIENTRY
329 _mesa_TextureSubImage1D(GLuint texture
, GLint level
, GLint xoffset
,
331 GLenum format
, GLenum type
,
332 const GLvoid
*pixels
);
335 _mesa_TextureSubImage2D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
336 GLint yoffset
, GLsizei width
, GLsizei height
,
337 GLenum format
, GLenum type
,
338 const GLvoid
*pixels
);
340 extern void GLAPIENTRY
341 _mesa_TextureSubImage2D(GLuint texture
, GLint level
,
342 GLint xoffset
, GLint yoffset
,
343 GLsizei width
, GLsizei height
,
344 GLenum format
, GLenum type
,
345 const GLvoid
*pixels
);
348 _mesa_TextureSubImage3D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
349 GLint yoffset
, GLint zoffset
, GLsizei width
,
350 GLsizei height
, GLsizei depth
, GLenum format
,
351 GLenum type
, const GLvoid
*pixels
);
353 extern void GLAPIENTRY
354 _mesa_TextureSubImage3D(GLuint texture
, GLint level
,
355 GLint xoffset
, GLint yoffset
, GLint zoffset
,
356 GLsizei width
, GLsizei height
, GLsizei depth
,
357 GLenum format
, GLenum type
,
358 const GLvoid
*pixels
);
361 extern void GLAPIENTRY
362 _mesa_CopyTexImage1D(GLenum target
, GLint level
, GLenum internalformat
,
363 GLint x
, GLint y
, GLsizei width
, GLint border
);
366 extern void GLAPIENTRY
367 _mesa_CopyTexImage2D( GLenum target
, GLint level
,
368 GLenum internalformat
, GLint x
, GLint y
,
369 GLsizei width
, GLsizei height
, GLint border
);
372 extern void GLAPIENTRY
373 _mesa_CopyTexImage1D_no_error(GLenum target
, GLint level
, GLenum internalformat
,
374 GLint x
, GLint y
, GLsizei width
, GLint border
);
377 extern void GLAPIENTRY
378 _mesa_CopyTexImage2D_no_error(GLenum target
, GLint level
, GLenum internalformat
,
379 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
383 extern void GLAPIENTRY
384 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
, GLint xoffset
,
385 GLint x
, GLint y
, GLsizei width
);
388 extern void GLAPIENTRY
389 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
390 GLint xoffset
, GLint yoffset
,
391 GLint x
, GLint y
, GLsizei width
, GLsizei height
);
394 extern void GLAPIENTRY
395 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
396 GLint xoffset
, GLint yoffset
, GLint zoffset
,
397 GLint x
, GLint y
, GLsizei width
, GLsizei height
);
399 extern void GLAPIENTRY
400 _mesa_CopyTextureSubImage1D(GLuint texture
, GLint level
,
401 GLint xoffset
, GLint x
, GLint y
, GLsizei width
);
403 extern void GLAPIENTRY
404 _mesa_CopyTextureSubImage2D(GLuint texture
, GLint level
,
405 GLint xoffset
, GLint yoffset
,
407 GLsizei width
, GLsizei height
);
409 extern void GLAPIENTRY
410 _mesa_CopyTextureSubImage3D(GLuint texture
, GLint level
,
411 GLint xoffset
, GLint yoffset
, GLint zoffset
,
413 GLsizei width
, GLsizei height
);
415 extern void GLAPIENTRY
416 _mesa_CopyTexSubImage1D_no_error(GLenum target
, GLint level
, GLint xoffset
,
417 GLint x
, GLint y
, GLsizei width
);
419 extern void GLAPIENTRY
420 _mesa_CopyTexSubImage2D_no_error(GLenum target
, GLint level
, GLint xoffset
,
421 GLint yoffset
, GLint x
, GLint y
, GLsizei width
,
424 extern void GLAPIENTRY
425 _mesa_CopyTexSubImage3D_no_error(GLenum target
, GLint level
, GLint xoffset
,
426 GLint yoffset
, GLint zoffset
, GLint x
, GLint y
,
427 GLsizei width
, GLsizei height
);
429 extern void GLAPIENTRY
430 _mesa_CopyTextureSubImage1D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
431 GLint x
, GLint y
, GLsizei width
);
433 extern void GLAPIENTRY
434 _mesa_CopyTextureSubImage2D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
435 GLint yoffset
, GLint x
, GLint y
,
436 GLsizei width
, GLsizei height
);
438 extern void GLAPIENTRY
439 _mesa_CopyTextureSubImage3D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
440 GLint yoffset
, GLint zoffset
, GLint x
,
441 GLint y
, GLsizei width
, GLsizei height
);
443 extern void GLAPIENTRY
444 _mesa_ClearTexSubImage( GLuint texture
, GLint level
,
445 GLint xoffset
, GLint yoffset
, GLint zoffset
,
446 GLsizei width
, GLsizei height
, GLsizei depth
,
447 GLenum format
, GLenum type
, const void *data
);
449 extern void GLAPIENTRY
450 _mesa_ClearTexImage( GLuint texture
, GLint level
,
451 GLenum format
, GLenum type
, const void *data
);
453 extern void GLAPIENTRY
454 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
455 GLenum internalformat
, GLsizei width
,
456 GLint border
, GLsizei imageSize
,
459 extern void GLAPIENTRY
460 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
461 GLenum internalformat
, GLsizei width
,
462 GLsizei height
, GLint border
, GLsizei imageSize
,
465 extern void GLAPIENTRY
466 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
467 GLenum internalformat
, GLsizei width
,
468 GLsizei height
, GLsizei depth
, GLint border
,
469 GLsizei imageSize
, const GLvoid
*data
);
471 extern void GLAPIENTRY
472 _mesa_CompressedTexImage1D_no_error(GLenum target
, GLint level
,
473 GLenum internalformat
, GLsizei width
,
474 GLint border
, GLsizei imageSize
,
477 extern void GLAPIENTRY
478 _mesa_CompressedTexImage2D_no_error(GLenum target
, GLint level
,
479 GLenum internalformat
, GLsizei width
,
480 GLsizei height
, GLint border
,
481 GLsizei imageSize
, const GLvoid
*data
);
483 extern void GLAPIENTRY
484 _mesa_CompressedTexImage3D_no_error(GLenum target
, GLint level
,
485 GLenum internalformat
, GLsizei width
,
486 GLsizei height
, GLsizei depth
, GLint border
,
487 GLsizei imageSize
, const GLvoid
*data
);
490 extern void GLAPIENTRY
491 _mesa_CompressedTexSubImage1D_no_error(GLenum target
, GLint level
,
492 GLint xoffset
, GLsizei width
,
493 GLenum format
, GLsizei imageSize
,
495 extern void GLAPIENTRY
496 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
497 GLsizei width
, GLenum format
,
498 GLsizei imageSize
, const GLvoid
*data
);
500 extern void GLAPIENTRY
501 _mesa_CompressedTextureSubImage1D_no_error(GLuint texture
, GLint level
,
502 GLint xoffset
, GLsizei width
,
503 GLenum format
, GLsizei imageSize
,
505 extern void GLAPIENTRY
506 _mesa_CompressedTextureSubImage1D(GLuint texture
, GLint level
, GLint xoffset
,
507 GLsizei width
, GLenum format
,
508 GLsizei imageSize
, const GLvoid
*data
);
510 extern void GLAPIENTRY
511 _mesa_CompressedTexSubImage2D_no_error(GLenum target
, GLint level
,
512 GLint xoffset
, GLint yoffset
,
513 GLsizei width
, GLsizei height
,
514 GLenum format
, GLsizei imageSize
,
516 extern void GLAPIENTRY
517 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
518 GLint yoffset
, GLsizei width
, GLsizei height
,
519 GLenum format
, GLsizei imageSize
,
522 extern void GLAPIENTRY
523 _mesa_CompressedTextureSubImage2D_no_error(GLuint texture
, GLint level
,
524 GLint xoffset
, GLint yoffset
,
525 GLsizei width
, GLsizei height
,
526 GLenum format
, GLsizei imageSize
,
528 extern void GLAPIENTRY
529 _mesa_CompressedTextureSubImage2D(GLuint texture
, GLint level
, GLint xoffset
,
531 GLsizei width
, GLsizei height
,
532 GLenum format
, GLsizei imageSize
,
535 extern void GLAPIENTRY
536 _mesa_CompressedTexSubImage3D_no_error(GLenum target
, GLint level
,
537 GLint xoffset
, GLint yoffset
,
538 GLint zoffset
, GLsizei width
,
539 GLsizei height
, GLsizei depth
,
540 GLenum format
, GLsizei imageSize
,
542 extern void GLAPIENTRY
543 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
544 GLint yoffset
, GLint zoffset
, GLsizei width
,
545 GLsizei height
, GLsizei depth
, GLenum format
,
546 GLsizei imageSize
, const GLvoid
*data
);
548 extern void GLAPIENTRY
549 _mesa_CompressedTextureSubImage3D_no_error(GLuint texture
, GLint level
,
550 GLint xoffset
, GLint yoffset
,
551 GLint zoffset
, GLsizei width
,
552 GLsizei height
, GLsizei depth
,
553 GLenum format
, GLsizei imageSize
,
555 extern void GLAPIENTRY
556 _mesa_CompressedTextureSubImage3D(GLuint texture
, GLint level
, GLint xoffset
,
557 GLint yoffset
, GLint zoffset
,
558 GLsizei width
, GLsizei height
,
560 GLenum format
, GLsizei imageSize
,
563 extern void GLAPIENTRY
564 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
);
566 extern void GLAPIENTRY
567 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
568 GLintptr offset
, GLsizeiptr size
);
570 extern void GLAPIENTRY
571 _mesa_TextureBuffer(GLuint texture
, GLenum internalFormat
, GLuint buffer
);
573 extern void GLAPIENTRY
574 _mesa_TextureBufferRange(GLuint texture
, GLenum internalFormat
, GLuint buffer
,
575 GLintptr offset
, GLsizeiptr size
);
578 extern void GLAPIENTRY
579 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
580 GLenum internalformat
, GLsizei width
,
581 GLsizei height
, GLboolean fixedsamplelocations
);
583 extern void GLAPIENTRY
584 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
585 GLenum internalformat
, GLsizei width
,
586 GLsizei height
, GLsizei depth
,
587 GLboolean fixedsamplelocations
);
589 extern void GLAPIENTRY
590 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
591 GLenum internalformat
, GLsizei width
,
592 GLsizei height
, GLboolean fixedsamplelocations
);
594 extern void GLAPIENTRY
595 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
596 GLenum internalformat
, GLsizei width
,
597 GLsizei height
, GLsizei depth
,
598 GLboolean fixedsamplelocations
);
601 _mesa_TextureStorage2DMultisample(GLuint texture
, GLsizei samples
,
602 GLenum internalformat
, GLsizei width
,
604 GLboolean fixedsamplelocations
);
607 _mesa_TextureStorage3DMultisample(GLuint texture
, GLsizei samples
,
608 GLenum internalformat
, GLsizei width
,
609 GLsizei height
, GLsizei depth
,
610 GLboolean fixedsamplelocations
);