1
1

Cleanup: use enum type for selection mode & internal algorithm enum

This commit is contained in:
2022-01-31 13:01:27 +11:00
parent 57f6aa4d83
commit 9ccdad8a21
7 changed files with 39 additions and 28 deletions

View File

@@ -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) {

View File

@@ -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

View File

@@ -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',

View File

@@ -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");

View File

@@ -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);

View File

@@ -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");

View File

@@ -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);