Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2013-03-29 20:02:27 +0400
committerSergey Sharybin <sergey.vfx@gmail.com>2013-03-29 20:02:27 +0400
commit2dff7c01ada2a645d39c2acdc83a10e4a295b35b (patch)
treeb68b29a7488b500b8beca2961685badfaf83952f /source/blender/imbuf/intern/colormanagement.c
parent44a43afd0e858a8a3d563ff0a1a7b6b8043bd8f3 (diff)
Implement GPU-side display transform for clip editor
Implemented using GLSL API from OpenColorIO library and some general functions were added to it's c-api: - OCIO_setupGLSLDraw prepares OpenGL context for GPU-based transformation for a giver processor. This function compiles and links shader, sets up it's argument. After this transformation would be applied on an image displaying as a 2D texture. So, glaDrawPixelsTex called after OCIO_setupGLSLDraw will do a proper color space transform. - OCIO_finishGLSLDraw restores OpenGL context after all color-managed display is over. - OCIO_freeOGLState frees allocated state structure used for cacheing some GLSL-related stuff. There're some utility functions in IMB_colormanagent which are basically proxies to lower level OCIO functions but which could be used from any place in blender. Chacheing of movie clip frame on GPU is also removed now, and either glaDrawPixelsTex or glaDrawPixelsAuto are used for display now. This is so no code duplication happens now and no large textures are lurking around in GPU memory. Known issues: - Texture buffer and GLSL are no longer checking for video card capabilities, possibly could lead to some artifacts on crappy drivers/cards. - Only float buffers are displaying using GLSL, byte buffers will still use fallback display method. This is to be addressed later. - If RGB curves are used as a part of display transform, GLSL display will also be disabled. This is also thing to be solved later. Additional changes: - glaDrawPixelsTexScaled will now use RGBA16F as an internal format of storing textures when it's used to draw float buffer. This is needed so LUT are applied without precision loss.
Diffstat (limited to 'source/blender/imbuf/intern/colormanagement.c')
-rw-r--r--source/blender/imbuf/intern/colormanagement.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/source/blender/imbuf/intern/colormanagement.c b/source/blender/imbuf/intern/colormanagement.c
index 65a3db839a9..6c33f6e3e33 100644
--- a/source/blender/imbuf/intern/colormanagement.c
+++ b/source/blender/imbuf/intern/colormanagement.c
@@ -102,6 +102,19 @@ typedef struct ColormanageProcessor {
int is_data_result;
} ColormanageProcessor;
+static struct global_glsl_state {
+ /* Actual processor used for GLSL baked LUTs. */
+ OCIO_ConstProcessorRcPtr *processor;
+
+ /* Settings of processor for comparison. */
+ char view[MAX_COLORSPACE_NAME];
+ char display[MAX_COLORSPACE_NAME];
+ float exposure, gamma;
+
+ /* Container for GLSL state needed for OCIO module. */
+ struct OCIO_GLSLDrawState *ocio_glsl_state;
+} global_glsl_state;
+
/*********************** Color managed cache *************************/
/* Cache Implementation Notes
@@ -607,6 +620,12 @@ void colormanagement_init(void)
void colormanagement_exit(void)
{
+ if (global_glsl_state.processor)
+ OCIO_processorRelease(global_glsl_state.processor);
+
+ if (global_glsl_state.ocio_glsl_state)
+ OCIO_freeOGLState(global_glsl_state.ocio_glsl_state);
+
colormanage_free_config();
}
@@ -2691,3 +2710,72 @@ void IMB_colormanagement_processor_free(ColormanageProcessor *cm_processor)
MEM_freeN(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)
+{
+ 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));
+}
+
+static void update_glsl_display_processor(const ColorManagedViewSettings *view_settings,
+ const ColorManagedDisplaySettings *display_settings)
+{
+ /* 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))
+ {
+ /* 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);
+ global_glsl_state.exposure = view_settings->exposure;
+ global_glsl_state.gamma = view_settings->gamma;
+
+ /* Free old processor, if any. */
+ if (global_glsl_state.processor)
+ OCIO_processorRelease(global_glsl_state.processor);
+
+ /* We're using display OCIO processor, no RGB curves yet. */
+ global_glsl_state.processor =
+ create_display_buffer_processor(global_glsl_state.view,
+ global_glsl_state.display,
+ global_glsl_state.exposure,
+ global_glsl_state.gamma);
+ }
+}
+
+int IMB_coloemanagement_setup_glsl_draw(const ColorManagedViewSettings *view_settings,
+ const ColorManagedDisplaySettings *display_settings)
+{
+ /* RGB curves mapping is not supported on GPU yet. */
+ if (view_settings->flag & COLORMANAGE_VIEW_USE_CURVES)
+ return FALSE;
+
+ /* Make sure OCIO processor is up-to-date. */
+ update_glsl_display_processor(view_settings, display_settings);
+
+ OCIO_setupGLSLDraw(&global_glsl_state.ocio_glsl_state, global_glsl_state.processor);
+
+ return TRUE;
+}
+
+int IMB_coloemanagement_setup_glsl_draw_from_ctx(const bContext *C)
+{
+ ColorManagedViewSettings *view_settings;
+ ColorManagedDisplaySettings *display_settings;
+
+ display_transform_get_from_ctx(C, &view_settings, &display_settings);
+
+ return IMB_coloemanagement_setup_glsl_draw(view_settings, display_settings);
+}
+
+void IMB_coloemanagement_finish_glsl_draw(void)
+{
+ OCIO_finishGLSLDraw(global_glsl_state.ocio_glsl_state);
+}