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 int
71 _mesa_tex_target_to_index(const struct gl_context *ctx, GLenum target);
72
73 extern void
74 _mesa_delete_texture_object( struct gl_context *ctx,
75 struct gl_texture_object *obj );
76
77 extern void
78 _mesa_clear_texture_object(struct gl_context *ctx,
79 struct gl_texture_object *obj,
80 struct gl_texture_image *retainTexImage);
81
82 extern void
83 _mesa_reference_texobj_(struct gl_texture_object **ptr,
84 struct gl_texture_object *tex);
85
86 static inline void
_mesa_reference_texobj(struct gl_texture_object ** ptr,struct gl_texture_object * tex)87 _mesa_reference_texobj(struct gl_texture_object **ptr,
88 struct gl_texture_object *tex)
89 {
90 if (*ptr != tex)
91 _mesa_reference_texobj_(ptr, tex);
92 }
93
94 /**
95 * Lock a texture for updating. See also _mesa_lock_context_textures().
96 */
97 static inline void
_mesa_lock_texture(struct gl_context * ctx,struct gl_texture_object * texObj)98 _mesa_lock_texture(struct gl_context *ctx, struct gl_texture_object *texObj)
99 {
100 if (!ctx->TexturesLocked)
101 simple_mtx_lock(&ctx->Shared->TexMutex);
102 ctx->Shared->TextureStateStamp++;
103 (void) texObj;
104 }
105
106 static inline void
_mesa_unlock_texture(struct gl_context * ctx,struct gl_texture_object * texObj)107 _mesa_unlock_texture(struct gl_context *ctx, struct gl_texture_object *texObj)
108 {
109 (void) texObj;
110 if (!ctx->TexturesLocked)
111 simple_mtx_unlock(&ctx->Shared->TexMutex);
112 }
113
114
115 /** Is the texture "complete" with respect to the given sampler state? */
116 static inline GLboolean
_mesa_is_texture_complete(const struct gl_texture_object * texObj,const struct gl_sampler_object * sampler,bool linear_as_nearest_for_int_tex)117 _mesa_is_texture_complete(const struct gl_texture_object *texObj,
118 const struct gl_sampler_object *sampler,
119 bool linear_as_nearest_for_int_tex)
120 {
121 struct gl_texture_image *img = texObj->Image[0][texObj->Attrib.BaseLevel];
122 bool isMultisample = img && img->NumSamples >= 2;
123
124 /*
125 * According to ARB_stencil_texturing, NEAREST_MIPMAP_NEAREST would
126 * be forbidden, however it is allowed per GL 4.5 rules, allow it
127 * even without GL 4.5 since it was a spec mistake.
128 */
129 /* Section 8.17 (texture completeness) of the OpenGL 4.6 core profile spec:
130 *
131 * "The texture is not multisample; either the magnification filter is not
132 * NEAREST, or the minification filter is neither NEAREST nor NEAREST_-
133 * MIPMAP_NEAREST; and any of
134 * – The internal format of the texture is integer.
135 * – The internal format is STENCIL_INDEX.
136 * – The internal format is DEPTH_STENCIL, and the value of DEPTH_-
137 * STENCIL_TEXTURE_MODE for the texture is STENCIL_INDEX.""
138 */
139 /* GL_EXT_texture_filter_minmax further modifies this to explain it does
140 * not apply to MIN/MAX reduction, only WEIGHTED_AVERAGE (i.e. default)
141 */
142 if (!isMultisample &&
143 (texObj->_IsIntegerFormat ||
144 (texObj->StencilSampling &&
145 img->_BaseFormat == GL_DEPTH_STENCIL)) &&
146 sampler->Attrib.ReductionMode == GL_WEIGHTED_AVERAGE_EXT &&
147 (sampler->Attrib.MagFilter != GL_NEAREST ||
148 (sampler->Attrib.MinFilter != GL_NEAREST &&
149 sampler->Attrib.MinFilter != GL_NEAREST_MIPMAP_NEAREST))) {
150 /* If the format is integer, only nearest filtering is allowed,
151 * but some applications (eg: Grid Autosport) uses the default
152 * filtering values.
153 */
154 if (texObj->_IsIntegerFormat &&
155 linear_as_nearest_for_int_tex) {
156 /* Skip return */
157 } else {
158 return GL_FALSE;
159 }
160 }
161
162 /* Section 8.17 (texture completeness) of the OpenGL 4.6 core profile spec:
163 *
164 * "The minification filter requires a mipmap (is neither NEAREST nor LINEAR),
165 * the texture is not multisample, and the texture is not mipmap complete.""
166 */
167 if (!isMultisample &&_mesa_is_mipmap_filter(sampler))
168 return texObj->_MipmapComplete;
169 else
170 return texObj->_BaseComplete;
171 }
172
173
174 extern void
175 _mesa_test_texobj_completeness( const struct gl_context *ctx,
176 struct gl_texture_object *obj );
177
178 extern GLboolean
179 _mesa_cube_level_complete(const struct gl_texture_object *texObj,
180 const GLint level);
181
182 extern GLboolean
183 _mesa_cube_complete(const struct gl_texture_object *texObj);
184
185 extern void
186 _mesa_dirty_texobj(struct gl_context *ctx, struct gl_texture_object *texObj);
187
188 extern struct gl_texture_object *
189 _mesa_get_fallback_texture(struct gl_context *ctx, gl_texture_index tex);
190
191 extern GLuint
192 _mesa_total_texture_memory(struct gl_context *ctx);
193
194 extern GLenum
195 _mesa_texture_base_format(const struct gl_texture_object *texObj);
196
197 extern void
198 _mesa_unlock_context_textures( struct gl_context *ctx );
199
200 extern void
201 _mesa_lock_context_textures( struct gl_context *ctx );
202
203 extern struct gl_texture_object *
204 _mesa_lookup_or_create_texture(struct gl_context *ctx, GLenum target,
205 GLuint texName, bool no_error, bool is_ext_dsa,
206 const char *name);
207
208 /*@}*/
209
210 #ifdef __cplusplus
211 }
212 #endif
213
214
215 #endif
216