[sldev] getting serious about software.

Nicholaz Beresford nicholaz at blueflash.cc
Sat Jun 23 06:28:05 PDT 2007


Just for the fun of it, here's my version
(it's exactly the same behavior as the float
version, not rounding up numbers that are already
powers of two).


Nick


Second Life from the inside out:
http://nicholaz-beresford.blogspot.com/
-------------- next part --------------
--- linden-orig\indra\llmath\llvolume.cpp	2007-06-13 10:13:18.000000000 +0200
+++ linden\indra\llmath\llvolume.cpp	2007-06-23 15:06:49.921875000 +0200
@@ -461,6 +461,16 @@
 	return pow(2.0f, power);
 }
 
+S32 next_power_of_two(S32 n)
+{
+	S32 res = (n<(1<<15)) ? (1<<15) : (1<<30);
+
+	while (res>=n) {
+		res>>= 1;
+	}
+
+	return (res<<1);
+}
 
 
 BOOL LLProfile::generate(BOOL path_open,F32 detail, S32 split, BOOL is_sculpted)
@@ -605,7 +615,7 @@
 			S32 sides = (S32)circle_detail;
 
 			if (is_sculpted)
-				sides = (S32)next_power_of_two((F32)sides);
+				sides = next_power_of_two(sides);
 			
 			genNGon(sides);
 			
@@ -1148,7 +1158,7 @@
 			S32 sides = (S32)llfloor(llfloor((MIN_DETAIL_FACES * detail + twist_mag * 3.5f * (detail-0.5f))) * mParams.getRevolutions());
 
 			if (is_sculpted)
-				sides = (S32)next_power_of_two((F32)sides);
+				sides = next_power_of_two(sides);
 			
 			genNGon(sides);
 		}


More information about the SLDev mailing list