diff options
Diffstat (limited to 'intern/opencolorio')
-rw-r--r-- | intern/opencolorio/CMakeLists.txt | 2 | ||||
-rw-r--r-- | intern/opencolorio/gpu_shader_display_transform.glsl | 10 | ||||
-rw-r--r-- | intern/opencolorio/gpu_shader_display_transform_vertex.glsl | 12 | ||||
-rw-r--r-- | intern/opencolorio/ocio_impl_glsl.cc | 98 |
4 files changed, 92 insertions, 30 deletions
diff --git a/intern/opencolorio/CMakeLists.txt b/intern/opencolorio/CMakeLists.txt index 75e228933aa..2611477252a 100644 --- a/intern/opencolorio/CMakeLists.txt +++ b/intern/opencolorio/CMakeLists.txt @@ -27,6 +27,7 @@ set(INC . ../glew-mx ../guardedalloc + ../gawain ../../source/blender/blenlib ) @@ -66,6 +67,7 @@ if(WITH_OPENCOLORIO) endif() data_to_c_simple(gpu_shader_display_transform.glsl SRC) + data_to_c_simple(gpu_shader_display_transform_vertex.glsl SRC) endif() diff --git a/intern/opencolorio/gpu_shader_display_transform.glsl b/intern/opencolorio/gpu_shader_display_transform.glsl index 853bf575582..372d41dfecb 100644 --- a/intern/opencolorio/gpu_shader_display_transform.glsl +++ b/intern/opencolorio/gpu_shader_display_transform.glsl @@ -10,6 +10,10 @@ uniform float image_texture_width; uniform float image_texture_height; #endif +in vec2 texCoord_interp; +out vec4 fragColor; +#define texture2D texture + #ifdef USE_CURVE_MAPPING /* Curve mapping parameters * @@ -143,7 +147,7 @@ vec4 apply_dither(vec2 st, vec4 col) void main() { - vec4 col = texture2D(image_texture, gl_TexCoord[0].st); + vec4 col = texture2D(image_texture, texCoord_interp.st); #ifdef USE_CURVE_MAPPING col = curvemapping_evaluate_premulRGBF(col); #endif @@ -165,8 +169,8 @@ void main() vec4 result = OCIODisplay(col, lut3d_texture); #ifdef USE_DITHER - result = apply_dither(gl_TexCoord[0].st, result); + result = apply_dither(texCoord_interp.st, result); #endif - gl_FragColor = result; + fragColor = result; } diff --git a/intern/opencolorio/gpu_shader_display_transform_vertex.glsl b/intern/opencolorio/gpu_shader_display_transform_vertex.glsl new file mode 100644 index 00000000000..054f7f3ec91 --- /dev/null +++ b/intern/opencolorio/gpu_shader_display_transform_vertex.glsl @@ -0,0 +1,12 @@ + +uniform mat4 ModelViewProjectionMatrix; + +in vec2 texCoord; +in vec2 pos; +out vec2 texCoord_interp; + +void main() +{ + gl_Position = ModelViewProjectionMatrix * vec4(pos.xy, 0.0f, 1.0f); + texCoord_interp = texCoord; +} diff --git a/intern/opencolorio/ocio_impl_glsl.cc b/intern/opencolorio/ocio_impl_glsl.cc index bf91ea143da..89df3080749 100644 --- a/intern/opencolorio/ocio_impl_glsl.cc +++ b/intern/opencolorio/ocio_impl_glsl.cc @@ -48,6 +48,9 @@ # pragma warning(pop) #endif +extern "C" { +#include "gawain/immediate.h" +} using namespace OCIO_NAMESPACE; @@ -58,6 +61,7 @@ using namespace OCIO_NAMESPACE; static const int LUT3D_EDGE_SIZE = 64; extern "C" char datatoc_gpu_shader_display_transform_glsl[]; +extern "C" char datatoc_gpu_shader_display_transform_vertex_glsl[]; /* **** OpenGL drawing routines using GLSL for color space transform ***** */ @@ -89,7 +93,9 @@ typedef struct OCIO_GLSLDrawState { /* GLSL stuff */ GLuint ocio_shader; + GLuint vert_shader; GLuint program; + ShaderInterface *shader_interface; /* Previous OpenGL state. */ GLint last_texture, last_texture_unit; @@ -116,14 +122,15 @@ static GLuint compileShaderText(GLenum shaderType, const char *text) return shader; } -static GLuint linkShaders(GLuint ocio_shader) +static GLuint linkShaders(GLuint ocio_shader, GLuint vert_shader) { - if (!ocio_shader) + if (!ocio_shader || !vert_shader) return 0; GLuint program = glCreateProgram(); glAttachShader(program, ocio_shader); + glAttachShader(program, vert_shader); glLinkProgram(program); @@ -339,6 +346,25 @@ bool OCIOImpl::setupGLSLDraw(OCIO_GLSLDrawState **state_r, OCIO_ConstProcessorRc glDeleteShader(state->ocio_shader); } + if (state->vert_shader) { + glDeleteShader(state->vert_shader); + } + + /* Vertex shader */ + std::ostringstream osv; + + if (supportGLSL13()) { + osv << "#version 130\n"; + } + else { + osv << "#version 120\n"; + } + + osv << datatoc_gpu_shader_display_transform_vertex_glsl; + + state->vert_shader = compileShaderText(GL_VERTEX_SHADER, osv.str().c_str()); + + /* Fragment shader */ std::ostringstream os; if (supportGLSL13()) { @@ -366,8 +392,12 @@ bool OCIOImpl::setupGLSLDraw(OCIO_GLSLDrawState **state_r, OCIO_ConstProcessorRc state->ocio_shader = compileShaderText(GL_FRAGMENT_SHADER, os.str().c_str()); - if (state->ocio_shader) { - state->program = linkShaders(state->ocio_shader); + if (state->ocio_shader && state->vert_shader) { + state->program = linkShaders(state->ocio_shader, state->vert_shader); + } + + if (state->program) { + state->shader_interface = ShaderInterface_create(state->program); } state->curve_mapping_used = use_curve_mapping; @@ -386,10 +416,21 @@ bool OCIOImpl::setupGLSLDraw(OCIO_GLSLDrawState **state_r, OCIO_ConstProcessorRc glActiveTexture(GL_TEXTURE0); - glUseProgram(state->program); - - glUniform1i(glGetUniformLocation(state->program, "image_texture"), 0); - glUniform1i(glGetUniformLocation(state->program, "lut3d_texture"), 1); + /* IMM needs vertex format even if we don't draw with it. + * + * NOTE: The only reason why it's here is because of Cycles viewport. + * All other areas are managing their own vertex formats. + * Doing it here is probably harmless, but kind of stupid. + * + * TODO(sergey): Look into some nicer solution. + */ + VertexFormat *format = immVertexFormat(); + VertexFormat_add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT); + VertexFormat_add_attrib(format, "texCoord", COMP_F32, 2, KEEP_FLOAT); + immBindProgram(state->program, state->shader_interface); + + immUniform1i("image_texture", 0); + immUniform1i("lut3d_texture", 1); if (state->texture_size_used) { /* we use textureSize() if possible for best performance, if not @@ -399,30 +440,30 @@ bool OCIOImpl::setupGLSLDraw(OCIO_GLSLDrawState **state_r, OCIO_ConstProcessorRc 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); + immUniform1f("image_texture_width", (float)width); + immUniform1f("image_texture_height", (float)height); } if (use_dither) { - glUniform1f(glGetUniformLocation(state->program, "dither"), dither); + immUniform1f("dither", dither); } if (use_curve_mapping) { - glUniform1i(glGetUniformLocation(state->program, "curve_mapping_texture"), 2); - glUniform1i(glGetUniformLocation(state->program, "curve_mapping_lut_size"), curve_mapping_settings->lut_size); - glUniform4iv(glGetUniformLocation(state->program, "use_curve_mapping_extend_extrapolate"), 1, curve_mapping_settings->use_extend_extrapolate); - glUniform4fv(glGetUniformLocation(state->program, "curve_mapping_mintable"), 1, curve_mapping_settings->mintable); - glUniform4fv(glGetUniformLocation(state->program, "curve_mapping_range"), 1, curve_mapping_settings->range); - glUniform4fv(glGetUniformLocation(state->program, "curve_mapping_ext_in_x"), 1, curve_mapping_settings->ext_in_x); - glUniform4fv(glGetUniformLocation(state->program, "curve_mapping_ext_in_y"), 1, curve_mapping_settings->ext_in_y); - glUniform4fv(glGetUniformLocation(state->program, "curve_mapping_ext_out_x"), 1, curve_mapping_settings->ext_out_x); - glUniform4fv(glGetUniformLocation(state->program, "curve_mapping_ext_out_y"), 1, curve_mapping_settings->ext_out_y); - glUniform4fv(glGetUniformLocation(state->program, "curve_mapping_first_x"), 1, curve_mapping_settings->first_x); - glUniform4fv(glGetUniformLocation(state->program, "curve_mapping_first_y"), 1, curve_mapping_settings->first_y); - glUniform4fv(glGetUniformLocation(state->program, "curve_mapping_last_x"), 1, curve_mapping_settings->last_x); - glUniform4fv(glGetUniformLocation(state->program, "curve_mapping_last_y"), 1, curve_mapping_settings->last_y); - glUniform3fv(glGetUniformLocation(state->program, "curve_mapping_black"), 1, curve_mapping_settings->black); - glUniform3fv(glGetUniformLocation(state->program, "curve_mapping_bwmul"), 1, curve_mapping_settings->bwmul); + immUniform1i("curve_mapping_texture", 2); + immUniform1i("curve_mapping_lut_size", curve_mapping_settings->lut_size); + immUniform4iv("use_curve_mapping_extend_extrapolate", curve_mapping_settings->use_extend_extrapolate); + immUniform4fv("curve_mapping_mintable", curve_mapping_settings->mintable); + immUniform4fv("curve_mapping_range", curve_mapping_settings->range); + immUniform4fv("curve_mapping_ext_in_x", curve_mapping_settings->ext_in_x); + immUniform4fv("curve_mapping_ext_in_y", curve_mapping_settings->ext_in_y); + immUniform4fv("curve_mapping_ext_out_x", curve_mapping_settings->ext_out_x); + immUniform4fv("curve_mapping_ext_out_y", curve_mapping_settings->ext_out_y); + immUniform4fv("curve_mapping_first_x", curve_mapping_settings->first_x); + immUniform4fv("curve_mapping_first_y", curve_mapping_settings->first_y); + immUniform4fv("curve_mapping_last_x", curve_mapping_settings->last_x); + immUniform4fv("curve_mapping_last_y", curve_mapping_settings->last_y); + immUniform3fv("curve_mapping_black", curve_mapping_settings->black); + immUniform3fv("curve_mapping_bwmul", curve_mapping_settings->bwmul); } return true; @@ -439,7 +480,7 @@ void OCIOImpl::finishGLSLDraw(OCIO_GLSLDrawState *state) { glActiveTexture(state->last_texture_unit); glBindTexture(GL_TEXTURE_2D, state->last_texture); - glUseProgram(0); + immUnbindProgram(); } void OCIOImpl::freeGLState(struct OCIO_GLSLDrawState *state) @@ -455,6 +496,9 @@ void OCIOImpl::freeGLState(struct OCIO_GLSLDrawState *state) if (state->program) glDeleteProgram(state->program); + if (state->shader_interface) + ShaderInterface_discard(state->shader_interface); + if (state->ocio_shader) glDeleteShader(state->ocio_shader); |