
class shaderDebugger{

	setup() {

		var shaders 	= document.shaders;

		var select 		= document.querySelector(".selectDebugShader");

		for (var i = 0; i < shaders.length; i++) {

			var currentShader 	= shaders[i];

			var option 			= document.createElement("option");

			option.innerText	= currentShader.path;

			option.id			= i;

			select.appendChild( option );

		}

		document.querySelector( "#showBuffers" ).addEventListener( "click", async function() {

			var select 			= document.querySelector(".selectDebugShader");

			var selectedIndex 	= select.selectedIndex;

			var selectedShader	= document.shaders[ selectedIndex ]

			const keysArray 	= Array.from( selectedShader.buffers );

			console.log("\n\n\n\n -------------------- Debugging Shader --------------- \n\n\n\n");

			console.log( "Shader Path:	", selectedShader.path );

			console.log( selectedShader );

			for (var i = 0; i < keysArray.length; i++) {

				const bindingInfo = selectedShader.bindings.find( b => b.varName === keysArray[i][0] );

			
				if( bindingInfo ) {

					if( bindingInfo.type == "storage" ) {

						await selectedShader.debugBuffer( keysArray[i][0] );

					}

				} else {

					console.log("this is a Uniform", keysArray, selectedShader.bindings);

				}

			}

		});	
	}

}


export default shaderDebugger;