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