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/GPU_select.h | |
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/GPU_select.h')
-rw-r--r-- | source/blender/gpu/GPU_select.h | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/source/blender/gpu/GPU_select.h b/source/blender/gpu/GPU_select.h index e5dda23b98d..90bbde4976c 100644 --- a/source/blender/gpu/GPU_select.h +++ b/source/blender/gpu/GPU_select.h @@ -43,10 +43,26 @@ typedef enum eGPUSelectMode { } eGPUSelectMode; /** + * The result of calling #GPU_select_begin & #GPU_select_end. + */ +typedef struct GPUSelectResult { + /** The selection identifier matching the value passed in by #GPU_select_load_id. */ + unsigned int id; + /** + * The nearest depth. + * - Only supported by picking modes (#GPU_SELECT_PICK_ALL and #GPU_SELECT_PICK_NEAREST) + * since occlusion quiries don't provide a convenient way of accessing the depth-buffer. + * - OpenGL's `GL_SELECT` supported both near and far depths, + * this has not been included as Blender doesn't need this however support could be added. + */ + unsigned int depth; +} GPUSelectResult; + +/** * Initialize and provide buffer for results. */ -void GPU_select_begin(unsigned int *buffer, - unsigned int bufsize, +void GPU_select_begin(GPUSelectResult *buffer, + unsigned int buffer_len, const struct rcti *input, eGPUSelectMode mode, int oldhits); @@ -82,8 +98,8 @@ void GPU_select_cache_end(void); * * Note that comparing depth as uint is fine. */ -const uint *GPU_select_buffer_near(const uint *buffer, int hits); -uint GPU_select_buffer_remove_by_id(uint *buffer, int hits, uint select_id); +const GPUSelectResult *GPU_select_buffer_near(const GPUSelectResult *buffer, int hits); +uint GPU_select_buffer_remove_by_id(GPUSelectResult *buffer, int hits, uint select_id); /** * Part of the solution copied from `rect_subregion_stride_calc`. */ |