Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-04-17 07:17:24 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-04-17 07:21:24 +0300
commite12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch)
tree8cf3453d12edb177a218ef8009357518ec6cab6a /source/blender/gpu/intern/gpu_select.c
parentb3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff)
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211. For details on usage and instructions for migrating branches without conflicts, see: https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'source/blender/gpu/intern/gpu_select.c')
-rw-r--r--source/blender/gpu/intern/gpu_select.c261
1 files changed, 128 insertions, 133 deletions
diff --git a/source/blender/gpu/intern/gpu_select.c b/source/blender/gpu/intern/gpu_select.c
index 875bcdcc674..4cfedc0708b 100644
--- a/source/blender/gpu/intern/gpu_select.c
+++ b/source/blender/gpu/intern/gpu_select.c
@@ -42,23 +42,23 @@
/* Internal algorithm used */
enum {
- /** 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,
+ /** 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,
};
typedef struct GPUSelectState {
- /* To ignore selection id calls when not initialized */
- bool select_is_active;
- /* mode of operation */
- char mode;
- /* internal algorithm for selection */
- char algorithm;
- /* allow GPU_select_begin/end without drawing */
- bool use_cache;
+ /* To ignore selection id calls when not initialized */
+ bool select_is_active;
+ /* mode of operation */
+ char mode;
+ /* internal algorithm for selection */
+ char algorithm;
+ /* allow GPU_select_begin/end without drawing */
+ bool use_cache;
} GPUSelectState;
static GPUSelectState g_select_state = {0};
@@ -68,35 +68,34 @@ static GPUSelectState g_select_state = {0};
*/
void GPU_select_begin(uint *buffer, uint bufsize, const rcti *input, char mode, int oldhits)
{
- if (mode == GPU_SELECT_NEAREST_SECOND_PASS) {
- /* In the case hits was '-1', don't start the second pass since it's not going to give useful results.
- * As well as buffer overflow in 'gpu_select_query_load_id'. */
- BLI_assert(oldhits != -1);
- }
-
- g_select_state.select_is_active = true;
- g_select_state.mode = mode;
-
- if (ELEM(g_select_state.mode, GPU_SELECT_PICK_ALL, GPU_SELECT_PICK_NEAREST)) {
- g_select_state.algorithm = ALGO_GL_PICK;
- }
- else {
- g_select_state.algorithm = ALGO_GL_QUERY;
- }
-
- switch (g_select_state.algorithm) {
- case ALGO_GL_QUERY:
- {
- g_select_state.use_cache = false;
- gpu_select_query_begin((uint (*)[4])buffer, bufsize / 4, input, mode, oldhits);
- break;
- }
- default: /* ALGO_GL_PICK */
- {
- gpu_select_pick_begin((uint (*)[4])buffer, bufsize / 4, input, mode);
- break;
- }
- }
+ if (mode == GPU_SELECT_NEAREST_SECOND_PASS) {
+ /* In the case hits was '-1', don't start the second pass since it's not going to give useful results.
+ * As well as buffer overflow in 'gpu_select_query_load_id'. */
+ BLI_assert(oldhits != -1);
+ }
+
+ g_select_state.select_is_active = true;
+ g_select_state.mode = mode;
+
+ if (ELEM(g_select_state.mode, GPU_SELECT_PICK_ALL, GPU_SELECT_PICK_NEAREST)) {
+ g_select_state.algorithm = ALGO_GL_PICK;
+ }
+ else {
+ g_select_state.algorithm = ALGO_GL_QUERY;
+ }
+
+ switch (g_select_state.algorithm) {
+ case ALGO_GL_QUERY: {
+ g_select_state.use_cache = false;
+ gpu_select_query_begin((uint(*)[4])buffer, bufsize / 4, input, mode, oldhits);
+ break;
+ }
+ default: /* ALGO_GL_PICK */
+ {
+ gpu_select_pick_begin((uint(*)[4])buffer, bufsize / 4, input, mode);
+ break;
+ }
+ }
}
/**
@@ -108,20 +107,19 @@ void GPU_select_begin(uint *buffer, uint bufsize, const rcti *input, char mode,
*/
bool GPU_select_load_id(uint id)
{
- /* if no selection mode active, ignore */
- if (!g_select_state.select_is_active)
- return true;
-
- switch (g_select_state.algorithm) {
- case ALGO_GL_QUERY:
- {
- return gpu_select_query_load_id(id);
- }
- default: /* ALGO_GL_PICK */
- {
- return gpu_select_pick_load_id(id);
- }
- }
+ /* if no selection mode active, ignore */
+ if (!g_select_state.select_is_active)
+ return true;
+
+ switch (g_select_state.algorithm) {
+ case ALGO_GL_QUERY: {
+ return gpu_select_query_load_id(id);
+ }
+ default: /* ALGO_GL_PICK */
+ {
+ return gpu_select_pick_load_id(id);
+ }
+ }
}
/**
@@ -131,24 +129,23 @@ bool GPU_select_load_id(uint id)
*/
uint GPU_select_end(void)
{
- uint hits = 0;
-
- switch (g_select_state.algorithm) {
- case ALGO_GL_QUERY:
- {
- hits = gpu_select_query_end();
- break;
- }
- default: /* ALGO_GL_PICK */
- {
- hits = gpu_select_pick_end();
- break;
- }
- }
-
- g_select_state.select_is_active = false;
-
- return hits;
+ uint hits = 0;
+
+ switch (g_select_state.algorithm) {
+ case ALGO_GL_QUERY: {
+ hits = gpu_select_query_end();
+ break;
+ }
+ default: /* ALGO_GL_PICK */
+ {
+ hits = gpu_select_pick_end();
+ break;
+ }
+ }
+
+ g_select_state.select_is_active = false;
+
+ return hits;
}
/* ----------------------------------------------------------------------------
@@ -160,36 +157,35 @@ uint GPU_select_end(void)
void GPU_select_cache_begin(void)
{
- /* validate on GPU_select_begin, clear if not supported */
- BLI_assert(g_select_state.use_cache == false);
- g_select_state.use_cache = true;
- if (g_select_state.algorithm == ALGO_GL_PICK) {
- gpu_select_pick_cache_begin();
- }
+ /* validate on GPU_select_begin, clear if not supported */
+ BLI_assert(g_select_state.use_cache == false);
+ g_select_state.use_cache = true;
+ if (g_select_state.algorithm == ALGO_GL_PICK) {
+ gpu_select_pick_cache_begin();
+ }
}
void GPU_select_cache_load_id(void)
{
- BLI_assert(g_select_state.use_cache == true);
- if (g_select_state.algorithm == ALGO_GL_PICK) {
- gpu_select_pick_cache_load_id();
- }
+ BLI_assert(g_select_state.use_cache == true);
+ if (g_select_state.algorithm == ALGO_GL_PICK) {
+ gpu_select_pick_cache_load_id();
+ }
}
void GPU_select_cache_end(void)
{
- if (g_select_state.algorithm == ALGO_GL_PICK) {
- gpu_select_pick_cache_end();
- }
- g_select_state.use_cache = false;
+ if (g_select_state.algorithm == ALGO_GL_PICK) {
+ gpu_select_pick_cache_end();
+ }
+ g_select_state.use_cache = false;
}
bool GPU_select_is_cached(void)
{
- return g_select_state.use_cache && gpu_select_pick_is_cached();
+ return g_select_state.use_cache && gpu_select_pick_is_cached();
}
-
/* ----------------------------------------------------------------------------
* Utilities
*/
@@ -202,50 +198,49 @@ bool GPU_select_is_cached(void)
*/
const uint *GPU_select_buffer_near(const uint *buffer, int hits)
{
- const uint *buffer_near = NULL;
- uint depth_min = (uint) - 1;
- for (int i = 0; i < hits; i++) {
- if (buffer[1] < depth_min) {
- BLI_assert(buffer[3] != -1);
- depth_min = buffer[1];
- buffer_near = buffer;
- }
- buffer += 4;
- }
- return buffer_near;
+ const uint *buffer_near = NULL;
+ uint depth_min = (uint)-1;
+ for (int i = 0; i < hits; i++) {
+ if (buffer[1] < depth_min) {
+ BLI_assert(buffer[3] != -1);
+ depth_min = buffer[1];
+ buffer_near = buffer;
+ }
+ buffer += 4;
+ }
+ return buffer_near;
}
/* Part of the solution copied from `rect_subregion_stride_calc`. */
-void GPU_select_buffer_stride_realign(
- const rcti *src, const rcti *dst, uint *r_buf)
+void GPU_select_buffer_stride_realign(const rcti *src, const rcti *dst, uint *r_buf)
{
- const int x = dst->xmin - src->xmin;
- const int y = dst->ymin - src->ymin;
-
- BLI_assert(src->xmin <= dst->xmin && src->ymin <= dst->ymin &&
- src->xmax >= dst->xmax && src->ymax >= dst->ymax);
- BLI_assert(x >= 0 && y >= 0);
-
- const int src_x = BLI_rcti_size_x(src);
- const int src_y = BLI_rcti_size_y(src);
- const int dst_x = BLI_rcti_size_x(dst);
- const int dst_y = BLI_rcti_size_y(dst);
-
- int last_px_written = dst_x * dst_y - 1;
- int last_px_id = src_x * (y + dst_y - 1) + (x + dst_x - 1);
- const int skip = src_x - dst_x;
-
- memset(&r_buf[last_px_id + 1], 0, (src_x * src_y - (last_px_id + 1)) * sizeof(*r_buf));
-
- while (true) {
- for (int i = dst_x; i--;) {
- r_buf[last_px_id--] = r_buf[last_px_written--];
- }
- if (last_px_written < 0) {
- break;
- }
- last_px_id -= skip;
- memset(&r_buf[last_px_id + 1], 0, skip * sizeof(*r_buf));
- }
- memset(r_buf, 0, (last_px_id + 1) * sizeof(*r_buf));
+ const int x = dst->xmin - src->xmin;
+ const int y = dst->ymin - src->ymin;
+
+ BLI_assert(src->xmin <= dst->xmin && src->ymin <= dst->ymin && src->xmax >= dst->xmax &&
+ src->ymax >= dst->ymax);
+ BLI_assert(x >= 0 && y >= 0);
+
+ const int src_x = BLI_rcti_size_x(src);
+ const int src_y = BLI_rcti_size_y(src);
+ const int dst_x = BLI_rcti_size_x(dst);
+ const int dst_y = BLI_rcti_size_y(dst);
+
+ int last_px_written = dst_x * dst_y - 1;
+ int last_px_id = src_x * (y + dst_y - 1) + (x + dst_x - 1);
+ const int skip = src_x - dst_x;
+
+ memset(&r_buf[last_px_id + 1], 0, (src_x * src_y - (last_px_id + 1)) * sizeof(*r_buf));
+
+ while (true) {
+ for (int i = dst_x; i--;) {
+ r_buf[last_px_id--] = r_buf[last_px_written--];
+ }
+ if (last_px_written < 0) {
+ break;
+ }
+ last_px_id -= skip;
+ memset(&r_buf[last_px_id + 1], 0, skip * sizeof(*r_buf));
+ }
+ memset(r_buf, 0, (last_px_id + 1) * sizeof(*r_buf));
}