insertPatches = function(patches) {
		// pass patches into texture, each patch in either r, g, b or a
		var patchArrayIndex = 0;
		var patchesIndex1 = 0;
		var patchesIndex2 = 0;
		for (var i = 0;i < patchCells;i++) {
			for (var j = 0;j < patchHeight;j++) {
				for (var k = 0;k < patchWidth;k++) {
					patchesIndex1 = i*4;
					patchesIndex2 = (j*patchWidth) + k;
					patchArrayIndex = ((patchSize*i) + patchesIndex2)*4;

					//set r with first patch
					if (patchesIndex1 < numPatches) {
						patchArray[patchArrayIndex] = patches[patchesIndex1][patchesIndex2];
					} else {
						patchArray[patchArrayIndex] = 0;
					}
					//set g with 2nd patch
					if (patchesIndex1+1 < numPatches) {
						patchArray[patchArrayIndex + 1] = patches[patchesIndex1+1][patchesIndex2];
					} else {
						patchArray[patchArrayIndex + 1] = 0;
					}
					//set b with 3rd patch
					if (patchesIndex1+2 < numPatches) {
						patchArray[patchArrayIndex + 2] = patches[patchesIndex1+2][patchesIndex2];
					} else {
						patchArray[patchArrayIndex + 2] = 0;
					}
					//set a with 4th patch
					if (patchesIndex1+3 < numPatches) {
						patchArray[patchArrayIndex + 3] = patches[patchesIndex1+3][patchesIndex2];
					} else {
						patchArray[patchArrayIndex + 3] = 0;
					}
				}
			}
		}

		// pass texture into an uniform
		gl.activeTexture(gl.TEXTURE1);
		gl.bindTexture(gl.TEXTURE_2D, patchTex);
		gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, textureWidth, textureHeight, 0, gl.RGBA, gl.FLOAT, patchArray);
		gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
		gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
		gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
		gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
	}
set up programs and load attributes etc *