Workbench: Support XRay rendering in OpenGL
authorJeroen Bakker <j.bakker@atmind.nl>
Tue, 21 Aug 2018 08:59:01 +0000 (10:59 +0200)
committerJeroen Bakker <j.bakker@atmind.nl>
Tue, 21 Aug 2018 09:00:46 +0000 (11:00 +0200)
OpenGL rendering only implemented the deferred renderer. This commit
will add the forward renderer. The forward renderer is used when XRay
mode is enabled

source/blender/draw/engines/workbench/transparent_mode.c
source/blender/draw/engines/workbench/workbench_forward.c
source/blender/draw/engines/workbench/workbench_private.h
source/blender/draw/engines/workbench/workbench_render.c

index 195b837..8d76da2 100644 (file)
@@ -69,6 +69,7 @@ static void workbench_transparent_draw_scene(void *vedata)
 {
        WORKBENCH_Data *data = vedata;
        workbench_forward_draw_scene(data);
+       workbench_forward_draw_finish(data);
 }
 
 static void workbench_transparent_engine_free(void)
index c311644..410c693 100644 (file)
@@ -626,6 +626,12 @@ void workbench_forward_draw_scene(WORKBENCH_Data *vedata)
        /* Apply checker pattern */
        GPU_framebuffer_bind(dfbl->depth_only_fb);
        DRW_draw_pass(psl->checker_depth_pass);
+}
+
+void workbench_forward_draw_finish(WORKBENCH_Data *vedata)
+{
+       WORKBENCH_StorageList *stl = vedata->stl;
+       WORKBENCH_PrivateData *wpd = stl->g_data;
 
        workbench_private_data_free(wpd);
        workbench_volume_smoke_textures_free(wpd);
index 11a52fb..bb01369 100644 (file)
@@ -258,6 +258,7 @@ void workbench_forward_engine_init(WORKBENCH_Data *vedata);
 void workbench_forward_engine_free(void);
 void workbench_forward_draw_background(WORKBENCH_Data *vedata);
 void workbench_forward_draw_scene(WORKBENCH_Data *vedata);
+void workbench_forward_draw_finish(WORKBENCH_Data *vedata);
 void workbench_forward_cache_init(WORKBENCH_Data *vedata);
 void workbench_forward_cache_populate(WORKBENCH_Data *vedata, Object *ob);
 void workbench_forward_cache_finish(WORKBENCH_Data *vedata);
index 1b25d4c..78064b0 100644 (file)
 
 #include "workbench_private.h"
 
-static void workbench_render_cache(
+static void workbench_render_deferred_cache(
         void *vedata, struct Object *ob,
         struct RenderEngine *UNUSED(engine), struct Depsgraph *UNUSED(depsgraph))
 {
        workbench_deferred_solid_cache_populate(vedata, ob);
 }
 
+static void workbench_render_forward_cache(
+        void *vedata, struct Object *ob,
+        struct RenderEngine *UNUSED(engine), struct Depsgraph *UNUSED(depsgraph))
+{
+       workbench_forward_cache_populate(vedata, ob);
+}
+
 static void workbench_render_matrices_init(RenderEngine *engine, Depsgraph *depsgraph)
 {
        /* TODO(sergey): Shall render hold pointer to an evaluated camera instead? */
@@ -121,7 +128,7 @@ static void workbench_render_framebuffers_finish(void)
 void workbench_render(WORKBENCH_Data *data, RenderEngine *engine, RenderLayer *render_layer, const rcti *rect)
 {
        const DRWContextState *draw_ctx = DRW_context_state_get();
-
+       const Scene *scene = draw_ctx->scene;
        Depsgraph *depsgraph = draw_ctx->depsgraph;
        workbench_render_matrices_init(engine, depsgraph);
 
@@ -130,27 +137,55 @@ void workbench_render(WORKBENCH_Data *data, RenderEngine *engine, RenderLayer *r
                return;
        }
 
-       /* Init engine. */
-       workbench_deferred_engine_init(data);
+       const bool deferred = (scene->display.shading.flag & V3D_SHADING_XRAY) == 0;
+
+       if (deferred)
+       {
+               /* Init engine. */
+               workbench_deferred_engine_init(data);
+
+               /* Init objects. */
+               workbench_deferred_cache_init(data);
+               DRW_render_object_iter(data, engine, depsgraph, workbench_render_deferred_cache);
+               workbench_deferred_cache_finish(data);
+               DRW_render_instance_buffer_finish();
 
-       /* Init objects. */
-       workbench_deferred_cache_init(data);
-       DRW_render_object_iter(data, engine, depsgraph, workbench_render_cache);
-       workbench_deferred_cache_finish(data);
-       DRW_render_instance_buffer_finish();
+               /* Draw. */
+               int num_samples = workbench_taa_calculate_num_iterations(data);
+               for (int sample = 0; sample < num_samples; sample++) {
+                       if (RE_engine_test_break(engine)) {
+                               break;
+                       }
 
-       /* Draw. */
-       int num_samples = workbench_taa_calculate_num_iterations(data);
-       for (int sample = 0; sample < num_samples; sample++) {
-               if (RE_engine_test_break(engine)) {
-                       break;
+                       workbench_deferred_draw_background(data);
+                       workbench_deferred_draw_scene(data);
                }
 
-               workbench_deferred_draw_background(data);
-               workbench_deferred_draw_scene(data);
+               workbench_deferred_draw_finish(data);
        }
+       else {
+               /* Init engine. */
+               workbench_forward_engine_init(data);
+
+               /* Init objects. */
+               workbench_forward_cache_init(data);
+               DRW_render_object_iter(data, engine, depsgraph, workbench_render_forward_cache);
+               workbench_forward_cache_finish(data);
+               DRW_render_instance_buffer_finish();
+
+               /* Draw. */
+               int num_samples = workbench_taa_calculate_num_iterations(data);
+               for (int sample = 0; sample < num_samples; sample++) {
+                       if (RE_engine_test_break(engine)) {
+                               break;
+                       }
+
+                       workbench_forward_draw_background(data);
+                       workbench_forward_draw_scene(data);
+               }
 
-       workbench_deferred_draw_finish(data);
+               workbench_forward_draw_finish(data);
+       }
 
        /* Write render output. */
        const char *viewname = RE_GetActiveRenderView(engine->re);