From a53a106065d7d71e2bc9d65668b0e811e8751713 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 5 Apr 2013 11:01:35 +0000 Subject: [PATCH] Fix #34872: Every images are displayed as black in UV/image editor Issue was caused by some mesa drivers does not support GL_RGBA16F. Now added check around glTexImage2D to verify whether requested internal format is actually supported. If not blender will fall back to non-GLSL image display. --- intern/opencolorio/ocio_impl_glsl.cc | 23 ++++++++++++++++++++--- source/blender/editors/screen/glutil.c | 7 +++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/intern/opencolorio/ocio_impl_glsl.cc b/intern/opencolorio/ocio_impl_glsl.cc index 9343a13e888..62df0b58ed6 100644 --- a/intern/opencolorio/ocio_impl_glsl.cc +++ b/intern/opencolorio/ocio_impl_glsl.cc @@ -60,6 +60,7 @@ typedef struct OCIO_GLSLDrawState { bool lut3d_texture_allocated; /* boolean flag indicating whether * lut texture is allocated */ + bool lut3d_texture_valid; GLuint lut3d_texture; /* OGL texture ID for 3D LUT */ @@ -170,12 +171,12 @@ static OCIO_GLSLDrawState *allocateOpenGLState(void) } /* Ensure LUT texture and array are allocated */ -static void ensureLUT3DAllocated(OCIO_GLSLDrawState *state) +static bool ensureLUT3DAllocated(OCIO_GLSLDrawState *state) { int num_3d_entries = 3 * LUT3D_EDGE_SIZE * LUT3D_EDGE_SIZE * LUT3D_EDGE_SIZE; if (state->lut3d_texture_allocated) - return; + return state->lut3d_texture_valid; glGenTextures(1, &state->lut3d_texture); @@ -188,11 +189,22 @@ static void ensureLUT3DAllocated(OCIO_GLSLDrawState *state) glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); + + /* clean glError buffer */ + while (glGetError() != GL_NO_ERROR) {} + glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB16F_ARB, LUT3D_EDGE_SIZE, LUT3D_EDGE_SIZE, LUT3D_EDGE_SIZE, 0, GL_RGB,GL_FLOAT, &state->lut3d); state->lut3d_texture_allocated = true; + + /* GL_RGB16F_ARB could be not supported at some drivers + * in this case we could not use GLSL display + */ + state->lut3d_texture_valid = glGetError() == GL_NO_ERROR; + + return state->lut3d_texture_valid; } /** @@ -218,7 +230,12 @@ bool OCIOImpl::setupGLSLDraw(OCIO_GLSLDrawState **state_r, OCIO_ConstProcessorRc glGetIntegerv(GL_TEXTURE_2D, &state->last_texture); glGetIntegerv(GL_ACTIVE_TEXTURE, &state->last_texture_unit); - ensureLUT3DAllocated(state); + if (!ensureLUT3DAllocated(state)) { + glActiveTexture(state->last_texture_unit); + glBindTexture(GL_TEXTURE_2D, state->last_texture); + + return false; + } /* Step 1: Create a GPU Shader Description */ GpuShaderDesc shaderDesc; diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c index ac8f44a3ab1..b6ee9254396 100644 --- a/source/blender/editors/screen/glutil.c +++ b/source/blender/editors/screen/glutil.c @@ -540,6 +540,13 @@ void glaDrawPixelsTexScaled(float x, float y, int img_w, int img_h, int format, if (type == GL_FLOAT) { /* need to set internal format to higher range float */ + + /* NOTE: this could fail on some drivers, like mesa, + * but currently this code is only used by color + * management stuff which already checks on whether + * it's possible to use GL_RGBA16F_ARB + */ + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, tex_w, tex_h, 0, format, GL_FLOAT, NULL); } else {