From 37fc23dd9e7738de7187e889f058cda845544ffb Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 24 Nov 2017 11:43:16 +0100 Subject: Refactor view3d offscreen drawing to avoid having multiple boolean arguments This is fully unreadable to have lots of boolean arguments scattered across the whole argument list. What does `false, true, true` mean in terms of behavior? Replace those with bitfield which has advantage of having more human readable meaning. --- source/blender/blenkernel/BKE_sequencer.h | 17 +++++++++++---- source/blender/blenkernel/intern/sequencer.c | 17 +++++++++------ source/blender/editors/include/ED_view3d.h | 19 ++++++++++++---- source/blender/editors/render/render_opengl.c | 13 +++++++---- .../editors/sculpt_paint/paint_image_proj.c | 2 +- source/blender/editors/space_view3d/view3d_draw.c | 25 +++++++++++----------- source/blender/windowmanager/intern/wm_files.c | 4 ++-- 7 files changed, 63 insertions(+), 34 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/BKE_sequencer.h b/source/blender/blenkernel/BKE_sequencer.h index 657e99f05d1..66325cee98e 100644 --- a/source/blender/blenkernel/BKE_sequencer.h +++ b/source/blender/blenkernel/BKE_sequencer.h @@ -421,11 +421,20 @@ 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 */ +/* NOTE: Keep in sync with V3D_OFS_* flags. */ +enum { + SEQ_OFSDRAW_NONE = (0), + SEQ_OFSDRAW_USE_BACKGROUND = (1 << 0), + SEQ_OFSDRAW_USE_FULL_SAMPLE = (1 << 1), + SEQ_OFSDRAW_USE_GPENCIL = (1 << 2), + SEQ_OFSDRAW_USE_SOLID_TEX = (1 << 2), +}; + typedef struct ImBuf *(*SequencerDrawView)( - struct Scene *, struct Object *, int, int, - unsigned int, int, bool, bool, bool, - int, int, bool, const char *, - struct GPUFX *, struct GPUOffScreen *, char[256]); + struct Scene *scene, struct Object *camera, int width, int height, + unsigned int flag, unsigned int draw_flags, int drawtype, int alpha_mode, + int samples, const char *viewname, + struct GPUFX *fx, struct GPUOffScreen *ofs, char err_out[256]); extern SequencerDrawView sequencer_view3d_cb; /* copy/paste */ diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index 9b0db300e6d..592091b057f 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -3295,11 +3295,17 @@ static ImBuf *seq_render_scene_strip(const SeqRenderData *context, Sequence *seq if ((sequencer_view3d_cb && do_seq_gl && camera) && is_thread_main) { char err_out[256] = "unknown"; - int width = (scene->r.xsch * scene->r.size) / 100; - int height = (scene->r.ysch * scene->r.size) / 100; + const int width = (scene->r.xsch * scene->r.size) / 100; + const int height = (scene->r.ysch * scene->r.size) / 100; const bool use_background = (scene->r.alphamode == R_ADDSKY); const char *viewname = BKE_scene_multiview_render_view_name_get(&scene->r, context->view_id); + unsigned int draw_flags = SEQ_OFSDRAW_NONE; + draw_flags |= (use_gpencil) ? SEQ_OFSDRAW_USE_GPENCIL : 0; + draw_flags |= (use_background) ? SEQ_OFSDRAW_USE_BACKGROUND : 0; + draw_flags |= (context->gpu_full_samples) ? SEQ_OFSDRAW_USE_FULL_SAMPLE : 0; + draw_flags |= (context->scene->r.seq_flag & R_SEQ_SOLID_TEX) ? SEQ_OFSDRAW_USE_SOLID_TEX : 0; + /* for old scene this can be uninitialized, * should probably be added to do_versions at some point if the functionality stays */ if (context->scene->r.seq_prev_type == 0) @@ -3309,11 +3315,8 @@ static ImBuf *seq_render_scene_strip(const SeqRenderData *context, Sequence *seq BKE_scene_update_for_newframe(context->eval_ctx, context->bmain, scene, scene->lay); 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, use_background, scene->r.alphamode, - context->gpu_samples, context->gpu_full_samples, viewname, + scene, camera, width, height, IB_rect, draw_flags, context->scene->r.seq_prev_type, + scene->r.alphamode, context->gpu_samples, viewname, 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); diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index 85fb0ee4447..0a87360e58d 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -367,15 +367,26 @@ void ED_view3d_draw_setup_view( struct wmWindow *win, struct Scene *scene, struct ARegion *ar, struct View3D *v3d, float viewmat[4][4], float winmat[4][4], const struct rcti *rect); +enum { + V3D_OFSDRAW_NONE = (0), + + V3D_OFSDRAW_USE_BACKGROUND = (1 << 0), + V3D_OFSDRAW_USE_FULL_SAMPLE = (1 << 1), + + /* Only works with ED_view3d_draw_offscreen_imbuf_simple(). */ + V3D_OFSDRAW_USE_GPENCIL = (1 << 2), + V3D_OFSDRAW_USE_SOLID_TEX = (1 << 2), +}; + 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, bool full_samples, const char *viewname, + unsigned int flag, unsigned int draw_flags, + int alpha_mode, int samples, const char *viewname, 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, bool full_samples, const char *viewname, + unsigned int flag, unsigned int draw_flags, int drawtype, int alpha_mode, + int samples, const char *viewname, 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]); diff --git a/source/blender/editors/render/render_opengl.c b/source/blender/editors/render/render_opengl.c index a27026878e1..a2d34ffefa8 100644 --- a/source/blender/editors/render/render_opengl.c +++ b/source/blender/editors/render/render_opengl.c @@ -353,11 +353,15 @@ static void screen_opengl_render_doit(OGLRender *oglrender, RenderResult *rr) ImBuf *ibuf_view; const int alpha_mode = (draw_sky) ? R_ADDSKY : R_ALPHAPREMUL; + unsigned int draw_flags = V3D_OFSDRAW_NONE; + draw_flags |= (oglrender->ofs_full_samples) ? V3D_OFSDRAW_USE_FULL_SAMPLE : 0; + if (view_context) { + draw_flags |= (draw_bgpic) ? V3D_OFSDRAW_USE_BACKGROUND : 0; + ibuf_view = ED_view3d_draw_offscreen_imbuf( scene, v3d, ar, sizex, sizey, - IB_rect, draw_bgpic, - alpha_mode, oglrender->ofs_samples, oglrender->ofs_full_samples, viewname, + IB_rect, draw_flags, alpha_mode, oglrender->ofs_samples, viewname, oglrender->fx, oglrender->ofs, err_out); /* for stamp only */ @@ -366,10 +370,11 @@ static void screen_opengl_render_doit(OGLRender *oglrender, RenderResult *rr) } } else { + draw_flags |= (V3D_OFSDRAW_USE_GPENCIL | V3D_OFSDRAW_USE_BACKGROUND); ibuf_view = ED_view3d_draw_offscreen_imbuf_simple( scene, scene->camera, oglrender->sizex, oglrender->sizey, - IB_rect, OB_SOLID, false, true, true, - alpha_mode, oglrender->ofs_samples, oglrender->ofs_full_samples, viewname, + IB_rect, draw_flags, OB_SOLID, + alpha_mode, oglrender->ofs_samples, viewname, oglrender->fx, oglrender->ofs, err_out); camera = scene->camera; } diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c index ae6dbbf440c..6fa45f1932a 100644 --- a/source/blender/editors/sculpt_paint/paint_image_proj.c +++ b/source/blender/editors/sculpt_paint/paint_image_proj.c @@ -5460,7 +5460,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, false, NULL, + w, h, IB_rect, V3D_OFSDRAW_NONE, R_ALPHAPREMUL, 0, NULL, NULL, NULL, err_out); if (!ibuf) { /* Mostly happens when OpenGL offscreen buffer was failed to create, */ diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 56508ea989a..8fd38d6a8de 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -3286,14 +3286,16 @@ void ED_view3d_draw_setup_view( */ 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, bool full_samples, const char *viewname, + unsigned int flag, unsigned int draw_flags, + int alpha_mode, int samples, const char *viewname, /* output vars */ GPUFX *fx, GPUOffScreen *ofs, char err_out[256]) { RegionView3D *rv3d = ar->regiondata; ImBuf *ibuf; const bool draw_sky = (alpha_mode == R_ADDSKY); + const bool draw_background = (draw_flags & V3D_OFSDRAW_USE_BACKGROUND); + const bool use_full_sample = (draw_flags & V3D_OFSDRAW_USE_FULL_SAMPLE); /* view state */ GPUFXSettings fx_settings = v3d->fx_settings; @@ -3309,7 +3311,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf( if (own_ofs) { /* bind */ - ofs = GPU_offscreen_create(sizex, sizey, full_samples ? 0 : samples, err_out); + ofs = GPU_offscreen_create(sizex, sizey, use_full_sample ? 0 : samples, err_out); if (ofs == NULL) { return NULL; } @@ -3354,7 +3356,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf( } } - if ((samples && full_samples) == 0) { + if ((samples && use_full_sample) == 0) { /* Single-pass render, common case */ ED_view3d_draw_offscreen( scene, v3d, ar, sizex, sizey, NULL, winmat, @@ -3454,8 +3456,8 @@ ImBuf *ED_view3d_draw_offscreen_imbuf( */ 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, bool full_samples, const char *viewname, + unsigned int flag, unsigned int draw_flags, int drawtype, + int alpha_mode, int samples, const char *viewname, GPUFX *fx, GPUOffScreen *ofs, char err_out[256]) { View3D v3d = {NULL}; @@ -3472,13 +3474,13 @@ ImBuf *ED_view3d_draw_offscreen_imbuf_simple( v3d.drawtype = drawtype; v3d.flag2 = V3D_RENDER_OVERRIDE; - if (use_gpencil) + if (draw_flags & V3D_OFSDRAW_USE_GPENCIL) v3d.flag2 |= V3D_SHOW_GPENCIL; - if (use_solid_tex) + if (draw_flags & V3D_OFSDRAW_USE_SOLID_TEX) v3d.flag2 |= V3D_SOLID_TEX; - if (draw_background) + if (draw_flags & V3D_OFSDRAW_USE_BACKGROUND) v3d.flag3 |= V3D_SHOW_WORLD; rv3d.persp = RV3D_CAMOB; @@ -3507,9 +3509,8 @@ ImBuf *ED_view3d_draw_offscreen_imbuf_simple( invert_m4_m4(rv3d.persinv, rv3d.viewinv); return ED_view3d_draw_offscreen_imbuf( - scene, &v3d, &ar, width, height, flag, - draw_background, alpha_mode, samples, full_samples, viewname, - fx, ofs, err_out); + scene, &v3d, &ar, width, height, flag, draw_flags, + alpha_mode, samples, viewname, fx, ofs, err_out); } diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index 2f6b18cfd3c..57f4219f23f 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -1029,14 +1029,14 @@ static ImBuf *blend_file_thumb(Scene *scene, bScreen *screen, BlendThumbnail **t 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, false, NULL, + IB_rect, OB_SOLID, V3D_OFSDRAW_NONE, R_ALPHAPREMUL, 0, NULL, 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, false, NULL, + IB_rect, V3D_OFSDRAW_NONE, R_ALPHAPREMUL, 0, NULL, NULL, NULL, err_out); } -- cgit v1.2.3