Viewport: implement hiding faces in paint modes.

In 2.79 hiding works in paint modes with selection enabled,
so it is a missing feature. This implements it in texture
paint overlays and in workbench base shading.

Reviewers: fclem

Differential Revision: https://developer.blender.org/D3989
This commit is contained in:
Alexander Gavrilov 2018-11-25 18:34:28 +03:00
parent 99f7934e19
commit 7d32d87a86
11 changed files with 139 additions and 85 deletions

View File

@ -1450,6 +1450,7 @@ void EEVEE_materials_cache_populate(EEVEE_Data *vedata, EEVEE_ViewLayerData *sld
is_sculpt_mode &&
((ob->sculpt && ob->sculpt->pbvh) && (BKE_pbvh_type(ob->sculpt->pbvh) != PBVH_FACES));
#endif
const bool use_hide = is_active && DRW_object_use_hide_faces(ob);
const bool is_default_mode_shader = is_sculpt_mode;
/* First get materials for this mesh. */
@ -1526,7 +1527,7 @@ void EEVEE_materials_cache_populate(EEVEE_Data *vedata, EEVEE_ViewLayerData *sld
int *auto_layer_is_srgb;
int auto_layer_count;
struct GPUBatch **mat_geom = DRW_cache_object_surface_material_get(
ob, gpumat_array, materials_len,
ob, gpumat_array, materials_len, use_hide,
&auto_layer_names,
&auto_layer_is_srgb,
&auto_layer_count);

View File

@ -715,13 +715,14 @@ void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob)
if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL)) {
const bool is_active = (ob == draw_ctx->obact);
const bool is_sculpt_mode = is_active && (draw_ctx->object_mode & OB_MODE_SCULPT) != 0;
const bool use_hide = is_active && DRW_object_use_hide_faces(ob);
bool is_drawn = false;
if (!is_sculpt_mode && TEXTURE_DRAWING_ENABLED(wpd) && ELEM(ob->type, OB_MESH)) {
const Mesh *me = ob->data;
if (me->mloopuv) {
const int materials_len = MAX2(1, (is_sculpt_mode ? 1 : ob->totcol));
struct GPUMaterial **gpumat_array = BLI_array_alloca(gpumat_array, materials_len);
struct GPUBatch **geom_array = me->totcol ? DRW_cache_mesh_surface_texpaint_get(ob) : NULL;
struct GPUBatch **geom_array = me->totcol ? DRW_cache_mesh_surface_texpaint_get(ob, use_hide) : NULL;
if (materials_len > 0 && geom_array) {
for (int i = 0; i < materials_len; i++) {
if (geom_array[i] == NULL) {
@ -744,7 +745,7 @@ void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob)
if (!is_drawn) {
if (ELEM(wpd->shading.color_type, V3D_SHADING_SINGLE_COLOR, V3D_SHADING_RANDOM_COLOR)) {
/* No material split needed */
struct GPUBatch *geom = DRW_cache_object_surface_get(ob);
struct GPUBatch *geom = DRW_cache_object_surface_get_ex(ob, use_hide);
if (geom) {
material = get_or_create_material_data(vedata, ob, NULL, NULL, wpd->shading.color_type);
if (is_sculpt_mode) {
@ -763,7 +764,7 @@ void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob)
}
struct GPUBatch **mat_geom = DRW_cache_object_surface_material_get(
ob, gpumat_array, materials_len, NULL, NULL, NULL);
ob, gpumat_array, materials_len, use_hide, NULL, NULL, NULL);
if (mat_geom) {
for (int i = 0; i < materials_len; ++i) {
if (mat_geom[i] == NULL) {
@ -787,7 +788,7 @@ void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob)
bool is_manifold;
struct GPUBatch *geom_shadow = DRW_cache_object_edge_detection_get(ob, &is_manifold);
if (geom_shadow) {
if (is_sculpt_mode) {
if (is_sculpt_mode || use_hide) {
/* Currently unsupported in sculpt mode. We could revert to the slow
* method in this case but I'm not sure if it's a good idea given that
* sculpted meshes are heavy to begin with. */

View File

@ -505,6 +505,7 @@ void workbench_forward_cache_populate(WORKBENCH_Data *vedata, Object *ob)
if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL)) {
const bool is_active = (ob == draw_ctx->obact);
const bool is_sculpt_mode = is_active && (draw_ctx->object_mode & OB_MODE_SCULPT) != 0;
const bool use_hide = is_active && DRW_object_use_hide_faces(ob);
bool is_drawn = false;
if (!is_sculpt_mode && TEXTURE_DRAWING_ENABLED(wpd) && ELEM(ob->type, OB_MESH)) {
@ -512,7 +513,7 @@ void workbench_forward_cache_populate(WORKBENCH_Data *vedata, Object *ob)
if (me->mloopuv) {
const int materials_len = MAX2(1, (is_sculpt_mode ? 1 : ob->totcol));
struct GPUMaterial **gpumat_array = BLI_array_alloca(gpumat_array, materials_len);
struct GPUBatch **geom_array = me->totcol ? DRW_cache_mesh_surface_texpaint_get(ob) : NULL;
struct GPUBatch **geom_array = me->totcol ? DRW_cache_mesh_surface_texpaint_get(ob, use_hide) : NULL;
if (materials_len > 0 && geom_array) {
for (int i = 0; i < materials_len; i++) {
if (geom_array[i] == NULL) {
@ -545,7 +546,7 @@ void workbench_forward_cache_populate(WORKBENCH_Data *vedata, Object *ob)
if (!is_drawn) {
if (ELEM(wpd->shading.color_type, V3D_SHADING_SINGLE_COLOR, V3D_SHADING_RANDOM_COLOR)) {
/* No material split needed */
struct GPUBatch *geom = DRW_cache_object_surface_get(ob);
struct GPUBatch *geom = DRW_cache_object_surface_get_ex(ob, use_hide);
if (geom) {
material = get_or_create_material_data(vedata, ob, NULL, NULL, wpd->shading.color_type);
if (is_sculpt_mode) {
@ -570,7 +571,7 @@ void workbench_forward_cache_populate(WORKBENCH_Data *vedata, Object *ob)
}
struct GPUBatch **mat_geom = DRW_cache_object_surface_material_get(
ob, gpumat_array, materials_len, NULL, NULL, NULL);
ob, gpumat_array, materials_len, use_hide, NULL, NULL, NULL);
if (mat_geom) {
for (int i = 0; i < materials_len; ++i) {
if (mat_geom[i] == NULL) {

View File

@ -512,6 +512,7 @@ DrawData *DRW_drawdata_ensure(
bool DRW_object_is_renderable(const struct Object *ob);
bool DRW_object_is_visible_in_active_context(const struct Object *ob);
bool DRW_object_is_flat_normal(const struct Object *ob);
bool DRW_object_use_hide_faces(const struct Object *ob);
bool DRW_object_is_visible_psys_in_active_context(const struct Object *object, const struct ParticleSystem *psys);

View File

@ -728,10 +728,15 @@ GPUBatch *DRW_cache_object_loose_edges_get(struct Object *ob)
}
GPUBatch *DRW_cache_object_surface_get(Object *ob)
{
return DRW_cache_object_surface_get_ex(ob, false);
}
GPUBatch *DRW_cache_object_surface_get_ex(Object *ob, bool use_hide)
{
switch (ob->type) {
case OB_MESH:
return DRW_cache_mesh_surface_get(ob);
return DRW_cache_mesh_surface_get(ob, use_hide);
case OB_CURVE:
return DRW_cache_curve_surface_get(ob);
case OB_SURF:
@ -746,7 +751,7 @@ GPUBatch *DRW_cache_object_surface_get(Object *ob)
}
GPUBatch **DRW_cache_object_surface_material_get(
struct Object *ob, struct GPUMaterial **gpumat_array, uint gpumat_array_len,
struct Object *ob, struct GPUMaterial **gpumat_array, uint gpumat_array_len, bool use_hide,
char **auto_layer_names, int **auto_layer_is_srgb, int *auto_layer_count)
{
if (auto_layer_names != NULL) {
@ -757,7 +762,7 @@ GPUBatch **DRW_cache_object_surface_material_get(
switch (ob->type) {
case OB_MESH:
return DRW_cache_mesh_surface_shaded_get(ob, gpumat_array, gpumat_array_len,
return DRW_cache_mesh_surface_shaded_get(ob, gpumat_array, gpumat_array_len, use_hide,
auto_layer_names, auto_layer_is_srgb, auto_layer_count);
case OB_CURVE:
return DRW_cache_curve_surface_shaded_get(ob, gpumat_array, gpumat_array_len);
@ -3049,12 +3054,12 @@ GPUBatch *DRW_cache_mesh_edge_detection_get(Object *ob, bool *r_is_manifold)
return DRW_mesh_batch_cache_get_edge_detection(me, r_is_manifold);
}
GPUBatch *DRW_cache_mesh_surface_get(Object *ob)
GPUBatch *DRW_cache_mesh_surface_get(Object *ob, bool use_hide)
{
BLI_assert(ob->type == OB_MESH);
Mesh *me = ob->data;
return DRW_mesh_batch_cache_get_triangles_with_normals(me);
return DRW_mesh_batch_cache_get_triangles_with_normals(me, use_hide);
}
void DRW_cache_mesh_face_wireframe_get(
@ -3127,23 +3132,23 @@ GPUBatch *DRW_cache_mesh_surface_vert_colors_get(Object *ob)
/* Return list of batches */
GPUBatch **DRW_cache_mesh_surface_shaded_get(
Object *ob, struct GPUMaterial **gpumat_array, uint gpumat_array_len,
Object *ob, struct GPUMaterial **gpumat_array, uint gpumat_array_len, bool use_hide,
char **auto_layer_names, int **auto_layer_is_srgb, int *auto_layer_count)
{
BLI_assert(ob->type == OB_MESH);
Mesh *me = ob->data;
return DRW_mesh_batch_cache_get_surface_shaded(me, gpumat_array, gpumat_array_len,
return DRW_mesh_batch_cache_get_surface_shaded(me, gpumat_array, gpumat_array_len, use_hide,
auto_layer_names, auto_layer_is_srgb, auto_layer_count);
}
/* Return list of batches */
GPUBatch **DRW_cache_mesh_surface_texpaint_get(Object *ob)
GPUBatch **DRW_cache_mesh_surface_texpaint_get(Object *ob, bool use_hide)
{
BLI_assert(ob->type == OB_MESH);
Mesh *me = ob->data;
return DRW_mesh_batch_cache_get_surface_texpaint(me);
return DRW_mesh_batch_cache_get_surface_texpaint(me, use_hide);
}
GPUBatch *DRW_cache_mesh_surface_texpaint_single_get(Object *ob)
@ -3183,7 +3188,7 @@ GPUBatch *DRW_cache_mesh_edges_paint_overlay_get(Object *ob, bool use_wire, bool
BLI_assert(ob->type == OB_MESH);
Mesh *me = ob->data;
return DRW_mesh_batch_cache_get_weight_overlay_edges(me, use_wire, use_sel);
return DRW_mesh_batch_cache_get_weight_overlay_edges(me, use_wire, use_sel, use_sel);
}
GPUBatch *DRW_cache_mesh_faces_weight_overlay_get(Object *ob)

View File

@ -53,9 +53,10 @@ struct GPUBatch *DRW_cache_screenspace_circle_get(void);
struct GPUBatch *DRW_cache_object_wire_outline_get(struct Object *ob);
struct GPUBatch *DRW_cache_object_edge_detection_get(struct Object *ob, bool *r_is_manifold);
struct GPUBatch *DRW_cache_object_surface_get(struct Object *ob);
struct GPUBatch *DRW_cache_object_surface_get_ex(struct Object *ob, bool use_hide);
struct GPUBatch *DRW_cache_object_loose_edges_get(struct Object *ob);
struct GPUBatch **DRW_cache_object_surface_material_get(
struct Object *ob, struct GPUMaterial **gpumat_array, uint gpumat_array_len,
struct Object *ob, struct GPUMaterial **gpumat_array, uint gpumat_array_len, bool use_hide,
char **auto_layer_names, int **auto_layer_is_srgb, int *auto_layer_count);
void DRW_cache_object_face_wireframe_get(
Object *ob, struct GPUTexture **r_vert_tx, struct GPUTexture **r_faceid_tx, int *r_tri_count);
@ -137,7 +138,7 @@ void DRW_cache_mesh_normals_overlay_get(
struct GPUBatch *DRW_cache_face_centers_get(struct Object *ob);
struct GPUBatch *DRW_cache_mesh_wire_outline_get(struct Object *ob);
struct GPUBatch *DRW_cache_mesh_edge_detection_get(struct Object *ob, bool *r_is_manifold);
struct GPUBatch *DRW_cache_mesh_surface_get(struct Object *ob);
struct GPUBatch *DRW_cache_mesh_surface_get(struct Object *ob, bool use_hide);
struct GPUBatch *DRW_cache_mesh_loose_edges_get(struct Object *ob);
struct GPUBatch *DRW_cache_mesh_surface_weights_get(struct Object *ob, struct ToolSettings *ts, bool paint_mode);
struct GPUBatch *DRW_cache_mesh_surface_vert_colors_get(struct Object *ob);
@ -148,9 +149,9 @@ struct GPUBatch *DRW_cache_mesh_edges_paint_overlay_get(struct Object *ob, bool
struct GPUBatch *DRW_cache_mesh_faces_weight_overlay_get(struct Object *ob);
struct GPUBatch *DRW_cache_mesh_verts_weight_overlay_get(struct Object *ob);
struct GPUBatch **DRW_cache_mesh_surface_shaded_get(
struct Object *ob, struct GPUMaterial **gpumat_array, uint gpumat_array_len,
struct Object *ob, struct GPUMaterial **gpumat_array, uint gpumat_array_len, bool use_hide,
char **auto_layer_names, int **auto_layer_is_srgb, int *auto_layer_count);
struct GPUBatch **DRW_cache_mesh_surface_texpaint_get(struct Object *ob);
struct GPUBatch **DRW_cache_mesh_surface_texpaint_get(struct Object *ob, bool use_hide);
struct GPUBatch *DRW_cache_mesh_surface_texpaint_single_get(struct Object *ob);
void DRW_cache_mesh_face_wireframe_get(
Object *ob, struct GPUTexture **r_vert_tx, struct GPUTexture **r_faceid_tx, int *r_tri_count);

View File

@ -128,16 +128,16 @@ bool DRW_mesh_weight_state_compare(const struct DRW_MeshWeightState *a, const st
/* Mesh */
struct GPUBatch **DRW_mesh_batch_cache_get_surface_shaded(
struct Mesh *me, struct GPUMaterial **gpumat_array, uint gpumat_array_len,
struct Mesh *me, struct GPUMaterial **gpumat_array, uint gpumat_array_len, bool use_hide,
char **auto_layer_names, int **auto_layer_is_srgb, int *auto_layer_count);
struct GPUBatch **DRW_mesh_batch_cache_get_surface_texpaint(struct Mesh *me);
struct GPUBatch **DRW_mesh_batch_cache_get_surface_texpaint(struct Mesh *me, bool use_hide);
struct GPUBatch *DRW_mesh_batch_cache_get_surface_texpaint_single(struct Mesh *me);
struct GPUBatch *DRW_mesh_batch_cache_get_weight_overlay_edges(struct Mesh *me, bool use_wire, bool use_sel);
struct GPUBatch *DRW_mesh_batch_cache_get_weight_overlay_edges(struct Mesh *me, bool use_wire, bool use_sel, bool use_hide);
struct GPUBatch *DRW_mesh_batch_cache_get_weight_overlay_faces(struct Mesh *me);
struct GPUBatch *DRW_mesh_batch_cache_get_weight_overlay_verts(struct Mesh *me);
struct GPUBatch *DRW_mesh_batch_cache_get_all_edges(struct Mesh *me);
struct GPUBatch *DRW_mesh_batch_cache_get_all_triangles(struct Mesh *me);
struct GPUBatch *DRW_mesh_batch_cache_get_triangles_with_normals(struct Mesh *me);
struct GPUBatch *DRW_mesh_batch_cache_get_triangles_with_normals(struct Mesh *me, bool use_hide);
struct GPUBatch *DRW_mesh_batch_cache_get_triangles_with_normals_and_weights(struct Mesh *me, const struct DRW_MeshWeightState *wstate);
struct GPUBatch *DRW_mesh_batch_cache_get_triangles_with_normals_and_vert_colors(struct Mesh *me);
struct GPUBatch *DRW_mesh_batch_cache_get_triangles_with_select_id(struct Mesh *me, bool use_hide, uint select_id_offset);

View File

@ -247,6 +247,7 @@ typedef struct MeshRenderData {
GPUPackedNormal *poly_normals_pack;
GPUPackedNormal *vert_normals_pack;
bool *edge_select_bool;
bool *edge_visible_bool;
} MeshRenderData;
enum {
@ -967,6 +968,7 @@ static void mesh_render_data_free(MeshRenderData *rdata)
MEM_SAFE_FREE(rdata->vert_normals_pack);
MEM_SAFE_FREE(rdata->vert_weight);
MEM_SAFE_FREE(rdata->edge_select_bool);
MEM_SAFE_FREE(rdata->edge_visible_bool);
MEM_SAFE_FREE(rdata->vert_color);
MEM_SAFE_FREE(rdata->mapped.loose_verts);
@ -1350,6 +1352,27 @@ static void mesh_render_data_ensure_edge_select_bool(MeshRenderData *rdata, bool
}
}
/** Ensure #MeshRenderData.edge_visible_bool */
static void mesh_render_data_ensure_edge_visible_bool(MeshRenderData *rdata)
{
bool *edge_visible_bool = rdata->edge_visible_bool;
if (edge_visible_bool == NULL) {
edge_visible_bool = rdata->edge_visible_bool =
MEM_callocN(sizeof(*edge_visible_bool) * rdata->edge_len, __func__);
for (int i = 0; i < rdata->poly_len; i++) {
const MPoly *poly = &rdata->mpoly[i];
if (!(poly->flag & ME_HIDE)) {
for (int j = 0; j < poly->totloop; j++) {
const MLoop *loop = &rdata->mloop[poly->loopstart + j];
edge_visible_bool[loop->e] = true;
}
}
}
}
}
/** \} */
/* ---------------------------------------------------------------------- */
@ -1949,6 +1972,7 @@ typedef struct MeshBatchCache {
GPUBatch *all_triangles;
GPUVertBuf *pos_with_normals;
GPUVertBuf *pos_with_normals_visible_only;
GPUVertBuf *tri_aligned_uv; /* Active UV layer (mloopuv) */
/**
@ -2298,7 +2322,7 @@ static void mesh_batch_cache_clear_selective(Mesh *me, GPUVertBuf *vert)
BLI_assert(vert != NULL);
if (cache->pos_with_normals == vert) {
if (ELEM(vert, cache->pos_with_normals, cache->pos_with_normals_visible_only)) {
GPU_BATCH_DISCARD_SAFE(cache->triangles_with_normals);
GPU_BATCH_DISCARD_SAFE(cache->triangles_with_weights);
GPU_BATCH_DISCARD_SAFE(cache->triangles_with_vert_colors);
@ -2371,6 +2395,7 @@ static void mesh_batch_cache_clear(Mesh *me)
GPU_BATCH_DISCARD_SAFE(cache->points_with_normals);
GPU_BATCH_DISCARD_SAFE(cache->ledges_with_normals);
GPU_VERTBUF_DISCARD_SAFE(cache->pos_with_normals);
GPU_VERTBUF_DISCARD_SAFE(cache->pos_with_normals_visible_only);
GPU_BATCH_DISCARD_SAFE(cache->triangles_with_weights);
GPU_BATCH_DISCARD_SAFE(cache->triangles_with_vert_colors);
GPU_VERTBUF_DISCARD_SAFE(cache->tri_aligned_uv);
@ -2923,19 +2948,11 @@ static GPUVertBuf *mesh_batch_cache_get_tri_pos_and_normals_ex(
}
static GPUVertBuf *mesh_batch_cache_get_tri_pos_and_normals(
MeshRenderData *rdata, MeshBatchCache *cache)
MeshRenderData *rdata, MeshBatchCache *cache, bool use_hide)
{
return mesh_batch_cache_get_tri_pos_and_normals_ex(
rdata, false,
&cache->pos_with_normals);
}
static GPUVertBuf *mesh_create_tri_pos_and_normals_visible_only(
MeshRenderData *rdata)
{
GPUVertBuf *vbo_dummy = NULL;
return mesh_batch_cache_get_tri_pos_and_normals_ex(
rdata, true,
&vbo_dummy);
rdata, use_hide,
use_hide ? &cache->pos_with_normals_visible_only : &cache->pos_with_normals);
}
static GPUVertBuf *mesh_batch_cache_get_facedot_pos_with_normals_and_flag(
@ -4402,7 +4419,7 @@ static GPUIndexBuf *mesh_batch_cache_get_loose_edges(MeshRenderData *rdata, Mesh
static GPUIndexBuf **mesh_batch_cache_get_triangles_in_order_split_by_material(
MeshRenderData *rdata, MeshBatchCache *cache,
/* Special case when drawing final evaluated mesh in editmode, so hidden faces are ignored. */
BMesh *bm_mapped, const int *p_origindex_mapped)
BMesh *bm_mapped, const int *p_origindex_mapped, bool use_hide)
{
BLI_assert(rdata->types & (MR_DATATYPE_VERT | MR_DATATYPE_POLY));
@ -4431,9 +4448,11 @@ static GPUIndexBuf **mesh_batch_cache_get_triangles_in_order_split_by_material(
}
else if (bm_mapped == NULL) {
for (uint i = 0; i < poly_len; i++) {
const MPoly *mp = &rdata->mpoly[i]; ;
const short ma_id = mp->mat_nr < mat_len ? mp->mat_nr : 0;
mat_tri_len[ma_id] += (mp->totloop - 2);
const MPoly *mp = &rdata->mpoly[i];
if (!use_hide || !(mp->flag & ME_HIDE)) {
const short ma_id = mp->mat_nr < mat_len ? mp->mat_nr : 0;
mat_tri_len[ma_id] += (mp->totloop - 2);
}
}
}
else {
@ -4475,11 +4494,16 @@ static GPUIndexBuf **mesh_batch_cache_get_triangles_in_order_split_by_material(
}
else if (bm_mapped == NULL) {
for (uint i = 0; i < poly_len; i++) {
const MPoly *mp = &rdata->mpoly[i]; ;
const short ma_id = mp->mat_nr < mat_len ? mp->mat_nr : 0;
for (int j = 2; j < mp->totloop; j++) {
GPU_indexbuf_add_tri_verts(&elb[ma_id], nidx + 0, nidx + 1, nidx + 2);
nidx += 3;
const MPoly *mp = &rdata->mpoly[i];
if (!use_hide || !(mp->flag & ME_HIDE)) {
const short ma_id = mp->mat_nr < mat_len ? mp->mat_nr : 0;
for (int j = 2; j < mp->totloop; j++) {
GPU_indexbuf_add_tri_verts(&elb[ma_id], nidx + 0, nidx + 1, nidx + 2);
nidx += 3;
}
}
else {
nidx += 3 * (mp->totloop - 2);
}
}
}
@ -4515,7 +4539,7 @@ static GPUIndexBuf **mesh_batch_cache_get_triangles_in_order_split_by_material(
}
static GPUVertBuf *mesh_create_edge_pos_with_sel(
MeshRenderData *rdata, bool use_wire, bool use_select_bool)
MeshRenderData *rdata, bool use_wire, bool use_select_bool, bool use_visible_bool)
{
BLI_assert(rdata->types & (MR_DATATYPE_VERT | MR_DATATYPE_EDGE | MR_DATATYPE_POLY | MR_DATATYPE_LOOP));
BLI_assert(rdata->edit_bmesh == NULL);
@ -4543,10 +4567,18 @@ static GPUVertBuf *mesh_create_edge_pos_with_sel(
mesh_render_data_ensure_edge_select_bool(rdata, use_wire);
}
bool *edge_select_bool = use_select_bool ? rdata->edge_select_bool : NULL;
if (use_visible_bool) {
mesh_render_data_ensure_edge_visible_bool(rdata);
}
bool *edge_visible_bool = use_visible_bool ? rdata->edge_visible_bool : NULL;
for (int i = 0; i < edge_len; i++) {
const MEdge *ed = &rdata->medge[i];
if (use_visible_bool && !edge_visible_bool[i]) {
continue;
}
uchar edge_vert_sel;
if (use_select_bool && edge_select_bool[i]) {
edge_vert_sel = true;
@ -4685,7 +4717,7 @@ GPUBatch *DRW_mesh_batch_cache_get_all_triangles(Mesh *me)
return cache->all_triangles;
}
GPUBatch *DRW_mesh_batch_cache_get_triangles_with_normals(Mesh *me)
GPUBatch *DRW_mesh_batch_cache_get_triangles_with_normals(Mesh *me, bool use_hide)
{
MeshBatchCache *cache = mesh_batch_cache_get(me);
@ -4694,7 +4726,7 @@ GPUBatch *DRW_mesh_batch_cache_get_triangles_with_normals(Mesh *me)
MeshRenderData *rdata = mesh_render_data_create(me, datatype);
cache->triangles_with_normals = GPU_batch_create(
GPU_PRIM_TRIS, mesh_batch_cache_get_tri_pos_and_normals(rdata, cache), NULL);
GPU_PRIM_TRIS, mesh_batch_cache_get_tri_pos_and_normals(rdata, cache, use_hide), NULL);
mesh_render_data_free(rdata);
}
@ -4741,11 +4773,9 @@ GPUBatch *DRW_mesh_batch_cache_get_triangles_with_normals_and_weights(
DRW_mesh_weight_state_copy(&cache->weight_state, wstate);
GPUVertBuf *vbo_tris = use_hide ?
mesh_create_tri_pos_and_normals_visible_only(rdata) :
mesh_batch_cache_get_tri_pos_and_normals(rdata, cache);
GPUVertBuf *vbo_tris = mesh_batch_cache_get_tri_pos_and_normals(rdata, cache, use_hide);
GPU_batch_vertbuf_add_ex(cache->triangles_with_weights, vbo_tris, use_hide);
GPU_batch_vertbuf_add(cache->triangles_with_weights, vbo_tris);
mesh_render_data_free(rdata);
}
@ -4766,10 +4796,8 @@ GPUBatch *DRW_mesh_batch_cache_get_triangles_with_normals_and_vert_colors(Mesh *
cache->triangles_with_vert_colors = GPU_batch_create_ex(
GPU_PRIM_TRIS, mesh_create_tri_vert_colors(rdata, use_hide), NULL, GPU_BATCH_OWNS_VBO);
GPUVertBuf *vbo_tris = use_hide ?
mesh_create_tri_pos_and_normals_visible_only(rdata) :
mesh_batch_cache_get_tri_pos_and_normals(rdata, cache);
GPU_batch_vertbuf_add_ex(cache->triangles_with_vert_colors, vbo_tris, use_hide);
GPUVertBuf *vbo_tris = mesh_batch_cache_get_tri_pos_and_normals(rdata, cache, use_hide);
GPU_batch_vertbuf_add(cache->triangles_with_vert_colors, vbo_tris);
mesh_render_data_free(rdata);
}
@ -4799,10 +4827,8 @@ struct GPUBatch *DRW_mesh_batch_cache_get_triangles_with_select_id(
cache->triangles_with_select_id = GPU_batch_create_ex(
GPU_PRIM_TRIS, mesh_create_tri_select_id(rdata, use_hide, select_id_offset), NULL, GPU_BATCH_OWNS_VBO);
GPUVertBuf *vbo_tris = use_hide ?
mesh_create_tri_pos_and_normals_visible_only(rdata) :
mesh_batch_cache_get_tri_pos_and_normals(rdata, cache);
GPU_batch_vertbuf_add_ex(cache->triangles_with_select_id, vbo_tris, use_hide);
GPUVertBuf *vbo_tris = mesh_batch_cache_get_tri_pos_and_normals(rdata, cache, use_hide);
GPU_batch_vertbuf_add(cache->triangles_with_select_id, vbo_tris);
mesh_render_data_free(rdata);
}
@ -4825,12 +4851,10 @@ struct GPUBatch *DRW_mesh_batch_cache_get_triangles_with_select_mask(struct Mesh
rdata->mapped.use = true;
}
GPUVertBuf *vbo_tris = use_hide ?
mesh_create_tri_pos_and_normals_visible_only(rdata) :
mesh_batch_cache_get_tri_pos_and_normals(rdata, cache);
GPUVertBuf *vbo_tris = mesh_batch_cache_get_tri_pos_and_normals(rdata, cache, use_hide);
cache->triangles_with_select_mask = GPU_batch_create_ex(
GPU_PRIM_TRIS, vbo_tris, NULL, use_hide ? GPU_BATCH_OWNS_VBO : 0);
cache->triangles_with_select_mask = GPU_batch_create(
GPU_PRIM_TRIS, vbo_tris, NULL);
mesh_render_data_free(rdata);
}
@ -4847,7 +4871,7 @@ GPUBatch *DRW_mesh_batch_cache_get_points_with_normals(Mesh *me)
MeshRenderData *rdata = mesh_render_data_create(me, datatype);
cache->points_with_normals = GPU_batch_create(
GPU_PRIM_POINTS, mesh_batch_cache_get_tri_pos_and_normals(rdata, cache), NULL);
GPU_PRIM_POINTS, mesh_batch_cache_get_tri_pos_and_normals(rdata, cache, false), NULL);
mesh_render_data_free(rdata);
}
@ -5221,7 +5245,7 @@ GPUBatch *DRW_mesh_batch_cache_get_verts_with_select_id(Mesh *me, uint select_id
}
GPUBatch **DRW_mesh_batch_cache_get_surface_shaded(
Mesh *me, struct GPUMaterial **gpumat_array, uint gpumat_array_len,
Mesh *me, struct GPUMaterial **gpumat_array, uint gpumat_array_len, bool use_hide,
char **auto_layer_names, int **auto_layer_is_srgb, int *auto_layer_count)
{
MeshBatchCache *cache = mesh_batch_cache_get(me);
@ -5262,9 +5286,9 @@ GPUBatch **DRW_mesh_batch_cache_get_surface_shaded(
GPUIndexBuf **el = mesh_batch_cache_get_triangles_in_order_split_by_material(
rdata, cache,
bm_mapped, p_origindex);
bm_mapped, p_origindex, use_hide);
GPUVertBuf *vbo = mesh_batch_cache_get_tri_pos_and_normals(rdata, cache);
GPUVertBuf *vbo = mesh_batch_cache_get_tri_pos_and_normals(rdata, cache, false);
GPUVertBuf *vbo_shading = mesh_batch_cache_get_tri_shading_data(rdata, cache);
for (int i = 0; i < mat_len; i++) {
@ -5287,7 +5311,7 @@ GPUBatch **DRW_mesh_batch_cache_get_surface_shaded(
return cache->shaded_triangles;
}
GPUBatch **DRW_mesh_batch_cache_get_surface_texpaint(Mesh *me)
GPUBatch **DRW_mesh_batch_cache_get_surface_texpaint(Mesh *me, bool use_hide)
{
MeshBatchCache *cache = mesh_batch_cache_get(me);
@ -5301,9 +5325,10 @@ GPUBatch **DRW_mesh_batch_cache_get_surface_texpaint(Mesh *me)
cache->texpaint_triangles = MEM_callocN(sizeof(*cache->texpaint_triangles) * mat_len, __func__);
GPUIndexBuf **el = mesh_batch_cache_get_triangles_in_order_split_by_material(rdata, cache, NULL, NULL);
GPUIndexBuf **el = mesh_batch_cache_get_triangles_in_order_split_by_material(rdata, cache, NULL, NULL, use_hide);
GPUVertBuf *vbo = mesh_batch_cache_get_tri_pos_and_normals(rdata, cache, false);
GPUVertBuf *vbo = mesh_batch_cache_get_tri_pos_and_normals(rdata, cache);
for (int i = 0; i < mat_len; i++) {
cache->texpaint_triangles[i] = GPU_batch_create(
GPU_PRIM_TRIS, vbo, el[i]);
@ -5328,7 +5353,7 @@ GPUBatch *DRW_mesh_batch_cache_get_surface_texpaint_single(Mesh *me)
MR_DATATYPE_VERT | MR_DATATYPE_LOOP | MR_DATATYPE_POLY | MR_DATATYPE_LOOPTRI | MR_DATATYPE_LOOPUV;
MeshRenderData *rdata = mesh_render_data_create(me, datatype);
GPUVertBuf *vbo = mesh_batch_cache_get_tri_pos_and_normals(rdata, cache);
GPUVertBuf *vbo = mesh_batch_cache_get_tri_pos_and_normals(rdata, cache, false);
cache->texpaint_triangles_single = GPU_batch_create(
GPU_PRIM_TRIS, vbo, NULL);
@ -5392,7 +5417,7 @@ GPUBatch *DRW_mesh_batch_cache_get_texpaint_loop_wire(Mesh *me)
return cache->texpaint_uv_loops;
}
GPUBatch *DRW_mesh_batch_cache_get_weight_overlay_edges(Mesh *me, bool use_wire, bool use_sel)
GPUBatch *DRW_mesh_batch_cache_get_weight_overlay_edges(Mesh *me, bool use_wire, bool use_sel, bool use_hide)
{
MeshBatchCache *cache = mesh_batch_cache_get(me);
@ -5402,7 +5427,7 @@ GPUBatch *DRW_mesh_batch_cache_get_weight_overlay_edges(Mesh *me, bool use_wire,
MeshRenderData *rdata = mesh_render_data_create(me, datatype);
cache->overlay_paint_edges = GPU_batch_create_ex(
GPU_PRIM_LINES, mesh_create_edge_pos_with_sel(rdata, use_wire, use_sel), NULL, GPU_BATCH_OWNS_VBO);
GPU_PRIM_LINES, mesh_create_edge_pos_with_sel(rdata, use_wire, use_sel, use_hide), NULL, GPU_BATCH_OWNS_VBO);
mesh_render_data_free(rdata);
}

View File

@ -189,6 +189,24 @@ bool DRW_object_is_flat_normal(const Object *ob)
return true;
}
bool DRW_object_use_hide_faces(const struct Object *ob)
{
if (ob->type == OB_MESH) {
const Mesh *me = ob->data;
switch (ob->mode) {
case OB_MODE_TEXTURE_PAINT:
case OB_MODE_VERTEX_PAINT:
return (me->editflag & ME_EDIT_PAINT_FACE_SEL) != 0;
case OB_MODE_WEIGHT_PAINT:
return (me->editflag & (ME_EDIT_PAINT_FACE_SEL | ME_EDIT_PAINT_VERT_SEL)) != 0;
}
}
return false;
}
bool DRW_object_is_visible_psys_in_active_context(
const Object *object,
const ParticleSystem *psys)

View File

@ -645,7 +645,7 @@ static void EDIT_MESH_cache_populate(void *vedata, Object *ob)
}
if (do_occlude_wire) {
geom = DRW_cache_mesh_surface_get(ob);
geom = DRW_cache_mesh_surface_get(ob, false);
DRW_shgroup_call_add(stl->g_data->depth_shgrp_hidden_wire, geom, ob->obmat);
}

View File

@ -291,21 +291,23 @@ static void PAINT_TEXTURE_cache_populate(void *vedata, Object *ob)
Scene *scene = draw_ctx->scene;
const bool use_surface = draw_ctx->v3d->overlay.texture_paint_mode_opacity != 0.0; //DRW_object_is_mode_shade(ob) == true;
const bool use_material_slots = (scene->toolsettings->imapaint.mode == IMAGEPAINT_MODE_MATERIAL);
const bool use_face_sel = (me->editflag & ME_EDIT_PAINT_FACE_SEL) != 0;
bool ok = false;
if (use_surface) {
if (me->mloopuv != NULL) {
if (use_material_slots) {
struct GPUBatch **geom_array = me->totcol ? DRW_cache_mesh_surface_texpaint_get(ob) : NULL;
if (use_material_slots || use_face_sel) {
struct GPUBatch **geom_array = me->totcol ? DRW_cache_mesh_surface_texpaint_get(ob, use_face_sel) : NULL;
if ((me->totcol == 0) || (geom_array == NULL)) {
struct GPUBatch *geom = DRW_cache_mesh_surface_get(ob);
struct GPUBatch *geom = DRW_cache_mesh_surface_get(ob, use_face_sel);
DRW_shgroup_call_add(stl->g_data->shgroup_fallback, geom, ob->obmat);
ok = true;
}
else {
for (int i = 0; i < me->totcol; i++) {
if (stl->g_data->shgroup_image_array[i]) {
DRW_shgroup_call_add(stl->g_data->shgroup_image_array[i], geom_array[i], ob->obmat);
const int index = use_material_slots ? i : 0;
if (stl->g_data->shgroup_image_array[index]) {
DRW_shgroup_call_add(stl->g_data->shgroup_image_array[index], geom_array[i], ob->obmat);
}
else {
DRW_shgroup_call_add(stl->g_data->shgroup_fallback, geom_array[i], ob->obmat);
@ -324,13 +326,12 @@ static void PAINT_TEXTURE_cache_populate(void *vedata, Object *ob)
}
if (!ok) {
struct GPUBatch *geom = DRW_cache_mesh_surface_get(ob);
struct GPUBatch *geom = DRW_cache_mesh_surface_get(ob, use_face_sel);
DRW_shgroup_call_add(stl->g_data->shgroup_fallback, geom, ob->obmat);
}
}
/* Face Mask */
const bool use_face_sel = (me->editflag & ME_EDIT_PAINT_FACE_SEL) != 0;
if (use_face_sel) {
struct GPUBatch *geom;
/* Note: ideally selected faces wouldn't show interior wire. */