|
@@ -1,6 +1,4 @@
|
|
package h2d;
|
|
package h2d;
|
|
-import h2d.RenderContext;
|
|
|
|
-import h2d.impl.BatchDrawState;
|
|
|
|
import hxd.Math;
|
|
import hxd.Math;
|
|
|
|
|
|
private typedef GraphicsPoint = hxd.poly2tri.Point;
|
|
private typedef GraphicsPoint = hxd.poly2tri.Point;
|
|
@@ -30,9 +28,8 @@ private class GraphicsContent extends h3d.prim.Primitive {
|
|
|
|
|
|
var tmp : hxd.FloatBuffer;
|
|
var tmp : hxd.FloatBuffer;
|
|
var index : hxd.IndexBuffer;
|
|
var index : hxd.IndexBuffer;
|
|
- var state : BatchDrawState;
|
|
|
|
|
|
|
|
- var buffers : Array<{ buf : hxd.FloatBuffer, vbuf : h3d.Buffer, idx : hxd.IndexBuffer, ibuf : h3d.Indexes, state : BatchDrawState }>;
|
|
|
|
|
|
+ var buffers : Array<{ buf : hxd.FloatBuffer, vbuf : h3d.Buffer, idx : hxd.IndexBuffer, ibuf : h3d.Indexes }>;
|
|
var bufferDirty : Bool;
|
|
var bufferDirty : Bool;
|
|
var indexDirty : Bool;
|
|
var indexDirty : Bool;
|
|
#if track_alloc
|
|
#if track_alloc
|
|
@@ -41,7 +38,6 @@ private class GraphicsContent extends h3d.prim.Primitive {
|
|
|
|
|
|
public function new() {
|
|
public function new() {
|
|
buffers = [];
|
|
buffers = [];
|
|
- state = new BatchDrawState();
|
|
|
|
#if track_alloc
|
|
#if track_alloc
|
|
this.allocPos = new hxd.impl.AllocPos();
|
|
this.allocPos = new hxd.impl.AllocPos();
|
|
#end
|
|
#end
|
|
@@ -49,7 +45,6 @@ private class GraphicsContent extends h3d.prim.Primitive {
|
|
|
|
|
|
public inline function addIndex(i) {
|
|
public inline function addIndex(i) {
|
|
index.push(i);
|
|
index.push(i);
|
|
- state.add(1);
|
|
|
|
indexDirty = true;
|
|
indexDirty = true;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -65,22 +60,13 @@ private class GraphicsContent extends h3d.prim.Primitive {
|
|
bufferDirty = true;
|
|
bufferDirty = true;
|
|
}
|
|
}
|
|
|
|
|
|
- public function setTile( tile : h2d.Tile ) {
|
|
|
|
- state.setTile(tile);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public function next() {
|
|
public function next() {
|
|
var nvect = tmp.length >> 3;
|
|
var nvect = tmp.length >> 3;
|
|
- if( nvect < 1 << 15 ) {
|
|
|
|
|
|
+ if( nvect < 1 << 15 )
|
|
return false;
|
|
return false;
|
|
- }
|
|
|
|
- buffers.push( { buf : tmp, idx : index, vbuf : null, ibuf : null, state: state } );
|
|
|
|
-
|
|
|
|
|
|
+ buffers.push( { buf : tmp, idx : index, vbuf : null, ibuf : null } );
|
|
tmp = new hxd.FloatBuffer();
|
|
tmp = new hxd.FloatBuffer();
|
|
index = new hxd.IndexBuffer();
|
|
index = new hxd.IndexBuffer();
|
|
- var tex = state.currentTexture;
|
|
|
|
- state = new BatchDrawState();
|
|
|
|
- state.setTexture(tex);
|
|
|
|
super.dispose();
|
|
super.dispose();
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
@@ -100,11 +86,12 @@ private class GraphicsContent extends h3d.prim.Primitive {
|
|
indexDirty = false;
|
|
indexDirty = false;
|
|
}
|
|
}
|
|
|
|
|
|
- public function doRender( ctx : h2d.RenderContext ) {
|
|
|
|
- if (index.length <= 0) return;
|
|
|
|
|
|
+ override function render( engine : h3d.Engine ) {
|
|
|
|
+ if (index.length <= 0) return ;
|
|
flush();
|
|
flush();
|
|
- for ( b in buffers ) b.state.drawIndexed(ctx, b.vbuf, b.ibuf);
|
|
|
|
- state.drawIndexed(ctx, buffer, indexes);
|
|
|
|
|
|
+ for( b in buffers )
|
|
|
|
+ engine.renderIndexed(b.vbuf, b.ibuf);
|
|
|
|
+ super.render(engine);
|
|
}
|
|
}
|
|
|
|
|
|
public inline function flush() {
|
|
public inline function flush() {
|
|
@@ -128,11 +115,9 @@ private class GraphicsContent extends h3d.prim.Primitive {
|
|
for( b in buffers ) {
|
|
for( b in buffers ) {
|
|
if( b.vbuf != null ) b.vbuf.dispose();
|
|
if( b.vbuf != null ) b.vbuf.dispose();
|
|
if( b.ibuf != null ) b.ibuf.dispose();
|
|
if( b.ibuf != null ) b.ibuf.dispose();
|
|
- b.state.clear();
|
|
|
|
b.vbuf = null;
|
|
b.vbuf = null;
|
|
b.ibuf = null;
|
|
b.ibuf = null;
|
|
}
|
|
}
|
|
- state.clear();
|
|
|
|
super.dispose();
|
|
super.dispose();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -408,13 +393,22 @@ class Graphics extends Drawable {
|
|
to these coordinates.
|
|
to these coordinates.
|
|
**/
|
|
**/
|
|
public function beginTileFill( ?dx : Float, ?dy : Float, ?scaleX : Float, ?scaleY : Float, ?tile : h2d.Tile ) {
|
|
public function beginTileFill( ?dx : Float, ?dy : Float, ?scaleX : Float, ?scaleY : Float, ?tile : h2d.Tile ) {
|
|
- if( tile == null )
|
|
|
|
- throw "Tile not specified";
|
|
|
|
- this.tile = tile;
|
|
|
|
beginFill(0xFFFFFF);
|
|
beginFill(0xFFFFFF);
|
|
- content.setTile(tile);
|
|
|
|
if( dx == null ) dx = 0;
|
|
if( dx == null ) dx = 0;
|
|
if( dy == null ) dy = 0;
|
|
if( dy == null ) dy = 0;
|
|
|
|
+ if( tile != null ) {
|
|
|
|
+ if( this.tile != null && tile.getTexture() != this.tile.getTexture() ) {
|
|
|
|
+ var tex = this.tile.getTexture();
|
|
|
|
+ if( tex.width != 1 || tex.height != 1 )
|
|
|
|
+ throw "All tiles must be of the same texture";
|
|
|
|
+ this.tile = tile;
|
|
|
|
+ }
|
|
|
|
+ if( this.tile == null )
|
|
|
|
+ this.tile = tile;
|
|
|
|
+ } else
|
|
|
|
+ tile = this.tile;
|
|
|
|
+ if( tile == null )
|
|
|
|
+ throw "Tile not specified";
|
|
if( scaleX == null ) scaleX = 1;
|
|
if( scaleX == null ) scaleX = 1;
|
|
if( scaleY == null ) scaleY = 1;
|
|
if( scaleY == null ) scaleY = 1;
|
|
dx -= tile.x;
|
|
dx -= tile.x;
|
|
@@ -647,8 +641,8 @@ class Graphics extends Drawable {
|
|
}
|
|
}
|
|
|
|
|
|
override function draw(ctx:RenderContext) {
|
|
override function draw(ctx:RenderContext) {
|
|
- if( !ctx.beginDrawBatchState(this) ) return;
|
|
|
|
- content.doRender(ctx);
|
|
|
|
|
|
+ if( !ctx.beginDrawObject(this, tile.getTexture()) ) return;
|
|
|
|
+ content.render(ctx.engine);
|
|
}
|
|
}
|
|
|
|
|
|
override function sync(ctx:RenderContext) {
|
|
override function sync(ctx:RenderContext) {
|