diff options
author | Campbell Barton <campbell@blender.org> | 2022-01-31 05:01:29 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-01-31 06:10:08 +0300 |
commit | 8815f2f11632ea84d706bacd18e60639cb13d6eb (patch) | |
tree | a1f479191ee6388c023e99ad8780ada8d6d0562e /source/blender/gpu/intern/gpu_select_pick.c | |
parent | 9ccdad8a2173e14848fbfa5401210d8ffb074352 (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/gpu/intern/gpu_select_pick.c')
-rw-r--r-- | source/blender/gpu/intern/gpu_select_pick.c | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/source/blender/gpu/intern/gpu_select_pick.c b/source/blender/gpu/intern/gpu_select_pick.c index ee509a076c9..680d1e8d6f5 100644 --- a/source/blender/gpu/intern/gpu_select_pick.c +++ b/source/blender/gpu/intern/gpu_select_pick.c @@ -238,10 +238,8 @@ static int depth_cmp(const void *v1, const void *v2) /* depth sorting */ typedef struct GPUPickState { /* cache on initialization */ - uint (*buffer)[4]; - - /* Buffer size (stores number of integers, for actual size multiply by sizeof integer). */ - uint bufsize; + GPUSelectResult *buffer; + uint buffer_len; /* mode of operation */ eGPUSelectMode mode; @@ -303,7 +301,10 @@ typedef struct GPUPickState { static GPUPickState g_pick_state = {0}; -void gpu_select_pick_begin(uint (*buffer)[4], uint bufsize, const rcti *input, eGPUSelectMode mode) +void gpu_select_pick_begin(GPUSelectResult *buffer, + const uint buffer_len, + const rcti *input, + eGPUSelectMode mode) { GPUPickState *ps = &g_pick_state; @@ -317,8 +318,8 @@ void gpu_select_pick_begin(uint (*buffer)[4], uint bufsize, const rcti *input, e GPU_debug_group_begin("Selection Pick"); - ps->bufsize = bufsize; ps->buffer = buffer; + ps->buffer_len = buffer_len; ps->mode = mode; const uint rect_len = (uint)(BLI_rcti_size_x(input) * BLI_rcti_size_y(input)); @@ -580,7 +581,7 @@ uint gpu_select_pick_end(void) rect_depth_final = ps->gl.rect_depth; } - uint maxhits = g_pick_state.bufsize; + uint maxhits = g_pick_state.buffer_len; DepthID *depth_data; uint depth_data_len = 0; @@ -675,11 +676,8 @@ uint gpu_select_pick_end(void) #ifdef DEBUG_PRINT printf(" hit: %u: depth %u\n", depth_data[i].id, depth_data[i].depth); #endif - /* first 3 are dummy values */ - g_pick_state.buffer[hits][0] = 1; - g_pick_state.buffer[hits][1] = depth_data[i].depth; - g_pick_state.buffer[hits][2] = 0x0; /* z-far is currently never used. */ - g_pick_state.buffer[hits][3] = depth_data[i].id; + g_pick_state.buffer[hits].depth = depth_data[i].depth; + g_pick_state.buffer[hits].id = depth_data[i].id; hits++; } BLI_assert(hits < maxhits); |