Forráskód Böngészése

Move math POT functions to hxd.Math

trethaller 6 éve
szülő
commit
212b6d5206
2 módosított fájl, 16 hozzáadás és 16 törlés
  1. 14 0
      hxd/Math.hx
  2. 2 16
      hxd/res/Gradients.hx

+ 14 - 0
hxd/Math.hx

@@ -145,6 +145,20 @@ class Math {
 		return (((v + (v >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24;
 	}
 
+	public static inline function isPOT(v : Int) : Bool {
+		return (v & (v - 1)) == 0;
+	}
+
+	public static inline function nextPOT(v : Int) : Int {
+		--v;
+		v |= v >> 1;
+		v |= v >> 2;
+		v |= v >> 4;
+		v |= v >> 8;
+		v |= v >> 16;
+		return ++v;
+	}
+
 	public static inline function distanceSq( dx : Float, dy : Float, dz = 0. ) {
 		return dx * dx + dy * dy + dz * dz;
 	}

+ 2 - 16
hxd/res/Gradients.hx

@@ -35,10 +35,10 @@ class Gradients extends Resource {
 	}
 
 	static function createTexture(grads : Array<Gradient>, twid : Int) {
-		if (!isPOT(twid)) throw "gradient resolution should be a power of two";
+		if (!hxd.Math.isPOT(twid)) throw "gradient resolution should be a power of two";
 
 		var ghei = grads.length > 1 ? 3 : 1;
-		var thei = nextPOT(ghei * grads.length);
+		var thei = hxd.Math.nextPOT(ghei * grads.length);
 		var tex  = new h3d.mat.Texture(twid, thei);
 
 		function uploadPixels() {
@@ -57,20 +57,6 @@ class Gradients extends Resource {
 		return tex;
 	}
 
-	static inline function isPOT(v : Int) : Bool {
-		return (v & (v - 1)) == 0;
-	}
-
-	static inline function nextPOT(v : Int) : Int {
-		--v;
-		v |= v >> 1;
-		v |= v >> 2;
-		v |= v >> 4;
-		v |= v >> 8;
-		v |= v >> 16;
-		return ++v;
-	}
-
 	static function appendPixels(pixels : hxd.Pixels, dat : Gradient, wid : Int, hei : Int, yoff : Int) {
 		var colors = new Array<{value : h3d.Vector, loc : Int}>();