[Bf-blender-cvs] [8957609] master: Sequencer: add support for grease pencil rendering in previews

Campbell Barton noreply at git.blender.org
Fri Jun 13 19:27:40 CEST 2014


Commit: 8957609f353f93475d79706cf2d6b306ed197beb
Author: Campbell Barton
Date:   Sat Jun 14 03:25:07 2014 +1000
https://developer.blender.org/rB8957609f353f93475d79706cf2d6b306ed197beb

Sequencer: add support for grease pencil rendering in previews

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

M	source/blender/editors/gpencil/drawgpencil.c
M	source/blender/editors/include/ED_gpencil.h
M	source/blender/editors/render/render_opengl.c

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

diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c
index eb784ab..a69c020 100644
--- a/source/blender/editors/gpencil/drawgpencil.c
+++ b/source/blender/editors/gpencil/drawgpencil.c
@@ -799,4 +799,11 @@ void ED_gpencil_draw_view3d(Scene *scene, View3D *v3d, ARegion *ar, bool only3d)
 	gp_draw_data(gpd, offsx, offsy, winx, winy, CFRA, dflag);
 }
 
+void ED_gpencil_draw_ex(bGPdata *gpd, int winx, int winy, const int cfra)
+{
+	int dflag = GP_DRAWDATA_NOSTATUS | GP_DRAWDATA_ONLYV2D;
+
+	gp_draw_data(gpd, 0, 0, winx, winy, cfra, dflag);
+}
+
 /* ************************************************** */
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index 8c8178b..63ffa1b 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -80,6 +80,7 @@ void ED_operatortypes_gpencil(void);
 void ED_gpencil_draw_2dimage(const struct bContext *C);
 void ED_gpencil_draw_view2d(const struct bContext *C, bool onlyv2d);
 void ED_gpencil_draw_view3d(struct Scene *scene, struct View3D *v3d, struct ARegion *ar, bool only3d);
+void ED_gpencil_draw_ex(struct bGPdata *gpd, int winx, int winy, const int cfra);
 
 void ED_gpencil_panel_standard_header(const struct bContext *C, struct Panel *pa);
 void ED_gpencil_panel_standard(const struct bContext *C, struct Panel *pa);
diff --git a/source/blender/editors/render/render_opengl.c b/source/blender/editors/render/render_opengl.c
index 94dbf2e..ecf5e96 100644
--- a/source/blender/editors/render/render_opengl.c
+++ b/source/blender/editors/render/render_opengl.c
@@ -36,6 +36,7 @@
 #include "MEM_guardedalloc.h"
 
 #include "BLI_math.h"
+#include "BLI_math_color_blend.h"
 #include "BLI_blenlib.h"
 #include "BLI_utildefines.h"
 #include "BLI_jitter.h"
@@ -57,6 +58,7 @@
 
 #include "ED_screen.h"
 #include "ED_view3d.h"
+#include "ED_gpencil.h"
 
 #include "RE_pipeline.h"
 #include "IMB_imbuf_types.h"
@@ -139,7 +141,9 @@ static void screen_opengl_render_apply(OGLRender *oglrender)
 
 	if (oglrender->is_sequencer) {
 		SeqRenderData context;
-		int chanshown = oglrender->sseq ? oglrender->sseq->chanshown : 0;
+		SpaceSeq *sseq = oglrender->sseq;
+		int chanshown = sseq ? sseq->chanshown : 0;
+		struct bGPdata *gpd = (sseq && (sseq->flag & SEQ_SHOW_GPENCIL)) ? sseq->gpd : NULL;
 
 		context = BKE_sequencer_new_render_data(oglrender->bmain->eval_ctx, oglrender->bmain,
 		                                        scene, oglrender->sizex, oglrender->sizey, 100.0f);
@@ -171,6 +175,33 @@ static void screen_opengl_render_apply(OGLRender *oglrender)
 
 			IMB_freeImBuf(linear_ibuf);
 		}
+
+		if (gpd) {
+			int i;
+			unsigned char *gp_rect;
+
+			GPU_offscreen_bind(oglrender->ofs);
+
+			glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+			wmOrtho2(0, sizex, 0, sizey);
+			glTranslatef(sizex / 2, sizey / 2, 0.0f);
+
+			ED_gpencil_draw_ex(gpd, sizex, sizey, scene->r.cfra);
+
+			gp_rect = MEM_mallocN(sizex * sizey * sizeof(unsigned char) * 4, "offscreen rect");
+			GPU_offscreen_read_pixels(oglrender->ofs, GL_UNSIGNED_BYTE, gp_rect);
+
+			for (i = 0; i < sizex * sizey * 4; i += 4) {
+				float  col_src[4];
+				rgba_uchar_to_float(col_src, &gp_rect[i]);
+				blend_color_mix_float(&rr->rectf[i], &rr->rectf[i], col_src);
+			}
+			GPU_offscreen_unbind(oglrender->ofs);
+
+			MEM_freeN(gp_rect);
+		}
 	}
 	else if (view_context) {
 		ED_view3d_draw_offscreen_init(scene, v3d);




More information about the Bf-blender-cvs mailing list