diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-04-03 19:59:54 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-04-03 19:59:54 +0400 |
commit | 9c49e71216c11d3369eb40b8b743c555b032e397 (patch) | |
tree | fa1241b1d889bf2c3ba9127b00d62fec9bd7763d /intern/opencolorio/ocio_impl_glsl.cc | |
parent | 03b07a719f186bfed15f9465555ec072a262deaa (diff) |
Bunch of fixes for GLSL display transform
- GLSL shader wasn't aware of alpha predivide option,
always assuming alpha is straight. Gave wrong results
when displaying transparent float buffers.
- GLSL display wasn't aware of float buffers with number
of channels different from 4, crashing when trying to
display image with different number of channels.
This required a bit larger changes, namely now it's
possible to pass format (GL_RGB, GL_RGBAm GL_LUMINANCE)
to glaDrawPixelsTex, This also implied adding format to
glaDrawPixelsAuto and modifying all places where this
functions are called.
Now GLSL will handle both 3 and 4 channels buffers,
single channel images are handled by CPU.
- Replaced hack for render result displaying with a bit
different hack.
Namely CPU conversion will happen only during render,
once render is done GLSL would be used for displaying
render result on a screen.
This is so because of the way renderer updates parts
of the image -- it happens without respect to active
render layer in image user. This is harmless because
only display buffer is modifying, but this is tricky
because we don't have original buffer opened during
rendering.
One more related fix here was about when rendering
multiple layers, wrong image would be displaying when
rendering is done. Added a signal to invalidate
display buffer once rendering is done (only happens
when using multiple layers). This solves issue with
wrong buffer stuck on the display when using regular
CPU display space transform and if GLSL is available
it'll make image displayed with a GLSL shader.
- As an additional change, byte buffers now also uses
GLSL display transform.
So now only dutehr and RGB curves are stoppers for
using GLSL for all kind of display transforms.
Diffstat (limited to 'intern/opencolorio/ocio_impl_glsl.cc')
-rw-r--r-- | intern/opencolorio/ocio_impl_glsl.cc | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/intern/opencolorio/ocio_impl_glsl.cc b/intern/opencolorio/ocio_impl_glsl.cc index 59845abca33..9343a13e888 100644 --- a/intern/opencolorio/ocio_impl_glsl.cc +++ b/intern/opencolorio/ocio_impl_glsl.cc @@ -77,15 +77,33 @@ typedef struct OCIO_GLSLDrawState { GLint last_texture, last_texture_unit; } OCIO_GLSLDrawState; -static const char * g_fragShaderText = "" +/* Hardcoded to do alpha predivide before color space conversion */ +static const char *g_fragShaderText = "" "\n" "uniform sampler2D tex1;\n" "uniform sampler3D tex2;\n" +"uniform bool predivide;\n" "\n" "void main()\n" "{\n" " vec4 col = texture2D(tex1, gl_TexCoord[0].st);\n" -" gl_FragColor = OCIODisplay(col, tex2);\n" +" if (predivide == false || col[3] == 1.0f || col[3] == 0.0f) {\n" +" gl_FragColor = OCIODisplay(col, tex2);\n" +" } else {\n" +" float alpha = col[3];\n" +" float inv_alpha = 1.0f / alpha;\n" +"\n" +" col[0] *= inv_alpha;\n" +" col[1] *= inv_alpha;\n" +" col[2] *= inv_alpha;\n" +"\n" +" gl_FragColor = OCIODisplay(col, tex2);\n" +"\n" +" col[0] *= alpha;\n" +" col[1] *= alpha;\n" +" col[2] *= alpha;\n" +" }\n" +"\n" "}\n"; static GLuint compileShaderText(GLenum shaderType, const char *text) @@ -187,7 +205,7 @@ static void ensureLUT3DAllocated(OCIO_GLSLDrawState *state) * When all drawing is finished, finishGLSLDraw shall be called to * restore OpenGL context to it's pre-GLSL draw state. */ -bool OCIOImpl::setupGLSLDraw(OCIO_GLSLDrawState **state_r, OCIO_ConstProcessorRcPtr *processor) +bool OCIOImpl::setupGLSLDraw(OCIO_GLSLDrawState **state_r, OCIO_ConstProcessorRcPtr *processor, bool predivide) { ConstProcessorRcPtr ocio_processor = *(ConstProcessorRcPtr *) processor; @@ -252,6 +270,7 @@ bool OCIOImpl::setupGLSLDraw(OCIO_GLSLDrawState **state_r, OCIO_ConstProcessorRc glUseProgram(state->program); glUniform1i(glGetUniformLocation(state->program, "tex1"), 0); glUniform1i(glGetUniformLocation(state->program, "tex2"), 1); + glUniform1i(glGetUniformLocation(state->program, "predivide"), predivide); return true; } |