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
39extern "C" {
40#endif
41
42/** Is the given value one of the 6 cube faces? */
43static inline GLboolean
44_mesa_is_cube_face(GLenum target)
45{
46   return (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X &&
47           target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z);
48}
49
50
51/**
52 * Return number of faces for a texture target.  This will be 6 for
53 * cube maps and 1 otherwise.
54 * NOTE: this function is not used for cube map arrays which operate
55 * more like 2D arrays than cube maps.
56 */
57static inline GLuint
58_mesa_num_tex_faces(GLenum target)
59{
60   switch (target) {
61   case GL_TEXTURE_CUBE_MAP:
62   case GL_PROXY_TEXTURE_CUBE_MAP:
63      return 6;
64   default:
65      return 1;
66   }
67}
68
69
70/**
71 * If the target is GL_TEXTURE_CUBE_MAP, return one of the
72 * GL_TEXTURE_CUBE_MAP_POSITIVE/NEGATIVE_X/Y/Z targets corresponding to
73 * the face parameter.
74 * Else, return target as-is.
75 */
76static inline GLenum
77_mesa_cube_face_target(GLenum target, unsigned face)
78{
79   if (target == GL_TEXTURE_CUBE_MAP) {
80      assert(face < 6);
81      return GL_TEXTURE_CUBE_MAP_POSITIVE_X + face;
82   }
83   else {
84      return target;
85   }
86}
87
88
89/**
90 * For cube map faces, return a face index in [0,5].
91 * For other targets return 0;
92 */
93static inline GLuint
94_mesa_tex_target_to_face(GLenum target)
95{
96   if (_mesa_is_cube_face(target))
97      return (GLuint) target - (GLuint) GL_TEXTURE_CUBE_MAP_POSITIVE_X;
98   else
99      return 0;
100}
101
102
103/** Are any of the dimensions of given texture equal to zero? */
104static inline GLboolean
105_mesa_is_zero_size_texture(const struct gl_texture_image *texImage)
106{
107   return (texImage->Width == 0 ||
108           texImage->Height == 0 ||
109           texImage->Depth == 0);
110}
111
112/** \name Internal functions */
113/*@{*/
114
115extern GLboolean
116_mesa_is_proxy_texture(GLenum target);
117
118extern bool
119_mesa_is_array_texture(GLenum target);
120
121extern struct gl_texture_image *
122_mesa_new_texture_image( struct gl_context *ctx );
123
124
125extern void
126_mesa_delete_texture_image( struct gl_context *ctx,
127                            struct gl_texture_image *teximage );
128
129
130extern void
131_mesa_init_teximage_fields(struct gl_context *ctx,
132                           struct gl_texture_image *img,
133                           GLsizei width, GLsizei height, GLsizei depth,
134                           GLint border, GLenum internalFormat,
135                           mesa_format format);
136
137
138extern mesa_format
139_mesa_choose_texture_format(struct gl_context *ctx,
140                            struct gl_texture_object *texObj,
141                            GLenum target, GLint level,
142                            GLenum internalFormat, GLenum format, GLenum type);
143
144extern void
145_mesa_update_fbo_texture(struct gl_context *ctx,
146                         struct gl_texture_object *texObj,
147                         GLuint face, GLuint level);
148
149extern void
150_mesa_clear_texture_image(struct gl_context *ctx,
151                          struct gl_texture_image *texImage);
152
153
154extern struct gl_texture_image *
155_mesa_select_tex_image(const struct gl_texture_object *texObj,
156                       GLenum target, GLint level);
157
158
159extern struct gl_texture_image *
160_mesa_get_tex_image(struct gl_context *ctx, struct gl_texture_object *texObj,
161                    GLenum target, GLint level);
162
163
164/**
165 * Return the base-level texture image for the given texture object.
166 */
167static inline const struct gl_texture_image *
168_mesa_base_tex_image(const struct gl_texture_object *texObj)
169{
170   return texObj->Image[0][texObj->BaseLevel];
171}
172
173
174extern GLint
175_mesa_max_texture_levels(struct gl_context *ctx, GLenum target);
176
177
178extern GLboolean
179_mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target,
180                          GLuint numLevels, GLint level,
181                          mesa_format format, GLuint numSamples,
182                          GLint width, GLint height, GLint depth);
183
184extern GLboolean
185_mesa_target_can_be_compressed(const struct gl_context *ctx, GLenum target,
186                               GLenum intFormat, GLenum *error);
187
188extern GLint
189_mesa_get_texture_dimensions(GLenum target);
190
191extern GLboolean
192_mesa_tex_target_is_layered(GLenum target);
193
194extern GLuint
195_mesa_get_texture_layers(const struct gl_texture_object *texObj, GLint level);
196
197extern GLsizei
198_mesa_get_tex_max_num_levels(GLenum target, GLsizei width, GLsizei height,
199                             GLsizei depth);
200
201extern GLboolean
202_mesa_legal_texture_dimensions(struct gl_context *ctx, GLenum target,
203                               GLint level, GLint width, GLint height,
204                               GLint depth, GLint border);
205
206extern mesa_format
207_mesa_validate_texbuffer_format(const struct gl_context *ctx,
208                                GLenum internalFormat);
209
210
211bool
212_mesa_legal_texture_base_format_for_target(struct gl_context *ctx,
213                                           GLenum target,
214                                           GLenum internalFormat);
215
216bool
217_mesa_format_no_online_compression(const struct gl_context *ctx, GLenum format);
218
219GLboolean
220_mesa_is_renderable_texture_format(struct gl_context *ctx, GLenum internalformat);
221
222extern void
223_mesa_texture_sub_image(struct gl_context *ctx, GLuint dims,
224                        struct gl_texture_object *texObj,
225                        struct gl_texture_image *texImage,
226                        GLenum target, GLint level,
227                        GLint xoffset, GLint yoffset, GLint zoffset,
228                        GLsizei width, GLsizei height, GLsizei depth,
229                        GLenum format, GLenum type, const GLvoid *pixels,
230                        bool dsa);
231
232extern void
233_mesa_compressed_texture_sub_image(struct gl_context *ctx, GLuint dims,
234                                   struct gl_texture_object *texObj,
235                                   struct gl_texture_image *texImage,
236                                   GLenum target, GLint level,
237                                   GLint xoffset, GLint yoffset,
238                                   GLint zoffset,
239                                   GLsizei width, GLsizei height,
240                                   GLsizei depth,
241                                   GLenum format, GLsizei imageSize,
242                                   const GLvoid *data);
243
244extern void
245_mesa_copy_texture_sub_image(struct gl_context *ctx, GLuint dims,
246                             struct gl_texture_object *texObj,
247                             GLenum target, GLint level,
248                             GLint xoffset, GLint yoffset, GLint zoffset,
249                             GLint x, GLint y,
250                             GLsizei width, GLsizei height,
251                             const char *caller);
252
253bool
254_mesa_is_cube_map_texture(GLenum target);
255
256/*@}*/
257
258
259/** \name API entry point functions */
260/*@{*/
261
262extern void GLAPIENTRY
263_mesa_TexImage1D( GLenum target, GLint level, GLint internalformat,
264                  GLsizei width, GLint border,
265                  GLenum format, GLenum type, const GLvoid *pixels );
266
267
268extern void GLAPIENTRY
269_mesa_TexImage2D( GLenum target, GLint level, GLint internalformat,
270                  GLsizei width, GLsizei height, GLint border,
271                  GLenum format, GLenum type, const GLvoid *pixels );
272
273
274extern void GLAPIENTRY
275_mesa_TexImage3D( GLenum target, GLint level, GLint internalformat,
276                  GLsizei width, GLsizei height, GLsizei depth, GLint border,
277                  GLenum format, GLenum type, const GLvoid *pixels );
278
279
280extern void GLAPIENTRY
281_mesa_TexImage3DEXT( GLenum target, GLint level, GLenum internalformat,
282                     GLsizei width, GLsizei height, GLsizei depth,
283                     GLint border, GLenum format, GLenum type,
284                     const GLvoid *pixels );
285
286extern void GLAPIENTRY
287_mesa_EGLImageTargetTexture2DOES( GLenum target, GLeglImageOES image );
288
289extern void GLAPIENTRY
290_mesa_TexSubImage1D( GLenum target, GLint level, GLint xoffset,
291                     GLsizei width,
292                     GLenum format, GLenum type,
293                     const GLvoid *pixels );
294
295
296extern void GLAPIENTRY
297_mesa_TexSubImage2D( GLenum target, GLint level,
298                     GLint xoffset, GLint yoffset,
299                     GLsizei width, GLsizei height,
300                     GLenum format, GLenum type,
301                     const GLvoid *pixels );
302
303
304extern void GLAPIENTRY
305_mesa_TexSubImage3D( GLenum target, GLint level,
306                     GLint xoffset, GLint yoffset, GLint zoffset,
307                     GLsizei width, GLsizei height, GLsizei depth,
308                     GLenum format, GLenum type,
309                     const GLvoid *pixels );
310
311extern void GLAPIENTRY
312_mesa_TextureSubImage1D(GLuint texture, GLint level, GLint xoffset,
313                        GLsizei width,
314                        GLenum format, GLenum type,
315                        const GLvoid *pixels);
316
317
318extern void GLAPIENTRY
319_mesa_TextureSubImage2D(GLuint texture, GLint level,
320                        GLint xoffset, GLint yoffset,
321                        GLsizei width, GLsizei height,
322                        GLenum format, GLenum type,
323                        const GLvoid *pixels);
324
325extern void GLAPIENTRY
326_mesa_TextureSubImage3D(GLuint texture, GLint level,
327                        GLint xoffset, GLint yoffset, GLint zoffset,
328                        GLsizei width, GLsizei height, GLsizei depth,
329                        GLenum format, GLenum type,
330                        const GLvoid *pixels);
331
332
333extern void GLAPIENTRY
334_mesa_CopyTexImage1D(GLenum target, GLint level, GLenum internalformat,
335                     GLint x, GLint y, GLsizei width, GLint border);
336
337
338extern void GLAPIENTRY
339_mesa_CopyTexImage2D( GLenum target, GLint level,
340                      GLenum internalformat, GLint x, GLint y,
341                      GLsizei width, GLsizei height, GLint border );
342
343
344extern void GLAPIENTRY
345_mesa_CopyTexSubImage1D( GLenum target, GLint level, GLint xoffset,
346                         GLint x, GLint y, GLsizei width );
347
348
349extern void GLAPIENTRY
350_mesa_CopyTexSubImage2D( GLenum target, GLint level,
351                         GLint xoffset, GLint yoffset,
352                         GLint x, GLint y, GLsizei width, GLsizei height );
353
354
355extern void GLAPIENTRY
356_mesa_CopyTexSubImage3D( GLenum target, GLint level,
357                         GLint xoffset, GLint yoffset, GLint zoffset,
358                         GLint x, GLint y, GLsizei width, GLsizei height );
359
360extern void GLAPIENTRY
361_mesa_CopyTextureSubImage1D(GLuint texture, GLint level,
362                            GLint xoffset, GLint x, GLint y, GLsizei width);
363
364extern void GLAPIENTRY
365_mesa_CopyTextureSubImage2D(GLuint texture, GLint level,
366                            GLint xoffset, GLint yoffset,
367                            GLint x, GLint y,
368                            GLsizei width, GLsizei height);
369
370extern void GLAPIENTRY
371_mesa_CopyTextureSubImage3D(GLuint texture, GLint level,
372                            GLint xoffset, GLint yoffset, GLint zoffset,
373                            GLint x, GLint y,
374                            GLsizei width, GLsizei height);
375
376extern void GLAPIENTRY
377_mesa_ClearTexSubImage( GLuint texture, GLint level,
378                        GLint xoffset, GLint yoffset, GLint zoffset,
379                        GLsizei width, GLsizei height, GLsizei depth,
380                        GLenum format, GLenum type, const void *data );
381
382extern void GLAPIENTRY
383_mesa_ClearTexImage( GLuint texture, GLint level,
384                     GLenum format, GLenum type, const void *data );
385
386extern void GLAPIENTRY
387_mesa_CompressedTexImage1D(GLenum target, GLint level,
388                              GLenum internalformat, GLsizei width,
389                              GLint border, GLsizei imageSize,
390                              const GLvoid *data);
391
392extern void GLAPIENTRY
393_mesa_CompressedTexImage2D(GLenum target, GLint level,
394                              GLenum internalformat, GLsizei width,
395                              GLsizei height, GLint border, GLsizei imageSize,
396                              const GLvoid *data);
397
398extern void GLAPIENTRY
399_mesa_CompressedTexImage3D(GLenum target, GLint level,
400                              GLenum internalformat, GLsizei width,
401                              GLsizei height, GLsizei depth, GLint border,
402                              GLsizei imageSize, const GLvoid *data);
403
404extern void GLAPIENTRY
405_mesa_CompressedTexSubImage1D(GLenum target, GLint level, GLint xoffset,
406                                 GLsizei width, GLenum format,
407                                 GLsizei imageSize, const GLvoid *data);
408
409extern void GLAPIENTRY
410_mesa_CompressedTextureSubImage1D(GLuint texture, GLint level, GLint xoffset,
411                                  GLsizei width, GLenum format,
412                                  GLsizei imageSize, const GLvoid *data);
413
414extern void GLAPIENTRY
415_mesa_CompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset,
416                                 GLint yoffset, GLsizei width, GLsizei height,
417                                 GLenum format, GLsizei imageSize,
418                                 const GLvoid *data);
419
420extern void GLAPIENTRY
421_mesa_CompressedTextureSubImage2D(GLuint texture, GLint level, GLint xoffset,
422                                  GLint yoffset,
423                                  GLsizei width, GLsizei height,
424                                  GLenum format, GLsizei imageSize,
425                                  const GLvoid *data);
426
427extern void GLAPIENTRY
428_mesa_CompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset,
429                                 GLint yoffset, GLint zoffset, GLsizei width,
430                                 GLsizei height, GLsizei depth, GLenum format,
431                                 GLsizei imageSize, const GLvoid *data);
432
433extern void GLAPIENTRY
434_mesa_CompressedTextureSubImage3D(GLuint texture, GLint level, GLint xoffset,
435                                  GLint yoffset, GLint zoffset,
436                                  GLsizei width, GLsizei height,
437                                  GLsizei depth,
438                                  GLenum format, GLsizei imageSize,
439                                  const GLvoid *data);
440
441extern void GLAPIENTRY
442_mesa_TexBuffer(GLenum target, GLenum internalFormat, GLuint buffer);
443
444extern void GLAPIENTRY
445_mesa_TexBufferRange(GLenum target, GLenum internalFormat, GLuint buffer,
446                     GLintptr offset, GLsizeiptr size);
447
448extern void GLAPIENTRY
449_mesa_TextureBuffer(GLuint texture, GLenum internalFormat, GLuint buffer);
450
451extern void GLAPIENTRY
452_mesa_TextureBufferRange(GLuint texture, GLenum internalFormat, GLuint buffer,
453                         GLintptr offset, GLsizeiptr size);
454
455
456extern void GLAPIENTRY
457_mesa_TexImage2DMultisample(GLenum target, GLsizei samples,
458                            GLenum internalformat, GLsizei width,
459                            GLsizei height, GLboolean fixedsamplelocations);
460
461extern void GLAPIENTRY
462_mesa_TexImage3DMultisample(GLenum target, GLsizei samples,
463                            GLenum internalformat, GLsizei width,
464                            GLsizei height, GLsizei depth,
465                            GLboolean fixedsamplelocations);
466
467extern void GLAPIENTRY
468_mesa_TexStorage2DMultisample(GLenum target, GLsizei samples,
469                              GLenum internalformat, GLsizei width,
470                              GLsizei height, GLboolean fixedsamplelocations);
471
472extern void GLAPIENTRY
473_mesa_TexStorage3DMultisample(GLenum target, GLsizei samples,
474                              GLenum internalformat, GLsizei width,
475                              GLsizei height, GLsizei depth,
476                              GLboolean fixedsamplelocations);
477
478void GLAPIENTRY
479_mesa_TextureStorage2DMultisample(GLuint texture, GLsizei samples,
480                                  GLenum internalformat, GLsizei width,
481                                  GLsizei height,
482                                  GLboolean fixedsamplelocations);
483
484void GLAPIENTRY
485_mesa_TextureStorage3DMultisample(GLuint texture, GLsizei samples,
486                                  GLenum internalformat, GLsizei width,
487                                  GLsizei height, GLsizei depth,
488                                  GLboolean fixedsamplelocations);
489/*@}*/
490
491#ifdef __cplusplus
492}
493#endif
494
495#endif
496