Просмотр исходного кода

Introduce TextureCache.allocTileTarget
Backward compat for Tile.fromColor

Yanrishatum 6 лет назад
Родитель
Сommit
67f452e79d

+ 1 - 1
h2d/Tile.hx

@@ -194,7 +194,7 @@ class Tile {
 	}
 
 
-	public static function fromColor( color : Int, ?width = 1., ?height = 1., ?alpha = 1., ?allocPos : h3d.impl.AllocPos ) : Tile {
+	public static function fromColor( color : Int, ?width = 1, ?height = 1, ?alpha = 1., ?allocPos : h3d.impl.AllocPos ) : Tile {
 		var t = new Tile(h3d.mat.Texture.fromColor(color,alpha,allocPos),0,0,1,1);
 		// scale to size
 		t.width = width;

+ 1 - 1
h2d/filter/Ambient.hx

@@ -17,7 +17,7 @@ class Ambient extends AbstractMask {
 	inline function set_invert(v) return pass.shader.maskInvert = v;
 
 	override function draw( ctx : RenderContext, t : h2d.Tile ) {
-		var out = ctx.textures.allocTarget("ambientTmp", hxd.Math.ceil(t.width), hxd.Math.ceil(t.height), false);
+		var out = ctx.textures.allocTileTarget("ambientTmp", t);
 		pass.apply(t.getTexture(), out, getMaskTexture(t), maskMatrix);
 		return h2d.Tile.fromTexture(out);
 	}

+ 1 - 1
h2d/filter/Bloom.hx

@@ -20,7 +20,7 @@ class Bloom extends Blur {
 	inline function set_power(v) return bloom.shader.power = v;
 
 	override function draw( ctx : RenderContext, t : h2d.Tile ) {
-		var dst = ctx.textures.allocTarget("dest", hxd.Math.ceil(t.width), hxd.Math.ceil(t.height), false);
+		var dst = ctx.textures.allocTileTarget("dest", t);
 		h3d.pass.Copy.run(t.getTexture(), dst);
 		var blurred = super.draw(ctx, t);
 		bloom.shader.texture = blurred.getTexture();

+ 1 - 1
h2d/filter/ColorMatrix.hx

@@ -16,7 +16,7 @@ class ColorMatrix extends Filter {
 	inline function set_matrix(m) return pass.matrix = m;
 
 	override function draw( ctx : RenderContext, t : h2d.Tile ) {
-		var tout = ctx.textures.allocTarget("colorMatrixOut", hxd.Math.ceil(t.width), hxd.Math.ceil(t.height), false);
+		var tout = ctx.textures.allocTileTarget("colorMatrixOut", t);
 		pass.apply(t.getTexture(), tout);
 		return h2d.Tile.fromTexture(tout);
 	}

+ 1 - 1
h2d/filter/Displacement.hx

@@ -28,7 +28,7 @@ class Displacement extends Filter {
 	}
 
 	override function draw( ctx : RenderContext, t : h2d.Tile ) {
-		var out = ctx.textures.allocTarget("displacementOutput", hxd.Math.ceil(t.width), hxd.Math.ceil(t.height), false);
+		var out = ctx.textures.allocTileTarget("displacementOutput", t);
 		ctx.engine.pushTarget(out);
 		var s = disp.shader;
 		s.texture = t.getTexture();

+ 1 - 1
h2d/filter/DropShadow.hx

@@ -21,7 +21,7 @@ class DropShadow extends Glow {
 
 	override function draw( ctx : RenderContext, t : h2d.Tile ) {
 		setParams();
-		var save = ctx.textures.allocTarget("glowSave", hxd.Math.ceil(t.width), hxd.Math.ceil(t.height), false);
+		var save = ctx.textures.allocTileTarget("glowSave", t);
 		h3d.pass.Copy.run(t.getTexture(), save, None);
 		pass.apply(ctx, save);
 		var dx = Math.round(Math.cos(angle) * distance);

+ 1 - 1
h2d/filter/Glow.hx

@@ -25,7 +25,7 @@ class Glow extends Blur {
 		setParams();
 		var tex = t.getTexture();
 		var old = tex.filter;
-		var save = ctx.textures.allocTarget("glowSave", hxd.Math.ceil(t.width), hxd.Math.ceil(t.height), false);
+		var save = ctx.textures.allocTileTarget("glowSave", t);
 		h3d.pass.Copy.run(tex, save, None);
 		tex.filter = Linear;
 		pass.apply(ctx, tex);

+ 1 - 1
h2d/filter/Mask.hx

@@ -42,7 +42,7 @@ class Mask extends AbstractMask {
 		var mask = getMaskTexture(t);
 		if( mask == null )
 			throw "Mask should be rendered before masked object";
-		var out = ctx.textures.allocTarget("maskTmp", hxd.Math.ceil(t.width), hxd.Math.ceil(t.height), false);
+		var out = ctx.textures.allocTileTarget("maskTmp", t);
 		ctx.engine.pushTarget(out);
 		pass.shader.texture = t.getTexture();
 		pass.shader.mask = getMaskTexture(t);

+ 1 - 1
h2d/filter/Shader.hx

@@ -24,7 +24,7 @@ class Shader< T:h3d.shader.ScreenShader > extends Filter {
 	function get_shader() return pass.shader;
 
 	override function draw( ctx : RenderContext, t : h2d.Tile ) {
-		var out = ctx.textures.allocTarget("shaderTmp", hxd.Math.ceil(t.width), hxd.Math.ceil(t.height), false);
+		var out = ctx.textures.allocTileTarget("shaderTmp", t);
 		ctx.engine.pushTarget(out);
 		Reflect.setField(shader, textureParam + "__", t.getTexture());
 		if( nearest ) t.getTexture().filter = Nearest;

+ 4 - 0
h3d/impl/TextureCache.hx

@@ -59,6 +59,10 @@ class TextureCache {
 		return allocTarget(name, Math.ceil(e.width * scale), Math.ceil(e.height * scale), defaultDepth, format);
 	}
 
+	public function allocTileTarget( name : String, tile : h2d.Tile, defaultDepth=false, ?format:hxd.PixelFormat, ?flags:Array<h3d.mat.Data.TextureFlags> ) {
+		return allocTarget( name, tile.iwidth, tile.iheight, defaultDepth, format, flags );
+	}
+
 	public function dispose() {
 		for( t in cache )
 			t.dispose();