[Bf-blender-cvs] [690f118cfbb] greasepencil-object: WIP: Initial steps to define render to image functions

Antonio Vazquez noreply at git.blender.org
Wed Feb 7 16:59:10 CET 2018


Commit: 690f118cfbb76de108f154c48da9516d192fd5d2
Author: Antonio Vazquez
Date:   Wed Feb 7 16:58:28 2018 +0100
Branches: greasepencil-object
https://developer.blender.org/rB690f118cfbb76de108f154c48da9516d192fd5d2

WIP: Initial steps to define render to image functions

This commit is to put in place all components of the render, but still not working and only enabled in debug mode.

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

M	source/blender/draw/engines/gpencil/gpencil_engine.c
M	source/blender/draw/engines/gpencil/gpencil_engine.h
M	source/blender/draw/intern/draw_manager.c

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

diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index a34f59a6906..6519ff65c73 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -34,10 +34,14 @@
 #include "DNA_gpencil_types.h"
 #include "DNA_view3d_types.h"
 
+#include "DEG_depsgraph_query.h"
+
 #include "draw_mode_engines.h"
 
 #include "UI_resources.h"
 
+#include "RE_pipeline.h"
+
 #include "gpencil_engine.h"
 
 #include "ED_screen.h"
@@ -685,6 +689,7 @@ static void GPENCIL_draw_scene(void *vedata)
 	ToolSettings *ts = scene->toolsettings;
 	Object *obact = draw_ctx->obact;
 	bool playing = (bool)stl->storage->playing;
+	bool is_render = stl->storage->is_render;
 
 	/* paper pass to display a confortable area to draw over complex scenes with geometry */
 	if ((obact) && (obact->type == OB_GPENCIL)) {
@@ -694,7 +699,7 @@ static void GPENCIL_draw_scene(void *vedata)
 	}
 
 	/* if we have a painting session, we use fast viewport drawing method */
-	if (stl->g_data->session_flag & GP_DRW_PAINT_PAINTING) {
+	if ((!is_render) && (stl->g_data->session_flag & GP_DRW_PAINT_PAINTING)) {
 		DRW_framebuffer_bind(dfbl->default_fb);
 
 		MULTISAMPLE_SYNC_ENABLE(dfbl);
@@ -800,10 +805,12 @@ static void GPENCIL_draw_scene(void *vedata)
 				DRW_framebuffer_bind(dfbl->default_fb);
 				DRW_draw_pass(psl->mix_pass);
 				/* prepare for fast drawing */
-				gpencil_prepare_fast_drawing(stl, dfbl, fbl, psl->mix_pass_noblend, clearcol);
+				if (!is_render) {
+					gpencil_prepare_fast_drawing(stl, dfbl, fbl, psl->mix_pass_noblend, clearcol);
+				}
 			}
 			/* edit points */
-			if (!playing) {
+			if ((!is_render) && (!playing)) {
 				DRW_draw_pass(psl->edit_pass);
 			}
 		}
@@ -835,6 +842,84 @@ static void GPENCIL_draw_scene(void *vedata)
 	}
 }
 
+/* init render data */
+void GPENCIL_render_init(GPENCIL_Data *ved, RenderEngine *engine, struct Depsgraph *depsgraph)
+{
+	GPENCIL_Data *vedata = (GPENCIL_Data *)ved;
+	GPENCIL_StorageList *stl = vedata->stl;
+	GPENCIL_FramebufferList *fbl = vedata->fbl;
+
+	Scene *scene = DEG_get_evaluated_scene(depsgraph);
+	const float *viewport_size = DRW_viewport_size_get();
+
+	/* In render mode the default framebuffer is not generated
+	* because there is no viewport. So we need to manually create one 
+	* NOTE : use 32 bit format for precision in render mode. 
+	*/
+	DRWFboTexture tex_color[2] = {
+		{ &e_data.render_depth_tx, DRW_TEX_DEPTH_24_STENCIL_8, DRW_TEX_TEMP },
+		{ &e_data.render_color_tx, DRW_TEX_RGBA_32, DRW_TEX_TEMP }
+	};
+	/* init main framebuffer */
+	DRW_framebuffer_init(
+		&fbl->main, &draw_engine_gpencil_type,
+		(int)viewport_size[0], (int)viewport_size[1],
+		tex_color, ARRAY_SIZE(tex_color));
+
+	/* Alloc transient data. */
+	if (!stl->g_data) {
+		stl->g_data = MEM_callocN(sizeof(*stl->g_data), __func__);
+	}
+	stl->storage->background_alpha = DRW_state_draw_background() ? 1.0f : 0.0f;
+
+	/* Set the pers & view matrix. */
+	struct Object *camera = RE_GetCamera(engine->re);
+	float frame = BKE_scene_frame_get(scene);
+	RE_GetCameraWindow(engine->re, camera, frame, stl->storage->winmat);
+	RE_GetCameraModelMatrix(engine->re, camera, stl->storage->viewinv);
+
+	invert_m4_m4(stl->storage->viewmat, stl->storage->viewinv);
+	mul_m4_m4m4(stl->storage->persmat, stl->storage->winmat, stl->storage->viewmat);
+	invert_m4_m4(stl->storage->persinv, stl->storage->persmat);
+	invert_m4_m4(stl->storage->wininv, stl->storage->winmat);
+
+	DRW_viewport_matrix_override_set(stl->storage->persmat, DRW_MAT_PERS);
+	DRW_viewport_matrix_override_set(stl->storage->persinv, DRW_MAT_PERSINV);
+	DRW_viewport_matrix_override_set(stl->storage->winmat, DRW_MAT_WIN);
+	DRW_viewport_matrix_override_set(stl->storage->wininv, DRW_MAT_WININV);
+	DRW_viewport_matrix_override_set(stl->storage->viewmat, DRW_MAT_VIEW);
+	DRW_viewport_matrix_override_set(stl->storage->viewinv, DRW_MAT_VIEWINV);
+
+	/* INIT CACHE */
+	GPENCIL_cache_init(vedata);
+}
+
+/* render all objects and select only grease pencil */
+void GPENCIL_render_cache(
+	void *vedata, struct Object *ob,
+	struct RenderEngine *UNUSED(engine), struct Depsgraph *UNUSED(depsgraph))
+{
+	if ((ob == NULL) || (DRW_check_object_visible_within_active_context(ob) == false)) {
+		return;
+	}
+
+	if (ob->type == OB_GPENCIL) {
+		GPENCIL_cache_populate(vedata, ob);
+	}
+}
+
+/* render grease pencil to image */
+static void GPENCIL_render_to_image(void *vedata, struct RenderEngine *engine, struct Depsgraph *depsgraph)
+{
+	GPENCIL_engine_init(vedata);
+	GPENCIL_render_init(vedata, engine, depsgraph);
+
+	DRW_render_object_iter(vedata, engine, depsgraph, GPENCIL_render_cache);
+
+	GPENCIL_cache_finish(vedata);
+	GPENCIL_draw_scene(vedata);
+}
+
 static const DrawEngineDataSize GPENCIL_data_size = DRW_VIEWPORT_DATA_SIZE(GPENCIL_Data);
 
 DrawEngineType draw_engine_gpencil_type = {
@@ -850,5 +935,5 @@ DrawEngineType draw_engine_gpencil_type = {
 	&GPENCIL_draw_scene,
 	NULL,
 	NULL,
-	NULL,
+	&GPENCIL_render_to_image,
 };
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 3099d32d2d8..221af1f6802 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -167,6 +167,12 @@ typedef struct GPENCIL_Storage {
 	int uselines;
 	float gridsize[2];
 	float gridcolor[3];
+
+	/* Render Matrices and data */
+	float background_alpha;
+	float persmat[4][4], persinv[4][4];
+	float viewmat[4][4], viewinv[4][4];
+	float winmat[4][4], wininv[4][4];
 } GPENCIL_Storage;
 
 typedef struct GPENCIL_StorageList {
@@ -198,7 +204,7 @@ typedef struct GPENCIL_PassList {
 } GPENCIL_PassList;
 
 typedef struct GPENCIL_FramebufferList {
-	struct GPUFrameBuffer *fb;
+	struct GPUFrameBuffer *main;
 	struct GPUFrameBuffer *temp_color_fb;
 	struct GPUFrameBuffer *vfx_color_fb_a;
 	struct GPUFrameBuffer *vfx_color_fb_b;
@@ -279,6 +285,11 @@ typedef struct GPENCIL_e_data {
 	struct GPUTexture *painting_color_tx;
 
 	struct GPUTexture *gpencil_blank_texture;
+	
+	/* render textures */
+	struct GPUTexture *render_depth_tx;
+	struct GPUTexture *render_color_tx;
+
 	/* runtime pointers texture */
 	struct GPUTexture *input_depth_tx;
 	struct GPUTexture *input_color_tx;
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index 27ba7743653..841a1d495b1 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -3655,6 +3655,13 @@ void DRW_render_to_image(RenderEngine *re, struct Depsgraph *depsgraph)
 	}
 
 	/* TODO grease pencil */
+	/* enabled only in debug mode */
+	if (G.debug_value >= 663) {
+		if (draw_engine_gpencil_type.render_to_image) {
+			ViewportEngineData *gpdata = DRW_viewport_engine_data_ensure(&draw_engine_gpencil_type);
+			draw_engine_gpencil_type.render_to_image(gpdata, re, depsgraph);
+		}
+	}
 
 	GPU_viewport_free(DST.viewport);
 	MEM_freeN(DST.viewport);



More information about the Bf-blender-cvs mailing list