`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
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,
}
/* 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 = {
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);
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)
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]);
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,
}
}
-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
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);
}
}
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);
}
}
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) {
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);
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);
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);
}
}
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) {
{
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);
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);
../../blentranslation
../../bmesh
../../depsgraph
+ ../../draw
../../gpu
../../imbuf
../../makesdna
#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
* \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;
}
buf_iter++;
}
MEM_freeN((void *)buf);
+
+ if (r_bitmap_len) {
+ *r_bitmap_len = bitmap_len;
+ }
+
return bitmap_buf;
}
* \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;
}
.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;
}
}
}
MEM_freeN((void *)buf);
+
+ if (r_bitmap_len) {
+ *r_bitmap_len = bitmap_len;
+ }
+
return bitmap_buf;
}
* \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;
}
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;
}
MEM_freeN((void *)buf);
MEM_freeN(buf_mask);
+ if (r_bitmap_len) {
+ *r_bitmap_len = bitmap_len;
+ }
+
return bitmap_buf;
}
};
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);
/* 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;
/* 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++) {