xref: /aosp_15_r20/external/mesa3d/src/mesa/main/teximage.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
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
_mesa_is_cube_face(GLenum target)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  */
57 static inline GLuint
_mesa_num_tex_faces(GLenum target)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  */
76 static inline GLenum
_mesa_cube_face_target(GLenum target,unsigned face)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  */
93 static inline GLuint
_mesa_tex_target_to_face(GLenum target)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? */
104 static inline GLboolean
_mesa_is_zero_size_texture(const struct gl_texture_image * texImage)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 
115 extern GLboolean
116 _mesa_is_proxy_texture(GLenum target);
117 
118 extern bool
119 _mesa_is_array_texture(GLenum target);
120 
121 
122 extern void
123 _mesa_delete_texture_image( struct gl_context *ctx,
124                             struct gl_texture_image *teximage );
125 
126 
127 extern void
128 _mesa_init_teximage_fields(struct gl_context *ctx,
129                            struct gl_texture_image *img,
130                            GLsizei width, GLsizei height, GLsizei depth,
131                            GLint border, GLenum internalFormat,
132                            mesa_format format);
133 extern void
134 _mesa_init_teximage_fields_ms(struct gl_context *ctx,
135                               struct gl_texture_image *img,
136                               GLsizei width, GLsizei height, GLsizei depth,
137                               GLint border, GLenum internalFormat,
138                               mesa_format format,
139                               GLuint numSamples,
140                               GLboolean fixedSampleLocations);
141 
142 void
143 _mesa_update_teximage_format_swizzle(struct gl_context *ctx,
144                                      struct gl_texture_image *img,
145                                      GLenum depth_mode);
146 extern mesa_format
147 _mesa_choose_texture_format(struct gl_context *ctx,
148                             struct gl_texture_object *texObj,
149                             GLenum target, GLint level,
150                             GLenum internalFormat, GLenum format, GLenum type);
151 
152 extern void
153 _mesa_update_fbo_texture(struct gl_context *ctx,
154                          struct gl_texture_object *texObj,
155                          GLuint face, GLuint level);
156 
157 extern void
158 _mesa_clear_texture_image(struct gl_context *ctx,
159                           struct gl_texture_image *texImage);
160 
161 
162 extern struct gl_texture_image *
163 _mesa_select_tex_image(const struct gl_texture_object *texObj,
164                        GLenum target, GLint level);
165 
166 
167 extern struct gl_texture_image *
168 _mesa_get_tex_image(struct gl_context *ctx, struct gl_texture_object *texObj,
169                     GLenum target, GLint level);
170 
171 mesa_format
172 _mesa_get_texbuffer_format(const struct gl_context *ctx, GLenum internalFormat);
173 
174 /**
175  * Return the base-level texture image for the given texture object.
176  */
177 static inline struct gl_texture_image *
_mesa_base_tex_image(const struct gl_texture_object * texObj)178 _mesa_base_tex_image(const struct gl_texture_object *texObj)
179 {
180    int base_level = MIN2(texObj->Attrib.BaseLevel, MAX_TEXTURE_LEVELS - 1);
181    return texObj->Image[0][base_level];
182 }
183 
184 
185 extern GLint
186 _mesa_max_texture_levels(const struct gl_context *ctx, GLenum target);
187 
188 
189 extern GLboolean
190 _mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target,
191                           GLuint numLevels, GLint level,
192                           mesa_format format, GLuint numSamples,
193                           GLint width, GLint height, GLint depth);
194 
195 extern GLboolean
196 _mesa_target_can_be_compressed(const struct gl_context *ctx, GLenum target,
197                                GLenum intFormat, GLenum *error);
198 
199 extern GLint
200 _mesa_get_texture_dimensions(GLenum target);
201 
202 extern GLboolean
203 _mesa_tex_target_is_layered(GLenum target);
204 
205 extern GLuint
206 _mesa_get_texture_layers(const struct gl_texture_object *texObj, GLint level);
207 
208 extern GLsizei
209 _mesa_get_tex_max_num_levels(GLenum target, GLsizei width, GLsizei height,
210                              GLsizei depth);
211 
212 extern GLboolean
213 _mesa_legal_texture_dimensions(struct gl_context *ctx, GLenum target,
214                                GLint level, GLint width, GLint height,
215                                GLint depth, GLint border);
216 
217 extern mesa_format
218 _mesa_validate_texbuffer_format(const struct gl_context *ctx,
219                                 GLenum internalFormat);
220 
221 
222 bool
223 _mesa_legal_texture_base_format_for_target(struct gl_context *ctx,
224                                            GLenum target,
225                                            GLenum internalFormat);
226 
227 bool
228 _mesa_format_no_online_compression(GLenum format);
229 
230 GLboolean
231 _mesa_is_renderable_texture_format(const struct gl_context *ctx,
232                                    GLenum internalformat);
233 
234 extern void
235 _mesa_texture_sub_image(struct gl_context *ctx, GLuint dims,
236                         struct gl_texture_object *texObj,
237                         struct gl_texture_image *texImage,
238                         GLenum target, GLint level,
239                         GLint xoffset, GLint yoffset, GLint zoffset,
240                         GLsizei width, GLsizei height, GLsizei depth,
241                         GLenum format, GLenum type, const GLvoid *pixels,
242                         bool dsa);
243 
244 extern void
245 _mesa_texture_storage_ms_memory(struct gl_context *ctx, GLuint dims,
246                                 struct gl_texture_object *texObj,
247                                 struct gl_memory_object *memObj,
248                                 GLenum target, GLsizei samples,
249                                 GLenum internalFormat, GLsizei width,
250                                 GLsizei height, GLsizei depth,
251                                 GLboolean fixedSampleLocations,
252                                 GLuint64 offset, const char* func);
253 
254 bool
255 _mesa_is_cube_map_texture(GLenum target);
256 
257 GLboolean
258 _mesa_sparse_texture_error_check(struct gl_context *ctx, GLuint dims,
259                                  struct gl_texture_object *texObj,
260                                  mesa_format format, GLenum target, GLsizei levels,
261                                  GLsizei width, GLsizei height, GLsizei depth,
262                                  const char *func);
263 
264 /*@}*/
265 
266 #ifdef __cplusplus
267 }
268 #endif
269 
270 #endif
271