Sequencer: add support for grease pencil rendering in previews
authorCampbell Barton <ideasman42@gmail.com>
Fri, 13 Jun 2014 17:25:07 +0000 (03:25 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 13 Jun 2014 17:25:07 +0000 (03:25 +1000)
source/blender/editors/gpencil/drawgpencil.c
source/blender/editors/include/ED_gpencil.h
source/blender/editors/render/render_opengl.c

index eb784abb34fea1de6f3866929c952985d6fac736..a69c020b07671cbfe0128ef54ed34a719ee767c6 100644 (file)
@@ -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);
+}
+
 /* ************************************************** */
index 8c8178bbdfa4185baf221c5c8adddfa93e545895..63ffa1bef0c55ce729e6260302a03dc4f6a9a938 100644 (file)
@@ -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);
index 94dbf2eed8cb2c62908f6fc7b47de5e3ed3d719a..ecf5e962c80b0468a07484f1e91a35ab39592a43 100644 (file)
@@ -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);