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