Select utils refactor: remove lagacy `ED_view3d_select_id_read_rect`
`ED_view3d_select_id_read_rect` serves only as a bridge to `DRW_framebuffer_select_id_read`. Keeping these codes similar only increases the complexity of some functions. Reviewers: campbellbarton Differential Revision: https://developer.blender.org/D5415
This commit is contained in:
parent
dafecfa683
commit
9d7d34c12a
|
@ -181,7 +181,7 @@ void DRW_select_context_create(struct Base **bases, const uint bases_len, short
|
|||
bool DRW_select_elem_get(const uint sel_id, uint *r_elem, uint *r_base_index, char *r_elem_type);
|
||||
uint DRW_select_context_offset_for_object_elem(const uint base_index, char elem_type);
|
||||
uint DRW_select_context_elem_len(void);
|
||||
void DRW_framebuffer_select_id_read(const struct rcti *rect, uint *r_buf);
|
||||
uint *DRW_framebuffer_select_id_read(const struct rcti *rect, uint *r_buf_len);
|
||||
void DRW_draw_select_id_object(struct Depsgraph *depsgraph,
|
||||
struct ViewLayer *view_layer,
|
||||
struct ARegion *ar,
|
||||
|
|
|
@ -344,7 +344,7 @@ uint DRW_select_context_elem_len(void)
|
|||
}
|
||||
|
||||
/* Read a block of pixels from the select frame buffer. */
|
||||
void DRW_framebuffer_select_id_read(const rcti *rect, uint *r_buf)
|
||||
uint *DRW_framebuffer_select_id_read(const rcti *rect, uint *r_buf_len)
|
||||
{
|
||||
/* clamp rect by texture */
|
||||
rcti r = {
|
||||
|
@ -356,6 +356,9 @@ void DRW_framebuffer_select_id_read(const rcti *rect, uint *r_buf)
|
|||
|
||||
rcti rect_clamp = *rect;
|
||||
if (BLI_rcti_isect(&r, &rect_clamp, &rect_clamp)) {
|
||||
size_t buf_len = BLI_rcti_size_x(rect) * BLI_rcti_size_y(rect);
|
||||
uint *r_buf = MEM_mallocN(buf_len * sizeof(*r_buf), __func__);
|
||||
|
||||
DRW_opengl_context_enable();
|
||||
GPU_framebuffer_bind(e_data.framebuffer_select_id);
|
||||
glReadBuffer(GL_COLOR_ATTACHMENT0);
|
||||
|
@ -373,12 +376,14 @@ void DRW_framebuffer_select_id_read(const rcti *rect, uint *r_buf)
|
|||
if (!BLI_rcti_compare(rect, &rect_clamp)) {
|
||||
GPU_select_buffer_stride_realign(rect, &rect_clamp, r_buf);
|
||||
}
|
||||
}
|
||||
else {
|
||||
size_t buf_size = BLI_rcti_size_x(rect) * BLI_rcti_size_y(rect) * sizeof(*r_buf);
|
||||
|
||||
memset(r_buf, 0, buf_size);
|
||||
if (r_buf_len) {
|
||||
*r_buf_len = buf_len;
|
||||
}
|
||||
|
||||
return r_buf;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void DRW_select_context_create(Base **UNUSED(bases), const uint bases_len, short select_mode)
|
||||
|
|
|
@ -24,14 +24,14 @@
|
|||
struct rcti;
|
||||
|
||||
/* Boolean array from selection ID's. */
|
||||
uint *ED_select_buffer_bitmap_from_rect(const uint bitmap_len, const struct rcti *rect);
|
||||
uint *ED_select_buffer_bitmap_from_circle(const uint bitmap_len,
|
||||
const int center[2],
|
||||
const int radius);
|
||||
uint *ED_select_buffer_bitmap_from_poly(const uint bitmap_len,
|
||||
const int poly[][2],
|
||||
uint *ED_select_buffer_bitmap_from_rect(const struct rcti *rect, uint *r_bitmap_len);
|
||||
uint *ED_select_buffer_bitmap_from_circle(const int center[2],
|
||||
const int radius,
|
||||
uint *r_bitmap_len);
|
||||
uint *ED_select_buffer_bitmap_from_poly(const int poly[][2],
|
||||
const int poly_len,
|
||||
const rcti *rect);
|
||||
const rcti *rect,
|
||||
uint *r_bitmap_len);
|
||||
|
||||
/* Single result from selection ID's. */
|
||||
uint ED_select_buffer_sample_point(const int center[2]);
|
||||
|
|
|
@ -465,8 +465,6 @@ int ED_view3d_backbuf_sample_size_clamp(struct ARegion *ar, const float dist);
|
|||
|
||||
void ED_view3d_select_id_validate(struct ViewContext *vc);
|
||||
|
||||
uint *ED_view3d_select_id_read_rect(const struct rcti *rect, uint *r_buf_len);
|
||||
|
||||
bool ED_view3d_autodist(struct Depsgraph *depsgraph,
|
||||
struct ARegion *ar,
|
||||
struct View3D *v3d,
|
||||
|
|
|
@ -238,22 +238,6 @@ void ED_view3d_backbuf_depth_validate(ViewContext *vc)
|
|||
}
|
||||
}
|
||||
|
||||
uint *ED_view3d_select_id_read_rect(const rcti *clip, uint *r_buf_len)
|
||||
{
|
||||
uint width = BLI_rcti_size_x(clip);
|
||||
uint height = BLI_rcti_size_y(clip);
|
||||
uint buf_len = width * height;
|
||||
uint *buf = MEM_mallocN(buf_len * sizeof(*buf), __func__);
|
||||
|
||||
DRW_framebuffer_select_id_read(clip, buf);
|
||||
|
||||
if (r_buf_len) {
|
||||
*r_buf_len = buf_len;
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
/**
|
||||
* allow for small values [0.5 - 2.5],
|
||||
* and large values, FLT_MAX by clamping by the area size
|
||||
|
|
|
@ -828,8 +828,7 @@ static bool do_lasso_select_mesh(ViewContext *vc,
|
|||
if (wm_userdata->data == NULL) {
|
||||
editselect_buf_cache_init_with_generic_userdata(wm_userdata, vc, ts->selectmode);
|
||||
esel = wm_userdata->data;
|
||||
const uint buffer_len = DRW_select_context_elem_len();
|
||||
esel->select_bitmap = ED_select_buffer_bitmap_from_poly(buffer_len, mcords, moves, &rect);
|
||||
esel->select_bitmap = ED_select_buffer_bitmap_from_poly(mcords, moves, &rect, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1140,7 +1139,7 @@ static bool do_lasso_select_paintvert(ViewContext *vc,
|
|||
editselect_buf_cache_init_with_generic_userdata(wm_userdata, vc, SCE_SELECT_VERTEX);
|
||||
esel = wm_userdata->data;
|
||||
const uint buffer_len = DRW_select_context_elem_len();
|
||||
esel->select_bitmap = ED_select_buffer_bitmap_from_poly(buffer_len, mcords, moves, &rect);
|
||||
esel->select_bitmap = ED_select_buffer_bitmap_from_poly(mcords, moves, &rect, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1199,7 +1198,7 @@ static bool do_lasso_select_paintface(ViewContext *vc,
|
|||
editselect_buf_cache_init_with_generic_userdata(wm_userdata, vc, SCE_SELECT_FACE);
|
||||
esel = wm_userdata->data;
|
||||
const uint buffer_len = DRW_select_context_elem_len();
|
||||
esel->select_bitmap = ED_select_buffer_bitmap_from_poly(buffer_len, mcords, moves, &rect);
|
||||
esel->select_bitmap = ED_select_buffer_bitmap_from_poly(mcords, moves, &rect, NULL);
|
||||
}
|
||||
|
||||
if (esel->select_bitmap) {
|
||||
|
@ -2554,8 +2553,7 @@ static bool do_paintvert_box_select(ViewContext *vc,
|
|||
if (wm_userdata->data == NULL) {
|
||||
editselect_buf_cache_init_with_generic_userdata(wm_userdata, vc, SCE_SELECT_VERTEX);
|
||||
esel = wm_userdata->data;
|
||||
const uint buffer_len = DRW_select_context_elem_len();
|
||||
esel->select_bitmap = ED_select_buffer_bitmap_from_rect(buffer_len, rect);
|
||||
esel->select_bitmap = ED_select_buffer_bitmap_from_rect(rect, NULL);
|
||||
}
|
||||
if (esel->select_bitmap != NULL) {
|
||||
changed |= edbm_backbuf_check_and_select_verts_obmode(me, esel, sel_op);
|
||||
|
@ -2609,8 +2607,7 @@ static bool do_paintface_box_select(ViewContext *vc,
|
|||
if (wm_userdata->data == NULL) {
|
||||
editselect_buf_cache_init_with_generic_userdata(wm_userdata, vc, SCE_SELECT_FACE);
|
||||
esel = wm_userdata->data;
|
||||
const uint buffer_len = DRW_select_context_elem_len();
|
||||
esel->select_bitmap = ED_select_buffer_bitmap_from_rect(buffer_len, rect);
|
||||
esel->select_bitmap = ED_select_buffer_bitmap_from_rect(rect, NULL);
|
||||
}
|
||||
if (esel->select_bitmap != NULL) {
|
||||
changed |= edbm_backbuf_check_and_select_faces_obmode(me, esel, sel_op);
|
||||
|
@ -2807,8 +2804,7 @@ static bool do_mesh_box_select(ViewContext *vc,
|
|||
if (wm_userdata->data == NULL) {
|
||||
editselect_buf_cache_init_with_generic_userdata(wm_userdata, vc, ts->selectmode);
|
||||
esel = wm_userdata->data;
|
||||
const uint buffer_len = DRW_select_context_elem_len();
|
||||
esel->select_bitmap = ED_select_buffer_bitmap_from_rect(buffer_len, rect);
|
||||
esel->select_bitmap = ED_select_buffer_bitmap_from_rect(rect, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3395,8 +3391,7 @@ static bool mesh_circle_select(ViewContext *vc,
|
|||
struct EditSelectBuf_Cache *esel = wm_userdata->data;
|
||||
|
||||
if (use_zbuf) {
|
||||
const uint buffer_len = DRW_select_context_elem_len();
|
||||
esel->select_bitmap = ED_select_buffer_bitmap_from_circle(buffer_len, mval, (int)(rad + 1.0f));
|
||||
esel->select_bitmap = ED_select_buffer_bitmap_from_circle(mval, (int)(rad + 1.0f), NULL);
|
||||
}
|
||||
|
||||
if (ts->selectmode & SCE_SELECT_VERTEX) {
|
||||
|
@ -3473,8 +3468,7 @@ static bool paint_facesel_circle_select(ViewContext *vc,
|
|||
|
||||
{
|
||||
struct EditSelectBuf_Cache *esel = wm_userdata->data;
|
||||
const uint buffer_len = DRW_select_context_elem_len();
|
||||
esel->select_bitmap = ED_select_buffer_bitmap_from_circle(buffer_len, mval, (int)(rad + 1.0f));
|
||||
esel->select_bitmap = ED_select_buffer_bitmap_from_circle(mval, (int)(rad + 1.0f), NULL);
|
||||
if (esel->select_bitmap != NULL) {
|
||||
changed |= edbm_backbuf_check_and_select_faces_obmode(me, esel, sel_op);
|
||||
MEM_freeN(esel->select_bitmap);
|
||||
|
@ -3528,8 +3522,7 @@ static bool paint_vertsel_circle_select(ViewContext *vc,
|
|||
|
||||
if (use_zbuf) {
|
||||
struct EditSelectBuf_Cache *esel = wm_userdata->data;
|
||||
const uint buffer_len = DRW_select_context_elem_len();
|
||||
esel->select_bitmap = ED_select_buffer_bitmap_from_circle(buffer_len, mval, (int)(rad + 1.0f));
|
||||
esel->select_bitmap = ED_select_buffer_bitmap_from_circle(mval, (int)(rad + 1.0f), NULL);
|
||||
if (esel->select_bitmap != NULL) {
|
||||
changed |= edbm_backbuf_check_and_select_verts_obmode(me, esel, sel_op);
|
||||
MEM_freeN(esel->select_bitmap);
|
||||
|
|
|
@ -22,6 +22,7 @@ set(INC
|
|||
../../blentranslation
|
||||
../../bmesh
|
||||
../../depsgraph
|
||||
../../draw
|
||||
../../gpu
|
||||
../../imbuf
|
||||
../../makesdna
|
||||
|
|
|
@ -33,12 +33,9 @@
|
|||
#include "BLI_rect.h"
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
#include "ED_select_buffer_utils.h"
|
||||
#include "DRW_engine.h"
|
||||
|
||||
/* Only for #ED_view3d_select_id_read,
|
||||
* note that this file shouldn't have 3D view specific logic in it, we could have a more general
|
||||
* way to read from selection buffers that doesn't depend on the view3d API. */
|
||||
#include "ED_view3d.h"
|
||||
#include "ED_select_buffer_utils.h"
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Select Bitmap from ID's
|
||||
|
@ -53,14 +50,20 @@
|
|||
* \param rect: The rectangle to sample indices from (min/max inclusive).
|
||||
* \returns a #BLI_bitmap the length of \a bitmap_len or NULL on failure.
|
||||
*/
|
||||
uint *ED_select_buffer_bitmap_from_rect(const uint bitmap_len, const rcti *rect)
|
||||
uint *ED_select_buffer_bitmap_from_rect(const rcti *rect, uint *r_bitmap_len)
|
||||
{
|
||||
const uint bitmap_len = DRW_select_context_elem_len();
|
||||
if (bitmap_len == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rcti rect_px = *rect;
|
||||
rect_px.xmax += 1;
|
||||
rect_px.ymax += 1;
|
||||
|
||||
uint buf_len;
|
||||
const uint *buf = ED_view3d_select_id_read_rect(&rect_px, &buf_len);
|
||||
const uint *buf = DRW_framebuffer_select_id_read(&rect_px, &buf_len);
|
||||
|
||||
if (buf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -77,6 +80,11 @@ uint *ED_select_buffer_bitmap_from_rect(const uint bitmap_len, const rcti *rect)
|
|||
buf_iter++;
|
||||
}
|
||||
MEM_freeN((void *)buf);
|
||||
|
||||
if (r_bitmap_len) {
|
||||
*r_bitmap_len = bitmap_len;
|
||||
}
|
||||
|
||||
return bitmap_buf;
|
||||
}
|
||||
|
||||
|
@ -86,10 +94,11 @@ uint *ED_select_buffer_bitmap_from_rect(const uint bitmap_len, const rcti *rect)
|
|||
* \param radius: Circle radius.
|
||||
* \returns a #BLI_bitmap the length of \a bitmap_len or NULL on failure.
|
||||
*/
|
||||
uint *ED_select_buffer_bitmap_from_circle(const uint bitmap_len,
|
||||
const int center[2],
|
||||
const int radius)
|
||||
uint *ED_select_buffer_bitmap_from_circle(const int center[2],
|
||||
const int radius,
|
||||
uint *r_bitmap_len)
|
||||
{
|
||||
const uint bitmap_len = DRW_select_context_elem_len();
|
||||
if (bitmap_len == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -101,7 +110,8 @@ uint *ED_select_buffer_bitmap_from_circle(const uint bitmap_len,
|
|||
.ymax = center[1] + radius + 1,
|
||||
};
|
||||
|
||||
const uint *buf = ED_view3d_select_id_read_rect(&rect, NULL);
|
||||
const uint *buf = DRW_framebuffer_select_id_read(&rect, NULL);
|
||||
|
||||
if (buf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -122,6 +132,11 @@ uint *ED_select_buffer_bitmap_from_circle(const uint bitmap_len,
|
|||
}
|
||||
}
|
||||
MEM_freeN((void *)buf);
|
||||
|
||||
if (r_bitmap_len) {
|
||||
*r_bitmap_len = bitmap_len;
|
||||
}
|
||||
|
||||
return bitmap_buf;
|
||||
}
|
||||
|
||||
|
@ -147,12 +162,13 @@ static void ed_select_buffer_mask_px_cb(int x, int x_end, int y, void *user_data
|
|||
* \param radius: Circle radius.
|
||||
* \returns a #BLI_bitmap the length of \a bitmap_len or NULL on failure.
|
||||
*/
|
||||
uint *ED_select_buffer_bitmap_from_poly(const uint bitmap_len,
|
||||
const int poly[][2],
|
||||
uint *ED_select_buffer_bitmap_from_poly(const int poly[][2],
|
||||
const int poly_len,
|
||||
const rcti *rect)
|
||||
const rcti *rect,
|
||||
uint *r_bitmap_len)
|
||||
|
||||
{
|
||||
const uint bitmap_len = DRW_select_context_elem_len();
|
||||
if (bitmap_len == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -163,7 +179,8 @@ uint *ED_select_buffer_bitmap_from_poly(const uint bitmap_len,
|
|||
|
||||
struct PolyMaskData poly_mask_data;
|
||||
uint buf_len;
|
||||
const uint *buf = ED_view3d_select_id_read_rect(&rect_px, &buf_len);
|
||||
const uint *buf = DRW_framebuffer_select_id_read(&rect_px, &buf_len);
|
||||
|
||||
if (buf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -196,6 +213,10 @@ uint *ED_select_buffer_bitmap_from_poly(const uint bitmap_len,
|
|||
MEM_freeN((void *)buf);
|
||||
MEM_freeN(buf_mask);
|
||||
|
||||
if (r_bitmap_len) {
|
||||
*r_bitmap_len = bitmap_len;
|
||||
}
|
||||
|
||||
return bitmap_buf;
|
||||
}
|
||||
|
||||
|
@ -221,7 +242,7 @@ uint ED_select_buffer_sample_point(const int center[2])
|
|||
};
|
||||
|
||||
uint buf_len;
|
||||
uint *buf = ED_view3d_select_id_read_rect(&rect, &buf_len);
|
||||
uint *buf = DRW_framebuffer_select_id_read(&rect, &buf_len);
|
||||
BLI_assert(0 != buf_len);
|
||||
uint ret = buf[0];
|
||||
MEM_freeN(buf);
|
||||
|
@ -243,6 +264,9 @@ uint ED_select_buffer_find_nearest_to_point(const int center[2],
|
|||
/* Create region around center (typically the mouse cursor).
|
||||
* This must be square and have an odd width,
|
||||
* the spiraling algorithm does not work with arbitrary rectangles. */
|
||||
|
||||
uint index = 0;
|
||||
|
||||
rcti rect;
|
||||
BLI_rcti_init_pt_radius(&rect, center, *dist);
|
||||
rect.xmax += 1;
|
||||
|
@ -255,15 +279,18 @@ uint ED_select_buffer_find_nearest_to_point(const int center[2],
|
|||
/* Read from selection framebuffer. */
|
||||
|
||||
uint buf_len;
|
||||
const uint *buf = ED_view3d_select_id_read_rect(&rect, &buf_len);
|
||||
const uint *buf = DRW_framebuffer_select_id_read(&rect, &buf_len);
|
||||
|
||||
if (buf == NULL) {
|
||||
return index;
|
||||
}
|
||||
|
||||
BLI_assert(width * height == buf_len);
|
||||
|
||||
/* Spiral, starting from center of buffer. */
|
||||
int spiral_offset = height * (int)(width / 2) + (height / 2);
|
||||
int spiral_direction = 0;
|
||||
|
||||
uint index = 0;
|
||||
|
||||
for (int nr = 1; nr <= height; nr++) {
|
||||
for (int a = 0; a < 2; a++) {
|
||||
for (int b = 0; b < nr; b++) {
|
||||
|
|
Loading…
Reference in New Issue