Upgrade to webgl2
This commit is contained in:
		@@ -3,7 +3,6 @@
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// k: number of subdivisions per edge
 | 
			
		||||
// On my machine, k = [1, 256)
 | 
			
		||||
// I prefer 96
 | 
			
		||||
var k = 64
 | 
			
		||||
// f(x, y): function to graph
 | 
			
		||||
@@ -69,8 +68,9 @@ function main() {
 | 
			
		||||
  // Retrieve <canvas> element
 | 
			
		||||
  var canvas = document.getElementById('webgl');
 | 
			
		||||
 | 
			
		||||
  // Get the rendering context for WebGL
 | 
			
		||||
  var gl = getWebGLContext(canvas);
 | 
			
		||||
  // Get the rendering context for WebGL *2*
 | 
			
		||||
  var gl = canvas.getContext('webgl2');
 | 
			
		||||
 | 
			
		||||
  if (!gl) {
 | 
			
		||||
    console.log('Failed to get the rendering context for WebGL');
 | 
			
		||||
    return;
 | 
			
		||||
@@ -151,7 +151,7 @@ function main() {
 | 
			
		||||
  gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
 | 
			
		||||
 | 
			
		||||
  // Draw the cube
 | 
			
		||||
  gl.drawElements(gl.TRIANGLES, n, gl.UNSIGNED_SHORT, 0);
 | 
			
		||||
  gl.drawElements(gl.TRIANGLES, n, gl.UNSIGNED_INT, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -237,7 +237,7 @@ function initVertexBuffers(gl) {
 | 
			
		||||
  var vertices = new Float32Array(bf.vertices);
 | 
			
		||||
  var colors = new Float32Array(bf.vertex_colors);
 | 
			
		||||
  var normals = new Float32Array(bf.vertex_normals);
 | 
			
		||||
  var indices = new Uint16Array(bf.indices);
 | 
			
		||||
  var indices = new Uint32Array(bf.indices);
 | 
			
		||||
 | 
			
		||||
  // Write the vertex property to buffers (coordinates, colors and normals)
 | 
			
		||||
  if (!initArrayBuffer(gl, 'a_Position', vertices, 3)) return -1;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user