Cleanup: Remove unused code in sculpt_mode, workbench and draw manager

This commit is contained in:
Clément Foucault 2019-05-04 01:41:39 +02:00
parent b2f1a65874
commit fb3b2ab709
Notes: blender-bot 2023-02-14 10:09:24 +01:00
Referenced by issue #62282, Multires: normals not updating when using smooth shading
9 changed files with 13 additions and 157 deletions

View File

@ -941,7 +941,7 @@ void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob)
const Mesh *me = (ob->type == OB_MESH) ? ob->data : NULL;
bool has_transp_mat = false;
if (!is_sculpt_mode && me && me->mloopuv && TEXTURE_DRAWING_ENABLED(wpd)) {
if (!is_sculpt_mode && TEXTURE_DRAWING_ENABLED(wpd) && me && me->mloopuv) {
/* Draw textured */
struct GPUBatch **geom_array = DRW_cache_mesh_surface_texpaint_get(ob);
for (int i = 0; i < materials_len; i++) {

View File

@ -401,10 +401,6 @@ DRWShadingGroup *DRW_shgroup_transform_feedback_create(struct GPUShader *shader,
DRWPass *pass,
struct GPUVertBuf *tf_target);
typedef void(DRWCallGenerateFn)(DRWShadingGroup *shgroup,
void (*draw_fn)(DRWShadingGroup *shgroup, struct GPUBatch *geom),
void *user_data);
/* return final visibility */
typedef bool(DRWCallVisibilityFn)(bool vis_in, void *user_data);
@ -422,9 +418,6 @@ void DRW_shgroup_call_procedural_lines_add(DRWShadingGroup *shgroup,
void DRW_shgroup_call_procedural_triangles_add(DRWShadingGroup *shgroup,
uint tria_count,
float (*obmat)[4]);
void DRW_shgroup_call_object_procedural_triangles_culled_add(DRWShadingGroup *shgroup,
uint tria_count,
struct Object *ob);
void DRW_shgroup_call_object_add_ex(DRWShadingGroup *shgroup,
struct GPUBatch *geom,
struct Object *ob,

View File

@ -3290,14 +3290,6 @@ GPUBatch *DRW_cache_mesh_surface_mesh_analysis_get(Object *ob)
return DRW_mesh_batch_cache_get_edit_mesh_analysis(ob->data);
}
void DRW_cache_mesh_sculpt_coords_ensure(Object *ob)
{
BLI_assert(ob->type == OB_MESH);
Mesh *me = ob->data;
DRW_mesh_cache_sculpt_coords_ensure(me);
}
/** \} */
/* -------------------------------------------------------------------- */

View File

@ -159,8 +159,6 @@ struct GPUBatch *DRW_mesh_batch_cache_get_edituv_facedots(struct Mesh *me);
struct GPUBatch *DRW_mesh_batch_cache_get_uv_edges(struct Mesh *me);
struct GPUBatch *DRW_mesh_batch_cache_get_edit_mesh_analysis(struct Mesh *me);
void DRW_mesh_cache_sculpt_coords_ensure(struct Mesh *me);
/* Edit mesh bitflags (is this the right place?) */
enum {
VFLAG_VERT_ACTIVE = 1 << 0,

View File

@ -4455,25 +4455,6 @@ GPUBatch *DRW_mesh_batch_cache_get_surface_edges(Mesh *me)
return DRW_batch_request(&cache->batch.wire_loops);
}
/**
* Needed for when we draw with shaded data.
*/
void DRW_mesh_cache_sculpt_coords_ensure(Mesh *UNUSED(me))
{
#if 0 /* Unused for now */
if (me->runtime.batch_cache) {
MeshBatchCache *cache = mesh_batch_cache_get(me);
if (cache && cache->pos_with_normals && cache->is_sculpt_points_tag) {
/* XXX Force update of all the batches that contains the pos_with_normals buffer.
* TODO(fclem): Ideally, Gawain should provide a way to update a buffer without destroying it. */
mesh_batch_cache_clear_selective(me, cache->pos_with_normals);
GPU_VERTBUF_DISCARD_SAFE(cache->pos_with_normals);
}
cache->is_sculpt_points_tag = false;
}
#endif
}
/* Compute 3D & 2D areas and their sum. */
BLI_INLINE void edit_uv_preprocess_stretch_area(BMFace *efa,
const int cd_loop_uv_offset,

View File

@ -142,8 +142,6 @@ typedef enum {
DRW_CALL_RANGE,
/** Draw instances without any instancing attributes. */
DRW_CALL_INSTANCES,
/** Uses a callback to draw with any number of batches. */
DRW_CALL_GENERATE,
/** Generate a drawcall without any #GPUBatch. */
DRW_CALL_PROCEDURAL,
} DRWCallType;
@ -166,10 +164,6 @@ typedef struct DRWCall {
/* Count can be adjusted between redraw. If needed, we can add fixed count. */
uint *count;
} instances;
struct { /* type == DRW_CALL_GENERATE */
DRWCallGenerateFn *geometry_fn;
void *user_data;
} generate;
struct { /* type == DRW_CALL_PROCEDURAL */
uint vert_count;
GPUPrimType prim_type;

View File

@ -522,15 +522,6 @@ void DRW_shgroup_call_procedural_triangles_add(DRWShadingGroup *shgroup,
drw_shgroup_call_procedural_add_ex(shgroup, GPU_PRIM_TRIS, tria_count * 3, obmat, NULL);
}
/* TODO (fclem): this is a sign that the api is starting to be limiting.
* Maybe add special function that general purpose for special cases. */
void DRW_shgroup_call_object_procedural_triangles_culled_add(DRWShadingGroup *shgroup,
uint tria_count,
Object *ob)
{
drw_shgroup_call_procedural_add_ex(shgroup, GPU_PRIM_TRIS, tria_count * 3, NULL, ob);
}
/* These calls can be culled and are optimized for redraw */
void DRW_shgroup_call_object_add_ex(
DRWShadingGroup *shgroup, GPUBatch *geom, Object *ob, Material *ma, bool bypass_culling)

View File

@ -680,12 +680,16 @@ bool DRW_culling_sphere_test(BoundSphere *bsphere)
/* Do a rough test first: Sphere VS Sphere intersect. */
BoundSphere *frustum_bsphere = &DST.clipping.frustum_bsphere;
float center_dist = len_squared_v3v3(bsphere->center, frustum_bsphere->center);
if (center_dist > SQUARE(bsphere->radius + frustum_bsphere->radius)) {
float center_dist_sq = len_squared_v3v3(bsphere->center, frustum_bsphere->center);
float radius_sum = bsphere->radius + frustum_bsphere->radius;
if (center_dist_sq > SQUARE(radius_sum)) {
return false;
}
/* TODO we could test against the inscribed sphere of the frustum to early out positively. */
/* Test against the 6 frustum planes. */
/* TODO order planes with sides first then far then near clip. Should be better culling heuristic
* when sculpting. */
for (int p = 0; p < 6; p++) {
float dist = plane_point_side_v3(DST.clipping.frustum_planes[p], bsphere->center);
if (dist < -bsphere->radius) {
@ -1319,9 +1323,6 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
draw_geometry_execute_ex(
shgroup, call->instances.geometry, 0, *call->instances.count, true);
break;
case DRW_CALL_GENERATE:
call->generate.geometry_fn(shgroup, draw_geometry_execute, call->generate.user_data);
break;
case DRW_CALL_PROCEDURAL:
GPU_draw_primitive(call->procedural.prim_type, call->procedural.vert_count);
break;

View File

@ -90,19 +90,11 @@ typedef struct SCULPT_Data {
/* *********** STATIC *********** */
static struct {
/* Custom shaders :
* Add sources to source/blender/draw/modes/shaders
* init in SCULPT_engine_init();
* free in SCULPT_engine_free(); */
struct GPUShader *shader_smooth;
struct GPUShader *shader_mask;
} e_data = {NULL}; /* Engine data */
typedef struct SCULPT_PrivateData {
DRWShadingGroup *mask_overlay_grp;
/* This keeps the references of the shading groups for
* easy access in SCULPT_cache_populate() */
DRWShadingGroup *group_flat;
DRWShadingGroup *group_smooth;
} SCULPT_PrivateData; /* Transient data */
/* *********** FUNCTIONS *********** */
@ -118,8 +110,8 @@ static void SCULPT_engine_init(void *vedata)
UNUSED_VARS(txl, fbl, stl);
if (!e_data.shader_smooth) {
e_data.shader_smooth = DRW_shader_create(
if (!e_data.shader_mask) {
e_data.shader_mask = DRW_shader_create(
datatoc_sculpt_mask_vert_glsl, NULL, datatoc_gpu_shader_3D_smooth_color_frag_glsl, NULL);
}
}
@ -142,50 +134,12 @@ static void SCULPT_cache_init(void *vedata)
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_MULTIPLY;
psl->pass = DRW_pass_create("Sculpt Pass", state);
DRWShadingGroup *shgrp = DRW_shgroup_create(e_data.shader_smooth, psl->pass);
DRWShadingGroup *shgrp = DRW_shgroup_create(e_data.shader_mask, psl->pass);
DRW_shgroup_uniform_float(shgrp, "maskOpacity", &v3d->overlay.sculpt_mode_mask_opacity, 1);
stl->g_data->mask_overlay_grp = shgrp;
}
}
static void sculpt_draw_mask_cb(DRWShadingGroup *shgroup,
void (*draw_fn)(DRWShadingGroup *shgroup, struct GPUBatch *geom),
void *user_data)
{
Object *ob = user_data;
PBVH *pbvh = ob->sculpt->pbvh;
if (pbvh) {
BKE_pbvh_draw_cb(pbvh,
NULL,
NULL,
false,
false,
true,
false,
(void (*)(void *, struct GPUBatch *))draw_fn,
shgroup);
}
}
static void sculpt_update_pbvh_normals(Object *object)
{
Mesh *mesh = object->data;
PBVH *pbvh = object->sculpt->pbvh;
SubdivCCG *subdiv_ccg = mesh->runtime.subdiv_ccg;
if (pbvh == NULL || subdiv_ccg == NULL) {
return;
}
BKE_sculpt_bvh_update_from_ccg(pbvh, subdiv_ccg);
struct CCGFace **faces;
int num_faces;
BKE_pbvh_get_grid_updates(pbvh, 1, (void ***)&faces, &num_faces);
if (num_faces > 0) {
BKE_subdiv_ccg_update_normals(subdiv_ccg, faces, num_faces);
MEM_freeN(faces);
}
}
/* Add geometry to shadingGroups. Execute for each objects */
static void SCULPT_cache_populate(void *vedata, Object *ob)
{
@ -198,20 +152,6 @@ static void SCULPT_cache_populate(void *vedata, Object *ob)
const DRWContextState *draw_ctx = DRW_context_state_get();
if (ob->sculpt && (ob == draw_ctx->obact)) {
sculpt_update_pbvh_normals(ob);
/* XXX, needed for dyntopo-undo (which clears).
* probably depsgraph should handlle? in 2.7x
* getting derived-mesh does this (mesh_build_data). */
if (ob->sculpt->pbvh == NULL) {
/* create PBVH immediately (would be created on the fly too,
* but this avoids waiting on first stroke) */
Scene *scene = draw_ctx->scene;
BKE_sculpt_update_mesh_elements(
draw_ctx->depsgraph, scene, scene->toolsettings->sculpt, ob, false, false);
}
PBVH *pbvh = ob->sculpt->pbvh;
if (pbvh && pbvh_has_mask(pbvh)) {
DRW_shgroup_call_sculpt_add(stl->g_data->mask_overlay_grp, ob, false, true, false);
@ -220,50 +160,16 @@ static void SCULPT_cache_populate(void *vedata, Object *ob)
}
}
/* Optional: Post-cache_populate callback */
static void SCULPT_cache_finish(void *vedata)
{
SCULPT_PassList *psl = ((SCULPT_Data *)vedata)->psl;
SCULPT_StorageList *stl = ((SCULPT_Data *)vedata)->stl;
/* Do something here! dependent on the objects gathered */
UNUSED_VARS(psl, stl);
}
/* Draw time ! Control rendering pipeline from here */
static void SCULPT_draw_scene(void *vedata)
{
SCULPT_PassList *psl = ((SCULPT_Data *)vedata)->psl;
SCULPT_FramebufferList *fbl = ((SCULPT_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. */
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)
{
DRW_SHADER_FREE_SAFE(e_data.shader_smooth);
DRW_SHADER_FREE_SAFE(e_data.shader_mask);
}
static const DrawEngineDataSize SCULPT_data_size = DRW_VIEWPORT_DATA_SIZE(SCULPT_Data);
@ -277,7 +183,7 @@ DrawEngineType draw_engine_sculpt_type = {
&SCULPT_engine_free,
&SCULPT_cache_init,
&SCULPT_cache_populate,
&SCULPT_cache_finish,
NULL,
NULL, /* draw_background but not needed by mode engines */
&SCULPT_draw_scene,
NULL,