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