Edit Mesh: Add support for draw option parameters
The visuals was already implemented but we could not toggle them off.
This commit is contained in:
parent
c05b9bbcc0
commit
457df4fa9b
|
@ -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. */
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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 */
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue