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"
47 * \name Internal functions
51 extern struct gl_texture_object
*
52 _mesa_lookup_texture(struct gl_context
*ctx
, GLuint id
);
54 extern struct gl_texture_object
*
55 _mesa_lookup_texture_err(struct gl_context
*ctx
, GLuint id
, const char* func
);
58 _mesa_begin_texture_lookups(struct gl_context
*ctx
);
61 _mesa_end_texture_lookups(struct gl_context
*ctx
);
63 extern struct gl_texture_object
*
64 _mesa_lookup_texture_locked(struct gl_context
*ctx
, GLuint id
);
66 extern struct gl_texture_object
*
67 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
);
69 extern struct gl_texture_object
*
70 _mesa_new_texture_object( struct gl_context
*ctx
, GLuint name
, GLenum target
);
73 _mesa_initialize_texture_object( struct gl_context
*ctx
,
74 struct gl_texture_object
*obj
,
75 GLuint name
, GLenum target
);
78 _mesa_tex_target_to_index(const struct gl_context
*ctx
, GLenum target
);
81 _mesa_delete_texture_object( struct gl_context
*ctx
,
82 struct gl_texture_object
*obj
);
85 _mesa_copy_texture_object( struct gl_texture_object
*dest
,
86 const struct gl_texture_object
*src
);
89 _mesa_clear_texture_object(struct gl_context
*ctx
,
90 struct gl_texture_object
*obj
);
93 _mesa_reference_texobj_(struct gl_texture_object
**ptr
,
94 struct gl_texture_object
*tex
);
97 _mesa_reference_texobj(struct gl_texture_object
**ptr
,
98 struct gl_texture_object
*tex
)
101 _mesa_reference_texobj_(ptr
, tex
);
105 * Lock a texture for updating. See also _mesa_lock_context_textures().
108 _mesa_lock_texture(struct gl_context
*ctx
, struct gl_texture_object
*texObj
)
110 mtx_lock(&ctx
->Shared
->TexMutex
);
111 ctx
->Shared
->TextureStateStamp
++;
116 _mesa_unlock_texture(struct gl_context
*ctx
, struct gl_texture_object
*texObj
)
119 mtx_unlock(&ctx
->Shared
->TexMutex
);
124 * Return number of faces for a texture target. This will be 6 for
125 * cube maps (and cube map arrays) and 1 otherwise.
126 * NOTE: this function is not used for cube map arrays which operate
127 * more like 2D arrays than cube maps.
130 _mesa_num_tex_faces(GLenum target
)
133 case GL_TEXTURE_CUBE_MAP
:
134 case GL_PROXY_TEXTURE_CUBE_MAP
:
142 /** Is the texture "complete" with respect to the given sampler state? */
143 static inline GLboolean
144 _mesa_is_texture_complete(const struct gl_texture_object
*texObj
,
145 const struct gl_sampler_object
*sampler
)
147 if (texObj
->_IsIntegerFormat
&&
148 (sampler
->MagFilter
!= GL_NEAREST
||
149 (sampler
->MinFilter
!= GL_NEAREST
&&
150 sampler
->MinFilter
!= GL_NEAREST_MIPMAP_NEAREST
))) {
151 /* If the format is integer, only nearest filtering is allowed */
155 /* From the ARB_stencil_texturing specification:
156 * "Add a new bullet point for the conditions that cause the texture
157 * to not be complete:
159 * * The internal format of the texture is DEPTH_STENCIL, the
160 * DEPTH_STENCIL_TEXTURE_MODE for the texture is STENCIL_INDEX and either
161 * the magnification filter or the minification filter is not NEAREST."
163 if (texObj
->StencilSampling
&&
164 texObj
->Image
[0][texObj
->BaseLevel
]->_BaseFormat
== GL_DEPTH_STENCIL
&&
165 (sampler
->MagFilter
!= GL_NEAREST
|| sampler
->MinFilter
!= GL_NEAREST
)) {
169 if (_mesa_is_mipmap_filter(sampler
))
170 return texObj
->_MipmapComplete
;
172 return texObj
->_BaseComplete
;
177 _mesa_test_texobj_completeness( const struct gl_context
*ctx
,
178 struct gl_texture_object
*obj
);
181 _mesa_cube_level_complete(const struct gl_texture_object
*texObj
,
185 _mesa_cube_complete(const struct gl_texture_object
*texObj
);
188 _mesa_dirty_texobj(struct gl_context
*ctx
, struct gl_texture_object
*texObj
);
190 extern struct gl_texture_object
*
191 _mesa_get_fallback_texture(struct gl_context
*ctx
, gl_texture_index tex
);
194 _mesa_total_texture_memory(struct gl_context
*ctx
);
197 _mesa_texture_base_format(const struct gl_texture_object
*texObj
);
200 _mesa_unlock_context_textures( struct gl_context
*ctx
);
203 _mesa_lock_context_textures( struct gl_context
*ctx
);
205 extern struct gl_texture_object
*
206 _mesa_create_nameless_texture(struct gl_context
*ctx
, GLenum target
);
209 _mesa_delete_nameless_texture(struct gl_context
*ctx
,
210 struct gl_texture_object
*texObj
);
216 * \name API functions
220 extern void GLAPIENTRY
221 _mesa_GenTextures(GLsizei n
, GLuint
*textures
);
223 extern void GLAPIENTRY
224 _mesa_CreateTextures(GLenum target
, GLsizei n
, GLuint
*textures
);
226 extern void GLAPIENTRY
227 _mesa_DeleteTextures( GLsizei n
, const GLuint
*textures
);
230 extern void GLAPIENTRY
231 _mesa_BindTexture( GLenum target
, GLuint texture
);
233 extern void GLAPIENTRY
234 _mesa_BindTextureUnit(GLuint unit
, GLuint texture
);
236 extern void GLAPIENTRY
237 _mesa_BindTextures( GLuint first
, GLsizei count
, const GLuint
*textures
);
240 extern void GLAPIENTRY
241 _mesa_PrioritizeTextures( GLsizei n
, const GLuint
*textures
,
242 const GLclampf
*priorities
);
245 extern GLboolean GLAPIENTRY
246 _mesa_AreTexturesResident( GLsizei n
, const GLuint
*textures
,
247 GLboolean
*residences
);
249 extern GLboolean GLAPIENTRY
250 _mesa_IsTexture( GLuint texture
);
252 extern void GLAPIENTRY
253 _mesa_InvalidateTexSubImage(GLuint texture
, GLint level
, GLint xoffset
,
254 GLint yoffset
, GLint zoffset
, GLsizei width
,
255 GLsizei height
, GLsizei depth
);
257 extern void GLAPIENTRY
258 _mesa_InvalidateTexImage(GLuint texture
, GLint level
);