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.
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>
17 <canvas id=
"example" width=
"1024" height=
"1024" style=
"width: 40px; height: 40px;">
19 <div id=
"description"></div>
20 <div id=
"console"></div>
24 debug("Tests a WebGL program that draws a bunch of large polygons");
28 "After clicking OK your machine may become unresponsive or crash.")) {
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);
41 var gl
= wtu
.create3DContext(canvas
);
42 var program
= wtu
.setupTexturedQuad(gl
);
44 assertMsg(gl
.getError() == gl
.NO_ERROR
, "Should be no errors from setup.");
46 var tex
= gl
.createTexture();
48 gl
.disable(gl
.DEPTH_TEST
);
50 wtu
.fillTexture(gl
, tex
, 4096, 4096, [0, 192, 128, 255], 0);
51 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "after creating texture");
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");
59 var loc
= gl
.getUniformLocation(program
, "tex");
60 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "after getting tex locations");
62 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "after setting tex uniform");
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
) {
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;
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");
83 var successfullyParsed
= true;