Commit: 6fa4ac542d7e13c118fd077b04023388706be801
Author: Antonio Vazquez
Date:   Tue Mar 6 19:14:04 2018 +0100
Branches: greasepencil-object
https://developer.blender.org/rB6fa4ac542d7e13c118fd077b04023388706be801

WIP: Integrate Cycles render

This is the first try to integrate the Cycles render with Grease Pencil.

Eevee uses its own call and don't need all this stuff because reuse all Eevee 
initialization code.

===================================================================

M       source/blender/draw/DRW_engine.h
M       source/blender/draw/intern/DRW_render.h
M       source/blender/draw/intern/draw_manager.c
M       source/blender/render/intern/source/external_engine.c

===================================================================

diff --git a/source/blender/draw/DRW_engine.h b/source/blender/draw/DRW_engine.h
index 4043f39b46d..64df82a8e9f 100644
--- a/source/blender/draw/DRW_engine.h
+++ b/source/blender/draw/DRW_engine.h
@@ -119,6 +119,9 @@ void DRW_draw_depth_loop(
         struct Depsgraph *depsgraph,
         struct ARegion *ar, struct View3D *v3d, const eObjectMode object_mode);
 
+/* grease pencil render */
+void DRW_render_gpencil(struct RenderEngine *engine, struct Depsgraph 
*depsgraph);
+
 /* This is here because GPUViewport needs it */
 void DRW_pass_free(struct DRWPass *pass);
 struct DRWInstanceDataList *DRW_instance_data_list_create(void);
diff --git a/source/blender/draw/intern/DRW_render.h 
b/source/blender/draw/intern/DRW_render.h
index bc83d1af1f2..b094b570f8e 100644
--- a/source/blender/draw/intern/DRW_render.h
+++ b/source/blender/draw/intern/DRW_render.h
@@ -427,7 +427,6 @@ struct DefaultTextureList     
*DRW_viewport_texture_list_get(void);
 void DRW_viewport_request_redraw(void);
 
 void DRW_render_to_image(struct RenderEngine *engine, struct Depsgraph *graph);
-void DRW_render_gpencil_to_image(struct RenderEngine *engine, struct 
RenderLayer *render_layer, const rcti *rect);
 void DRW_render_object_iter(
        void *vedata, struct RenderEngine *engine, struct Depsgraph *graph,
        void (*callback)(void *vedata, struct Object *ob, struct RenderEngine 
*engine, struct Depsgraph *graph));
diff --git a/source/blender/draw/intern/draw_manager.c 
b/source/blender/draw/intern/draw_manager.c
index 45436162d6e..83b028c504f 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -1274,18 +1274,88 @@ static bool DRW_render_check_object_type(struct 
Depsgraph *depsgraph, short obty
        return false;
 }
 
-void DRW_render_gpencil_to_image(RenderEngine *engine, struct RenderLayer 
*render_layer, const rcti *rect)
+static void DRW_render_gpencil_to_image(RenderEngine *engine, struct Depsgraph 
*depsgraph, struct RenderLayer *render_layer, const rcti *rect)
 {
-       const DRWContextState *draw_ctx = DRW_context_state_get();
-
        if (draw_engine_gpencil_type.render_to_image) {
-               if (DRW_render_check_object_type(draw_ctx->depsgraph, 
OB_GPENCIL)) {
+               if (DRW_render_check_object_type(depsgraph, OB_GPENCIL)) {
                        ViewportEngineData *gpdata = 
drw_viewport_engine_data_ensure(&draw_engine_gpencil_type);
                        draw_engine_gpencil_type.render_to_image(gpdata, 
engine, render_layer, rect);
                }
        }
 }
 
+void DRW_render_gpencil(struct RenderEngine *engine, struct Depsgraph 
*depsgraph)
+{
+       /* This function is only valid for Cycles 
+        * Eevee done all work in the Eevee render directly.
+        * Maybe it can be done equal for both engines?
+       */
+       if (STREQ(engine->type->name, "Eevee")) {
+               return;
+       }
+
+       Scene *scene = DEG_get_evaluated_scene(depsgraph);
+       ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph);
+       RenderEngineType *engine_type = engine->type;
+       DrawEngineType *draw_engine_type = engine_type->draw_engine;
+       RenderData *r = &scene->r;
+       Render *render = engine->re;
+       /* Changing Context */
+       DRW_opengl_context_enable();
+       /* Reset before using it. */
+       memset(&DST, 0x0, offsetof(DRWManager, ogl_context));
+       DST.options.is_image_render = true;
+       DST.options.is_scene_render = true;
+       DST.options.draw_background = scene->r.alphamode == R_ADDSKY;
+       DST.buffer_finish_called = true;
+
+       DST.draw_ctx = (DRWContextState) {
+               NULL, NULL, NULL, scene, view_layer, NULL, engine_type, 
depsgraph, OB_MODE_OBJECT, NULL,
+       };
+       drw_context_state_init();
+
+       DST.viewport = GPU_viewport_create();
+       const int size[2] = { (r->size * r->xsch) / 100, (r->size * r->ysch) / 
100 };
+       GPU_viewport_size_set(DST.viewport, size);
+
+       drw_viewport_var_init();
+
+       /* set default viewport */
+       gpuPushAttrib(GPU_ENABLE_BIT | GPU_VIEWPORT_BIT);
+       glDisable(GL_SCISSOR_TEST);
+       glViewport(0, 0, size[0], size[1]);
+
+       /* Main rendering. */
+       rctf view_rect;
+       rcti render_rect;
+       RE_GetViewPlane(render, &view_rect, &render_rect);
+       if (BLI_rcti_is_empty(&render_rect)) {
+               BLI_rcti_init(&render_rect, 0, size[0], 0, size[1]);
+       }
+
+       RenderResult *render_result = RE_engine_get_result(engine);
+       RenderLayer *render_layer = render_result->layers.first;
+
+       DRW_render_gpencil_to_image(engine, depsgraph, render_layer, 
&render_rect);
+
+       /* Force cache to reset. */
+       drw_viewport_cache_resize();
+       GPU_viewport_free(DST.viewport);
+       DRW_state_reset();
+
+       glDisable(GL_DEPTH_TEST);
+
+       /* Restore Drawing area. */
+       gpuPopAttrib();
+       glEnable(GL_SCISSOR_TEST);
+       GPU_framebuffer_restore();
+
+       /* Changing Context */
+       DRW_opengl_context_disable();
+
+       DST.buffer_finish_called = false;
+}
+
 void DRW_render_to_image(RenderEngine *engine, struct Depsgraph *depsgraph)
 {
        Scene *scene = DEG_get_evaluated_scene(depsgraph);
@@ -1350,7 +1420,7 @@ void DRW_render_to_image(RenderEngine *engine, struct 
Depsgraph *depsgraph)
                RE_SetActiveRenderView(render, render_view->name);
                engine_type->draw_engine->render_to_image(data, engine, 
render_layer, &render_rect);
                /* grease pencil: render result is merged in the previous 
render result. */
-               DRW_render_gpencil_to_image(engine, render_layer, &render_rect);
+               DRW_render_gpencil_to_image(engine, depsgraph, render_layer, 
&render_rect);
                DST.buffer_finish_called = false;
        }
 
diff --git a/source/blender/render/intern/source/external_engine.c 
b/source/blender/render/intern/source/external_engine.c
index ebc4c704adf..a286dda7f5e 100644
--- a/source/blender/render/intern/source/external_engine.c
+++ b/source/blender/render/intern/source/external_engine.c
@@ -768,6 +768,9 @@ int RE_engine_render(Render *re, int do_all)
                        BKE_scene_graph_update_tagged(eval_ctx, depsgraph, 
re->main, re->scene, view_layer);
                        type->render_to_image(engine, depsgraph);
 
+                       /* grease pencil render over previous render result */
+                       DRW_render_gpencil(engine, depsgraph);
+
                        DEG_graph_free(depsgraph);
                        DEG_evaluation_context_free(eval_ctx);
                }

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to