From 297261eb906c56c7decf4401e6a3e06cec1691e8 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Fri, 6 Mar 2020 12:08:03 +0100 Subject: CodeCleanup: Added enums to opengl render functions Motivation the functions get 3 different kind of flag parameters (ImBuf, DrawType, OffscreenRendering) the naming of the flags were not clear, leading to mistakes and unnecessary time spend debugging. --- source/blender/blenkernel/BKE_sequencer.h | 15 ---- .../blender/blenkernel/BKE_sequencer_offscreen.h | 56 ++++++++++++++ source/blender/blenkernel/intern/sequencer.c | 1 + source/blender/editors/include/ED_view3d.h | 60 +++++---------- .../blender/editors/include/ED_view3d_offscreen.h | 90 ++++++++++++++++++++++ source/blender/editors/render/render_opengl.c | 11 ++- .../editors/sculpt_paint/paint_image_proj.c | 1 + .../editors/space_sequencer/space_sequencer.c | 4 +- source/blender/editors/space_view3d/view3d_draw.c | 17 ++-- source/blender/imbuf/IMB_imbuf_types.h | 65 ++++++++-------- source/blender/makesdna/DNA_object_enums.h | 10 +++ source/blender/makesdna/DNA_object_types.h | 10 --- source/blender/makesdna/DNA_view3d_types.h | 4 +- source/blender/python/gpu/CMakeLists.txt | 2 + source/blender/python/gpu/gpu_py_offscreen.c | 3 +- source/blender/windowmanager/intern/wm_files.c | 1 + 16 files changed, 232 insertions(+), 118 deletions(-) create mode 100644 source/blender/blenkernel/BKE_sequencer_offscreen.h create mode 100644 source/blender/editors/include/ED_view3d_offscreen.h diff --git a/source/blender/blenkernel/BKE_sequencer.h b/source/blender/blenkernel/BKE_sequencer.h index 789d6b694cb..2a45d89bad4 100644 --- a/source/blender/blenkernel/BKE_sequencer.h +++ b/source/blender/blenkernel/BKE_sequencer.h @@ -521,21 +521,6 @@ struct Sequence *BKE_sequencer_add_movie_strip(struct bContext *C, ListBase *seqbasep, struct SeqLoadInfo *seq_load); -typedef struct ImBuf *(*SequencerDrawView)(struct Depsgraph *depsgraph, - struct Scene *scene, - struct View3DShading *shading_override, - int drawtype, - struct Object *camera, - int width, - int height, - unsigned int flag, - unsigned int draw_flags, - int alpha_mode, - const char *viewname, - struct GPUOffScreen *ofs, - char err_out[256]); -extern SequencerDrawView sequencer_view3d_cb; - /* copy/paste */ extern ListBase seqbase_clipboard; extern int seqbase_clipboard_frame; diff --git a/source/blender/blenkernel/BKE_sequencer_offscreen.h b/source/blender/blenkernel/BKE_sequencer_offscreen.h new file mode 100644 index 00000000000..72e3f246dcb --- /dev/null +++ b/source/blender/blenkernel/BKE_sequencer_offscreen.h @@ -0,0 +1,56 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2004 Blender Foundation. + * All rights reserved. + */ + +#ifndef __BKE_SEQUENCER_OFFSCREEN_H__ +#define __BKE_SEQUENCER_OFFSCREEN_H__ + +/** \file + * \ingroup bke + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "DNA_object_enums.h" + +#include "DNA_view3d_types.h" + +#include "IMB_imbuf_types.h" + +typedef struct ImBuf *(*SequencerDrawView)(struct Depsgraph *depsgraph, + struct Scene *scene, + struct View3DShading *shading_override, + eObjectDrawType drawtype, + struct Object *camera, + int width, + int height, + eImBufFlags flag, + eV3DOffscreenDrawFlag draw_flags, + int alpha_mode, + const char *viewname, + struct GPUOffScreen *ofs, + char err_out[256]); +extern SequencerDrawView sequencer_view3d_cb; + +#ifdef __cplusplus +} +#endif + +#endif /* __BKE_SEQUENCER_H__ */ diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index e86563ea08c..ea53726a94d 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -64,6 +64,7 @@ #include "BKE_layer.h" #include "BKE_main.h" #include "BKE_sequencer.h" +#include "BKE_sequencer_offscreen.h" #include "BKE_movieclip.h" #include "BKE_fcurve.h" #include "BKE_scene.h" diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index 66468275a1e..9627e7d7617 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -45,7 +45,6 @@ struct EditBone; struct GPUOffScreen; struct GPUViewport; struct ID; -struct ImBuf; struct MVert; struct Main; struct MetaElem; @@ -101,6 +100,24 @@ typedef struct ViewDepths { bool damaged; } ViewDepths; +typedef struct ViewDrawOffscreenContext { + struct Depsgraph *depsgraph; + struct Scene *scene; + int drawtype; + struct View3D *v3d; + struct ARegion *ar; + int winx; + int winy; + float viewmat[4][4]; + float winmat[4][4]; + bool do_sky; + bool is_persp; + const char *viewname; + const bool do_color_management; + struct GPUOffScreen *ofs; + struct GPUViewport *viewport; +} ViewDrawOffscreenContext; + /* Rotate 3D cursor on placement. */ enum eV3DCursorOrient { V3D_CURSOR_ORIENT_NONE = 0, @@ -564,21 +581,6 @@ void ED_draw_object_facemap(struct Depsgraph *depsgraph, struct RenderEngineType *ED_view3d_engine_type(struct Scene *scene, int drawtype); bool ED_view3d_context_activate(struct bContext *C); -void ED_view3d_draw_offscreen(struct Depsgraph *depsgraph, - struct Scene *scene, - int drawtype, - struct View3D *v3d, - struct ARegion *ar, - int winx, - int winy, - float viewmat[4][4], - float winmat[4][4], - bool do_sky, - bool is_persp, - const char *viewname, - const bool do_color_management, - struct GPUOffScreen *ofs, - struct GPUViewport *viewport); void ED_view3d_draw_setup_view(struct wmWindow *win, struct Depsgraph *depsgraph, struct Scene *scene, @@ -588,32 +590,6 @@ void ED_view3d_draw_setup_view(struct wmWindow *win, float winmat[4][4], const struct rcti *rect); -struct ImBuf *ED_view3d_draw_offscreen_imbuf(struct Depsgraph *depsgraph, - struct Scene *scene, - int drawtype, - struct View3D *v3d, - struct ARegion *ar, - int sizex, - int sizey, - unsigned int flag, - int alpha_mode, - const char *viewname, - struct GPUOffScreen *ofs, - char err_out[256]); -struct ImBuf *ED_view3d_draw_offscreen_imbuf_simple(struct Depsgraph *depsgraph, - struct Scene *scene, - struct View3DShading *shading_override, - int drawtype, - struct Object *camera, - int width, - int height, - unsigned int flag, - unsigned int draw_flags, - int alpha_mode, - 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]); struct Object *ED_view3d_give_object_under_cursor(struct bContext *C, const int mval[2]); bool ED_view3d_is_object_under_cursor(struct bContext *C, const int mval[2]); diff --git a/source/blender/editors/include/ED_view3d_offscreen.h b/source/blender/editors/include/ED_view3d_offscreen.h new file mode 100644 index 00000000000..5a31516ec64 --- /dev/null +++ b/source/blender/editors/include/ED_view3d_offscreen.h @@ -0,0 +1,90 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2008 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup editors + */ + +#ifndef __ED_VIEW3D_OFFSCREEN_H__ +#define __ED_VIEW3D_OFFSCREEN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* ********* exports for space_view3d/ module for offscreen rendering ********** */ +struct Depsgraph; +struct Scene; +struct View3D; +struct ARegion; +struct GPUOffScreen; +struct GPUViewport; +struct View3DShading; + +#include "DNA_view3d_types.h" +#include "DNA_object_enums.h" +#include "IMB_imbuf_types.h" + +void ED_view3d_draw_offscreen(struct Depsgraph *depsgraph, + struct Scene *scene, + eObjectDrawType drawtype, + struct View3D *v3d, + struct ARegion *ar, + int winx, + int winy, + float viewmat[4][4], + float winmat[4][4], + bool do_sky, + bool is_persp, + const char *viewname, + const bool do_color_management, + struct GPUOffScreen *ofs, + struct GPUViewport *viewport); + +struct ImBuf *ED_view3d_draw_offscreen_imbuf(struct Depsgraph *depsgraph, + struct Scene *scene, + eObjectDrawType drawtype, + struct View3D *v3d, + struct ARegion *ar, + int sizex, + int sizey, + eImBufFlags imbuf_flag, + int alpha_mode, + const char *viewname, + struct GPUOffScreen *ofs, + char err_out[256]); +struct ImBuf *ED_view3d_draw_offscreen_imbuf_simple(struct Depsgraph *depsgraph, + struct Scene *scene, + struct View3DShading *shading_override, + eObjectDrawType drawtype, + struct Object *camera, + int width, + int height, + eImBufFlags imbuf_flags, + eV3DOffscreenDrawFlag draw_flags, + int alpha_mode, + const char *viewname, + struct GPUOffScreen *ofs, + char err_out[256]); + +#ifdef __cplusplus +} +#endif + +#endif /* __ED_VIEW3D_H__ */ diff --git a/source/blender/editors/render/render_opengl.c b/source/blender/editors/render/render_opengl.c index f212eb07e2e..add023fe57a 100644 --- a/source/blender/editors/render/render_opengl.c +++ b/source/blender/editors/render/render_opengl.c @@ -67,6 +67,7 @@ #include "ED_screen.h" #include "ED_view3d.h" +#include "ED_view3d_offscreen.h" #include "ED_gpencil.h" #include "RE_pipeline.h" @@ -368,7 +369,8 @@ static void screen_opengl_render_doit(const bContext *C, OGLRender *oglrender, R char err_out[256] = "unknown"; ImBuf *ibuf_view; const int alpha_mode = (draw_sky) ? R_ADDSKY : R_ALPHAPREMUL; - int output_flags = oglrender->color_depth <= R_IMF_CHAN_DEPTH_8 ? IB_rect : IB_rectfloat; + eImBufFlags imbuf_flags = oglrender->color_depth <= R_IMF_CHAN_DEPTH_8 ? IB_rect : + IB_rectfloat; if (view_context) { ibuf_view = ED_view3d_draw_offscreen_imbuf(depsgraph, @@ -378,7 +380,7 @@ static void screen_opengl_render_doit(const bContext *C, OGLRender *oglrender, R ar, sizex, sizey, - output_flags, + imbuf_flags, alpha_mode, viewname, oglrender->ofs, @@ -397,7 +399,7 @@ static void screen_opengl_render_doit(const bContext *C, OGLRender *oglrender, R scene->camera, oglrender->sizex, oglrender->sizey, - output_flags, + imbuf_flags, V3D_OFSDRAW_SHOW_ANNOTATION, alpha_mode, viewname, @@ -1382,6 +1384,3 @@ void RENDER_OT_opengl(wmOperatorType *ot) "Use the current 3D view for rendering, else use scene settings"); RNA_def_property_flag(prop, PROP_SKIP_SAVE); } - -/* function for getting an opengl buffer from a View3D, used by sequencer */ -// extern void *sequencer_view3d_cb; diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c index c980ffdc5d1..163111ce32f 100644 --- a/source/blender/editors/sculpt_paint/paint_image_proj.c +++ b/source/blender/editors/sculpt_paint/paint_image_proj.c @@ -87,6 +87,7 @@ #include "ED_screen.h" #include "ED_uvedit.h" #include "ED_view3d.h" +#include "ED_view3d_offscreen.h" #include "GPU_extensions.h" #include "GPU_init_exit.h" diff --git a/source/blender/editors/space_sequencer/space_sequencer.c b/source/blender/editors/space_sequencer/space_sequencer.c index 1e2470c1866..d225c70b56b 100644 --- a/source/blender/editors/space_sequencer/space_sequencer.c +++ b/source/blender/editors/space_sequencer/space_sequencer.c @@ -38,10 +38,12 @@ #include "BKE_lib_id.h" #include "BKE_screen.h" #include "BKE_sequencer.h" +#include "BKE_sequencer_offscreen.h" #include "ED_space_api.h" #include "ED_screen.h" -#include "ED_view3d.h" /* only for sequencer view3d drawing callback */ +#include "ED_view3d.h" +#include "ED_view3d_offscreen.h" /* only for sequencer view3d drawing callback */ #include "WM_api.h" #include "WM_types.h" diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 4ff8a9a3884..c58c4b33f05 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -67,6 +67,7 @@ #include "ED_screen.h" #include "ED_screen_types.h" #include "ED_transform.h" +#include "ED_view3d_offscreen.h" #include "DEG_depsgraph_query.h" @@ -1630,7 +1631,7 @@ static void view3d_stereo3d_setup_offscreen(Depsgraph *depsgraph, void ED_view3d_draw_offscreen(Depsgraph *depsgraph, Scene *scene, - int drawtype, + eObjectDrawType drawtype, View3D *v3d, ARegion *ar, int winx, @@ -1710,12 +1711,12 @@ void ED_view3d_draw_offscreen(Depsgraph *depsgraph, */ ImBuf *ED_view3d_draw_offscreen_imbuf(Depsgraph *depsgraph, Scene *scene, - int drawtype, + eObjectDrawType drawtype, View3D *v3d, ARegion *ar, int sizex, int sizey, - uint flag, + eImBufFlags imbuf_flag, int alpha_mode, const char *viewname, /* output vars */ @@ -1755,7 +1756,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(Depsgraph *depsgraph, GPU_offscreen_bind(ofs, true); /* read in pixels & stamp */ - ImBuf *ibuf = IMB_allocImBuf(sizex, sizey, 32, flag); + ImBuf *ibuf = IMB_allocImBuf(sizex, sizey, 32, imbuf_flag); /* render 3d view */ if (rv3d->persp == RV3D_CAMOB && v3d->camera) { @@ -1856,12 +1857,12 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(Depsgraph *depsgraph, ImBuf *ED_view3d_draw_offscreen_imbuf_simple(Depsgraph *depsgraph, Scene *scene, View3DShading *shading_override, - int drawtype, + eObjectDrawType drawtype, Object *camera, int width, int height, - uint flag, - uint draw_flags, + eImBufFlags imbuf_flag, + eV3DOffscreenDrawFlag draw_flags, int alpha_mode, const char *viewname, GPUOffScreen *ofs, @@ -1934,7 +1935,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf_simple(Depsgraph *depsgraph, &ar, width, height, - flag, + imbuf_flag, alpha_mode, viewname, ofs, diff --git a/source/blender/imbuf/IMB_imbuf_types.h b/source/blender/imbuf/IMB_imbuf_types.h index 3559a7ca387..4a5f8cc1bfe 100644 --- a/source/blender/imbuf/IMB_imbuf_types.h +++ b/source/blender/imbuf/IMB_imbuf_types.h @@ -141,6 +141,38 @@ typedef struct ImbFormatOptions { char quality; } ImbFormatOptions; +/** + * \name Imbuf Component flags + * \brief These flags determine the components of an ImBuf struct. + * + * \{ */ + +typedef enum eImBufFlags { + IB_rect = 1 << 0, + IB_test = 1 << 1, + IB_zbuf = 1 << 3, + IB_mem = 1 << 4, + IB_rectfloat = 1 << 5, + IB_zbuffloat = 1 << 6, + IB_multilayer = 1 << 7, + IB_metadata = 1 << 8, + IB_animdeinterlace = 1 << 9, + IB_tiles = 1 << 10, + IB_tilecache = 1 << 11, + /** indicates whether image on disk have premul alpha */ + IB_alphamode_premul = 1 << 12, + /** if this flag is set, alpha mode would be guessed from file */ + IB_alphamode_detect = 1 << 13, + /* alpha channel is unrelated to RGB and should not affect it */ + IB_alphamode_channel_packed = 1 << 14, + /** ignore alpha on load and substitute it with 1.0f */ + IB_alphamode_ignore = 1 << 15, + IB_thumbnail = 1 << 16, + IB_multiview = 1 << 17, + IB_halffloat = 1 << 18, +} eImBufFlags; + +/** \} */ typedef struct ImBuf { struct ImBuf *next, *prev; /**< allow lists of ImBufs, for caches or flipbooks */ @@ -267,39 +299,6 @@ enum { IB_PERSISTENT = (1 << 5), }; -/** - * \name Imbuf Component flags - * \brief These flags determine the components of an ImBuf struct. - * - * \{ */ - -enum { - IB_rect = 1 << 0, - IB_test = 1 << 1, - IB_zbuf = 1 << 3, - IB_mem = 1 << 4, - IB_rectfloat = 1 << 5, - IB_zbuffloat = 1 << 6, - IB_multilayer = 1 << 7, - IB_metadata = 1 << 8, - IB_animdeinterlace = 1 << 9, - IB_tiles = 1 << 10, - IB_tilecache = 1 << 11, - /** indicates whether image on disk have premul alpha */ - IB_alphamode_premul = 1 << 12, - /** if this flag is set, alpha mode would be guessed from file */ - IB_alphamode_detect = 1 << 13, - /* alpha channel is unrelated to RGB and should not affect it */ - IB_alphamode_channel_packed = 1 << 14, - /** ignore alpha on load and substitute it with 1.0f */ - IB_alphamode_ignore = 1 << 15, - IB_thumbnail = 1 << 16, - IB_multiview = 1 << 17, - IB_halffloat = 1 << 18, -}; - -/** \} */ - /** * \name Imbuf preset profile tags * \brief Some predefined color space profiles that 8 bit imbufs can represent diff --git a/source/blender/makesdna/DNA_object_enums.h b/source/blender/makesdna/DNA_object_enums.h index 3214de5b3c6..3ba26dc4bb5 100644 --- a/source/blender/makesdna/DNA_object_enums.h +++ b/source/blender/makesdna/DNA_object_enums.h @@ -39,6 +39,16 @@ typedef enum eObjectMode { OB_MODE_WEIGHT_GPENCIL = 1 << 10, } eObjectMode; +/** #Object.dt */ +typedef enum eObjectDrawType { + OB_BOUNDBOX = 1, + OB_WIRE = 2, + OB_SOLID = 3, + OB_MATERIAL = 4, + OB_TEXTURE = 5, + OB_RENDER = 6, +} eObjectDrawType; + /** Any mode where the brush system is used. */ #define OB_MODE_ALL_PAINT \ (OB_MODE_SCULPT | OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT) diff --git a/source/blender/makesdna/DNA_object_types.h b/source/blender/makesdna/DNA_object_types.h index bfa7400f926..4d15abc3c77 100644 --- a/source/blender/makesdna/DNA_object_types.h +++ b/source/blender/makesdna/DNA_object_types.h @@ -527,16 +527,6 @@ enum { OB_NEGZ = 5, }; -/* dt: no flags */ -enum { - OB_BOUNDBOX = 1, - OB_WIRE = 2, - OB_SOLID = 3, - OB_MATERIAL = 4, - OB_TEXTURE = 5, - OB_RENDER = 6, -}; - /* dtx: flags (short) */ enum { OB_DRAWBOUNDOX = 1 << 0, diff --git a/source/blender/makesdna/DNA_view3d_types.h b/source/blender/makesdna/DNA_view3d_types.h index ce0c68055d9..f0743a3fbb9 100644 --- a/source/blender/makesdna/DNA_view3d_types.h +++ b/source/blender/makesdna/DNA_view3d_types.h @@ -608,11 +608,11 @@ enum { }; /** Settings for offscreen rendering */ -enum { +typedef enum eV3DOffscreenDrawFlag { V3D_OFSDRAW_NONE = (0), V3D_OFSDRAW_SHOW_ANNOTATION = (1 << 0), V3D_OFSDRAW_OVERRIDE_SCENE_SETTINGS = (1 << 1), -}; +} eV3DOffscreenDrawFlag; #define RV3D_CAMZOOM_MIN -30 #define RV3D_CAMZOOM_MAX 600 diff --git a/source/blender/python/gpu/CMakeLists.txt b/source/blender/python/gpu/CMakeLists.txt index 22a3d3a79de..7f6fd9eefab 100644 --- a/source/blender/python/gpu/CMakeLists.txt +++ b/source/blender/python/gpu/CMakeLists.txt @@ -19,7 +19,9 @@ set(INC . ../../blenkernel ../../blenlib + ../../editors/include ../../gpu + ../../imbuf ../../makesdna ../../../../intern/glew-mx ../../../../intern/guardedalloc diff --git a/source/blender/python/gpu/gpu_py_offscreen.c b/source/blender/python/gpu/gpu_py_offscreen.c index 7e371d4f774..b0e0dd27c7d 100644 --- a/source/blender/python/gpu/gpu_py_offscreen.c +++ b/source/blender/python/gpu/gpu_py_offscreen.c @@ -43,7 +43,8 @@ #include "GPU_framebuffer.h" #include "GPU_texture.h" -#include "../editors/include/ED_view3d.h" +#include "ED_view3d.h" +#include "ED_view3d_offscreen.h" #include "../mathutils/mathutils.h" diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index 2dcacc3dc30..a12d325f6d5 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -105,6 +105,7 @@ #include "ED_outliner.h" #include "ED_screen.h" #include "ED_view3d.h" +#include "ED_view3d_offscreen.h" #include "ED_util.h" #include "ED_undo.h" -- cgit v1.2.3