Commit: 764cc75e1f92abefa3adf4ece3bbfe99e5227599 Author: mano-wii Date: Wed Aug 7 12:43:04 2019 -0300 Branches: master https://developer.blender.org/rB764cc75e1f92abefa3adf4ece3bbfe99e5227599
Edit Mesh Selection: Move ED_view3d_select_ functions to bf_draw It is easier to deal with private values of the DRW_select engine and gives room for improvement. Reviewers: campbellbarton, fclem Differential Revision: https://developer.blender.org/D5415 =================================================================== M source/blender/draw/CMakeLists.txt M source/blender/draw/DRW_engine.h A source/blender/draw/DRW_select_buffer.h R053 source/blender/editors/util/select_buffer_utils.c source/blender/draw/engines/select/select_buffer.c M source/blender/draw/engines/select/select_draw_utils.c M source/blender/draw/engines/select/select_engine.c M source/blender/draw/engines/select/select_private.h M source/blender/draw/intern/draw_manager.c D source/blender/editors/include/ED_select_buffer_utils.h M source/blender/editors/mesh/editmesh_select.c M source/blender/editors/mesh/meshtools.c M source/blender/editors/sculpt_paint/CMakeLists.txt M source/blender/editors/sculpt_paint/paint_utils.c M source/blender/editors/space_view3d/view3d_draw_legacy.c M source/blender/editors/space_view3d/view3d_select.c M source/blender/editors/util/CMakeLists.txt =================================================================== diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt index 8dc4972bcc1..27328084f31 100644 --- a/source/blender/draw/CMakeLists.txt +++ b/source/blender/draw/CMakeLists.txt @@ -129,8 +129,10 @@ set(SRC engines/gpencil/gpencil_shader_fx.c engines/select/select_engine.c engines/select/select_draw_utils.c + engines/select/select_buffer.c DRW_engine.h + DRW_select_buffer.h intern/DRW_render.h intern/draw_cache.h intern/draw_cache_impl.h diff --git a/source/blender/draw/DRW_engine.h b/source/blender/draw/DRW_engine.h index 87a96740c56..53cec599b82 100644 --- a/source/blender/draw/DRW_engine.h +++ b/source/blender/draw/DRW_engine.h @@ -176,17 +176,4 @@ void DRW_deferred_shader_remove(struct GPUMaterial *mat); struct DrawDataList *DRW_drawdatalist_from_id(struct ID *id); void DRW_drawdata_free(struct ID *id); -/* select_engine.c */ -void DRW_select_context_create(struct Base **bases, const uint bases_len, short select_mode); -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); -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, - struct View3D *v3d, - struct Object *ob, - short select_mode); - #endif /* __DRW_ENGINE_H__ */ diff --git a/source/blender/draw/DRW_select_buffer.h b/source/blender/draw/DRW_select_buffer.h new file mode 100644 index 00000000000..cc3cb94175a --- /dev/null +++ b/source/blender/draw/DRW_select_buffer.h @@ -0,0 +1,65 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright 2016, Blender Foundation. + */ + +/** \file + * \ingroup draw + */ + +#ifndef __DRW_SELECT_BUFFER_H__ +#define __DRW_SELECT_BUFFER_H__ + +#include "BLI_sys_types.h" /* for bool and uint */ + +struct ARegion; +struct Base; +struct Depsgraph; +struct Object; +struct View3D; +struct ViewLayer; +struct rcti; + +/* select_buffer.c */ +void DRW_select_buffer_context_create(struct Base **bases, + const uint bases_len, + short select_mode); +bool DRW_select_buffer_elem_get(const uint sel_id, + uint *r_elem, + uint *r_base_index, + char *r_elem_type); +uint DRW_select_buffer_context_offset_for_object_elem(const uint base_index, char elem_type); +uint *DRW_select_buffer_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, + struct View3D *v3d, + struct Object *ob, + short select_mode); +uint *DRW_select_buffer_bitmap_from_rect(const struct rcti *rect, uint *r_bitmap_len); +uint *DRW_select_buffer_bitmap_from_circle(const int center[2], + const int radius, + uint *r_bitmap_len); +uint *DRW_select_buffer_bitmap_from_poly(const int poly[][2], + const int poly_len, + const struct rcti *rect); +uint DRW_select_buffer_sample_point(const int center[2]); +uint DRW_select_buffer_find_nearest_to_point(const int center[2], + const uint id_min, + const uint id_max, + uint *dist); + +#endif /* __DRW_SELECT_BUFFER_H__ */ diff --git a/source/blender/editors/util/select_buffer_utils.c b/source/blender/draw/engines/select/select_buffer.c similarity index 53% rename from source/blender/editors/util/select_buffer_utils.c rename to source/blender/draw/engines/select/select_buffer.c index df5864d3dd1..6ee62a59cb5 100644 --- a/source/blender/editors/util/select_buffer_utils.c +++ b/source/blender/draw/engines/select/select_buffer.c @@ -13,17 +13,13 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * The Original Code is Copyright (C) 2008 Blender Foundation. - * All rights reserved. + * Copyright 2019, Blender Foundation. */ /** \file - * \ingroup edutil + * \ingroup draw_engine * - * Generic utilities for handling buffer selection where selection ID's are drawn onto - * an off screen buffer. - * - * All coordinates are relative to the current region. + * Utilities to read id buffer created in select_engine. */ #include "MEM_guardedalloc.h" @@ -31,11 +27,67 @@ #include "BLI_bitmap.h" #include "BLI_bitmap_draw_2d.h" #include "BLI_rect.h" -#include "BLI_utildefines.h" + +#include "DNA_screen_types.h" + +#include "GPU_select.h" #include "DRW_engine.h" +#include "DRW_select_buffer.h" + +#include "select_private.h" +#include "select_engine.h" + +/* -------------------------------------------------------------------- */ +/** \name Buffer of select ID's + * \{ */ + +/* Read a block of pixels from the select frame buffer. */ +uint *DRW_select_buffer_read(const rcti *rect, uint *r_buf_len) +{ + struct SELECTID_Context *select_ctx = select_context_get(); + + /* clamp rect by texture */ + rcti r = { + .xmin = 0, + .xmax = GPU_texture_width(select_ctx->texture_u32), + .ymin = 0, + .ymax = GPU_texture_height(select_ctx->texture_u32), + }; + + rcti rect_clamp = *rect; + if (BLI_rcti_isect(&r, &rect_clamp, &rect_clamp)) { + uint 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(select_ctx->framebuffer_select_id); + glReadBuffer(GL_COLOR_ATTACHMENT0); + glReadPixels(rect_clamp.xmin, + rect_clamp.ymin, + BLI_rcti_size_x(&rect_clamp), + BLI_rcti_size_y(&rect_clamp), + GL_RED_INTEGER, + GL_UNSIGNED_INT, + r_buf); + + GPU_framebuffer_restore(); + DRW_opengl_context_disable(); + + if (!BLI_rcti_compare(rect, &rect_clamp)) { + GPU_select_buffer_stride_realign(rect, &rect_clamp, r_buf); + } -#include "ED_select_buffer_utils.h" + if (r_buf_len) { + *r_buf_len = buf_len; + } + + return r_buf; + } + return NULL; +} + +/** \} */ /* -------------------------------------------------------------------- */ /** \name Select Bitmap from ID's @@ -46,13 +98,15 @@ * \{ */ /** - * \param bitmap_len: Number of indices in the selection id buffer. * \param rect: The rectangle to sample indices from (min/max inclusive). + * \param mask: Specifies the rect pixels (optional). * \returns a #BLI_bitmap the length of \a bitmap_len or NULL on failure. */ -uint *ED_select_buffer_bitmap_from_rect(const rcti *rect, uint *r_bitmap_len) +uint *DRW_select_buffer_bitmap_from_rect(const rcti *rect, uint *r_bitmap_len) { - const uint bitmap_len = DRW_select_context_elem_len(); + struct SELECTID_Context *select_ctx = select_context_get(); + + const uint bitmap_len = select_ctx->last_index_drawn; if (bitmap_len == 0) { return NULL; } @@ -62,16 +116,13 @@ uint *ED_select_buffer_bitmap_from_rect(const rcti *rect, uint *r_bitmap_len) rect_px.ymax += 1; uint buf_len; - const uint *buf = DRW_framebuffer_select_id_read(&rect_px, &buf_len); - + uint *buf = DRW_select_buffer_read(&rect_px, &buf_len); if (buf == NULL) { return NULL; } - const uint *buf_iter = buf; - BLI_bitmap *bitmap_buf = BLI_BITMAP_NEW(bitmap_len, __func__); - + const uint *buf_iter = buf; while (buf_len--) { const uint index = *buf_iter - 1; if (index < bitmap_len) { @@ -79,12 +130,8 @@ uint *ED_select_buffer_bitmap_from_rect(const rcti *rect, uint *r_bitmap_len) } buf_iter++; } - MEM_freeN((void *)buf); - - if (r_bitmap_len) { - *r_bitmap_len = bitmap_len; - } + MEM_freeN((void *)buf); return bitmap_buf; } @@ -94,11 +141,13 @@ uint *ED_select_buffer_bitmap_from_rect(const rcti *rect, uint *r_bitmap_len) * \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 int center[2], - const int radius, - uint *r_bitmap_len) +uint *DRW_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(); + struct SELECTID_Context *select_ctx = select_context_get(); + + const uint bitmap_len = select_ctx->last_index_drawn; if (bitmap_len == 0) { return NULL; } @@ -110,7 +159,7 @@ uint *ED_select_buffer_bitmap_from_circle(const int center[2], .ymax = center[1] + radius + 1, }; - const uint *buf = DRW_framebuffer_select_id_read(&rect, NULL); + const uint *buf = DRW_select_buffer_read(&rect @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list [email protected] https://lists.blender.org/mailman/listinfo/bf-blender-cvs
