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_get_texobj_by_target_and_texunit(struct gl_context
*ctx
, GLenum target
,
64 bool allowProxyTargets
,
67 extern struct gl_texture_object
*
68 _mesa_new_texture_object( struct gl_context
*ctx
, GLuint name
, GLenum target
);
71 _mesa_initialize_texture_object( struct gl_context
*ctx
,
72 struct gl_texture_object
*obj
,
73 GLuint name
, GLenum target
);
76 _mesa_tex_target_to_index(const struct gl_context
*ctx
, GLenum target
);
79 _mesa_delete_texture_object( struct gl_context
*ctx
,
80 struct gl_texture_object
*obj
);
83 _mesa_copy_texture_object( struct gl_texture_object
*dest
,
84 const struct gl_texture_object
*src
);
87 _mesa_clear_texture_object(struct gl_context
*ctx
,
88 struct gl_texture_object
*obj
,
89 struct gl_texture_image
*retainTexImage
);
92 _mesa_reference_texobj_(struct gl_texture_object
**ptr
,
93 struct gl_texture_object
*tex
);
96 _mesa_reference_texobj(struct gl_texture_object
**ptr
,
97 struct gl_texture_object
*tex
)
100 _mesa_reference_texobj_(ptr
, tex
);
104 * Lock a texture for updating. See also _mesa_lock_context_textures().
107 _mesa_lock_texture(struct gl_context
*ctx
, struct gl_texture_object
*texObj
)
109 mtx_lock(&ctx
->Shared
->TexMutex
);
110 ctx
->Shared
->TextureStateStamp
++;
115 _mesa_unlock_texture(struct gl_context
*ctx
, struct gl_texture_object
*texObj
)
118 mtx_unlock(&ctx
->Shared
->TexMutex
);
122 /** Is the texture "complete" with respect to the given sampler state? */
123 static inline GLboolean
124 _mesa_is_texture_complete(const struct gl_texture_object
*texObj
,
125 const struct gl_sampler_object
*sampler
)
127 struct gl_texture_image
*img
= texObj
->Image
[0][texObj
->BaseLevel
];
128 bool isMultisample
= img
&& img
->NumSamples
>= 2;
131 * According to ARB_stencil_texturing, NEAREST_MIPMAP_NEAREST would
132 * be forbidden, however it is allowed per GL 4.5 rules, allow it
133 * even without GL 4.5 since it was a spec mistake.
135 /* Section 8.17 (texture completeness) of the OpenGL 4.6 core profile spec:
137 * "The texture is not multisample; either the magnification filter is not
138 * NEAREST, or the minification filter is neither NEAREST nor NEAREST_-
139 * MIPMAP_NEAREST; and any of
140 * – The internal format of the texture is integer.
141 * – The internal format is STENCIL_INDEX.
142 * – The internal format is DEPTH_STENCIL, and the value of DEPTH_-
143 * STENCIL_TEXTURE_MODE for the texture is STENCIL_INDEX.""
145 if (!isMultisample
&&
146 (texObj
->_IsIntegerFormat
||
147 (texObj
->StencilSampling
&&
148 img
->_BaseFormat
== GL_DEPTH_STENCIL
)) &&
149 (sampler
->MagFilter
!= GL_NEAREST
||
150 (sampler
->MinFilter
!= GL_NEAREST
&&
151 sampler
->MinFilter
!= GL_NEAREST_MIPMAP_NEAREST
))) {
152 /* If the format is integer, only nearest filtering is allowed */
156 /* Section 8.17 (texture completeness) of the OpenGL 4.6 core profile spec:
158 * "The minification filter requires a mipmap (is neither NEAREST nor LINEAR),
159 * the texture is not multisample, and the texture is not mipmap complete.""
161 if (!isMultisample
&&_mesa_is_mipmap_filter(sampler
))
162 return texObj
->_MipmapComplete
;
164 return texObj
->_BaseComplete
;
169 _mesa_test_texobj_completeness( const struct gl_context
*ctx
,
170 struct gl_texture_object
*obj
);
173 _mesa_cube_level_complete(const struct gl_texture_object
*texObj
,
177 _mesa_cube_complete(const struct gl_texture_object
*texObj
);
180 _mesa_dirty_texobj(struct gl_context
*ctx
, struct gl_texture_object
*texObj
);
182 extern struct gl_texture_object
*
183 _mesa_get_fallback_texture(struct gl_context
*ctx
, gl_texture_index tex
);
186 _mesa_total_texture_memory(struct gl_context
*ctx
);
189 _mesa_texture_base_format(const struct gl_texture_object
*texObj
);
192 _mesa_unlock_context_textures( struct gl_context
*ctx
);
195 _mesa_lock_context_textures( struct gl_context
*ctx
);
198 _mesa_delete_nameless_texture(struct gl_context
*ctx
,
199 struct gl_texture_object
*texObj
);
202 _mesa_bind_texture(struct gl_context
*ctx
, GLenum target
,
203 struct gl_texture_object
*tex_obj
);
205 extern struct gl_texture_object
*
206 _mesa_lookup_or_create_texture(struct gl_context
*ctx
, GLenum target
,
207 GLuint texName
, bool no_error
, bool is_ext_dsa
,
213 * \name API functions
218 _mesa_GenTextures_no_error(GLsizei n
, GLuint
*textures
);
220 extern void GLAPIENTRY
221 _mesa_GenTextures(GLsizei n
, GLuint
*textures
);
224 _mesa_CreateTextures_no_error(GLenum target
, GLsizei n
, GLuint
*textures
);
226 extern void GLAPIENTRY
227 _mesa_CreateTextures(GLenum target
, GLsizei n
, GLuint
*textures
);
230 _mesa_DeleteTextures_no_error(GLsizei n
, const GLuint
*textures
);
232 extern void GLAPIENTRY
233 _mesa_DeleteTextures( GLsizei n
, const GLuint
*textures
);
237 _mesa_BindTexture_no_error(GLenum target
, GLuint texture
);
239 extern void GLAPIENTRY
240 _mesa_BindTexture( GLenum target
, GLuint texture
);
243 _mesa_BindMultiTextureEXT(GLenum texunit
, GLenum target
, GLuint texture
);
246 _mesa_BindTextureUnit_no_error(GLuint unit
, GLuint texture
);
248 extern void GLAPIENTRY
249 _mesa_BindTextureUnit(GLuint unit
, GLuint texture
);
252 _mesa_BindTextures_no_error(GLuint first
, GLsizei count
,
253 const GLuint
*textures
);
255 extern void GLAPIENTRY
256 _mesa_BindTextures( GLuint first
, GLsizei count
, const GLuint
*textures
);
259 extern void GLAPIENTRY
260 _mesa_PrioritizeTextures( GLsizei n
, const GLuint
*textures
,
261 const GLclampf
*priorities
);
264 extern GLboolean GLAPIENTRY
265 _mesa_AreTexturesResident( GLsizei n
, const GLuint
*textures
,
266 GLboolean
*residences
);
268 extern GLboolean GLAPIENTRY
269 _mesa_IsTexture( GLuint texture
);
272 _mesa_InvalidateTexSubImage_no_error(GLuint texture
, GLint level
, GLint xoffset
,
273 GLint yoffset
, GLint zoffset
,
274 GLsizei width
, GLsizei height
,
277 extern void GLAPIENTRY
278 _mesa_InvalidateTexSubImage(GLuint texture
, GLint level
, GLint xoffset
,
279 GLint yoffset
, GLint zoffset
, GLsizei width
,
280 GLsizei height
, GLsizei depth
);
282 _mesa_InvalidateTexImage_no_error(GLuint texture
, GLint level
);
284 extern void GLAPIENTRY
285 _mesa_InvalidateTexImage(GLuint texture
, GLint level
);