Blender V4.3
gpu_select_pick.cc File Reference
#include <cfloat>
#include <cstdlib>
#include <cstring>
#include "GPU_debug.hh"
#include "GPU_framebuffer.hh"
#include "GPU_select.hh"
#include "GPU_state.hh"
#include "MEM_guardedalloc.h"
#include "BLI_listbase.h"
#include "BLI_rect.h"
#include "BLI_utildefines.h"
#include "gpu_select_private.hh"
#include "BLI_strict_flags.h"

Go to the source code of this file.

Classes

struct  SubRectStride
 
struct  DepthBufCache
 
struct  DepthID
 
struct  GPUPickState
 

Macros

#define ALLOC_DEPTHS   200
 
#define DEPTH_MAX   0xffffffff
 
#define EVAL_TEST()
 
#define EVAL_TEST()
 
#define EVAL_TEST(i_src, i_dst)
 

Functions

#DepthBufCache

Result of reading GPU_framebuffer_read_depth, use for both cache and non-cached storage.

static DepthBufCachedepth_buf_malloc (uint rect_len)
 
static bool depth_buf_rect_depth_any (const DepthBufCache *rect_depth, uint rect_len)
 
static bool depth_buf_subrect_depth_any (const DepthBufCache *rect_depth, const SubRectStride *sub_rect)
 
static bool depth_buf_rect_depth_any_filled (const DepthBufCache *rect_prev, const DepthBufCache *rect_curr, uint rect_len)
 
static bool depth_buf_subrect_depth_any_filled (const DepthBufCache *rect_src, const DepthBufCache *rect_dst, const SubRectStride *sub_rect)
 
#DepthID

Internal structure for storing hits.

static int depth_id_cmp (const void *v1, const void *v2)
 
static int depth_cmp (const void *v1, const void *v2)
 
Caching

Support multiple begin/end's reusing depth buffers.

void gpu_select_pick_cache_begin ()
 
void gpu_select_pick_cache_end ()
 
bool gpu_select_pick_is_cached ()
 
void gpu_select_pick_cache_load_id ()
 

#SubRectStride

typedef uint depth_t
 
static void rect_subregion_stride_calc (const rcti *src, const rcti *dst, SubRectStride *r_sub)
 
BLI_INLINE bool depth_is_filled (const depth_t *prev, const depth_t *curr)
 

Main Selection Begin/End/Load API

static GPUPickState g_pick_state {}
 
void gpu_select_pick_begin (GPUSelectBuffer *buffer, const rcti *input, eGPUSelectMode mode)
 
static void gpu_select_load_id_pass_all (const DepthBufCache *rect_curr)
 
static void gpu_select_load_id_pass_nearest (const DepthBufCache *rect_prev, const DepthBufCache *rect_curr)
 
bool gpu_select_pick_load_id (uint id, bool end)
 
uint gpu_select_pick_end ()
 

Detailed Description

Custom select code for picking small regions (not efficient for large regions). gpu_select_pick_* API.

Definition in file gpu_select_pick.cc.

Macro Definition Documentation

◆ ALLOC_DEPTHS

#define ALLOC_DEPTHS   200

Definition at line 33 of file gpu_select_pick.cc.

Referenced by gpu_select_load_id_pass_all(), and gpu_select_pick_begin().

◆ DEPTH_MAX

◆ EVAL_TEST [1/3]

#define EVAL_TEST ( )
Value:
if (depth_best > *curr) { \
depth_best = *curr; \
} \
((void)0)

Referenced by gpu_select_load_id_pass_all(), gpu_select_load_id_pass_nearest(), and gpu_select_pick_end().

◆ EVAL_TEST [2/3]

#define EVAL_TEST ( )
Value:
if (depth_is_filled(prev, curr)) { \
*id_ptr = id; \
} \
((void)0)
BLI_INLINE bool depth_is_filled(const depth_t *prev, const depth_t *curr)

◆ EVAL_TEST [3/3]

#define EVAL_TEST ( i_src,
i_dst )
Value:
{ \
const uint id = ps->nearest.rect_id[i_dst]; \
if (id != SELECT_ID_NONE) { \
const depth_t depth = rect_depth_final->buf[i_src]; \
if (depth_last == nullptr || depth_last->id != id) { \
DepthID *d = &depth_data[depth_data_len_first_pass++]; \
d->id = id; \
d->depth = depth; \
} \
else if (depth_last->depth > depth) { \
depth_last->depth = depth; \
} \
} \
} \
((void)0)
unsigned int uint
uint depth_t
#define SELECT_ID_NONE
depth_t depth

Typedef Documentation

◆ depth_t

typedef uint depth_t

We may want to change back to float if uint isn't well supported.

Definition at line 55 of file gpu_select_pick.cc.

Function Documentation

◆ depth_buf_malloc()

static DepthBufCache * depth_buf_malloc ( uint rect_len)
static

Definition at line 106 of file gpu_select_pick.cc.

References DepthBufCache::id, MEM_mallocN, and SELECT_ID_NONE.

Referenced by gpu_select_pick_begin(), and gpu_select_pick_load_id().

◆ depth_buf_rect_depth_any()

static bool depth_buf_rect_depth_any ( const DepthBufCache * rect_depth,
uint rect_len )
static

Definition at line 114 of file gpu_select_pick.cc.

References DepthBufCache::buf, and DEPTH_MAX.

Referenced by gpu_select_pick_load_id().

◆ depth_buf_rect_depth_any_filled()

static bool depth_buf_rect_depth_any_filled ( const DepthBufCache * rect_prev,
const DepthBufCache * rect_curr,
uint rect_len )
static

Definition at line 141 of file gpu_select_pick.cc.

References DepthBufCache::buf, and depth_is_filled().

Referenced by gpu_select_pick_load_id().

◆ depth_buf_subrect_depth_any()

static bool depth_buf_subrect_depth_any ( const DepthBufCache * rect_depth,
const SubRectStride * sub_rect )
static

◆ depth_buf_subrect_depth_any_filled()

static bool depth_buf_subrect_depth_any_filled ( const DepthBufCache * rect_src,
const DepthBufCache * rect_dst,
const SubRectStride * sub_rect )
static

Both buffers are the same size, just check if the sub-rect contains any differences.

Definition at line 162 of file gpu_select_pick.cc.

References DepthBufCache::buf, depth_is_filled(), SubRectStride::skip, SubRectStride::span, SubRectStride::span_len, and SubRectStride::start.

Referenced by gpu_select_pick_cache_load_id().

◆ depth_cmp()

static int depth_cmp ( const void * v1,
const void * v2 )
static

Definition at line 208 of file gpu_select_pick.cc.

References DepthID::depth, and v2.

Referenced by gpu_select_pick_end().

◆ depth_id_cmp()

static int depth_id_cmp ( const void * v1,
const void * v2 )
static

Definition at line 195 of file gpu_select_pick.cc.

References DepthID::id, and v2.

Referenced by gpu_select_pick_end().

◆ depth_is_filled()

BLI_INLINE bool depth_is_filled ( const depth_t * prev,
const depth_t * curr )

Ignore depth clearing as a change, only check if its been changed and filled in (ignore clearing since XRAY does this).

Definition at line 85 of file gpu_select_pick.cc.

References DEPTH_MAX.

Referenced by depth_buf_rect_depth_any_filled(), and depth_buf_subrect_depth_any_filled().

◆ gpu_select_load_id_pass_all()

◆ gpu_select_load_id_pass_nearest()

◆ gpu_select_pick_begin()

◆ gpu_select_pick_cache_begin()

void gpu_select_pick_cache_begin ( )

◆ gpu_select_pick_cache_end()

◆ gpu_select_pick_cache_load_id()

◆ gpu_select_pick_end()

◆ gpu_select_pick_is_cached()

bool gpu_select_pick_is_cached ( )
Returns
true if drawing is not needed.

Definition at line 723 of file gpu_select_pick.cc.

References g_pick_state, and GPUPickState::is_cached.

Referenced by GPU_select_is_cached().

◆ gpu_select_pick_load_id()

◆ rect_subregion_stride_calc()

static void rect_subregion_stride_calc ( const rcti * src,
const rcti * dst,
SubRectStride * r_sub )
static

Calculate values needed for looping over a sub-region (smaller buffer within a larger buffer).

'src' must be bigger than 'dst'.

Definition at line 62 of file gpu_select_pick.cc.

References BLI_assert, BLI_rcti_size_x(), BLI_rcti_size_y(), SubRectStride::skip, SubRectStride::span, SubRectStride::span_len, SubRectStride::start, rcti::xmax, rcti::xmin, rcti::ymax, and rcti::ymin.

Referenced by gpu_select_pick_begin().

Variable Documentation

◆ g_pick_state