From 9ccdad8a2173e14848fbfa5401210d8ffb074352 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 31 Jan 2022 13:01:27 +1100 Subject: Cleanup: use enum type for selection mode & internal algorithm enum --- source/blender/editors/space_view3d/view3d_view.c | 4 ++-- source/blender/gpu/GPU_select.h | 11 +++++++---- source/blender/gpu/intern/gpu_select.c | 11 ++++++----- source/blender/gpu/intern/gpu_select_pick.c | 10 +++++++--- source/blender/gpu/intern/gpu_select_private.h | 7 +++++-- source/blender/gpu/intern/gpu_select_sample_query.cc | 4 ++-- .../windowmanager/gizmo/intern/wm_gizmo_map.c | 20 ++++++++++---------- 7 files changed, 39 insertions(+), 28 deletions(-) (limited to 'source') diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index 165f931394d..3b975fa0cfd 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -866,7 +866,7 @@ struct DrawSelectLoopUserData { uint *buffer; uint buffer_len; const rcti *rect; - char gpu_select_mode; + eGPUSelectMode gpu_select_mode; }; static bool drw_select_loop_pass(eDRWSelectStage stage, void *user_data) @@ -950,7 +950,7 @@ int view3d_opengl_select_ex(ViewContext *vc, const bool use_nearest = (is_pick_select && select_mode == VIEW3D_SELECT_PICK_NEAREST); bool draw_surface = true; - char gpu_select_mode; + eGPUSelectMode gpu_select_mode; /* case not a box select */ if (input->xmin == input->xmax) { diff --git a/source/blender/gpu/GPU_select.h b/source/blender/gpu/GPU_select.h index c02af763311..e5dda23b98d 100644 --- a/source/blender/gpu/GPU_select.h +++ b/source/blender/gpu/GPU_select.h @@ -32,7 +32,7 @@ extern "C" { struct rcti; /** Flags for mode of operation. */ -enum { +typedef enum eGPUSelectMode { GPU_SELECT_ALL = 1, /* gpu_select_query */ GPU_SELECT_NEAREST_FIRST_PASS = 2, @@ -40,13 +40,16 @@ enum { /* gpu_select_pick */ GPU_SELECT_PICK_ALL = 4, GPU_SELECT_PICK_NEAREST = 5, -}; +} eGPUSelectMode; /** * Initialize and provide buffer for results. */ -void GPU_select_begin( - unsigned int *buffer, unsigned int bufsize, const struct rcti *input, char mode, int oldhits); +void GPU_select_begin(unsigned int *buffer, + unsigned int bufsize, + const struct rcti *input, + eGPUSelectMode mode, + int oldhits); /** * Loads a new selection id and ends previous query, if any. * In second pass of selection it also returns diff --git a/source/blender/gpu/intern/gpu_select.c b/source/blender/gpu/intern/gpu_select.c index 958aab65b57..741df05799f 100644 --- a/source/blender/gpu/intern/gpu_select.c +++ b/source/blender/gpu/intern/gpu_select.c @@ -43,22 +43,22 @@ * \{ */ /* Internal algorithm used */ -enum { +typedef enum eGPUSelectAlgo { /** glBegin/EndQuery(GL_SAMPLES_PASSED... ), `gpu_select_query.c` * Only sets 4th component (ID) correctly. */ ALGO_GL_QUERY = 1, /** Read depth buffer for every drawing pass and extract depths, `gpu_select_pick.c` * Only sets 4th component (ID) correctly. */ ALGO_GL_PICK = 2, -}; +} eGPUSelectAlgo; typedef struct GPUSelectState { /* To ignore selection id calls when not initialized */ bool select_is_active; /* mode of operation */ - char mode; + eGPUSelectMode mode; /* internal algorithm for selection */ - char algorithm; + eGPUSelectAlgo algorithm; /* allow GPU_select_begin/end without drawing */ bool use_cache; /** @@ -80,7 +80,8 @@ static GPUSelectState g_select_state = {0}; /** \name Public API * \{ */ -void GPU_select_begin(uint *buffer, uint bufsize, const rcti *input, char mode, int oldhits) +void GPU_select_begin( + uint *buffer, uint bufsize, const rcti *input, eGPUSelectMode mode, int oldhits) { if (mode == GPU_SELECT_NEAREST_SECOND_PASS) { /* In the case hits was '-1', diff --git a/source/blender/gpu/intern/gpu_select_pick.c b/source/blender/gpu/intern/gpu_select_pick.c index ddd3dfc6879..ee509a076c9 100644 --- a/source/blender/gpu/intern/gpu_select_pick.c +++ b/source/blender/gpu/intern/gpu_select_pick.c @@ -243,7 +243,7 @@ typedef struct GPUPickState { /* Buffer size (stores number of integers, for actual size multiply by sizeof integer). */ uint bufsize; /* mode of operation */ - char mode; + eGPUSelectMode mode; /* OpenGL drawing, never use when (is_cached == true). */ struct { @@ -303,12 +303,16 @@ typedef struct GPUPickState { static GPUPickState g_pick_state = {0}; -void gpu_select_pick_begin(uint (*buffer)[4], uint bufsize, const rcti *input, char mode) +void gpu_select_pick_begin(uint (*buffer)[4], uint bufsize, const rcti *input, eGPUSelectMode mode) { GPUPickState *ps = &g_pick_state; #ifdef DEBUG_PRINT - printf("%s: mode=%d, use_cache=%d, is_cache=%d\n", __func__, mode, ps->use_cache, ps->is_cached); + printf("%s: mode=%d, use_cache=%d, is_cache=%d\n", + __func__, + (int)mode, + ps->use_cache, + ps->is_cached); #endif GPU_debug_group_begin("Selection Pick"); diff --git a/source/blender/gpu/intern/gpu_select_private.h b/source/blender/gpu/intern/gpu_select_private.h index e5a84a037a6..940cb0bb9e2 100644 --- a/source/blender/gpu/intern/gpu_select_private.h +++ b/source/blender/gpu/intern/gpu_select_private.h @@ -31,7 +31,10 @@ extern "C" { /* gpu_select_pick */ -void gpu_select_pick_begin(uint (*buffer)[4], uint bufsize, const rcti *input, char mode); +void gpu_select_pick_begin(uint (*buffer)[4], + uint bufsize, + const rcti *input, + eGPUSelectMode mode); bool gpu_select_pick_load_id(uint id, bool end); uint gpu_select_pick_end(void); @@ -46,7 +49,7 @@ void gpu_select_pick_cache_load_id(void); /* gpu_select_sample_query */ void gpu_select_query_begin( - uint (*buffer)[4], uint bufsize, const rcti *input, char mode, int oldhits); + uint (*buffer)[4], uint bufsize, const rcti *input, eGPUSelectMode mode, int oldhits); bool gpu_select_query_load_id(uint id); uint gpu_select_query_end(void); diff --git a/source/blender/gpu/intern/gpu_select_sample_query.cc b/source/blender/gpu/intern/gpu_select_sample_query.cc index a430d4a9d62..3d0b8518f98 100644 --- a/source/blender/gpu/intern/gpu_select_sample_query.cc +++ b/source/blender/gpu/intern/gpu_select_sample_query.cc @@ -59,7 +59,7 @@ struct GPUSelectQueryState { /* Buffer size (stores number of integers, for actual size multiply by `sizeof(int)`). */ uint bufsize; /* Mode of operation. */ - char mode; + eGPUSelectMode mode; uint index; int oldhits; @@ -73,7 +73,7 @@ struct GPUSelectQueryState { static GPUSelectQueryState g_query_state = {false}; void gpu_select_query_begin( - uint (*buffer)[4], uint bufsize, const rcti *input, char mode, int oldhits) + uint (*buffer)[4], uint bufsize, const rcti *input, const eGPUSelectMode mode, int oldhits) { GPU_debug_group_begin("Selection Queries"); diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c index e61de28d0a4..024aee84565 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c @@ -582,19 +582,19 @@ static int gizmo_find_intersected_3d_intern(wmGizmo **visible_gizmos, * - #GPU_SELECT_ALL: Use it to check if there is anything at the cursor location * (only ever runs once). * - #GPU_SELECT_PICK_NEAREST: Use if there are more than 1 item at the cursor location, - * select the best one. + * pick the nearest one. * - #GPU_SELECT_PICK_ALL: Use for the same purpose as #GPU_SELECT_PICK_NEAREST * when the selection depths need to re-ordered based on a bias. * */ - const int gpu_select_mode = (use_depth_test ? - (has_3d_select_bias ? - /* Using select bias means the depths need to be - * re-calculated based on the bias to pick the best. */ - GPU_SELECT_PICK_ALL : - /* No bias, just pick the closest. */ - GPU_SELECT_PICK_NEAREST) : - /* Fast-path (occlusion queries). */ - GPU_SELECT_ALL); + const eGPUSelectMode gpu_select_mode = + (use_depth_test ? (has_3d_select_bias ? + /* Using select bias means the depths need to be + * re-calculated based on the bias to pick the best. */ + GPU_SELECT_PICK_ALL : + /* No bias, just pick the closest. */ + GPU_SELECT_PICK_NEAREST) : + /* Fast-path (occlusion queries). */ + GPU_SELECT_ALL); if (GPU_select_is_cached()) { GPU_select_begin(buffer, ARRAY_SIZE(buffer), &rect, gpu_select_mode, 0); -- cgit v1.2.3