Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <campbell@blender.org>2022-01-31 05:01:29 +0300
committerCampbell Barton <campbell@blender.org>2022-01-31 06:10:08 +0300
commit8815f2f11632ea84d706bacd18e60639cb13d6eb (patch)
treea1f479191ee6388c023e99ad8780ada8d6d0562e /source/blender/editors/armature/armature_select.c
parent9ccdad8a2173e14848fbfa5401210d8ffb074352 (diff)
Cleanup: use struct for GPU the select buffer
GPU_select originally used GL_SELECT which defined the format for storing the selection result. Now this is no longer the case, define our own struct - making the code easier to follow: - Avoid having to deal with arrays in both `uint*` and `uint(*)[4]` multiplying offsets by 4 in some cases & not others. - No magic numbers for the offsets of depth & selection-ID. - No need to allocate unused members to match GL_SELECT (halving the buffer size).
Diffstat (limited to 'source/blender/editors/armature/armature_select.c')
-rw-r--r--source/blender/editors/armature/armature_select.c81
1 files changed, 44 insertions, 37 deletions
diff --git a/source/blender/editors/armature/armature_select.c b/source/blender/editors/armature/armature_select.c
index 5e4cb813064..f9b52eb53ed 100644
--- a/source/blender/editors/armature/armature_select.c
+++ b/source/blender/editors/armature/armature_select.c
@@ -55,6 +55,8 @@
#include "DEG_depsgraph.h"
+#include "GPU_select.h"
+
#include "armature_intern.h"
/* utility macros for storing a temp int in the bone (selection flag) */
@@ -67,10 +69,10 @@
Base *ED_armature_base_and_ebone_from_select_buffer(Base **bases,
uint bases_len,
- int hit,
+ const uint select_id,
EditBone **r_ebone)
{
- const uint hit_object = hit & 0xFFFF;
+ const uint hit_object = select_id & 0xFFFF;
Base *base = NULL;
EditBone *ebone = NULL;
/* TODO(campbell): optimize, eg: sort & binary search. */
@@ -81,7 +83,7 @@ Base *ED_armature_base_and_ebone_from_select_buffer(Base **bases,
}
}
if (base != NULL) {
- const uint hit_bone = (hit & ~BONESEL_ANY) >> 16;
+ const uint hit_bone = (select_id & ~BONESEL_ANY) >> 16;
bArmature *arm = base->object->data;
ebone = BLI_findlink(arm->edbo, hit_bone);
}
@@ -91,10 +93,10 @@ Base *ED_armature_base_and_ebone_from_select_buffer(Base **bases,
Object *ED_armature_object_and_ebone_from_select_buffer(Object **objects,
uint objects_len,
- int hit,
+ const uint select_id,
EditBone **r_ebone)
{
- const uint hit_object = hit & 0xFFFF;
+ const uint hit_object = select_id & 0xFFFF;
Object *ob = NULL;
EditBone *ebone = NULL;
/* TODO(campbell): optimize, eg: sort & binary search. */
@@ -105,7 +107,7 @@ Object *ED_armature_object_and_ebone_from_select_buffer(Object **objects,
}
}
if (ob != NULL) {
- const uint hit_bone = (hit & ~BONESEL_ANY) >> 16;
+ const uint hit_bone = (select_id & ~BONESEL_ANY) >> 16;
bArmature *arm = ob->data;
ebone = BLI_findlink(arm->edbo, hit_bone);
}
@@ -115,10 +117,10 @@ Object *ED_armature_object_and_ebone_from_select_buffer(Object **objects,
Base *ED_armature_base_and_pchan_from_select_buffer(Base **bases,
uint bases_len,
- int hit,
+ const uint select_id,
bPoseChannel **r_pchan)
{
- const uint hit_object = hit & 0xFFFF;
+ const uint hit_object = select_id & 0xFFFF;
Base *base = NULL;
bPoseChannel *pchan = NULL;
/* TODO(campbell): optimize, eg: sort & binary search. */
@@ -130,7 +132,7 @@ Base *ED_armature_base_and_pchan_from_select_buffer(Base **bases,
}
if (base != NULL) {
if (base->object->pose != NULL) {
- const uint hit_bone = (hit & ~BONESEL_ANY) >> 16;
+ const uint hit_bone = (select_id & ~BONESEL_ANY) >> 16;
/* pchan may be NULL. */
pchan = BLI_findlink(&base->object->pose->chanbase, hit_bone);
}
@@ -141,11 +143,11 @@ Base *ED_armature_base_and_pchan_from_select_buffer(Base **bases,
Base *ED_armature_base_and_bone_from_select_buffer(Base **bases,
uint bases_len,
- int hit,
+ const uint select_id,
Bone **r_bone)
{
bPoseChannel *pchan = NULL;
- Base *base = ED_armature_base_and_pchan_from_select_buffer(bases, bases_len, hit, &pchan);
+ Base *base = ED_armature_base_and_pchan_from_select_buffer(bases, bases_len, select_id, &pchan);
*r_bone = pchan ? pchan->bone : NULL;
return base;
}
@@ -166,8 +168,8 @@ Base *ED_armature_base_and_bone_from_select_buffer(Base **bases,
static void *ed_armature_pick_bone_from_selectbuffer_impl(const bool is_editmode,
Base **bases,
uint bases_len,
- const uint *buffer,
- short hits,
+ const GPUSelectResult *buffer,
+ const short hits,
bool findunsel,
bool do_nearest,
Base **r_base)
@@ -181,7 +183,7 @@ static void *ed_armature_pick_bone_from_selectbuffer_impl(const bool is_editmode
int minsel = 0xffffffff, minunsel = 0xffffffff;
for (short i = 0; i < hits; i++) {
- hitresult = buffer[3 + (i * 4)];
+ hitresult = buffer[i].id;
if (hitresult & BONESEL_ANY) { /* to avoid including objects in selection */
Base *base = NULL;
@@ -221,10 +223,10 @@ static void *ed_armature_pick_bone_from_selectbuffer_impl(const bool is_editmode
if (data) {
if (sel) {
if (do_nearest) {
- if (minsel > buffer[4 * i + 1]) {
+ if (minsel > buffer[i].depth) {
firstSel = data;
firstSel_base = base;
- minsel = buffer[4 * i + 1];
+ minsel = buffer[i].depth;
}
}
else {
@@ -237,10 +239,10 @@ static void *ed_armature_pick_bone_from_selectbuffer_impl(const bool is_editmode
}
else {
if (do_nearest) {
- if (minunsel > buffer[4 * i + 1]) {
+ if (minunsel > buffer[i].depth) {
firstunSel = data;
firstunSel_base = base;
- minunsel = buffer[4 * i + 1];
+ minunsel = buffer[i].depth;
}
}
else {
@@ -268,8 +270,8 @@ static void *ed_armature_pick_bone_from_selectbuffer_impl(const bool is_editmode
EditBone *ED_armature_pick_ebone_from_selectbuffer(Base **bases,
uint bases_len,
- const uint *buffer,
- short hits,
+ const GPUSelectResult *buffer,
+ const short hits,
bool findunsel,
bool do_nearest,
Base **r_base)
@@ -281,8 +283,8 @@ EditBone *ED_armature_pick_ebone_from_selectbuffer(Base **bases,
bPoseChannel *ED_armature_pick_pchan_from_selectbuffer(Base **bases,
uint bases_len,
- const uint *buffer,
- short hits,
+ const GPUSelectResult *buffer,
+ const short hits,
bool findunsel,
bool do_nearest,
Base **r_base)
@@ -294,8 +296,8 @@ bPoseChannel *ED_armature_pick_pchan_from_selectbuffer(Base **bases,
Bone *ED_armature_pick_bone_from_selectbuffer(Base **bases,
uint bases_len,
- const uint *buffer,
- short hits,
+ const GPUSelectResult *buffer,
+ const short hits,
bool findunsel,
bool do_nearest,
Base **r_base)
@@ -327,7 +329,7 @@ static void *ed_armature_pick_bone_impl(
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
ViewContext vc;
rcti rect;
- uint buffer[MAXPICKBUF];
+ GPUSelectResult buffer[MAXPICKELEMS];
short hits;
ED_view3d_viewcontext_init(C, &vc, depsgraph);
@@ -340,7 +342,7 @@ static void *ed_armature_pick_bone_impl(
hits = view3d_opengl_select_with_id_filter(&vc,
buffer,
- MAXPICKBUF,
+ ARRAY_SIZE(buffer),
&rect,
VIEW3D_SELECT_PICK_NEAREST,
VIEW3D_SELECT_FILTER_NOP,
@@ -636,15 +638,15 @@ void ARMATURE_OT_select_linked_pick(wmOperatorType *ot)
* \{ */
/* utility function for get_nearest_editbonepoint */
-static int selectbuffer_ret_hits_12(uint *UNUSED(buffer), const int hits12)
+static int selectbuffer_ret_hits_12(GPUSelectResult *UNUSED(buffer), const int hits12)
{
return hits12;
}
-static int selectbuffer_ret_hits_5(uint *buffer, const int hits12, const int hits5)
+static int selectbuffer_ret_hits_5(GPUSelectResult *buffer, const int hits12, const int hits5)
{
- const int ofs = 4 * hits12;
- memcpy(buffer, buffer + ofs, 4 * hits5 * sizeof(uint));
+ const int ofs = hits12;
+ memcpy(buffer, buffer + ofs, hits5 * sizeof(*buffer));
return hits5;
}
@@ -653,7 +655,7 @@ static int selectbuffer_ret_hits_5(uint *buffer, const int hits12, const int hit
static EditBone *get_nearest_editbonepoint(
ViewContext *vc, bool findunsel, bool use_cycle, Base **r_base, int *r_selmask)
{
- uint buffer[MAXPICKBUF];
+ GPUSelectResult buffer[MAXPICKELEMS];
struct {
uint hitresult;
Base *base;
@@ -692,7 +694,7 @@ static EditBone *get_nearest_editbonepoint(
rcti rect;
BLI_rcti_init_pt_radius(&rect, vc->mval, 12);
const int hits12 = view3d_opengl_select_with_id_filter(
- vc, buffer, MAXPICKBUF, &rect, select_mode, select_filter, select_id_ignore);
+ vc, buffer, ARRAY_SIZE(buffer), &rect, select_mode, select_filter, select_id_ignore);
if (hits12 == 1) {
hits = selectbuffer_ret_hits_12(buffer, hits12);
@@ -701,10 +703,15 @@ static EditBone *get_nearest_editbonepoint(
else if (hits12 > 0) {
int ofs;
- ofs = 4 * hits12;
+ ofs = hits12;
BLI_rcti_init_pt_radius(&rect, vc->mval, 5);
- const int hits5 = view3d_opengl_select_with_id_filter(
- vc, buffer + ofs, MAXPICKBUF - ofs, &rect, select_mode, select_filter, select_id_ignore);
+ const int hits5 = view3d_opengl_select_with_id_filter(vc,
+ buffer + ofs,
+ ARRAY_SIZE(buffer) - ofs,
+ &rect,
+ select_mode,
+ select_filter,
+ select_id_ignore);
if (hits5 == 1) {
hits = selectbuffer_ret_hits_5(buffer, hits12, hits5);
@@ -732,7 +739,7 @@ cache_end:
/* See if there are any selected bones in this group */
if (hits > 0) {
if (hits == 1) {
- result_bias.hitresult = buffer[3];
+ result_bias.hitresult = buffer->id;
result_bias.base = ED_armature_base_and_ebone_from_select_buffer(
bases, bases_len, result_bias.hitresult, &result_bias.ebone);
}
@@ -771,7 +778,7 @@ cache_end:
}
for (int i = 0; i < hits; i++) {
- const uint hitresult = buffer[3 + (i * 4)];
+ const uint hitresult = buffer[i].id;
Base *base = NULL;
EditBone *ebone;