Pārlūkot izejas kodu

update scaleGrid in sync() phase

ncannasse 9 gadi atpakaļ
vecāks
revīzija
e1a364575a
2 mainītis faili ar 14 papildinājumiem un 6 dzēšanām
  1. 6 3
      h2d/ScaleGrid.hx
  2. 8 3
      h2d/TileGroup.hx

+ 6 - 3
h2d/ScaleGrid.hx

@@ -105,9 +105,12 @@ class ScaleGrid extends h2d.TileGroup {
 		content.addColor(bw, bh, curColor, t);
 	}
 
-	override function draw( ctx : RenderContext ) {
-		if( content.isEmpty() ) updateContent();
-		super.draw(ctx);
+	override function sync( ctx : RenderContext ) {
+		if( content.isEmpty() ) {
+			content.dispose();
+			updateContent();
+		}
+		super.sync(ctx);
 	}
 
 }

+ 8 - 3
h2d/TileGroup.hx

@@ -339,9 +339,12 @@ class TileGroup extends Drawable {
 		content.clear();
 	}
 
+	/**
+		If you want to add tiles after the GPU memory has been allocated (when the tilegroup with sync/displayed),
+		make sure to call invalidate() first to force a refresh of your data.
+	**/
 	public function invalidate() {
-		if( content.buffer!=null )
-			content.buffer.dispose();
+		content.dispose();
 	}
 
 	/**
@@ -386,9 +389,11 @@ class TileGroup extends Drawable {
 
 	@:allow(h2d)
 	function drawWith( ctx:RenderContext, obj : Drawable ) {
+		var max = content.triCount();
+		if( max == 0 )
+			return;
 		ctx.beginDrawObject(obj, tile.getTexture());
 		var min = rangeMin < 0 ? 0 : rangeMin * 2;
-		var max = content.triCount();
 		if( rangeMax > 0 && rangeMax < max * 2 ) max = rangeMax * 2;
 		content.doRender(ctx.engine, min, max - min);
 	}