Cleanup: GL Render (simplify internal logic)
authorCampbell Barton <ideasman42@gmail.com>
Wed, 11 Nov 2015 10:56:25 +0000 (21:56 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 11 Nov 2015 12:07:07 +0000 (23:07 +1100)
Reduce code-paths so improvements to 3D view render apply to sequencer too.

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 418179ceab71e0e0a51ffc6ef753804e00fe6a30..350edde407b601b94d99b7645d4faa8141c5087d 100644 (file)
@@ -36,6 +36,7 @@ struct StripColorBalance;
 struct Editing;
 struct GSet;
 struct GPUOffScreen;
+struct GPUFX;
 struct ImBuf;
 struct Main;
 struct Mask;
@@ -105,6 +106,7 @@ typedef struct SeqRenderData {
 
        /* special case for OpenGL render */
        struct GPUOffScreen *gpu_offscreen;
+       struct GPUFX *gpu_fx;
        int gpu_samples;
 } SeqRenderData;
 
@@ -417,7 +419,7 @@ typedef struct ImBuf *(*SequencerDrawView)(
         struct Scene *, struct Object *, int, int,
         unsigned int, int, bool, bool, bool,
         int, int, const char *,
-        struct GPUOffScreen *, char[256]);
+        struct GPUFX *, struct GPUOffScreen *, char[256]);
 extern SequencerDrawView sequencer_view3d_cb;
 
 /* copy/paste */
index 45d33e51e18330a8a2288bd44d81cdae34d460e4..6d583651e0ffdd391420448be30b99a05bdc2587 100644 (file)
@@ -3222,7 +3222,7 @@ static ImBuf *seq_render_scene_strip(const SeqRenderData *context, Sequence *seq
                        (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);
+                       context->gpu_fx, context->gpu_offscreen, err_out);
                if (ibuf == NULL) {
                        fprintf(stderr, "seq_render_scene_strip failed to get opengl buffer: %s\n", err_out);
                }
index 9da12211daa3c3a615e0c3e57a9faf32264f8798..e5fe163ce4027629948b5e35596d5f340d59b91c 100644 (file)
@@ -334,12 +334,12 @@ 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 GPUFX *fx, 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 GPUFX *fx, 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 263abe752c28c98c1c3a435a27dc35bfbabf1a76..2a48d30dfd18f89d25d1034d6b8f12a02b1b98f2 100644 (file)
@@ -253,7 +253,6 @@ static void screen_opengl_render_doit(OGLRender *oglrender, RenderResult *rr)
        RegionView3D *rv3d = oglrender->rv3d;
        Object *camera = NULL;
        ImBuf *ibuf;
-       float winmat[4][4];
        float *rectf = RE_RenderViewGetById(rr, oglrender->view_id)->rectf;
        int sizex = oglrender->sizex;
        int sizey = oglrender->sizey;
@@ -276,6 +275,7 @@ static void screen_opengl_render_doit(OGLRender *oglrender, RenderResult *rr)
 
                context.view_id = BKE_scene_multiview_view_id_get(&scene->r, viewname);
                context.gpu_offscreen = oglrender->ofs;
+               context.gpu_fx = oglrender->fx;
                context.gpu_samples = oglrender->ofs_samples;
 
                ibuf = BKE_sequencer_give_ibuf(&context, CFRA, chanshown);
@@ -337,62 +337,32 @@ static void screen_opengl_render_doit(OGLRender *oglrender, RenderResult *rr)
                        MEM_freeN(gp_rect);
                }
        }
-       else if (view_context) {
-               bool is_persp;
-               /* full copy */
-               GPUFXSettings fx_settings = v3d->fx_settings;
-
-               ED_view3d_draw_offscreen_init(scene, v3d);
-
-               GPU_offscreen_bind(oglrender->ofs, true); /* bind */
-
-               /* render 3d view */
-               if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
-#if 0
-                       const bool is_ortho = (scene->r.mode & R_ORTHO) != 0;
-#endif
-                       camera = BKE_camera_multiview_render(oglrender->scene, v3d->camera, viewname);
-                       RE_GetCameraWindow(oglrender->re, camera, scene->r.cfra, winmat);
-                       if (camera->type == OB_CAMERA) {
-                               Camera *cam = camera->data;
-                               is_persp = cam->type == CAM_PERSP;
+       else {
+               /* shouldnt suddenly give errors mid-render but possible */
+               char err_out[256] = "unknown";
+               ImBuf *ibuf_view;
+
+               if (view_context) {
+                       ibuf_view = ED_view3d_draw_offscreen_imbuf(
+                              scene, v3d, ar, sizex, sizey,
+                              IB_rect, draw_bgpic,
+                              (draw_sky) ? R_ADDSKY : R_ALPHAPREMUL, oglrender->ofs_samples, viewname,
+                              oglrender->fx, oglrender->ofs, err_out);
+
+                       /* for stamp only */
+                       if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
+                               camera = BKE_camera_multiview_render(oglrender->scene, v3d->camera, viewname);
                        }
-                       else
-                               is_persp = true;
-                       BKE_camera_to_gpu_dof(camera, &fx_settings);
                }
                else {
-                       rctf viewplane;
-                       float clipsta, clipend;
-
-                       bool is_ortho = ED_view3d_viewplane_get(v3d, rv3d, sizex, sizey, &viewplane, &clipsta, &clipend, NULL);
-                       if (is_ortho) orthographic_m4(winmat, viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, -clipend, clipend);
-                       else perspective_m4(winmat, viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, clipsta, clipend);
-
-                       is_persp = !is_ortho;
+                       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->fx, oglrender->ofs, err_out);
+                       camera = scene->camera;
                }
 
-               rect = MEM_mallocN(sizex * sizey * sizeof(unsigned char) * 4, "offscreen rect");
-
-               ED_view3d_draw_offscreen(
-                       scene, v3d, ar, sizex, sizey, NULL, winmat,
-                       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 */
-       }
-       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, oglrender->ofs_samples, viewname,
-                       oglrender->ofs, err_out);
-               camera = scene->camera;
-
                if (ibuf_view) {
                        /* steal rect reference from ibuf */
                        rect = (unsigned char *)ibuf_view->rect;
index 565f8a51610bdcfe330ef7a0b3b6d67ffd740d7e..3b6f88f053838fb39762caeb2e7824ad8701dfca 100644 (file)
@@ -5402,7 +5402,7 @@ static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op)
        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);
+               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 40cd91a6e2fec0b28c6bdad6595734d060359d9d..14861734bfa82e2c662712c8c28682969122c703 100644 (file)
@@ -3296,13 +3296,18 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
         unsigned int flag, bool draw_background,
         int alpha_mode, int samples, const char *viewname,
         /* output vars */
-        GPUOffScreen *ofs, char err_out[256])
+        GPUFX *fx, GPUOffScreen *ofs, char err_out[256])
 {
        RegionView3D *rv3d = ar->regiondata;
        ImBuf *ibuf;
        const bool draw_sky = (alpha_mode == R_ADDSKY) && v3d && (v3d->flag3 & V3D_SHOW_WORLD);
        const bool own_ofs = (ofs == NULL);
 
+       /* view state */
+       GPUFXSettings fx_settings = {NULL};
+       float winmat[4][4];
+       bool is_ortho;
+
        if (UNLIKELY(v3d == NULL))
                return NULL;
 
@@ -3325,7 +3330,6 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
        /* render 3d view */
        if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
                CameraParams params;
-               GPUFXSettings fx_settings = {NULL};
                Object *camera = BKE_camera_multiview_render(scene, v3d->camera, viewname);
 
                BKE_camera_params_init(&params);
@@ -3339,19 +3343,29 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
 
                BKE_camera_to_gpu_dof(camera, &fx_settings);
 
-               ED_view3d_draw_offscreen(
-                       scene, v3d, ar, sizex, sizey, NULL, params.winmat,
-                       draw_background, draw_sky, !params.is_ortho, viewname,
-                       NULL, &fx_settings,
-                       ofs);
+               is_ortho = params.is_ortho;
+               copy_m4_m4(winmat, params.winmat);
        }
        else {
-               ED_view3d_draw_offscreen(
-                       scene, v3d, ar, sizex, sizey, NULL, NULL,
-                       draw_background, draw_sky, true, viewname,
-                       NULL, NULL, ofs);
+               rctf viewplane;
+               float clipsta, clipend;
+
+               fx_settings = v3d->fx_settings;
+
+               is_ortho = ED_view3d_viewplane_get(v3d, rv3d, sizex, sizey, &viewplane, &clipsta, &clipend, NULL);
+               if (is_ortho) {
+                       orthographic_m4(winmat, viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, -clipend, clipend);
+               }
+               else {
+                       perspective_m4(winmat, viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, clipsta, clipend);
+               }
        }
 
+       ED_view3d_draw_offscreen(
+               scene, v3d, ar, sizex, sizey, NULL, winmat,
+               draw_background, draw_sky, !is_ortho, viewname,
+               fx, &fx_settings, ofs);
+
        /* read in pixels & stamp */
        ibuf = IMB_allocImBuf(sizex, sizey, 32, flag);
 
@@ -3368,7 +3382,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
 
                glPopAttrib();
        }
-       
+
        if (ibuf->rect_float && ibuf->rect)
                IMB_rect_from_float(ibuf);
 
@@ -3387,7 +3401,7 @@ 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])
+        GPUFX *fx, GPUOffScreen *ofs, char err_out[256])
 {
        View3D v3d = {NULL};
        ARegion ar = {NULL};
@@ -3437,9 +3451,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf_simple(
        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);
+               fx, ofs, err_out);
 }
 
 
index 37fb4e5d89e63d54e0f13eea3f90453e4054bbf5..87f8c17ca1fea3bc896a7f0e02e178db3d350059 100644 (file)
@@ -936,14 +936,14 @@ static ImBuf *blend_file_thumb(Scene *scene, bScreen *screen, BlendThumbnail **t
                        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);
+                       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, 0, NULL,
-                       NULL, err_out);
+                       NULL, NULL, err_out);
        }
 
        if (ibuf) {