Philipp Tiefenbacher avatar Philipp Tiefenbacher committed 1263ccc

single webgl context mode

Comments (0)

Files changed (1)

hackathonAlpha.html

 
 <script type="text/javascript">
 
-var nrSimsRows = 3;
-var nrSimsCols = 3;
+var nrSimsRows;
+var nrSimsCols;
 
 var nrSims;
 var caCanvas;
 var ctlXRes, ctlYRes, ctlRandomDensity, ctlNrSims, ctlFramerate;
 var evoCellData;
 
-var caCanvas2;
+var useOneCanvas = true;
 
 function setup()
 {
 
 	//document.getElementById('floatingPalette').addEventListener('click', handleFloatingPaletteClick, false);
 
-	caCanvas = new EvoCell.CACanvas(jQuery("#c")[0]);
-	caCanvas.setupPaletteShader(getShaderFromElement(caCanvas.gl, "shader-fs-palette"));
-	
+	if (useOneCanvas)
+	{
+		caCanvas = new EvoCell.CACanvas(jQuery("#c")[0]);
+		caCanvas.setupPaletteShader(getShaderFromElement(caCanvas.gl, "shader-fs-palette"));
+	}
 	new Draggable('floatingPalette');
 	
 	jQuery('#evocellFile').change(handleFileSelect);
 	rowHeight = Math.floor((height / nrSimsRows) - 1);
 	
 	randomDensity = parseFloat(ctlRandomDensity.value);
-	caCanvas.setSize(width, height);
-
+	
+	if (useOneCanvas)
+	{
+		caCanvas.setSize(width, height);
+	}
 	
 	oldSims = caSims;
 	caSims = [];
 		}
 		else
 		{
-			//var canvas = EnsureCanvas("genCanvas_" + i);
-			//var caCanvas = new EvoCell.CACanvas(canvas);
-			caSims[i] = new EvoCell.CASimulation(caCanvas, evoCellData, colWidth, rowHeight);
+			if (useOneCanvas)
+			{	
+				caSims[i] = new EvoCell.CASimulation(caCanvas, evoCellData, colWidth, rowHeight);
+			}
+			else
+			{
+				var canvasX = EnsureCanvas("genCanvas_" + i);
+				var caCanvasX = new EvoCell.CACanvas(canvasX);
+				caCanvasX.setupPaletteShader(getShaderFromElement(caCanvasX.gl, "shader-fs-palette"));
+				caSims[i] = new EvoCell.CASimulation(caCanvasX, evoCellData, colWidth, rowHeight);
+			}
+			
 		}
 		caSims[i].setSize(colWidth, rowHeight);
-		//caSims[i].caCanvas.setSize(colWidth, colWidth);
+		if (!useOneCanvas)
+		{
+			caSims[i].caCanvas.setSize(colWidth, rowHeight);
+		}
+	}
+
+	if (!useOneCanvas)
+	{
+		for (var i = nrSims; i < oldSims.length; i++)
+		{
+			//oldSims[i].caCanvas.setSize(10, 10);
+		}
 	}
 
 	fillPalette(caSims[0].ruleData);
 		for (var c = 0; c < nrSimsCols; c++)
 		{
 			var idx = r*nrSimsCols+c;
-			//caSims[idx].caCanvas.draw(caSims[idx]);
-			caCanvas.draw(caSims[idx], null, [(width / nrSimsCols) * (c + 0.5) - colWidth/2, (height / nrSimsRows) * (r + 0.5) - rowHeight/2, colWidth, rowHeight]);
+			if (useOneCanvas)
+			{
+				caCanvas.draw(caSims[idx], null, [(width / nrSimsCols) * (c + 0.5) - colWidth/2, (height / nrSimsRows) * (r + 0.5) - rowHeight/2, colWidth, rowHeight]);		}
+			else
+			{
+				caSims[idx].caCanvas.draw(caSims[idx]);
+			}
+			
 		}
 	}
 
 	var canvas = document.getElementById(id);
 	if (!canvas)
 	{
-		container.innerHTML += "<canvas id='" + id + "' width='100' height='333'></canvas>";
+		container.innerHTML += "<div style='background-color:#cdc; border:2px solid gray;'><canvas id='" + id + "' width='100' height='333'></canvas></div>";
 		canvas = document.getElementById(id);
 	}
 	return canvas;
 
 	<div id="canvasContainer" style="pojkhsition:absolute;"></div>
 
-	<canvas id="c" width="10" height="33"></canvas>
-	<canvas id="c2" width="10" height="33" style="position:absolute;"></canvas>
+	<canvas id="c" width="10" height="33" border:1px solid gray;></canvas>
+	<canvas id="c2" width="10" height="33" style="position:absolute;" border:1px solid gray;></canvas>
 
 	<form name="controls" action="">
 	<input type="button" id="cmdRunPause" value="run/pause" onclick="pausePlease = !pausePlease; if (!pausePlease) anim();">
 	<input type="number" id="xres" name="xres" min="100" max="4000" value="1000" onchange="handleReset();" />
 	<input type="number" id="yres" name="yres" min="100" max="4000" value="3333" onchange="handleReset();" />
 	<input type="number" id="randomDensity" min="0" max="1" step="0.001" value="0.01" onchange="handleReset();">
-	<input type="number" id="nrSims" min="1" max="6" step="1" value="3" onchange="handleReset();">
+	<input type="number" id="nrSims" min="1" max="6" step="1" value="2" onchange="handleReset();">
 	<input type="button" value="Reset" onclick="handleReset(1);">
 	<input type="file" value="evocellFile" id="evocellFile" />
 	fps<input size="1" id="framerate">
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.