diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-05-12 23:01:23 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-05-12 23:01:23 +0400 |
commit | df746390020f4484c76d95e094f2533a84bf436c (patch) | |
tree | d40cdb0daf27e9d07621651c7accfa0fc0d41ce2 /source | |
parent | 87b308fc23f4b8889c07d1df9f20df7d5f113d63 (diff) |
Speedup for rendered viewport for blender internal
Display code was a bottleneck here, so made it so render
result draw follows Image Draw settings.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/render/render_internal.c | 53 | ||||
-rw-r--r-- | source/blender/imbuf/IMB_colormanagement.h | 5 | ||||
-rw-r--r-- | source/blender/imbuf/intern/colormanagement.c | 24 |
3 files changed, 71 insertions, 11 deletions
diff --git a/source/blender/editors/render/render_internal.c b/source/blender/editors/render/render_internal.c index 424af022366..3e6d426eb06 100644 --- a/source/blender/editors/render/render_internal.c +++ b/source/blender/editors/render/render_internal.c @@ -42,6 +42,7 @@ #include "DNA_scene_types.h" #include "DNA_view3d_types.h" +#include "DNA_userdef_types.h" #include "BKE_blender.h" #include "BKE_context.h" @@ -1027,18 +1028,48 @@ void render_view3d_draw(RenderEngine *engine, const bContext *C) RE_AcquireResultImage(re, &rres); if (rres.rectf) { - unsigned char *rect_byte = MEM_mallocN(rres.rectx * rres.recty * sizeof(int), "ed_preview_draw_rect"); - - RE_AcquiredResultGet32(re, &rres, (unsigned int *)rect_byte); - - glEnable(GL_BLEND); - glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - glaDrawPixelsTex(rres.xof, rres.yof, rres.rectx, rres.recty, GL_RGBA, GL_UNSIGNED_BYTE, GL_LINEAR, rect_byte); - glDisable(GL_BLEND); - - MEM_freeN(rect_byte); + Scene *scene = CTX_data_scene(C); + bool force_fallback = false; + bool need_fallback = true; + float dither = scene->r.dither_intensity; + + /* Dithering is not supported on GLSL yet */ + force_fallback |= dither != 0.0f; + + /* If user decided not to use GLSL, fallback to glaDrawPixelsAuto */ + force_fallback |= (U.image_draw_method != IMAGE_DRAW_METHOD_GLSL); + + /* Try using GLSL display transform. */ + if (force_fallback == false) { + if (IMB_colormanagement_setup_glsl_draw(NULL, &scene->display_settings, TRUE)) { + glEnable(GL_BLEND); + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + glaDrawPixelsTex(rres.xof, rres.yof, rres.rectx, rres.recty, GL_RGBA, GL_FLOAT, + GL_LINEAR, rres.rectf); + glDisable(GL_BLEND); + + IMB_colormanagement_finish_glsl_draw(); + need_fallback = false; + } + } + + /* If GLSL failed, use old-school CPU-based transform. */ + if (need_fallback) { + unsigned char *display_buffer = MEM_mallocN(4 * rres.rectx * rres.recty * sizeof(char), + "render_view3d_draw"); + + IMB_colormanagement_buffer_make_display_space(rres.rectf, display_buffer, rres.rectx, rres.recty, + 4, dither, NULL, &scene->display_settings); + + glEnable(GL_BLEND); + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + glaDrawPixelsAuto(rres.xof, rres.yof, rres.rectx, rres.recty, GL_RGBA, GL_UNSIGNED_BYTE, + GL_LINEAR, display_buffer); + glDisable(GL_BLEND); + + MEM_freeN(display_buffer); + } } RE_ReleaseResultImage(re); } - diff --git a/source/blender/imbuf/IMB_colormanagement.h b/source/blender/imbuf/IMB_colormanagement.h index 314daed00dd..7399b8554aa 100644 --- a/source/blender/imbuf/IMB_colormanagement.h +++ b/source/blender/imbuf/IMB_colormanagement.h @@ -93,6 +93,11 @@ struct ImBuf *IMB_colormanagement_imbuf_for_write(struct ImBuf *ibuf, int save_a const struct ColorManagedDisplaySettings *display_settings, struct ImageFormatData *image_format_data); +void IMB_colormanagement_buffer_make_display_space(float *buffer, unsigned char *display_buffer, + int width, int height, int channels, float dither, + const struct ColorManagedViewSettings *view_settings, + const struct ColorManagedDisplaySettings *display_settings); + /* ** Public display buffers interfaces ** */ void IMB_colormanagement_display_settings_from_ctx(const struct bContext *C, diff --git a/source/blender/imbuf/intern/colormanagement.c b/source/blender/imbuf/intern/colormanagement.c index c127a7b719a..78eb5eeb65b 100644 --- a/source/blender/imbuf/intern/colormanagement.c +++ b/source/blender/imbuf/intern/colormanagement.c @@ -1863,6 +1863,30 @@ ImBuf *IMB_colormanagement_imbuf_for_write(ImBuf *ibuf, int save_as_render, int return colormanaged_ibuf; } +void IMB_colormanagement_buffer_make_display_space(float *buffer, unsigned char *display_buffer, + int width, int height, int channels, float dither, + const ColorManagedViewSettings *view_settings, + const ColorManagedDisplaySettings *display_settings) +{ + ColormanageProcessor *cm_processor; + size_t float_buffer_size = width * height * channels * sizeof(float); + float *display_buffer_float = MEM_mallocN(float_buffer_size, "byte_buffer_make_display_space"); + + memcpy(display_buffer_float, buffer, float_buffer_size); + + cm_processor = IMB_colormanagement_display_processor_new(view_settings, display_settings); + + processor_transform_apply_threaded(display_buffer_float, width, height, channels, + cm_processor, TRUE); + + IMB_buffer_byte_from_float(display_buffer, display_buffer_float, + channels, dither, IB_PROFILE_SRGB, IB_PROFILE_SRGB, + TRUE, width, height, width, width); + + MEM_freeN(display_buffer_float); + IMB_colormanagement_processor_free(cm_processor); +} + static void imbuf_verify_float(ImBuf *ibuf) { /* multiple threads could request for display buffer at once and in case |