diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2017-03-12 23:16:03 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2017-03-12 23:16:03 +0300 |
commit | 9c6b9e889c01f3ba9775ea942457f58c1b1e63e9 (patch) | |
tree | 0e972cd200f87051a0485883f37c0f319bf29adb /source/blender/draw/modes | |
parent | 40532b9c3b2648f7c0594abb88e73f738dca3229 (diff) |
Clay Engine: Mode engine templates.
Standard Engine layout easy to extend.
Note that most of the work will also happen in mesh_render.c to create geometry batches.
Diffstat (limited to 'source/blender/draw/modes')
-rw-r--r-- | source/blender/draw/modes/draw_mode_engines.h | 13 | ||||
-rw-r--r-- | source/blender/draw/modes/edit_curve_mode.c | 259 | ||||
-rw-r--r-- | source/blender/draw/modes/edit_lattice_mode.c | 259 | ||||
-rw-r--r-- | source/blender/draw/modes/edit_metaball_mode.c | 259 | ||||
-rw-r--r-- | source/blender/draw/modes/edit_surface_mode.c | 259 | ||||
-rw-r--r-- | source/blender/draw/modes/edit_text_mode.c | 259 | ||||
-rw-r--r-- | source/blender/draw/modes/paint_texture_mode.c | 259 | ||||
-rw-r--r-- | source/blender/draw/modes/paint_vertex_mode.c | 259 | ||||
-rw-r--r-- | source/blender/draw/modes/paint_weight_mode.c | 259 | ||||
-rw-r--r-- | source/blender/draw/modes/particle_mode.c | 259 | ||||
-rw-r--r-- | source/blender/draw/modes/pose_mode.c | 259 | ||||
-rw-r--r-- | source/blender/draw/modes/sculpt_mode.c | 259 |
12 files changed, 2861 insertions, 1 deletions
diff --git a/source/blender/draw/modes/draw_mode_engines.h b/source/blender/draw/modes/draw_mode_engines.h index 01af249b736..c3b4d5ee61a 100644 --- a/source/blender/draw/modes/draw_mode_engines.h +++ b/source/blender/draw/modes/draw_mode_engines.h @@ -27,7 +27,18 @@ #define __DRAW_MODES_ENGINES_H__ extern DrawEngineType draw_engine_object_type; -extern DrawEngineType draw_engine_edit_mesh_type; extern DrawEngineType draw_engine_edit_armature_type; +extern DrawEngineType draw_engine_edit_curve_type; +extern DrawEngineType draw_engine_edit_lattice_type; +extern DrawEngineType draw_engine_edit_mesh_type; +extern DrawEngineType draw_engine_edit_metaball_type; +extern DrawEngineType draw_engine_edit_surface_type; +extern DrawEngineType draw_engine_edit_text_type; +extern DrawEngineType draw_engine_paint_texture_type; +extern DrawEngineType draw_engine_paint_vertex_type; +extern DrawEngineType draw_engine_paint_weight_type; +extern DrawEngineType draw_engine_particle_type; +extern DrawEngineType draw_engine_pose_type; +extern DrawEngineType draw_engine_sculpt_type; #endif /* __DRAW_MODES_ENGINES_H__ */
\ No newline at end of file diff --git a/source/blender/draw/modes/edit_curve_mode.c b/source/blender/draw/modes/edit_curve_mode.c new file mode 100644 index 00000000000..acf36c29174 --- /dev/null +++ b/source/blender/draw/modes/edit_curve_mode.c @@ -0,0 +1,259 @@ +/* + * Copyright 2016, Blender Foundation. + * + * 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. + * + * Contributor(s): Blender Institute + * + */ + +/** \file blender/draw/modes/edit_curve_mode.c + * \ingroup draw + */ + +#include "DRW_engine.h" +#include "DRW_render.h" + +/* If builtin shaders are needed */ +#include "GPU_shader.h" + +#include "draw_common.h" + +#include "draw_mode_engines.h" + +/* *********** LISTS *********** */ +/* All lists are per viewport specific datas. + * They are all free when viewport changes engines + * or is free itself. Use EDIT_CURVE_engine_init() to + * initialize most of them and EDIT_CURVE_cache_init() + * for EDIT_CURVE_PassList */ + +/* keep it under MAX_PASSES */ +typedef struct EDIT_CURVE_PassList { + /* Declare all passes here and init them in + * EDIT_CURVE_cache_init(). + * Only contains (DRWPass *) */ + struct DRWPass *pass; +} EDIT_CURVE_PassList; + +/* keep it under MAX_BUFFERS */ +typedef struct EDIT_CURVE_FramebufferList { + /* Contains all framebuffer objects needed by this engine. + * Only contains (GPUFrameBuffer *) */ + // struct GPUFrameBuffer *fb; +} EDIT_CURVE_FramebufferList; + +/* keep it under MAX_TEXTURES */ +typedef struct EDIT_CURVE_TextureList { + /* Contains all framebuffer textures / utility textures + * needed by this engine. Only viewport specific textures + * (not per object). Only contains (GPUTexture *) */ + // struct GPUTexture *texture; +} EDIT_CURVE_TextureList; + +/* keep it under MAX_STORAGE */ +typedef struct EDIT_CURVE_StorageList { + /* Contains any other memory block that the engine needs. + * Only directly MEM_(m/c)allocN'ed blocks because they are + * free with MEM_freeN() when viewport is freed. + * (not per object) */ + // struct CustomStruct *block; +} EDIT_CURVE_StorageList; + +typedef struct EDIT_CURVE_Data { + /* Struct returned by DRW_viewport_engine_data_get. + * If you don't use one of these, just make it a (void *) */ + // void *fbl; + char engine_name[32]; /* Required */ + EDIT_CURVE_FramebufferList *fbl; + EDIT_CURVE_TextureList *txl; + EDIT_CURVE_PassList *psl; + EDIT_CURVE_StorageList *stl; +} EDIT_CURVE_Data; + +/* *********** STATIC *********** */ + +/* This keeps the references of the shading groups for + * easy access in EDIT_CURVE_cache_populate() */ +static DRWShadingGroup *group; + +/* If needed, contains all global/Theme colors + * Add needed theme colors / values to DRW_globals_update() and update UBO + * Not needed for constant color. */ +extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */ +extern struct GlobalsUboStorage ts; /* draw_common.c */ + +/* Custom shaders : + * Add sources to source/blender/draw/modes/shaders + * init in EDIT_CURVE_engine_init(); + * free in EDIT_CURVE_engine_free(); */ +static struct GPUShader *custom_shader = NULL; + +/* This keeps the reference of the viewport engine data because + * DRW_viewport_engine_data_get is slow and we don't want to + * call it for every object */ +static EDIT_CURVE_Data *vedata; + +/* *********** FUNCTIONS *********** */ + +/* Init Textures, Framebuffers, Storage and Shaders. + * It is called for every frames. + * (Optionnal) */ +static void EDIT_CURVE_engine_init(void) +{ + EDIT_CURVE_Data *vedata = DRW_viewport_engine_data_get("EditCurveMode"); + EDIT_CURVE_TextureList *txl = vedata->txl; + EDIT_CURVE_FramebufferList *fbl = vedata->fbl; + EDIT_CURVE_StorageList *stl = vedata->stl; + + /* Init Framebuffers like this: order is attachment order (for color texs) */ + /* + * DRWFboTexture tex[2] = {{&txl->depth, DRW_BUF_DEPTH_24}, + * {&txl->color, DRW_BUF_RGBA_8}}; + */ + + /* DRW_framebuffer_init takes care of checking if + * the framebuffer is valid and has the right size*/ + /* + * float *viewport_size = DRW_viewport_size_get(); + * DRW_framebuffer_init(&fbl->occlude_wire_fb, + * (int)viewport_size[0], (int)viewport_size[1], + * tex, 2); + */ + + if (!custom_shader) { + custom_shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR); + } +} + +/* Here init all passes and shading groups + * Assume that all Passes are NULL */ +static void EDIT_CURVE_cache_init(void) +{ + vedata = DRW_viewport_engine_data_get("EditCurveMode"); + EDIT_CURVE_PassList *psl = vedata->psl; + EDIT_CURVE_StorageList *stl = vedata->stl; + + { + /* Create a pass */ + DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND | DRW_STATE_WIRE; + psl->pass = DRW_pass_create("My Pass", state); + + /* Create a shadingGroup using a function in draw_common.c or custom one */ + /* + * group = shgroup_dynlines_uniform_color(psl->pass, ts.colorWire); + * -- or -- + * group = DRW_shgroup_create(custom_shader, psl->pass); + */ + group = DRW_shgroup_create(custom_shader, psl->pass); + + /* Uniforms need a pointer to it's value so be sure it's accessible at + * any given time (i.e. use static vars) */ + static float color[4] = {0.2f, 0.5f, 0.3f, 1.0}; + DRW_shgroup_uniform_vec4(group, "color", color, 1); + } + +} + +/* Add geometry to shadingGroups. Execute for each objects */ +static void EDIT_CURVE_cache_populate(Object *ob) +{ + EDIT_CURVE_PassList *psl = vedata->psl; + EDIT_CURVE_StorageList *stl = vedata->stl; + + if (ob->type == OB_MESH) { + /* Get geometry cache */ + struct Batch *geom = DRW_cache_surface_get(ob); + + /* Add geom to a shading group */ + DRW_shgroup_call_add(group, geom, ob->obmat); + } +} + +/* Optionnal : Post-cache_populate callback */ +static void EDIT_CURVE_cache_finish(void) +{ + EDIT_CURVE_PassList *psl = vedata->psl; + EDIT_CURVE_StorageList *stl = vedata->stl; + + /* Do something here! dependant on the objects gathered */ +} + +/* Draw time ! Control rendering pipeline from here */ +static void EDIT_CURVE_draw_scene(void) +{ + EDIT_CURVE_Data *ved = DRW_viewport_engine_data_get("EditCurveMode"); + EDIT_CURVE_PassList *psl = ved->psl; + EDIT_CURVE_FramebufferList *fbl = vedata->fbl; + + /* Default framebuffer and texture */ + DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get(); + DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); + + /* Show / hide entire passes, swap framebuffers ... whatever you fancy */ + /* + * DRW_framebuffer_texture_detach(dtxl->depth); + * DRW_framebuffer_bind(fbl->custom_fb); + * DRW_draw_pass(psl->pass); + * DRW_framebuffer_texture_attach(dfbl->default_fb, dtxl->depth, 0); + * DRW_framebuffer_bind(dfbl->default_fb); + */ + + /* ... or just render passes on default framebuffer. */ + DRW_draw_pass(psl->pass); + + /* If you changed framebuffer, double check you rebind + * the default one with its textures attached before finishing */ +} + +/* Cleanup when destroying the engine. + * This is not per viewport ! only when quitting blender. + * Mostly used for freeing shaders */ +static void EDIT_CURVE_engine_free(void) +{ + // if (custom_shader) + // DRW_shader_free(custom_shader); +} + +/* Create collection settings here. + * + * Be sure to add this function there : + * source/blender/draw/DRW_engine.h + * source/blender/blenkernel/intern/layer.c + * source/blenderplayer/bad_level_call_stubs/stubs.c + * + * And relevant collection settings to : + * source/blender/makesrna/intern/rna_scene.c + * source/blender/blenkernel/intern/layer.c + */ +void EDIT_CURVE_collection_settings_create(CollectionEngineSettings *ces) +{ + BLI_assert(ces); + // BKE_collection_engine_property_add_int(ces, "my_bool_prop", false); + // BKE_collection_engine_property_add_int(ces, "my_int_prop", 0); + // BKE_collection_engine_property_add_float(ces, "my_float_prop", 0.0f); +} + +DrawEngineType draw_engine_edit_curve_type = { + NULL, NULL, + N_("EditCurveMode"), + &EDIT_CURVE_engine_init, + &EDIT_CURVE_engine_free, + &EDIT_CURVE_cache_init, + &EDIT_CURVE_cache_populate, + &EDIT_CURVE_cache_finish, + NULL, /* draw_background but not needed by mode engines */ + &EDIT_CURVE_draw_scene +}; diff --git a/source/blender/draw/modes/edit_lattice_mode.c b/source/blender/draw/modes/edit_lattice_mode.c new file mode 100644 index 00000000000..219b70cf139 --- /dev/null +++ b/source/blender/draw/modes/edit_lattice_mode.c @@ -0,0 +1,259 @@ +/* + * Copyright 2016, Blender Foundation. + * + * 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. + * + * Contributor(s): Blender Institute + * + */ + +/** \file blender/draw/modes/edit_lattice_mode.c + * \ingroup draw + */ + +#include "DRW_engine.h" +#include "DRW_render.h" + +/* If builtin shaders are needed */ +#include "GPU_shader.h" + +#include "draw_common.h" + +#include "draw_mode_engines.h" + +/* *********** LISTS *********** */ +/* All lists are per viewport specific datas. + * They are all free when viewport changes engines + * or is free itself. Use EDIT_LATTICE_engine_init() to + * initialize most of them and EDIT_LATTICE_cache_init() + * for EDIT_LATTICE_PassList */ + +/* keep it under MAX_PASSES */ +typedef struct EDIT_LATTICE_PassList { + /* Declare all passes here and init them in + * EDIT_LATTICE_cache_init(). + * Only contains (DRWPass *) */ + struct DRWPass *pass; +} EDIT_LATTICE_PassList; + +/* keep it under MAX_BUFFERS */ +typedef struct EDIT_LATTICE_FramebufferList { + /* Contains all framebuffer objects needed by this engine. + * Only contains (GPUFrameBuffer *) */ + // struct GPUFrameBuffer *fb; +} EDIT_LATTICE_FramebufferList; + +/* keep it under MAX_TEXTURES */ +typedef struct EDIT_LATTICE_TextureList { + /* Contains all framebuffer textures / utility textures + * needed by this engine. Only viewport specific textures + * (not per object). Only contains (GPUTexture *) */ + // struct GPUTexture *texture; +} EDIT_LATTICE_TextureList; + +/* keep it under MAX_STORAGE */ +typedef struct EDIT_LATTICE_StorageList { + /* Contains any other memory block that the engine needs. + * Only directly MEM_(m/c)allocN'ed blocks because they are + * free with MEM_freeN() when viewport is freed. + * (not per object) */ + // struct CustomStruct *block; +} EDIT_LATTICE_StorageList; + +typedef struct EDIT_LATTICE_Data { + /* Struct returned by DRW_viewport_engine_data_get. + * If you don't use one of these, just make it a (void *) */ + // void *fbl; + char engine_name[32]; /* Required */ + EDIT_LATTICE_FramebufferList *fbl; + EDIT_LATTICE_TextureList *txl; + EDIT_LATTICE_PassList *psl; + EDIT_LATTICE_StorageList *stl; +} EDIT_LATTICE_Data; + +/* *********** STATIC *********** */ + +/* This keeps the references of the shading groups for + * easy access in EDIT_LATTICE_cache_populate() */ +static DRWShadingGroup *group; + +/* If needed, contains all global/Theme colors + * Add needed theme colors / values to DRW_globals_update() and update UBO + * Not needed for constant color. */ +extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */ +extern struct GlobalsUboStorage ts; /* draw_common.c */ + +/* Custom shaders : + * Add sources to source/blender/draw/modes/shaders + * init in EDIT_LATTICE_engine_init(); + * free in EDIT_LATTICE_engine_free(); */ +static struct GPUShader *custom_shader = NULL; + +/* This keeps the reference of the viewport engine data because + * DRW_viewport_engine_data_get is slow and we don't want to + * call it for every object */ +static EDIT_LATTICE_Data *vedata; + +/* *********** FUNCTIONS *********** */ + +/* Init Textures, Framebuffers, Storage and Shaders. + * It is called for every frames. + * (Optionnal) */ +static void EDIT_LATTICE_engine_init(void) +{ + EDIT_LATTICE_Data *vedata = DRW_viewport_engine_data_get("EditLatticeMode"); + EDIT_LATTICE_TextureList *txl = vedata->txl; + EDIT_LATTICE_FramebufferList *fbl = vedata->fbl; + EDIT_LATTICE_StorageList *stl = vedata->stl; + + /* Init Framebuffers like this: order is attachment order (for color texs) */ + /* + * DRWFboTexture tex[2] = {{&txl->depth, DRW_BUF_DEPTH_24}, + * {&txl->color, DRW_BUF_RGBA_8}}; + */ + + /* DRW_framebuffer_init takes care of checking if + * the framebuffer is valid and has the right size*/ + /* + * float *viewport_size = DRW_viewport_size_get(); + * DRW_framebuffer_init(&fbl->occlude_wire_fb, + * (int)viewport_size[0], (int)viewport_size[1], + * tex, 2); + */ + + if (!custom_shader) { + custom_shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR); + } +} + +/* Here init all passes and shading groups + * Assume that all Passes are NULL */ +static void EDIT_LATTICE_cache_init(void) +{ + vedata = DRW_viewport_engine_data_get("EditLatticeMode"); + EDIT_LATTICE_PassList *psl = vedata->psl; + EDIT_LATTICE_StorageList *stl = vedata->stl; + + { + /* Create a pass */ + DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND | DRW_STATE_WIRE; + psl->pass = DRW_pass_create("My Pass", state); + + /* Create a shadingGroup using a function in draw_common.c or custom one */ + /* + * group = shgroup_dynlines_uniform_color(psl->pass, ts.colorWire); + * -- or -- + * group = DRW_shgroup_create(custom_shader, psl->pass); + */ + group = DRW_shgroup_create(custom_shader, psl->pass); + + /* Uniforms need a pointer to it's value so be sure it's accessible at + * any given time (i.e. use static vars) */ + static float color[4] = {1.0f, 0.0f, 0.0f, 1.0}; + DRW_shgroup_uniform_vec4(group, "color", color, 1); + } + +} + +/* Add geometry to shadingGroups. Execute for each objects */ +static void EDIT_LATTICE_cache_populate(Object *ob) +{ + EDIT_LATTICE_PassList *psl = vedata->psl; + EDIT_LATTICE_StorageList *stl = vedata->stl; + + if (ob->type == OB_MESH) { + /* Get geometry cache */ + struct Batch *geom = DRW_cache_surface_get(ob); + + /* Add geom to a shading group */ + DRW_shgroup_call_add(group, geom, ob->obmat); + } +} + +/* Optionnal : Post-cache_populate callback */ +static void EDIT_LATTICE_cache_finish(void) +{ + EDIT_LATTICE_PassList *psl = vedata->psl; + EDIT_LATTICE_StorageList *stl = vedata->stl; + + /* Do something here! dependant on the objects gathered */ +} + +/* Draw time ! Control rendering pipeline from here */ +static void EDIT_LATTICE_draw_scene(void) +{ + EDIT_LATTICE_Data *ved = DRW_viewport_engine_data_get("EditLatticeMode"); + EDIT_LATTICE_PassList *psl = ved->psl; + EDIT_LATTICE_FramebufferList *fbl = vedata->fbl; + + /* Default framebuffer and texture */ + DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get(); + DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); + + /* Show / hide entire passes, swap framebuffers ... whatever you fancy */ + /* + * DRW_framebuffer_texture_detach(dtxl->depth); + * DRW_framebuffer_bind(fbl->custom_fb); + * DRW_draw_pass(psl->pass); + * DRW_framebuffer_texture_attach(dfbl->default_fb, dtxl->depth, 0); + * DRW_framebuffer_bind(dfbl->default_fb); + */ + + /* ... or just render passes on default framebuffer. */ + DRW_draw_pass(psl->pass); + + /* If you changed framebuffer, double check you rebind + * the default one with its textures attached before finishing */ +} + +/* Cleanup when destroying the engine. + * This is not per viewport ! only when quitting blender. + * Mostly used for freeing shaders */ +static void EDIT_LATTICE_engine_free(void) +{ + // if (custom_shader) + // DRW_shader_free(custom_shader); +} + +/* Create collection settings here. + * + * Be sure to add this function there : + * source/blender/draw/DRW_engine.h + * source/blender/blenkernel/intern/layer.c + * source/blenderplayer/bad_level_call_stubs/stubs.c + * + * And relevant collection settings to : + * source/blender/makesrna/intern/rna_scene.c + * source/blender/blenkernel/intern/layer.c + */ +void EDIT_LATTICE_collection_settings_create(CollectionEngineSettings *ces) +{ + BLI_assert(ces); + // BKE_collection_engine_property_add_int(ces, "my_bool_prop", false); + // BKE_collection_engine_property_add_int(ces, "my_int_prop", 0); + // BKE_collection_engine_property_add_float(ces, "my_float_prop", 0.0f); +} + +DrawEngineType draw_engine_edit_lattice_type = { + NULL, NULL, + N_("EditLatticeMode"), + &EDIT_LATTICE_engine_init, + &EDIT_LATTICE_engine_free, + &EDIT_LATTICE_cache_init, + &EDIT_LATTICE_cache_populate, + &EDIT_LATTICE_cache_finish, + NULL, /* draw_background but not needed by mode engines */ + &EDIT_LATTICE_draw_scene +}; diff --git a/source/blender/draw/modes/edit_metaball_mode.c b/source/blender/draw/modes/edit_metaball_mode.c new file mode 100644 index 00000000000..0f314f355c0 --- /dev/null +++ b/source/blender/draw/modes/edit_metaball_mode.c @@ -0,0 +1,259 @@ +/* + * Copyright 2016, Blender Foundation. + * + * 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. + * + * Contributor(s): Blender Institute + * + */ + +/** \file blender/draw/modes/edit_metaball_mode.c + * \ingroup draw + */ + +#include "DRW_engine.h" +#include "DRW_render.h" + +/* If builtin shaders are needed */ +#include "GPU_shader.h" + +#include "draw_common.h" + +#include "draw_mode_engines.h" + +/* *********** LISTS *********** */ +/* All lists are per viewport specific datas. + * They are all free when viewport changes engines + * or is free itself. Use EDIT_METABALL_engine_init() to + * initialize most of them and EDIT_METABALL_cache_init() + * for EDIT_METABALL_PassList */ + +/* keep it under MAX_PASSES */ +typedef struct EDIT_METABALL_PassList { + /* Declare all passes here and init them in + * EDIT_METABALL_cache_init(). + * Only contains (DRWPass *) */ + struct DRWPass *pass; +} EDIT_METABALL_PassList; + +/* keep it under MAX_BUFFERS */ +typedef struct EDIT_METABALL_FramebufferList { + /* Contains all framebuffer objects needed by this engine. + * Only contains (GPUFrameBuffer *) */ + // struct GPUFrameBuffer *fb; +} EDIT_METABALL_FramebufferList; + +/* keep it under MAX_TEXTURES */ +typedef struct EDIT_METABALL_TextureList { + /* Contains all framebuffer textures / utility textures + * needed by this engine. Only viewport specific textures + * (not per object). Only contains (GPUTexture *) */ + // struct GPUTexture *texture; +} EDIT_METABALL_TextureList; + +/* keep it under MAX_STORAGE */ +typedef struct EDIT_METABALL_StorageList { + /* Contains any other memory block that the engine needs. + * Only directly MEM_(m/c)allocN'ed blocks because they are + * free with MEM_freeN() when viewport is freed. + * (not per object) */ + // struct CustomStruct *block; +} EDIT_METABALL_StorageList; + +typedef struct EDIT_METABALL_Data { + /* Struct returned by DRW_viewport_engine_data_get. + * If you don't use one of these, just make it a (void *) */ + // void *fbl; + char engine_name[32]; /* Required */ + EDIT_METABALL_FramebufferList *fbl; + EDIT_METABALL_TextureList *txl; + EDIT_METABALL_PassList *psl; + EDIT_METABALL_StorageList *stl; +} EDIT_METABALL_Data; + +/* *********** STATIC *********** */ + +/* This keeps the references of the shading groups for + * easy access in EDIT_METABALL_cache_populate() */ +static DRWShadingGroup *group; + +/* If needed, contains all global/Theme colors + * Add needed theme colors / values to DRW_globals_update() and update UBO + * Not needed for constant color. */ +extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */ +extern struct GlobalsUboStorage ts; /* draw_common.c */ + +/* Custom shaders : + * Add sources to source/blender/draw/modes/shaders + * init in EDIT_METABALL_engine_init(); + * free in EDIT_METABALL_engine_free(); */ +static struct GPUShader *custom_shader = NULL; + +/* This keeps the reference of the viewport engine data because + * DRW_viewport_engine_data_get is slow and we don't want to + * call it for every object */ +static EDIT_METABALL_Data *vedata; + +/* *********** FUNCTIONS *********** */ + +/* Init Textures, Framebuffers, Storage and Shaders. + * It is called for every frames. + * (Optionnal) */ +static void EDIT_METABALL_engine_init(void) +{ + EDIT_METABALL_Data *vedata = DRW_viewport_engine_data_get("EditMetaballMode"); + EDIT_METABALL_TextureList *txl = vedata->txl; + EDIT_METABALL_FramebufferList *fbl = vedata->fbl; + EDIT_METABALL_StorageList *stl = vedata->stl; + + /* Init Framebuffers like this: order is attachment order (for color texs) */ + /* + * DRWFboTexture tex[2] = {{&txl->depth, DRW_BUF_DEPTH_24}, + * {&txl->color, DRW_BUF_RGBA_8}}; + */ + + /* DRW_framebuffer_init takes care of checking if + * the framebuffer is valid and has the right size*/ + /* + * float *viewport_size = DRW_viewport_size_get(); + * DRW_framebuffer_init(&fbl->occlude_wire_fb, + * (int)viewport_size[0], (int)viewport_size[1], + * tex, 2); + */ + + if (!custom_shader) { + custom_shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR); + } +} + +/* Here init all passes and shading groups + * Assume that all Passes are NULL */ +static void EDIT_METABALL_cache_init(void) +{ + vedata = DRW_viewport_engine_data_get("EditMetaballMode"); + EDIT_METABALL_PassList *psl = vedata->psl; + EDIT_METABALL_StorageList *stl = vedata->stl; + + { + /* Create a pass */ + DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND | DRW_STATE_WIRE; + psl->pass = DRW_pass_create("My Pass", state); + + /* Create a shadingGroup using a function in draw_common.c or custom one */ + /* + * group = shgroup_dynlines_uniform_color(psl->pass, ts.colorWire); + * -- or -- + * group = DRW_shgroup_create(custom_shader, psl->pass); + */ + group = DRW_shgroup_create(custom_shader, psl->pass); + + /* Uniforms need a pointer to it's value so be sure it's accessible at + * any given time (i.e. use static vars) */ + static float color[4] = {0.0f, 1.0f, 0.0f, 1.0}; + DRW_shgroup_uniform_vec4(group, "color", color, 1); + } + +} + +/* Add geometry to shadingGroups. Execute for each objects */ +static void EDIT_METABALL_cache_populate(Object *ob) +{ + EDIT_METABALL_PassList *psl = vedata->psl; + EDIT_METABALL_StorageList *stl = vedata->stl; + + if (ob->type == OB_MESH) { + /* Get geometry cache */ + struct Batch *geom = DRW_cache_surface_get(ob); + + /* Add geom to a shading group */ + DRW_shgroup_call_add(group, geom, ob->obmat); + } +} + +/* Optionnal : Post-cache_populate callback */ +static void EDIT_METABALL_cache_finish(void) +{ + EDIT_METABALL_PassList *psl = vedata->psl; + EDIT_METABALL_StorageList *stl = vedata->stl; + + /* Do something here! dependant on the objects gathered */ +} + +/* Draw time ! Control rendering pipeline from here */ +static void EDIT_METABALL_draw_scene(void) +{ + EDIT_METABALL_Data *ved = DRW_viewport_engine_data_get("EditMetaballMode"); + EDIT_METABALL_PassList *psl = ved->psl; + EDIT_METABALL_FramebufferList *fbl = vedata->fbl; + + /* Default framebuffer and texture */ + DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get(); + DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); + + /* Show / hide entire passes, swap framebuffers ... whatever you fancy */ + /* + * DRW_framebuffer_texture_detach(dtxl->depth); + * DRW_framebuffer_bind(fbl->custom_fb); + * DRW_draw_pass(psl->pass); + * DRW_framebuffer_texture_attach(dfbl->default_fb, dtxl->depth, 0); + * DRW_framebuffer_bind(dfbl->default_fb); + */ + + /* ... or just render passes on default framebuffer. */ + DRW_draw_pass(psl->pass); + + /* If you changed framebuffer, double check you rebind + * the default one with its textures attached before finishing */ +} + +/* Cleanup when destroying the engine. + * This is not per viewport ! only when quitting blender. + * Mostly used for freeing shaders */ +static void EDIT_METABALL_engine_free(void) +{ + // if (custom_shader) + // DRW_shader_free(custom_shader); +} + +/* Create collection settings here. + * + * Be sure to add this function there : + * source/blender/draw/DRW_engine.h + * source/blender/blenkernel/intern/layer.c + * source/blenderplayer/bad_level_call_stubs/stubs.c + * + * And relevant collection settings to : + * source/blender/makesrna/intern/rna_scene.c + * source/blender/blenkernel/intern/layer.c + */ +void EDIT_METABALL_collection_settings_create(CollectionEngineSettings *ces) +{ + BLI_assert(ces); + // BKE_collection_engine_property_add_int(ces, "my_bool_prop", false); + // BKE_collection_engine_property_add_int(ces, "my_int_prop", 0); + // BKE_collection_engine_property_add_float(ces, "my_float_prop", 0.0f); +} + +DrawEngineType draw_engine_edit_metaball_type = { + NULL, NULL, + N_("EditMetaballMode"), + &EDIT_METABALL_engine_init, + &EDIT_METABALL_engine_free, + &EDIT_METABALL_cache_init, + &EDIT_METABALL_cache_populate, + &EDIT_METABALL_cache_finish, + NULL, /* draw_background but not needed by mode engines */ + &EDIT_METABALL_draw_scene +}; diff --git a/source/blender/draw/modes/edit_surface_mode.c b/source/blender/draw/modes/edit_surface_mode.c new file mode 100644 index 00000000000..e320a7c8b36 --- /dev/null +++ b/source/blender/draw/modes/edit_surface_mode.c @@ -0,0 +1,259 @@ +/* + * Copyright 2016, Blender Foundation. + * + * 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. + * + * Contributor(s): Blender Institute + * + */ + +/** \file blender/draw/modes/edit_surface_mode.c + * \ingroup draw + */ + +#include "DRW_engine.h" +#include "DRW_render.h" + +/* If builtin shaders are needed */ +#include "GPU_shader.h" + +#include "draw_common.h" + +#include "draw_mode_engines.h" + +/* *********** LISTS *********** */ +/* All lists are per viewport specific datas. + * They are all free when viewport changes engines + * or is free itself. Use EDIT_SURFACE_engine_init() to + * initialize most of them and EDIT_SURFACE_cache_init() + * for EDIT_SURFACE_PassList */ + +/* keep it under MAX_PASSES */ +typedef struct EDIT_SURFACE_PassList { + /* Declare all passes here and init them in + * EDIT_SURFACE_cache_init(). + * Only contains (DRWPass *) */ + struct DRWPass *pass; +} EDIT_SURFACE_PassList; + +/* keep it under MAX_BUFFERS */ +typedef struct EDIT_SURFACE_FramebufferList { + /* Contains all framebuffer objects needed by this engine. + * Only contains (GPUFrameBuffer *) */ + // struct GPUFrameBuffer *fb; +} EDIT_SURFACE_FramebufferList; + +/* keep it under MAX_TEXTURES */ +typedef struct EDIT_SURFACE_TextureList { + /* Contains all framebuffer textures / utility textures + * needed by this engine. Only viewport specific textures + * (not per object). Only contains (GPUTexture *) */ + // struct GPUTexture *texture; +} EDIT_SURFACE_TextureList; + +/* keep it under MAX_STORAGE */ +typedef struct EDIT_SURFACE_StorageList { + /* Contains any other memory block that the engine needs. + * Only directly MEM_(m/c)allocN'ed blocks because they are + * free with MEM_freeN() when viewport is freed. + * (not per object) */ + // struct CustomStruct *block; +} EDIT_SURFACE_StorageList; + +typedef struct EDIT_SURFACE_Data { + /* Struct returned by DRW_viewport_engine_data_get. + * If you don't use one of these, just make it a (void *) */ + // void *fbl; + char engine_name[32]; /* Required */ + EDIT_SURFACE_FramebufferList *fbl; + EDIT_SURFACE_TextureList *txl; + EDIT_SURFACE_PassList *psl; + EDIT_SURFACE_StorageList *stl; +} EDIT_SURFACE_Data; + +/* *********** STATIC *********** */ + +/* This keeps the references of the shading groups for + * easy access in EDIT_SURFACE_cache_populate() */ +static DRWShadingGroup *group; + +/* If needed, contains all global/Theme colors + * Add needed theme colors / values to DRW_globals_update() and update UBO + * Not needed for constant color. */ +extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */ +extern struct GlobalsUboStorage ts; /* draw_common.c */ + +/* Custom shaders : + * Add sources to source/blender/draw/modes/shaders + * init in EDIT_SURFACE_engine_init(); + * free in EDIT_SURFACE_engine_free(); */ +static struct GPUShader *custom_shader = NULL; + +/* This keeps the reference of the viewport engine data because + * DRW_viewport_engine_data_get is slow and we don't want to + * call it for every object */ +static EDIT_SURFACE_Data *vedata; + +/* *********** FUNCTIONS *********** */ + +/* Init Textures, Framebuffers, Storage and Shaders. + * It is called for every frames. + * (Optionnal) */ +static void EDIT_SURFACE_engine_init(void) +{ + EDIT_SURFACE_Data *vedata = DRW_viewport_engine_data_get("EditSurfaceMode"); + EDIT_SURFACE_TextureList *txl = vedata->txl; + EDIT_SURFACE_FramebufferList *fbl = vedata->fbl; + EDIT_SURFACE_StorageList *stl = vedata->stl; + + /* Init Framebuffers like this: order is attachment order (for color texs) */ + /* + * DRWFboTexture tex[2] = {{&txl->depth, DRW_BUF_DEPTH_24}, + * {&txl->color, DRW_BUF_RGBA_8}}; + */ + + /* DRW_framebuffer_init takes care of checking if + * the framebuffer is valid and has the right size*/ + /* + * float *viewport_size = DRW_viewport_size_get(); + * DRW_framebuffer_init(&fbl->occlude_wire_fb, + * (int)viewport_size[0], (int)viewport_size[1], + * tex, 2); + */ + + if (!custom_shader) { + custom_shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR); + } +} + +/* Here init all passes and shading groups + * Assume that all Passes are NULL */ +static void EDIT_SURFACE_cache_init(void) +{ + vedata = DRW_viewport_engine_data_get("EditSurfaceMode"); + EDIT_SURFACE_PassList *psl = vedata->psl; + EDIT_SURFACE_StorageList *stl = vedata->stl; + + { + /* Create a pass */ + DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND | DRW_STATE_WIRE; + psl->pass = DRW_pass_create("My Pass", state); + + /* Create a shadingGroup using a function in draw_common.c or custom one */ + /* + * group = shgroup_dynlines_uniform_color(psl->pass, ts.colorWire); + * -- or -- + * group = DRW_shgroup_create(custom_shader, psl->pass); + */ + group = DRW_shgroup_create(custom_shader, psl->pass); + + /* Uniforms need a pointer to it's value so be sure it's accessible at + * any given time (i.e. use static vars) */ + static float color[4] = {0.0f, 0.0f, 1.0f, 1.0}; + DRW_shgroup_uniform_vec4(group, "color", color, 1); + } + +} + +/* Add geometry to shadingGroups. Execute for each objects */ +static void EDIT_SURFACE_cache_populate(Object *ob) +{ + EDIT_SURFACE_PassList *psl = vedata->psl; + EDIT_SURFACE_StorageList *stl = vedata->stl; + + if (ob->type == OB_MESH) { + /* Get geometry cache */ + struct Batch *geom = DRW_cache_surface_get(ob); + + /* Add geom to a shading group */ + DRW_shgroup_call_add(group, geom, ob->obmat); + } +} + +/* Optionnal : Post-cache_populate callback */ +static void EDIT_SURFACE_cache_finish(void) +{ + EDIT_SURFACE_PassList *psl = vedata->psl; + EDIT_SURFACE_StorageList *stl = vedata->stl; + + /* Do something here! dependant on the objects gathered */ +} + +/* Draw time ! Control rendering pipeline from here */ +static void EDIT_SURFACE_draw_scene(void) +{ + EDIT_SURFACE_Data *ved = DRW_viewport_engine_data_get("EditSurfaceMode"); + EDIT_SURFACE_PassList *psl = ved->psl; + EDIT_SURFACE_FramebufferList *fbl = vedata->fbl; + + /* Default framebuffer and texture */ + DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get(); + DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); + + /* Show / hide entire passes, swap framebuffers ... whatever you fancy */ + /* + * DRW_framebuffer_texture_detach(dtxl->depth); + * DRW_framebuffer_bind(fbl->custom_fb); + * DRW_draw_pass(psl->pass); + * DRW_framebuffer_texture_attach(dfbl->default_fb, dtxl->depth, 0); + * DRW_framebuffer_bind(dfbl->default_fb); + */ + + /* ... or just render passes on default framebuffer. */ + DRW_draw_pass(psl->pass); + + /* If you changed framebuffer, double check you rebind + * the default one with its textures attached before finishing */ +} + +/* Cleanup when destroying the engine. + * This is not per viewport ! only when quitting blender. + * Mostly used for freeing shaders */ +static void EDIT_SURFACE_engine_free(void) +{ + // if (custom_shader) + // DRW_shader_free(custom_shader); +} + +/* Create collection settings here. + * + * Be sure to add this function there : + * source/blender/draw/DRW_engine.h + * source/blender/blenkernel/intern/layer.c + * source/blenderplayer/bad_level_call_stubs/stubs.c + * + * And relevant collection settings to : + * source/blender/makesrna/intern/rna_scene.c + * source/blender/blenkernel/intern/layer.c + */ +void EDIT_SURFACE_collection_settings_create(CollectionEngineSettings *ces) +{ + BLI_assert(ces); + // BKE_collection_engine_property_add_int(ces, "my_bool_prop", false); + // BKE_collection_engine_property_add_int(ces, "my_int_prop", 0); + // BKE_collection_engine_property_add_float(ces, "my_float_prop", 0.0f); +} + +DrawEngineType draw_engine_edit_surface_type = { + NULL, NULL, + N_("EditSurfaceMode"), + &EDIT_SURFACE_engine_init, + &EDIT_SURFACE_engine_free, + &EDIT_SURFACE_cache_init, + &EDIT_SURFACE_cache_populate, + &EDIT_SURFACE_cache_finish, + NULL, /* draw_background but not needed by mode engines */ + &EDIT_SURFACE_draw_scene +}; diff --git a/source/blender/draw/modes/edit_text_mode.c b/source/blender/draw/modes/edit_text_mode.c new file mode 100644 index 00000000000..13e8744a339 --- /dev/null +++ b/source/blender/draw/modes/edit_text_mode.c @@ -0,0 +1,259 @@ +/* + * Copyright 2016, Blender Foundation. + * + * 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. + * + * Contributor(s): Blender Institute + * + */ + +/** \file blender/draw/modes/edit_text_mode.c + * \ingroup draw + */ + +#include "DRW_engine.h" +#include "DRW_render.h" + +/* If builtin shaders are needed */ +#include "GPU_shader.h" + +#include "draw_common.h" + +#include "draw_mode_engines.h" + +/* *********** LISTS *********** */ +/* All lists are per viewport specific datas. + * They are all free when viewport changes engines + * or is free itself. Use EDIT_TEXT_engine_init() to + * initialize most of them and EDIT_TEXT_cache_init() + * for EDIT_TEXT_PassList */ + +/* keep it under MAX_PASSES */ +typedef struct EDIT_TEXT_PassList { + /* Declare all passes here and init them in + * EDIT_TEXT_cache_init(). + * Only contains (DRWPass *) */ + struct DRWPass *pass; +} EDIT_TEXT_PassList; + +/* keep it under MAX_BUFFERS */ +typedef struct EDIT_TEXT_FramebufferList { + /* Contains all framebuffer objects needed by this engine. + * Only contains (GPUFrameBuffer *) */ + // struct GPUFrameBuffer *fb; +} EDIT_TEXT_FramebufferList; + +/* keep it under MAX_TEXTURES */ +typedef struct EDIT_TEXT_TextureList { + /* Contains all framebuffer textures / utility textures + * needed by this engine. Only viewport specific textures + * (not per object). Only contains (GPUTexture *) */ + // struct GPUTexture *texture; +} EDIT_TEXT_TextureList; + +/* keep it under MAX_STORAGE */ +typedef struct EDIT_TEXT_StorageList { + /* Contains any other memory block that the engine needs. + * Only directly MEM_(m/c)allocN'ed blocks because they are + * free with MEM_freeN() when viewport is freed. + * (not per object) */ + // struct CustomStruct *block; +} EDIT_TEXT_StorageList; + +typedef struct EDIT_TEXT_Data { + /* Struct returned by DRW_viewport_engine_data_get. + * If you don't use one of these, just make it a (void *) */ + // void *fbl; + char engine_name[32]; /* Required */ + EDIT_TEXT_FramebufferList *fbl; + EDIT_TEXT_TextureList *txl; + EDIT_TEXT_PassList *psl; + EDIT_TEXT_StorageList *stl; +} EDIT_TEXT_Data; + +/* *********** STATIC *********** */ + +/* This keeps the references of the shading groups for + * easy access in EDIT_TEXT_cache_populate() */ +static DRWShadingGroup *group; + +/* If needed, contains all global/Theme colors + * Add needed theme colors / values to DRW_globals_update() and update UBO + * Not needed for constant color. */ +extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */ +extern struct GlobalsUboStorage ts; /* draw_common.c */ + +/* Custom shaders : + * Add sources to source/blender/draw/modes/shaders + * init in EDIT_TEXT_engine_init(); + * free in EDIT_TEXT_engine_free(); */ +static struct GPUShader *custom_shader = NULL; + +/* This keeps the reference of the viewport engine data because + * DRW_viewport_engine_data_get is slow and we don't want to + * call it for every object */ +static EDIT_TEXT_Data *vedata; + +/* *********** FUNCTIONS *********** */ + +/* Init Textures, Framebuffers, Storage and Shaders. + * It is called for every frames. + * (Optionnal) */ +static void EDIT_TEXT_engine_init(void) +{ + EDIT_TEXT_Data *vedata = DRW_viewport_engine_data_get("EditTextMode"); + EDIT_TEXT_TextureList *txl = vedata->txl; + EDIT_TEXT_FramebufferList *fbl = vedata->fbl; + EDIT_TEXT_StorageList *stl = vedata->stl; + + /* Init Framebuffers like this: order is attachment order (for color texs) */ + /* + * DRWFboTexture tex[2] = {{&txl->depth, DRW_BUF_DEPTH_24}, + * {&txl->color, DRW_BUF_RGBA_8}}; + */ + + /* DRW_framebuffer_init takes care of checking if + * the framebuffer is valid and has the right size*/ + /* + * float *viewport_size = DRW_viewport_size_get(); + * DRW_framebuffer_init(&fbl->occlude_wire_fb, + * (int)viewport_size[0], (int)viewport_size[1], + * tex, 2); + */ + + if (!custom_shader) { + custom_shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR); + } +} + +/* Here init all passes and shading groups + * Assume that all Passes are NULL */ +static void EDIT_TEXT_cache_init(void) +{ + vedata = DRW_viewport_engine_data_get("EditTextMode"); + EDIT_TEXT_PassList *psl = vedata->psl; + EDIT_TEXT_StorageList *stl = vedata->stl; + + { + /* Create a pass */ + DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND | DRW_STATE_WIRE; + psl->pass = DRW_pass_create("My Pass", state); + + /* Create a shadingGroup using a function in draw_common.c or custom one */ + /* + * group = shgroup_dynlines_uniform_color(psl->pass, ts.colorWire); + * -- or -- + * group = DRW_shgroup_create(custom_shader, psl->pass); + */ + group = DRW_shgroup_create(custom_shader, psl->pass); + + /* Uniforms need a pointer to it's value so be sure it's accessible at + * any given time (i.e. use static vars) */ + static float color[4] = {1.0f, 0.0f, 0.0f, 1.0}; + DRW_shgroup_uniform_vec4(group, "color", color, 1); + } + +} + +/* Add geometry to shadingGroups. Execute for each objects */ +static void EDIT_TEXT_cache_populate(Object *ob) +{ + EDIT_TEXT_PassList *psl = vedata->psl; + EDIT_TEXT_StorageList *stl = vedata->stl; + + if (ob->type == OB_MESH) { + /* Get geometry cache */ + struct Batch *geom = DRW_cache_surface_get(ob); + + /* Add geom to a shading group */ + DRW_shgroup_call_add(group, geom, ob->obmat); + } +} + +/* Optionnal : Post-cache_populate callback */ +static void EDIT_TEXT_cache_finish(void) +{ + EDIT_TEXT_PassList *psl = vedata->psl; + EDIT_TEXT_StorageList *stl = vedata->stl; + + /* Do something here! dependant on the objects gathered */ +} + +/* Draw time ! Control rendering pipeline from here */ +static void EDIT_TEXT_draw_scene(void) +{ + EDIT_TEXT_Data *ved = DRW_viewport_engine_data_get("EditTextMode"); + EDIT_TEXT_PassList *psl = ved->psl; + EDIT_TEXT_FramebufferList *fbl = vedata->fbl; + + /* Default framebuffer and texture */ + DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get(); + DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); + + /* Show / hide entire passes, swap framebuffers ... whatever you fancy */ + /* + * DRW_framebuffer_texture_detach(dtxl->depth); + * DRW_framebuffer_bind(fbl->custom_fb); + * DRW_draw_pass(psl->pass); + * DRW_framebuffer_texture_attach(dfbl->default_fb, dtxl->depth, 0); + * DRW_framebuffer_bind(dfbl->default_fb); + */ + + /* ... or just render passes on default framebuffer. */ + DRW_draw_pass(psl->pass); + + /* If you changed framebuffer, double check you rebind + * the default one with its textures attached before finishing */ +} + +/* Cleanup when destroying the engine. + * This is not per viewport ! only when quitting blender. + * Mostly used for freeing shaders */ +static void EDIT_TEXT_engine_free(void) +{ + // if (custom_shader) + // DRW_shader_free(custom_shader); +} + +/* Create collection settings here. + * + * Be sure to add this function there : + * source/blender/draw/DRW_engine.h + * source/blender/blenkernel/intern/layer.c + * source/blenderplayer/bad_level_call_stubs/stubs.c + * + * And relevant collection settings to : + * source/blender/makesrna/intern/rna_scene.c + * source/blender/blenkernel/intern/layer.c + */ +void EDIT_TEXT_collection_settings_create(CollectionEngineSettings *ces) +{ + BLI_assert(ces); + // BKE_collection_engine_property_add_int(ces, "my_bool_prop", false); + // BKE_collection_engine_property_add_int(ces, "my_int_prop", 0); + // BKE_collection_engine_property_add_float(ces, "my_float_prop", 0.0f); +} + +DrawEngineType draw_engine_edit_text_type = { + NULL, NULL, + N_("EditTextMode"), + &EDIT_TEXT_engine_init, + &EDIT_TEXT_engine_free, + &EDIT_TEXT_cache_init, + &EDIT_TEXT_cache_populate, + &EDIT_TEXT_cache_finish, + NULL, /* draw_background but not needed by mode engines */ + &EDIT_TEXT_draw_scene +}; diff --git a/source/blender/draw/modes/paint_texture_mode.c b/source/blender/draw/modes/paint_texture_mode.c new file mode 100644 index 00000000000..99046fe2c1c --- /dev/null +++ b/source/blender/draw/modes/paint_texture_mode.c @@ -0,0 +1,259 @@ +/* + * Copyright 2016, Blender Foundation. + * + * 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. + * + * Contributor(s): Blender Institute + * + */ + +/** \file blender/draw/modes/paint_texture_mode.c + * \ingroup draw + */ + +#include "DRW_engine.h" +#include "DRW_render.h" + +/* If builtin shaders are needed */ +#include "GPU_shader.h" + +#include "draw_common.h" + +#include "draw_mode_engines.h" + +/* *********** LISTS *********** */ +/* All lists are per viewport specific datas. + * They are all free when viewport changes engines + * or is free itself. Use PAINT_TEXTURE_engine_init() to + * initialize most of them and PAINT_TEXTURE_cache_init() + * for PAINT_TEXTURE_PassList */ + +/* keep it under MAX_PASSES */ +typedef struct PAINT_TEXTURE_PassList { + /* Declare all passes here and init them in + * PAINT_TEXTURE_cache_init(). + * Only contains (DRWPass *) */ + struct DRWPass *pass; +} PAINT_TEXTURE_PassList; + +/* keep it under MAX_BUFFERS */ +typedef struct PAINT_TEXTURE_FramebufferList { + /* Contains all framebuffer objects needed by this engine. + * Only contains (GPUFrameBuffer *) */ + // struct GPUFrameBuffer *fb; +} PAINT_TEXTURE_FramebufferList; + +/* keep it under MAX_TEXTURES */ +typedef struct PAINT_TEXTURE_TextureList { + /* Contains all framebuffer textures / utility textures + * needed by this engine. Only viewport specific textures + * (not per object). Only contains (GPUTexture *) */ + // struct GPUTexture *texture; +} PAINT_TEXTURE_TextureList; + +/* keep it under MAX_STORAGE */ +typedef struct PAINT_TEXTURE_StorageList { + /* Contains any other memory block that the engine needs. + * Only directly MEM_(m/c)allocN'ed blocks because they are + * free with MEM_freeN() when viewport is freed. + * (not per object) */ + // struct CustomStruct *block; +} PAINT_TEXTURE_StorageList; + +typedef struct PAINT_TEXTURE_Data { + /* Struct returned by DRW_viewport_engine_data_get. + * If you don't use one of these, just make it a (void *) */ + // void *fbl; + char engine_name[32]; /* Required */ + PAINT_TEXTURE_FramebufferList *fbl; + PAINT_TEXTURE_TextureList *txl; + PAINT_TEXTURE_PassList *psl; + PAINT_TEXTURE_StorageList *stl; +} PAINT_TEXTURE_Data; + +/* *********** STATIC *********** */ + +/* This keeps the references of the shading groups for + * easy access in PAINT_TEXTURE_cache_populate() */ +static DRWShadingGroup *group; + +/* If needed, contains all global/Theme colors + * Add needed theme colors / values to DRW_globals_update() and update UBO + * Not needed for constant color. */ +extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */ +extern struct GlobalsUboStorage ts; /* draw_common.c */ + +/* Custom shaders : + * Add sources to source/blender/draw/modes/shaders + * init in PAINT_TEXTURE_engine_init(); + * free in PAINT_TEXTURE_engine_free(); */ +static struct GPUShader *custom_shader = NULL; + +/* This keeps the reference of the viewport engine data because + * DRW_viewport_engine_data_get is slow and we don't want to + * call it for every object */ +static PAINT_TEXTURE_Data *vedata; + +/* *********** FUNCTIONS *********** */ + +/* Init Textures, Framebuffers, Storage and Shaders. + * It is called for every frames. + * (Optionnal) */ +static void PAINT_TEXTURE_engine_init(void) +{ + PAINT_TEXTURE_Data *vedata = DRW_viewport_engine_data_get("PaintTextureMode"); + PAINT_TEXTURE_TextureList *txl = vedata->txl; + PAINT_TEXTURE_FramebufferList *fbl = vedata->fbl; + PAINT_TEXTURE_StorageList *stl = vedata->stl; + + /* Init Framebuffers like this: order is attachment order (for color texs) */ + /* + * DRWFboTexture tex[2] = {{&txl->depth, DRW_BUF_DEPTH_24}, + * {&txl->color, DRW_BUF_RGBA_8}}; + */ + + /* DRW_framebuffer_init takes care of checking if + * the framebuffer is valid and has the right size*/ + /* + * float *viewport_size = DRW_viewport_size_get(); + * DRW_framebuffer_init(&fbl->occlude_wire_fb, + * (int)viewport_size[0], (int)viewport_size[1], + * tex, 2); + */ + + if (!custom_shader) { + custom_shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR); + } +} + +/* Here init all passes and shading groups + * Assume that all Passes are NULL */ +static void PAINT_TEXTURE_cache_init(void) +{ + vedata = DRW_viewport_engine_data_get("PaintTextureMode"); + PAINT_TEXTURE_PassList *psl = vedata->psl; + PAINT_TEXTURE_StorageList *stl = vedata->stl; + + { + /* Create a pass */ + DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND | DRW_STATE_WIRE; + psl->pass = DRW_pass_create("My Pass", state); + + /* Create a shadingGroup using a function in draw_common.c or custom one */ + /* + * group = shgroup_dynlines_uniform_color(psl->pass, ts.colorWire); + * -- or -- + * group = DRW_shgroup_create(custom_shader, psl->pass); + */ + group = DRW_shgroup_create(custom_shader, psl->pass); + + /* Uniforms need a pointer to it's value so be sure it's accessible at + * any given time (i.e. use static vars) */ + static float color[4] = {0.2f, 0.5f, 0.3f, 1.0}; + DRW_shgroup_uniform_vec4(group, "color", color, 1); + } + +} + +/* Add geometry to shadingGroups. Execute for each objects */ +static void PAINT_TEXTURE_cache_populate(Object *ob) +{ + PAINT_TEXTURE_PassList *psl = vedata->psl; + PAINT_TEXTURE_StorageList *stl = vedata->stl; + + if (ob->type == OB_MESH) { + /* Get geometry cache */ + struct Batch *geom = DRW_cache_surface_get(ob); + + /* Add geom to a shading group */ + DRW_shgroup_call_add(group, geom, ob->obmat); + } +} + +/* Optionnal : Post-cache_populate callback */ +static void PAINT_TEXTURE_cache_finish(void) +{ + PAINT_TEXTURE_PassList *psl = vedata->psl; + PAINT_TEXTURE_StorageList *stl = vedata->stl; + + /* Do something here! dependant on the objects gathered */ +} + +/* Draw time ! Control rendering pipeline from here */ +static void PAINT_TEXTURE_draw_scene(void) +{ + PAINT_TEXTURE_Data *ved = DRW_viewport_engine_data_get("PaintTextureMode"); + PAINT_TEXTURE_PassList *psl = ved->psl; + PAINT_TEXTURE_FramebufferList *fbl = vedata->fbl; + + /* Default framebuffer and texture */ + DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get(); + DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); + + /* Show / hide entire passes, swap framebuffers ... whatever you fancy */ + /* + * DRW_framebuffer_texture_detach(dtxl->depth); + * DRW_framebuffer_bind(fbl->custom_fb); + * DRW_draw_pass(psl->pass); + * DRW_framebuffer_texture_attach(dfbl->default_fb, dtxl->depth, 0); + * DRW_framebuffer_bind(dfbl->default_fb); + */ + + /* ... or just render passes on default framebuffer. */ + DRW_draw_pass(psl->pass); + + /* If you changed framebuffer, double check you rebind + * the default one with its textures attached before finishing */ +} + +/* Cleanup when destroying the engine. + * This is not per viewport ! only when quitting blender. + * Mostly used for freeing shaders */ +static void PAINT_TEXTURE_engine_free(void) +{ + // if (custom_shader) + // DRW_shader_free(custom_shader); +} + +/* Create collection settings here. + * + * Be sure to add this function there : + * source/blender/draw/DRW_engine.h + * source/blender/blenkernel/intern/layer.c + * source/blenderplayer/bad_level_call_stubs/stubs.c + * + * And relevant collection settings to : + * source/blender/makesrna/intern/rna_scene.c + * source/blender/blenkernel/intern/layer.c + */ +void PAINT_TEXTURE_collection_settings_create(CollectionEngineSettings *ces) +{ + BLI_assert(ces); + // BKE_collection_engine_property_add_int(ces, "my_bool_prop", false); + // BKE_collection_engine_property_add_int(ces, "my_int_prop", 0); + // BKE_collection_engine_property_add_float(ces, "my_float_prop", 0.0f); +} + +DrawEngineType draw_engine_paint_texture_type = { + NULL, NULL, + N_("PaintTextureMode"), + &PAINT_TEXTURE_engine_init, + &PAINT_TEXTURE_engine_free, + &PAINT_TEXTURE_cache_init, + &PAINT_TEXTURE_cache_populate, + &PAINT_TEXTURE_cache_finish, + NULL, /* draw_background but not needed by mode engines */ + &PAINT_TEXTURE_draw_scene +}; diff --git a/source/blender/draw/modes/paint_vertex_mode.c b/source/blender/draw/modes/paint_vertex_mode.c new file mode 100644 index 00000000000..051ee48ec10 --- /dev/null +++ b/source/blender/draw/modes/paint_vertex_mode.c @@ -0,0 +1,259 @@ +/* + * Copyright 2016, Blender Foundation. + * + * 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. + * + * Contributor(s): Blender Institute + * + */ + +/** \file blender/draw/modes/paint_vertex_mode.c + * \ingroup draw + */ + +#include "DRW_engine.h" +#include "DRW_render.h" + +/* If builtin shaders are needed */ +#include "GPU_shader.h" + +#include "draw_common.h" + +#include "draw_mode_engines.h" + +/* *********** LISTS *********** */ +/* All lists are per viewport specific datas. + * They are all free when viewport changes engines + * or is free itself. Use PAINT_VERTEX_engine_init() to + * initialize most of them and PAINT_VERTEX_cache_init() + * for PAINT_VERTEX_PassList */ + +/* keep it under MAX_PASSES */ +typedef struct PAINT_VERTEX_PassList { + /* Declare all passes here and init them in + * PAINT_VERTEX_cache_init(). + * Only contains (DRWPass *) */ + struct DRWPass *pass; +} PAINT_VERTEX_PassList; + +/* keep it under MAX_BUFFERS */ +typedef struct PAINT_VERTEX_FramebufferList { + /* Contains all framebuffer objects needed by this engine. + * Only contains (GPUFrameBuffer *) */ + // struct GPUFrameBuffer *fb; +} PAINT_VERTEX_FramebufferList; + +/* keep it under MAX_TEXTURES */ +typedef struct PAINT_VERTEX_TextureList { + /* Contains all framebuffer textures / utility textures + * needed by this engine. Only viewport specific textures + * (not per object). Only contains (GPUTexture *) */ + // struct GPUTexture *texture; +} PAINT_VERTEX_TextureList; + +/* keep it under MAX_STORAGE */ +typedef struct PAINT_VERTEX_StorageList { + /* Contains any other memory block that the engine needs. + * Only directly MEM_(m/c)allocN'ed blocks because they are + * free with MEM_freeN() when viewport is freed. + * (not per object) */ + // struct CustomStruct *block; +} PAINT_VERTEX_StorageList; + +typedef struct PAINT_VERTEX_Data { + /* Struct returned by DRW_viewport_engine_data_get. + * If you don't use one of these, just make it a (void *) */ + // void *fbl; + char engine_name[32]; /* Required */ + PAINT_VERTEX_FramebufferList *fbl; + PAINT_VERTEX_TextureList *txl; + PAINT_VERTEX_PassList *psl; + PAINT_VERTEX_StorageList *stl; +} PAINT_VERTEX_Data; + +/* *********** STATIC *********** */ + +/* This keeps the references of the shading groups for + * easy access in PAINT_VERTEX_cache_populate() */ +static DRWShadingGroup *group; + +/* If needed, contains all global/Theme colors + * Add needed theme colors / values to DRW_globals_update() and update UBO + * Not needed for constant color. */ +extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */ +extern struct GlobalsUboStorage ts; /* draw_common.c */ + +/* Custom shaders : + * Add sources to source/blender/draw/modes/shaders + * init in PAINT_VERTEX_engine_init(); + * free in PAINT_VERTEX_engine_free(); */ +static struct GPUShader *custom_shader = NULL; + +/* This keeps the reference of the viewport engine data because + * DRW_viewport_engine_data_get is slow and we don't want to + * call it for every object */ +static PAINT_VERTEX_Data *vedata; + +/* *********** FUNCTIONS *********** */ + +/* Init Textures, Framebuffers, Storage and Shaders. + * It is called for every frames. + * (Optionnal) */ +static void PAINT_VERTEX_engine_init(void) +{ + PAINT_VERTEX_Data *vedata = DRW_viewport_engine_data_get("PaintVertexMode"); + PAINT_VERTEX_TextureList *txl = vedata->txl; + PAINT_VERTEX_FramebufferList *fbl = vedata->fbl; + PAINT_VERTEX_StorageList *stl = vedata->stl; + + /* Init Framebuffers like this: order is attachment order (for color texs) */ + /* + * DRWFboTexture tex[2] = {{&txl->depth, DRW_BUF_DEPTH_24}, + * {&txl->color, DRW_BUF_RGBA_8}}; + */ + + /* DRW_framebuffer_init takes care of checking if + * the framebuffer is valid and has the right size*/ + /* + * float *viewport_size = DRW_viewport_size_get(); + * DRW_framebuffer_init(&fbl->occlude_wire_fb, + * (int)viewport_size[0], (int)viewport_size[1], + * tex, 2); + */ + + if (!custom_shader) { + custom_shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR); + } +} + +/* Here init all passes and shading groups + * Assume that all Passes are NULL */ +static void PAINT_VERTEX_cache_init(void) +{ + vedata = DRW_viewport_engine_data_get("PaintVertexMode"); + PAINT_VERTEX_PassList *psl = vedata->psl; + PAINT_VERTEX_StorageList *stl = vedata->stl; + + { + /* Create a pass */ + DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND | DRW_STATE_WIRE; + psl->pass = DRW_pass_create("My Pass", state); + + /* Create a shadingGroup using a function in draw_common.c or custom one */ + /* + * group = shgroup_dynlines_uniform_color(psl->pass, ts.colorWire); + * -- or -- + * group = DRW_shgroup_create(custom_shader, psl->pass); + */ + group = DRW_shgroup_create(custom_shader, psl->pass); + + /* Uniforms need a pointer to it's value so be sure it's accessible at + * any given time (i.e. use static vars) */ + static float color[4] = {0.2f, 0.5f, 0.3f, 1.0}; + DRW_shgroup_uniform_vec4(group, "color", color, 1); + } + +} + +/* Add geometry to shadingGroups. Execute for each objects */ +static void PAINT_VERTEX_cache_populate(Object *ob) +{ + PAINT_VERTEX_PassList *psl = vedata->psl; + PAINT_VERTEX_StorageList *stl = vedata->stl; + + if (ob->type == OB_MESH) { + /* Get geometry cache */ + struct Batch *geom = DRW_cache_surface_get(ob); + + /* Add geom to a shading group */ + DRW_shgroup_call_add(group, geom, ob->obmat); + } +} + +/* Optionnal : Post-cache_populate callback */ +static void PAINT_VERTEX_cache_finish(void) +{ + PAINT_VERTEX_PassList *psl = vedata->psl; + PAINT_VERTEX_StorageList *stl = vedata->stl; + + /* Do something here! dependant on the objects gathered */ +} + +/* Draw time ! Control rendering pipeline from here */ +static void PAINT_VERTEX_draw_scene(void) +{ + PAINT_VERTEX_Data *ved = DRW_viewport_engine_data_get("PaintVertexMode"); + PAINT_VERTEX_PassList *psl = ved->psl; + PAINT_VERTEX_FramebufferList *fbl = vedata->fbl; + + /* Default framebuffer and texture */ + DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get(); + DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); + + /* Show / hide entire passes, swap framebuffers ... whatever you fancy */ + /* + * DRW_framebuffer_texture_detach(dtxl->depth); + * DRW_framebuffer_bind(fbl->custom_fb); + * DRW_draw_pass(psl->pass); + * DRW_framebuffer_texture_attach(dfbl->default_fb, dtxl->depth, 0); + * DRW_framebuffer_bind(dfbl->default_fb); + */ + + /* ... or just render passes on default framebuffer. */ + DRW_draw_pass(psl->pass); + + /* If you changed framebuffer, double check you rebind + * the default one with its textures attached before finishing */ +} + +/* Cleanup when destroying the engine. + * This is not per viewport ! only when quitting blender. + * Mostly used for freeing shaders */ +static void PAINT_VERTEX_engine_free(void) +{ + // if (custom_shader) + // DRW_shader_free(custom_shader); +} + +/* Create collection settings here. + * + * Be sure to add this function there : + * source/blender/draw/DRW_engine.h + * source/blender/blenkernel/intern/layer.c + * source/blenderplayer/bad_level_call_stubs/stubs.c + * + * And relevant collection settings to : + * source/blender/makesrna/intern/rna_scene.c + * source/blender/blenkernel/intern/layer.c + */ +void PAINT_VERTEX_collection_settings_create(CollectionEngineSettings *ces) +{ + BLI_assert(ces); + // BKE_collection_engine_property_add_int(ces, "my_bool_prop", false); + // BKE_collection_engine_property_add_int(ces, "my_int_prop", 0); + // BKE_collection_engine_property_add_float(ces, "my_float_prop", 0.0f); +} + +DrawEngineType draw_engine_paint_vertex_type = { + NULL, NULL, + N_("PaintVertexMode"), + &PAINT_VERTEX_engine_init, + &PAINT_VERTEX_engine_free, + &PAINT_VERTEX_cache_init, + &PAINT_VERTEX_cache_populate, + &PAINT_VERTEX_cache_finish, + NULL, /* draw_background but not needed by mode engines */ + &PAINT_VERTEX_draw_scene +}; diff --git a/source/blender/draw/modes/paint_weight_mode.c b/source/blender/draw/modes/paint_weight_mode.c new file mode 100644 index 00000000000..d5cfae88bfe --- /dev/null +++ b/source/blender/draw/modes/paint_weight_mode.c @@ -0,0 +1,259 @@ +/* + * Copyright 2016, Blender Foundation. + * + * 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. + * + * Contributor(s): Blender Institute + * + */ + +/** \file blender/draw/modes/paint_weight_mode.c + * \ingroup draw + */ + +#include "DRW_engine.h" +#include "DRW_render.h" + +/* If builtin shaders are needed */ +#include "GPU_shader.h" + +#include "draw_common.h" + +#include "draw_mode_engines.h" + +/* *********** LISTS *********** */ +/* All lists are per viewport specific datas. + * They are all free when viewport changes engines + * or is free itself. Use PAINT_WEIGHT_engine_init() to + * initialize most of them and PAINT_WEIGHT_cache_init() + * for PAINT_WEIGHT_PassList */ + +/* keep it under MAX_PASSES */ +typedef struct PAINT_WEIGHT_PassList { + /* Declare all passes here and init them in + * PAINT_WEIGHT_cache_init(). + * Only contains (DRWPass *) */ + struct DRWPass *pass; +} PAINT_WEIGHT_PassList; + +/* keep it under MAX_BUFFERS */ +typedef struct PAINT_WEIGHT_FramebufferList { + /* Contains all framebuffer objects needed by this engine. + * Only contains (GPUFrameBuffer *) */ + // struct GPUFrameBuffer *fb; +} PAINT_WEIGHT_FramebufferList; + +/* keep it under MAX_TEXTURES */ +typedef struct PAINT_WEIGHT_TextureList { + /* Contains all framebuffer textures / utility textures + * needed by this engine. Only viewport specific textures + * (not per object). Only contains (GPUTexture *) */ + // struct GPUTexture *texture; +} PAINT_WEIGHT_TextureList; + +/* keep it under MAX_STORAGE */ +typedef struct PAINT_WEIGHT_StorageList { + /* Contains any other memory block that the engine needs. + * Only directly MEM_(m/c)allocN'ed blocks because they are + * free with MEM_freeN() when viewport is freed. + * (not per object) */ + // struct CustomStruct *block; +} PAINT_WEIGHT_StorageList; + +typedef struct PAINT_WEIGHT_Data { + /* Struct returned by DRW_viewport_engine_data_get. + * If you don't use one of these, just make it a (void *) */ + // void *fbl; + char engine_name[32]; /* Required */ + PAINT_WEIGHT_FramebufferList *fbl; + PAINT_WEIGHT_TextureList *txl; + PAINT_WEIGHT_PassList *psl; + PAINT_WEIGHT_StorageList *stl; +} PAINT_WEIGHT_Data; + +/* *********** STATIC *********** */ + +/* This keeps the references of the shading groups for + * easy access in PAINT_WEIGHT_cache_populate() */ +static DRWShadingGroup *group; + +/* If needed, contains all global/Theme colors + * Add needed theme colors / values to DRW_globals_update() and update UBO + * Not needed for constant color. */ +extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */ +extern struct GlobalsUboStorage ts; /* draw_common.c */ + +/* Custom shaders : + * Add sources to source/blender/draw/modes/shaders + * init in PAINT_WEIGHT_engine_init(); + * free in PAINT_WEIGHT_engine_free(); */ +static struct GPUShader *custom_shader = NULL; + +/* This keeps the reference of the viewport engine data because + * DRW_viewport_engine_data_get is slow and we don't want to + * call it for every object */ +static PAINT_WEIGHT_Data *vedata; + +/* *********** FUNCTIONS *********** */ + +/* Init Textures, Framebuffers, Storage and Shaders. + * It is called for every frames. + * (Optionnal) */ +static void PAINT_WEIGHT_engine_init(void) +{ + PAINT_WEIGHT_Data *vedata = DRW_viewport_engine_data_get("PaintWeightMode"); + PAINT_WEIGHT_TextureList *txl = vedata->txl; + PAINT_WEIGHT_FramebufferList *fbl = vedata->fbl; + PAINT_WEIGHT_StorageList *stl = vedata->stl; + + /* Init Framebuffers like this: order is attachment order (for color texs) */ + /* + * DRWFboTexture tex[2] = {{&txl->depth, DRW_BUF_DEPTH_24}, + * {&txl->color, DRW_BUF_RGBA_8}}; + */ + + /* DRW_framebuffer_init takes care of checking if + * the framebuffer is valid and has the right size*/ + /* + * float *viewport_size = DRW_viewport_size_get(); + * DRW_framebuffer_init(&fbl->occlude_wire_fb, + * (int)viewport_size[0], (int)viewport_size[1], + * tex, 2); + */ + + if (!custom_shader) { + custom_shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR); + } +} + +/* Here init all passes and shading groups + * Assume that all Passes are NULL */ +static void PAINT_WEIGHT_cache_init(void) +{ + vedata = DRW_viewport_engine_data_get("PaintWeightMode"); + PAINT_WEIGHT_PassList *psl = vedata->psl; + PAINT_WEIGHT_StorageList *stl = vedata->stl; + + { + /* Create a pass */ + DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND | DRW_STATE_WIRE; + psl->pass = DRW_pass_create("My Pass", state); + + /* Create a shadingGroup using a function in draw_common.c or custom one */ + /* + * group = shgroup_dynlines_uniform_color(psl->pass, ts.colorWire); + * -- or -- + * group = DRW_shgroup_create(custom_shader, psl->pass); + */ + group = DRW_shgroup_create(custom_shader, psl->pass); + + /* Uniforms need a pointer to it's value so be sure it's accessible at + * any given time (i.e. use static vars) */ + static float color[4] = {0.2f, 0.5f, 0.3f, 1.0}; + DRW_shgroup_uniform_vec4(group, "color", color, 1); + } + +} + +/* Add geometry to shadingGroups. Execute for each objects */ +static void PAINT_WEIGHT_cache_populate(Object *ob) +{ + PAINT_WEIGHT_PassList *psl = vedata->psl; + PAINT_WEIGHT_StorageList *stl = vedata->stl; + + if (ob->type == OB_MESH) { + /* Get geometry cache */ + struct Batch *geom = DRW_cache_surface_get(ob); + + /* Add geom to a shading group */ + DRW_shgroup_call_add(group, geom, ob->obmat); + } +} + +/* Optionnal : Post-cache_populate callback */ +static void PAINT_WEIGHT_cache_finish(void) +{ + PAINT_WEIGHT_PassList *psl = vedata->psl; + PAINT_WEIGHT_StorageList *stl = vedata->stl; + + /* Do something here! dependant on the objects gathered */ +} + +/* Draw time ! Control rendering pipeline from here */ +static void PAINT_WEIGHT_draw_scene(void) +{ + PAINT_WEIGHT_Data *ved = DRW_viewport_engine_data_get("PaintWeightMode"); + PAINT_WEIGHT_PassList *psl = ved->psl; + PAINT_WEIGHT_FramebufferList *fbl = vedata->fbl; + + /* Default framebuffer and texture */ + DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get(); + DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); + + /* Show / hide entire passes, swap framebuffers ... whatever you fancy */ + /* + * DRW_framebuffer_texture_detach(dtxl->depth); + * DRW_framebuffer_bind(fbl->custom_fb); + * DRW_draw_pass(psl->pass); + * DRW_framebuffer_texture_attach(dfbl->default_fb, dtxl->depth, 0); + * DRW_framebuffer_bind(dfbl->default_fb); + */ + + /* ... or just render passes on default framebuffer. */ + DRW_draw_pass(psl->pass); + + /* If you changed framebuffer, double check you rebind + * the default one with its textures attached before finishing */ +} + +/* Cleanup when destroying the engine. + * This is not per viewport ! only when quitting blender. + * Mostly used for freeing shaders */ +static void PAINT_WEIGHT_engine_free(void) +{ + // if (custom_shader) + // DRW_shader_free(custom_shader); +} + +/* Create collection settings here. + * + * Be sure to add this function there : + * source/blender/draw/DRW_engine.h + * source/blender/blenkernel/intern/layer.c + * source/blenderplayer/bad_level_call_stubs/stubs.c + * + * And relevant collection settings to : + * source/blender/makesrna/intern/rna_scene.c + * source/blender/blenkernel/intern/layer.c + */ +void PAINT_WEIGHT_collection_settings_create(CollectionEngineSettings *ces) +{ + BLI_assert(ces); + // BKE_collection_engine_property_add_int(ces, "my_bool_prop", false); + // BKE_collection_engine_property_add_int(ces, "my_int_prop", 0); + // BKE_collection_engine_property_add_float(ces, "my_float_prop", 0.0f); +} + +DrawEngineType draw_engine_paint_weight_type = { + NULL, NULL, + N_("PaintWeightMode"), + &PAINT_WEIGHT_engine_init, + &PAINT_WEIGHT_engine_free, + &PAINT_WEIGHT_cache_init, + &PAINT_WEIGHT_cache_populate, + &PAINT_WEIGHT_cache_finish, + NULL, /* draw_background but not needed by mode engines */ + &PAINT_WEIGHT_draw_scene +}; diff --git a/source/blender/draw/modes/particle_mode.c b/source/blender/draw/modes/particle_mode.c new file mode 100644 index 00000000000..98b0e6862e6 --- /dev/null +++ b/source/blender/draw/modes/particle_mode.c @@ -0,0 +1,259 @@ +/* + * Copyright 2016, Blender Foundation. + * + * 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. + * + * Contributor(s): Blender Institute + * + */ + +/** \file blender/draw/modes/particle_mode.c + * \ingroup draw + */ + +#include "DRW_engine.h" +#include "DRW_render.h" + +/* If builtin shaders are needed */ +#include "GPU_shader.h" + +#include "draw_common.h" + +#include "draw_mode_engines.h" + +/* *********** LISTS *********** */ +/* All lists are per viewport specific datas. + * They are all free when viewport changes engines + * or is free itself. Use PARTICLE_engine_init() to + * initialize most of them and PARTICLE_cache_init() + * for PARTICLE_PassList */ + +/* keep it under MAX_PASSES */ +typedef struct PARTICLE_PassList { + /* Declare all passes here and init them in + * PARTICLE_cache_init(). + * Only contains (DRWPass *) */ + struct DRWPass *pass; +} PARTICLE_PassList; + +/* keep it under MAX_BUFFERS */ +typedef struct PARTICLE_FramebufferList { + /* Contains all framebuffer objects needed by this engine. + * Only contains (GPUFrameBuffer *) */ + // struct GPUFrameBuffer *fb; +} PARTICLE_FramebufferList; + +/* keep it under MAX_TEXTURES */ +typedef struct PARTICLE_TextureList { + /* Contains all framebuffer textures / utility textures + * needed by this engine. Only viewport specific textures + * (not per object). Only contains (GPUTexture *) */ + // struct GPUTexture *texture; +} PARTICLE_TextureList; + +/* keep it under MAX_STORAGE */ +typedef struct PARTICLE_StorageList { + /* Contains any other memory block that the engine needs. + * Only directly MEM_(m/c)allocN'ed blocks because they are + * free with MEM_freeN() when viewport is freed. + * (not per object) */ + // struct CustomStruct *block; +} PARTICLE_StorageList; + +typedef struct PARTICLE_Data { + /* Struct returned by DRW_viewport_engine_data_get. + * If you don't use one of these, just make it a (void *) */ + // void *fbl; + char engine_name[32]; /* Required */ + PARTICLE_FramebufferList *fbl; + PARTICLE_TextureList *txl; + PARTICLE_PassList *psl; + PARTICLE_StorageList *stl; +} PARTICLE_Data; + +/* *********** STATIC *********** */ + +/* This keeps the references of the shading groups for + * easy access in PARTICLE_cache_populate() */ +static DRWShadingGroup *group; + +/* If needed, contains all global/Theme colors + * Add needed theme colors / values to DRW_globals_update() and update UBO + * Not needed for constant color. */ +extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */ +extern struct GlobalsUboStorage ts; /* draw_common.c */ + +/* Custom shaders : + * Add sources to source/blender/draw/modes/shaders + * init in PARTICLE_engine_init(); + * free in PARTICLE_engine_free(); */ +static struct GPUShader *custom_shader = NULL; + +/* This keeps the reference of the viewport engine data because + * DRW_viewport_engine_data_get is slow and we don't want to + * call it for every object */ +static PARTICLE_Data *vedata; + +/* *********** FUNCTIONS *********** */ + +/* Init Textures, Framebuffers, Storage and Shaders. + * It is called for every frames. + * (Optionnal) */ +static void PARTICLE_engine_init(void) +{ + PARTICLE_Data *vedata = DRW_viewport_engine_data_get("ParticleMode"); + PARTICLE_TextureList *txl = vedata->txl; + PARTICLE_FramebufferList *fbl = vedata->fbl; + PARTICLE_StorageList *stl = vedata->stl; + + /* Init Framebuffers like this: order is attachment order (for color texs) */ + /* + * DRWFboTexture tex[2] = {{&txl->depth, DRW_BUF_DEPTH_24}, + * {&txl->color, DRW_BUF_RGBA_8}}; + */ + + /* DRW_framebuffer_init takes care of checking if + * the framebuffer is valid and has the right size*/ + /* + * float *viewport_size = DRW_viewport_size_get(); + * DRW_framebuffer_init(&fbl->occlude_wire_fb, + * (int)viewport_size[0], (int)viewport_size[1], + * tex, 2); + */ + + if (!custom_shader) { + custom_shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR); + } +} + +/* Here init all passes and shading groups + * Assume that all Passes are NULL */ +static void PARTICLE_cache_init(void) +{ + vedata = DRW_viewport_engine_data_get("ParticleMode"); + PARTICLE_PassList *psl = vedata->psl; + PARTICLE_StorageList *stl = vedata->stl; + + { + /* Create a pass */ + DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND | DRW_STATE_WIRE; + psl->pass = DRW_pass_create("My Pass", state); + + /* Create a shadingGroup using a function in draw_common.c or custom one */ + /* + * group = shgroup_dynlines_uniform_color(psl->pass, ts.colorWire); + * -- or -- + * group = DRW_shgroup_create(custom_shader, psl->pass); + */ + group = DRW_shgroup_create(custom_shader, psl->pass); + + /* Uniforms need a pointer to it's value so be sure it's accessible at + * any given time (i.e. use static vars) */ + static float color[4] = {0.2f, 0.5f, 0.3f, 1.0}; + DRW_shgroup_uniform_vec4(group, "color", color, 1); + } + +} + +/* Add geometry to shadingGroups. Execute for each objects */ +static void PARTICLE_cache_populate(Object *ob) +{ + PARTICLE_PassList *psl = vedata->psl; + PARTICLE_StorageList *stl = vedata->stl; + + if (ob->type == OB_MESH) { + /* Get geometry cache */ + struct Batch *geom = DRW_cache_surface_get(ob); + + /* Add geom to a shading group */ + DRW_shgroup_call_add(group, geom, ob->obmat); + } +} + +/* Optionnal : Post-cache_populate callback */ +static void PARTICLE_cache_finish(void) +{ + PARTICLE_PassList *psl = vedata->psl; + PARTICLE_StorageList *stl = vedata->stl; + + /* Do something here! dependant on the objects gathered */ +} + +/* Draw time ! Control rendering pipeline from here */ +static void PARTICLE_draw_scene(void) +{ + PARTICLE_Data *ved = DRW_viewport_engine_data_get("ParticleMode"); + PARTICLE_PassList *psl = ved->psl; + PARTICLE_FramebufferList *fbl = vedata->fbl; + + /* Default framebuffer and texture */ + DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get(); + DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); + + /* Show / hide entire passes, swap framebuffers ... whatever you fancy */ + /* + * DRW_framebuffer_texture_detach(dtxl->depth); + * DRW_framebuffer_bind(fbl->custom_fb); + * DRW_draw_pass(psl->pass); + * DRW_framebuffer_texture_attach(dfbl->default_fb, dtxl->depth, 0); + * DRW_framebuffer_bind(dfbl->default_fb); + */ + + /* ... or just render passes on default framebuffer. */ + DRW_draw_pass(psl->pass); + + /* If you changed framebuffer, double check you rebind + * the default one with its textures attached before finishing */ +} + +/* Cleanup when destroying the engine. + * This is not per viewport ! only when quitting blender. + * Mostly used for freeing shaders */ +static void PARTICLE_engine_free(void) +{ + // if (custom_shader) + // DRW_shader_free(custom_shader); +} + +/* Create collection settings here. + * + * Be sure to add this function there : + * source/blender/draw/DRW_engine.h + * source/blender/blenkernel/intern/layer.c + * source/blenderplayer/bad_level_call_stubs/stubs.c + * + * And relevant collection settings to : + * source/blender/makesrna/intern/rna_scene.c + * source/blender/blenkernel/intern/layer.c + */ +void PARTICLE_collection_settings_create(CollectionEngineSettings *ces) +{ + BLI_assert(ces); + // BKE_collection_engine_property_add_int(ces, "my_bool_prop", false); + // BKE_collection_engine_property_add_int(ces, "my_int_prop", 0); + // BKE_collection_engine_property_add_float(ces, "my_float_prop", 0.0f); +} + +DrawEngineType draw_engine_particle_type = { + NULL, NULL, + N_("ParticleMode"), + &PARTICLE_engine_init, + &PARTICLE_engine_free, + &PARTICLE_cache_init, + &PARTICLE_cache_populate, + &PARTICLE_cache_finish, + NULL, /* draw_background but not needed by mode engines */ + &PARTICLE_draw_scene +}; diff --git a/source/blender/draw/modes/pose_mode.c b/source/blender/draw/modes/pose_mode.c new file mode 100644 index 00000000000..94c0d334f07 --- /dev/null +++ b/source/blender/draw/modes/pose_mode.c @@ -0,0 +1,259 @@ +/* + * Copyright 2016, Blender Foundation. + * + * 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. + * + * Contributor(s): Blender Institute + * + */ + +/** \file blender/draw/modes/pose_mode.c + * \ingroup draw + */ + +#include "DRW_engine.h" +#include "DRW_render.h" + +/* If builtin shaders are needed */ +#include "GPU_shader.h" + +#include "draw_common.h" + +#include "draw_mode_engines.h" + +/* *********** LISTS *********** */ +/* All lists are per viewport specific datas. + * They are all free when viewport changes engines + * or is free itself. Use POSE_engine_init() to + * initialize most of them and POSE_cache_init() + * for POSE_PassList */ + +/* keep it under MAX_PASSES */ +typedef struct POSE_PassList { + /* Declare all passes here and init them in + * POSE_cache_init(). + * Only contains (DRWPass *) */ + struct DRWPass *pass; +} POSE_PassList; + +/* keep it under MAX_BUFFERS */ +typedef struct POSE_FramebufferList { + /* Contains all framebuffer objects needed by this engine. + * Only contains (GPUFrameBuffer *) */ + // struct GPUFrameBuffer *fb; +} POSE_FramebufferList; + +/* keep it under MAX_TEXTURES */ +typedef struct POSE_TextureList { + /* Contains all framebuffer textures / utility textures + * needed by this engine. Only viewport specific textures + * (not per object). Only contains (GPUTexture *) */ + // struct GPUTexture *texture; +} POSE_TextureList; + +/* keep it under MAX_STORAGE */ +typedef struct POSE_StorageList { + /* Contains any other memory block that the engine needs. + * Only directly MEM_(m/c)allocN'ed blocks because they are + * free with MEM_freeN() when viewport is freed. + * (not per object) */ + // struct CustomStruct *block; +} POSE_StorageList; + +typedef struct POSE_Data { + /* Struct returned by DRW_viewport_engine_data_get. + * If you don't use one of these, just make it a (void *) */ + // void *fbl; + char engine_name[32]; /* Required */ + POSE_FramebufferList *fbl; + POSE_TextureList *txl; + POSE_PassList *psl; + POSE_StorageList *stl; +} POSE_Data; + +/* *********** STATIC *********** */ + +/* This keeps the references of the shading groups for + * easy access in POSE_cache_populate() */ +static DRWShadingGroup *group; + +/* If needed, contains all global/Theme colors + * Add needed theme colors / values to DRW_globals_update() and update UBO + * Not needed for constant color. */ +extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */ +extern struct GlobalsUboStorage ts; /* draw_common.c */ + +/* Custom shaders : + * Add sources to source/blender/draw/modes/shaders + * init in POSE_engine_init(); + * free in POSE_engine_free(); */ +static struct GPUShader *custom_shader = NULL; + +/* This keeps the reference of the viewport engine data because + * DRW_viewport_engine_data_get is slow and we don't want to + * call it for every object */ +static POSE_Data *vedata; + +/* *********** FUNCTIONS *********** */ + +/* Init Textures, Framebuffers, Storage and Shaders. + * It is called for every frames. + * (Optionnal) */ +static void POSE_engine_init(void) +{ + POSE_Data *vedata = DRW_viewport_engine_data_get("PoseMode"); + POSE_TextureList *txl = vedata->txl; + POSE_FramebufferList *fbl = vedata->fbl; + POSE_StorageList *stl = vedata->stl; + + /* Init Framebuffers like this: order is attachment order (for color texs) */ + /* + * DRWFboTexture tex[2] = {{&txl->depth, DRW_BUF_DEPTH_24}, + * {&txl->color, DRW_BUF_RGBA_8}}; + */ + + /* DRW_framebuffer_init takes care of checking if + * the framebuffer is valid and has the right size*/ + /* + * float *viewport_size = DRW_viewport_size_get(); + * DRW_framebuffer_init(&fbl->occlude_wire_fb, + * (int)viewport_size[0], (int)viewport_size[1], + * tex, 2); + */ + + if (!custom_shader) { + custom_shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR); + } +} + +/* Here init all passes and shading groups + * Assume that all Passes are NULL */ +static void POSE_cache_init(void) +{ + vedata = DRW_viewport_engine_data_get("PoseMode"); + POSE_PassList *psl = vedata->psl; + POSE_StorageList *stl = vedata->stl; + + { + /* Create a pass */ + DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND | DRW_STATE_WIRE; + psl->pass = DRW_pass_create("My Pass", state); + + /* Create a shadingGroup using a function in draw_common.c or custom one */ + /* + * group = shgroup_dynlines_uniform_color(psl->pass, ts.colorWire); + * -- or -- + * group = DRW_shgroup_create(custom_shader, psl->pass); + */ + group = DRW_shgroup_create(custom_shader, psl->pass); + + /* Uniforms need a pointer to it's value so be sure it's accessible at + * any given time (i.e. use static vars) */ + static float color[4] = {0.2f, 0.5f, 0.3f, 1.0}; + DRW_shgroup_uniform_vec4(group, "color", color, 1); + } + +} + +/* Add geometry to shadingGroups. Execute for each objects */ +static void POSE_cache_populate(Object *ob) +{ + POSE_PassList *psl = vedata->psl; + POSE_StorageList *stl = vedata->stl; + + if (ob->type == OB_MESH) { + /* Get geometry cache */ + struct Batch *geom = DRW_cache_surface_get(ob); + + /* Add geom to a shading group */ + DRW_shgroup_call_add(group, geom, ob->obmat); + } +} + +/* Optionnal : Post-cache_populate callback */ +static void POSE_cache_finish(void) +{ + POSE_PassList *psl = vedata->psl; + POSE_StorageList *stl = vedata->stl; + + /* Do something here! dependant on the objects gathered */ +} + +/* Draw time ! Control rendering pipeline from here */ +static void POSE_draw_scene(void) +{ + POSE_Data *ved = DRW_viewport_engine_data_get("PoseMode"); + POSE_PassList *psl = ved->psl; + POSE_FramebufferList *fbl = vedata->fbl; + + /* Default framebuffer and texture */ + DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get(); + DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); + + /* Show / hide entire passes, swap framebuffers ... whatever you fancy */ + /* + * DRW_framebuffer_texture_detach(dtxl->depth); + * DRW_framebuffer_bind(fbl->custom_fb); + * DRW_draw_pass(psl->pass); + * DRW_framebuffer_texture_attach(dfbl->default_fb, dtxl->depth, 0); + * DRW_framebuffer_bind(dfbl->default_fb); + */ + + /* ... or just render passes on default framebuffer. */ + DRW_draw_pass(psl->pass); + + /* If you changed framebuffer, double check you rebind + * the default one with its textures attached before finishing */ +} + +/* Cleanup when destroying the engine. + * This is not per viewport ! only when quitting blender. + * Mostly used for freeing shaders */ +static void POSE_engine_free(void) +{ + // if (custom_shader) + // DRW_shader_free(custom_shader); +} + +/* Create collection settings here. + * + * Be sure to add this function there : + * source/blender/draw/DRW_engine.h + * source/blender/blenkernel/intern/layer.c + * source/blenderplayer/bad_level_call_stubs/stubs.c + * + * And relevant collection settings to : + * source/blender/makesrna/intern/rna_scene.c + * source/blender/blenkernel/intern/layer.c + */ +void POSE_collection_settings_create(CollectionEngineSettings *ces) +{ + BLI_assert(ces); + // BKE_collection_engine_property_add_int(ces, "my_bool_prop", false); + // BKE_collection_engine_property_add_int(ces, "my_int_prop", 0); + // BKE_collection_engine_property_add_float(ces, "my_float_prop", 0.0f); +} + +DrawEngineType draw_engine_pose_type = { + NULL, NULL, + N_("PoseMode"), + &POSE_engine_init, + &POSE_engine_free, + &POSE_cache_init, + &POSE_cache_populate, + &POSE_cache_finish, + NULL, /* draw_background but not needed by mode engines */ + &POSE_draw_scene +}; diff --git a/source/blender/draw/modes/sculpt_mode.c b/source/blender/draw/modes/sculpt_mode.c new file mode 100644 index 00000000000..19f13631b89 --- /dev/null +++ b/source/blender/draw/modes/sculpt_mode.c @@ -0,0 +1,259 @@ +/* + * Copyright 2016, Blender Foundation. + * + * 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. + * + * Contributor(s): Blender Institute + * + */ + +/** \file blender/draw/modes/sculpt_mode.c + * \ingroup draw + */ + +#include "DRW_engine.h" +#include "DRW_render.h" + +/* If builtin shaders are needed */ +#include "GPU_shader.h" + +#include "draw_common.h" + +#include "draw_mode_engines.h" + +/* *********** LISTS *********** */ +/* All lists are per viewport specific datas. + * They are all free when viewport changes engines + * or is free itself. Use SCULPT_engine_init() to + * initialize most of them and SCULPT_cache_init() + * for SCULPT_PassList */ + +/* keep it under MAX_PASSES */ +typedef struct SCULPT_PassList { + /* Declare all passes here and init them in + * SCULPT_cache_init(). + * Only contains (DRWPass *) */ + struct DRWPass *pass; +} SCULPT_PassList; + +/* keep it under MAX_BUFFERS */ +typedef struct SCULPT_FramebufferList { + /* Contains all framebuffer objects needed by this engine. + * Only contains (GPUFrameBuffer *) */ + // struct GPUFrameBuffer *fb; +} SCULPT_FramebufferList; + +/* keep it under MAX_TEXTURES */ +typedef struct SCULPT_TextureList { + /* Contains all framebuffer textures / utility textures + * needed by this engine. Only viewport specific textures + * (not per object). Only contains (GPUTexture *) */ + // struct GPUTexture *texture; +} SCULPT_TextureList; + +/* keep it under MAX_STORAGE */ +typedef struct SCULPT_StorageList { + /* Contains any other memory block that the engine needs. + * Only directly MEM_(m/c)allocN'ed blocks because they are + * free with MEM_freeN() when viewport is freed. + * (not per object) */ + // struct CustomStruct *block; +} SCULPT_StorageList; + +typedef struct SCULPT_Data { + /* Struct returned by DRW_viewport_engine_data_get. + * If you don't use one of these, just make it a (void *) */ + // void *fbl; + char engine_name[32]; /* Required */ + SCULPT_FramebufferList *fbl; + SCULPT_TextureList *txl; + SCULPT_PassList *psl; + SCULPT_StorageList *stl; +} SCULPT_Data; + +/* *********** STATIC *********** */ + +/* This keeps the references of the shading groups for + * easy access in SCULPT_cache_populate() */ +static DRWShadingGroup *group; + +/* If needed, contains all global/Theme colors + * Add needed theme colors / values to DRW_globals_update() and update UBO + * Not needed for constant color. */ +extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */ +extern struct GlobalsUboStorage ts; /* draw_common.c */ + +/* Custom shaders : + * Add sources to source/blender/draw/modes/shaders + * init in SCULPT_engine_init(); + * free in SCULPT_engine_free(); */ +static struct GPUShader *custom_shader = NULL; + +/* This keeps the reference of the viewport engine data because + * DRW_viewport_engine_data_get is slow and we don't want to + * call it for every object */ +static SCULPT_Data *vedata; + +/* *********** FUNCTIONS *********** */ + +/* Init Textures, Framebuffers, Storage and Shaders. + * It is called for every frames. + * (Optionnal) */ +static void SCULPT_engine_init(void) +{ + SCULPT_Data *vedata = DRW_viewport_engine_data_get("SculptMode"); + SCULPT_TextureList *txl = vedata->txl; + SCULPT_FramebufferList *fbl = vedata->fbl; + SCULPT_StorageList *stl = vedata->stl; + + /* Init Framebuffers like this: order is attachment order (for color texs) */ + /* + * DRWFboTexture tex[2] = {{&txl->depth, DRW_BUF_DEPTH_24}, + * {&txl->color, DRW_BUF_RGBA_8}}; + */ + + /* DRW_framebuffer_init takes care of checking if + * the framebuffer is valid and has the right size*/ + /* + * float *viewport_size = DRW_viewport_size_get(); + * DRW_framebuffer_init(&fbl->occlude_wire_fb, + * (int)viewport_size[0], (int)viewport_size[1], + * tex, 2); + */ + + if (!custom_shader) { + custom_shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR); + } +} + +/* Here init all passes and shading groups + * Assume that all Passes are NULL */ +static void SCULPT_cache_init(void) +{ + vedata = DRW_viewport_engine_data_get("SculptMode"); + SCULPT_PassList *psl = vedata->psl; + SCULPT_StorageList *stl = vedata->stl; + + { + /* Create a pass */ + DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND | DRW_STATE_WIRE; + psl->pass = DRW_pass_create("My Pass", state); + + /* Create a shadingGroup using a function in draw_common.c or custom one */ + /* + * group = shgroup_dynlines_uniform_color(psl->pass, ts.colorWire); + * -- or -- + * group = DRW_shgroup_create(custom_shader, psl->pass); + */ + group = DRW_shgroup_create(custom_shader, psl->pass); + + /* Uniforms need a pointer to it's value so be sure it's accessible at + * any given time (i.e. use static vars) */ + static float color[4] = {0.2f, 0.5f, 0.3f, 1.0}; + DRW_shgroup_uniform_vec4(group, "color", color, 1); + } + +} + +/* Add geometry to shadingGroups. Execute for each objects */ +static void SCULPT_cache_populate(Object *ob) +{ + SCULPT_PassList *psl = vedata->psl; + SCULPT_StorageList *stl = vedata->stl; + + if (ob->type == OB_MESH) { + /* Get geometry cache */ + struct Batch *geom = DRW_cache_surface_get(ob); + + /* Add geom to a shading group */ + DRW_shgroup_call_add(group, geom, ob->obmat); + } +} + +/* Optionnal : Post-cache_populate callback */ +static void SCULPT_cache_finish(void) +{ + SCULPT_PassList *psl = vedata->psl; + SCULPT_StorageList *stl = vedata->stl; + + /* Do something here! dependant on the objects gathered */ +} + +/* Draw time ! Control rendering pipeline from here */ +static void SCULPT_draw_scene(void) +{ + SCULPT_Data *ved = DRW_viewport_engine_data_get("SculptMode"); + SCULPT_PassList *psl = ved->psl; + SCULPT_FramebufferList *fbl = vedata->fbl; + + /* Default framebuffer and texture */ + DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get(); + DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); + + /* Show / hide entire passes, swap framebuffers ... whatever you fancy */ + /* + * DRW_framebuffer_texture_detach(dtxl->depth); + * DRW_framebuffer_bind(fbl->custom_fb); + * DRW_draw_pass(psl->pass); + * DRW_framebuffer_texture_attach(dfbl->default_fb, dtxl->depth, 0); + * DRW_framebuffer_bind(dfbl->default_fb); + */ + + /* ... or just render passes on default framebuffer. */ + DRW_draw_pass(psl->pass); + + /* If you changed framebuffer, double check you rebind + * the default one with its textures attached before finishing */ +} + +/* Cleanup when destroying the engine. + * This is not per viewport ! only when quitting blender. + * Mostly used for freeing shaders */ +static void SCULPT_engine_free(void) +{ + // if (custom_shader) + // DRW_shader_free(custom_shader); +} + +/* Create collection settings here. + * + * Be sure to add this function there : + * source/blender/draw/DRW_engine.h + * source/blender/blenkernel/intern/layer.c + * source/blenderplayer/bad_level_call_stubs/stubs.c + * + * And relevant collection settings to : + * source/blender/makesrna/intern/rna_scene.c + * source/blender/blenkernel/intern/layer.c + */ +void SCULPT_collection_settings_create(CollectionEngineSettings *ces) +{ + BLI_assert(ces); + // BKE_collection_engine_property_add_int(ces, "my_bool_prop", false); + // BKE_collection_engine_property_add_int(ces, "my_int_prop", 0); + // BKE_collection_engine_property_add_float(ces, "my_float_prop", 0.0f); +} + +DrawEngineType draw_engine_sculpt_type = { + NULL, NULL, + N_("SculptMode"), + &SCULPT_engine_init, + &SCULPT_engine_free, + &SCULPT_cache_init, + &SCULPT_cache_populate, + &SCULPT_cache_finish, + NULL, /* draw_background but not needed by mode engines */ + &SCULPT_draw_scene +}; |