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.
36 #include "samplerobj.h"
45 * \name Internal functions
49 extern struct gl_texture_object
*
50 _mesa_lookup_texture(struct gl_context
*ctx
, GLuint id
);
52 extern struct gl_texture_object
*
53 _mesa_lookup_texture_err(struct gl_context
*ctx
, GLuint id
, const char* func
);
55 extern struct gl_texture_object
*
56 _mesa_lookup_texture_locked(struct gl_context
*ctx
, GLuint id
);
58 extern struct gl_texture_object
*
59 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
);
61 extern struct gl_texture_object
*
62 _mesa_new_texture_object( struct gl_context
*ctx
, GLuint name
, GLenum target
);
65 _mesa_initialize_texture_object( struct gl_context
*ctx
,
66 struct gl_texture_object
*obj
,
67 GLuint name
, GLenum target
);
70 _mesa_tex_target_to_index(const struct gl_context
*ctx
, GLenum target
);
73 _mesa_delete_texture_object( struct gl_context
*ctx
,
74 struct gl_texture_object
*obj
);
77 _mesa_copy_texture_object( struct gl_texture_object
*dest
,
78 const struct gl_texture_object
*src
);
81 _mesa_clear_texture_object(struct gl_context
*ctx
,
82 struct gl_texture_object
*obj
,
83 struct gl_texture_image
*retainTexImage
);
86 _mesa_reference_texobj_(struct gl_texture_object
**ptr
,
87 struct gl_texture_object
*tex
);
90 _mesa_reference_texobj(struct gl_texture_object
**ptr
,
91 struct gl_texture_object
*tex
)
94 _mesa_reference_texobj_(ptr
, tex
);
98 * Lock a texture for updating. See also _mesa_lock_context_textures().
101 _mesa_lock_texture(struct gl_context
*ctx
, struct gl_texture_object
*texObj
)
103 mtx_lock(&ctx
->Shared
->TexMutex
);
104 ctx
->Shared
->TextureStateStamp
++;
109 _mesa_unlock_texture(struct gl_context
*ctx
, struct gl_texture_object
*texObj
)
112 mtx_unlock(&ctx
->Shared
->TexMutex
);
116 /** Is the texture "complete" with respect to the given sampler state? */
117 static inline GLboolean
118 _mesa_is_texture_complete(const struct gl_texture_object
*texObj
,
119 const struct gl_sampler_object
*sampler
)
122 * According to ARB_stencil_texturing, NEAREST_MIPMAP_NEAREST would
123 * be forbidden, however it is allowed per GL 4.5 rules, allow it
124 * even without GL 4.5 since it was a spec mistake.
126 if ((texObj
->_IsIntegerFormat
||
127 (texObj
->StencilSampling
&&
128 texObj
->Image
[0][texObj
->BaseLevel
]->_BaseFormat
== GL_DEPTH_STENCIL
)) &&
129 (sampler
->MagFilter
!= GL_NEAREST
||
130 (sampler
->MinFilter
!= GL_NEAREST
&&
131 sampler
->MinFilter
!= GL_NEAREST_MIPMAP_NEAREST
))) {
132 /* If the format is integer, only nearest filtering is allowed */
136 if (_mesa_is_mipmap_filter(sampler
))
137 return texObj
->_MipmapComplete
;
139 return texObj
->_BaseComplete
;
144 _mesa_test_texobj_completeness( const struct gl_context
*ctx
,
145 struct gl_texture_object
*obj
);
148 _mesa_cube_level_complete(const struct gl_texture_object
*texObj
,
152 _mesa_cube_complete(const struct gl_texture_object
*texObj
);
155 _mesa_dirty_texobj(struct gl_context
*ctx
, struct gl_texture_object
*texObj
);
157 extern struct gl_texture_object
*
158 _mesa_get_fallback_texture(struct gl_context
*ctx
, gl_texture_index tex
);
161 _mesa_total_texture_memory(struct gl_context
*ctx
);
164 _mesa_texture_base_format(const struct gl_texture_object
*texObj
);
167 _mesa_unlock_context_textures( struct gl_context
*ctx
);
170 _mesa_lock_context_textures( struct gl_context
*ctx
);
173 _mesa_delete_nameless_texture(struct gl_context
*ctx
,
174 struct gl_texture_object
*texObj
);
177 _mesa_bind_texture(struct gl_context
*ctx
, GLenum target
,
178 struct gl_texture_object
*tex_obj
);
182 * \name API functions
187 _mesa_GenTextures_no_error(GLsizei n
, GLuint
*textures
);
189 extern void GLAPIENTRY
190 _mesa_GenTextures(GLsizei n
, GLuint
*textures
);
193 _mesa_CreateTextures_no_error(GLenum target
, GLsizei n
, GLuint
*textures
);
195 extern void GLAPIENTRY
196 _mesa_CreateTextures(GLenum target
, GLsizei n
, GLuint
*textures
);
199 _mesa_DeleteTextures_no_error(GLsizei n
, const GLuint
*textures
);
201 extern void GLAPIENTRY
202 _mesa_DeleteTextures( GLsizei n
, const GLuint
*textures
);
206 _mesa_BindTexture_no_error(GLenum target
, GLuint texture
);
208 extern void GLAPIENTRY
209 _mesa_BindTexture( GLenum target
, GLuint texture
);
212 _mesa_BindTextureUnit_no_error(GLuint unit
, GLuint texture
);
214 extern void GLAPIENTRY
215 _mesa_BindTextureUnit(GLuint unit
, GLuint texture
);
218 _mesa_BindTextures_no_error(GLuint first
, GLsizei count
,
219 const GLuint
*textures
);
221 extern void GLAPIENTRY
222 _mesa_BindTextures( GLuint first
, GLsizei count
, const GLuint
*textures
);
225 extern void GLAPIENTRY
226 _mesa_PrioritizeTextures( GLsizei n
, const GLuint
*textures
,
227 const GLclampf
*priorities
);
230 extern GLboolean GLAPIENTRY
231 _mesa_AreTexturesResident( GLsizei n
, const GLuint
*textures
,
232 GLboolean
*residences
);
234 extern GLboolean GLAPIENTRY
235 _mesa_IsTexture( GLuint texture
);
238 _mesa_InvalidateTexSubImage_no_error(GLuint texture
, GLint level
, GLint xoffset
,
239 GLint yoffset
, GLint zoffset
,
240 GLsizei width
, GLsizei height
,
243 extern void GLAPIENTRY
244 _mesa_InvalidateTexSubImage(GLuint texture
, GLint level
, GLint xoffset
,
245 GLint yoffset
, GLint zoffset
, GLsizei width
,
246 GLsizei height
, GLsizei depth
);
248 _mesa_InvalidateTexImage_no_error(GLuint texture
, GLint level
);
250 extern void GLAPIENTRY
251 _mesa_InvalidateTexImage(GLuint texture
, GLint level
);