GPU: Fix color difference when rendering to gpu_py_offscreen
authorClément Foucault <foucault.clem@gmail.com>
Thu, 28 Mar 2019 21:38:55 +0000 (22:38 +0100)
committerClément Foucault <foucault.clem@gmail.com>
Thu, 28 Mar 2019 21:38:55 +0000 (22:38 +0100)
Now we do the color management inside the Draw manager and output CM byte
buffer.

source/blender/draw/DRW_engine.h
source/blender/draw/intern/draw_manager.c
source/blender/editors/include/ED_view3d.h
source/blender/editors/space_view3d/view3d_draw.c
source/blender/python/gpu/gpu_py_offscreen.c

index 49d17e3..f5e679a 100644 (file)
@@ -111,6 +111,7 @@ void DRW_draw_render_loop_offscreen(
         struct RenderEngineType *engine_type,
         struct ARegion *ar, struct View3D *v3d,
         const bool draw_background,
+        const bool do_color_management,
         struct GPUOffScreen *ofs,
         struct GPUViewport *viewport);
 void DRW_draw_select_loop(
index 8a532ec..44ec992 100644 (file)
@@ -1673,7 +1673,9 @@ void DRW_draw_render_loop(
 void DRW_draw_render_loop_offscreen(
         struct Depsgraph *depsgraph, RenderEngineType *engine_type,
         ARegion *ar, View3D *v3d,
-        const bool draw_background, GPUOffScreen *ofs,
+        const bool draw_background,
+        const bool do_color_management,
+        GPUOffScreen *ofs,
         GPUViewport *viewport)
 {
        /* Create temporary viewport if needed. */
@@ -1686,7 +1688,9 @@ void DRW_draw_render_loop_offscreen(
 
        /* Reset before using it. */
        drw_state_prepare_clean_for_draw(&DST);
-       DST.options.is_image_render = true;
+       /* WATCH: Force color management to output CManaged byte buffer by
+        * forcing is_image_render to false. */
+       DST.options.is_image_render = !do_color_management;
        DST.options.draw_background = draw_background;
        DRW_draw_render_loop_ex(depsgraph, engine_type, ar, v3d, render_viewport, NULL);
 
index 04488ae..02ea002 100644 (file)
@@ -450,7 +450,7 @@ void ED_view3d_draw_offscreen(
         int drawtype,
         struct View3D *v3d, struct ARegion *ar, int winx, int winy, float viewmat[4][4],
         float winmat[4][4], bool do_sky, bool is_persp, const char *viewname,
-        struct GPUFXSettings *fx_settings,
+        struct GPUFXSettings *fx_settings, bool do_color_managment,
         struct GPUOffScreen *ofs, struct GPUViewport *viewport);
 void ED_view3d_draw_setup_view(
         struct wmWindow *win, struct Depsgraph *depsgraph, struct Scene *scene, struct ARegion *ar, struct View3D *v3d,
index 39a7732..522d081 100644 (file)
@@ -1455,7 +1455,7 @@ void ED_view3d_draw_offscreen(
         View3D *v3d, ARegion *ar, int winx, int winy,
         float viewmat[4][4], float winmat[4][4],
         bool do_sky, bool UNUSED(is_persp), const char *viewname,
-        GPUFXSettings *UNUSED(fx_settings),
+        GPUFXSettings *UNUSED(fx_settings), const bool do_color_management,
         GPUOffScreen *ofs, GPUViewport *viewport)
 {
        RegionView3D *rv3d = ar->regiondata;
@@ -1501,7 +1501,7 @@ void ED_view3d_draw_offscreen(
        /* main drawing call */
        DRW_draw_render_loop_offscreen(
                depsgraph, engine_type, ar, v3d,
-               do_sky, ofs, viewport);
+               do_sky, do_color_management, ofs, viewport);
 
        /* restore size */
        ar->winx = bwinx;
@@ -1604,12 +1604,13 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
        }
 
        if ((samples && use_full_sample) == 0) {
+               const bool do_color_management = (ibuf->rect_float == NULL);
                /* Single-pass render, common case */
                ED_view3d_draw_offscreen(
                        depsgraph, scene, drawtype,
                        v3d, ar, sizex, sizey, NULL, winmat,
                        draw_sky, !is_ortho, viewname,
-                       &fx_settings, ofs, NULL);
+                       &fx_settings, do_color_management, ofs, NULL);
 
                if (ibuf->rect_float) {
                        GPU_offscreen_read_pixels(ofs, GL_FLOAT, ibuf->rect_float);
@@ -1634,7 +1635,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
                        depsgraph, scene, drawtype,
                        v3d, ar, sizex, sizey, NULL, winmat,
                        draw_sky, !is_ortho, viewname,
-                       &fx_settings, ofs, viewport);
+                       &fx_settings, false, ofs, viewport);
                GPU_offscreen_read_pixels(ofs, GL_FLOAT, accum_buffer);
 
                /* skip the first sample */
@@ -1649,7 +1650,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
                                depsgraph, scene, drawtype,
                                v3d, ar, sizex, sizey, NULL, winmat_jitter,
                                draw_sky, !is_ortho, viewname,
-                               &fx_settings, ofs, viewport);
+                               &fx_settings, false, ofs, viewport);
                        GPU_offscreen_read_pixels(ofs, GL_FLOAT, rect_temp);
 
                        uint i = sizex * sizey * 4;
index 21edae0..5482677 100644 (file)
@@ -259,6 +259,7 @@ static PyObject *bpygpu_offscreen_draw_view3d(BPyGPUOffScreen *self, PyObject *a
                                 true,
                                 "",
                                 NULL,
+                                true,
                                 self->ofs,
                                 NULL);