mesa: update fallthrough comment so gcc can see it
[mesa.git] / src / mesa / main / texobj.h
1 /**
2 * \file texobj.h
3 * Texture object management.
4 */
5
6 /*
7 * Mesa 3-D graphics library
8 *
9 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
10 *
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:
17 *
18 * The above copyright notice and this permission notice shall be included
19 * in all copies or substantial portions of the Software.
20 *
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.
28 */
29
30
31 #ifndef TEXTOBJ_H
32 #define TEXTOBJ_H
33
34
35 #include "glheader.h"
36 #include "samplerobj.h"
37
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43
44 /**
45 * \name Internal functions
46 */
47 /*@{*/
48
49 extern struct gl_texture_object *
50 _mesa_lookup_texture(struct gl_context *ctx, GLuint id);
51
52 extern struct gl_texture_object *
53 _mesa_lookup_texture_err(struct gl_context *ctx, GLuint id, const char* func);
54
55 extern struct gl_texture_object *
56 _mesa_lookup_texture_locked(struct gl_context *ctx, GLuint id);
57
58 extern struct gl_texture_object *
59 _mesa_get_current_tex_object(struct gl_context *ctx, GLenum target);
60
61 extern struct gl_texture_object *
62 _mesa_get_texobj_by_target_and_texunit(struct gl_context *ctx, GLenum target,
63 GLuint texunit,
64 bool allowProxyTargets,
65 const char* caller);
66
67 extern struct gl_texture_object *
68 _mesa_new_texture_object( struct gl_context *ctx, GLuint name, GLenum target );
69
70 extern void
71 _mesa_initialize_texture_object( struct gl_context *ctx,
72 struct gl_texture_object *obj,
73 GLuint name, GLenum target );
74
75 extern int
76 _mesa_tex_target_to_index(const struct gl_context *ctx, GLenum target);
77
78 extern void
79 _mesa_delete_texture_object( struct gl_context *ctx,
80 struct gl_texture_object *obj );
81
82 extern void
83 _mesa_copy_texture_object( struct gl_texture_object *dest,
84 const struct gl_texture_object *src );
85
86 extern void
87 _mesa_clear_texture_object(struct gl_context *ctx,
88 struct gl_texture_object *obj,
89 struct gl_texture_image *retainTexImage);
90
91 extern void
92 _mesa_reference_texobj_(struct gl_texture_object **ptr,
93 struct gl_texture_object *tex);
94
95 static inline void
96 _mesa_reference_texobj(struct gl_texture_object **ptr,
97 struct gl_texture_object *tex)
98 {
99 if (*ptr != tex)
100 _mesa_reference_texobj_(ptr, tex);
101 }
102
103 /**
104 * Lock a texture for updating. See also _mesa_lock_context_textures().
105 */
106 static inline void
107 _mesa_lock_texture(struct gl_context *ctx, struct gl_texture_object *texObj)
108 {
109 mtx_lock(&ctx->Shared->TexMutex);
110 ctx->Shared->TextureStateStamp++;
111 (void) texObj;
112 }
113
114 static inline void
115 _mesa_unlock_texture(struct gl_context *ctx, struct gl_texture_object *texObj)
116 {
117 (void) texObj;
118 mtx_unlock(&ctx->Shared->TexMutex);
119 }
120
121
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,
126 bool linear_as_nearest_for_int_tex)
127 {
128 struct gl_texture_image *img = texObj->Image[0][texObj->BaseLevel];
129 bool isMultisample = img && img->NumSamples >= 2;
130
131 /*
132 * According to ARB_stencil_texturing, NEAREST_MIPMAP_NEAREST would
133 * be forbidden, however it is allowed per GL 4.5 rules, allow it
134 * even without GL 4.5 since it was a spec mistake.
135 */
136 /* Section 8.17 (texture completeness) of the OpenGL 4.6 core profile spec:
137 *
138 * "The texture is not multisample; either the magnification filter is not
139 * NEAREST, or the minification filter is neither NEAREST nor NEAREST_-
140 * MIPMAP_NEAREST; and any of
141 * – The internal format of the texture is integer.
142 * – The internal format is STENCIL_INDEX.
143 * – The internal format is DEPTH_STENCIL, and the value of DEPTH_-
144 * STENCIL_TEXTURE_MODE for the texture is STENCIL_INDEX.""
145 */
146 if (!isMultisample &&
147 (texObj->_IsIntegerFormat ||
148 (texObj->StencilSampling &&
149 img->_BaseFormat == GL_DEPTH_STENCIL)) &&
150 (sampler->MagFilter != GL_NEAREST ||
151 (sampler->MinFilter != GL_NEAREST &&
152 sampler->MinFilter != GL_NEAREST_MIPMAP_NEAREST))) {
153 /* If the format is integer, only nearest filtering is allowed,
154 * but some applications (eg: Grid Autosport) uses the default
155 * filtering values.
156 */
157 if (texObj->_IsIntegerFormat &&
158 linear_as_nearest_for_int_tex) {
159 /* Skip return */
160 } else {
161 return GL_FALSE;
162 }
163 }
164
165 /* Section 8.17 (texture completeness) of the OpenGL 4.6 core profile spec:
166 *
167 * "The minification filter requires a mipmap (is neither NEAREST nor LINEAR),
168 * the texture is not multisample, and the texture is not mipmap complete.""
169 */
170 if (!isMultisample &&_mesa_is_mipmap_filter(sampler))
171 return texObj->_MipmapComplete;
172 else
173 return texObj->_BaseComplete;
174 }
175
176
177 extern void
178 _mesa_test_texobj_completeness( const struct gl_context *ctx,
179 struct gl_texture_object *obj );
180
181 extern GLboolean
182 _mesa_cube_level_complete(const struct gl_texture_object *texObj,
183 const GLint level);
184
185 extern GLboolean
186 _mesa_cube_complete(const struct gl_texture_object *texObj);
187
188 extern void
189 _mesa_dirty_texobj(struct gl_context *ctx, struct gl_texture_object *texObj);
190
191 extern struct gl_texture_object *
192 _mesa_get_fallback_texture(struct gl_context *ctx, gl_texture_index tex);
193
194 extern GLuint
195 _mesa_total_texture_memory(struct gl_context *ctx);
196
197 extern GLenum
198 _mesa_texture_base_format(const struct gl_texture_object *texObj);
199
200 extern void
201 _mesa_unlock_context_textures( struct gl_context *ctx );
202
203 extern void
204 _mesa_lock_context_textures( struct gl_context *ctx );
205
206 extern void
207 _mesa_delete_nameless_texture(struct gl_context *ctx,
208 struct gl_texture_object *texObj);
209
210 extern void
211 _mesa_bind_texture(struct gl_context *ctx, GLenum target,
212 struct gl_texture_object *tex_obj);
213
214 extern struct gl_texture_object *
215 _mesa_lookup_or_create_texture(struct gl_context *ctx, GLenum target,
216 GLuint texName, bool no_error, bool is_ext_dsa,
217 const char *name);
218
219 /*@}*/
220
221 /**
222 * \name API functions
223 */
224 /*@{*/
225
226 void GLAPIENTRY
227 _mesa_GenTextures_no_error(GLsizei n, GLuint *textures);
228
229 extern void GLAPIENTRY
230 _mesa_GenTextures(GLsizei n, GLuint *textures);
231
232 void GLAPIENTRY
233 _mesa_CreateTextures_no_error(GLenum target, GLsizei n, GLuint *textures);
234
235 extern void GLAPIENTRY
236 _mesa_CreateTextures(GLenum target, GLsizei n, GLuint *textures);
237
238 void GLAPIENTRY
239 _mesa_DeleteTextures_no_error(GLsizei n, const GLuint *textures);
240
241 extern void GLAPIENTRY
242 _mesa_DeleteTextures( GLsizei n, const GLuint *textures );
243
244
245 void GLAPIENTRY
246 _mesa_BindTexture_no_error(GLenum target, GLuint texture);
247
248 extern void GLAPIENTRY
249 _mesa_BindTexture( GLenum target, GLuint texture );
250
251 void GLAPIENTRY
252 _mesa_BindMultiTextureEXT(GLenum texunit, GLenum target, GLuint texture);
253
254 void GLAPIENTRY
255 _mesa_BindTextureUnit_no_error(GLuint unit, GLuint texture);
256
257 extern void GLAPIENTRY
258 _mesa_BindTextureUnit(GLuint unit, GLuint texture);
259
260 void GLAPIENTRY
261 _mesa_BindTextures_no_error(GLuint first, GLsizei count,
262 const GLuint *textures);
263
264 extern void GLAPIENTRY
265 _mesa_BindTextures( GLuint first, GLsizei count, const GLuint *textures );
266
267
268 extern void GLAPIENTRY
269 _mesa_PrioritizeTextures( GLsizei n, const GLuint *textures,
270 const GLclampf *priorities );
271
272
273 extern GLboolean GLAPIENTRY
274 _mesa_AreTexturesResident( GLsizei n, const GLuint *textures,
275 GLboolean *residences );
276
277 extern GLboolean GLAPIENTRY
278 _mesa_IsTexture( GLuint texture );
279
280 void GLAPIENTRY
281 _mesa_InvalidateTexSubImage_no_error(GLuint texture, GLint level, GLint xoffset,
282 GLint yoffset, GLint zoffset,
283 GLsizei width, GLsizei height,
284 GLsizei depth);
285
286 extern void GLAPIENTRY
287 _mesa_InvalidateTexSubImage(GLuint texture, GLint level, GLint xoffset,
288 GLint yoffset, GLint zoffset, GLsizei width,
289 GLsizei height, GLsizei depth);
290 void GLAPIENTRY
291 _mesa_InvalidateTexImage_no_error(GLuint texture, GLint level);
292
293 extern void GLAPIENTRY
294 _mesa_InvalidateTexImage(GLuint texture, GLint level);
295
296 /*@}*/
297
298
299 #ifdef __cplusplus
300 }
301 #endif
302
303
304 #endif