Support for multi-sample sequencer GL render
authorCampbell Barton <ideasman42@gmail.com>
Wed, 14 Oct 2015 01:39:52 +0000 (12:39 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 14 Oct 2015 01:50:03 +0000 (12:50 +1100)
OpenGL sequencer render now uses a single fbo for all rendering.

source/blender/blenkernel/BKE_sequencer.h
source/blender/blenkernel/intern/sequencer.c
source/blender/editors/include/ED_view3d.h
source/blender/editors/render/render_opengl.c
source/blender/editors/sculpt_paint/paint_image_proj.c
source/blender/editors/space_view3d/view3d_draw.c
source/blender/windowmanager/intern/wm_files.c

index 360243d7b2ad63cdcd42540e5b31e50a1ff83bfc..06f46131c689830d1ec4cf3f0a147fbe4c8b19ad 100644 (file)
@@ -35,6 +35,7 @@ struct EvaluationContext;
 struct StripColorBalance;
 struct Editing;
 struct GSet;
+struct GPUOffScreen;
 struct ImBuf;
 struct Main;
 struct Mask;
@@ -101,6 +102,10 @@ typedef struct SeqRenderData {
        bool skip_cache;
        bool is_proxy_render;
        size_t view_id;
+
+       /* special case for OpenGL render */
+       struct GPUOffScreen *gpu_offscreen;
+       int gpu_samples;
 } SeqRenderData;
 
 void BKE_sequencer_new_render_data(
@@ -408,7 +413,11 @@ struct Sequence *BKE_sequencer_add_sound_strip(struct bContext *C, ListBase *seq
 struct Sequence *BKE_sequencer_add_movie_strip(struct bContext *C, ListBase *seqbasep, struct SeqLoadInfo *seq_load);
 
 /* view3d draw callback, run when not in background view */
-typedef struct ImBuf *(*SequencerDrawView)(struct Scene *, struct Object *, int, int, unsigned int, int, bool, bool, bool, int, const char *, char[256]);
+typedef struct ImBuf *(*SequencerDrawView)(
+        struct Scene *, struct Object *, int, int,
+        unsigned int, int, bool, bool, bool,
+        int, int, const char *,
+        struct GPUOffScreen *, char[256]);
 extern SequencerDrawView sequencer_view3d_cb;
 
 /* copy/paste */
index fc8fa616d208be5bd11a3d3d48c3e01ff8fb1b86..40cacb2b926ba80fa4757c5482e839d3de502492 100644 (file)
@@ -563,6 +563,8 @@ void BKE_sequencer_new_render_data(
        r_context->skip_cache = false;
        r_context->is_proxy_render = false;
        r_context->view_id = 0;
+       r_context->gpu_offscreen = NULL;
+       r_context->gpu_samples = (scene->r.mode & R_OSA) ? scene->r.osa : 0;
 }
 
 /* ************************* iterator ************************** */
@@ -3212,10 +3214,14 @@ static ImBuf *seq_render_scene_strip(const SeqRenderData *context, Sequence *seq
 
                /* opengl offscreen render */
                BKE_scene_update_for_newframe(context->eval_ctx, context->bmain, scene, scene->lay);
-               ibuf = sequencer_view3d_cb(scene, camera, width, height, IB_rect,
-                                          context->scene->r.seq_prev_type,
-                                          (context->scene->r.seq_flag & R_SEQ_SOLID_TEX) != 0,
-                                          use_gpencil, true, scene->r.alphamode, viewname, err_out);
+               ibuf = sequencer_view3d_cb(
+                       /* set for OpenGL render (NULL when scrubbing) */
+                       scene, camera, width, height, IB_rect,
+                       context->scene->r.seq_prev_type,
+                       (context->scene->r.seq_flag & R_SEQ_SOLID_TEX) != 0,
+                       use_gpencil, true, scene->r.alphamode,
+                       context->gpu_samples, viewname,
+                       context->gpu_offscreen, err_out);
                if (ibuf == NULL) {
                        fprintf(stderr, "seq_render_scene_strip failed to get opengl buffer: %s\n", err_out);
                }
index 416e821b3f8b7d71fe06c70fc2c0aa79862e9a56..5cd73e4efb5d793a96e2ced4b2e4d69e5c57a63a 100644 (file)
@@ -323,15 +323,20 @@ bool ED_view3d_context_activate(struct bContext *C);
 void ED_view3d_draw_offscreen_init(struct Scene *scene, struct View3D *v3d);
 void ED_view3d_draw_offscreen(
         struct Scene *scene, struct View3D *v3d, struct ARegion *ar, int winx, int winy, float viewmat[4][4],
-        float winmat[4][4], bool do_bgpic, bool do_sky, bool is_persp,
-        struct GPUOffScreen *ofs,
+        float winmat[4][4], bool do_bgpic, bool do_sky, bool is_persp, const char *viewname,
         struct GPUFX *fx, struct GPUFXSettings *fx_settings,
-        const char *viewname);
-
-struct ImBuf *ED_view3d_draw_offscreen_imbuf(struct Scene *scene, struct View3D *v3d, struct ARegion *ar, int sizex, int sizey, unsigned int flag,
-                                             bool draw_background, int alpha_mode, const char *viewname, char err_out[256]);
-struct ImBuf *ED_view3d_draw_offscreen_imbuf_simple(struct Scene *scene, struct Object *camera, int width, int height, unsigned int flag, int drawtype,
-                                             bool use_solid_tex, bool use_gpencil, bool draw_background, int alpha_mode, const char *viewname, char err_out[256]);
+        struct GPUOffScreen *ofs);
+
+struct ImBuf *ED_view3d_draw_offscreen_imbuf(
+        struct Scene *scene, struct View3D *v3d, struct ARegion *ar, int sizex, int sizey,
+        unsigned int flag, bool draw_background,
+        int alpha_mode, int samples, const char *viewname,
+        struct GPUOffScreen *ofs, char err_out[256]);
+struct ImBuf *ED_view3d_draw_offscreen_imbuf_simple(
+        struct Scene *scene, struct Object *camera, int width, int height,
+        unsigned int flag, int drawtype, bool use_solid_tex, bool use_gpencil, bool draw_background,
+        int alpha_mode, int samples, const char *viewname,
+        struct GPUOffScreen *ofs, char err_out[256]);
 
 struct Base *ED_view3d_give_base_under_cursor(struct bContext *C, const int mval[2]);
 void ED_view3d_quadview_update(struct ScrArea *sa, struct ARegion *ar, bool do_clip);
index c8ced552109bc8f2c18405884a0deb8b3db5d13d..46ed860391eb301cf5d108069d11d918e29991e0 100644 (file)
@@ -96,6 +96,7 @@ typedef struct OGLRender {
        ImageUser iuser;
 
        GPUOffScreen *ofs;
+       int ofs_samples;
        GPUFX *fx;
        int sizex, sizey;
        int write_still;
@@ -279,6 +280,9 @@ static void screen_opengl_render_doit(OGLRender *oglrender, RenderResult *rr)
                        &context);
 
                context.view_id = BKE_scene_multiview_view_id_get(&scene->r, viewname);
+               context.gpu_offscreen = oglrender->ofs;
+               context.gpu_samples = oglrender->ofs_samples;
+
                ibuf = BKE_sequencer_give_ibuf(&context, CFRA, chanshown);
 
                if (ibuf) {
@@ -377,8 +381,9 @@ static void screen_opengl_render_doit(OGLRender *oglrender, RenderResult *rr)
 
                ED_view3d_draw_offscreen(
                        scene, v3d, ar, sizex, sizey, NULL, winmat,
-                       draw_bgpic, draw_sky, is_persp,
-                       oglrender->ofs, oglrender->fx, &fx_settings, viewname);
+                       draw_bgpic, draw_sky, is_persp, viewname,
+                       oglrender->fx, &fx_settings,
+                       oglrender->ofs);
                GPU_offscreen_read_pixels(oglrender->ofs, GL_UNSIGNED_BYTE, rect);
 
                GPU_offscreen_unbind(oglrender->ofs, true); /* unbind */
@@ -386,9 +391,11 @@ static void screen_opengl_render_doit(OGLRender *oglrender, RenderResult *rr)
        else {
                /* shouldnt suddenly give errors mid-render but possible */
                char err_out[256] = "unknown";
-               ImBuf *ibuf_view = ED_view3d_draw_offscreen_imbuf_simple(scene, scene->camera, oglrender->sizex, oglrender->sizey,
-                                                                        IB_rect, OB_SOLID, false, true, true,
-                                                                        (draw_sky) ? R_ADDSKY : R_ALPHAPREMUL, viewname, err_out);
+               ImBuf *ibuf_view = ED_view3d_draw_offscreen_imbuf_simple(
+                       scene, scene->camera, oglrender->sizex, oglrender->sizey,
+                       IB_rect, OB_SOLID, false, true, true,
+                       (draw_sky) ? R_ADDSKY : R_ALPHAPREMUL, oglrender->ofs_samples, viewname,
+                       oglrender->ofs, err_out);
                camera = scene->camera;
 
                if (ibuf_view) {
@@ -498,12 +505,12 @@ static bool screen_opengl_render_init(bContext *C, wmOperator *op)
        GPUOffScreen *ofs;
        OGLRender *oglrender;
        int sizex, sizey;
+       const int samples = (scene->r.mode & R_OSA) ? scene->r.osa : 0;
        bool is_view_context = RNA_boolean_get(op->ptr, "view_context");
        const bool is_animation = RNA_boolean_get(op->ptr, "animation");
        const bool is_sequencer = RNA_boolean_get(op->ptr, "sequencer");
        const bool is_write_still = RNA_boolean_get(op->ptr, "write_still");
        char err_out[256] = "unknown";
-       int samples = (scene->r.mode & R_OSA) ? scene->r.osa : 0;
 
        if (G.background) {
                BKE_report(op->reports, RPT_ERROR, "Cannot use OpenGL render in background mode (no opengl context)");
@@ -555,6 +562,7 @@ static bool screen_opengl_render_init(bContext *C, wmOperator *op)
        op->customdata = oglrender;
 
        oglrender->ofs = ofs;
+       oglrender->ofs_samples = samples;
        oglrender->sizex = sizex;
        oglrender->sizey = sizey;
        oglrender->bmain = CTX_data_main(C);
index 73a3cce50dc2f9c54ccc3229d350caf23d707ee8..565f8a51610bdcfe330ef7a0b3b6d67ffd740d7e 100644 (file)
@@ -5399,7 +5399,10 @@ static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op)
        if (w > maxsize) w = maxsize;
        if (h > maxsize) h = maxsize;
 
-       ibuf = ED_view3d_draw_offscreen_imbuf(scene, CTX_wm_view3d(C), CTX_wm_region(C), w, h, IB_rect, false, R_ALPHAPREMUL, NULL, err_out);
+       ibuf = ED_view3d_draw_offscreen_imbuf(
+               scene, CTX_wm_view3d(C), CTX_wm_region(C),
+               w, h, IB_rect, false, R_ALPHAPREMUL, 0, NULL,
+               NULL, err_out);
        if (!ibuf) {
                /* Mostly happens when OpenGL offscreen buffer was failed to create, */
                /* but could be other reasons. Should be handled in the future. nazgul */
index ac12528483ff92234af8ec703344af0db2ecd005..6840e8a1d28b95bb6122fa3ee117e590a57cc384 100644 (file)
@@ -3144,10 +3144,9 @@ static void view3d_main_area_clear(Scene *scene, View3D *v3d, ARegion *ar)
 void ED_view3d_draw_offscreen(
         Scene *scene, View3D *v3d, ARegion *ar, int winx, int winy,
         float viewmat[4][4], float winmat[4][4],
-        bool do_bgpic, bool do_sky, bool is_persp,
-        GPUOffScreen *ofs,
+        bool do_bgpic, bool do_sky, bool is_persp, const char *viewname,
         GPUFX *fx, GPUFXSettings *fx_settings,
-        const char *viewname)
+        GPUOffScreen *ofs)
 {
        struct bThemeState theme_state;
        int bwinx, bwiny;
@@ -3247,26 +3246,37 @@ void ED_view3d_draw_offscreen(
        G.f &= ~G_RENDER_OGL;
 }
 
-/* utility func for ED_view3d_draw_offscreen */
-ImBuf *ED_view3d_draw_offscreen_imbuf(Scene *scene, View3D *v3d, ARegion *ar, int sizex, int sizey, unsigned int flag,
-                                      bool draw_background, int alpha_mode, const char *viewname, char err_out[256])
+/**
+ * Utility func for ED_view3d_draw_offscreen
+ *
+ * \param ofs: Optional off-screen buffer, can be NULL.
+ * (avoids re-creating when doing multiple GL renders).
+ */
+ImBuf *ED_view3d_draw_offscreen_imbuf(
+        Scene *scene, View3D *v3d, ARegion *ar, int sizex, int sizey,
+        unsigned int flag, bool draw_background,
+        int alpha_mode, int samples, const char *viewname,
+        /* output vars */
+        GPUOffScreen *ofs, char err_out[256])
 {
        RegionView3D *rv3d = ar->regiondata;
        ImBuf *ibuf;
-       GPUOffScreen *ofs;
-       bool draw_sky = (alpha_mode == R_ADDSKY) && v3d && (v3d->flag3 & V3D_SHOW_WORLD);
+       const bool draw_sky = (alpha_mode == R_ADDSKY) && v3d && (v3d->flag3 & V3D_SHOW_WORLD);
+       const bool own_ofs = (ofs == NULL);
 
        if (UNLIKELY(v3d == NULL))
                return NULL;
 
-       /* state changes make normal drawing go weird otherwise */
-       glPushAttrib(GL_LIGHTING_BIT);
+       if (own_ofs) {
+               /* state changes make normal drawing go weird otherwise */
+               glPushAttrib(GL_LIGHTING_BIT);
 
-       /* bind */
-       ofs = GPU_offscreen_create(sizex, sizey, 0, err_out);
-       if (ofs == NULL) {
-               glPopAttrib();
-               return NULL;
+               /* bind */
+               ofs = GPU_offscreen_create(sizex, sizey, samples, err_out);
+               if (ofs == NULL) {
+                       glPopAttrib();
+                       return NULL;
+               }
        }
 
        ED_view3d_draw_offscreen_init(scene, v3d);
@@ -3292,14 +3302,15 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(Scene *scene, View3D *v3d, ARegion *ar, in
 
                ED_view3d_draw_offscreen(
                        scene, v3d, ar, sizex, sizey, NULL, params.winmat,
-                       draw_background, draw_sky, !params.is_ortho,
-                       ofs, NULL, &fx_settings, viewname);
+                       draw_background, draw_sky, !params.is_ortho, viewname,
+                       NULL, &fx_settings,
+                       ofs);
        }
        else {
                ED_view3d_draw_offscreen(
                        scene, v3d, ar, sizex, sizey, NULL, NULL,
-                       draw_background, draw_sky, true,
-                       ofs, NULL, NULL, viewname);
+                       draw_background, draw_sky, true, viewname,
+                       NULL, NULL, ofs);
        }
 
        /* read in pixels & stamp */
@@ -3312,9 +3323,12 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(Scene *scene, View3D *v3d, ARegion *ar, in
 
        /* unbind */
        GPU_offscreen_unbind(ofs, true);
-       GPU_offscreen_free(ofs);
 
-       glPopAttrib();
+       if (own_ofs) {
+               GPU_offscreen_free(ofs);
+
+               glPopAttrib();
+       }
        
        if (ibuf->rect_float && ibuf->rect)
                IMB_rect_from_float(ibuf);
@@ -3322,10 +3336,19 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(Scene *scene, View3D *v3d, ARegion *ar, in
        return ibuf;
 }
 
-/* creates own 3d views, used by the sequencer */
-ImBuf *ED_view3d_draw_offscreen_imbuf_simple(Scene *scene, Object *camera, int width, int height, unsigned int flag, int drawtype,
-                                             bool use_solid_tex, bool use_gpencil, bool draw_background, int alpha_mode,
-                                             const char *viewname, char err_out[256])
+/**
+ * Creates own fake 3d views (wrapping #ED_view3d_draw_offscreen_imbuf)
+ *
+ * \param ofs: Optional off-screen buffer can be NULL.
+ * (avoids re-creating when doing multiple GL renders).
+ *
+ * \note used by the sequencer
+ */
+ImBuf *ED_view3d_draw_offscreen_imbuf_simple(
+        Scene *scene, Object *camera, int width, int height,
+        unsigned int flag, int drawtype, bool use_solid_tex, bool use_gpencil, bool draw_background,
+        int alpha_mode, int samples, const char *viewname,
+        GPUOffScreen *ofs, char err_out[256])
 {
        View3D v3d = {NULL};
        ARegion ar = {NULL};
@@ -3372,8 +3395,10 @@ ImBuf *ED_view3d_draw_offscreen_imbuf_simple(Scene *scene, Object *camera, int w
        mul_m4_m4m4(rv3d.persmat, rv3d.winmat, rv3d.viewmat);
        invert_m4_m4(rv3d.persinv, rv3d.viewinv);
 
-       return ED_view3d_draw_offscreen_imbuf(scene, &v3d, &ar, width, height, flag,
-                                             draw_background, alpha_mode, viewname, err_out);
+       return ED_view3d_draw_offscreen_imbuf(
+               scene, &v3d, &ar, width, height, flag,
+               draw_background, alpha_mode, samples, viewname,
+               ofs, err_out);
 
        // seq_view3d_cb(scene, cfra, render_size, seqrectx, seqrecty);
 }
index c54b06b4a2e23ee7c5509b230d7fd932ba5e78af..8288b2ed1efe712ce14c17fc76912658838227a9 100644 (file)
@@ -932,13 +932,18 @@ static ImBuf *blend_file_thumb(Scene *scene, bScreen *screen, BlendThumbnail **t
 
        /* gets scaled to BLEN_THUMB_SIZE */
        if (scene->camera) {
-               ibuf = ED_view3d_draw_offscreen_imbuf_simple(scene, scene->camera,
-                                                            BLEN_THUMB_SIZE * 2, BLEN_THUMB_SIZE * 2,
-                                                            IB_rect, OB_SOLID, false, false, false, R_ALPHAPREMUL, NULL, err_out);
+               ibuf = ED_view3d_draw_offscreen_imbuf_simple(
+                       scene, scene->camera,
+                       BLEN_THUMB_SIZE * 2, BLEN_THUMB_SIZE * 2,
+                       IB_rect, OB_SOLID, false, false, false, R_ALPHAPREMUL, 0, NULL,
+                       NULL, err_out);
        }
        else {
-               ibuf = ED_view3d_draw_offscreen_imbuf(scene, v3d, ar, BLEN_THUMB_SIZE * 2, BLEN_THUMB_SIZE * 2,
-                                                     IB_rect, false, R_ALPHAPREMUL, NULL, err_out);
+               ibuf = ED_view3d_draw_offscreen_imbuf(
+                       scene, v3d, ar,
+                       BLEN_THUMB_SIZE * 2, BLEN_THUMB_SIZE * 2,
+                       IB_rect, false, R_ALPHAPREMUL, 0, NULL,
+                       NULL, err_out);
        }
 
        if (ibuf) {