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