Edit Mesh: Add support for draw option parameters
authorClément Foucault <foucault.clem@gmail.com>
Wed, 5 Sep 2018 15:02:00 +0000 (17:02 +0200)
committerClément Foucault <foucault.clem@gmail.com>
Wed, 5 Sep 2018 17:00:13 +0000 (19:00 +0200)
The visuals was already implemented but we could not toggle them off.

source/blender/draw/intern/DRW_render.h
source/blender/draw/intern/draw_cache_impl.h
source/blender/draw/intern/draw_cache_impl_curve.c
source/blender/draw/intern/draw_cache_impl_lattice.c
source/blender/draw/intern/draw_cache_impl_mesh.c
source/blender/draw/intern/draw_manager_data.c
source/blender/draw/modes/edit_mesh_mode.c
source/blender/draw/modes/shaders/edit_lattice_overlay_loosevert_vert.glsl
source/blender/draw/modes/shaders/edit_mesh_overlay_facefill_vert.glsl
source/blender/draw/modes/shaders/edit_mesh_overlay_vert.glsl

index 7c3701266c730cc0f1faf5c0e7b954904facfa5b..eedac5e43c21691b16cfea17e427b99c69ea87f3 100644 (file)
@@ -405,6 +405,7 @@ void DRW_shgroup_uniform_bool(DRWShadingGroup *shgroup, const char *name, const
 void DRW_shgroup_uniform_int(DRWShadingGroup *shgroup, const char *name, const int *value, int arraysize);
 void DRW_shgroup_uniform_ivec2(DRWShadingGroup *shgroup, const char *name, const int *value, int arraysize);
 void DRW_shgroup_uniform_ivec3(DRWShadingGroup *shgroup, const char *name, const int *value, int arraysize);
+void DRW_shgroup_uniform_ivec4(DRWShadingGroup *shgroup, const char *name, const int *value, int arraysize);
 void DRW_shgroup_uniform_mat3(DRWShadingGroup *shgroup, const char *name, const float (*value)[3]);
 void DRW_shgroup_uniform_mat4(DRWShadingGroup *shgroup, const char *name, const float (*value)[4]);
 /* Store value instead of referencing it. */
index bae7e65f5e87ded1a6b7a26643f3a49fab919a4d..d601bfc3a3e61c4e7f835f19e5ab58b3d93e49ba 100644 (file)
@@ -134,6 +134,29 @@ void DRW_mesh_batch_cache_get_wireframes_face_texbuf(
 
 void DRW_mesh_cache_sculpt_coords_ensure(struct Mesh *me);
 
+/* Edit mesh bitflags (is this the right place?) */
+
+enum {
+       VFLAG_VERTEX_ACTIVE   = 1 << 0,
+       VFLAG_VERTEX_SELECTED = 1 << 1,
+       VFLAG_FACE_ACTIVE     = 1 << 2,
+       VFLAG_FACE_SELECTED   = 1 << 3,
+       VFLAG_FACE_FREESTYLE  = 1 << 4,
+       /* Beware to not go over 1 << 7 (it's a byte flag)
+        * (see gpu_shader_edit_mesh_overlay_geom.glsl) */
+};
+
+enum {
+       VFLAG_EDGE_EXISTS   = 1 << 0,
+       VFLAG_EDGE_ACTIVE   = 1 << 1,
+       VFLAG_EDGE_SELECTED = 1 << 2,
+       VFLAG_EDGE_SEAM     = 1 << 3,
+       VFLAG_EDGE_SHARP    = 1 << 4,
+       VFLAG_EDGE_FREESTYLE = 1 << 5,
+       /* Beware to not go over 1 << 7 (it's a byte flag)
+        * (see gpu_shader_edit_mesh_overlay_geom.glsl) */
+};
+
 /* Particles */
 struct GPUBatch *DRW_particles_batch_cache_get_hair(
         struct Object *object, struct ParticleSystem *psys, struct ModifierData *md);
index 3fd8a970db9615875e5bf1b35da4efd08539a91f..bad15dfe69778a7152a168298291375c4f733d16 100644 (file)
@@ -292,10 +292,6 @@ static int curve_render_data_normal_len_get(const CurveRenderData *rdata)
        return rdata->normal.len;
 }
 
-enum {
-       VFLAG_VERTEX_SELECTED = 1 << 0,
-       VFLAG_VERTEX_ACTIVE   = 1 << 1,
-};
 
 /* ---------------------------------------------------------------------- */
 /* Curve GPUBatch Cache */
index 4ffbe7b7546d2948953fd9ae3e93eeafd84dedd3..b077162b41dcc1276faf570a8d286360f37926fb 100644 (file)
@@ -273,11 +273,6 @@ static void lattice_render_data_weight_col_get(const LatticeRenderData *rdata, c
        }
 }
 
-enum {
-       VFLAG_VERTEX_SELECTED = 1 << 0,
-       VFLAG_VERTEX_ACTIVE   = 1 << 1,
-};
-
 /* ---------------------------------------------------------------------- */
 /* Lattice GPUBatch Cache */
 
index 1c70d40d6f1dc945f656f69174acdd5d66470a8d..238d2f28c43e671b3ab0cc3d3a24bfd67bd67227 100644 (file)
@@ -1331,29 +1331,6 @@ static bool mesh_render_data_edge_vcos_manifold_pnors(
        return true;
 }
 
-
-/* First 2 bytes are bit flags
- * 3rd is for sharp edges
- * 4rd is for creased edges */
-enum {
-       VFLAG_VERTEX_ACTIVE   = 1 << 0,
-       VFLAG_VERTEX_SELECTED = 1 << 1,
-       VFLAG_FACE_ACTIVE     = 1 << 2,
-       VFLAG_FACE_SELECTED   = 1 << 3,
-       VFLAG_FACE_FREESTYLE  = 1 << 4,
-};
-
-enum {
-       VFLAG_EDGE_EXISTS   = 1 << 0,
-       VFLAG_EDGE_ACTIVE   = 1 << 1,
-       VFLAG_EDGE_SELECTED = 1 << 2,
-       VFLAG_EDGE_SEAM     = 1 << 3,
-       VFLAG_EDGE_SHARP    = 1 << 4,
-       VFLAG_EDGE_FREESTYLE = 1 << 5,
-       /* Beware to not go over 1 << 7
-        * (see gpu_shader_edit_mesh_overlay_geom.glsl) */
-};
-
 static uchar mesh_render_data_looptri_flag(MeshRenderData *rdata, const BMFace *efa)
 {
        uchar fflag = 0;
index 96e862d243924bbe042a82ec9812de57a5c11318..26507a835537013bd2881accec0b3e3567c2a3fa 100644 (file)
@@ -220,6 +220,11 @@ void DRW_shgroup_uniform_ivec3(DRWShadingGroup *shgroup, const char *name, const
        drw_shgroup_uniform(shgroup, name, DRW_UNIFORM_INT, value, 3, arraysize);
 }
 
+void DRW_shgroup_uniform_ivec4(DRWShadingGroup *shgroup, const char *name, const int *value, int arraysize)
+{
+       drw_shgroup_uniform(shgroup, name, DRW_UNIFORM_INT, value, 4, arraysize);
+}
+
 void DRW_shgroup_uniform_mat3(DRWShadingGroup *shgroup, const char *name, const float (*value)[3])
 {
        drw_shgroup_uniform(shgroup, name, DRW_UNIFORM_FLOAT, (float *)value, 9, 1);
index a79c0e2dc3107242e6f0a2509644425f08124ea9..c68af6803e67dbfe9c831e53f2f18bb796163ead 100644 (file)
@@ -33,6 +33,7 @@
 
 #include "draw_common.h"
 
+#include "draw_cache_impl.h"
 #include "draw_mode_engines.h"
 
 #include "edit_mesh_mode_intern.h" /* own include */
@@ -137,9 +138,11 @@ typedef struct EDIT_MESH_PrivateData {
        DRWShadingGroup *facedot_occluded_shgrp;
        DRWShadingGroup *facefill_occluded_shgrp;
 
+       int data_mask[4];
        int ghost_ob;
        int edit_ob;
        bool do_zbufclip;
+       float edge_width_scale;
 } EDIT_MESH_PrivateData; /* Transient data */
 
 /* *********** FUNCTIONS *********** */
@@ -309,15 +312,15 @@ static void EDIT_MESH_engine_init(void *vedata)
                e_data.ghost_clear_depth_sh = DRW_shader_create(datatoc_edit_mesh_overlay_ghost_clear_vert_glsl,
                                                                NULL, NULL, NULL);
        }
+
 }
 
 static DRWPass *edit_mesh_create_overlay_pass(
-        float *faceAlpha, DRWState statemod,
+        float *face_alpha, float *edge_width_scale, int *data_mask,
+        DRWState statemod,
         DRWShadingGroup **r_face_shgrp, DRWShadingGroup **r_ledges_shgrp,
         DRWShadingGroup **r_lverts_shgrp, DRWShadingGroup **r_facedot_shgrp)
 {
-       static float edge_width_scale;
-
        GPUShader *tri_sh, *ledge_sh;
        const DRWContextState *draw_ctx = DRW_context_state_get();
        RegionView3D *rv3d = draw_ctx->rv3d;
@@ -331,32 +334,30 @@ static DRWPass *edit_mesh_create_overlay_pass(
                "Edit Mesh Face Overlay Pass",
                DRW_STATE_WRITE_COLOR | DRW_STATE_POINT | statemod);
 
-
-       /* Applies on top of the theme edge width, so edge-mode can have thick edges. */
-       edge_width_scale = (tsettings->selectmode & (SCE_SELECT_EDGE)) ? 1.75f : 1.0f;
-
        *r_face_shgrp = DRW_shgroup_create(tri_sh, pass);
        DRW_shgroup_uniform_block(*r_face_shgrp, "globalsBlock", globals_ubo);
        DRW_shgroup_uniform_vec2(*r_face_shgrp, "viewportSize", DRW_viewport_size_get(), 1);
-       DRW_shgroup_uniform_float(*r_face_shgrp, "faceAlphaMod", faceAlpha, 1);
-       DRW_shgroup_uniform_float(*r_face_shgrp, "edgeScale", &edge_width_scale, 1);
+       DRW_shgroup_uniform_float(*r_face_shgrp, "faceAlphaMod", face_alpha, 1);
+       DRW_shgroup_uniform_float(*r_face_shgrp, "edgeScale", edge_width_scale, 1);
+       DRW_shgroup_uniform_ivec4(*r_face_shgrp, "dataMask", data_mask, 1);
 
        *r_ledges_shgrp = DRW_shgroup_create(ledge_sh, pass);
        DRW_shgroup_uniform_block(*r_ledges_shgrp, "globalsBlock", globals_ubo);
        DRW_shgroup_uniform_vec2(*r_ledges_shgrp, "viewportSize", DRW_viewport_size_get(), 1);
-       DRW_shgroup_uniform_float(*r_ledges_shgrp, "edgeScale", &edge_width_scale, 1);
+       DRW_shgroup_uniform_float(*r_ledges_shgrp, "edgeScale", edge_width_scale, 1);
+       DRW_shgroup_uniform_ivec4(*r_ledges_shgrp, "dataMask", data_mask, 1);
 
        if ((tsettings->selectmode & (SCE_SELECT_VERTEX)) != 0) {
                *r_lverts_shgrp = DRW_shgroup_create(e_data.overlay_vert_sh, pass);
                DRW_shgroup_uniform_block(*r_lverts_shgrp, "globalsBlock", globals_ubo);
                DRW_shgroup_uniform_vec2(*r_lverts_shgrp, "viewportSize", DRW_viewport_size_get(), 1);
-               DRW_shgroup_uniform_float(*r_lverts_shgrp, "edgeScale", &edge_width_scale, 1);
+               DRW_shgroup_uniform_float(*r_lverts_shgrp, "edgeScale", edge_width_scale, 1);
        }
 
        if ((tsettings->selectmode & (SCE_SELECT_FACE)) != 0) {
                *r_facedot_shgrp = DRW_shgroup_create(e_data.overlay_facedot_sh, pass);
                DRW_shgroup_uniform_block(*r_facedot_shgrp, "globalsBlock", globals_ubo);
-               DRW_shgroup_uniform_float(*r_facedot_shgrp, "edgeScale", &edge_width_scale, 1);
+               DRW_shgroup_uniform_float(*r_facedot_shgrp, "edgeScale", edge_width_scale, 1);
        }
 
        return pass;
@@ -374,6 +375,8 @@ static void EDIT_MESH_cache_init(void *vedata)
 
        const DRWContextState *draw_ctx = DRW_context_state_get();
        View3D *v3d = draw_ctx->v3d;
+       Scene *scene = draw_ctx->scene;
+       ToolSettings *tsettings = scene->toolsettings;
 
        static float zero = 0.0f;
 
@@ -388,6 +391,38 @@ static void EDIT_MESH_cache_init(void *vedata)
                                   (draw_ctx->v3d->shading.type < OB_MATERIAL);
        stl->g_data->do_zbufclip = ((v3d->flag & V3D_ZBUF_SELECT) == 0) || xray_enabled;
 
+       /* Applies on top of the theme edge width, so edge-mode can have thick edges. */
+       stl->g_data->edge_width_scale = (tsettings->selectmode & (SCE_SELECT_EDGE)) ? 1.75f : 1.0f;
+
+       stl->g_data->data_mask[0] = 0xFF; /* Face Flag */
+       stl->g_data->data_mask[1] = 0xFF; /* Edge Flag */
+       stl->g_data->data_mask[2] = 0xFF; /* Crease */
+       stl->g_data->data_mask[3] = 0xFF; /* BWeight */
+
+       if (draw_ctx->object_edit->type == OB_MESH) {
+               if (BKE_object_is_in_editmode(draw_ctx->object_edit)) {
+                       const Mesh *me = draw_ctx->object_edit->data;
+                       if ((me->drawflag & ME_DRAW_FREESTYLE_FACE) == 0) {
+                               stl->g_data->data_mask[0] &= ~VFLAG_FACE_FREESTYLE;
+                       }
+                       if ((me->drawflag & ME_DRAWSEAMS) == 0) {
+                               stl->g_data->data_mask[1] &= ~VFLAG_EDGE_SEAM;
+                       }
+                       if ((me->drawflag & ME_DRAWSHARP) == 0) {
+                               stl->g_data->data_mask[1] &= ~VFLAG_EDGE_SHARP;
+                       }
+                       if ((me->drawflag & ME_DRAW_FREESTYLE_EDGE) == 0) {
+                               stl->g_data->data_mask[1] &= ~VFLAG_EDGE_FREESTYLE;
+                       }
+                       if ((me->drawflag & ME_DRAWCREASES) == 0) {
+                               stl->g_data->data_mask[2] = 0x0;
+                       }
+                       if ((me->drawflag & ME_DRAWBWEIGHTS) == 0) {
+                               stl->g_data->data_mask[3] = 0x0;
+                       }
+               }
+       }
+
        {
                psl->vcolor_faces = DRW_pass_create(
                        "Vert Color Pass",
@@ -443,14 +478,16 @@ static void EDIT_MESH_cache_init(void *vedata)
 
        if (!stl->g_data->do_zbufclip) {
                psl->edit_face_overlay = edit_mesh_create_overlay_pass(
-                       &face_mod, DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_BLEND,
+                       &face_mod, &stl->g_data->edge_width_scale, stl->g_data->data_mask,
+                       DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_BLEND,
                        &stl->g_data->face_overlay_shgrp, &stl->g_data->ledges_overlay_shgrp,
                        &stl->g_data->lverts_overlay_shgrp, &stl->g_data->facedot_overlay_shgrp);
        }
        else {
                /* We render all wires with depth and opaque to a new fbo and blend the result based on depth values */
                psl->edit_face_occluded = edit_mesh_create_overlay_pass(
-                       &zero, DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_WRITE_DEPTH,
+                       &zero, &stl->g_data->edge_width_scale, stl->g_data->data_mask,
+                       DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_WRITE_DEPTH,
                        &stl->g_data->face_occluded_shgrp, &stl->g_data->ledges_occluded_shgrp,
                        &stl->g_data->lverts_occluded_shgrp, &stl->g_data->facedot_occluded_shgrp);
 
@@ -461,6 +498,7 @@ static void EDIT_MESH_cache_init(void *vedata)
                        DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_BLEND);
                stl->g_data->facefill_occluded_shgrp = DRW_shgroup_create(e_data.overlay_facefill_sh, psl->facefill_occlude);
                DRW_shgroup_uniform_block(stl->g_data->facefill_occluded_shgrp, "globalsBlock", globals_ubo);
+               DRW_shgroup_uniform_ivec4(stl->g_data->facefill_occluded_shgrp, "dataMask", stl->g_data->data_mask, 1);
 
                /* we need a full screen pass to combine the result */
                struct GPUBatch *quad = DRW_cache_fullscreen_quad_get();
index 0cbc66a2b1f7a3a3bfe6caa63821c3e45c9f11c0..fba5d604ccf19b3f4d245056d4fc6d03984f2c1f 100644 (file)
@@ -3,6 +3,7 @@
 
 uniform mat4 ModelViewProjectionMatrix;
 uniform vec2 viewportSize;
+uniform ivec4 dataMask = ivec4(0xFF);
 
 in vec3 pos;
 in int data;
@@ -32,7 +33,7 @@ void main()
        eData1 = eData2 = vec4(1e10);
        eData2.zw = proj(pPos);
 
-       vertFlag = data;
+       vertFlag = data & dataMask;
 
        gl_PointSize = sizeVertex;
        gl_Position = pPos;
index 40ea6b301b40a78fbc72305240046b174d7faa97..068dc3369fb04b85636c4bb410886d64060da82f 100644 (file)
@@ -1,5 +1,6 @@
 
 uniform mat4 ModelViewProjectionMatrix;
+uniform ivec4 dataMask = ivec4(0xFF);
 
 in vec3 pos;
 in ivec4 data;
@@ -14,11 +15,13 @@ void main()
 {
        gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
 
-       if ((data.x & FACE_ACTIVE) != 0)
+       ivec4 data_m = data & dataMask;
+
+       if ((data_m.x & FACE_ACTIVE) != 0)
                faceColor = colorFaceSelect;
-       else if ((data.x & FACE_SELECTED) != 0)
+       else if ((data_m.x & FACE_SELECTED) != 0)
                faceColor = colorFaceSelect;
-       else if ((data.x & FACE_FREESTYLE) != 0)
+       else if ((data_m.x & FACE_FREESTYLE) != 0)
                faceColor = colorFaceFreestyle;
        else
                faceColor = colorFace;
index 8ebfa4376f01c705f324bdb9268b5fde41a72142..7cab2a5035fa2d448a08f69be7e6cd88f7b40157 100644 (file)
@@ -7,6 +7,7 @@
 
 uniform mat4 ModelViewMatrix;
 uniform mat4 ModelViewProjectionMatrix;
+uniform ivec4 dataMask = ivec4(0xFF);
 
 in vec3 pos;
 in ivec4 data;
@@ -27,7 +28,7 @@ void main()
 {
        vPos = ModelViewMatrix * vec4(pos, 1.0);
        pPos = ModelViewProjectionMatrix * vec4(pos, 1.0);
-       vData = data;
+       vData = data & dataMask;
 #ifdef VERTEX_FACING
        vec3 view_normal = normalize(NormalMatrix * vnor);
        vec3 view_vec = (ProjectionMatrix[3][3] == 0.0)