[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [33330] trunk/blender/source/blender/ editors: bugfix [#23118] Blender freezes when combing hair - OS X path changes related?

Campbell Barton ideasman42 at gmail.com
Fri Nov 26 13:57:35 CET 2010


Revision: 33330
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=33330
Author:   campbellbarton
Date:     2010-11-26 13:57:35 +0100 (Fri, 26 Nov 2010)

Log Message:
-----------
bugfix [#23118] Blender freezes when combing hair - OS X path changes related?
- glReadPixels() was running to get the depth on each pixel, this works fine one some cards but was locking up on OSX.
- Replace glReadPixels() call with a single call to view3d_update_depths() right after view3d_validate_backbuf(), so the depths are only read once.
- Unrelated to the changes above, but should improve performance: view3d_validate_backbuf() was being called on every redraw while combing, now only call once when combing starts.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/include/ED_view3d.h
    trunk/blender/source/blender/editors/physics/particle_edit.c
    trunk/blender/source/blender/editors/space_view3d/view3d_intern.h

Modified: trunk/blender/source/blender/editors/include/ED_view3d.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_view3d.h	2010-11-26 12:38:42 UTC (rev 33329)
+++ trunk/blender/source/blender/editors/include/ED_view3d.h	2010-11-26 12:57:35 UTC (rev 33330)
@@ -79,6 +79,7 @@
 void view3d_unproject(struct bglMats *mats, float out[3], const short x, const short y, const float z);
 
 /* Depth buffer */
+void view3d_update_depths(struct ARegion *ar);
 float read_cached_depth(struct ViewContext *vc, int x, int y);
 void request_depth_update(struct RegionView3D *rv3d);
 

Modified: trunk/blender/source/blender/editors/physics/particle_edit.c
===================================================================
--- trunk/blender/source/blender/editors/physics/particle_edit.c	2010-11-26 12:38:42 UTC (rev 33329)
+++ trunk/blender/source/blender/editors/physics/particle_edit.c	2010-11-26 12:57:35 UTC (rev 33330)
@@ -30,6 +30,7 @@
 #include <stdlib.h>
 #include <math.h>
 #include <string.h>
+#include <assert.h>
 
 #include "MEM_guardedalloc.h"
 
@@ -369,8 +370,16 @@
 	/* note, the object argument means the modelview matrix does not account for the objects matrix, use viewmat rather then (obmat * viewmat) */
 	view3d_get_transformation(data->vc.ar, data->vc.rv3d, NULL, &data->mats);
 
-	if((data->vc.v3d->drawtype>OB_WIRE) && (data->vc.v3d->flag & V3D_ZBUF_SELECT))
-		view3d_validate_backbuf(&data->vc);
+	if((data->vc.v3d->drawtype>OB_WIRE) && (data->vc.v3d->flag & V3D_ZBUF_SELECT)) {
+		if(data->vc.v3d->flag & V3D_INVALID_BACKBUF) {
+			view3d_validate_backbuf(&data->vc);
+
+			/* we may need to force an update here by setting the rv3d as dirty
+			 * for now it seems ok, but take care!:
+			 * rv3d->depths->dirty = 1; */
+			view3d_update_depths(data->vc.ar);
+		}
+	}
 }
 
 /*************************** selection utilities *******************************/
@@ -397,14 +406,23 @@
 	x=wco[0];
 	y=wco[1];
 
+#if 0 /* works well but too slow on some systems [#23118] */
 	x+= (short)data->vc.ar->winrct.xmin;
 	y+= (short)data->vc.ar->winrct.ymin;
 
 	/* PE_set_view3d_data calls this. no need to call here */
 	/* view3d_validate_backbuf(&data->vc); */
 	glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depth);
+#else /* faster to use depths, these are calculated in PE_set_view3d_data */
+	{
+		ViewDepths *vd = data->vc.rv3d->depths;
+		assert(vd && vd->depths);
+		/* we know its not clipped */
+		depth= vd->depths[y * vd->w + x];
+	}
+#endif
 
-	if((float)uz - 0.0001 > depth)
+	if((float)uz - 0.00001 > depth)
 		return 0;
 	else
 		return 1;
@@ -3321,6 +3339,9 @@
 
 	int first;
 	int lastmouse[2];
+
+	/* optional cached view settings to avoid setting on every mousemove */
+	PEData data;
 } BrushEdit;
 
 static int brush_edit_init(bContext *C, wmOperator *op)
@@ -3345,6 +3366,9 @@
 	bedit->ob= ob;
 	bedit->edit= edit;
 
+	/* cache view depths and settings for re-use */
+	PE_set_view3d_data(C, &bedit->data);
+
 	return 1;
 }
 
@@ -3392,6 +3416,7 @@
 	if(((pset->brushtype == PE_BRUSH_ADD) ?
 		(sqrt(dx * dx + dy * dy) > pset->brush[PE_BRUSH_ADD].step) : (dx != 0 || dy != 0))
 		|| bedit->first) {
+		PEData data= bedit->data;
 
 		view3d_operator_needs_opengl(C);
 		selected= (short)count_selected_keys(scene, edit);
@@ -3399,9 +3424,6 @@
 		switch(pset->brushtype) {
 			case PE_BRUSH_COMB:
 			{
-				PEData data;
-
-				PE_set_view3d_data(C, &data);
 				data.mval= mval;
 				data.rad= (float)brush->size;
 
@@ -3421,10 +3443,7 @@
 			}
 			case PE_BRUSH_CUT:
 			{
-				PEData data;
-				
 				if(edit->psys && edit->pathcache) {
-					PE_set_view3d_data(C, &data);
 					data.mval= mval;
 					data.rad= (float)brush->size;
 					data.cutfac= brush->strength;
@@ -3445,9 +3464,6 @@
 			}
 			case PE_BRUSH_LENGTH:
 			{
-				PEData data;
-				
-				PE_set_view3d_data(C, &data);
 				data.mval= mval;
 				
 				data.rad= (float)brush->size;
@@ -3466,10 +3482,7 @@
 			}
 			case PE_BRUSH_PUFF:
 			{
-				PEData data;
-
 				if(edit->psys) {
-					PE_set_view3d_data(C, &data);
 					data.dm= psmd->dm;
 					data.mval= mval;
 					data.rad= (float)brush->size;
@@ -3490,10 +3503,7 @@
 			}
 			case PE_BRUSH_ADD:
 			{
-				PEData data;
-
 				if(edit->psys && edit->psys->part->from==PART_FROM_FACE) {
-					PE_set_view3d_data(C, &data);
 					data.mval= mval;
 
 					added= brush_add(&data, brush->count);
@@ -3507,9 +3517,6 @@
 			}
 			case PE_BRUSH_SMOOTH:
 			{
-				PEData data;
-
-				PE_set_view3d_data(C, &data);
 				data.mval= mval;
 				data.rad= (float)brush->size;
 
@@ -3531,9 +3538,6 @@
 			}
 			case PE_BRUSH_WEIGHT:
 			{
-				PEData data;
-				PE_set_view3d_data(C, &data);
-
 				if(edit->psys) {
 					data.dm= psmd->dm;
 					data.mval= mval;

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_intern.h
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_intern.h	2010-11-26 12:38:42 UTC (rev 33329)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_intern.h	2010-11-26 12:57:35 UTC (rev 33330)
@@ -136,7 +136,6 @@
 
 void circf(float x, float y, float rad);
 void circ(float x, float y, float rad);
-void view3d_update_depths(struct ARegion *ar);
 void view3d_update_depths_rect(struct ARegion *ar, struct ViewDepths *d, struct rcti *rect);
 float view3d_depth_near(struct ViewDepths *d);
 





More information about the Bf-blender-cvs mailing list