Pārlūkot izejas kodu

remove ScreenFx shader list (use pass shaders) + fixed apply with customPass which uses both shader lists

Nicolas Cannasse 3 gadi atpakaļ
vecāks
revīzija
17244ceb87
4 mainītis faili ar 21 papildinājumiem un 50 dzēšanām
  1. 8 8
      h3d/pass/Copy.hx
  2. 6 19
      h3d/pass/CubeCopy.hx
  3. 6 22
      h3d/pass/ScreenFx.hx
  4. 1 1
      h3d/scene/pbr/Renderer.hx

+ 8 - 8
h3d/pass/Copy.hx

@@ -35,13 +35,13 @@ class ArrayCopy extends ScreenFx<ArrayCopyShader> {
 		shader.texture = from;
 		shader.layer = fromLayer;
 		if( customPass != null ) {
-			var old = pass;
-			pass = customPass;
-			if( blend != null ) pass.setBlendMode(blend);
-			var h = shaders;
+			if( blend != null ) customPass.setBlendMode(blend);
+			var h = @:privateAccess customPass.shaders;
 			while( h.next != null )
 				h = h.next;
 			h.next = @:privateAccess pass.shaders;
+			var old = pass;
+			pass = customPass;
 			render();
 			pass = old;
 			h.next = null;
@@ -89,13 +89,13 @@ class Copy extends ScreenFx<CopyShader> {
 			engine.pushTarget(to, layer != null ? layer : 0);
 		shader.texture = from;
 		if( customPass != null ) {
-			var old = pass;
-			pass = customPass;
-			if( blend != null ) pass.setBlendMode(blend);
-			var h = shaders;
+			if( blend != null ) customPass.setBlendMode(blend);
+			var h = @:privateAccess customPass.shaders;
 			while( h.next != null )
 				h = h.next;
 			h.next = @:privateAccess pass.shaders;
+			var old = pass;
+			pass = customPass;
 			render();
 			pass = old;
 			h.next = null;

+ 6 - 19
h3d/pass/CubeCopy.hx

@@ -25,42 +25,29 @@ class CubeCopy extends ScreenFx<CubeCopyShader> {
 		super(new CubeCopyShader());
 	}
 
-	public function apply( from, to, ?blend : h3d.mat.BlendMode, ?customPass : h3d.mat.Pass ) {
+	public function apply( from, to, ?blend : h3d.mat.BlendMode ) {
 		shader.texture = from;
 		for(i in 0 ... 6){
 			if( to != null )
 				engine.pushTarget(to, i);
 			shader.mat = cubeDir[i];
-			if( customPass != null ) {
-				var old = pass;
-				pass = customPass;
-				if( blend != null ) pass.setBlendMode(blend);
-				var h = shaders;
-				while( h.next != null )
-					h = h.next;
-				h.next = @:privateAccess pass.shaders;
-				render();
-				pass = old;
-				h.next = null;
-			} else {
-				pass.setBlendMode(blend == null ? None : blend);
-				render();
-			}
+			pass.setBlendMode(blend == null ? None : blend);
+			render();
 			if( to != null )
 				engine.popTarget();
 		}
 		shader.texture = null;
 	}
 
-	public static function run( from : h3d.mat.Texture, to : h3d.mat.Texture, ?blend : h3d.mat.BlendMode, ?pass : h3d.mat.Pass ) {
+	public static function run( from : h3d.mat.Texture, to : h3d.mat.Texture, ?blend : h3d.mat.BlendMode ) {
 		var engine = h3d.Engine.getCurrent();
-		if( to != null && from != null && (blend == null || blend == None) && pass == null && engine.driver.copyTexture(from, to) )
+		if( to != null && from != null && (blend == null || blend == None) && engine.driver.copyTexture(from, to) )
 			return;
 		var inst : CubeCopy = @:privateAccess engine.resCache.get(CubeCopy);
 		if( inst == null ) {
 			inst = new CubeCopy();
 			@:privateAccess engine.resCache.set(CubeCopy, inst);
 		}
-		return inst.apply(from, to, blend, pass);
+		return inst.apply(from, to, blend);
 	}
 }

+ 6 - 22
h3d/pass/ScreenFx.hx

@@ -8,12 +8,10 @@ class ScreenFx<T:h3d.shader.ScreenShader> {
 	var manager : ShaderManager;
 	var _engine : h3d.Engine;
 	var engine(get,never) : h3d.Engine;
-	var shaders : hxsl.ShaderList;
 	var buffers : h3d.shader.Buffers;
 
 	public function new(shader, ?output) {
 		this.shader = shader;
-		shaders = new hxsl.ShaderList(shader);
 		manager = new ShaderManager(output);
 		pass = new h3d.mat.Pass("screenfx", new hxsl.ShaderList(shader));
 		pass.culling = None;
@@ -34,37 +32,23 @@ class ScreenFx<T:h3d.shader.ScreenShader> {
 			manager.globals.fastSet(g.gid, g.value);
 	}
 
-	public function addShader<T:hxsl.Shader>(s:T) {
-		shaders = hxsl.ShaderList.addSort(s, shaders);
+	public inline function addShader<T:hxsl.Shader>(s:T) {
 		return pass.addShader(s);
 	}
 
-	public function removeShader(s:hxsl.Shader) {
-		var prev : hxsl.ShaderList = null;
-		var cur = shaders;
-		while( cur != null ) {
-			if( cur.s == s ) {
-				if( prev == null ) shaders = cur.next else prev.next = cur.next;
-				return true;
-			}
-			prev = cur;
-			cur = cur.next;
-		}
-		return false;
+	public inline function removeShader(s:hxsl.Shader) {
+		return pass.removeShader(s);
 	}
 
-	public function getShader<T:hxsl.Shader>(cl:Class<T>) : T {
-		for( s in shaders ) {
-			var si = hxd.impl.Api.downcast(s, cl);
-			if( si != null ) return si;
-		}
-		return null;
+	public inline function getShader<T:hxsl.Shader>(cl:Class<T>) : T {
+		return pass.getShader(cl);
 	}
 
 	public function render() {
 		if( primitive == null )
 			primitive = h3d.prim.Plane2D.get();
 		shader.flipY = engine.driver.hasFeature(BottomLeftCoords) && engine.getCurrentTarget() != null ? -1 : 1;
+		var shaders = @:privateAccess pass.shaders;
 		var rts = manager.compileShaders(shaders);
 		engine.selectMaterial(pass);
 		engine.selectShader(rts);

+ 1 - 1
h3d/scene/pbr/Renderer.hx

@@ -366,7 +366,7 @@ class Renderer extends h3d.scene.Renderer {
 		var props : RenderProps = props;
 
 		// reset tonemap shaders
-		var s = @:privateAccess tonemap.shaders;
+		var s = @:privateAccess tonemap.pass.shaders;
 		while( s != null ) {
 			if( s.s != tonemap.shader ) tonemap.removeShader(s.s);
 			s = s.next;