diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2020-08-04 19:44:42 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2020-08-05 03:26:44 +0300 |
commit | d1b3da697d814bcb35a718d2d7c660bd2120cb4b (patch) | |
tree | 06afb414b2600a2f3d7eb7259974361b836a1250 /source/blender/gpu/intern | |
parent | de947c5c507e747b715877f9193efe146752ca87 (diff) |
GPUTexture: Check PROXY textures for cubemap types
It can happen than some textures are not supported on some implementation
even if they fix the `GPU_max_texture_size` and `GPU_max_texture_layers`.
Diffstat (limited to 'source/blender/gpu/intern')
-rw-r--r-- | source/blender/gpu/intern/gpu_texture.c | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/source/blender/gpu/intern/gpu_texture.c b/source/blender/gpu/intern/gpu_texture.c index a332cddddb0..112fcb8f801 100644 --- a/source/blender/gpu/intern/gpu_texture.c +++ b/source/blender/gpu/intern/gpu_texture.c @@ -733,12 +733,16 @@ static bool gpu_texture_check_capacity( break; case GL_PROXY_TEXTURE_1D_ARRAY: case GL_PROXY_TEXTURE_2D: + case GL_PROXY_TEXTURE_CUBE_MAP: glTexImage2D(proxy, 0, internalformat, tex->w, tex->h, 0, data_format, data_type, NULL); break; case GL_PROXY_TEXTURE_2D_ARRAY: case GL_PROXY_TEXTURE_3D: glTexImage3D( proxy, 0, internalformat, tex->w, tex->h, tex->d, 0, data_format, data_type, NULL); + case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY_ARB: + glTexImage3D( + proxy, 0, internalformat, tex->w, tex->h, tex->d * 6, 0, data_format, data_type, NULL); break; } int width = 0; @@ -764,8 +768,11 @@ static bool gpu_texture_try_alloc(GPUTexture *tex, ret = gpu_texture_check_capacity(tex, proxy, internalformat, data_format, data_type); if (!ret && try_rescale) { - BLI_assert( - !ELEM(proxy, GL_PROXY_TEXTURE_1D_ARRAY, GL_PROXY_TEXTURE_2D_ARRAY)); // not implemented + BLI_assert(!ELEM(proxy, + GL_PROXY_TEXTURE_1D_ARRAY, + GL_PROXY_TEXTURE_2D_ARRAY, + GL_PROXY_TEXTURE_CUBE_MAP, + GL_PROXY_TEXTURE_CUBE_MAP_ARRAY_ARB)); // not implemented const int w = tex->w, h = tex->h, d = tex->d; @@ -1016,10 +1023,14 @@ GPUTexture *GPU_texture_cube_create(int w, tex->format_flag = GPU_FORMAT_CUBE; tex->number = -1; + GLenum proxy; + if (d == 0) { + proxy = GL_PROXY_TEXTURE_CUBE_MAP; tex->target_base = tex->target = GL_TEXTURE_CUBE_MAP; } else { + proxy = GL_PROXY_TEXTURE_CUBE_MAP_ARRAY_ARB; tex->target_base = tex->target = GL_TEXTURE_CUBE_MAP_ARRAY_ARB; tex->format_flag |= GPU_FORMAT_ARRAY; @@ -1055,7 +1066,10 @@ GPUTexture *GPU_texture_cube_create(int w, return NULL; } - if (G.debug & G_DEBUG_GPU) { + bool valid = gpu_texture_try_alloc( + tex, proxy, internalformat, data_format, data_type, tex->components, false, NULL, NULL); + + if (G.debug & G_DEBUG_GPU || !valid) { printf( "GPUTexture: create : %s,\t w : %5d, h : %5d, d : %5d, comp : %4d, size : %.2f " "MiB,\t %s\n", @@ -1068,6 +1082,22 @@ GPUTexture *GPU_texture_cube_create(int w, gl_enum_to_str(internalformat)); } + if (!valid) { + if (err_out) { + BLI_strncpy(err_out, "GPUTexture: texture alloc failed\n", 256); + } + else { + fprintf(stderr, + "GPUTexture: texture alloc failed. Likely not enough Video Memory or the requested " + "size is not supported by the implementation.\n"); + fprintf(stderr, + "Current texture memory usage : %.2f MiB.\n", + gpu_texture_memory_footprint_compute(tex) / 1048576.0f); + } + GPU_texture_free(tex); + return NULL; + } + gpu_texture_memory_footprint_add(tex); glBindTexture(tex->target, tex->bindcode); |