[Bf-blender-cvs] [d1b3da697d8] blender-v2.90-release: GPUTexture: Check PROXY textures for cubemap types

Clément Foucault noreply at git.blender.org
Wed Aug 5 02:34:57 CEST 2020


Commit: d1b3da697d814bcb35a718d2d7c660bd2120cb4b
Author: Clément Foucault
Date:   Tue Aug 4 18:44:42 2020 +0200
Branches: blender-v2.90-release
https://developer.blender.org/rBd1b3da697d814bcb35a718d2d7c660bd2120cb4b

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`.

===================================================================

M	source/blender/gpu/intern/gpu_texture.c

===================================================================

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);



More information about the Bf-blender-cvs mailing list