3D View: wrap GPU_select cache calls

Avoids including GPU_select and makes it more clear that the cache is
needed for view3d_opengl_select calls.

Also use typed enum for select mode.
This commit is contained in:
Campbell Barton 2017-03-09 20:47:37 +11:00
parent 4ab322fdd2
commit 88e8e7a074
4 changed files with 26 additions and 12 deletions

@ -53,8 +53,6 @@
#include "ED_screen.h" #include "ED_screen.h"
#include "ED_view3d.h" #include "ED_view3d.h"
#include "GPU_select.h"
#include "armature_intern.h" #include "armature_intern.h"
/* utility macros for storing a temp int in the bone (selection flag) */ /* utility macros for storing a temp int in the bone (selection flag) */
@ -343,7 +341,7 @@ static EditBone *get_nearest_editbonepoint(
int hits = 0; int hits = 0;
/* we _must_ end cache before return, use 'goto cache_end' */ /* we _must_ end cache before return, use 'goto cache_end' */
GPU_select_cache_begin(); view3d_opengl_select_cache_begin();
BLI_rcti_init_pt_radius(&rect, mval, 12); BLI_rcti_init_pt_radius(&rect, mval, 12);
hits12 = view3d_opengl_select(vc, buffer, MAXPICKBUF, &rect, select_mode); hits12 = view3d_opengl_select(vc, buffer, MAXPICKBUF, &rect, select_mode);
@ -368,7 +366,7 @@ static EditBone *get_nearest_editbonepoint(
} }
cache_end: cache_end:
GPU_select_cache_end(); view3d_opengl_select_cache_end();
/* See if there are any selected bones in this group */ /* See if there are any selected bones in this group */
if (hits > 0) { if (hits > 0) {

@ -303,18 +303,21 @@ bool ED_view3d_autodist_depth_seg(struct ARegion *ar, const int mval_sta[2], con
#define MAXPICKELEMS 2500 #define MAXPICKELEMS 2500
#define MAXPICKBUF (4 * MAXPICKELEMS) #define MAXPICKBUF (4 * MAXPICKELEMS)
enum { typedef enum {
/* all elements in the region, ignore depth */ /* all elements in the region, ignore depth */
VIEW3D_SELECT_ALL = 0, VIEW3D_SELECT_ALL = 0,
/* pick also depth sorts (only for small regions!) */ /* pick also depth sorts (only for small regions!) */
VIEW3D_SELECT_PICK_ALL = 1, VIEW3D_SELECT_PICK_ALL = 1,
/* sorts and only returns visible objects (only for small regions!) */ /* sorts and only returns visible objects (only for small regions!) */
VIEW3D_SELECT_PICK_NEAREST = 2, VIEW3D_SELECT_PICK_NEAREST = 2,
}; } eV3DSelectMode;
void view3d_opengl_select_cache_begin(void);
void view3d_opengl_select_cache_end(void);
int view3d_opengl_select( int view3d_opengl_select(
struct ViewContext *vc, unsigned int *buffer, unsigned int bufsize, const struct rcti *input, struct ViewContext *vc, unsigned int *buffer, unsigned int bufsize, const struct rcti *input,
int select_mode); eV3DSelectMode select_mode);
/* view3d_select.c */ /* view3d_select.c */
float ED_view3d_select_dist_px(void); float ED_view3d_select_dist_px(void);

@ -96,8 +96,6 @@
#include "GPU_draw.h" #include "GPU_draw.h"
#include "GPU_select.h"
#include "view3d_intern.h" /* own include */ #include "view3d_intern.h" /* own include */
// #include "PIL_time_utildefines.h" // #include "PIL_time_utildefines.h"
@ -1243,7 +1241,7 @@ static int mixed_bones_object_selectbuffer(
int hits = 0; int hits = 0;
/* we _must_ end cache before return, use 'goto finally' */ /* we _must_ end cache before return, use 'goto finally' */
GPU_select_cache_begin(); view3d_opengl_select_cache_begin();
BLI_rcti_init_pt_radius(&rect, mval, 14); BLI_rcti_init_pt_radius(&rect, mval, 14);
hits15 = view3d_opengl_select(vc, buffer, MAXPICKBUF, &rect, select_mode); hits15 = view3d_opengl_select(vc, buffer, MAXPICKBUF, &rect, select_mode);
@ -1287,7 +1285,7 @@ static int mixed_bones_object_selectbuffer(
} }
finally: finally:
GPU_select_cache_end(); view3d_opengl_select_cache_end();
return hits; return hits;
} }

@ -1163,6 +1163,21 @@ static void view3d_select_loop(ViewContext *vc, Scene *scene, View3D *v3d, ARegi
} }
} }
/**
* Optionally cache data for multiple calls to #view3d_opengl_select
*
* just avoid GPU_select headers outside this file
*/
void view3d_opengl_select_cache_begin(void)
{
GPU_select_cache_begin();
}
void view3d_opengl_select_cache_end(void)
{
GPU_select_cache_end();
}
/** /**
* \warning be sure to account for a negative return value * \warning be sure to account for a negative return value
* This is an error, "Too many objects in select buffer" * This is an error, "Too many objects in select buffer"
@ -1172,7 +1187,7 @@ static void view3d_select_loop(ViewContext *vc, Scene *scene, View3D *v3d, ARegi
*/ */
int view3d_opengl_select( int view3d_opengl_select(
ViewContext *vc, unsigned int *buffer, unsigned int bufsize, const rcti *input, ViewContext *vc, unsigned int *buffer, unsigned int bufsize, const rcti *input,
int select_mode) eV3DSelectMode select_mode)
{ {
Scene *scene = vc->scene; Scene *scene = vc->scene;
View3D *v3d = vc->v3d; View3D *v3d = vc->v3d;