3 * Texture object management.
7 * Mesa 3-D graphics library
9 * Copyright (C) 1999-2006 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.
38 #include "samplerobj.h"
42 * \name Internal functions
46 extern struct gl_texture_object
*
47 _mesa_lookup_texture(struct gl_context
*ctx
, GLuint id
);
49 extern struct gl_texture_object
*
50 _mesa_new_texture_object( struct gl_context
*ctx
, GLuint name
, GLenum target
);
53 _mesa_initialize_texture_object( struct gl_context
*ctx
,
54 struct gl_texture_object
*obj
,
55 GLuint name
, GLenum target
);
58 _mesa_tex_target_to_index(const struct gl_context
*ctx
, GLenum target
);
61 _mesa_delete_texture_object( struct gl_context
*ctx
,
62 struct gl_texture_object
*obj
);
65 _mesa_copy_texture_object( struct gl_texture_object
*dest
,
66 const struct gl_texture_object
*src
);
69 _mesa_clear_texture_object(struct gl_context
*ctx
,
70 struct gl_texture_object
*obj
);
73 _mesa_reference_texobj_(struct gl_texture_object
**ptr
,
74 struct gl_texture_object
*tex
);
77 _mesa_reference_texobj(struct gl_texture_object
**ptr
,
78 struct gl_texture_object
*tex
)
81 _mesa_reference_texobj_(ptr
, tex
);
86 * Return number of faces for a texture target. This will be 6 for
87 * cube maps (and cube map arrays) and 1 otherwise.
88 * NOTE: this function is not used for cube map arrays which operate
89 * more like 2D arrays than cube maps.
92 _mesa_num_tex_faces(GLenum target
)
95 case GL_TEXTURE_CUBE_MAP
:
96 case GL_PROXY_TEXTURE_CUBE_MAP
:
104 /** Is the texture "complete" with respect to the given sampler state? */
105 static inline GLboolean
106 _mesa_is_texture_complete(const struct gl_texture_object
*texObj
,
107 const struct gl_sampler_object
*sampler
)
109 if (texObj
->_IsIntegerFormat
&&
110 (sampler
->MagFilter
!= GL_NEAREST
||
111 (sampler
->MinFilter
!= GL_NEAREST
&&
112 sampler
->MinFilter
!= GL_NEAREST_MIPMAP_NEAREST
))) {
113 /* If the format is integer, only nearest filtering is allowed */
117 /* From the ARB_stencil_texturing specification:
118 * "Add a new bullet point for the conditions that cause the texture
119 * to not be complete:
121 * * The internal format of the texture is DEPTH_STENCIL, the
122 * DEPTH_STENCIL_TEXTURE_MODE for the texture is STENCIL_INDEX and either
123 * the magnification filter or the minification filter is not NEAREST."
125 if (texObj
->StencilSampling
&&
126 texObj
->Image
[0][texObj
->BaseLevel
]->_BaseFormat
== GL_DEPTH_STENCIL
&&
127 (sampler
->MagFilter
!= GL_NEAREST
|| sampler
->MinFilter
!= GL_NEAREST
)) {
131 if (_mesa_is_mipmap_filter(sampler
))
132 return texObj
->_MipmapComplete
;
134 return texObj
->_BaseComplete
;
139 _mesa_test_texobj_completeness( const struct gl_context
*ctx
,
140 struct gl_texture_object
*obj
);
143 _mesa_cube_complete(const struct gl_texture_object
*texObj
);
146 _mesa_dirty_texobj(struct gl_context
*ctx
, struct gl_texture_object
*texObj
);
148 extern struct gl_texture_object
*
149 _mesa_get_fallback_texture(struct gl_context
*ctx
, gl_texture_index tex
);
152 _mesa_total_texture_memory(struct gl_context
*ctx
);
155 _mesa_unlock_context_textures( struct gl_context
*ctx
);
158 _mesa_lock_context_textures( struct gl_context
*ctx
);
163 * \name API functions
167 extern void GLAPIENTRY
168 _mesa_GenTextures( GLsizei n
, GLuint
*textures
);
171 extern void GLAPIENTRY
172 _mesa_DeleteTextures( GLsizei n
, const GLuint
*textures
);
175 extern void GLAPIENTRY
176 _mesa_BindTexture( GLenum target
, GLuint texture
);
179 extern void GLAPIENTRY
180 _mesa_PrioritizeTextures( GLsizei n
, const GLuint
*textures
,
181 const GLclampf
*priorities
);
184 extern GLboolean GLAPIENTRY
185 _mesa_AreTexturesResident( GLsizei n
, const GLuint
*textures
,
186 GLboolean
*residences
);
188 extern GLboolean GLAPIENTRY
189 _mesa_IsTexture( GLuint texture
);
191 extern void GLAPIENTRY
192 _mesa_InvalidateTexSubImage(GLuint texture
, GLint level
, GLint xoffset
,
193 GLint yoffset
, GLint zoffset
, GLsizei width
,
194 GLsizei height
, GLsizei depth
);
196 extern void GLAPIENTRY
197 _mesa_InvalidateTexImage(GLuint texture
, GLint level
);