f33991dd2d66bd768e2a31959d47db6a62b3e113
[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 "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 void
55 _mesa_begin_texture_lookups(struct gl_context *ctx);
56
57 extern void
58 _mesa_end_texture_lookups(struct gl_context *ctx);
59
60 extern struct gl_texture_object *
61 _mesa_lookup_texture_locked(struct gl_context *ctx, GLuint id);
62
63 extern struct gl_texture_object *
64 _mesa_new_texture_object( struct gl_context *ctx, GLuint name, GLenum target );
65
66 extern void
67 _mesa_initialize_texture_object( struct gl_context *ctx,
68 struct gl_texture_object *obj,
69 GLuint name, GLenum target );
70
71 extern int
72 _mesa_tex_target_to_index(const struct gl_context *ctx, GLenum target);
73
74 extern void
75 _mesa_delete_texture_object( struct gl_context *ctx,
76 struct gl_texture_object *obj );
77
78 extern void
79 _mesa_copy_texture_object( struct gl_texture_object *dest,
80 const struct gl_texture_object *src );
81
82 extern void
83 _mesa_clear_texture_object(struct gl_context *ctx,
84 struct gl_texture_object *obj);
85
86 extern void
87 _mesa_reference_texobj_(struct gl_texture_object **ptr,
88 struct gl_texture_object *tex);
89
90 static inline void
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 /**
100 * Return number of faces for a texture target. This will be 6 for
101 * cube maps (and cube map arrays) and 1 otherwise.
102 * NOTE: this function is not used for cube map arrays which operate
103 * more like 2D arrays than cube maps.
104 */
105 static inline GLuint
106 _mesa_num_tex_faces(GLenum target)
107 {
108 switch (target) {
109 case GL_TEXTURE_CUBE_MAP:
110 case GL_PROXY_TEXTURE_CUBE_MAP:
111 return 6;
112 default:
113 return 1;
114 }
115 }
116
117
118 /** Is the texture "complete" with respect to the given sampler state? */
119 static inline GLboolean
120 _mesa_is_texture_complete(const struct gl_texture_object *texObj,
121 const struct gl_sampler_object *sampler)
122 {
123 if (texObj->_IsIntegerFormat &&
124 (sampler->MagFilter != GL_NEAREST ||
125 (sampler->MinFilter != GL_NEAREST &&
126 sampler->MinFilter != GL_NEAREST_MIPMAP_NEAREST))) {
127 /* If the format is integer, only nearest filtering is allowed */
128 return GL_FALSE;
129 }
130
131 /* From the ARB_stencil_texturing specification:
132 * "Add a new bullet point for the conditions that cause the texture
133 * to not be complete:
134 *
135 * * The internal format of the texture is DEPTH_STENCIL, the
136 * DEPTH_STENCIL_TEXTURE_MODE for the texture is STENCIL_INDEX and either
137 * the magnification filter or the minification filter is not NEAREST."
138 */
139 if (texObj->StencilSampling &&
140 texObj->Image[0][texObj->BaseLevel]->_BaseFormat == GL_DEPTH_STENCIL &&
141 (sampler->MagFilter != GL_NEAREST || sampler->MinFilter != GL_NEAREST)) {
142 return GL_FALSE;
143 }
144
145 if (_mesa_is_mipmap_filter(sampler))
146 return texObj->_MipmapComplete;
147 else
148 return texObj->_BaseComplete;
149 }
150
151
152 extern void
153 _mesa_test_texobj_completeness( const struct gl_context *ctx,
154 struct gl_texture_object *obj );
155
156 extern GLboolean
157 _mesa_cube_complete(const struct gl_texture_object *texObj);
158
159 extern void
160 _mesa_dirty_texobj(struct gl_context *ctx, struct gl_texture_object *texObj);
161
162 extern struct gl_texture_object *
163 _mesa_get_fallback_texture(struct gl_context *ctx, gl_texture_index tex);
164
165 extern GLuint
166 _mesa_total_texture_memory(struct gl_context *ctx);
167
168 extern GLenum
169 _mesa_texture_base_format(const struct gl_texture_object *texObj);
170
171 extern void
172 _mesa_unlock_context_textures( struct gl_context *ctx );
173
174 extern void
175 _mesa_lock_context_textures( struct gl_context *ctx );
176
177 /*@}*/
178
179 /**
180 * \name API functions
181 */
182 /*@{*/
183
184 extern void GLAPIENTRY
185 _mesa_GenTextures( GLsizei n, GLuint *textures );
186
187
188 extern void GLAPIENTRY
189 _mesa_DeleteTextures( GLsizei n, const GLuint *textures );
190
191
192 extern void GLAPIENTRY
193 _mesa_BindTexture( GLenum target, GLuint texture );
194
195
196 extern void GLAPIENTRY
197 _mesa_BindTextures( GLuint first, GLsizei count, const GLuint *textures );
198
199
200 extern void GLAPIENTRY
201 _mesa_PrioritizeTextures( GLsizei n, const GLuint *textures,
202 const GLclampf *priorities );
203
204
205 extern GLboolean GLAPIENTRY
206 _mesa_AreTexturesResident( GLsizei n, const GLuint *textures,
207 GLboolean *residences );
208
209 extern GLboolean GLAPIENTRY
210 _mesa_IsTexture( GLuint texture );
211
212 extern void GLAPIENTRY
213 _mesa_InvalidateTexSubImage(GLuint texture, GLint level, GLint xoffset,
214 GLint yoffset, GLint zoffset, GLsizei width,
215 GLsizei height, GLsizei depth);
216
217 extern void GLAPIENTRY
218 _mesa_InvalidateTexImage(GLuint texture, GLint level);
219
220 /*@}*/
221
222
223 #ifdef __cplusplus
224 }
225 #endif
226
227
228 #endif