[Bf-blender-cvs] [14b6e4ec679] temp-select-pick: Use unsigned int for depth values
Campbell Barton
noreply at git.blender.org
Wed Mar 8 18:38:55 CET 2017
Commit: 14b6e4ec6799c833dd7383f9332fcc1a014fbad0
Author: Campbell Barton
Date: Thu Mar 9 04:15:51 2017 +1100
Branches: temp-select-pick
https://developer.blender.org/rB14b6e4ec6799c833dd7383f9332fcc1a014fbad0
Use unsigned int for depth values
===================================================================
M source/blender/editors/space_view3d/view3d_select.c
M source/blender/gpu/intern/gpu_select_pick.c
===================================================================
diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c
index 2fe09cb1d0a..a786c001ee6 100644
--- a/source/blender/editors/space_view3d/view3d_select.c
+++ b/source/blender/editors/space_view3d/view3d_select.c
@@ -1230,8 +1230,8 @@ static int mixed_bones_object_selectbuffer(
}
}
- use_cycle = true ;
- do_nearest = false ;
+// use_cycle = true ;
+// do_nearest = false ;
if (r_do_nearest) {
*r_do_nearest = do_nearest;
@@ -1243,7 +1243,7 @@ static int mixed_bones_object_selectbuffer(
int hits = 0;
/* we _must_ end cache before return, use 'goto finally' */
- GPU_select_cache_begin();
+ /* GPU_select_cache_begin(); */
BLI_rcti_init_pt_radius(&rect, mval, 14);
hits15 = view3d_opengl_select(vc, buffer, MAXPICKBUF, &rect, select_mode);
@@ -1286,7 +1286,7 @@ static int mixed_bones_object_selectbuffer(
}
finally:
- GPU_select_cache_end();
+ /* GPU_select_cache_end(); */
return hits;
}
diff --git a/source/blender/gpu/intern/gpu_select_pick.c b/source/blender/gpu/intern/gpu_select_pick.c
index 7aad484f1bb..80d3e6122a8 100644
--- a/source/blender/gpu/intern/gpu_select_pick.c
+++ b/source/blender/gpu/intern/gpu_select_pick.c
@@ -34,6 +34,7 @@
#include "GPU_select.h"
#include "GPU_extensions.h"
#include "GPU_glew.h"
+#include "GPU_debug.h"
#include "MEM_guardedalloc.h"
@@ -53,7 +54,7 @@
#define ALLOC_DEPTHS 200
/* Z-depth of cleared depth buffer */
-#define DEPTH_MAX 1.0
+#define DEPTH_MAX 0xffffffff
/* ----------------------------------------------------------------------------
* SubRectStride
@@ -67,6 +68,9 @@ typedef struct SubRectStride {
unsigned int skip; /* skip those */
} SubRectStride;
+/* we may want to change back to float if uint isn't well supported */
+typedef unsigned int depth_t;
+
/**
* Calculate values needed for looping over a sub-region (smaller buffer within a larger buffer).
*
@@ -102,12 +106,12 @@ static void rect_subregion_stride_calc(const rcti *src, const rcti *dst, SubRect
typedef struct DepthBufCache {
struct DepthBufCache *next, *prev;
unsigned int id;
- float buf[0];
+ depth_t buf[0];
} DepthBufCache;
static DepthBufCache *depth_buf_malloc(unsigned int rect_len)
{
- DepthBufCache *rect = MEM_mallocN(sizeof(DepthBufCache) + sizeof(float) * rect_len, __func__);
+ DepthBufCache *rect = MEM_mallocN(sizeof(DepthBufCache) + sizeof(depth_t) * rect_len, __func__);
rect->id = SELECT_ID_NONE;
return rect;
}
@@ -120,10 +124,10 @@ static bool depth_buf_subrect_equal(
const DepthBufCache *rect_src, const DepthBufCache *rect_dst)
{
/* same as above but different rect sizes */
- const float *prev = rect_src->buf + sub_rect->start;
- const float *curr = rect_dst->buf + sub_rect->start;
+ const depth_t *prev = rect_src->buf + sub_rect->start;
+ const depth_t *curr = rect_dst->buf + sub_rect->start;
for (unsigned int i = 0; i < sub_rect->span_len; i++) {
- const float *curr_end = curr + sub_rect->span;
+ const depth_t *curr_end = curr + sub_rect->span;
for (; curr < curr_end; prev++, curr++) {
if (*prev != *curr) {
return false;
@@ -143,7 +147,7 @@ static bool depth_buf_subrect_equal(
typedef struct DepthID {
unsigned int id;
- float depth;
+ depth_t depth;
} DepthID;
static int depth_id_cmp(const void *v1, const void *v2)
@@ -262,17 +266,23 @@ void gpu_select_pick_begin(
/* disable writing to the framebuffer */
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
+
/* Without this orthographic mode doesn't give enough precision between objects */
glEnable(GL_DEPTH_TEST);
- glDepthMask(GL_TRUE);
if (mode == GPU_SELECT_PICK_SORT_ALL) {
- glDepthFunc(GL_ALWAYS);
+ glDepthMask(GL_TRUE);
+ glDepthFunc(GL_NOTEQUAL);
}
else {
+ glDepthMask(GL_TRUE);
glDepthFunc(GL_LEQUAL);
}
+ glPixelTransferi(GL_DEPTH_BIAS, 0.0);
+ glPixelTransferi(GL_DEPTH_SCALE, 1.0);
+
+
float viewport[4];
glGetFloatv(GL_SCISSOR_BOX, viewport);
@@ -288,8 +298,8 @@ void gpu_select_pick_begin(
/* It's possible we don't want to clear depth buffer,
* so existing elements are masked by current z-buffer. */
- /* glClear(GL_DEPTH_BUFFER_BIT); */
- glClearDepth((float)DEPTH_MAX);
+ glClear(GL_DEPTH_BUFFER_BIT);
+ /* glClearDepth((float)DEPTH_MAX); */
/* scratch buffer (read new values here) */
ps->gl.rect_depth_test = depth_buf_malloc(rect_len);
@@ -297,7 +307,10 @@ void gpu_select_pick_begin(
/* set initial 'far' value */
#if 1
- glReadPixels(UNPACK4(ps->gl.clip_readpixels), GL_DEPTH_COMPONENT, GL_FLOAT, ps->gl.rect_depth->buf);
+ GPU_ASSERT_NO_GL_ERRORS(__func__);
+ glReadPixels(UNPACK4(ps->gl.clip_readpixels), GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, ps->gl.rect_depth->buf);
+ GPU_ASSERT_NO_GL_ERRORS(__func__);
+ printf("%u\n", ps->gl.rect_depth->buf[0]);
#else
copy_vn_fl(ps->gl.rect_depth->buf, rect_len, DEPTH_MAX);
#endif
@@ -335,7 +348,7 @@ static void gpu_select_load_id_pass(const DepthBufCache *rect_prev, const DepthB
const unsigned int id = rect_curr->id;
if (g_pick_state.mode == GPU_SELECT_PICK_SORT_ALL) {
/* find the best depth for this pass and store in 'all.hits' */
- float depth_best = DEPTH_MAX;
+ depth_t depth_best = DEPTH_MAX;
#define EVAL_TEST() \
if (*curr != *prev) { \
@@ -345,8 +358,8 @@ static void gpu_select_load_id_pass(const DepthBufCache *rect_prev, const DepthB
} ((void)0)
if (ps->is_cached == false) {
- const float *prev = rect_prev->buf;
- const float *curr = rect_curr->buf;
+ const depth_t *prev = rect_prev->buf;
+ const depth_t *curr = rect_curr->buf;
BLI_assert(ps->src.rect_len == ps->dst.rect_len);
const unsigned int rect_len = ps->src.rect_len;
for (unsigned int i = 0; i < rect_len; i++, curr++, prev++) {
@@ -355,10 +368,10 @@ static void gpu_select_load_id_pass(const DepthBufCache *rect_prev, const DepthB
}
else {
/* same as above but different rect sizes */
- const float *prev = rect_prev->buf + ps->cache.sub_rect.start;
- const float *curr = rect_curr->buf + ps->cache.sub_rect.start;
+ const depth_t *prev = rect_prev->buf + ps->cache.sub_rect.start;
+ const depth_t *curr = rect_curr->buf + ps->cache.sub_rect.start;
for (unsigned int i = 0; i < ps->cache.sub_rect.span_len; i++) {
- const float *curr_end = curr + ps->cache.sub_rect.span;
+ const depth_t *curr_end = curr + ps->cache.sub_rect.span;
for (; curr < curr_end; prev++, curr++) {
EVAL_TEST();
}
@@ -389,8 +402,8 @@ static void gpu_select_load_id_pass(const DepthBufCache *rect_prev, const DepthB
} ((void)0)
if (ps->is_cached == false) {
- const float *prev = rect_prev->buf;
- const float *curr = rect_curr->buf;
+ const depth_t *prev = rect_prev->buf;
+ const depth_t *curr = rect_curr->buf;
BLI_assert(ps->src.rect_len == ps->dst.rect_len);
const unsigned int rect_len = ps->src.rect_len;
for (unsigned int i = 0; i < rect_len; i++, curr++, prev++, id_ptr++) {
@@ -399,10 +412,10 @@ static void gpu_select_load_id_pass(const DepthBufCache *rect_prev, const DepthB
}
else {
/* same as above but different rect sizes */
- const float *prev = rect_prev->buf + ps->cache.sub_rect.start;
- const float *curr = rect_curr->buf + ps->cache.sub_rect.start;
+ const depth_t *prev = rect_prev->buf + ps->cache.sub_rect.start;
+ const depth_t *curr = rect_curr->buf + ps->cache.sub_rect.start;
for (unsigned int i = 0; i < ps->cache.sub_rect.span_len; i++) {
- const float *curr_end = curr + ps->cache.sub_rect.span;
+ const depth_t *curr_end = curr + ps->cache.sub_rect.span;
for (; curr < curr_end; prev++, curr++, id_ptr++) {
EVAL_TEST();
}
@@ -422,9 +435,11 @@ bool gpu_select_pick_load_id(unsigned int id)
GPUPickState *ps = &g_pick_state;
if (ps->gl.is_init) {
const unsigned int rect_len = ps->src.rect_len;
- glReadPixels(UNPACK4(ps->gl.clip_readpixels), GL_DEPTH_COMPONENT, GL_FLOAT, ps->gl.rect_depth_test->buf);
+ GPU_ASSERT_NO_GL_ERRORS(__func__);
+ glReadPixels(UNPACK4(ps->gl.clip_readpixels), GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, ps->gl.rect_depth_test->buf);
+ GPU_ASSERT_NO_GL_ERRORS(__func__);
/* perform initial memcmp since most cases the array remains unchanged */
- if (memcmp(ps->gl.rect_depth->buf, ps->gl.rect_depth_test->buf, rect_len * sizeof(float)) != 0) {
+ if (memcmp(ps->gl.rect_depth->buf, ps->gl.rect_depth_test->buf, rect_len * sizeof(depth_t)) != 0) {
ps->gl.rect_depth_test->id = ps->gl.prev_id;
gpu_select_load_id_pass(ps->gl.rect_depth, ps->gl.rect_depth_test);
@@ -461,7 +476,6 @@ unsigned int gpu_select_pick_end(void)
glPopAttrib();
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
- glDepthRange(0.0, 1.0);
}
/* assign but never free directly since it may be in cache */
@@ -508,7 +522,7 @@ unsigned int gpu_select_pick_end(void)
{ \
const unsigned int id = ps->nearest.rect_id[i_dst]; \
if (id != SELECT_ID_NONE) { \
- const float depth = rect_depth_final->buf[i_src]; \
+ const depth_t depth = rect_depth_final->buf[i_src]; \
if (depth_last == NULL || depth_last->id != id) { \
DepthID *d = &depth_data[depth_data_len_first_pass++]; \
d->id = id; \
@@ -572,7 +586,7 @@ unsigned int gpu_select_pick_end(void)
for (unsigned int i = 0; i < depth_data_len; i++) {
#ifdef DEBUG_PRINT
- printf(" hit: %d: depth %.15f\n", depth_data[i].id, depth_data[i].depth);
+ printf(" hit: %d: depth %u\n", depth_data[i].id, depth_data[i].depth);
#endif
/* first 3 are dummy values */
g_pick_state.buffer[hits][0] = 1;
More information about the Bf-blender-cvs
mailing list