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
);
162 * Return the base-level texture image for the given texture object.
164 static inline const struct gl_texture_image
*
165 _mesa_base_tex_image(const struct gl_texture_object
*texObj
)
167 return texObj
->Image
[0][texObj
->BaseLevel
];
172 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
);
176 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
,
177 GLuint numLevels
, GLint level
,
178 mesa_format format
, GLuint numSamples
,
179 GLint width
, GLint height
, GLint depth
);
182 _mesa_target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
183 GLenum intFormat
, GLenum
*error
);
186 _mesa_get_texture_dimensions(GLenum target
);
189 _mesa_tex_target_is_layered(GLenum target
);
192 _mesa_get_texture_layers(const struct gl_texture_object
*texObj
, GLint level
);
195 _mesa_get_tex_max_num_levels(GLenum target
, GLsizei width
, GLsizei height
,
199 _mesa_legal_texture_dimensions(struct gl_context
*ctx
, GLenum target
,
200 GLint level
, GLint width
, GLint height
,
201 GLint depth
, GLint border
);
204 _mesa_validate_texbuffer_format(const struct gl_context
*ctx
,
205 GLenum internalFormat
);
209 _mesa_legal_texture_base_format_for_target(struct gl_context
*ctx
,
211 GLenum internalFormat
);
214 _mesa_format_no_online_compression(const struct gl_context
*ctx
, GLenum format
);
217 _mesa_is_renderable_texture_format(struct gl_context
*ctx
, GLenum internalformat
);
220 _mesa_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
221 struct gl_texture_object
*texObj
,
222 struct gl_texture_image
*texImage
,
223 GLenum target
, GLint level
,
224 GLint xoffset
, GLint yoffset
, GLint zoffset
,
225 GLsizei width
, GLsizei height
, GLsizei depth
,
226 GLenum format
, GLenum type
, const GLvoid
*pixels
,
230 _mesa_is_cube_map_texture(GLenum target
);
235 /** \name API entry point functions */
238 extern void GLAPIENTRY
239 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalformat
,
240 GLsizei width
, GLint border
,
241 GLenum format
, GLenum type
, const GLvoid
*pixels
);
244 extern void GLAPIENTRY
245 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalformat
,
246 GLsizei width
, GLsizei height
, GLint border
,
247 GLenum format
, GLenum type
, const GLvoid
*pixels
);
250 extern void GLAPIENTRY
251 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalformat
,
252 GLsizei width
, GLsizei height
, GLsizei depth
, GLint border
,
253 GLenum format
, GLenum type
, const GLvoid
*pixels
);
256 extern void GLAPIENTRY
257 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalformat
,
258 GLsizei width
, GLsizei height
, GLsizei depth
,
259 GLint border
, GLenum format
, GLenum type
,
260 const GLvoid
*pixels
);
262 extern void GLAPIENTRY
263 _mesa_TexImage1D_no_error(GLenum target
, GLint level
, GLint internalformat
,
264 GLsizei width
, GLint border
,
265 GLenum format
, GLenum type
, const GLvoid
*pixels
);
267 extern void GLAPIENTRY
268 _mesa_TexImage2D_no_error(GLenum target
, GLint level
, GLint internalformat
,
269 GLsizei width
, GLsizei height
, GLint border
,
270 GLenum format
, GLenum type
, const GLvoid
*pixels
);
272 extern void GLAPIENTRY
273 _mesa_TexImage3D_no_error(GLenum target
, GLint level
, GLint internalformat
,
274 GLsizei width
, GLsizei height
, GLsizei depth
,
275 GLint border
, GLenum format
, GLenum type
,
276 const GLvoid
*pixels
);
278 extern void GLAPIENTRY
279 _mesa_EGLImageTargetTexture2DOES( GLenum target
, GLeglImageOES image
);
282 _mesa_TexSubImage1D_no_error(GLenum target
, GLint level
, GLint xoffset
,
284 GLenum format
, GLenum type
,
285 const GLvoid
*pixels
);
287 extern void GLAPIENTRY
288 _mesa_TexSubImage1D( GLenum target
, GLint level
, GLint xoffset
,
290 GLenum format
, GLenum type
,
291 const GLvoid
*pixels
);
294 _mesa_TexSubImage2D_no_error(GLenum target
, GLint level
,
295 GLint xoffset
, GLint yoffset
,
296 GLsizei width
, GLsizei height
,
297 GLenum format
, GLenum type
,
298 const GLvoid
*pixels
);
300 extern void GLAPIENTRY
301 _mesa_TexSubImage2D( GLenum target
, GLint level
,
302 GLint xoffset
, GLint yoffset
,
303 GLsizei width
, GLsizei height
,
304 GLenum format
, GLenum type
,
305 const GLvoid
*pixels
);
308 _mesa_TexSubImage3D_no_error(GLenum target
, GLint level
,
309 GLint xoffset
, GLint yoffset
, GLint zoffset
,
310 GLsizei width
, GLsizei height
, GLsizei depth
,
311 GLenum format
, GLenum type
,
312 const GLvoid
*pixels
);
314 extern void GLAPIENTRY
315 _mesa_TexSubImage3D( GLenum target
, GLint level
,
316 GLint xoffset
, GLint yoffset
, GLint zoffset
,
317 GLsizei width
, GLsizei height
, GLsizei depth
,
318 GLenum format
, GLenum type
,
319 const GLvoid
*pixels
);
322 _mesa_TextureSubImage1D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
323 GLsizei width
, GLenum format
, GLenum type
,
324 const GLvoid
*pixels
);
326 extern void GLAPIENTRY
327 _mesa_TextureSubImage1D(GLuint texture
, GLint level
, GLint xoffset
,
329 GLenum format
, GLenum type
,
330 const GLvoid
*pixels
);
333 _mesa_TextureSubImage2D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
334 GLint yoffset
, GLsizei width
, GLsizei height
,
335 GLenum format
, GLenum type
,
336 const GLvoid
*pixels
);
338 extern void GLAPIENTRY
339 _mesa_TextureSubImage2D(GLuint texture
, GLint level
,
340 GLint xoffset
, GLint yoffset
,
341 GLsizei width
, GLsizei height
,
342 GLenum format
, GLenum type
,
343 const GLvoid
*pixels
);
346 _mesa_TextureSubImage3D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
347 GLint yoffset
, GLint zoffset
, GLsizei width
,
348 GLsizei height
, GLsizei depth
, GLenum format
,
349 GLenum type
, const GLvoid
*pixels
);
351 extern void GLAPIENTRY
352 _mesa_TextureSubImage3D(GLuint texture
, GLint level
,
353 GLint xoffset
, GLint yoffset
, GLint zoffset
,
354 GLsizei width
, GLsizei height
, GLsizei depth
,
355 GLenum format
, GLenum type
,
356 const GLvoid
*pixels
);
359 extern void GLAPIENTRY
360 _mesa_CopyTexImage1D(GLenum target
, GLint level
, GLenum internalformat
,
361 GLint x
, GLint y
, GLsizei width
, GLint border
);
364 extern void GLAPIENTRY
365 _mesa_CopyTexImage2D( GLenum target
, GLint level
,
366 GLenum internalformat
, GLint x
, GLint y
,
367 GLsizei width
, GLsizei height
, GLint border
);
370 extern void GLAPIENTRY
371 _mesa_CopyTexImage1D_no_error(GLenum target
, GLint level
, GLenum internalformat
,
372 GLint x
, GLint y
, GLsizei width
, GLint border
);
375 extern void GLAPIENTRY
376 _mesa_CopyTexImage2D_no_error(GLenum target
, GLint level
, GLenum internalformat
,
377 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
381 extern void GLAPIENTRY
382 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
, GLint xoffset
,
383 GLint x
, GLint y
, GLsizei width
);
386 extern void GLAPIENTRY
387 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
388 GLint xoffset
, GLint yoffset
,
389 GLint x
, GLint y
, GLsizei width
, GLsizei height
);
392 extern void GLAPIENTRY
393 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
394 GLint xoffset
, GLint yoffset
, GLint zoffset
,
395 GLint x
, GLint y
, GLsizei width
, GLsizei height
);
397 extern void GLAPIENTRY
398 _mesa_CopyTextureSubImage1D(GLuint texture
, GLint level
,
399 GLint xoffset
, GLint x
, GLint y
, GLsizei width
);
401 extern void GLAPIENTRY
402 _mesa_CopyTextureSubImage2D(GLuint texture
, GLint level
,
403 GLint xoffset
, GLint yoffset
,
405 GLsizei width
, GLsizei height
);
407 extern void GLAPIENTRY
408 _mesa_CopyTextureSubImage3D(GLuint texture
, GLint level
,
409 GLint xoffset
, GLint yoffset
, GLint zoffset
,
411 GLsizei width
, GLsizei height
);
413 extern void GLAPIENTRY
414 _mesa_CopyTexSubImage1D_no_error(GLenum target
, GLint level
, GLint xoffset
,
415 GLint x
, GLint y
, GLsizei width
);
417 extern void GLAPIENTRY
418 _mesa_CopyTexSubImage2D_no_error(GLenum target
, GLint level
, GLint xoffset
,
419 GLint yoffset
, GLint x
, GLint y
, GLsizei width
,
422 extern void GLAPIENTRY
423 _mesa_CopyTexSubImage3D_no_error(GLenum target
, GLint level
, GLint xoffset
,
424 GLint yoffset
, GLint zoffset
, GLint x
, GLint y
,
425 GLsizei width
, GLsizei height
);
427 extern void GLAPIENTRY
428 _mesa_CopyTextureSubImage1D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
429 GLint x
, GLint y
, GLsizei width
);
431 extern void GLAPIENTRY
432 _mesa_CopyTextureSubImage2D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
433 GLint yoffset
, GLint x
, GLint y
,
434 GLsizei width
, GLsizei height
);
436 extern void GLAPIENTRY
437 _mesa_CopyTextureSubImage3D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
438 GLint yoffset
, GLint zoffset
, GLint x
,
439 GLint y
, GLsizei width
, GLsizei height
);
441 extern void GLAPIENTRY
442 _mesa_ClearTexSubImage( GLuint texture
, GLint level
,
443 GLint xoffset
, GLint yoffset
, GLint zoffset
,
444 GLsizei width
, GLsizei height
, GLsizei depth
,
445 GLenum format
, GLenum type
, const void *data
);
447 extern void GLAPIENTRY
448 _mesa_ClearTexImage( GLuint texture
, GLint level
,
449 GLenum format
, GLenum type
, const void *data
);
451 extern void GLAPIENTRY
452 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
453 GLenum internalformat
, GLsizei width
,
454 GLint border
, GLsizei imageSize
,
457 extern void GLAPIENTRY
458 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
459 GLenum internalformat
, GLsizei width
,
460 GLsizei height
, GLint border
, GLsizei imageSize
,
463 extern void GLAPIENTRY
464 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
465 GLenum internalformat
, GLsizei width
,
466 GLsizei height
, GLsizei depth
, GLint border
,
467 GLsizei imageSize
, const GLvoid
*data
);
469 extern void GLAPIENTRY
470 _mesa_CompressedTexImage1D_no_error(GLenum target
, GLint level
,
471 GLenum internalformat
, GLsizei width
,
472 GLint border
, GLsizei imageSize
,
475 extern void GLAPIENTRY
476 _mesa_CompressedTexImage2D_no_error(GLenum target
, GLint level
,
477 GLenum internalformat
, GLsizei width
,
478 GLsizei height
, GLint border
,
479 GLsizei imageSize
, const GLvoid
*data
);
481 extern void GLAPIENTRY
482 _mesa_CompressedTexImage3D_no_error(GLenum target
, GLint level
,
483 GLenum internalformat
, GLsizei width
,
484 GLsizei height
, GLsizei depth
, GLint border
,
485 GLsizei imageSize
, const GLvoid
*data
);
488 extern void GLAPIENTRY
489 _mesa_CompressedTexSubImage1D_no_error(GLenum target
, GLint level
,
490 GLint xoffset
, GLsizei width
,
491 GLenum format
, GLsizei imageSize
,
493 extern void GLAPIENTRY
494 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
495 GLsizei width
, GLenum format
,
496 GLsizei imageSize
, const GLvoid
*data
);
498 extern void GLAPIENTRY
499 _mesa_CompressedTextureSubImage1D_no_error(GLuint texture
, GLint level
,
500 GLint xoffset
, GLsizei width
,
501 GLenum format
, GLsizei imageSize
,
503 extern void GLAPIENTRY
504 _mesa_CompressedTextureSubImage1D(GLuint texture
, GLint level
, GLint xoffset
,
505 GLsizei width
, GLenum format
,
506 GLsizei imageSize
, const GLvoid
*data
);
508 extern void GLAPIENTRY
509 _mesa_CompressedTexSubImage2D_no_error(GLenum target
, GLint level
,
510 GLint xoffset
, GLint yoffset
,
511 GLsizei width
, GLsizei height
,
512 GLenum format
, GLsizei imageSize
,
514 extern void GLAPIENTRY
515 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
516 GLint yoffset
, GLsizei width
, GLsizei height
,
517 GLenum format
, GLsizei imageSize
,
520 extern void GLAPIENTRY
521 _mesa_CompressedTextureSubImage2D_no_error(GLuint texture
, GLint level
,
522 GLint xoffset
, GLint yoffset
,
523 GLsizei width
, GLsizei height
,
524 GLenum format
, GLsizei imageSize
,
526 extern void GLAPIENTRY
527 _mesa_CompressedTextureSubImage2D(GLuint texture
, GLint level
, GLint xoffset
,
529 GLsizei width
, GLsizei height
,
530 GLenum format
, GLsizei imageSize
,
533 extern void GLAPIENTRY
534 _mesa_CompressedTexSubImage3D_no_error(GLenum target
, GLint level
,
535 GLint xoffset
, GLint yoffset
,
536 GLint zoffset
, GLsizei width
,
537 GLsizei height
, GLsizei depth
,
538 GLenum format
, GLsizei imageSize
,
540 extern void GLAPIENTRY
541 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
542 GLint yoffset
, GLint zoffset
, GLsizei width
,
543 GLsizei height
, GLsizei depth
, GLenum format
,
544 GLsizei imageSize
, const GLvoid
*data
);
546 extern void GLAPIENTRY
547 _mesa_CompressedTextureSubImage3D_no_error(GLuint texture
, GLint level
,
548 GLint xoffset
, GLint yoffset
,
549 GLint zoffset
, GLsizei width
,
550 GLsizei height
, GLsizei depth
,
551 GLenum format
, GLsizei imageSize
,
553 extern void GLAPIENTRY
554 _mesa_CompressedTextureSubImage3D(GLuint texture
, GLint level
, GLint xoffset
,
555 GLint yoffset
, GLint zoffset
,
556 GLsizei width
, GLsizei height
,
558 GLenum format
, GLsizei imageSize
,
561 extern void GLAPIENTRY
562 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
);
564 extern void GLAPIENTRY
565 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
566 GLintptr offset
, GLsizeiptr size
);
568 extern void GLAPIENTRY
569 _mesa_TextureBuffer(GLuint texture
, GLenum internalFormat
, GLuint buffer
);
571 extern void GLAPIENTRY
572 _mesa_TextureBufferRange(GLuint texture
, GLenum internalFormat
, GLuint buffer
,
573 GLintptr offset
, GLsizeiptr size
);
576 extern void GLAPIENTRY
577 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
578 GLenum internalformat
, GLsizei width
,
579 GLsizei height
, GLboolean fixedsamplelocations
);
581 extern void GLAPIENTRY
582 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
583 GLenum internalformat
, GLsizei width
,
584 GLsizei height
, GLsizei depth
,
585 GLboolean fixedsamplelocations
);
587 extern void GLAPIENTRY
588 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
589 GLenum internalformat
, GLsizei width
,
590 GLsizei height
, GLboolean fixedsamplelocations
);
592 extern void GLAPIENTRY
593 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
594 GLenum internalformat
, GLsizei width
,
595 GLsizei height
, GLsizei depth
,
596 GLboolean fixedsamplelocations
);
599 _mesa_TextureStorage2DMultisample(GLuint texture
, GLsizei samples
,
600 GLenum internalformat
, GLsizei width
,
602 GLboolean fixedsamplelocations
);
605 _mesa_TextureStorage3DMultisample(GLuint texture
, GLsizei samples
,
606 GLenum internalformat
, GLsizei width
,
607 GLsizei height
, GLsizei depth
,
608 GLboolean fixedsamplelocations
);