content/canvas/test/webgl-conformance/extra/lots-of-polys-example.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!--
michael@0 2 Copyright (c) 2009 The Chromium Authors. All rights reserved.
michael@0 3 Use of this source code is governed by a BSD-style license that can be
michael@0 4 found in the LICENSE file.
michael@0 5 -->
michael@0 6 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
michael@0 7 "http://www.w3.org/TR/html4/loose.dtd">
michael@0 8 <html>
michael@0 9 <head>
michael@0 10 <meta charset="utf-8">
michael@0 11 <title>WebGL Lots of polygons example.</title>
michael@0 12 <link rel="stylesheet" href="../resources/js-test-style.css"/>
michael@0 13 <script src="../resources/js-test-pre.js"></script>
michael@0 14 <script src="../conformance/resources/webgl-test-utils.js"> </script>
michael@0 15 </head>
michael@0 16 <body>
michael@0 17 <canvas id="example" width="1024" height="1024" style="width: 40px; height: 40px;">
michael@0 18 </canvas>
michael@0 19 <div id="description"></div>
michael@0 20 <div id="console"></div>
michael@0 21 <script>
michael@0 22 window.onload = init;
michael@0 23 debug("Tests a WebGL program that draws a bunch of large polygons");
michael@0 24
michael@0 25 function init() {
michael@0 26 if (confirm(
michael@0 27 "after clicking ok your machine may be come unresponsive or crash")) {
michael@0 28 main();
michael@0 29 } else {
michael@0 30 debug("cancelled");
michael@0 31 }
michael@0 32 }
michael@0 33
michael@0 34 function main() {
michael@0 35 var wtu = WebGLTestUtils;
michael@0 36 var canvas = document.getElementById("example");
michael@0 37 canvas.addEventListener("webglcontextlost", function(e) { e.preventDefault(); }, false);
michael@0 38 canvas.addEventListener("webglcontextrestored", function(e) { }, false);
michael@0 39
michael@0 40 var gl = wtu.create3DContext(canvas);
michael@0 41 var program = wtu.setupTexturedQuad(gl);
michael@0 42
michael@0 43 assertMsg(gl.getError() == gl.NO_ERROR, "Should be no errors from setup.");
michael@0 44
michael@0 45 var tex = gl.createTexture();
michael@0 46 gl.enable(gl.BLEND);
michael@0 47 gl.disable(gl.DEPTH_TEST);
michael@0 48
michael@0 49 wtu.fillTexture(gl, tex, 4096, 4096, [0, 192, 128, 255], 0);
michael@0 50 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after creating texture");
michael@0 51
michael@0 52 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
michael@0 53 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
michael@0 54 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
michael@0 55 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
michael@0 56 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after setting texture params");
michael@0 57
michael@0 58 var loc = gl.getUniformLocation(program, "tex");
michael@0 59 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after getting tex locations");
michael@0 60 gl.uniform1i(loc, 0);
michael@0 61 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after setting tex uniform");
michael@0 62
michael@0 63 var numQuads = 100000;
michael@0 64 var indexBuf = new ArrayBuffer(numQuads * 6);
michael@0 65 var indices = new Uint8Array(indexBuf);
michael@0 66 for (var ii = 0; ii < numQuads; ++ii) {
michael@0 67 var offset = ii * 6;
michael@0 68 indices[offset + 0] = 0;
michael@0 69 indices[offset + 1] = 1;
michael@0 70 indices[offset + 2] = 2;
michael@0 71 indices[offset + 3] = 3;
michael@0 72 indices[offset + 4] = 4;
michael@0 73 indices[offset + 5] = 5;
michael@0 74 }
michael@0 75 var indexBuffer = gl.createBuffer();
michael@0 76 gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
michael@0 77 gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW);
michael@0 78 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after creating index buffer");
michael@0 79 gl.drawElements(gl.TRIANGLES, numQuads * 6, gl.UNSIGNED_BYTE, 0);
michael@0 80 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after drawing");
michael@0 81
michael@0 82 successfullyParsed = true;
michael@0 83 }
michael@0 84 </script>
michael@0 85 </body>
michael@0 86 </html>
michael@0 87
michael@0 88

mercurial