• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "compiler.h"
36 #include "glheader.h"
37 #include "mtypes.h"
38 #include "samplerobj.h"
39 
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 
46 /**
47  * \name Internal functions
48  */
49 /*@{*/
50 
51 extern struct gl_texture_object *
52 _mesa_lookup_texture(struct gl_context *ctx, GLuint id);
53 
54 extern struct gl_texture_object *
55 _mesa_lookup_texture_err(struct gl_context *ctx, GLuint id, const char* func);
56 
57 extern void
58 _mesa_begin_texture_lookups(struct gl_context *ctx);
59 
60 extern void
61 _mesa_end_texture_lookups(struct gl_context *ctx);
62 
63 extern struct gl_texture_object *
64 _mesa_lookup_texture_locked(struct gl_context *ctx, GLuint id);
65 
66 extern struct gl_texture_object *
67 _mesa_get_current_tex_object(struct gl_context *ctx, GLenum target);
68 
69 extern struct gl_texture_object *
70 _mesa_new_texture_object( struct gl_context *ctx, GLuint name, GLenum target );
71 
72 extern void
73 _mesa_initialize_texture_object( struct gl_context *ctx,
74                                  struct gl_texture_object *obj,
75                                  GLuint name, GLenum target );
76 
77 extern int
78 _mesa_tex_target_to_index(const struct gl_context *ctx, GLenum target);
79 
80 extern void
81 _mesa_delete_texture_object( struct gl_context *ctx,
82                              struct gl_texture_object *obj );
83 
84 extern void
85 _mesa_copy_texture_object( struct gl_texture_object *dest,
86                            const struct gl_texture_object *src );
87 
88 extern void
89 _mesa_clear_texture_object(struct gl_context *ctx,
90                            struct gl_texture_object *obj);
91 
92 extern void
93 _mesa_reference_texobj_(struct gl_texture_object **ptr,
94                         struct gl_texture_object *tex);
95 
96 static inline void
_mesa_reference_texobj(struct gl_texture_object ** ptr,struct gl_texture_object * tex)97 _mesa_reference_texobj(struct gl_texture_object **ptr,
98                        struct gl_texture_object *tex)
99 {
100    if (*ptr != tex)
101       _mesa_reference_texobj_(ptr, tex);
102 }
103 
104 /**
105  * Lock a texture for updating.  See also _mesa_lock_context_textures().
106  */
107 static inline void
_mesa_lock_texture(struct gl_context * ctx,struct gl_texture_object * texObj)108 _mesa_lock_texture(struct gl_context *ctx, struct gl_texture_object *texObj)
109 {
110    mtx_lock(&ctx->Shared->TexMutex);
111    ctx->Shared->TextureStateStamp++;
112    (void) texObj;
113 }
114 
115 static inline void
_mesa_unlock_texture(struct gl_context * ctx,struct gl_texture_object * texObj)116 _mesa_unlock_texture(struct gl_context *ctx, struct gl_texture_object *texObj)
117 {
118    (void) texObj;
119    mtx_unlock(&ctx->Shared->TexMutex);
120 }
121 
122 
123 /** Is the texture "complete" with respect to the given sampler state? */
124 static inline GLboolean
_mesa_is_texture_complete(const struct gl_texture_object * texObj,const struct gl_sampler_object * sampler)125 _mesa_is_texture_complete(const struct gl_texture_object *texObj,
126                           const struct gl_sampler_object *sampler)
127 {
128    /*
129     * According to ARB_stencil_texturing, NEAREST_MIPMAP_NEAREST would
130     * be forbidden, however it is allowed per GL 4.5 rules, allow it
131     * even without GL 4.5 since it was a spec mistake.
132     */
133    if ((texObj->_IsIntegerFormat ||
134         (texObj->StencilSampling &&
135          texObj->Image[0][texObj->BaseLevel]->_BaseFormat == GL_DEPTH_STENCIL)) &&
136        (sampler->MagFilter != GL_NEAREST ||
137         (sampler->MinFilter != GL_NEAREST &&
138          sampler->MinFilter != GL_NEAREST_MIPMAP_NEAREST))) {
139       /* If the format is integer, only nearest filtering is allowed */
140       return GL_FALSE;
141    }
142 
143    if (_mesa_is_mipmap_filter(sampler))
144       return texObj->_MipmapComplete;
145    else
146       return texObj->_BaseComplete;
147 }
148 
149 
150 extern void
151 _mesa_test_texobj_completeness( const struct gl_context *ctx,
152                                 struct gl_texture_object *obj );
153 
154 extern GLboolean
155 _mesa_cube_level_complete(const struct gl_texture_object *texObj,
156                           const GLint level);
157 
158 extern GLboolean
159 _mesa_cube_complete(const struct gl_texture_object *texObj);
160 
161 extern void
162 _mesa_dirty_texobj(struct gl_context *ctx, struct gl_texture_object *texObj);
163 
164 extern struct gl_texture_object *
165 _mesa_get_fallback_texture(struct gl_context *ctx, gl_texture_index tex);
166 
167 extern GLuint
168 _mesa_total_texture_memory(struct gl_context *ctx);
169 
170 extern GLenum
171 _mesa_texture_base_format(const struct gl_texture_object *texObj);
172 
173 extern void
174 _mesa_unlock_context_textures( struct gl_context *ctx );
175 
176 extern void
177 _mesa_lock_context_textures( struct gl_context *ctx );
178 
179 extern void
180 _mesa_delete_nameless_texture(struct gl_context *ctx,
181                               struct gl_texture_object *texObj);
182 
183 
184 /*@}*/
185 
186 /**
187  * \name API functions
188  */
189 /*@{*/
190 
191 extern void GLAPIENTRY
192 _mesa_GenTextures(GLsizei n, GLuint *textures);
193 
194 extern void GLAPIENTRY
195 _mesa_CreateTextures(GLenum target, GLsizei n, GLuint *textures);
196 
197 extern void GLAPIENTRY
198 _mesa_DeleteTextures( GLsizei n, const GLuint *textures );
199 
200 
201 extern void GLAPIENTRY
202 _mesa_BindTexture( GLenum target, GLuint texture );
203 
204 extern void GLAPIENTRY
205 _mesa_BindTextureUnit(GLuint unit, GLuint texture);
206 
207 extern void GLAPIENTRY
208 _mesa_BindTextures( GLuint first, GLsizei count, const GLuint *textures );
209 
210 
211 extern void GLAPIENTRY
212 _mesa_PrioritizeTextures( GLsizei n, const GLuint *textures,
213                           const GLclampf *priorities );
214 
215 
216 extern GLboolean GLAPIENTRY
217 _mesa_AreTexturesResident( GLsizei n, const GLuint *textures,
218                            GLboolean *residences );
219 
220 extern GLboolean GLAPIENTRY
221 _mesa_IsTexture( GLuint texture );
222 
223 extern void GLAPIENTRY
224 _mesa_InvalidateTexSubImage(GLuint texture, GLint level, GLint xoffset,
225                             GLint yoffset, GLint zoffset, GLsizei width,
226                             GLsizei height, GLsizei depth);
227 
228 extern void GLAPIENTRY
229 _mesa_InvalidateTexImage(GLuint texture, GLint level);
230 
231 /*@}*/
232 
233 
234 #ifdef __cplusplus
235 }
236 #endif
237 
238 
239 #endif
240