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