[Bf-blender-cvs] [1702117] master: Occlusion Query based selection.

Antony Riakiotakis noreply at git.blender.org
Wed Jul 23 15:28:35 CEST 2014


Commit: 17021171f1b544aaa89d4776736255d8753e239c
Author: Antony Riakiotakis
Date:   Wed Jul 23 15:24:07 2014 +0200
Branches: master
https://developer.blender.org/rB17021171f1b544aaa89d4776736255d8753e239c

Occlusion Query based selection.

This patch creates an interface for selection mechanisms in opengl. This
makes it possible to switch between occlusion query based or select
rendermode based selection transparently.

This is really useful on graphics drivers that do not accelerate the
select rendermode path (some ATI cards are notorious for this, and the
new path is used by default there), since occlusion queries are always
hardware accelerated due to their use in games.

The option can be found under system - selection. Auto just enables
occlusion queries for ATI users while the rest of the options enforce
one of the two methods always.

There is just one known change, previous code enforced nearest bone to
always get selected, even when mouse selecting near the same position, I
couldn't replicate the behaviour though.

patch by me with edits and review by Campbell.

Thanks!

===================================================================

M	build_files/cmake/macros.cmake
M	release/scripts/startup/bl_ui/space_userpref.py
M	source/blender/editors/armature/CMakeLists.txt
M	source/blender/editors/armature/SConscript
M	source/blender/editors/armature/armature_select.c
M	source/blender/editors/armature/editarmature_sketch.c
M	source/blender/editors/include/ED_view3d.h
M	source/blender/editors/metaball/mball_edit.c
M	source/blender/editors/space_view3d/drawarmature.c
M	source/blender/editors/space_view3d/drawobject.c
M	source/blender/editors/space_view3d/view3d_select.c
M	source/blender/editors/space_view3d/view3d_view.c
M	source/blender/editors/transform/CMakeLists.txt
M	source/blender/editors/transform/SConscript
M	source/blender/editors/transform/transform_conversions.c
M	source/blender/editors/transform/transform_manipulator.c
M	source/blender/gpu/CMakeLists.txt
A	source/blender/gpu/GPU_select.h
A	source/blender/gpu/intern/gpu_select.c
M	source/blender/makesdna/DNA_userdef_types.h
M	source/blender/makesrna/intern/rna_userdef.c

===================================================================

diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake
index bfd1cf6..8890c13 100644
--- a/build_files/cmake/macros.cmake
+++ b/build_files/cmake/macros.cmake
@@ -493,6 +493,7 @@ macro(SETUP_BLENDER_SORTED_LIBS)
 		bf_bmesh
 		bf_blenkernel
 		bf_nodes
+		bf_rna
 		bf_gpu
 		bf_blenloader
 		bf_imbuf
@@ -532,7 +533,6 @@ macro(SETUP_BLENDER_SORTED_LIBS)
 		extern_openjpeg
 		extern_redcode
 		ge_videotex
-		bf_rna
 		bf_dna
 		bf_blenfont
 		bf_intern_audaspace
diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index cba6f06..bbcd541 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -418,6 +418,12 @@ class USERPREF_PT_system(Panel):
         col.prop(system, "use_16bit_textures")
 
         col.separator()
+        col.label(text="Selection")
+        sub = col.column()
+        sub.active = system.is_occlusion_query_supported()
+        sub.prop(system, "select_method", text="")
+
+        col.separator()
 
         col.label(text="Anisotropic Filtering")
         col.prop(system, "anisotropic_filter", text="")
diff --git a/source/blender/editors/armature/CMakeLists.txt b/source/blender/editors/armature/CMakeLists.txt
index ca2dc1b..9aa17f1 100644
--- a/source/blender/editors/armature/CMakeLists.txt
+++ b/source/blender/editors/armature/CMakeLists.txt
@@ -26,6 +26,7 @@ set(INC
 	../../makesdna
 	../../makesrna
 	../../windowmanager
+	../../gpu
 	../../../../intern/guardedalloc
 )
 
diff --git a/source/blender/editors/armature/SConscript b/source/blender/editors/armature/SConscript
index b3c1ea2..c68045c 100644
--- a/source/blender/editors/armature/SConscript
+++ b/source/blender/editors/armature/SConscript
@@ -39,6 +39,7 @@ incs = [
     '../../blenlib',
     '../../makesdna',
     '../../makesrna',
+    '../../gpu',
     '../../windowmanager',
     ]
 incs = ' '.join(incs)
diff --git a/source/blender/editors/armature/armature_select.c b/source/blender/editors/armature/armature_select.c
index 9c3c93e..12d13b0 100644
--- a/source/blender/editors/armature/armature_select.c
+++ b/source/blender/editors/armature/armature_select.c
@@ -160,7 +160,7 @@ void *get_nearest_bone(bContext *C, short findunsel, int x, int y)
 	rect.ymin = rect.ymax = y;
 	
 	glInitNames();
-	hits = view3d_opengl_select(&vc, buffer, MAXPICKBUF, &rect);
+	hits = view3d_opengl_select(&vc, buffer, MAXPICKBUF, &rect, true);
 
 	if (hits > 0)
 		return get_bone_from_selectbuffer(vc.scene, vc.scene->basact, buffer, hits, findunsel);
@@ -295,13 +295,13 @@ static EditBone *get_nearest_editbonepoint(ViewContext *vc, const int mval[2],
 	rect.ymin = mval[1] - 5;
 	rect.ymax = mval[1] + 5;
 
-	hits = view3d_opengl_select(vc, buffer, MAXPICKBUF, &rect);
+	hits = view3d_opengl_select(vc, buffer, MAXPICKBUF, &rect, true);
 	if (hits == 0) {
 		rect.xmin = mval[0] - 12;
 		rect.xmax = mval[0] + 12;
 		rect.ymin = mval[1] - 12;
 		rect.ymax = mval[1] + 12;
-		hits = view3d_opengl_select(vc, buffer, MAXPICKBUF, &rect);
+		hits = view3d_opengl_select(vc, buffer, MAXPICKBUF, &rect, true);
 	}
 	/* See if there are any selected bones in this group */
 	if (hits > 0) {
diff --git a/source/blender/editors/armature/editarmature_sketch.c b/source/blender/editors/armature/editarmature_sketch.c
index 475ffd2..ba10532 100644
--- a/source/blender/editors/armature/editarmature_sketch.c
+++ b/source/blender/editors/armature/editarmature_sketch.c
@@ -53,6 +53,8 @@
 #include "WM_api.h"
 #include "WM_types.h"
 
+#include "GPU_select.h"
+
 typedef int (*GestureDetectFct)(bContext *, SK_Gesture *, SK_Sketch *);
 typedef void (*GestureApplyFct)(bContext *, SK_Gesture *, SK_Sketch *);
 
@@ -493,7 +495,7 @@ static void sk_drawStroke(SK_Stroke *stk, int id, float color[3], int start, int
 	gluQuadricNormals(quad, GLU_SMOOTH);
 
 	if (id != -1) {
-		glLoadName(id);
+		GPU_select_load_id(id);
 
 		for (i = 0; i < stk->nb_points; i++) {
 			glPushMatrix();
@@ -1969,7 +1971,7 @@ static int sk_selectStroke(bContext *C, SK_Sketch *sketch, const int mval[2], in
 	rect.ymin = mval[1] - 5;
 	rect.ymax = mval[1] + 5;
 
-	hits = view3d_opengl_select(&vc, buffer, MAXPICKBUF, &rect);
+	hits = view3d_opengl_select(&vc, buffer, MAXPICKBUF, &rect, true);
 
 	if (hits > 0) {
 		int besthitresult = -1;
@@ -2032,7 +2034,7 @@ static void sk_drawSketch(Scene *scene, View3D *UNUSED(v3d), SK_Sketch *sketch,
 			sk_drawStroke(stk, id, NULL, -1, -1);
 		}
 
-		glLoadName(-1);
+		GPU_select_load_id(-1);
 	}
 	else {
 		float selected_rgb[3] = {1, 0, 0};
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index ed68dd7..b0ea984 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -270,7 +270,7 @@ bool ED_view3d_autodist_depth_seg(struct ARegion *ar, const int mval_sta[2], con
 
 /* select */
 #define MAXPICKBUF      10000
-short view3d_opengl_select(struct ViewContext *vc, unsigned int *buffer, unsigned int bufsize, const rcti *input);
+short view3d_opengl_select(struct ViewContext *vc, unsigned int *buffer, unsigned int bufsize, const rcti *input, bool do_nearest);
 
 /* view3d_select.c */
 float ED_view3d_select_dist_px(void);
diff --git a/source/blender/editors/metaball/mball_edit.c b/source/blender/editors/metaball/mball_edit.c
index 36c7bb4..feac7f6 100644
--- a/source/blender/editors/metaball/mball_edit.c
+++ b/source/blender/editors/metaball/mball_edit.c
@@ -594,7 +594,7 @@ bool mouse_mball(bContext *C, const int mval[2], bool extend, bool deselect, boo
 	rect.ymin = mval[1] - 12;
 	rect.ymax = mval[1] + 12;
 
-	hits = view3d_opengl_select(&vc, buffer, MAXPICKBUF, &rect);
+	hits = view3d_opengl_select(&vc, buffer, MAXPICKBUF, &rect, true);
 
 	/* does startelem exist? */
 	ml = mb->editelems->first;
diff --git a/source/blender/editors/space_view3d/drawarmature.c b/source/blender/editors/space_view3d/drawarmature.c
index 34634fc..4a6215d 100644
--- a/source/blender/editors/space_view3d/drawarmature.c
+++ b/source/blender/editors/space_view3d/drawarmature.c
@@ -67,6 +67,7 @@
 
 #include "view3d_intern.h"
 
+#include "GPU_select.h"
 
 /* *************** Armature Drawing - Coloring API ***************************** */
 
@@ -551,7 +552,7 @@ static void draw_bone_points(const short dt, int armflag, unsigned int boneflag,
 	/*	Draw root point if we are not connected */
 	if ((boneflag & BONE_CONNECTED) == 0) {
 		if (id != -1)
-			glLoadName(id | BONESEL_ROOT);
+			GPU_select_load_id(id | BONESEL_ROOT);
 		
 		if (dt <= OB_WIRE) {
 			if (armflag & ARM_EDITMODE) {
@@ -574,7 +575,7 @@ static void draw_bone_points(const short dt, int armflag, unsigned int boneflag,
 	
 	/*	Draw tip point */
 	if (id != -1)
-		glLoadName(id | BONESEL_TIP);
+		GPU_select_load_id(id | BONESEL_TIP);
 	
 	if (dt <= OB_WIRE) {
 		if (armflag & ARM_EDITMODE) {
@@ -787,7 +788,7 @@ static void draw_sphere_bone_wire(float smat[4][4], float imat[4][4],
 	/*	Draw root point if we are not connected */
 	if ((boneflag & BONE_CONNECTED) == 0) {
 		if (id != -1)
-			glLoadName(id | BONESEL_ROOT);
+			GPU_select_load_id(id | BONESEL_ROOT);
 		
 		drawcircball(GL_LINE_LOOP, headvec, head, imat);
 	}
@@ -799,7 +800,7 @@ static void draw_sphere_bone_wire(float smat[4][4], float imat[4][4],
 	}
 	
 	if (id != -1)
-		glLoadName(id | BONESEL_TIP);
+		GPU_select_load_id(id | BONESEL_TIP);
 	
 	drawcircball(GL_LINE_LOOP, tailvec, tail, imat);
 	
@@ -830,7 +831,7 @@ static void draw_sphere_bone_wire(float smat[4][4], float imat[4][4],
 		cross_v3_v3v3(norvect, vec, imat[2]);
 		
 		if (id != -1)
-			glLoadName(id | BONESEL_BONE);
+			GPU_select_load_id(id | BONESEL_BONE);
 		
 		glBegin(GL_LINES);
 
@@ -907,7 +908,7 @@ static void draw_sphere_bone(const short dt, int armflag, int boneflag, short co
 	/*	Draw root point if we are not connected */
 	if ((boneflag & BONE_CONNECTED) == 0) {
 		if (id != -1)
-			glLoadName(id | BONESEL_ROOT);
+			GPU_select_load_id(id | BONESEL_ROOT);
 		gluSphere(qobj, head, 16, 10);
 	}
 	
@@ -918,7 +919,7 @@ static void draw_sphere_bone(const short dt, int armflag, int boneflag, short co
 	}
 
 	if (id != -1)
-		glLoadName(id | BONESEL_TIP);
+		GPU_select_load_id(id | BONESEL_TIP);
 	
 	glTranslatef(0.0f, 0.0f, length);
 	gluSphere(qobj, tail, 16, 10);
@@ -939,7 +940,7 @@ static void draw_sphere_bone(const short dt, int armflag, int boneflag, short co
 	
 	if (length > (head + tail)) {
 		if (id != -1)
-			glLoadName(id | BONESEL_BONE);
+			GPU_select_load_id(id | BONESEL_BONE);
 		
 		glEnable(GL_POLYGON_OFFSET_FILL);
 		glPolygonOffset(-1.0f, -1.0f);
@@ -1009,7 +1010,7 @@ static void draw_line_bone(int armflag, int boneflag, short constflag, unsigned
 		/*	Draw root point if we are not connected */
 		if ((boneflag & BONE_CONNECTED) == 0) {
 			if (G.f & G_PICKSEL) {  /* no bitmap in selection mode, crashes 3d cards... */
-				glLoadName(id | BONESEL_ROOT);
+				GPU_select_load_id(id | BONESEL_ROOT);
 				glBegin(GL_POINTS);
 				glVertex3f(0.0f, 0.0f, 0.0f);
 				glEnd();
@@ -1021,7 +1022,7 @@ static void draw_line_bone(int armflag, int boneflag, short constflag, unsigned
 		}
 		
 		if (id != -1)
-			glLoadName((GLuint) id | BONESEL_BONE);
+			GPU_select_load_id((GLuint) id | BONESEL_BONE);
 		
 		glBegin(GL_LINES);
 		glVertex3f(0.0f, 0.0f, 0.0f);
@@ -1031,7 +1032,7 @@ static void draw_line_bone(int armflag, int boneflag, short constflag, unsigned
 		/* tip */
 		if (G.f & G_PICKSEL) {
 			/* no bitmap in selection mode, crashes 3d cards... */
-			glLoadName(id | BONESEL_TIP);
+			GPU_select_load_id(id | BONESEL_TIP);
 			glBegin(GL_POINTS);
 			glVertex3f(0.0f, 1.0f, 0.0f);
 			glEnd();
@@ -1043,7 +1044,7 @@ static void draw_line_bone(int armflag, int boneflag, short constflag, unsigned
 		
 		/* further we send no names */
 		if (id != -1)
-			glLoadName(id & 0xFFFF);  /* object tag, for bordersel optim */
+			GPU_select_load_id(id & 0xFFFF);  /* object tag, for bordersel optim */
 		
 		if (armflag & ARM_POSEMODE)
 			set_pchan_glColor(PCHAN_COLOR_LINEBONE, boneflag, constflag);
@@ -1161,7 +1162,7 @@ static void draw_b_bone(const short dt, int armflag, int boneflag, short constfl
 	}
 	
 	if (id 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list