Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGermano <germano.costa@ig.com.br>2017-11-16 20:12:32 +0300
committerGermano <germano.costa@ig.com.br>2017-11-16 20:12:32 +0300
commit88c88c4610260ef3d00420c3e9fc3c1cd56aad14 (patch)
treeb9e49f253fd37c773c2098b583019e2240655885 /source/blender/draw/modes
parent562da211c21bc57e35d7b2dba2f36c2472de90a2 (diff)
Fix T51210: Draw Manager: Support for Metaball Drawing
Differential Revision: D2914
Diffstat (limited to 'source/blender/draw/modes')
-rw-r--r--source/blender/draw/modes/edit_metaball_mode.c156
-rw-r--r--source/blender/draw/modes/object_mode.c34
2 files changed, 103 insertions, 87 deletions
diff --git a/source/blender/draw/modes/edit_metaball_mode.c b/source/blender/draw/modes/edit_metaball_mode.c
index 202e520193b..fb61114686b 100644
--- a/source/blender/draw/modes/edit_metaball_mode.c
+++ b/source/blender/draw/modes/edit_metaball_mode.c
@@ -26,8 +26,13 @@
#include "DRW_engine.h"
#include "DRW_render.h"
+#include "DNA_meta_types.h"
+
+#include "BKE_mball.h"
+
/* If builtin shaders are needed */
#include "GPU_shader.h"
+#include "GPU_select.h"
#include "draw_common.h"
@@ -71,7 +76,7 @@ typedef struct EDIT_METABALL_StorageList {
* 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;
+ // struct CustomStruct *block;
struct EDIT_METABALL_PrivateData *g_data;
} EDIT_METABALL_StorageList;
@@ -88,14 +93,6 @@ typedef struct EDIT_METABALL_Data {
/* *********** STATIC *********** */
-static struct {
- /* Custom shaders :
- * Add sources to source/blender/draw/modes/shaders
- * init in EDIT_METABALL_engine_init();
- * free in EDIT_METABALL_engine_free(); */
- struct GPUShader *custom_shader;
-} e_data = {NULL}; /* Engine data */
-
typedef struct EDIT_METABALL_PrivateData {
/* This keeps the references of the shading groups for
* easy access in EDIT_METABALL_cache_populate() */
@@ -104,37 +101,6 @@ typedef struct EDIT_METABALL_PrivateData {
/* *********** FUNCTIONS *********** */
-/* Init Textures, Framebuffers, Storage and Shaders.
- * It is called for every frames.
- * (Optional) */
-static void EDIT_METABALL_engine_init(void *vedata)
-{
- EDIT_METABALL_TextureList *txl = ((EDIT_METABALL_Data *)vedata)->txl;
- EDIT_METABALL_FramebufferList *fbl = ((EDIT_METABALL_Data *)vedata)->fbl;
- EDIT_METABALL_StorageList *stl = ((EDIT_METABALL_Data *)vedata)->stl;
-
- UNUSED_VARS(txl, fbl, stl);
-
- /* Init Framebuffers like this: order is attachment order (for color texs) */
- /*
- * DRWFboTexture tex[2] = {{&txl->depth, DRW_TEX_DEPTH_24, 0},
- * {&txl->color, DRW_TEX_RGBA_8, DRW_TEX_FILTER}};
- */
-
- /* 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 (!e_data.custom_shader) {
- e_data.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)
@@ -153,70 +119,86 @@ static void EDIT_METABALL_cache_init(void *vedata)
psl->pass = DRW_pass_create("My Pass", state);
/* Create a shadingGroup using a function in draw_common.c or custom one */
- /*
- * stl->g_data->group = shgroup_dynlines_uniform_color(psl->pass, ts.colorWire);
- * -- or --
- * stl->g_data->group = DRW_shgroup_create(e_data.custom_shader, psl->pass);
- */
- stl->g_data->group = DRW_shgroup_create(e_data.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(stl->g_data->group, "color", color, 1);
+ stl->g_data->group = shgroup_instance_mball_helpers(psl->pass, DRW_cache_screenspace_circle_get());
}
-
}
-/* Add geometry to shadingGroups. Execute for each objects */
-static void EDIT_METABALL_cache_populate(void *vedata, Object *ob)
+static void EDIT_METABALL_cache_populate_radius_visualization(
+ DRWShadingGroup *group, MetaElem *ml, const float scale_xform[3][4],
+ const float *radius, const int selection_id)
{
- EDIT_METABALL_PassList *psl = ((EDIT_METABALL_Data *)vedata)->psl;
- EDIT_METABALL_StorageList *stl = ((EDIT_METABALL_Data *)vedata)->stl;
+ const float *color;
+ static const float col_radius[3] = {0.63, 0.19, 0.19}; /* 0x3030A0 */
+ static const float col_radius_select[3] = {0.94, 0.63, 0.63}; /* 0xA0A0F0 */
- UNUSED_VARS(psl, stl);
+ if ((ml->flag & SELECT) && (ml->flag & MB_SCALE_RAD)) color = col_radius_select;
+ else color = col_radius;
- if (ob->type == OB_MESH) {
- /* Get geometry cache */
- struct Gwn_Batch *geom = DRW_cache_mesh_surface_get(ob);
+ if (selection_id != -1) {
+ ml->selcol1 = selection_id;
+ DRW_select_load_id(selection_id);
+ }
+
+ DRW_shgroup_call_dynamic_add(group, scale_xform, radius, color);
+}
+
+static void EDIT_METABALL_cache_populate_stiffness_visualization(
+ DRWShadingGroup *group, MetaElem *ml, const float scale_xform[3][4],
+ const float *radius, const int selection_id)
+{
+ const float *color;
+ static const float col_stiffness[3] = {0.19, 0.63, 0.19}; /* 0x30A030 */
+ static const float col_stiffness_select[3] = {0.63, 0.94, 0.63}; /* 0xA0F0A0 */
- /* Add geom to a shading group */
- DRW_shgroup_call_add(stl->g_data->group, geom, ob->obmat);
+ if ((ml->flag & SELECT) && !(ml->flag & MB_SCALE_RAD)) color = col_stiffness_select;
+ else color = col_stiffness;
+
+ if (selection_id != -1) {
+ ml->selcol2 = selection_id;
+ DRW_select_load_id(selection_id);
}
+
+ DRW_shgroup_call_dynamic_add(group, scale_xform, radius, color);
}
-/* Optional: Post-cache_populate callback */
-static void EDIT_METABALL_cache_finish(void *vedata)
+/* Add geometry to shadingGroups. Execute for each objects */
+static void EDIT_METABALL_cache_populate(void *vedata, Object *ob)
{
- EDIT_METABALL_PassList *psl = ((EDIT_METABALL_Data *)vedata)->psl;
+ //EDIT_METABALL_PassList *psl = ((EDIT_METABALL_Data *)vedata)->psl;
EDIT_METABALL_StorageList *stl = ((EDIT_METABALL_Data *)vedata)->stl;
- /* Do something here! dependant on the objects gathered */
- UNUSED_VARS(psl, stl);
+ if (ob->type == OB_MBALL) {
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ Scene *scene = draw_ctx->scene;
+ Object *obedit = scene->obedit;
+ DRWShadingGroup *group = stl->g_data->group;
+
+ if (ob == obedit) {
+ MetaBall *mb = ob->data;
+
+ const bool is_select = DRW_state_is_select();
+
+ int selection_id = 0;
+
+ for (MetaElem *ml = mb->editelems->first; ml != NULL; ml = ml->next) {
+ BKE_mball_element_calc_display_m3x4(ml->draw_scale_xform, ob->obmat, &ml->x);
+ ml->draw_stiffness_radius = ml->rad * atanf(ml->s) / (float)M_PI_2;
+
+ EDIT_METABALL_cache_populate_radius_visualization(
+ group, ml, ml->draw_scale_xform, &ml->rad, is_select ? ++selection_id : -1);
+
+ EDIT_METABALL_cache_populate_stiffness_visualization(
+ group, ml, ml->draw_scale_xform, &ml->draw_stiffness_radius, is_select ? ++selection_id : -1);
+ }
+ }
+ }
}
/* Draw time ! Control rendering pipeline from here */
static void EDIT_METABALL_draw_scene(void *vedata)
{
EDIT_METABALL_PassList *psl = ((EDIT_METABALL_Data *)vedata)->psl;
- EDIT_METABALL_FramebufferList *fbl = ((EDIT_METABALL_Data *)vedata)->fbl;
-
- /* Default framebuffer and texture */
- DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
- DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
-
- UNUSED_VARS(fbl, dfbl, dtxl);
-
- /* 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, 0);
- * DRW_framebuffer_bind(dfbl->default_fb);
- */
-
- /* ... or just render passes on default framebuffer. */
+ /* render passes on default framebuffer. */
DRW_draw_pass(psl->pass);
/* If you changed framebuffer, double check you rebind
@@ -258,11 +240,11 @@ DrawEngineType draw_engine_edit_metaball_type = {
NULL, NULL,
N_("EditMetaballMode"),
&EDIT_METABALL_data_size,
- &EDIT_METABALL_engine_init,
+ NULL,
&EDIT_METABALL_engine_free,
&EDIT_METABALL_cache_init,
&EDIT_METABALL_cache_populate,
- &EDIT_METABALL_cache_finish,
+ NULL,
NULL, /* draw_background but not needed by mode engines */
&EDIT_METABALL_draw_scene,
NULL,
diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c
index a981a51a846..534ef9fb5bd 100644
--- a/source/blender/draw/modes/object_mode.c
+++ b/source/blender/draw/modes/object_mode.c
@@ -31,6 +31,7 @@
#include "DNA_camera_types.h"
#include "DNA_curve_types.h"
#include "DNA_mesh_types.h"
+#include "DNA_meta_types.h"
#include "DNA_object_force.h"
#include "DNA_lightprobe_types.h"
#include "DNA_particle_types.h"
@@ -43,6 +44,7 @@
#include "BKE_camera.h"
#include "BKE_curve.h"
#include "BKE_global.h"
+#include "BKE_mball.h"
#include "BKE_object.h"
#include "BKE_particle.h"
#include "BKE_image.h"
@@ -149,6 +151,9 @@ typedef struct OBJECT_PrivateData {
DRWShadingGroup *probe_planar;
DRWShadingGroup *probe_grid;
+ /* MetaBalls */
+ DRWShadingGroup *mball_circle;
+
/* Lamps */
DRWShadingGroup *lamp_center;
DRWShadingGroup *lamp_center_group;
@@ -950,6 +955,13 @@ static void OBJECT_cache_init(void *vedata)
}
{
+ /* Metaballs Helpers */
+ struct Gwn_Batch *geom;
+ geom = DRW_cache_screenspace_circle_get();
+ stl->g_data->mball_circle = shgroup_instance_mball_helpers(psl->non_meshes, geom);
+ }
+
+ {
/* Lamps */
/* TODO
* for now we create multiple times the same VBO with only lamp center coordinates
@@ -1077,6 +1089,20 @@ static void OBJECT_cache_init(void *vedata)
}
}
+static void DRW_shgroup_mball_helpers(OBJECT_StorageList *stl, Object *ob, SceneLayer *scene_layer)
+{
+ MetaBall *mb = ob->data;
+
+ float *color;
+ DRW_object_wire_theme_get(ob, scene_layer, &color);
+
+ for (MetaElem *ml = mb->elems.first; ml != NULL; ml = ml->next) {
+ /* draw radius */
+ BKE_mball_element_calc_display_m3x4(ml->draw_scale_xform, ob->obmat, &ml->x);
+ DRW_shgroup_call_dynamic_add(stl->g_data->mball_circle, ml->draw_scale_xform, &ml->rad, color);
+ }
+}
+
static void DRW_shgroup_lamp(OBJECT_StorageList *stl, Object *ob, SceneLayer *scene_layer)
{
Lamp *la = ob->data;
@@ -1812,6 +1838,14 @@ static void OBJECT_cache_populate(void *vedata, Object *ob)
}
break;
}
+ case OB_MBALL:
+ {
+ Object *obedit = scene->obedit;
+ if (ob != obedit) {
+ DRW_shgroup_mball_helpers(stl, ob, scene_layer);
+ }
+ break;
+ }
case OB_LAMP:
DRW_shgroup_lamp(stl, ob, scene_layer);
break;