Commits

Philipp Tiefenbacher committed d755cb7 Draft

mixDish parameter cleanup, hope type checks are not slow in js

  • Participants
  • Parent commits 283e9e1

Comments (0)

Files changed (2)

src/game/CellSpace.js

 	var zoom = 2;
 	
 	var fpsMonotor = new utils.FPSMonitor("fpsMonitor");
+
 	// Setup core 	
 	var context = document.getElementById('c');
 	var reactor = new  EC.Reactor(context, gameW, gameH);
 				gl.uniform1f(gl.getUniformLocation(shader, "state"), 0.);
 			});
 
+			//reactor.mixDish(drawRectShader, enemyDish, 
+
 			// space
 			if (keyboard.isPressed(32)) {
 				enemyDish.randomize(enemyRule.nrStates, 0.0004);
 
 
 			// Dish INTERACTION ///////////////////////////////////
-			reactor.mixDish(intersectSpawnShader, shipExplosionDish, {tex1: shipDish, tex2: enemyDish}, {state: (shipExplosionRule.nrStates-1)/255.});
-			reactor.mixDish(intersectSpawnShader, enemyDish, {tex1: enemyDish, tex2: shipExplosionDish}, {state: 1./255.});
-			reactor.mixDish(intersectSpawnShader, shipDish, {tex1: shipDish, tex2: shipExplosionDish}, {state: 3./255.});	
+			reactor.mixDish(intersectSpawnShader, shipExplosionDish, {tex1: shipDish, tex2: enemyDish, state: (shipExplosionRule.nrStates-1)/255.});
+			reactor.mixDish(intersectSpawnShader, enemyDish, {tex1: enemyDish, tex2: shipExplosionDish, state: 1./255.});
+			reactor.mixDish(intersectSpawnShader, shipDish, {tex1: shipDish, tex2: shipExplosionDish, state: 3./255.});	
 
 
 			// COMPOSE ////////////////////////////////////////////
 			reactor.applyShaderOnDish(clearShader, renderDish);
-			reactor.mixDish(mixShader, renderDish, {texNew: enemy2Dish}, {texPalette: enemy2Colors.getTexture()});
-			reactor.mixDish(mixShader, renderDish, {texNew: enemyDish}, {texPalette: enemyColors.getTexture()});
-			reactor.mixDish(mixShader, renderDish, {texNew: shipDish}, {texPalette: shipColors.getTexture()});
-			reactor.mixDish(mixShader, renderDish, {texNew: shipExplosionDish}, {texPalette: shipExplosionColors.getTexture()});
+			reactor.mixDish(mixShader, renderDish, {texNew: enemy2Dish, texPalette: enemy2Colors.getTexture()});
+			reactor.mixDish(mixShader, renderDish, {texNew: enemyDish, texPalette: enemyColors.getTexture()});
+			reactor.mixDish(mixShader, renderDish, {texNew: shipDish, texPalette: shipColors.getTexture()});
+			reactor.mixDish(mixShader, renderDish, {texNew: shipExplosionDish, texPalette: shipExplosionColors.getTexture()});
 
 			
 			//RENDER

src/game/gl/Reactor.js

 		this.applyShader(paintShader, null, bindCallback)
 	}
 
-	Reactor.prototype.mixDish = function(mixShader, mainDish, paramDishes, parameters, callback)
+	Reactor.prototype.mixDish = function(mixShader, mainDish, parameters, callback)
 	{
 		var framebuffer = mainDish.getNextFramebuffer();
 		var bindCallback = function(gl, progCA)
 			gl.activeTexture(gl.TEXTURE0);    
 			gl.bindTexture(gl.TEXTURE_2D, mainDish.getCurrentTexture());
 
-		// TODO: if arrays (not dictionaries) then name texture1, texture2, texture3, ...
+		// TODO: if arrays (not dictionaries) then name tex1, tex2, tex3, ...
 			var textureCount = 1;
-			for (var paramName in paramDishes) {
-				gl.uniform1i(gl.getUniformLocation(progCA, paramName), textureCount);
-				gl.activeTexture(gl.TEXTURE0 + textureCount);    
-				gl.bindTexture(gl.TEXTURE_2D, paramDishes[paramName].getCurrentTexture());	
-				textureCount++;
-			}
 			for (var paramName in parameters) {
 				var param = parameters[paramName];
+				if (param instanceof Dish) {
+					param = param.getCurrentTexture();
+				}
+				// distinguish types				
 				if (param instanceof WebGLTexture) {
 					gl.uniform1i(gl.getUniformLocation(progCA, paramName), textureCount);
 					gl.activeTexture(gl.TEXTURE0 + textureCount);    
 					textureCount++;
 				}
 				else {
-					//if (param is int) 
+					//if (param is int) // TODO: int 
 					if (typeof param === "number") {
 						gl.uniform1f(gl.getUniformLocation(progCA, paramName), param);
 					}