tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

lots-of-polys-example.html (2852B)


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