diff options
Diffstat (limited to 'source/blender/gpu/intern/gpu_extensions.c')
-rw-r--r-- | source/blender/gpu/intern/gpu_extensions.c | 72 |
1 files changed, 43 insertions, 29 deletions
diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c index 78ac17d450d..6cd16df3c88 100644 --- a/source/blender/gpu/intern/gpu_extensions.c +++ b/source/blender/gpu/intern/gpu_extensions.c @@ -225,39 +225,47 @@ int GPU_print_error(const char *str) return 0; } -static void GPU_print_framebuffer_error(GLenum status) +static void GPU_print_framebuffer_error(GLenum status, char err_out[256]) { - fprintf(stderr, "GPUFrameBuffer: framebuffer incomplete error %d\n", - (int)status); + const char *err= "unknown"; switch(status) { case GL_FRAMEBUFFER_COMPLETE_EXT: break; case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT: - fprintf(stderr, "Incomplete attachment.\n"); + err= "Incomplete attachment"; break; case GL_FRAMEBUFFER_UNSUPPORTED_EXT: - fprintf(stderr, "Unsupported framebuffer format.\n"); + err= "Unsupported framebuffer format"; break; case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT: - fprintf(stderr, "Missing attachment.\n"); + err= "Missing attachment"; break; case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT: - fprintf(stderr, "Attached images must have same dimensions.\n"); + err= "Attached images must have same dimensions"; break; case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT: - fprintf(stderr, "Attached images must have same format.\n"); + err= "Attached images must have same format"; break; case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT: - fprintf(stderr, "Missing draw buffer.\n"); + err= "Missing draw buffer"; break; case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT: - fprintf(stderr, "Missing read buffer.\n"); - break; - default: - fprintf(stderr, "Unknown.\n"); + err= "Missing read buffer"; break; } + + if(err_out) { + snprintf(err_out, 256, "GPUFrameBuffer: framebuffer incomplete error %d '%s'", + (int)status, + err); + } + else { + fprintf(stderr, "GPUFrameBuffer: framebuffer incomplete error %d '%s'\n", + (int)status, + err); + } + } /* GPUTexture */ @@ -318,7 +326,7 @@ static void GPU_glTexSubImageEmpty(GLenum target, GLenum format, int x, int y, i MEM_freeN(pixels); } -static GPUTexture *GPU_texture_create_nD(int w, int h, int n, float *fpixels, int depth) +static GPUTexture *GPU_texture_create_nD(int w, int h, int n, float *fpixels, int depth, char err_out[256]) { GPUTexture *tex; GLenum type, format, internalformat; @@ -338,8 +346,14 @@ static GPUTexture *GPU_texture_create_nD(int w, int h, int n, float *fpixels, in glGenTextures(1, &tex->bindcode); if (!tex->bindcode) { - fprintf(stderr, "GPUTexture: texture create failed: %d\n", - (int)glGetError()); + if(err_out) { + snprintf(err_out, 256, "GPUTexture: texture create failed: %d", + (int)glGetError()); + } + else { + fprintf(stderr, "GPUTexture: texture create failed: %d\n", + (int)glGetError()); + } GPU_texture_free(tex); return NULL; } @@ -555,9 +569,9 @@ GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, double time, return tex; } -GPUTexture *GPU_texture_create_1D(int w, float *fpixels) +GPUTexture *GPU_texture_create_1D(int w, float *fpixels, char err_out[256]) { - GPUTexture *tex = GPU_texture_create_nD(w, 1, 1, fpixels, 0); + GPUTexture *tex = GPU_texture_create_nD(w, 1, 1, fpixels, 0, err_out); if (tex) GPU_texture_unbind(tex); @@ -565,9 +579,9 @@ GPUTexture *GPU_texture_create_1D(int w, float *fpixels) return tex; } -GPUTexture *GPU_texture_create_2D(int w, int h, float *fpixels) +GPUTexture *GPU_texture_create_2D(int w, int h, float *fpixels, char err_out[256]) { - GPUTexture *tex = GPU_texture_create_nD(w, h, 2, fpixels, 0); + GPUTexture *tex = GPU_texture_create_nD(w, h, 2, fpixels, 0, err_out); if (tex) GPU_texture_unbind(tex); @@ -575,9 +589,9 @@ GPUTexture *GPU_texture_create_2D(int w, int h, float *fpixels) return tex; } -GPUTexture *GPU_texture_create_depth(int w, int h) +GPUTexture *GPU_texture_create_depth(int w, int h, char err_out[256]) { - GPUTexture *tex = GPU_texture_create_nD(w, h, 2, NULL, 1); + GPUTexture *tex = GPU_texture_create_nD(w, h, 2, NULL, 1, err_out); if (tex) GPU_texture_unbind(tex); @@ -705,7 +719,7 @@ GPUFrameBuffer *GPU_framebuffer_create(void) return fb; } -int GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex) +int GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, char err_out[256]) { GLenum status; GLenum attachment; @@ -734,7 +748,7 @@ int GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex) if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { GPU_framebuffer_restore(); - GPU_print_framebuffer_error(status); + GPU_print_framebuffer_error(status, err_out); return 0; } @@ -846,7 +860,7 @@ struct GPUOffScreen { GPUTexture *depth; }; -GPUOffScreen *GPU_offscreen_create(int *width, int *height) +GPUOffScreen *GPU_offscreen_create(int *width, int *height, char err_out[256]) { GPUOffScreen *ofs; @@ -858,7 +872,7 @@ GPUOffScreen *GPU_offscreen_create(int *width, int *height) return NULL; } - ofs->depth = GPU_texture_create_depth(*width, *height); + ofs->depth = GPU_texture_create_depth(*width, *height, err_out); if(!ofs->depth) { GPU_offscreen_free(ofs); return NULL; @@ -870,18 +884,18 @@ GPUOffScreen *GPU_offscreen_create(int *width, int *height) printf("Offscreen size differs from given size!\n"); } - if(!GPU_framebuffer_texture_attach(ofs->fb, ofs->depth)) { + if(!GPU_framebuffer_texture_attach(ofs->fb, ofs->depth, err_out)) { GPU_offscreen_free(ofs); return NULL; } - ofs->color = GPU_texture_create_2D(*width, *height, NULL); + ofs->color = GPU_texture_create_2D(*width, *height, NULL, err_out); if(!ofs->color) { GPU_offscreen_free(ofs); return NULL; } - if(!GPU_framebuffer_texture_attach(ofs->fb, ofs->color)) { + if(!GPU_framebuffer_texture_attach(ofs->fb, ofs->color, err_out)) { GPU_offscreen_free(ofs); return NULL; } |