Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
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 Slow Shader 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 id="slow" type="text/something-not-javascript"> |
michael@0 | 22 | precision mediump float; |
michael@0 | 23 | uniform sampler2D tex; |
michael@0 | 24 | varying vec2 texCoord; |
michael@0 | 25 | void main() { |
michael@0 | 26 | gl_FragColor = texture2D(tex, texture2D(tex, texture2D(tex, texCoord).xy).xy); |
michael@0 | 27 | } |
michael@0 | 28 | </script> |
michael@0 | 29 | <script> |
michael@0 | 30 | window.onload = main; |
michael@0 | 31 | |
michael@0 | 32 | debug("Tests drawing a very slow shader."); |
michael@0 | 33 | var wtu = WebGLTestUtils; |
michael@0 | 34 | var canvas = document.getElementById("example"); |
michael@0 | 35 | canvas.addEventListener("webglcontextlost", function(e) { e.preventDefault(); }, false); |
michael@0 | 36 | canvas.addEventListener("webglcontextrestored", function(e) { }, false); |
michael@0 | 37 | var gl = wtu.create3DContext(canvas); |
michael@0 | 38 | var maxTexSize = gl.getParameter(gl.MAX_TEXTURE_SIZE); |
michael@0 | 39 | var texSize = Math.min(maxTexSize, 4096); |
michael@0 | 40 | debug("Max Texture size: " + maxTexSize); |
michael@0 | 41 | debug("Texture size: " + texSize); |
michael@0 | 42 | var shaderSource = |
michael@0 | 43 | document.getElementById("slow").text.replace(/\$size/g, texSize + ".0"); |
michael@0 | 44 | wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after getting a context"); |
michael@0 | 45 | var vs = wtu.setupSimpleTextureVertexShader(gl); |
michael@0 | 46 | var fs = wtu.loadShader( |
michael@0 | 47 | gl, |
michael@0 | 48 | shaderSource, |
michael@0 | 49 | gl.FRAGMENT_SHADER) |
michael@0 | 50 | var program = wtu.setupProgram( |
michael@0 | 51 | gl, |
michael@0 | 52 | [vs, fs], |
michael@0 | 53 | ['vPosition', 'texCoord0'], |
michael@0 | 54 | [0, 1]); |
michael@0 | 55 | wtu.setupUnitQuad(gl, 0, 1); |
michael@0 | 56 | wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after program setup"); |
michael@0 | 57 | var tex = gl.createTexture(); |
michael@0 | 58 | gl.enable(gl.BLEND); |
michael@0 | 59 | gl.disable(gl.DEPTH_TEST); |
michael@0 | 60 | |
michael@0 | 61 | wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after creating texture"); |
michael@0 | 62 | debug("preparing..."); |
michael@0 | 63 | var numBytes = texSize * texSize * 4; |
michael@0 | 64 | var pixelBuf = new ArrayBuffer(numBytes); |
michael@0 | 65 | var pixels = new Uint8Array(pixelBuf); |
michael@0 | 66 | for (var ii = 0; ii < numBytes; ++ii) { |
michael@0 | 67 | pixels[ii] = Math.random() * 255; |
michael@0 | 68 | } |
michael@0 | 69 | gl.bindTexture(gl.TEXTURE_2D, tex); |
michael@0 | 70 | gl.texImage2D( |
michael@0 | 71 | gl.TEXTURE_2D, 0, gl.RGBA, texSize, texSize, 0, |
michael@0 | 72 | gl.RGBA, gl.UNSIGNED_BYTE, pixels); |
michael@0 | 73 | wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after texture setup"); |
michael@0 | 74 | |
michael@0 | 75 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); |
michael@0 | 76 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); |
michael@0 | 77 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT); |
michael@0 | 78 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT); |
michael@0 | 79 | wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after texture param setting"); |
michael@0 | 80 | |
michael@0 | 81 | var loc = gl.getUniformLocation(program, "tex"); |
michael@0 | 82 | wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after getting tex location"); |
michael@0 | 83 | gl.uniform1i(loc, 0); |
michael@0 | 84 | wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after setting tex uniform"); |
michael@0 | 85 | |
michael@0 | 86 | var numQuads = 1000; |
michael@0 | 87 | var indexBuf = new ArrayBuffer(numQuads * 6); |
michael@0 | 88 | var indices = new Uint8Array(indexBuf); |
michael@0 | 89 | for (var ii = 0; ii < numQuads; ++ii) { |
michael@0 | 90 | var offset = ii * 6; |
michael@0 | 91 | indices[offset + 0] = 0; |
michael@0 | 92 | indices[offset + 1] = 1; |
michael@0 | 93 | indices[offset + 2] = 2; |
michael@0 | 94 | indices[offset + 3] = 3; |
michael@0 | 95 | indices[offset + 4] = 4; |
michael@0 | 96 | indices[offset + 5] = 5; |
michael@0 | 97 | } |
michael@0 | 98 | var indexBuffer = gl.createBuffer(); |
michael@0 | 99 | gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer); |
michael@0 | 100 | gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW); |
michael@0 | 101 | wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after setting up indices"); |
michael@0 | 102 | |
michael@0 | 103 | function main () { |
michael@0 | 104 | if (confirm( |
michael@0 | 105 | "after clicking ok your machine may be come unresponsive or crash")) { |
michael@0 | 106 | gl.drawElements(gl.TRIANGLES, numQuads * 6, gl.UNSIGNED_BYTE, 0); |
michael@0 | 107 | wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after drawing"); |
michael@0 | 108 | } else { |
michael@0 | 109 | debug("cancelled"); |
michael@0 | 110 | } |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | successfullyParsed = true; |
michael@0 | 114 | </script> |
michael@0 | 115 | </body> |
michael@0 | 116 | </html> |