[Bf-committers] Hard vert and face limit.

Robert Wenzlaff bf-committers@blender.org
Tue, 2 Sep 2003 22:59:50 -0400


--Boundary-00=_mkVV/NMaf9AqIAQ
Content-Type: text/plain;
  charset="us-ascii"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

After showing alltaken how to raise the hardcoded limit in 
blender/source/blender/render/extern/include/render_types.h
I started looking at making the Vert and Face tables dynamically sized from 
the scene data.

Changing the allocation was easy, coming up with a reliable pixel and face 
count was tough.  R.totvert is counted as the tables are loaded.  The meaning 
of G.totvert changes depending whether you are in editmode, and 
RE_init_render_data() was called before it was set anyway.

So, I changed RE_init_render() to be "reentrant", ie; it can be saffely called 
any time, and added a call to it i do_render().   But G.totverts still 
changed meaning with editmode, and it wasn't set at all if you didn't select 
at least 1 object.   So when init_render_data() is called, if editmode is 
detected, I save the current G.obedit, G.totface, and G.totvert, clear 
G.obedit and call countall().  If you are in editmode, I add the old 
G.totvert and G.totface to the totals, or you miss any new verts and faces 
made in editmode.  It over allocates a little, since the old verts and faces 
are in the non-edit G.tot numbers, but its' still more efficient than 
allocating for 2M verts always.  My .blend went from, allocating 0.91M to 
0.82M.  My 2.269M vert test file went from 62.43M to 62.34M. 

I then allocate the tables based on those numbers >>7 (since they are not even 
powers of 2 they always seem to be too small if  I >>8 ).  When done, I 
restore G.obedit and the counts.

Only 2 other files used these #defines. renderdatabase.c had a couple of upper 
limit checks  that I removed in RE_findOrAddVlak, and RE_findOrAddVert, and 
convertBlenderScene.c had a limit on stars and verts.  There is an alocation 
in sort_halos() that I'm not sure how to handle.  Currently I have :
R.bloha= (HaloRen **)MEM_callocN(sizeof(void *)*((R.totvert>>7)+1),"Bloha");
Since I think halos are done after the vert tables are filled,  R.totvert 
should be valid.  It hasn't segfaulted yet on me doing halos...   Please 
correct me if you think this is wrong.

Anyone see a problem with this method?  Are there other places in the code I 
need to modify?
-- 
**********************************************
  Lesson learned from watching 'DragonballZ':
              Jedis are wimps.
**********************************************
Robert Wenzlaff    rwenzlaff@soylent-green.com

--Boundary-00=_mkVV/NMaf9AqIAQ
Content-Type: text/x-diff;
  charset="us-ascii";
  name="MaxVert.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="MaxVert.patch"

Index: source/blender/renderconverter/intern/convertBlenderScene.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/renderconverter/intern/convertBlenderScene.c,v
retrieving revision 1.8
diff -u -r1.8 convertBlenderScene.c
--- source/blender/renderconverter/intern/convertBlenderScene.c	17 Aug 2003 15:57:12 -0000	1.8
+++ source/blender/renderconverter/intern/convertBlenderScene.c	3 Sep 2003 02:51:51 -0000
@@ -301,13 +301,13 @@
 					}
 				}
 			}
-			if(done > MAXVERT) {
-				printf("Too many stars\n");
-				break;
-			}
+//			if(done > MAXVERT) {
+//				printf("Too many stars\n");
+//				break;
+//			}
 			if(blender_test_break()) break;
 		}
-		if(done > MAXVERT) break;
+//		if(done > MAXVERT) break;
 
 		if(blender_test_break()) break;
 	}
@@ -1348,7 +1348,7 @@
 	/* re-assamble R.bloha */
 
 	bloha= R.bloha;
-	R.bloha= (HaloRen **)MEM_callocN(sizeof(void *)*(MAXVERT>>8),"Bloha");
+	R.bloha= (HaloRen **)MEM_callocN(sizeof(void *)*((R.totvert>>7)+1),"Bloha");
 
 	haso= hablock;
 	for(a=0; a<R.tothalo; a++) {
Index: source/blender/render/intern/source/renderdatabase.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/render/intern/source/renderdatabase.c,v
retrieving revision 1.4
diff -u -r1.4 renderdatabase.c
--- source/blender/render/intern/source/renderdatabase.c	28 Apr 2003 11:25:42 -0000	1.4
+++ source/blender/render/intern/source/renderdatabase.c	3 Sep 2003 02:51:51 -0000
@@ -78,7 +78,7 @@
 	VertRen *v;
 	int a;
 
-	if(nr<0 || nr>MAXVERT ) {
+	if(nr<0 ) {
 		printf("error in findOrAddVert: %d\n",nr);
 		return R.blove[0];
 	}
@@ -99,7 +99,7 @@
 	HaloRen *h;
 	int a;
 
-	if(nr<0 || nr>MAXVERT ) {
+	if(nr<0 ) {
 		printf("error in findOrAddHalo: %d\n",nr);
 		return R.bloha[0];
 	}
@@ -120,7 +120,7 @@
 	VlakRen *v;
 	int a;
 
-	if(nr<0 || nr>MAXVLAK ) {
+	if(nr<0) {
 		printf("error in findOrAddVlak: %d\n",nr);
 		return R.blovl[0];
 	}
Index: source/blender/render/intern/source/initrender.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/render/intern/source/initrender.c,v
retrieving revision 1.8
diff -u -r1.8 initrender.c
--- source/blender/render/intern/source/initrender.c	24 May 2003 20:04:33 -0000	1.8
+++ source/blender/render/intern/source/initrender.c	3 Sep 2003 02:51:53 -0000
@@ -80,6 +80,7 @@
 #include "BIF_writemovie.h"		/* start_movie(), append_movie(), end_movie() */
 
 #include "BSE_drawview.h"
+#include "BSE_edit.h"	/* countall() */
 #include "BSE_sequence.h"
 
 #ifdef WITH_QUICKTIME
@@ -131,14 +132,59 @@
 
 void RE_init_render_data(void)
 {
-	memset(&R, 0, sizeof(RE_Render));
-	memset(&O, 0, sizeof(Osa));
-	O.dxwin[0]= 1.0;
-	O.dywin[1]= 1.0;
-	
-	R.blove= (VertRen **)MEM_callocN(sizeof(void *)*(MAXVERT>>8),"Blove");
-	R.blovl= (VlakRen **)MEM_callocN(sizeof(void *)*(MAXVLAK>>8),"Blovl");
-	R.bloha= (HaloRen **)MEM_callocN(sizeof(void *)*(MAXVERT>>8),"Bloha");
+	int oldtotvert=0, totvert, oldtotface=0, totface;
+	short editmode=0;
+	Object *temp;
+	/* Update Vert and Face count  - Need to make a custom count function so
+	   we don't invalidate the editmode buffer.  */
+	if (G.obedit) {
+		printf("editmode detected.\n");
+		oldtotvert=G.totvert;
+		oldtotface=G.totface;
+		temp=G.obedit;
+		G.obedit=0;
+		editmode=1;
+	}
+	
+	countall();
+	totvert=G.totvert+oldtotvert; /* To cover new verts and faces made in editmode */
+	totface=G.totface+oldtotface; /* It over estimates a bit, but still better than always */
+				      /* allocating for the max. */
+	
+	printf("Totverts=%i, totalvlak=%i\n", totvert, totface);
+	
+	if (editmode) {
+		G.totvert=oldtotvert;
+		G.totface=oldtotface;
+		G.obedit=temp;
+	}
+	
+	
+		
+	if (R.blove) { /*Free previously allocated tables*/
+		MEM_freeN(R.blove);
+		R.blove= 0;
+		MEM_freeN(R.blovl);
+		R.blovl= 0;
+		MEM_freeN(R.bloha);
+		R.bloha= 0;
+		MEM_freeN(R.la);
+		R.la= 0;	
+	}
+	else {	/* First time, then fill renother render data*/
+		memset(&R, 0, sizeof(RE_Render));
+		memset(&O, 0, sizeof(Osa));
+		O.dxwin[0]= 1.0;
+		O.dywin[1]= 1.0;
+	}
+	
+		
+	printf("allocating renderdata. %i groups of VertRen, %i groups of VlakRen.\n", 
+		((totvert)>>7)+1, ((totface)>>7)+1);
+	/*Allocate the tables  totvlak not a power of 2,  So >>7 instead of >>8 */
+	R.blove= (VertRen **)MEM_callocN(sizeof(void *)*((totvert>>7)+1),"Blove");
+	R.blovl= (VlakRen **)MEM_callocN(sizeof(void *)*((totface>>7)+1),"Blovl");
+	R.bloha= (HaloRen **)MEM_callocN(sizeof(void *)*((totvert>>7)+1),"Bloha");
 	R.la= (LampRen **)MEM_mallocN(MAXLAMP*sizeof(void *),"renderlamparray");
 
 	init_def_material();
Index: source/blender/src/renderwin.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/renderwin.c,v
retrieving revision 1.22
diff -u -r1.22 renderwin.c
--- source/blender/src/renderwin.c	19 Jul 2003 20:19:31 -0000	1.22
+++ source/blender/src/renderwin.c	3 Sep 2003 02:51:54 -0000
@@ -777,6 +777,8 @@
 
 static void do_render(View3D *ogl_render_view3d, int anim, int force_dispwin)
 {
+	RE_init_render_data();
+	
 	if (R.displaymode == R_DISPLAYWIN || force_dispwin) {
 		RE_set_initrenderdisplay_callback(NULL);
 		RE_set_clearrenderdisplay_callback(renderwin_clear_display_cb);

--Boundary-00=_mkVV/NMaf9AqIAQ--