|
@@ -1,6 +1,6 @@
|
|
|
package h3d.scene;
|
|
|
|
|
|
-class PassGroup {
|
|
|
+class PassObjects {
|
|
|
public var name : String;
|
|
|
public var passes : h3d.pass.Object;
|
|
|
public var rendered : Bool;
|
|
@@ -14,86 +14,49 @@ private typedef SMap<T> = #if flash haxe.ds.UnsafeStringMap<T> #else Map<String,
|
|
|
|
|
|
class Renderer {
|
|
|
|
|
|
- var def : h3d.pass.Base;
|
|
|
- var depth : h3d.pass.Base;
|
|
|
- var normal : h3d.pass.Base;
|
|
|
- var shadow : h3d.pass.Base;
|
|
|
- var passes : SMap<h3d.pass.Base>;
|
|
|
- var passGroups : SMap<PassGroup>;
|
|
|
- var allPasses : Array<{ name : String, p : h3d.pass.Base }>;
|
|
|
+ var defaultPass : h3d.pass.Base;
|
|
|
+ var passObjects : SMap<PassObjects>;
|
|
|
+ var allPasses : Array<h3d.pass.Base>;
|
|
|
var ctx : RenderContext;
|
|
|
var tcache : h3d.impl.TextureCache;
|
|
|
var hasSetTarget = false;
|
|
|
|
|
|
public function new() {
|
|
|
- passes = new SMap();
|
|
|
allPasses = [];
|
|
|
tcache = new h3d.impl.TextureCache();
|
|
|
- passGroups = new SMap();
|
|
|
+ passObjects = new SMap();
|
|
|
}
|
|
|
|
|
|
public function dispose() {
|
|
|
for( p in allPasses )
|
|
|
- p.p.dispose();
|
|
|
- passes = new SMap();
|
|
|
- allPasses = [];
|
|
|
- passGroups = new SMap();
|
|
|
+ p.dispose();
|
|
|
+ passObjects = new SMap();
|
|
|
tcache.dispose();
|
|
|
- def = depth = normal = shadow = null;
|
|
|
- }
|
|
|
-
|
|
|
- public function compileShader( pass : h3d.mat.Pass ) {
|
|
|
- var p = getPass(pass.name);
|
|
|
- p.setContext(ctx);
|
|
|
- return p.compileShader(pass);
|
|
|
}
|
|
|
|
|
|
- function hasFeature(f) {
|
|
|
- return h3d.Engine.getCurrent().driver.hasFeature(f);
|
|
|
- }
|
|
|
-
|
|
|
- function createDefaultPass( name : String ) : h3d.pass.Base {
|
|
|
- switch( name ) {
|
|
|
- case "depth":
|
|
|
- if( depth != null ) return depth;
|
|
|
- return depth = new h3d.pass.Depth();
|
|
|
- case "normal":
|
|
|
- if( normal != null ) return normal;
|
|
|
- return normal = new h3d.pass.Normal();
|
|
|
- case "shadow":
|
|
|
- if( shadow != null ) return shadow;
|
|
|
- return shadow = new h3d.pass.ShadowMap(1024);
|
|
|
- default:
|
|
|
- if( def != null ) return def;
|
|
|
- return def = new h3d.pass.Default();
|
|
|
- }
|
|
|
+ public function getPass<T:h3d.pass.Base>( c : Class<T> ) : T {
|
|
|
+ for( p in allPasses )
|
|
|
+ if( Std.is(p, c) )
|
|
|
+ return cast p;
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
- public function getPass( name : String, create = true ) {
|
|
|
- var p = passes.get(name);
|
|
|
- if( p == null && create ) {
|
|
|
- p = createDefaultPass(name);
|
|
|
- setPass(name, p);
|
|
|
- }
|
|
|
- return p;
|
|
|
+ public function getPassByName( name : String ) {
|
|
|
+ for( p in allPasses )
|
|
|
+ if( p.name == name )
|
|
|
+ return p;
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
- function getPassPriority( p : { name : String, p : h3d.pass.Base } ) {
|
|
|
- var pr = p.p.priority * 10;
|
|
|
- switch( p.name ) {
|
|
|
- case "alpha": pr -= 1;
|
|
|
- case "additive": pr -= 2;
|
|
|
- }
|
|
|
- return pr;
|
|
|
+ public function debugCompileShader( pass : h3d.mat.Pass ) {
|
|
|
+ var p = getPassByName(pass.name);
|
|
|
+ if( p == null ) p = defaultPass;
|
|
|
+ p.setContext(ctx);
|
|
|
+ return p.compileShader(pass);
|
|
|
}
|
|
|
|
|
|
- public function setPass( name : String, p : h3d.pass.Base ) {
|
|
|
- for( p in allPasses )
|
|
|
- if( p.name == name )
|
|
|
- allPasses.remove(p);
|
|
|
- passes.set(name, p);
|
|
|
- allPasses.push({ name : name, p : p });
|
|
|
- allPasses.sort(function(p1, p2) return getPassPriority(p2) - getPassPriority(p1));
|
|
|
+ function hasFeature(f) {
|
|
|
+ return h3d.Engine.getCurrent().driver.hasFeature(f);
|
|
|
}
|
|
|
|
|
|
@:access(h3d.scene.Object)
|
|
@@ -113,22 +76,15 @@ class Renderer {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- inline function front2back(passes) {
|
|
|
- return depthSort(passes, true);
|
|
|
- }
|
|
|
-
|
|
|
- inline function back2front(passes) {
|
|
|
- return depthSort(passes, false);
|
|
|
+ inline function clear( ?color, ?depth, ?stencil ) {
|
|
|
+ ctx.engine.clear(color, depth, stencil);
|
|
|
}
|
|
|
|
|
|
+ // for legacy purposes
|
|
|
inline function allocTarget( name : String, size = 0, depth = true ) {
|
|
|
return tcache.allocTarget(name, ctx, ctx.engine.width >> size, ctx.engine.height >> size, depth);
|
|
|
}
|
|
|
|
|
|
- inline function clear( ?color, ?depth, ?stencil ) {
|
|
|
- ctx.engine.clear(color, depth, stencil);
|
|
|
- }
|
|
|
-
|
|
|
function copy( from, to, ?blend ) {
|
|
|
h3d.pass.Copy.run(from, to, blend);
|
|
|
}
|
|
@@ -146,54 +102,43 @@ class Renderer {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ function has( name : String ) {
|
|
|
+ return passObjects.get(name) != null;
|
|
|
+ }
|
|
|
+
|
|
|
function get( name : String ) {
|
|
|
- var p = passGroups.get(name);
|
|
|
+ var p = passObjects.get(name);
|
|
|
if( p == null ) return null;
|
|
|
p.rendered = true;
|
|
|
return p.passes;
|
|
|
}
|
|
|
|
|
|
- function draw( name : String ) {
|
|
|
- if( def == null ) def = new h3d.pass.Default();
|
|
|
- def.draw(get(name));
|
|
|
+ function getSort( name : String, front2Back = false ) {
|
|
|
+ var p = passObjects.get(name);
|
|
|
+ if( p == null ) return null;
|
|
|
+ p.passes = depthSort(p.passes, front2Back);
|
|
|
+ p.rendered = true;
|
|
|
+ return p.passes;
|
|
|
}
|
|
|
|
|
|
- function renderPass( name : String, p : h3d.pass.Base, passes ) {
|
|
|
- return p.draw(passes);
|
|
|
+ function draw( name : String ) {
|
|
|
+ defaultPass.draw(get(name));
|
|
|
}
|
|
|
|
|
|
function render() {
|
|
|
- for( p in allPasses ) {
|
|
|
- var pdata = passGroups.get(p.name);
|
|
|
- if( pdata != null && pdata.rendered )
|
|
|
- continue;
|
|
|
- if( pdata != null || p.p.forceProcessing ) {
|
|
|
- p.p.setContext(ctx);
|
|
|
- var passes = pdata == null ? null : pdata.passes;
|
|
|
- if( p.name == "alpha" )
|
|
|
- passes = depthSort(passes);
|
|
|
- if( p.name == "default" )
|
|
|
- passes = depthSort(passes, true);
|
|
|
- passes = renderPass(p.name, p.p, passes);
|
|
|
- if( pdata != null ) {
|
|
|
- pdata.passes = passes;
|
|
|
- pdata.rendered = true;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ throw "Not implemented";
|
|
|
}
|
|
|
|
|
|
- public function process( passes : Array<PassGroup> ) {
|
|
|
+ public function process( passes : Array<PassObjects> ) {
|
|
|
hasSetTarget = false;
|
|
|
- // alloc passes
|
|
|
- for( p in passes ) {
|
|
|
- getPass(p.name).setContext(ctx);
|
|
|
- passGroups.set(p.name, p);
|
|
|
- }
|
|
|
+ for( p in allPasses )
|
|
|
+ p.setContext(ctx);
|
|
|
+ for( p in passes )
|
|
|
+ passObjects.set(p.name, p);
|
|
|
render();
|
|
|
resetTarget();
|
|
|
for( p in passes )
|
|
|
- passGroups.set(p.name, null);
|
|
|
+ passObjects.set(p.name, null);
|
|
|
}
|
|
|
|
|
|
}
|