Commit: d2f35d6d5001dbe190bb3e147caec1b974d373ab
Author: Antony Riakiotakis
Date:   Thu Apr 23 19:02:08 2015 +0200
Branches: master
https://developer.blender.org/rBd2f35d6d5001dbe190bb3e147caec1b974d373ab

3D textures: detect if we are pushing OpenGL too hard with the texture
size.

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

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

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

diff --git a/source/blender/gpu/intern/gpu_extensions.c 
b/source/blender/gpu/intern/gpu_extensions.c
index 0d735d1..9e361a4 100644
--- a/source/blender/gpu/intern/gpu_extensions.c
+++ b/source/blender/gpu/intern/gpu_extensions.c
@@ -561,6 +561,7 @@ GPUTexture *GPU_texture_create_3D(int w, int h, int depth, 
int channels, const f
        GLenum type, format, internalformat;
        void *pixels = NULL;
        const float vfBorderColor[4] = {0.0f, 0.0f, 0.0f, 0.0f};
+       int r_width;
 
        if (!GLEW_VERSION_1_2)
                return NULL;
@@ -603,24 +604,37 @@ GPUTexture *GPU_texture_create_3D(int w, int h, int 
depth, int channels, const f
                internalformat = GL_INTENSITY;
        }
 
+       /* 3D textures are quite heavy, test if it's possible to create them 
first */
+       glTexImage3D(GL_PROXY_TEXTURE_3D, 0, internalformat, tex->w, tex->h, 
tex->depth, 0, format, type, NULL);
+       glGetTexLevelParameteriv(GL_PROXY_TEXTURE_3D, 0, GL_TEXTURE_WIDTH, 
&r_width);
+
+       if (r_width == 0) {
+               fprintf(stderr, "OpenGL cannot handle a 3D texture of this 
size\n");
+               glBindTexture(tex->target, 0);
+               GPU_texture_free(tex);
+               return NULL;
+       }
+
 #if 0
        if (fpixels)
                pixels = GPU_texture_convert_pixels(w*h*depth, fpixels);
 #endif
 
-       glTexImage3D(tex->target, 0, internalformat, tex->w, tex->h, 
tex->depth, 0, format, type, NULL);
-
        GPU_ASSERT_NO_GL_ERRORS("3D glTexImage3D");
 
        if (fpixels) {
                if (!GPU_non_power_of_two_support() && (w != tex->w || h != 
tex->h || depth != tex->depth)) {
                        /* clear first to avoid unitialized pixels */
                        float *zero= 
MEM_callocN(sizeof(float)*tex->w*tex->h*tex->depth, "zero");
-                       glTexSubImage3D(tex->target, 0, 0, 0, 0, tex->w, 
tex->h, tex->depth, format, type, zero);
+                       glTexImage3D(tex->target, 0, internalformat, tex->w, 
tex->h, tex->depth, 0, format, type, NULL);
+                       glTexSubImage3D(tex->target, 0, 0, 0, 0, tex->w, 
tex->h, tex->depth, GL_INTENSITY, GL_FLOAT, zero);
+                       glTexSubImage3D(tex->target, 0, 0, 0, 0, w, h, depth, 
format, type, fpixels);
                        MEM_freeN(zero);
                }
+               else {
+                       glTexImage3D(tex->target, 0, internalformat, tex->w, 
tex->h, tex->depth, 0, format, type, fpixels);
+               }
 
-               glTexSubImage3D(tex->target, 0, 0, 0, 0, w, h, depth, format, 
type, fpixels);
                GPU_ASSERT_NO_GL_ERRORS("3D glTexSubImage3D");
        }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to