mesa: Refactor internalFormat / target checks to a separate function
[mesa.git] / src / mesa / main / teximage.h
1 /**
2 * \file teximage.h
3 * Texture images manipulation functions.
4 */
5
6 /*
7 * Mesa 3-D graphics library
8 *
9 * Copyright (C) 1999-2005 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 TEXIMAGE_H
32 #define TEXIMAGE_H
33
34
35 #include "mtypes.h"
36 #include "formats.h"
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42 /** Is the given value one of the 6 cube faces? */
43 static inline GLboolean
44 _mesa_is_cube_face(GLenum target)
45 {
46 return (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
47 target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB);
48 }
49
50 /** Is any of the dimensions of given texture equal to zero? */
51 static inline GLboolean
52 _mesa_is_zero_size_texture(const struct gl_texture_image *texImage)
53 {
54 return (texImage->Width == 0 ||
55 texImage->Height == 0 ||
56 texImage->Depth == 0);
57 }
58
59 /** \name Internal functions */
60 /*@{*/
61
62 extern GLint
63 _mesa_base_tex_format( struct gl_context *ctx, GLint internalFormat );
64
65
66 extern GLboolean
67 _mesa_is_proxy_texture(GLenum target);
68
69 extern GLenum
70 _mesa_get_proxy_target(GLenum target);
71
72 extern struct gl_texture_image *
73 _mesa_new_texture_image( struct gl_context *ctx );
74
75
76 extern void
77 _mesa_delete_texture_image( struct gl_context *ctx,
78 struct gl_texture_image *teximage );
79
80
81 extern void
82 _mesa_init_teximage_fields(struct gl_context *ctx,
83 struct gl_texture_image *img,
84 GLsizei width, GLsizei height, GLsizei depth,
85 GLint border, GLenum internalFormat,
86 gl_format format);
87
88
89 extern gl_format
90 _mesa_choose_texture_format(struct gl_context *ctx,
91 struct gl_texture_object *texObj,
92 GLenum target, GLint level,
93 GLenum internalFormat, GLenum format, GLenum type);
94
95 extern void
96 _mesa_update_fbo_texture(struct gl_context *ctx,
97 struct gl_texture_object *texObj,
98 GLuint face, GLuint level);
99
100 extern void
101 _mesa_clear_texture_image(struct gl_context *ctx,
102 struct gl_texture_image *texImage);
103
104
105 extern struct gl_texture_object *
106 _mesa_select_tex_object(struct gl_context *ctx,
107 const struct gl_texture_unit *texUnit,
108 GLenum target);
109
110 extern struct gl_texture_object *
111 _mesa_get_current_tex_object(struct gl_context *ctx, GLenum target);
112
113
114 extern struct gl_texture_image *
115 _mesa_select_tex_image(struct gl_context *ctx,
116 const struct gl_texture_object *texObj,
117 GLenum target, GLint level);
118
119
120 extern struct gl_texture_image *
121 _mesa_get_tex_image(struct gl_context *ctx, struct gl_texture_object *texObj,
122 GLenum target, GLint level);
123
124
125 extern GLint
126 _mesa_max_texture_levels(struct gl_context *ctx, GLenum target);
127
128
129 extern GLboolean
130 _mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level,
131 gl_format format,
132 GLint width, GLint height, GLint depth, GLint border);
133
134
135 extern GLuint
136 _mesa_tex_target_to_face(GLenum target);
137
138 extern GLint
139 _mesa_get_texture_dimensions(GLenum target);
140
141 extern GLboolean
142 _mesa_tex_target_is_layered(GLenum target);
143
144 extern GLuint
145 _mesa_get_texture_layers(const struct gl_texture_object *texObj, GLint level);
146
147 extern GLsizei
148 _mesa_get_tex_max_num_levels(GLenum target, GLsizei width, GLsizei height,
149 GLsizei depth);
150
151 extern GLboolean
152 _mesa_legal_texture_dimensions(struct gl_context *ctx, GLenum target,
153 GLint level, GLint width, GLint height,
154 GLint depth, GLint border);
155
156 extern gl_format
157 _mesa_validate_texbuffer_format(const struct gl_context *ctx,
158 GLenum internalFormat);
159
160
161 bool
162 _mesa_legal_texture_base_format_for_target(struct gl_context *ctx,
163 GLenum target,
164 GLenum internalFormat,
165 unsigned dimensions,
166 const char *caller);
167
168 /**
169 * Lock a texture for updating. See also _mesa_lock_context_textures().
170 */
171 static inline void
172 _mesa_lock_texture(struct gl_context *ctx, struct gl_texture_object *texObj)
173 {
174 _glthread_LOCK_MUTEX(ctx->Shared->TexMutex);
175 ctx->Shared->TextureStateStamp++;
176 (void) texObj;
177 }
178
179 static inline void
180 _mesa_unlock_texture(struct gl_context *ctx, struct gl_texture_object *texObj)
181 {
182 (void) texObj;
183 _glthread_UNLOCK_MUTEX(ctx->Shared->TexMutex);
184 }
185
186 /*@}*/
187
188
189 /** \name API entry point functions */
190 /*@{*/
191
192 extern void GLAPIENTRY
193 _mesa_TexImage1D( GLenum target, GLint level, GLint internalformat,
194 GLsizei width, GLint border,
195 GLenum format, GLenum type, const GLvoid *pixels );
196
197
198 extern void GLAPIENTRY
199 _mesa_TexImage2D( GLenum target, GLint level, GLint internalformat,
200 GLsizei width, GLsizei height, GLint border,
201 GLenum format, GLenum type, const GLvoid *pixels );
202
203
204 extern void GLAPIENTRY
205 _mesa_TexImage3D( GLenum target, GLint level, GLint internalformat,
206 GLsizei width, GLsizei height, GLsizei depth, GLint border,
207 GLenum format, GLenum type, const GLvoid *pixels );
208
209
210 extern void GLAPIENTRY
211 _mesa_TexImage3DEXT( GLenum target, GLint level, GLenum internalformat,
212 GLsizei width, GLsizei height, GLsizei depth,
213 GLint border, GLenum format, GLenum type,
214 const GLvoid *pixels );
215
216 extern void GLAPIENTRY
217 _mesa_EGLImageTargetTexture2DOES( GLenum target, GLeglImageOES image );
218
219 extern void GLAPIENTRY
220 _mesa_TexSubImage1D( GLenum target, GLint level, GLint xoffset,
221 GLsizei width,
222 GLenum format, GLenum type,
223 const GLvoid *pixels );
224
225
226 extern void GLAPIENTRY
227 _mesa_TexSubImage2D( GLenum target, GLint level,
228 GLint xoffset, GLint yoffset,
229 GLsizei width, GLsizei height,
230 GLenum format, GLenum type,
231 const GLvoid *pixels );
232
233
234 extern void GLAPIENTRY
235 _mesa_TexSubImage3D( GLenum target, GLint level,
236 GLint xoffset, GLint yoffset, GLint zoffset,
237 GLsizei width, GLsizei height, GLsizei depth,
238 GLenum format, GLenum type,
239 const GLvoid *pixels );
240
241
242 extern void GLAPIENTRY
243 _mesa_CopyTexImage1D( GLenum target, GLint level, GLenum internalformat,
244 GLint x, GLint y, GLsizei width, GLint border );
245
246
247 extern void GLAPIENTRY
248 _mesa_CopyTexImage2D( GLenum target, GLint level,
249 GLenum internalformat, GLint x, GLint y,
250 GLsizei width, GLsizei height, GLint border );
251
252
253 extern void GLAPIENTRY
254 _mesa_CopyTexSubImage1D( GLenum target, GLint level, GLint xoffset,
255 GLint x, GLint y, GLsizei width );
256
257
258 extern void GLAPIENTRY
259 _mesa_CopyTexSubImage2D( GLenum target, GLint level,
260 GLint xoffset, GLint yoffset,
261 GLint x, GLint y, GLsizei width, GLsizei height );
262
263
264 extern void GLAPIENTRY
265 _mesa_CopyTexSubImage3D( GLenum target, GLint level,
266 GLint xoffset, GLint yoffset, GLint zoffset,
267 GLint x, GLint y, GLsizei width, GLsizei height );
268
269
270
271 extern void GLAPIENTRY
272 _mesa_CompressedTexImage1D(GLenum target, GLint level,
273 GLenum internalformat, GLsizei width,
274 GLint border, GLsizei imageSize,
275 const GLvoid *data);
276
277 extern void GLAPIENTRY
278 _mesa_CompressedTexImage2D(GLenum target, GLint level,
279 GLenum internalformat, GLsizei width,
280 GLsizei height, GLint border, GLsizei imageSize,
281 const GLvoid *data);
282
283 extern void GLAPIENTRY
284 _mesa_CompressedTexImage3D(GLenum target, GLint level,
285 GLenum internalformat, GLsizei width,
286 GLsizei height, GLsizei depth, GLint border,
287 GLsizei imageSize, const GLvoid *data);
288
289 extern void GLAPIENTRY
290 _mesa_CompressedTexSubImage1D(GLenum target, GLint level, GLint xoffset,
291 GLsizei width, GLenum format,
292 GLsizei imageSize, const GLvoid *data);
293
294 extern void GLAPIENTRY
295 _mesa_CompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset,
296 GLint yoffset, GLsizei width, GLsizei height,
297 GLenum format, GLsizei imageSize,
298 const GLvoid *data);
299
300 extern void GLAPIENTRY
301 _mesa_CompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset,
302 GLint yoffset, GLint zoffset, GLsizei width,
303 GLsizei height, GLsizei depth, GLenum format,
304 GLsizei imageSize, const GLvoid *data);
305
306
307 extern void GLAPIENTRY
308 _mesa_TexBuffer(GLenum target, GLenum internalFormat, GLuint buffer);
309
310 extern void GLAPIENTRY
311 _mesa_TexBufferRange(GLenum target, GLenum internalFormat, GLuint buffer,
312 GLintptr offset, GLsizeiptr size);
313
314
315 extern void GLAPIENTRY
316 _mesa_TexImage2DMultisample(GLenum target, GLsizei samples,
317 GLenum internalformat, GLsizei width,
318 GLsizei height, GLboolean fixedsamplelocations);
319
320 extern void GLAPIENTRY
321 _mesa_TexImage3DMultisample(GLenum target, GLsizei samples,
322 GLenum internalformat, GLsizei width,
323 GLsizei height, GLsizei depth,
324 GLboolean fixedsamplelocations);
325
326 extern void GLAPIENTRY
327 _mesa_TexStorage2DMultisample(GLenum target, GLsizei samples,
328 GLenum internalformat, GLsizei width,
329 GLsizei height, GLboolean fixedsamplelocations);
330
331 extern void GLAPIENTRY
332 _mesa_TexStorage3DMultisample(GLenum target, GLsizei samples,
333 GLenum internalformat, GLsizei width,
334 GLsizei height, GLsizei depth,
335 GLboolean fixedsamplelocations);
336
337 /*@}*/
338
339 #ifdef __cplusplus
340 }
341 #endif
342
343 #endif