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 /source/blender/imbuf | |
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 'source/blender/imbuf')
-rw-r--r-- | source/blender/imbuf/IMB_colormanagement.h | 16 | ||||
-rw-r--r-- | source/blender/imbuf/intern/colormanagement.c | 67 |
2 files changed, 58 insertions, 25 deletions
diff --git a/source/blender/imbuf/IMB_colormanagement.h b/source/blender/imbuf/IMB_colormanagement.h index a758cfa04f0..203d01cab67 100644 --- a/source/blender/imbuf/IMB_colormanagement.h +++ b/source/blender/imbuf/IMB_colormanagement.h @@ -152,14 +152,22 @@ void IMB_colormanagement_processor_free(struct ColormanageProcessor *cm_processo /* Configures GLSL shader for conversion from scene linear to display space */ int IMB_colormanagement_setup_glsl_draw(const struct ColorManagedViewSettings *view_settings, - const struct ColorManagedDisplaySettings *display_settings); -/* Same as above, but color management settings are guessing from a given context */ -int IMB_colormanagement_setup_glsl_draw_from_ctx(const struct bContext *C); + const struct ColorManagedDisplaySettings *display_settings, + int predivide); +/* Same as above, but display space conversion happens from a specified space */ +int IMB_colormanagement_setup_glsl_draw_from_space(const struct ColorManagedViewSettings *view_settings, + const struct ColorManagedDisplaySettings *display_settings, + struct ColorSpace *colorspace, + int predivide); +/* Same as setup_glsl_draw, but color management settings are guessing from a given context */ +int IMB_colormanagement_setup_glsl_draw_ctx(const struct bContext *C, int predivide); +/* Same as setup_glsl_draw_from_space, but color management settings are guessing from a given context */ +int IMB_colormanagement_setup_glsl_draw_from_space_ctx(const struct bContext *C, struct ColorSpace *colorspace, int predivide); /* Finish GLSL-based display space conversion */ void IMB_colormanagement_finish_glsl_draw(void); /* Configures GLSL shader for conversion from space defined by role to scene linear space */ -int IMB_colormanagement_setup_transform_from_role_glsl(int role); +int IMB_colormanagement_setup_transform_from_role_glsl(int role, int predivide); /* Finish GLSL-based color space conversion */ void IMB_colormanagement_finish_glsl_transform(void); diff --git a/source/blender/imbuf/intern/colormanagement.c b/source/blender/imbuf/intern/colormanagement.c index 3ed69550873..1e6fac4f4f0 100644 --- a/source/blender/imbuf/intern/colormanagement.c +++ b/source/blender/imbuf/intern/colormanagement.c @@ -109,6 +109,7 @@ static struct global_glsl_state { /* Settings of processor for comparison. */ char view[MAX_COLORSPACE_NAME]; char display[MAX_COLORSPACE_NAME]; + char input[MAX_COLORSPACE_NAME]; float exposure, gamma; /* Container for GLSL state needed for OCIO module. */ @@ -703,8 +704,10 @@ static ColorSpace *display_transform_get_colorspace(const ColorManagedViewSettin return NULL; } -static OCIO_ConstProcessorRcPtr *create_display_buffer_processor(const char *view_transform, const char *display, - float exposure, float gamma) +static OCIO_ConstProcessorRcPtr *create_display_buffer_processor(const char *view_transform, + const char *display, + float exposure, float gamma, + const char *from_colorspace) { OCIO_ConstConfigRcPtr *config = OCIO_getCurrentConfig(); OCIO_DisplayTransformRcPtr *dt; @@ -712,8 +715,7 @@ static OCIO_ConstProcessorRcPtr *create_display_buffer_processor(const char *vie dt = OCIO_createDisplayTransform(); - /* assuming handling buffer was already converted to scene linear space */ - OCIO_displayTransformSetInputColorSpaceName(dt, global_role_scene_linear); + OCIO_displayTransformSetInputColorSpaceName(dt, from_colorspace); OCIO_displayTransformSetView(dt, view_transform); OCIO_displayTransformSetDisplay(dt, display); @@ -2621,7 +2623,8 @@ ColormanageProcessor *IMB_colormanagement_display_processor_new(const ColorManag cm_processor->is_data_result = display_space->is_data; cm_processor->processor = create_display_buffer_processor(applied_view_settings->view_transform, display_settings->display_device, - applied_view_settings->exposure, applied_view_settings->gamma); + applied_view_settings->exposure, applied_view_settings->gamma, + global_role_scene_linear); if (applied_view_settings->flag & COLORMANAGE_VIEW_USE_CURVES) { cm_processor->curve_mapping = curvemapping_copy(applied_view_settings->curve_mapping); @@ -2718,26 +2721,30 @@ void IMB_colormanagement_processor_free(ColormanageProcessor *cm_processor) /* **** OpenGL drawing routines using GLSL for color space transform ***** */ static bool check_glsl_display_processor_changed(const ColorManagedViewSettings *view_settings, - const ColorManagedDisplaySettings *display_settings) + const ColorManagedDisplaySettings *display_settings, + const char *from_colorspace) { return !(global_glsl_state.exposure == view_settings->exposure && global_glsl_state.gamma == view_settings->gamma && STREQ(global_glsl_state.view, view_settings->view_transform) && - STREQ(global_glsl_state.display, display_settings->display_device)); + STREQ(global_glsl_state.display, display_settings->display_device) && + STREQ(global_glsl_state.input, from_colorspace)); } static void update_glsl_display_processor(const ColorManagedViewSettings *view_settings, - const ColorManagedDisplaySettings *display_settings) + const ColorManagedDisplaySettings *display_settings, + const char *from_colorspace) { /* Update state if there's no processor yet or * processor settings has been changed. */ if (global_glsl_state.processor == NULL || - check_glsl_display_processor_changed(view_settings, display_settings)) + check_glsl_display_processor_changed(view_settings, display_settings, from_colorspace)) { /* Store settings of processor for further comparison. */ strcpy(global_glsl_state.view, view_settings->view_transform); strcpy(global_glsl_state.display, display_settings->display_device); + strcpy(global_glsl_state.input, from_colorspace); global_glsl_state.exposure = view_settings->exposure; global_glsl_state.gamma = view_settings->gamma; @@ -2750,13 +2757,14 @@ static void update_glsl_display_processor(const ColorManagedViewSettings *view_s create_display_buffer_processor(global_glsl_state.view, global_glsl_state.display, global_glsl_state.exposure, - global_glsl_state.gamma); + global_glsl_state.gamma, + global_glsl_state.input); } } /** - * Configures GLSL shader for conversion from scene linear - * to display space + * Configures GLSL shader for conversion from specified to + * display color space * * Will create appropriate OCIO processor and setup GLSL shader, * so further 2D texture usage will use this conversion. @@ -2767,8 +2775,9 @@ static void update_glsl_display_processor(const ColorManagedViewSettings *view_s * This is low-level function, use glaDrawImBuf_glsl_ctx if you * only need to display given image buffer */ -int IMB_colormanagement_setup_glsl_draw(const ColorManagedViewSettings *view_settings, - const ColorManagedDisplaySettings *display_settings) +int IMB_colormanagement_setup_glsl_draw_from_space(const ColorManagedViewSettings *view_settings, + const ColorManagedDisplaySettings *display_settings, + struct ColorSpace *from_colorspace, int predivide) { ColorManagedViewSettings default_view_settings; const ColorManagedViewSettings *applied_view_settings; @@ -2790,20 +2799,36 @@ int IMB_colormanagement_setup_glsl_draw(const ColorManagedViewSettings *view_set return FALSE; /* Make sure OCIO processor is up-to-date. */ - update_glsl_display_processor(applied_view_settings, display_settings); + update_glsl_display_processor(applied_view_settings, display_settings, + from_colorspace ? from_colorspace->name : global_role_scene_linear); + + return OCIO_setupGLSLDraw(&global_glsl_state.ocio_glsl_state, global_glsl_state.processor, predivide); +} - return OCIO_setupGLSLDraw(&global_glsl_state.ocio_glsl_state, global_glsl_state.processor); +/* Configures GLSL shader for conversion from scene linear to display space */ +int IMB_colormanagement_setup_glsl_draw(const ColorManagedViewSettings *view_settings, + const ColorManagedDisplaySettings *display_settings, + int predivide) +{ + return IMB_colormanagement_setup_glsl_draw_from_space(view_settings, display_settings, + NULL, predivide); } -/* Same as above, but color management settings are guessing from a given context */ -int IMB_colormanagement_setup_glsl_draw_from_ctx(const bContext *C) +/* Same as setup_glsl_draw_from_space, but color management settings are guessing from a given context */ +int IMB_colormanagement_setup_glsl_draw_from_space_ctx(const struct bContext *C, struct ColorSpace *from_colorspace, int predivide) { ColorManagedViewSettings *view_settings; ColorManagedDisplaySettings *display_settings; display_transform_get_from_ctx(C, &view_settings, &display_settings); - return IMB_colormanagement_setup_glsl_draw(view_settings, display_settings); + return IMB_colormanagement_setup_glsl_draw_from_space(view_settings, display_settings, from_colorspace, predivide); +} + +/* Same as setup_glsl_draw, but color management settings are guessing from a given context */ +int IMB_colormanagement_setup_glsl_draw_ctx(const bContext *C, int predivide) +{ + return IMB_colormanagement_setup_glsl_draw_from_space_ctx(C, NULL, predivide); } /* Finish GLSL-based display space conversion */ @@ -2827,7 +2852,7 @@ void IMB_colormanagement_finish_glsl_draw(void) * When there's no need to apply transform on 2D textures, use * IMB_colormanagement_finish_glsl_transform(). */ -int IMB_colormanagement_setup_transform_from_role_glsl(int role) +int IMB_colormanagement_setup_transform_from_role_glsl(int role, int predivide) { OCIO_ConstProcessorRcPtr *processor; ColorSpace *colorspace; @@ -2836,7 +2861,7 @@ int IMB_colormanagement_setup_transform_from_role_glsl(int role) processor = colorspace_to_scene_linear_processor(colorspace); - return OCIO_setupGLSLDraw(&global_glsl_state.transform_ocio_glsl_state, processor); + return OCIO_setupGLSLDraw(&global_glsl_state.transform_ocio_glsl_state, processor, predivide); } /* Finish GLSL-based color space conversion */ |