diff options
author | mano-wii <germano.costa@ig.com.br> | 2019-03-15 22:02:55 +0300 |
---|---|---|
committer | mano-wii <germano.costa@ig.com.br> | 2019-03-15 23:02:48 +0300 |
commit | 681661dbed121c7b81e9129c57df5eadb03c1009 (patch) | |
tree | 8802195c72af13e1bb7324131024cc98fb5971a7 /source/blender/editors/mesh | |
parent | 4510f88d00a721a3d4ad3aa675050723eec2292c (diff) |
GPU: Simplify select shaders.
The shaders are: `GPU_SHADER_3D_FLAT_SELECT_ID` and `GPU_SHADER_3D_UNIFORM_SELECT_ID`.
This commit allows the drawing of the mesh select ids to be done on a 32UI format texture.
This simplifies the shader that previously acted on the backbuffer and had to do an uint to rgba conversion.
Differential Revision: https://developer.blender.org/D4350
Diffstat (limited to 'source/blender/editors/mesh')
-rw-r--r-- | source/blender/editors/mesh/editface.c | 30 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_select.c | 67 | ||||
-rw-r--r-- | source/blender/editors/mesh/meshtools.c | 29 |
3 files changed, 54 insertions, 72 deletions
diff --git a/source/blender/editors/mesh/editface.c b/source/blender/editors/mesh/editface.c index 5afde1b3ba1..e226985300c 100644 --- a/source/blender/editors/mesh/editface.c +++ b/source/blender/editors/mesh/editface.c @@ -272,7 +272,7 @@ void paintface_select_linked(bContext *C, Object *ob, const int mval[2], const b if (me == NULL || me->totpoly == 0) return; if (mval) { - if (!ED_mesh_pick_face(C, ob, mval, &index, ED_MESH_PICK_DEFAULT_FACE_SIZE)) { + if (!ED_mesh_pick_face(C, ob, mval, &index, ED_MESH_PICK_DEFAULT_FACE_DIST)) { return; } } @@ -374,7 +374,7 @@ bool paintface_mouse_select(struct bContext *C, Object *ob, const int mval[2], b /* Get the face under the cursor */ me = BKE_mesh_from_object(ob); - if (!ED_mesh_pick_face(C, ob, mval, &index, ED_MESH_PICK_DEFAULT_FACE_SIZE)) + if (!ED_mesh_pick_face(C, ob, mval, &index, ED_MESH_PICK_DEFAULT_FACE_DIST)) return false; if (index >= me->totpoly) @@ -418,22 +418,17 @@ bool paintface_mouse_select(struct bContext *C, Object *ob, const int mval[2], b return true; } -int do_paintface_box_select(ViewContext *vc, rcti *rect, int sel_op) +int do_paintface_box_select(ViewContext *vc, const rcti *rect, int sel_op) { Object *ob = vc->obact; Mesh *me; MPoly *mpoly; - struct ImBuf *ibuf; - unsigned int *rt; + uint *rt; char *selar; int a, index; - const int size[2] = { - BLI_rcti_size_x(rect) + 1, - BLI_rcti_size_y(rect) + 1}; me = BKE_mesh_from_object(ob); - - if ((me == NULL) || (me->totpoly == 0) || (size[0] * size[1] <= 0)) { + if ((me == NULL) || (me->totpoly == 0) || BLI_rcti_is_empty(rect)) { return OPERATOR_CANCELLED; } @@ -443,17 +438,12 @@ int do_paintface_box_select(ViewContext *vc, rcti *rect, int sel_op) paintface_deselect_all_visible(vc->C, vc->obact, SEL_DESELECT, false); } - ED_view3d_backbuf_validate(vc); + uint buf_len; + uint *buf = ED_view3d_select_id_read_rect(vc, rect, &buf_len); - ibuf = IMB_allocImBuf(size[0], size[1], 32, IB_rect); - rt = ibuf->rect; - view3d_opengl_read_pixels(vc->ar, rect->xmin, rect->ymin, size[0], size[1], GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect); - if (ENDIAN_ORDER == B_ENDIAN) { - IMB_convert_rgba_to_abgr(ibuf); - } - GPU_select_to_index_array(ibuf->rect, size[0] * size[1]); + rt = buf; - a = size[0] * size[1]; + a = buf_len; while (a--) { if (*rt) { index = *rt; @@ -476,7 +466,7 @@ int do_paintface_box_select(ViewContext *vc, rcti *rect, int sel_op) } } - IMB_freeImBuf(ibuf); + MEM_freeN(buf); MEM_freeN(selar); #ifdef __APPLE__ diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c index 80d23f37e71..991e0f94383 100644 --- a/source/blender/editors/mesh/editmesh_select.c +++ b/source/blender/editors/mesh/editmesh_select.c @@ -213,32 +213,29 @@ bool EDBM_backbuf_border_init( ViewContext *vc, short xmin, short ymin, short xmax, short ymax) { - struct ImBuf *buf; - unsigned int *dr; - int a; + uint *buf, *dr, buf_len; if (vc->obedit == NULL || !V3D_IS_ZBUF(vc->v3d)) { return false; } - buf = ED_view3d_backbuf_read(vc, xmin, ymin, xmax, ymax); + buf = ED_view3d_select_id_read(vc, xmin, ymin, xmax, ymax, &buf_len); if ((buf == NULL) || (bm_vertoffs == 0)) { return false; } - dr = buf->rect; + dr = buf; /* build selection lookup */ selbuf = edbm_backbuf_alloc(bm_vertoffs + 1); - a = (xmax - xmin + 1) * (ymax - ymin + 1); - while (a--) { + while (buf_len--) { if (*dr > 0 && *dr <= bm_vertoffs) { BLI_BITMAP_ENABLE(selbuf, *dr); } dr++; } - IMB_freeImBuf(buf); + MEM_freeN(buf); return true; } @@ -286,9 +283,7 @@ static void edbm_mask_lasso_px_cb(int x, int x_end, int y, void *user_data) */ bool EDBM_backbuf_border_mask_init(ViewContext *vc, const int mcords[][2], short tot, short xmin, short ymin, short xmax, short ymax) { - unsigned int *dr, *dr_mask, *dr_mask_arr; - struct ImBuf *buf; - int a; + uint *buf, *dr, *dr_mask, *dr_mask_arr, buf_len; struct LassoMaskData lasso_mask_data; /* method in use for face selecting too */ @@ -301,14 +296,14 @@ bool EDBM_backbuf_border_mask_init(ViewContext *vc, const int mcords[][2], short return false; } - buf = ED_view3d_backbuf_read(vc, xmin, ymin, xmax, ymax); + buf = ED_view3d_select_id_read(vc, xmin, ymin, xmax, ymax, &buf_len); if ((buf == NULL) || (bm_vertoffs == 0)) { return false; } - dr = buf->rect; + dr = buf; - dr_mask = dr_mask_arr = MEM_callocN(sizeof(*dr_mask) * buf->x * buf->y, __func__); + dr_mask = dr_mask_arr = MEM_callocN(sizeof(*dr_mask) * buf_len, __func__); lasso_mask_data.px = dr_mask; lasso_mask_data.width = (xmax - xmin) + 1; @@ -320,14 +315,13 @@ bool EDBM_backbuf_border_mask_init(ViewContext *vc, const int mcords[][2], short /* build selection lookup */ selbuf = edbm_backbuf_alloc(bm_vertoffs + 1); - a = (xmax - xmin + 1) * (ymax - ymin + 1); - while (a--) { + while (buf_len--) { if (*dr > 0 && *dr <= bm_vertoffs && *dr_mask == true) { BLI_BITMAP_ENABLE(selbuf, *dr); } dr++; dr_mask++; } - IMB_freeImBuf(buf); + MEM_freeN(buf); MEM_freeN(dr_mask_arr); return true; @@ -338,8 +332,7 @@ bool EDBM_backbuf_circle_init( ViewContext *vc, short xs, short ys, short rads) { - struct ImBuf *buf; - unsigned int *dr; + uint *buf, *dr; short xmin, ymin, xmax, ymax, xc, yc; int radsq; @@ -355,12 +348,12 @@ bool EDBM_backbuf_circle_init( xmin = xs - rads; xmax = xs + rads; ymin = ys - rads; ymax = ys + rads; - buf = ED_view3d_backbuf_read(vc, xmin, ymin, xmax, ymax); + buf = ED_view3d_select_id_read(vc, xmin, ymin, xmax, ymax, NULL); if ((buf == NULL) || (bm_vertoffs == 0)) { return false; } - dr = buf->rect; + dr = buf; /* build selection lookup */ selbuf = edbm_backbuf_alloc(bm_vertoffs + 1); @@ -375,7 +368,7 @@ bool EDBM_backbuf_circle_init( } } - IMB_freeImBuf(buf); + MEM_freeN(buf); return true; } @@ -472,26 +465,24 @@ BMVert *EDBM_vert_find_nearest_ex( BMesh *bm = vc->em->bm; if (V3D_IS_ZBUF(vc->v3d)) { - const int dist_px = ED_view3d_backbuf_sample_size_clamp(vc->ar, *r_dist); - float dist_test; + uint dist_px = (uint)ED_view3d_backbuf_sample_size_clamp(vc->ar, *r_dist); unsigned int index; BMVert *eve; /* No afterqueue (yet), so we check it now, otherwise the bm_xxxofs indices are bad. */ { FAKE_SELECT_MODE_BEGIN(vc, fake_select_mode, select_mode, SCE_SELECT_VERTEX); - ED_view3d_backbuf_validate_with_select_mode(vc, select_mode); + ED_view3d_select_id_validate_with_select_mode(vc, select_mode); - index = ED_view3d_backbuf_sample_rect( - vc, vc->mval, dist_px, bm_wireoffs, 0xFFFFFF, &dist_test); + index = ED_view3d_select_id_read_nearest(vc, vc->mval, bm_wireoffs, 0xFFFFFF, &dist_px); eve = index ? BM_vert_at_index_find_or_table(bm, index - 1) : NULL; FAKE_SELECT_MODE_END(vc, fake_select_mode); } if (eve) { - if (dist_test < *r_dist) { - *r_dist = dist_test; + if (dist_px < *r_dist) { + *r_dist = dist_px; return eve; } } @@ -665,17 +656,16 @@ BMEdge *EDBM_edge_find_nearest_ex( BMesh *bm = vc->em->bm; if (V3D_IS_ZBUF(vc->v3d)) { - const int dist_px = ED_view3d_backbuf_sample_size_clamp(vc->ar, *r_dist); - float dist_test = 0.0f; + uint dist_px = (uint)ED_view3d_backbuf_sample_size_clamp(vc->ar, *r_dist); unsigned int index; BMEdge *eed; /* No afterqueue (yet), so we check it now, otherwise the bm_xxxofs indices are bad. */ { FAKE_SELECT_MODE_BEGIN(vc, fake_select_mode, select_mode, SCE_SELECT_EDGE); - ED_view3d_backbuf_validate_with_select_mode(vc, select_mode); + ED_view3d_select_id_validate_with_select_mode(vc, select_mode); - index = ED_view3d_backbuf_sample_rect(vc, vc->mval, dist_px, bm_solidoffs, bm_wireoffs, &dist_test); + index = ED_view3d_select_id_read_nearest(vc, vc->mval, bm_solidoffs, bm_wireoffs, &dist_px); eed = index ? BM_edge_at_index_find_or_table(bm, index - 1) : NULL; FAKE_SELECT_MODE_END(vc, fake_select_mode); @@ -703,8 +693,8 @@ BMEdge *EDBM_edge_find_nearest_ex( /* end exception */ if (eed) { - if (dist_test < *r_dist) { - *r_dist = dist_test; + if (dist_px < *r_dist) { + *r_dist = dist_px; return eed; } } @@ -842,9 +832,9 @@ BMFace *EDBM_face_find_nearest_ex( { FAKE_SELECT_MODE_BEGIN(vc, fake_select_mode, select_mode, SCE_SELECT_FACE); - ED_view3d_backbuf_validate_with_select_mode(vc, select_mode); + ED_view3d_select_id_validate_with_select_mode(vc, select_mode); - index = ED_view3d_backbuf_sample(vc, vc->mval[0], vc->mval[1]); + index = ED_view3d_select_id_sample(vc, vc->mval[0], vc->mval[1]); efa = index ? BM_face_at_index_find_or_table(bm, index - 1) : NULL; FAKE_SELECT_MODE_END(vc, fake_select_mode); @@ -974,7 +964,6 @@ static bool unified_findnearest( Object *obedit = base_iter->object; ED_view3d_viewcontext_init_object(vc, obedit); BLI_assert(vc->em->selectmode == em->selectmode); - ED_view3d_backbuf_validate(vc); BMFace *efa_zbuf = NULL; BMFace *efa_test = EDBM_face_find_nearest_ex(vc, &dist, dist_center_p, true, use_cycle, &efa_zbuf); if (efa_test && dist_center_p) { @@ -999,7 +988,6 @@ static bool unified_findnearest( Base *base_iter = bases[base_index]; Object *obedit = base_iter->object; ED_view3d_viewcontext_init_object(vc, obedit); - ED_view3d_backbuf_validate(vc); BMEdge *eed_zbuf = NULL; BMEdge *eed_test = EDBM_edge_find_nearest_ex(vc, &dist, dist_center_p, true, use_cycle, &eed_zbuf); if (eed_test && dist_center_p) { @@ -1021,7 +1009,6 @@ static bool unified_findnearest( Base *base_iter = bases[base_index]; Object *obedit = base_iter->object; ED_view3d_viewcontext_init_object(vc, obedit); - ED_view3d_backbuf_validate(vc); BMVert *eve_test = EDBM_vert_find_nearest_ex(vc, &dist, true, use_cycle); if (eve_test) { hit.v.base_index = base_index; diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index 2b8535f868b..952690775b7 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -1014,7 +1014,7 @@ int *mesh_get_x_mirror_faces(Object *ob, BMEditMesh *em, Mesh *me_eval) * * \return boolean true == Found */ -bool ED_mesh_pick_face(bContext *C, Object *ob, const int mval[2], unsigned int *index, int size) +bool ED_mesh_pick_face(bContext *C, Object *ob, const int mval[2], unsigned int *index, int dist_px) { ViewContext vc; Mesh *me = ob->data; @@ -1026,16 +1026,18 @@ bool ED_mesh_pick_face(bContext *C, Object *ob, const int mval[2], unsigned int ED_view3d_viewcontext_init(C, &vc); - if (size) { + if (dist_px) { /* sample rect to increase chances of selecting, so that when clicking * on an edge in the backbuf, we can still select a face */ - float dummy_dist; - *index = ED_view3d_backbuf_sample_rect(&vc, mval, size, 1, me->totpoly + 1, &dummy_dist); + ED_view3d_select_id_validate(&vc); + + *index = ED_view3d_select_id_read_nearest( + &vc, mval, 1, me->totpoly + 1, &dist_px); } else { /* sample only on the exact position */ - *index = ED_view3d_backbuf_sample(&vc, mval[0], mval[1]); + *index = ED_view3d_select_id_sample(&vc, mval[0], mval[1]); } if ((*index) == 0 || (*index) > (unsigned int)me->totpoly) @@ -1045,6 +1047,7 @@ bool ED_mesh_pick_face(bContext *C, Object *ob, const int mval[2], unsigned int return true; } + static void ed_mesh_pick_face_vert__mpoly_find( /* context */ struct ARegion *ar, const float mval[2], @@ -1073,7 +1076,7 @@ static void ed_mesh_pick_face_vert__mpoly_find( * Use when the back buffer stores face index values. but we want a vert. * This gets the face then finds the closest vertex to mval. */ -bool ED_mesh_pick_face_vert(bContext *C, Object *ob, const int mval[2], unsigned int *index, int size) +bool ED_mesh_pick_face_vert(bContext *C, Object *ob, const int mval[2], unsigned int *index, int dist_px) { Depsgraph *depsgraph = CTX_data_depsgraph(C); unsigned int poly_index; @@ -1081,7 +1084,7 @@ bool ED_mesh_pick_face_vert(bContext *C, Object *ob, const int mval[2], unsigned BLI_assert(me && GS(me->id.name) == ID_ME); - if (ED_mesh_pick_face(C, ob, mval, &poly_index, size)) { + if (ED_mesh_pick_face(C, ob, mval, &poly_index, dist_px)) { Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); struct ARegion *ar = CTX_wm_region(C); @@ -1181,7 +1184,7 @@ static void ed_mesh_pick_vert__mapFunc(void *userData, int index, const float co } } } -bool ED_mesh_pick_vert(bContext *C, Object *ob, const int mval[2], unsigned int *index, int size, bool use_zbuf) +bool ED_mesh_pick_vert(bContext *C, Object *ob, const int mval[2], unsigned int *index, int dist_px, bool use_zbuf) { ViewContext vc; Mesh *me = ob->data; @@ -1194,16 +1197,18 @@ bool ED_mesh_pick_vert(bContext *C, Object *ob, const int mval[2], unsigned int ED_view3d_viewcontext_init(C, &vc); if (use_zbuf) { - if (size > 0) { + if (dist_px > 0) { /* sample rect to increase chances of selecting, so that when clicking * on an face in the backbuf, we can still select a vert */ - float dummy_dist; - *index = ED_view3d_backbuf_sample_rect(&vc, mval, size, 1, me->totvert + 1, &dummy_dist); + ED_view3d_select_id_validate(&vc); + + *index = ED_view3d_select_id_read_nearest( + &vc, mval, 1, me->totvert + 1, &dist_px); } else { /* sample only on the exact position */ - *index = ED_view3d_backbuf_sample(&vc, mval[0], mval[1]); + *index = ED_view3d_select_id_sample(&vc, mval[0], mval[1]); } if ((*index) == 0 || (*index) > (unsigned int)me->totvert) |