Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_view3d/view3d_utils.c
| Show First 20 Lines • Show All 1,624 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Depth Buffer Utilities | /** \name Depth Buffer Utilities | ||||
| * \{ */ | * \{ */ | ||||
| struct ReadData { | |||||
| int count; | |||||
| int count_max; | |||||
| float r_depth; | |||||
| }; | |||||
| static bool depth_read_test_fn(const void *value, void *userdata) | static bool depth_read_test_fn(const void *value, void *userdata) | ||||
| { | { | ||||
| float *r_depth = userdata; | struct ReadData *data = userdata; | ||||
| float depth = *(float *)value; | float depth = *(float *)value; | ||||
| if (depth < *r_depth) { | if (depth < data->r_depth) { | ||||
| *r_depth = depth; | data->r_depth = depth; | ||||
| } | |||||
| if ((++data->count) >= data->count_max) { | |||||
| /* Outside the margin. */ | |||||
| return true; | |||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| bool ED_view3d_depth_read_cached(const ViewDepths *vd, | bool ED_view3d_depth_read_cached(const ViewDepths *vd, | ||||
| const int mval[2], | const int mval[2], | ||||
| int margin, | int margin, | ||||
| float *r_depth) | float *r_depth) | ||||
| { | { | ||||
| if (!vd || !vd->depths) { | if (!vd || !vd->depths) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| int x = mval[0]; | int x = mval[0]; | ||||
| int y = mval[1]; | int y = mval[1]; | ||||
| if (x < 0 || y < 0 || x >= vd->w || y >= vd->h) { | if (x < 0 || y < 0 || x >= vd->w || y >= vd->h) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| float depth = 1.0f; | float depth = 1.0f; | ||||
| if (margin) { | if (margin) { | ||||
| /* TODO: No need to go spiral. */ | |||||
| int shape[2] = {vd->w, vd->h}; | int shape[2] = {vd->w, vd->h}; | ||||
| BLI_array_iter_spiral_square(vd->depths, shape, mval, depth_read_test_fn, &depth); | int pixel_count = (min_ii(x + margin + 1, shape[1]) - max_ii(x - margin, 0)) * | ||||
| (min_ii(y + margin + 1, shape[0]) - max_ii(y - margin, 0)); | |||||
| struct ReadData data; | |||||
| data.count = 0; | |||||
| data.count_max = pixel_count; | |||||
| data.r_depth = 1.0f; | |||||
| /* TODO: No need to go spiral. */ | |||||
| BLI_array_iter_spiral_square(vd->depths, shape, mval, depth_read_test_fn, &data); | |||||
| depth = data.r_depth; | |||||
| } | } | ||||
| else { | else { | ||||
| depth = vd->depths[y * vd->w + x]; | depth = vd->depths[y * vd->w + x]; | ||||
| } | } | ||||
| BLI_assert(1.0 <= vd->depth_range[1]); | BLI_assert(1.0 <= vd->depth_range[1]); | ||||
| if (depth != 1.0f) { | if (depth != 1.0f) { | ||||
| *r_depth = depth; | *r_depth = depth; | ||||
| ▲ Show 20 Lines • Show All 81 Lines • Show Last 20 Lines | |||||