1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Mesa 3-D graphics library 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Copyright (C) 2011 VMware, Inc. All Rights Reserved. 5bf215546Sopenharmony_ci * 6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 8bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 9bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 11bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 12bf215546Sopenharmony_ci * 13bf215546Sopenharmony_ci * The above copyright notice and this permission notice shall be included 14bf215546Sopenharmony_ci * in all copies or substantial portions of the Software. 15bf215546Sopenharmony_ci * 16bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20bf215546Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21bf215546Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22bf215546Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE. 23bf215546Sopenharmony_ci */ 24bf215546Sopenharmony_ci 25bf215546Sopenharmony_ci/** 26bf215546Sopenharmony_ci * \file texstorage.c 27bf215546Sopenharmony_ci * GL_ARB_texture_storage functions 28bf215546Sopenharmony_ci */ 29bf215546Sopenharmony_ci 30bf215546Sopenharmony_ci#include "glheader.h" 31bf215546Sopenharmony_ci#include "context.h" 32bf215546Sopenharmony_ci#include "enums.h" 33bf215546Sopenharmony_ci 34bf215546Sopenharmony_ci#include "macros.h" 35bf215546Sopenharmony_ci#include "teximage.h" 36bf215546Sopenharmony_ci#include "texobj.h" 37bf215546Sopenharmony_ci#include "mipmap.h" 38bf215546Sopenharmony_ci#include "texstorage.h" 39bf215546Sopenharmony_ci#include "textureview.h" 40bf215546Sopenharmony_ci#include "mtypes.h" 41bf215546Sopenharmony_ci#include "glformats.h" 42bf215546Sopenharmony_ci#include "hash.h" 43bf215546Sopenharmony_ci#include "api_exec_decl.h" 44bf215546Sopenharmony_ci 45bf215546Sopenharmony_ci#include "state_tracker/st_cb_texture.h" 46bf215546Sopenharmony_ci 47bf215546Sopenharmony_ci/** 48bf215546Sopenharmony_ci * Check if the given texture target is a legal texture object target 49bf215546Sopenharmony_ci * for a glTexStorage() command. 50bf215546Sopenharmony_ci * This is a bit different than legal_teximage_target() when it comes 51bf215546Sopenharmony_ci * to cube maps. 52bf215546Sopenharmony_ci */ 53bf215546Sopenharmony_cibool 54bf215546Sopenharmony_ci_mesa_is_legal_tex_storage_target(const struct gl_context *ctx, 55bf215546Sopenharmony_ci GLuint dims, GLenum target) 56bf215546Sopenharmony_ci{ 57bf215546Sopenharmony_ci if (dims < 1 || dims > 3) { 58bf215546Sopenharmony_ci _mesa_problem(ctx, "invalid dims=%u in _mesa_is_legal_tex_storage_target()", dims); 59bf215546Sopenharmony_ci return false; 60bf215546Sopenharmony_ci } 61bf215546Sopenharmony_ci 62bf215546Sopenharmony_ci switch (dims) { 63bf215546Sopenharmony_ci case 2: 64bf215546Sopenharmony_ci switch (target) { 65bf215546Sopenharmony_ci case GL_TEXTURE_2D: 66bf215546Sopenharmony_ci case GL_TEXTURE_CUBE_MAP: 67bf215546Sopenharmony_ci return true; 68bf215546Sopenharmony_ci } 69bf215546Sopenharmony_ci break; 70bf215546Sopenharmony_ci case 3: 71bf215546Sopenharmony_ci switch (target) { 72bf215546Sopenharmony_ci case GL_TEXTURE_3D: 73bf215546Sopenharmony_ci return true; 74bf215546Sopenharmony_ci case GL_TEXTURE_2D_ARRAY: 75bf215546Sopenharmony_ci return ctx->Extensions.EXT_texture_array; 76bf215546Sopenharmony_ci case GL_TEXTURE_CUBE_MAP_ARRAY: 77bf215546Sopenharmony_ci return _mesa_has_texture_cube_map_array(ctx); 78bf215546Sopenharmony_ci } 79bf215546Sopenharmony_ci break; 80bf215546Sopenharmony_ci } 81bf215546Sopenharmony_ci 82bf215546Sopenharmony_ci if (!_mesa_is_desktop_gl(ctx)) 83bf215546Sopenharmony_ci return false; 84bf215546Sopenharmony_ci 85bf215546Sopenharmony_ci switch (dims) { 86bf215546Sopenharmony_ci case 1: 87bf215546Sopenharmony_ci switch (target) { 88bf215546Sopenharmony_ci case GL_TEXTURE_1D: 89bf215546Sopenharmony_ci case GL_PROXY_TEXTURE_1D: 90bf215546Sopenharmony_ci return true; 91bf215546Sopenharmony_ci default: 92bf215546Sopenharmony_ci return false; 93bf215546Sopenharmony_ci } 94bf215546Sopenharmony_ci case 2: 95bf215546Sopenharmony_ci switch (target) { 96bf215546Sopenharmony_ci case GL_PROXY_TEXTURE_2D: 97bf215546Sopenharmony_ci case GL_PROXY_TEXTURE_CUBE_MAP: 98bf215546Sopenharmony_ci return true; 99bf215546Sopenharmony_ci case GL_TEXTURE_RECTANGLE: 100bf215546Sopenharmony_ci case GL_PROXY_TEXTURE_RECTANGLE: 101bf215546Sopenharmony_ci return ctx->Extensions.NV_texture_rectangle; 102bf215546Sopenharmony_ci case GL_TEXTURE_1D_ARRAY: 103bf215546Sopenharmony_ci case GL_PROXY_TEXTURE_1D_ARRAY: 104bf215546Sopenharmony_ci return ctx->Extensions.EXT_texture_array; 105bf215546Sopenharmony_ci default: 106bf215546Sopenharmony_ci return false; 107bf215546Sopenharmony_ci } 108bf215546Sopenharmony_ci case 3: 109bf215546Sopenharmony_ci switch (target) { 110bf215546Sopenharmony_ci case GL_PROXY_TEXTURE_3D: 111bf215546Sopenharmony_ci return true; 112bf215546Sopenharmony_ci case GL_PROXY_TEXTURE_2D_ARRAY: 113bf215546Sopenharmony_ci return ctx->Extensions.EXT_texture_array; 114bf215546Sopenharmony_ci case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY: 115bf215546Sopenharmony_ci return ctx->Extensions.ARB_texture_cube_map_array; 116bf215546Sopenharmony_ci default: 117bf215546Sopenharmony_ci return false; 118bf215546Sopenharmony_ci } 119bf215546Sopenharmony_ci default: 120bf215546Sopenharmony_ci unreachable("impossible dimensions"); 121bf215546Sopenharmony_ci } 122bf215546Sopenharmony_ci} 123bf215546Sopenharmony_ci 124bf215546Sopenharmony_ci 125bf215546Sopenharmony_ci/** Helper to get a particular texture image in a texture object */ 126bf215546Sopenharmony_cistatic struct gl_texture_image * 127bf215546Sopenharmony_ciget_tex_image(struct gl_context *ctx, 128bf215546Sopenharmony_ci struct gl_texture_object *texObj, 129bf215546Sopenharmony_ci GLuint face, GLuint level) 130bf215546Sopenharmony_ci{ 131bf215546Sopenharmony_ci const GLenum faceTarget = 132bf215546Sopenharmony_ci (texObj->Target == GL_TEXTURE_CUBE_MAP || 133bf215546Sopenharmony_ci texObj->Target == GL_PROXY_TEXTURE_CUBE_MAP) 134bf215546Sopenharmony_ci ? GL_TEXTURE_CUBE_MAP_POSITIVE_X + face : texObj->Target; 135bf215546Sopenharmony_ci return _mesa_get_tex_image(ctx, texObj, faceTarget, level); 136bf215546Sopenharmony_ci} 137bf215546Sopenharmony_ci 138bf215546Sopenharmony_ci 139bf215546Sopenharmony_ci 140bf215546Sopenharmony_cistatic GLboolean 141bf215546Sopenharmony_ciinitialize_texture_fields(struct gl_context *ctx, 142bf215546Sopenharmony_ci struct gl_texture_object *texObj, 143bf215546Sopenharmony_ci GLint levels, 144bf215546Sopenharmony_ci GLsizei width, GLsizei height, GLsizei depth, 145bf215546Sopenharmony_ci GLenum internalFormat, mesa_format texFormat) 146bf215546Sopenharmony_ci{ 147bf215546Sopenharmony_ci const GLenum target = texObj->Target; 148bf215546Sopenharmony_ci const GLuint numFaces = _mesa_num_tex_faces(target); 149bf215546Sopenharmony_ci GLint level, levelWidth = width, levelHeight = height, levelDepth = depth; 150bf215546Sopenharmony_ci GLuint face; 151bf215546Sopenharmony_ci 152bf215546Sopenharmony_ci /* Set up all the texture object's gl_texture_images */ 153bf215546Sopenharmony_ci for (level = 0; level < levels; level++) { 154bf215546Sopenharmony_ci for (face = 0; face < numFaces; face++) { 155bf215546Sopenharmony_ci struct gl_texture_image *texImage = 156bf215546Sopenharmony_ci get_tex_image(ctx, texObj, face, level); 157bf215546Sopenharmony_ci 158bf215546Sopenharmony_ci if (!texImage) { 159bf215546Sopenharmony_ci _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexStorage"); 160bf215546Sopenharmony_ci return GL_FALSE; 161bf215546Sopenharmony_ci } 162bf215546Sopenharmony_ci 163bf215546Sopenharmony_ci _mesa_init_teximage_fields(ctx, texImage, 164bf215546Sopenharmony_ci levelWidth, levelHeight, levelDepth, 165bf215546Sopenharmony_ci 0, internalFormat, texFormat); 166bf215546Sopenharmony_ci } 167bf215546Sopenharmony_ci 168bf215546Sopenharmony_ci _mesa_next_mipmap_level_size(target, 0, 169bf215546Sopenharmony_ci levelWidth, levelHeight, levelDepth, 170bf215546Sopenharmony_ci &levelWidth, &levelHeight, &levelDepth); 171bf215546Sopenharmony_ci } 172bf215546Sopenharmony_ci return GL_TRUE; 173bf215546Sopenharmony_ci} 174bf215546Sopenharmony_ci 175bf215546Sopenharmony_ci 176bf215546Sopenharmony_ci/** 177bf215546Sopenharmony_ci * Clear all fields of texture object to zeros. Used for proxy texture tests 178bf215546Sopenharmony_ci * and to clean up when a texture memory allocation fails. 179bf215546Sopenharmony_ci */ 180bf215546Sopenharmony_cistatic void 181bf215546Sopenharmony_ciclear_texture_fields(struct gl_context *ctx, 182bf215546Sopenharmony_ci struct gl_texture_object *texObj) 183bf215546Sopenharmony_ci{ 184bf215546Sopenharmony_ci const GLenum target = texObj->Target; 185bf215546Sopenharmony_ci const GLuint numFaces = _mesa_num_tex_faces(target); 186bf215546Sopenharmony_ci GLint level; 187bf215546Sopenharmony_ci GLuint face; 188bf215546Sopenharmony_ci 189bf215546Sopenharmony_ci for (level = 0; level < ARRAY_SIZE(texObj->Image[0]); level++) { 190bf215546Sopenharmony_ci for (face = 0; face < numFaces; face++) { 191bf215546Sopenharmony_ci struct gl_texture_image *texImage = 192bf215546Sopenharmony_ci get_tex_image(ctx, texObj, face, level); 193bf215546Sopenharmony_ci 194bf215546Sopenharmony_ci if (!texImage) { 195bf215546Sopenharmony_ci _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexStorage"); 196bf215546Sopenharmony_ci return; 197bf215546Sopenharmony_ci } 198bf215546Sopenharmony_ci 199bf215546Sopenharmony_ci _mesa_clear_texture_image(ctx, texImage); 200bf215546Sopenharmony_ci } 201bf215546Sopenharmony_ci } 202bf215546Sopenharmony_ci} 203bf215546Sopenharmony_ci 204bf215546Sopenharmony_ci 205bf215546Sopenharmony_ci/** 206bf215546Sopenharmony_ci * Update/re-validate framebuffer object. 207bf215546Sopenharmony_ci */ 208bf215546Sopenharmony_cistatic void 209bf215546Sopenharmony_ciupdate_fbo_texture(struct gl_context *ctx, struct gl_texture_object *texObj) 210bf215546Sopenharmony_ci{ 211bf215546Sopenharmony_ci const unsigned numFaces = _mesa_num_tex_faces(texObj->Target); 212bf215546Sopenharmony_ci for (int level = 0; level < ARRAY_SIZE(texObj->Image[0]); level++) { 213bf215546Sopenharmony_ci for (unsigned face = 0; face < numFaces; face++) 214bf215546Sopenharmony_ci _mesa_update_fbo_texture(ctx, texObj, face, level); 215bf215546Sopenharmony_ci } 216bf215546Sopenharmony_ci} 217bf215546Sopenharmony_ci 218bf215546Sopenharmony_ci 219bf215546Sopenharmony_ciGLboolean 220bf215546Sopenharmony_ci_mesa_is_legal_tex_storage_format(const struct gl_context *ctx, 221bf215546Sopenharmony_ci GLenum internalformat) 222bf215546Sopenharmony_ci{ 223bf215546Sopenharmony_ci /* check internal format - note that only sized formats are allowed */ 224bf215546Sopenharmony_ci switch (internalformat) { 225bf215546Sopenharmony_ci case GL_ALPHA: 226bf215546Sopenharmony_ci case GL_LUMINANCE: 227bf215546Sopenharmony_ci case GL_LUMINANCE_ALPHA: 228bf215546Sopenharmony_ci case GL_INTENSITY: 229bf215546Sopenharmony_ci case GL_RED: 230bf215546Sopenharmony_ci case GL_RG: 231bf215546Sopenharmony_ci case GL_RGB: 232bf215546Sopenharmony_ci case GL_RGBA: 233bf215546Sopenharmony_ci case GL_BGRA: 234bf215546Sopenharmony_ci case GL_DEPTH_COMPONENT: 235bf215546Sopenharmony_ci case GL_DEPTH_STENCIL: 236bf215546Sopenharmony_ci case GL_COMPRESSED_ALPHA: 237bf215546Sopenharmony_ci case GL_COMPRESSED_LUMINANCE_ALPHA: 238bf215546Sopenharmony_ci case GL_COMPRESSED_LUMINANCE: 239bf215546Sopenharmony_ci case GL_COMPRESSED_INTENSITY: 240bf215546Sopenharmony_ci case GL_COMPRESSED_RGB: 241bf215546Sopenharmony_ci case GL_COMPRESSED_RGBA: 242bf215546Sopenharmony_ci case GL_COMPRESSED_SRGB: 243bf215546Sopenharmony_ci case GL_COMPRESSED_SRGB_ALPHA: 244bf215546Sopenharmony_ci case GL_COMPRESSED_SLUMINANCE: 245bf215546Sopenharmony_ci case GL_COMPRESSED_SLUMINANCE_ALPHA: 246bf215546Sopenharmony_ci case GL_RED_INTEGER: 247bf215546Sopenharmony_ci case GL_GREEN_INTEGER: 248bf215546Sopenharmony_ci case GL_BLUE_INTEGER: 249bf215546Sopenharmony_ci case GL_ALPHA_INTEGER: 250bf215546Sopenharmony_ci case GL_RGB_INTEGER: 251bf215546Sopenharmony_ci case GL_RGBA_INTEGER: 252bf215546Sopenharmony_ci case GL_BGR_INTEGER: 253bf215546Sopenharmony_ci case GL_BGRA_INTEGER: 254bf215546Sopenharmony_ci case GL_LUMINANCE_INTEGER_EXT: 255bf215546Sopenharmony_ci case GL_LUMINANCE_ALPHA_INTEGER_EXT: 256bf215546Sopenharmony_ci /* these unsized formats are illegal */ 257bf215546Sopenharmony_ci return GL_FALSE; 258bf215546Sopenharmony_ci default: 259bf215546Sopenharmony_ci return _mesa_base_tex_format(ctx, internalformat) > 0; 260bf215546Sopenharmony_ci } 261bf215546Sopenharmony_ci} 262bf215546Sopenharmony_ci 263bf215546Sopenharmony_ci 264bf215546Sopenharmony_ci/** 265bf215546Sopenharmony_ci * Do error checking for calls to glTexStorage1/2/3D(). 266bf215546Sopenharmony_ci * If an error is found, record it with _mesa_error(), unless the target 267bf215546Sopenharmony_ci * is a proxy texture. 268bf215546Sopenharmony_ci * \return GL_TRUE if any error, GL_FALSE otherwise. 269bf215546Sopenharmony_ci */ 270bf215546Sopenharmony_cistatic GLboolean 271bf215546Sopenharmony_citex_storage_error_check(struct gl_context *ctx, 272bf215546Sopenharmony_ci struct gl_texture_object *texObj, 273bf215546Sopenharmony_ci struct gl_memory_object *memObj, 274bf215546Sopenharmony_ci GLuint dims, GLenum target, 275bf215546Sopenharmony_ci GLsizei levels, GLenum internalformat, 276bf215546Sopenharmony_ci GLsizei width, GLsizei height, GLsizei depth, 277bf215546Sopenharmony_ci bool dsa) 278bf215546Sopenharmony_ci{ 279bf215546Sopenharmony_ci const char* suffix = dsa ? (memObj ? "tureMem" : "ture") : 280bf215546Sopenharmony_ci (memObj ? "Mem" : ""); 281bf215546Sopenharmony_ci 282bf215546Sopenharmony_ci /* Legal format checking has been moved to texstorage and texturestorage in 283bf215546Sopenharmony_ci * order to allow meta functions to use legacy formats. */ 284bf215546Sopenharmony_ci 285bf215546Sopenharmony_ci /* size check */ 286bf215546Sopenharmony_ci if (!_mesa_valid_tex_storage_dim(width, height, depth)) { 287bf215546Sopenharmony_ci _mesa_error(ctx, GL_INVALID_VALUE, 288bf215546Sopenharmony_ci "glTex%sStorage%uD(width, height or depth < 1)", 289bf215546Sopenharmony_ci suffix, dims); 290bf215546Sopenharmony_ci return GL_TRUE; 291bf215546Sopenharmony_ci } 292bf215546Sopenharmony_ci 293bf215546Sopenharmony_ci if (_mesa_is_compressed_format(ctx, internalformat)) { 294bf215546Sopenharmony_ci GLenum err; 295bf215546Sopenharmony_ci if (!_mesa_target_can_be_compressed(ctx, target, internalformat, &err)) { 296bf215546Sopenharmony_ci _mesa_error(ctx, err, 297bf215546Sopenharmony_ci "glTex%sStorage%dD(internalformat = %s)", suffix, dims, 298bf215546Sopenharmony_ci _mesa_enum_to_string(internalformat)); 299bf215546Sopenharmony_ci return GL_TRUE; 300bf215546Sopenharmony_ci } 301bf215546Sopenharmony_ci } 302bf215546Sopenharmony_ci 303bf215546Sopenharmony_ci /* levels check */ 304bf215546Sopenharmony_ci if (levels < 1) { 305bf215546Sopenharmony_ci _mesa_error(ctx, GL_INVALID_VALUE, "glTex%sStorage%uD(levels < 1)", 306bf215546Sopenharmony_ci suffix, dims); 307bf215546Sopenharmony_ci return GL_TRUE; 308bf215546Sopenharmony_ci } 309bf215546Sopenharmony_ci 310bf215546Sopenharmony_ci /* check levels against maximum (note different error than above) */ 311bf215546Sopenharmony_ci if (levels > (GLint) _mesa_max_texture_levels(ctx, target)) { 312bf215546Sopenharmony_ci _mesa_error(ctx, GL_INVALID_OPERATION, 313bf215546Sopenharmony_ci "glTex%sStorage%uD(levels too large)", 314bf215546Sopenharmony_ci suffix, dims); 315bf215546Sopenharmony_ci return GL_TRUE; 316bf215546Sopenharmony_ci } 317bf215546Sopenharmony_ci 318bf215546Sopenharmony_ci /* check levels against width/height/depth */ 319bf215546Sopenharmony_ci if (levels > _mesa_get_tex_max_num_levels(target, width, height, depth)) { 320bf215546Sopenharmony_ci _mesa_error(ctx, GL_INVALID_OPERATION, 321bf215546Sopenharmony_ci "glTex%sStorage%uD(too many levels" 322bf215546Sopenharmony_ci " for max texture dimension)", 323bf215546Sopenharmony_ci suffix, dims); 324bf215546Sopenharmony_ci return GL_TRUE; 325bf215546Sopenharmony_ci } 326bf215546Sopenharmony_ci 327bf215546Sopenharmony_ci /* non-default texture object check */ 328bf215546Sopenharmony_ci if (!_mesa_is_proxy_texture(target) && (!texObj || (texObj->Name == 0))) { 329bf215546Sopenharmony_ci _mesa_error(ctx, GL_INVALID_OPERATION, 330bf215546Sopenharmony_ci "glTex%sStorage%uD(texture object 0)", 331bf215546Sopenharmony_ci suffix, dims); 332bf215546Sopenharmony_ci return GL_TRUE; 333bf215546Sopenharmony_ci } 334bf215546Sopenharmony_ci 335bf215546Sopenharmony_ci /* Check if texObj->Immutable is set */ 336bf215546Sopenharmony_ci if (!_mesa_is_proxy_texture(target) && texObj->Immutable) { 337bf215546Sopenharmony_ci _mesa_error(ctx, GL_INVALID_OPERATION, "glTex%sStorage%uD(immutable)", 338bf215546Sopenharmony_ci suffix, dims); 339bf215546Sopenharmony_ci return GL_TRUE; 340bf215546Sopenharmony_ci } 341bf215546Sopenharmony_ci 342bf215546Sopenharmony_ci /* additional checks for depth textures */ 343bf215546Sopenharmony_ci if (!_mesa_legal_texture_base_format_for_target(ctx, target, internalformat)) { 344bf215546Sopenharmony_ci _mesa_error(ctx, GL_INVALID_OPERATION, "glTex%sStorage%uD(bad target for texture)", 345bf215546Sopenharmony_ci suffix, dims); 346bf215546Sopenharmony_ci return GL_TRUE; 347bf215546Sopenharmony_ci } 348bf215546Sopenharmony_ci 349bf215546Sopenharmony_ci return GL_FALSE; 350bf215546Sopenharmony_ci} 351bf215546Sopenharmony_ci 352bf215546Sopenharmony_ciGLboolean 353bf215546Sopenharmony_ci_mesa_sparse_texture_error_check(struct gl_context *ctx, GLuint dims, 354bf215546Sopenharmony_ci struct gl_texture_object *texObj, 355bf215546Sopenharmony_ci mesa_format format, GLenum target, GLsizei levels, 356bf215546Sopenharmony_ci GLsizei width, GLsizei height, GLsizei depth, 357bf215546Sopenharmony_ci const char *func) 358bf215546Sopenharmony_ci{ 359bf215546Sopenharmony_ci int px, py, pz; 360bf215546Sopenharmony_ci int index = texObj->VirtualPageSizeIndex; 361bf215546Sopenharmony_ci if (!st_GetSparseTextureVirtualPageSize(ctx, target, format, index, 362bf215546Sopenharmony_ci &px, &py, &pz)) { 363bf215546Sopenharmony_ci _mesa_error(ctx, GL_INVALID_OPERATION, "%s(sparse index = %d)", 364bf215546Sopenharmony_ci func, index); 365bf215546Sopenharmony_ci return GL_TRUE; 366bf215546Sopenharmony_ci } 367bf215546Sopenharmony_ci 368bf215546Sopenharmony_ci if (target == GL_TEXTURE_3D) { 369bf215546Sopenharmony_ci if (width > ctx->Const.MaxSparse3DTextureSize || 370bf215546Sopenharmony_ci height > ctx->Const.MaxSparse3DTextureSize || 371bf215546Sopenharmony_ci depth > ctx->Const.MaxSparse3DTextureSize) 372bf215546Sopenharmony_ci goto exceed_max_size; 373bf215546Sopenharmony_ci } else { 374bf215546Sopenharmony_ci if (width > ctx->Const.MaxSparseTextureSize || 375bf215546Sopenharmony_ci height > ctx->Const.MaxSparseTextureSize) 376bf215546Sopenharmony_ci goto exceed_max_size; 377bf215546Sopenharmony_ci 378bf215546Sopenharmony_ci if (target == GL_TEXTURE_2D_ARRAY || 379bf215546Sopenharmony_ci target == GL_TEXTURE_CUBE_MAP_ARRAY) { 380bf215546Sopenharmony_ci if (depth > ctx->Const.MaxSparseArrayTextureLayers) 381bf215546Sopenharmony_ci goto exceed_max_size; 382bf215546Sopenharmony_ci } else if (target == GL_TEXTURE_1D_ARRAY) { 383bf215546Sopenharmony_ci if (height > ctx->Const.MaxSparseArrayTextureLayers) 384bf215546Sopenharmony_ci goto exceed_max_size; 385bf215546Sopenharmony_ci } 386bf215546Sopenharmony_ci } 387bf215546Sopenharmony_ci 388bf215546Sopenharmony_ci /* ARB_sparse_texture2 allow non-page-aligned base texture size. */ 389bf215546Sopenharmony_ci if (!_mesa_has_ARB_sparse_texture2(ctx) && 390bf215546Sopenharmony_ci (width % px || height % py || depth % pz)) { 391bf215546Sopenharmony_ci _mesa_error(ctx, GL_INVALID_VALUE, "%s(sparse page size)", func); 392bf215546Sopenharmony_ci return GL_TRUE; 393bf215546Sopenharmony_ci } 394bf215546Sopenharmony_ci 395bf215546Sopenharmony_ci /* ARB_sparse_texture spec: 396bf215546Sopenharmony_ci * 397bf215546Sopenharmony_ci * If the value of SPARSE_TEXTURE_FULL_ARRAY_CUBE_MIPMAPS_ARB is FALSE, 398bf215546Sopenharmony_ci * then TexStorage* will generate an INVALID_OPERATION error if 399bf215546Sopenharmony_ci * * the texture's TEXTURE_SPARSE_ARB parameter is TRUE, 400bf215546Sopenharmony_ci * * <target> is one of TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY, 401bf215546Sopenharmony_ci * TEXTURE_CUBE_MAP, or TEXTURE_CUBE_MAP_ARRAY, and 402bf215546Sopenharmony_ci * * for the virtual page size corresponding to the 403bf215546Sopenharmony_ci * VIRTUAL_PAGE_SIZE_INDEX_ARB parameter, either of the following is 404bf215546Sopenharmony_ci * true: 405bf215546Sopenharmony_ci * - <width> is not a multiple of VIRTUAL_PAGE_SIZE_X_ARB * 406bf215546Sopenharmony_ci * 2^(<levels>-1), or 407bf215546Sopenharmony_ci * - <height> is not a multiple of VIRTUAL_PAGE_SIZE_Y_ARB * 408bf215546Sopenharmony_ci * 2^(<levels>-1). 409bf215546Sopenharmony_ci * 410bf215546Sopenharmony_ci * This make sure all allocated mipmap level size is multiple of virtual 411bf215546Sopenharmony_ci * page size when SPARSE_TEXTURE_FULL_ARRAY_CUBE_MIPMAPS_ARB is FALSE. 412bf215546Sopenharmony_ci */ 413bf215546Sopenharmony_ci if (!ctx->Const.SparseTextureFullArrayCubeMipmaps && 414bf215546Sopenharmony_ci (target == GL_TEXTURE_1D_ARRAY || 415bf215546Sopenharmony_ci target == GL_TEXTURE_2D_ARRAY || 416bf215546Sopenharmony_ci target == GL_TEXTURE_CUBE_MAP || 417bf215546Sopenharmony_ci target == GL_TEXTURE_CUBE_MAP_ARRAY) && 418bf215546Sopenharmony_ci (width % (px << (levels - 1)) || 419bf215546Sopenharmony_ci height % (py << (levels - 1)))) { 420bf215546Sopenharmony_ci _mesa_error(ctx, GL_INVALID_OPERATION, "%s(sparse array align)", func); 421bf215546Sopenharmony_ci return GL_TRUE; 422bf215546Sopenharmony_ci } 423bf215546Sopenharmony_ci 424bf215546Sopenharmony_ci return GL_FALSE; 425bf215546Sopenharmony_ci 426bf215546Sopenharmony_ciexceed_max_size: 427bf215546Sopenharmony_ci _mesa_error(ctx, GL_INVALID_VALUE, "%s(exceed max sparse size)", func); 428bf215546Sopenharmony_ci return GL_TRUE; 429bf215546Sopenharmony_ci} 430bf215546Sopenharmony_ci 431bf215546Sopenharmony_ci/** 432bf215546Sopenharmony_ci * Helper that does the storage allocation for _mesa_TexStorage1/2/3D() 433bf215546Sopenharmony_ci * and _mesa_TextureStorage1/2/3D(). 434bf215546Sopenharmony_ci */ 435bf215546Sopenharmony_cistatic ALWAYS_INLINE void 436bf215546Sopenharmony_citexture_storage(struct gl_context *ctx, GLuint dims, 437bf215546Sopenharmony_ci struct gl_texture_object *texObj, 438bf215546Sopenharmony_ci struct gl_memory_object *memObj, GLenum target, 439bf215546Sopenharmony_ci GLsizei levels, GLenum internalformat, GLsizei width, 440bf215546Sopenharmony_ci GLsizei height, GLsizei depth, GLuint64 offset, bool dsa, 441bf215546Sopenharmony_ci bool no_error) 442bf215546Sopenharmony_ci{ 443bf215546Sopenharmony_ci GLboolean sizeOK = GL_TRUE, dimensionsOK = GL_TRUE; 444bf215546Sopenharmony_ci mesa_format texFormat; 445bf215546Sopenharmony_ci const char* suffix = dsa ? (memObj ? "tureMem" : "ture") : 446bf215546Sopenharmony_ci (memObj ? "Mem" : ""); 447bf215546Sopenharmony_ci 448bf215546Sopenharmony_ci assert(texObj); 449bf215546Sopenharmony_ci 450bf215546Sopenharmony_ci if (!no_error) { 451bf215546Sopenharmony_ci if (tex_storage_error_check(ctx, texObj, memObj, dims, target, levels, 452bf215546Sopenharmony_ci internalformat, width, height, depth, dsa)) { 453bf215546Sopenharmony_ci return; /* error was recorded */ 454bf215546Sopenharmony_ci } 455bf215546Sopenharmony_ci } 456bf215546Sopenharmony_ci 457bf215546Sopenharmony_ci texFormat = _mesa_choose_texture_format(ctx, texObj, target, 0, 458bf215546Sopenharmony_ci internalformat, GL_NONE, GL_NONE); 459bf215546Sopenharmony_ci 460bf215546Sopenharmony_ci if (!no_error) { 461bf215546Sopenharmony_ci /* check that width, height, depth are legal for the mipmap level */ 462bf215546Sopenharmony_ci dimensionsOK = _mesa_legal_texture_dimensions(ctx, target, 0, 463bf215546Sopenharmony_ci width, height, depth, 0); 464bf215546Sopenharmony_ci 465bf215546Sopenharmony_ci sizeOK = st_TestProxyTexImage(ctx, target, levels, 0, texFormat, 466bf215546Sopenharmony_ci 1, width, height, depth); 467bf215546Sopenharmony_ci } 468bf215546Sopenharmony_ci 469bf215546Sopenharmony_ci if (_mesa_is_proxy_texture(target)) { 470bf215546Sopenharmony_ci if (dimensionsOK && sizeOK) { 471bf215546Sopenharmony_ci initialize_texture_fields(ctx, texObj, levels, width, height, depth, 472bf215546Sopenharmony_ci internalformat, texFormat); 473bf215546Sopenharmony_ci } 474bf215546Sopenharmony_ci else { 475bf215546Sopenharmony_ci /* clear all image fields for [levels] */ 476bf215546Sopenharmony_ci clear_texture_fields(ctx, texObj); 477bf215546Sopenharmony_ci } 478bf215546Sopenharmony_ci } 479bf215546Sopenharmony_ci else { 480bf215546Sopenharmony_ci if (!no_error) { 481bf215546Sopenharmony_ci if (!dimensionsOK) { 482bf215546Sopenharmony_ci _mesa_error(ctx, GL_INVALID_VALUE, 483bf215546Sopenharmony_ci "glTex%sStorage%uD(invalid width, height or depth)", 484bf215546Sopenharmony_ci suffix, dims); 485bf215546Sopenharmony_ci return; 486bf215546Sopenharmony_ci } 487bf215546Sopenharmony_ci 488bf215546Sopenharmony_ci if (!sizeOK) { 489bf215546Sopenharmony_ci _mesa_error(ctx, GL_OUT_OF_MEMORY, 490bf215546Sopenharmony_ci "glTex%sStorage%uD(texture too large)", 491bf215546Sopenharmony_ci suffix, dims); 492bf215546Sopenharmony_ci return; 493bf215546Sopenharmony_ci } 494bf215546Sopenharmony_ci 495bf215546Sopenharmony_ci if (texObj->IsSparse) { 496bf215546Sopenharmony_ci char func[32]; 497bf215546Sopenharmony_ci snprintf(func, 32, "glTex%sStorage%uD", suffix, dims); 498bf215546Sopenharmony_ci if (_mesa_sparse_texture_error_check(ctx, dims, texObj, texFormat, target, 499bf215546Sopenharmony_ci levels, width, height, depth, func)) 500bf215546Sopenharmony_ci return; /* error was recorded */ 501bf215546Sopenharmony_ci } 502bf215546Sopenharmony_ci } 503bf215546Sopenharmony_ci 504bf215546Sopenharmony_ci assert(levels > 0); 505bf215546Sopenharmony_ci assert(width > 0); 506bf215546Sopenharmony_ci assert(height > 0); 507bf215546Sopenharmony_ci assert(depth > 0); 508bf215546Sopenharmony_ci 509bf215546Sopenharmony_ci if (!initialize_texture_fields(ctx, texObj, levels, width, height, depth, 510bf215546Sopenharmony_ci internalformat, texFormat)) { 511bf215546Sopenharmony_ci return; 512bf215546Sopenharmony_ci } 513bf215546Sopenharmony_ci 514bf215546Sopenharmony_ci /* Setup the backing memory */ 515bf215546Sopenharmony_ci if (memObj) { 516bf215546Sopenharmony_ci if (!st_SetTextureStorageForMemoryObject(ctx, texObj, memObj, 517bf215546Sopenharmony_ci levels, 518bf215546Sopenharmony_ci width, height, depth, 519bf215546Sopenharmony_ci offset)) { 520bf215546Sopenharmony_ci 521bf215546Sopenharmony_ci clear_texture_fields(ctx, texObj); 522bf215546Sopenharmony_ci return; 523bf215546Sopenharmony_ci } 524bf215546Sopenharmony_ci } 525bf215546Sopenharmony_ci else { 526bf215546Sopenharmony_ci if (!st_AllocTextureStorage(ctx, texObj, levels, 527bf215546Sopenharmony_ci width, height, depth)) { 528bf215546Sopenharmony_ci /* Reset the texture images' info to zeros. 529bf215546Sopenharmony_ci * Strictly speaking, we probably don't have to do this since 530bf215546Sopenharmony_ci * generating GL_OUT_OF_MEMORY can leave things in an undefined 531bf215546Sopenharmony_ci * state but this puts things in a consistent state. 532bf215546Sopenharmony_ci */ 533bf215546Sopenharmony_ci clear_texture_fields(ctx, texObj); 534bf215546Sopenharmony_ci _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTex%sStorage%uD", 535bf215546Sopenharmony_ci suffix, dims); 536bf215546Sopenharmony_ci return; 537bf215546Sopenharmony_ci } 538bf215546Sopenharmony_ci } 539bf215546Sopenharmony_ci 540bf215546Sopenharmony_ci _mesa_set_texture_view_state(ctx, texObj, target, levels); 541bf215546Sopenharmony_ci 542bf215546Sopenharmony_ci update_fbo_texture(ctx, texObj); 543bf215546Sopenharmony_ci } 544bf215546Sopenharmony_ci} 545bf215546Sopenharmony_ci 546bf215546Sopenharmony_ci 547bf215546Sopenharmony_cistatic void 548bf215546Sopenharmony_citexture_storage_error(struct gl_context *ctx, GLuint dims, 549bf215546Sopenharmony_ci struct gl_texture_object *texObj, 550bf215546Sopenharmony_ci GLenum target, GLsizei levels, 551bf215546Sopenharmony_ci GLenum internalformat, GLsizei width, 552bf215546Sopenharmony_ci GLsizei height, GLsizei depth, bool dsa) 553bf215546Sopenharmony_ci{ 554bf215546Sopenharmony_ci texture_storage(ctx, dims, texObj, NULL, target, levels, internalformat, 555bf215546Sopenharmony_ci width, height, depth, dsa, 0, false); 556bf215546Sopenharmony_ci} 557bf215546Sopenharmony_ci 558bf215546Sopenharmony_ci 559bf215546Sopenharmony_cistatic void 560bf215546Sopenharmony_citexture_storage_no_error(struct gl_context *ctx, GLuint dims, 561bf215546Sopenharmony_ci struct gl_texture_object *texObj, 562bf215546Sopenharmony_ci GLenum target, GLsizei levels, 563bf215546Sopenharmony_ci GLenum internalformat, GLsizei width, 564bf215546Sopenharmony_ci GLsizei height, GLsizei depth, bool dsa) 565bf215546Sopenharmony_ci{ 566bf215546Sopenharmony_ci texture_storage(ctx, dims, texObj, NULL, target, levels, internalformat, 567bf215546Sopenharmony_ci width, height, depth, dsa, 0, true); 568bf215546Sopenharmony_ci} 569bf215546Sopenharmony_ci 570bf215546Sopenharmony_ci 571bf215546Sopenharmony_ci/** 572bf215546Sopenharmony_ci * Helper used by _mesa_TexStorage1/2/3D(). 573bf215546Sopenharmony_ci */ 574bf215546Sopenharmony_cistatic void 575bf215546Sopenharmony_citexstorage_error(GLuint dims, GLenum target, GLsizei levels, 576bf215546Sopenharmony_ci GLenum internalformat, GLsizei width, GLsizei height, 577bf215546Sopenharmony_ci GLsizei depth, const char *caller) 578bf215546Sopenharmony_ci{ 579bf215546Sopenharmony_ci struct gl_texture_object *texObj; 580bf215546Sopenharmony_ci GET_CURRENT_CONTEXT(ctx); 581bf215546Sopenharmony_ci 582bf215546Sopenharmony_ci /* Check target. This is done here so that texture_storage 583bf215546Sopenharmony_ci * can receive unsized formats. 584bf215546Sopenharmony_ci */ 585bf215546Sopenharmony_ci if (!_mesa_is_legal_tex_storage_target(ctx, dims, target)) { 586bf215546Sopenharmony_ci _mesa_error(ctx, GL_INVALID_ENUM, 587bf215546Sopenharmony_ci "%s(illegal target=%s)", 588bf215546Sopenharmony_ci caller, _mesa_enum_to_string(target)); 589bf215546Sopenharmony_ci return; 590bf215546Sopenharmony_ci } 591bf215546Sopenharmony_ci 592bf215546Sopenharmony_ci if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 593bf215546Sopenharmony_ci _mesa_debug(ctx, "%s %s %d %s %d %d %d\n", caller, 594bf215546Sopenharmony_ci _mesa_enum_to_string(target), levels, 595bf215546Sopenharmony_ci _mesa_enum_to_string(internalformat), 596bf215546Sopenharmony_ci width, height, depth); 597bf215546Sopenharmony_ci 598bf215546Sopenharmony_ci /* Check the format to make sure it is sized. */ 599bf215546Sopenharmony_ci if (!_mesa_is_legal_tex_storage_format(ctx, internalformat)) { 600bf215546Sopenharmony_ci _mesa_error(ctx, GL_INVALID_ENUM, 601bf215546Sopenharmony_ci "%s(internalformat = %s)", caller, 602bf215546Sopenharmony_ci _mesa_enum_to_string(internalformat)); 603bf215546Sopenharmony_ci return; 604bf215546Sopenharmony_ci } 605bf215546Sopenharmony_ci 606bf215546Sopenharmony_ci texObj = _mesa_get_current_tex_object(ctx, target); 607bf215546Sopenharmony_ci if (!texObj) 608bf215546Sopenharmony_ci return; 609bf215546Sopenharmony_ci 610bf215546Sopenharmony_ci texture_storage_error(ctx, dims, texObj, target, levels, 611bf215546Sopenharmony_ci internalformat, width, height, depth, false); 612bf215546Sopenharmony_ci} 613bf215546Sopenharmony_ci 614bf215546Sopenharmony_ci 615bf215546Sopenharmony_cistatic void 616bf215546Sopenharmony_citexstorage_no_error(GLuint dims, GLenum target, GLsizei levels, 617bf215546Sopenharmony_ci GLenum internalformat, GLsizei width, GLsizei height, 618bf215546Sopenharmony_ci GLsizei depth) 619bf215546Sopenharmony_ci{ 620bf215546Sopenharmony_ci GET_CURRENT_CONTEXT(ctx); 621bf215546Sopenharmony_ci 622bf215546Sopenharmony_ci struct gl_texture_object *texObj = _mesa_get_current_tex_object(ctx, target); 623bf215546Sopenharmony_ci texture_storage_no_error(ctx, dims, texObj, target, levels, 624bf215546Sopenharmony_ci internalformat, width, height, depth, false); 625bf215546Sopenharmony_ci} 626bf215546Sopenharmony_ci 627bf215546Sopenharmony_ci 628bf215546Sopenharmony_ci/** 629bf215546Sopenharmony_ci * Helper used by _mesa_TextureStorage1/2/3D(). 630bf215546Sopenharmony_ci */ 631bf215546Sopenharmony_cistatic void 632bf215546Sopenharmony_citexturestorage_error(GLuint dims, GLuint texture, GLsizei levels, 633bf215546Sopenharmony_ci GLenum internalformat, GLsizei width, GLsizei height, 634bf215546Sopenharmony_ci GLsizei depth, const char *caller) 635bf215546Sopenharmony_ci{ 636bf215546Sopenharmony_ci struct gl_texture_object *texObj; 637bf215546Sopenharmony_ci GET_CURRENT_CONTEXT(ctx); 638bf215546Sopenharmony_ci 639bf215546Sopenharmony_ci if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) 640bf215546Sopenharmony_ci _mesa_debug(ctx, "%s %d %d %s %d %d %d\n", 641bf215546Sopenharmony_ci caller, texture, levels, 642bf215546Sopenharmony_ci _mesa_enum_to_string(internalformat), 643bf215546Sopenharmony_ci width, height, depth); 644bf215546Sopenharmony_ci 645bf215546Sopenharmony_ci /* Check the format to make sure it is sized. */ 646bf215546Sopenharmony_ci if (!_mesa_is_legal_tex_storage_format(ctx, internalformat)) { 647bf215546Sopenharmony_ci _mesa_error(ctx, GL_INVALID_ENUM, 648bf215546Sopenharmony_ci "%s(internalformat = %s)", caller, 649bf215546Sopenharmony_ci _mesa_enum_to_string(internalformat)); 650bf215546Sopenharmony_ci return; 651bf215546Sopenharmony_ci } 652bf215546Sopenharmony_ci 653bf215546Sopenharmony_ci texObj = _mesa_lookup_texture_err(ctx, texture, caller); 654bf215546Sopenharmony_ci if (!texObj) 655bf215546Sopenharmony_ci return; 656bf215546Sopenharmony_ci 657bf215546Sopenharmony_ci /* Check target. This is done here so that texture_storage 658bf215546Sopenharmony_ci * can receive unsized formats. 659bf215546Sopenharmony_ci */ 660bf215546Sopenharmony_ci if (!_mesa_is_legal_tex_storage_target(ctx, dims, texObj->Target)) { 661bf215546Sopenharmony_ci _mesa_error(ctx, GL_INVALID_OPERATION, 662bf215546Sopenharmony_ci "%s(illegal target=%s)", caller, 663bf215546Sopenharmony_ci _mesa_enum_to_string(texObj->Target)); 664bf215546Sopenharmony_ci return; 665bf215546Sopenharmony_ci } 666bf215546Sopenharmony_ci 667bf215546Sopenharmony_ci texture_storage_error(ctx, dims, texObj, texObj->Target, 668bf215546Sopenharmony_ci levels, internalformat, width, height, depth, true); 669bf215546Sopenharmony_ci} 670bf215546Sopenharmony_ci 671bf215546Sopenharmony_ci 672bf215546Sopenharmony_cistatic void 673bf215546Sopenharmony_citexturestorage_no_error(GLuint dims, GLuint texture, GLsizei levels, 674bf215546Sopenharmony_ci GLenum internalformat, GLsizei width, GLsizei height, 675bf215546Sopenharmony_ci GLsizei depth) 676bf215546Sopenharmony_ci{ 677bf215546Sopenharmony_ci GET_CURRENT_CONTEXT(ctx); 678bf215546Sopenharmony_ci 679bf215546Sopenharmony_ci struct gl_texture_object *texObj = _mesa_lookup_texture(ctx, texture); 680bf215546Sopenharmony_ci texture_storage_no_error(ctx, dims, texObj, texObj->Target, 681bf215546Sopenharmony_ci levels, internalformat, width, height, depth, true); 682bf215546Sopenharmony_ci} 683bf215546Sopenharmony_ci 684bf215546Sopenharmony_ci 685bf215546Sopenharmony_civoid GLAPIENTRY 686bf215546Sopenharmony_ci_mesa_TexStorage1D_no_error(GLenum target, GLsizei levels, 687bf215546Sopenharmony_ci GLenum internalformat, GLsizei width) 688bf215546Sopenharmony_ci{ 689bf215546Sopenharmony_ci texstorage_no_error(1, target, levels, internalformat, width, 1, 1); 690bf215546Sopenharmony_ci} 691bf215546Sopenharmony_ci 692bf215546Sopenharmony_ci 693bf215546Sopenharmony_civoid GLAPIENTRY 694bf215546Sopenharmony_ci_mesa_TexStorage1D(GLenum target, GLsizei levels, GLenum internalformat, 695bf215546Sopenharmony_ci GLsizei width) 696bf215546Sopenharmony_ci{ 697bf215546Sopenharmony_ci texstorage_error(1, target, levels, internalformat, width, 1, 1, 698bf215546Sopenharmony_ci "glTexStorage1D"); 699bf215546Sopenharmony_ci} 700bf215546Sopenharmony_ci 701bf215546Sopenharmony_ci 702bf215546Sopenharmony_civoid GLAPIENTRY 703bf215546Sopenharmony_ci_mesa_TexStorage2D_no_error(GLenum target, GLsizei levels, 704bf215546Sopenharmony_ci GLenum internalformat, GLsizei width, 705bf215546Sopenharmony_ci GLsizei height) 706bf215546Sopenharmony_ci{ 707bf215546Sopenharmony_ci texstorage_no_error(2, target, levels, internalformat, width, height, 1); 708bf215546Sopenharmony_ci} 709bf215546Sopenharmony_ci 710bf215546Sopenharmony_ci 711bf215546Sopenharmony_civoid GLAPIENTRY 712bf215546Sopenharmony_ci_mesa_TexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, 713bf215546Sopenharmony_ci GLsizei width, GLsizei height) 714bf215546Sopenharmony_ci{ 715bf215546Sopenharmony_ci texstorage_error(2, target, levels, internalformat, width, height, 1, 716bf215546Sopenharmony_ci "glTexStorage2D"); 717bf215546Sopenharmony_ci} 718bf215546Sopenharmony_ci 719bf215546Sopenharmony_ci 720bf215546Sopenharmony_civoid GLAPIENTRY 721bf215546Sopenharmony_ci_mesa_TexStorage3D_no_error(GLenum target, GLsizei levels, 722bf215546Sopenharmony_ci GLenum internalformat, GLsizei width, 723bf215546Sopenharmony_ci GLsizei height, GLsizei depth) 724bf215546Sopenharmony_ci{ 725bf215546Sopenharmony_ci texstorage_no_error(3, target, levels, internalformat, width, height, depth); 726bf215546Sopenharmony_ci} 727bf215546Sopenharmony_ci 728bf215546Sopenharmony_ci 729bf215546Sopenharmony_civoid GLAPIENTRY 730bf215546Sopenharmony_ci_mesa_TexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, 731bf215546Sopenharmony_ci GLsizei width, GLsizei height, GLsizei depth) 732bf215546Sopenharmony_ci{ 733bf215546Sopenharmony_ci texstorage_error(3, target, levels, internalformat, width, height, depth, 734bf215546Sopenharmony_ci "glTexStorage3D"); 735bf215546Sopenharmony_ci} 736bf215546Sopenharmony_ci 737bf215546Sopenharmony_ci 738bf215546Sopenharmony_civoid GLAPIENTRY 739bf215546Sopenharmony_ci_mesa_TextureStorage1D_no_error(GLuint texture, GLsizei levels, 740bf215546Sopenharmony_ci GLenum internalformat, GLsizei width) 741bf215546Sopenharmony_ci{ 742bf215546Sopenharmony_ci texturestorage_no_error(1, texture, levels, internalformat, width, 1, 1); 743bf215546Sopenharmony_ci} 744bf215546Sopenharmony_ci 745bf215546Sopenharmony_ci 746bf215546Sopenharmony_civoid GLAPIENTRY 747bf215546Sopenharmony_ci_mesa_TextureStorage1D(GLuint texture, GLsizei levels, GLenum internalformat, 748bf215546Sopenharmony_ci GLsizei width) 749bf215546Sopenharmony_ci{ 750bf215546Sopenharmony_ci texturestorage_error(1, texture, levels, internalformat, width, 1, 1, 751bf215546Sopenharmony_ci "glTextureStorage1D"); 752bf215546Sopenharmony_ci} 753bf215546Sopenharmony_ci 754bf215546Sopenharmony_ci 755bf215546Sopenharmony_civoid GLAPIENTRY 756bf215546Sopenharmony_ci_mesa_TextureStorage2D_no_error(GLuint texture, GLsizei levels, 757bf215546Sopenharmony_ci GLenum internalformat, 758bf215546Sopenharmony_ci GLsizei width, GLsizei height) 759bf215546Sopenharmony_ci{ 760bf215546Sopenharmony_ci texturestorage_no_error(2, texture, levels, internalformat, width, height, 1); 761bf215546Sopenharmony_ci} 762bf215546Sopenharmony_ci 763bf215546Sopenharmony_ci 764bf215546Sopenharmony_civoid GLAPIENTRY 765bf215546Sopenharmony_ci_mesa_TextureStorage2D(GLuint texture, GLsizei levels, 766bf215546Sopenharmony_ci GLenum internalformat, 767bf215546Sopenharmony_ci GLsizei width, GLsizei height) 768bf215546Sopenharmony_ci{ 769bf215546Sopenharmony_ci texturestorage_error(2, texture, levels, internalformat, width, height, 1, 770bf215546Sopenharmony_ci "glTextureStorage2D"); 771bf215546Sopenharmony_ci} 772bf215546Sopenharmony_ci 773bf215546Sopenharmony_ci 774bf215546Sopenharmony_civoid GLAPIENTRY 775bf215546Sopenharmony_ci_mesa_TextureStorage3D_no_error(GLuint texture, GLsizei levels, 776bf215546Sopenharmony_ci GLenum internalformat, GLsizei width, 777bf215546Sopenharmony_ci GLsizei height, GLsizei depth) 778bf215546Sopenharmony_ci{ 779bf215546Sopenharmony_ci texturestorage_no_error(3, texture, levels, internalformat, width, height, 780bf215546Sopenharmony_ci depth); 781bf215546Sopenharmony_ci} 782bf215546Sopenharmony_ci 783bf215546Sopenharmony_ci 784bf215546Sopenharmony_civoid GLAPIENTRY 785bf215546Sopenharmony_ci_mesa_TextureStorage3D(GLuint texture, GLsizei levels, GLenum internalformat, 786bf215546Sopenharmony_ci GLsizei width, GLsizei height, GLsizei depth) 787bf215546Sopenharmony_ci{ 788bf215546Sopenharmony_ci texturestorage_error(3, texture, levels, internalformat, width, height, depth, 789bf215546Sopenharmony_ci "glTextureStorage3D"); 790bf215546Sopenharmony_ci} 791bf215546Sopenharmony_ci 792bf215546Sopenharmony_ci 793bf215546Sopenharmony_civoid GLAPIENTRY 794bf215546Sopenharmony_ci_mesa_TextureStorage1DEXT(GLuint texture, GLenum target, GLsizei levels, 795bf215546Sopenharmony_ci GLenum internalformat, 796bf215546Sopenharmony_ci GLsizei width) 797bf215546Sopenharmony_ci{ 798bf215546Sopenharmony_ci GET_CURRENT_CONTEXT(ctx); 799bf215546Sopenharmony_ci /* 'texture' must always be initialized, even if the call to 800bf215546Sopenharmony_ci * glTextureStorage1DEXT will generate an error. 801bf215546Sopenharmony_ci */ 802bf215546Sopenharmony_ci if (!_mesa_lookup_or_create_texture(ctx, target, texture, false, true, 803bf215546Sopenharmony_ci "glTextureStorage1DEXT")) 804bf215546Sopenharmony_ci return; 805bf215546Sopenharmony_ci texturestorage_error(1, texture, levels, internalformat, width, 1, 1, 806bf215546Sopenharmony_ci "glTextureStorage1DEXT"); 807bf215546Sopenharmony_ci} 808bf215546Sopenharmony_ci 809bf215546Sopenharmony_ci 810bf215546Sopenharmony_civoid GLAPIENTRY 811bf215546Sopenharmony_ci_mesa_TextureStorage2DEXT(GLuint texture, GLenum target, GLsizei levels, 812bf215546Sopenharmony_ci GLenum internalformat, 813bf215546Sopenharmony_ci GLsizei width, GLsizei height) 814bf215546Sopenharmony_ci{ 815bf215546Sopenharmony_ci GET_CURRENT_CONTEXT(ctx); 816bf215546Sopenharmony_ci /* 'texture' must always be initialized, even if the call to 817bf215546Sopenharmony_ci * glTextureStorage2DEXT will generate an error. 818bf215546Sopenharmony_ci */ 819bf215546Sopenharmony_ci if (!_mesa_lookup_or_create_texture(ctx, target, texture, false, true, 820bf215546Sopenharmony_ci "glTextureStorage2DEXT")) 821bf215546Sopenharmony_ci return; 822bf215546Sopenharmony_ci texturestorage_error(2, texture, levels, internalformat, width, height, 1, 823bf215546Sopenharmony_ci "glTextureStorage2DEXT"); 824bf215546Sopenharmony_ci} 825bf215546Sopenharmony_ci 826bf215546Sopenharmony_ci 827bf215546Sopenharmony_civoid GLAPIENTRY 828bf215546Sopenharmony_ci_mesa_TextureStorage3DEXT(GLuint texture, GLenum target, GLsizei levels, 829bf215546Sopenharmony_ci GLenum internalformat, 830bf215546Sopenharmony_ci GLsizei width, GLsizei height, GLsizei depth) 831bf215546Sopenharmony_ci{ 832bf215546Sopenharmony_ci GET_CURRENT_CONTEXT(ctx); 833bf215546Sopenharmony_ci /* 'texture' must always be initialized, even if the call to 834bf215546Sopenharmony_ci * glTextureStorage3DEXT will generate an error. 835bf215546Sopenharmony_ci */ 836bf215546Sopenharmony_ci if (!_mesa_lookup_or_create_texture(ctx, target, texture, false, true, 837bf215546Sopenharmony_ci "glTextureStorage3DEXT")) 838bf215546Sopenharmony_ci return; 839bf215546Sopenharmony_ci texturestorage_error(3, texture, levels, internalformat, width, height, depth, 840bf215546Sopenharmony_ci "glTextureStorage3DEXT"); 841bf215546Sopenharmony_ci} 842bf215546Sopenharmony_ci 843bf215546Sopenharmony_ci 844bf215546Sopenharmony_civoid 845bf215546Sopenharmony_ci_mesa_texture_storage_memory(struct gl_context *ctx, GLuint dims, 846bf215546Sopenharmony_ci struct gl_texture_object *texObj, 847bf215546Sopenharmony_ci struct gl_memory_object *memObj, 848bf215546Sopenharmony_ci GLenum target, GLsizei levels, 849bf215546Sopenharmony_ci GLenum internalformat, GLsizei width, 850bf215546Sopenharmony_ci GLsizei height, GLsizei depth, 851bf215546Sopenharmony_ci GLuint64 offset, bool dsa) 852bf215546Sopenharmony_ci{ 853bf215546Sopenharmony_ci assert(memObj); 854bf215546Sopenharmony_ci 855bf215546Sopenharmony_ci texture_storage(ctx, dims, texObj, memObj, target, levels, internalformat, 856bf215546Sopenharmony_ci width, height, depth, offset, dsa, false); 857bf215546Sopenharmony_ci} 858