|
@@ -1,17 +1,27 @@
|
|
package h3d.scene;
|
|
package h3d.scene;
|
|
import h3d.pass.Object in ObjectPass;
|
|
import h3d.pass.Object in ObjectPass;
|
|
|
|
|
|
|
|
+private class SharedGlobal {
|
|
|
|
+ public var gid : Int;
|
|
|
|
+ public var value : Dynamic;
|
|
|
|
+ public function new(gid, value) {
|
|
|
|
+ this.gid = gid;
|
|
|
|
+ this.value = value;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
class RenderContext extends h3d.impl.RenderContext {
|
|
class RenderContext extends h3d.impl.RenderContext {
|
|
|
|
|
|
public var camera : h3d.Camera;
|
|
public var camera : h3d.Camera;
|
|
public var drawPass : ObjectPass;
|
|
public var drawPass : ObjectPass;
|
|
|
|
|
|
- public var sharedGlobals : Map<Int,Dynamic>;
|
|
|
|
|
|
+ var sharedGlobals : Array<SharedGlobal>;
|
|
public var lightSystem : h3d.pass.LightSystem;
|
|
public var lightSystem : h3d.pass.LightSystem;
|
|
public var uploadParams : Void -> Void;
|
|
public var uploadParams : Void -> Void;
|
|
public var extraShaders : hxsl.ShaderList;
|
|
public var extraShaders : hxsl.ShaderList;
|
|
|
|
|
|
var pool : ObjectPass;
|
|
var pool : ObjectPass;
|
|
|
|
+ var firstAlloc : ObjectPass;
|
|
var cachedShaderList : Array<hxsl.ShaderList>;
|
|
var cachedShaderList : Array<hxsl.ShaderList>;
|
|
var cachedPos : Int;
|
|
var cachedPos : Int;
|
|
var passes : ObjectPass;
|
|
var passes : ObjectPass;
|
|
@@ -32,7 +42,7 @@ class RenderContext extends h3d.impl.RenderContext {
|
|
}
|
|
}
|
|
|
|
|
|
public function start() {
|
|
public function start() {
|
|
- sharedGlobals = new Map();
|
|
|
|
|
|
+ sharedGlobals = [];
|
|
lights = null;
|
|
lights = null;
|
|
drawPass = null;
|
|
drawPass = null;
|
|
passes = null;
|
|
passes = null;
|
|
@@ -49,19 +59,34 @@ class RenderContext extends h3d.impl.RenderContext {
|
|
}
|
|
}
|
|
|
|
|
|
public function getGlobal( name : String ) : Dynamic {
|
|
public function getGlobal( name : String ) : Dynamic {
|
|
- return sharedGlobals.get(hxsl.Globals.allocID(name));
|
|
|
|
|
|
+ var id = hxsl.Globals.allocID(name);
|
|
|
|
+ for( g in sharedGlobals )
|
|
|
|
+ if( g.gid == id )
|
|
|
|
+ return g.value;
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public inline function setGlobal( name : String, value : Dynamic ) {
|
|
|
|
+ setGlobalID(hxsl.Globals.allocID(name), value);
|
|
}
|
|
}
|
|
|
|
|
|
- public function setGlobal( name : String, value : Dynamic ) {
|
|
|
|
- sharedGlobals.set(hxsl.Globals.allocID(name), value);
|
|
|
|
|
|
+ public function setGlobalID( gid : Int, value : Dynamic ) {
|
|
|
|
+ for( g in sharedGlobals )
|
|
|
|
+ if( g.gid == gid ) {
|
|
|
|
+ g.value = value;
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ sharedGlobals.push(new SharedGlobal(gid, value));
|
|
}
|
|
}
|
|
|
|
|
|
public function emitPass( pass : h3d.mat.Pass, obj : h3d.scene.Object ) {
|
|
public function emitPass( pass : h3d.mat.Pass, obj : h3d.scene.Object ) {
|
|
var o = pool;
|
|
var o = pool;
|
|
- if( o == null )
|
|
|
|
|
|
+ if( o == null ) {
|
|
o = new ObjectPass();
|
|
o = new ObjectPass();
|
|
- else
|
|
|
|
- pool = o.next;
|
|
|
|
|
|
+ o.nextAlloc = firstAlloc;
|
|
|
|
+ firstAlloc = o;
|
|
|
|
+ } else
|
|
|
|
+ pool = o.nextAlloc;
|
|
o.pass = pass;
|
|
o.pass = pass;
|
|
o.obj = obj;
|
|
o.obj = obj;
|
|
o.next = passes;
|
|
o.next = passes;
|
|
@@ -89,20 +114,19 @@ class RenderContext extends h3d.impl.RenderContext {
|
|
drawPass = null;
|
|
drawPass = null;
|
|
uploadParams = null;
|
|
uploadParams = null;
|
|
// move passes to pool, and erase data
|
|
// move passes to pool, and erase data
|
|
- var p = passes, prev = null;
|
|
|
|
|
|
+ var p = firstAlloc, prev = null;
|
|
while( p != null ) {
|
|
while( p != null ) {
|
|
p.obj = null;
|
|
p.obj = null;
|
|
p.pass = null;
|
|
p.pass = null;
|
|
p.shader = null;
|
|
p.shader = null;
|
|
p.shaders = null;
|
|
p.shaders = null;
|
|
|
|
+ p.next = null;
|
|
p.index = 0;
|
|
p.index = 0;
|
|
prev = p;
|
|
prev = p;
|
|
- p = p.next;
|
|
|
|
- }
|
|
|
|
- if( prev != null ) {
|
|
|
|
- prev.next = pool;
|
|
|
|
- pool = passes;
|
|
|
|
|
|
+ p = p.nextAlloc;
|
|
}
|
|
}
|
|
|
|
+ pool = firstAlloc;
|
|
|
|
+
|
|
for( c in cachedShaderList ) {
|
|
for( c in cachedShaderList ) {
|
|
c.s = null;
|
|
c.s = null;
|
|
c.next = null;
|
|
c.next = null;
|