1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/test/webgl-conformance/extra/lots-of-polys-example.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,88 @@ 1.4 +<!-- 1.5 +Copyright (c) 2009 The Chromium Authors. All rights reserved. 1.6 +Use of this source code is governed by a BSD-style license that can be 1.7 +found in the LICENSE file. 1.8 + --> 1.9 +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 1.10 + "http://www.w3.org/TR/html4/loose.dtd"> 1.11 +<html> 1.12 +<head> 1.13 +<meta charset="utf-8"> 1.14 +<title>WebGL Lots of polygons example.</title> 1.15 +<link rel="stylesheet" href="../resources/js-test-style.css"/> 1.16 +<script src="../resources/js-test-pre.js"></script> 1.17 +<script src="../conformance/resources/webgl-test-utils.js"> </script> 1.18 +</head> 1.19 +<body> 1.20 +<canvas id="example" width="1024" height="1024" style="width: 40px; height: 40px;"> 1.21 +</canvas> 1.22 +<div id="description"></div> 1.23 +<div id="console"></div> 1.24 +<script> 1.25 +window.onload = init; 1.26 +debug("Tests a WebGL program that draws a bunch of large polygons"); 1.27 + 1.28 +function init() { 1.29 + if (confirm( 1.30 + "after clicking ok your machine may be come unresponsive or crash")) { 1.31 + main(); 1.32 + } else { 1.33 + debug("cancelled"); 1.34 + } 1.35 +} 1.36 + 1.37 +function main() { 1.38 + var wtu = WebGLTestUtils; 1.39 + var canvas = document.getElementById("example"); 1.40 + canvas.addEventListener("webglcontextlost", function(e) { e.preventDefault(); }, false); 1.41 + canvas.addEventListener("webglcontextrestored", function(e) { }, false); 1.42 + 1.43 + var gl = wtu.create3DContext(canvas); 1.44 + var program = wtu.setupTexturedQuad(gl); 1.45 + 1.46 + assertMsg(gl.getError() == gl.NO_ERROR, "Should be no errors from setup."); 1.47 + 1.48 + var tex = gl.createTexture(); 1.49 + gl.enable(gl.BLEND); 1.50 + gl.disable(gl.DEPTH_TEST); 1.51 + 1.52 + wtu.fillTexture(gl, tex, 4096, 4096, [0, 192, 128, 255], 0); 1.53 + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after creating texture"); 1.54 + 1.55 + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); 1.56 + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); 1.57 + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); 1.58 + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); 1.59 + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after setting texture params"); 1.60 + 1.61 + var loc = gl.getUniformLocation(program, "tex"); 1.62 + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after getting tex locations"); 1.63 + gl.uniform1i(loc, 0); 1.64 + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after setting tex uniform"); 1.65 + 1.66 + var numQuads = 100000; 1.67 + var indexBuf = new ArrayBuffer(numQuads * 6); 1.68 + var indices = new Uint8Array(indexBuf); 1.69 + for (var ii = 0; ii < numQuads; ++ii) { 1.70 + var offset = ii * 6; 1.71 + indices[offset + 0] = 0; 1.72 + indices[offset + 1] = 1; 1.73 + indices[offset + 2] = 2; 1.74 + indices[offset + 3] = 3; 1.75 + indices[offset + 4] = 4; 1.76 + indices[offset + 5] = 5; 1.77 + } 1.78 + var indexBuffer = gl.createBuffer(); 1.79 + gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer); 1.80 + gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW); 1.81 + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after creating index buffer"); 1.82 + gl.drawElements(gl.TRIANGLES, numQuads * 6, gl.UNSIGNED_BYTE, 0); 1.83 + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after drawing"); 1.84 + 1.85 + successfullyParsed = true; 1.86 +} 1.87 +</script> 1.88 +</body> 1.89 +</html> 1.90 + 1.91 +