|
@@ -5,20 +5,20 @@ class Engine {
|
|
|
|
|
|
var s3d : flash.display.Stage3D;
|
|
var s3d : flash.display.Stage3D;
|
|
var ctx : flash.display3D.Context3D;
|
|
var ctx : flash.display3D.Context3D;
|
|
-
|
|
|
|
|
|
+
|
|
public var camera : h3d.Camera;
|
|
public var camera : h3d.Camera;
|
|
public var mem(default,null) : h3d.impl.MemoryManager;
|
|
public var mem(default,null) : h3d.impl.MemoryManager;
|
|
-
|
|
|
|
|
|
+
|
|
public var hardware(default, null) : Bool;
|
|
public var hardware(default, null) : Bool;
|
|
public var width(default, null) : Int;
|
|
public var width(default, null) : Int;
|
|
public var height(default, null) : Int;
|
|
public var height(default, null) : Int;
|
|
public var debug(default, set) : Bool;
|
|
public var debug(default, set) : Bool;
|
|
-
|
|
|
|
|
|
+
|
|
public var drawTriangles(default, null) : Int;
|
|
public var drawTriangles(default, null) : Int;
|
|
public var drawCalls(default, null) : Int;
|
|
public var drawCalls(default, null) : Int;
|
|
-
|
|
|
|
|
|
+
|
|
public var backgroundColor : Int;
|
|
public var backgroundColor : Int;
|
|
-
|
|
|
|
|
|
+
|
|
var curMatBits : Int;
|
|
var curMatBits : Int;
|
|
var curShader : Shader.ShaderData;
|
|
var curShader : Shader.ShaderData;
|
|
var curBuffer : h3d.impl.MemoryManager.BigBuffer;
|
|
var curBuffer : h3d.impl.MemoryManager.BigBuffer;
|
|
@@ -27,29 +27,25 @@ class Engine {
|
|
var antiAlias : Int;
|
|
var antiAlias : Int;
|
|
var debugPoint : h3d.CustomObject<h3d.impl.Shaders.PointShader>;
|
|
var debugPoint : h3d.CustomObject<h3d.impl.Shaders.PointShader>;
|
|
var debugLine : h3d.CustomObject<h3d.impl.Shaders.LineShader>;
|
|
var debugLine : h3d.CustomObject<h3d.impl.Shaders.LineShader>;
|
|
-
|
|
|
|
|
|
+
|
|
public function new( width = 0, height = 0, hardware = true, aa = 0, stageIndex = 0 ) {
|
|
public function new( width = 0, height = 0, hardware = true, aa = 0, stageIndex = 0 ) {
|
|
- var stage = flash.Lib.current.stage;
|
|
|
|
- var Cap = flash.system.Capabilities;
|
|
|
|
- if( Cap.os.indexOf("iPhone") != -1 ) {
|
|
|
|
- if( width == 0 ) width = Std.int(Cap.screenResolutionX > Cap.screenResolutionY ? Cap.screenResolutionX : Cap.screenResolutionY);
|
|
|
|
- if( height == 0 ) height = Std.int(Cap.screenResolutionX > Cap.screenResolutionY ? Cap.screenResolutionY : Cap.screenResolutionX);
|
|
|
|
- } else {
|
|
|
|
- if( width == 0 ) width = stage.stageWidth;
|
|
|
|
- if( height == 0 ) height = stage.stageHeight;
|
|
|
|
- }
|
|
|
|
|
|
+ if( width == 0 )
|
|
|
|
+ width = Caps.width;
|
|
|
|
+ if( height == 0 )
|
|
|
|
+ height = Caps.height;
|
|
this.width = width;
|
|
this.width = width;
|
|
this.height = height;
|
|
this.height = height;
|
|
this.hardware = hardware;
|
|
this.hardware = hardware;
|
|
this.antiAlias = aa;
|
|
this.antiAlias = aa;
|
|
|
|
+ var stage = flash.Lib.current.stage;
|
|
s3d = stage.stage3Ds[stageIndex];
|
|
s3d = stage.stage3Ds[stageIndex];
|
|
camera = new Camera();
|
|
camera = new Camera();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public function show( b ) {
|
|
public function show( b ) {
|
|
s3d.visible = b;
|
|
s3d.visible = b;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public function init() {
|
|
public function init() {
|
|
s3d.addEventListener(flash.events.Event.CONTEXT3D_CREATE, onCreate);
|
|
s3d.addEventListener(flash.events.Event.CONTEXT3D_CREATE, onCreate);
|
|
s3d.requestContext3D( hardware ? "auto" : "software" );
|
|
s3d.requestContext3D( hardware ? "auto" : "software" );
|
|
@@ -58,15 +54,15 @@ class Engine {
|
|
public function saveTo( bmp : flash.display.BitmapData ) {
|
|
public function saveTo( bmp : flash.display.BitmapData ) {
|
|
ctx.drawToBitmapData(bmp);
|
|
ctx.drawToBitmapData(bmp);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public function driverName() {
|
|
public function driverName() {
|
|
return ctx == null ? "None" : ctx.driverInfo.split(" ")[0];
|
|
return ctx == null ? "None" : ctx.driverInfo.split(" ")[0];
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public function isReady() {
|
|
public function isReady() {
|
|
return ctx != null;
|
|
return ctx != null;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public function selectShader( shader : Shader ) {
|
|
public function selectShader( shader : Shader ) {
|
|
var s = shader.getData();
|
|
var s = shader.getData();
|
|
if( s.program == null ) {
|
|
if( s.program == null ) {
|
|
@@ -115,7 +111,7 @@ class Engine {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public function selectMaterial( m : h3d.mat.Material ) {
|
|
public function selectMaterial( m : h3d.mat.Material ) {
|
|
var diff = curMatBits ^ m.bits;
|
|
var diff = curMatBits ^ m.bits;
|
|
if( diff != 0 ) {
|
|
if( diff != 0 ) {
|
|
@@ -131,7 +127,7 @@ class Engine {
|
|
}
|
|
}
|
|
selectShader(m.shader);
|
|
selectShader(m.shader);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
function selectBuffer( buf : h3d.impl.MemoryManager.BigBuffer ) {
|
|
function selectBuffer( buf : h3d.impl.MemoryManager.BigBuffer ) {
|
|
if( buf == curBuffer )
|
|
if( buf == curBuffer )
|
|
return;
|
|
return;
|
|
@@ -152,7 +148,7 @@ class Engine {
|
|
ctx.setVertexBufferAt(i, null);
|
|
ctx.setVertexBufferAt(i, null);
|
|
curAttributes = pos;
|
|
curAttributes = pos;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public function renderIndexes( b : h3d.impl.Buffer, indexes : h3d.impl.Indexes, vertPerTri : Int, startTri = 0, drawTri = -1 ) {
|
|
public function renderIndexes( b : h3d.impl.Buffer, indexes : h3d.impl.Indexes, vertPerTri : Int, startTri = 0, drawTri = -1 ) {
|
|
do {
|
|
do {
|
|
var ntri = Std.int(b.nvert / vertPerTri);
|
|
var ntri = Std.int(b.nvert / vertPerTri);
|
|
@@ -192,21 +188,21 @@ class Engine {
|
|
b = b.next;
|
|
b = b.next;
|
|
} while( b != null );
|
|
} while( b != null );
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public inline function renderQuads( b : h3d.impl.Buffer ) {
|
|
public inline function renderQuads( b : h3d.impl.Buffer ) {
|
|
return renderIndexes(b, mem.quadIndexes, 2);
|
|
return renderIndexes(b, mem.quadIndexes, 2);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public inline function renderBuffer( b : h3d.impl.Buffer ) {
|
|
public inline function renderBuffer( b : h3d.impl.Buffer ) {
|
|
return renderIndexes(b, mem.indexes, 3);
|
|
return renderIndexes(b, mem.indexes, 3);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
function set_debug(d) {
|
|
function set_debug(d) {
|
|
debug = d;
|
|
debug = d;
|
|
if( ctx != null ) ctx.enableErrorChecking = d && hardware;
|
|
if( ctx != null ) ctx.enableErrorChecking = d && hardware;
|
|
return d;
|
|
return d;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
function onCreate(_) {
|
|
function onCreate(_) {
|
|
ctx = s3d.context3D;
|
|
ctx = s3d.context3D;
|
|
mem = new h3d.impl.MemoryManager(ctx, 65400);
|
|
mem = new h3d.impl.MemoryManager(ctx, 65400);
|
|
@@ -215,10 +211,10 @@ class Engine {
|
|
resize(width, height, antiAlias);
|
|
resize(width, height, antiAlias);
|
|
onReady();
|
|
onReady();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public dynamic function onReady() {
|
|
public dynamic function onReady() {
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public function resize(width, height, aa = 0) {
|
|
public function resize(width, height, aa = 0) {
|
|
this.width = width;
|
|
this.width = width;
|
|
this.height = height;
|
|
this.height = height;
|
|
@@ -226,7 +222,7 @@ class Engine {
|
|
ctx.configureBackBuffer(width, height, aa);
|
|
ctx.configureBackBuffer(width, height, aa);
|
|
camera.ratio = width / height;
|
|
camera.ratio = width / height;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public function begin() {
|
|
public function begin() {
|
|
if( ctx == null ) return false;
|
|
if( ctx == null ) return false;
|
|
try {
|
|
try {
|
|
@@ -235,18 +231,18 @@ class Engine {
|
|
ctx = null;
|
|
ctx = null;
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
// init
|
|
// init
|
|
drawTriangles = 0;
|
|
drawTriangles = 0;
|
|
drawCalls = 0;
|
|
drawCalls = 0;
|
|
curMatBits = -1;
|
|
curMatBits = -1;
|
|
-
|
|
|
|
|
|
+
|
|
curShader = null;
|
|
curShader = null;
|
|
curBuffer = null;
|
|
curBuffer = null;
|
|
curTextures = [];
|
|
curTextures = [];
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
function reset() {
|
|
function reset() {
|
|
curMatBits = -1;
|
|
curMatBits = -1;
|
|
curShader = null;
|
|
curShader = null;
|
|
@@ -258,12 +254,12 @@ class Engine {
|
|
ctx.setTextureAt(i, null);
|
|
ctx.setTextureAt(i, null);
|
|
curTextures = [];
|
|
curTextures = [];
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public function end() {
|
|
public function end() {
|
|
ctx.present();
|
|
ctx.present();
|
|
reset();
|
|
reset();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public function setTarget( tex : h3d.mat.Texture ) {
|
|
public function setTarget( tex : h3d.mat.Texture ) {
|
|
if( tex == null )
|
|
if( tex == null )
|
|
ctx.setRenderToBackBuffer();
|
|
ctx.setRenderToBackBuffer();
|
|
@@ -273,27 +269,27 @@ class Engine {
|
|
ctx.clear(0, 0, 0, 0);
|
|
ctx.clear(0, 0, 0, 0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public function setRenderZone( x = 0, y = 0, width = -1, height = -1 ) {
|
|
public function setRenderZone( x = 0, y = 0, width = -1, height = -1 ) {
|
|
if( x == 0 && y == 0 && width < 0 && height < 0 )
|
|
if( x == 0 && y == 0 && width < 0 && height < 0 )
|
|
ctx.setScissorRectangle(null);
|
|
ctx.setScissorRectangle(null);
|
|
else
|
|
else
|
|
ctx.setScissorRectangle(new flash.geom.Rectangle(x, y, width < 0 ? this.width : width, height < 0 ? this.height : height));
|
|
ctx.setScissorRectangle(new flash.geom.Rectangle(x, y, width < 0 ? this.width : width, height < 0 ? this.height : height));
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public function render( obj : { function render( engine : Engine ) : Void; } ) {
|
|
public function render( obj : { function render( engine : Engine ) : Void; } ) {
|
|
if( !begin() ) return false;
|
|
if( !begin() ) return false;
|
|
obj.render(this);
|
|
obj.render(this);
|
|
end();
|
|
end();
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public function dispose() {
|
|
public function dispose() {
|
|
s3d.removeEventListener(flash.events.Event.CONTEXT3D_CREATE, onCreate);
|
|
s3d.removeEventListener(flash.events.Event.CONTEXT3D_CREATE, onCreate);
|
|
ctx.dispose();
|
|
ctx.dispose();
|
|
ctx = null;
|
|
ctx = null;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
// debug functions
|
|
// debug functions
|
|
public function point( x : Float, y : Float, z : Float, color = 0x80FF0000, size = 1.0, depth = false ) {
|
|
public function point( x : Float, y : Float, z : Float, color = 0x80FF0000, size = 1.0, depth = false ) {
|
|
if( debugPoint == null ) {
|
|
if( debugPoint == null ) {
|
|
@@ -309,7 +305,7 @@ class Engine {
|
|
debugPoint.shader.color = color;
|
|
debugPoint.shader.color = color;
|
|
debugPoint.render(this);
|
|
debugPoint.render(this);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public function line( x1 : Float, y1 : Float, z1 : Float, x2 : Float, y2 : Float, z2 : Float, color = 0x80FF0000, depth = false ) {
|
|
public function line( x1 : Float, y1 : Float, z1 : Float, x2 : Float, y2 : Float, z2 : Float, color = 0x80FF0000, depth = false ) {
|
|
if( debugLine == null ) {
|
|
if( debugLine == null ) {
|
|
debugLine = new CustomObject(new h3d.prim.Plan2D(), new h3d.impl.Shaders.LineShader());
|
|
debugLine = new CustomObject(new h3d.prim.Plan2D(), new h3d.impl.Shaders.LineShader());
|
|
@@ -324,11 +320,11 @@ class Engine {
|
|
debugLine.shader.color = color;
|
|
debugLine.shader.color = color;
|
|
debugLine.render(this);
|
|
debugLine.render(this);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public function lineP( a : { x : Float, y : Float, z : Float }, b : { x : Float, y : Float, z : Float }, color = 0x80FF0000, depth = false ) {
|
|
public function lineP( a : { x : Float, y : Float, z : Float }, b : { x : Float, y : Float, z : Float }, color = 0x80FF0000, depth = false ) {
|
|
line(a.x, a.y, a.z, b.x, b.y, b.z, color, depth);
|
|
line(a.x, a.y, a.z, b.x, b.y, b.z, color, depth);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
static var BLEND = [
|
|
static var BLEND = [
|
|
flash.display3D.Context3DBlendFactor.ONE,
|
|
flash.display3D.Context3DBlendFactor.ONE,
|
|
flash.display3D.Context3DBlendFactor.ZERO,
|
|
flash.display3D.Context3DBlendFactor.ZERO,
|
|
@@ -348,7 +344,7 @@ class Engine {
|
|
flash.display3D.Context3DTriangleFace.FRONT,
|
|
flash.display3D.Context3DTriangleFace.FRONT,
|
|
flash.display3D.Context3DTriangleFace.FRONT_AND_BACK,
|
|
flash.display3D.Context3DTriangleFace.FRONT_AND_BACK,
|
|
];
|
|
];
|
|
-
|
|
|
|
|
|
+
|
|
static var COMPARE = [
|
|
static var COMPARE = [
|
|
flash.display3D.Context3DCompareMode.ALWAYS,
|
|
flash.display3D.Context3DCompareMode.ALWAYS,
|
|
flash.display3D.Context3DCompareMode.NEVER,
|
|
flash.display3D.Context3DCompareMode.NEVER,
|
|
@@ -359,7 +355,7 @@ class Engine {
|
|
flash.display3D.Context3DCompareMode.LESS,
|
|
flash.display3D.Context3DCompareMode.LESS,
|
|
flash.display3D.Context3DCompareMode.LESS_EQUAL,
|
|
flash.display3D.Context3DCompareMode.LESS_EQUAL,
|
|
];
|
|
];
|
|
-
|
|
|
|
|
|
+
|
|
static var FORMAT = [
|
|
static var FORMAT = [
|
|
flash.display3D.Context3DVertexBufferFormat.BYTES_4,
|
|
flash.display3D.Context3DVertexBufferFormat.BYTES_4,
|
|
flash.display3D.Context3DVertexBufferFormat.FLOAT_1,
|
|
flash.display3D.Context3DVertexBufferFormat.FLOAT_1,
|