diff options
Diffstat (limited to 'intern/opencolorio/ocio_impl_glsl.cc')
-rw-r--r-- | intern/opencolorio/ocio_impl_glsl.cc | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/intern/opencolorio/ocio_impl_glsl.cc b/intern/opencolorio/ocio_impl_glsl.cc index 3a23c266345..677be0bf9ed 100644 --- a/intern/opencolorio/ocio_impl_glsl.cc +++ b/intern/opencolorio/ocio_impl_glsl.cc @@ -71,6 +71,10 @@ typedef struct OCIO_GLSLDrawState { GLuint curve_mapping_texture; size_t curve_mapping_cache_id; + bool predivide_used; + + bool texture_size_used; + /* Cache */ std::string lut3dcacheid; std::string shadercacheid; @@ -221,6 +225,17 @@ bool OCIOImpl::supportGLSLDraw() return GLEW_VERSION_2_0 && (GLEW_VERSION_3_0 || GLEW_ARB_texture_float); } +static bool supportGLSL13() +{ + const char *version = (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION); + int major = 1, minor = 0; + + if (version && sscanf(version, "%d.%d", &major, &minor) == 2) + return (major > 1 || (major == 1 && minor >= 30)); + + return false; +} + /** * Setup OpenGL contexts for a transform defined by processor using GLSL * All LUT allocating baking and shader compilation happens here. @@ -233,7 +248,7 @@ bool OCIOImpl::supportGLSLDraw() */ bool OCIOImpl::setupGLSLDraw(OCIO_GLSLDrawState **state_r, OCIO_ConstProcessorRcPtr *processor, OCIO_CurveMappingSettings *curve_mapping_settings, - float dither, bool predivide) + float dither, bool use_predivide) { ConstProcessorRcPtr ocio_processor = *(ConstProcessorRcPtr *) processor; bool use_curve_mapping = curve_mapping_settings != NULL; @@ -302,6 +317,7 @@ bool OCIOImpl::setupGLSLDraw(OCIO_GLSLDrawState **state_r, OCIO_ConstProcessorRc std::string shaderCacheID = ocio_processor->getGpuShaderTextCacheID(shaderDesc); if (state->program == 0 || shaderCacheID != state->shadercacheid || + use_predivide != state->predivide_used || use_curve_mapping != state->curve_mapping_used || use_dither != state->dither_used) { @@ -317,7 +333,17 @@ bool OCIOImpl::setupGLSLDraw(OCIO_GLSLDrawState **state_r, OCIO_ConstProcessorRc std::ostringstream os; - os << "#version 130\n"; + if (supportGLSL13()) { + os << "#version 130\n"; + } + else { + os << "#define USE_TEXTURE_SIZE\n"; + state->texture_size_used = use_dither; + } + + if (use_predivide) { + os << "#define USE_PREDIVIDE\n"; + } if (use_dither) { os << "#define USE_DITHER\n"; @@ -338,6 +364,7 @@ bool OCIOImpl::setupGLSLDraw(OCIO_GLSLDrawState **state_r, OCIO_ConstProcessorRc state->curve_mapping_used = use_curve_mapping; state->dither_used = use_dither; + state->predivide_used = use_predivide; } if (state->program) { @@ -355,7 +382,18 @@ bool OCIOImpl::setupGLSLDraw(OCIO_GLSLDrawState **state_r, OCIO_ConstProcessorRc glUniform1i(glGetUniformLocation(state->program, "image_texture"), 0); glUniform1i(glGetUniformLocation(state->program, "lut3d_texture"), 1); - glUniform1i(glGetUniformLocation(state->program, "predivide"), predivide); + + if (state->texture_size_used) { + /* we use textureSize() if possible for best performance, if not + * supported we query the size and pass it as uniform variables */ + GLint width, height; + + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width); + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height); + + glUniform1f(glGetUniformLocation(state->program, "image_texture_width"), (float)width); + glUniform1f(glGetUniformLocation(state->program, "image_texture_height"), (float)height); + } if (use_dither) { glUniform1f(glGetUniformLocation(state->program, "dither"), dither); |