| 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 Out Of Resources Test</title> | |
| 12 <link rel="stylesheet" href="../resources/js-test-style.css"/> | |
| 13 <script src="../resources/desktop-gl-constants.js" type="text/javascript"></scri
pt> | |
| 14 <script src="../../debug/webgl-debug.js"></script> | |
| 15 <script src="../resources/js-test-pre.js"></script> | |
| 16 <script src="../conformance/resources/webgl-test.js"></script> | |
| 17 </head> | |
| 18 <body> | |
| 19 <div id="description"></div> | |
| 20 <div id="console"></div> | |
| 21 <canvas id="canvas" width="2" height="2"> </canvas> | |
| 22 <canvas id="canvas2" width="2" height="2"> </canvas> | |
| 23 <script> | |
| 24 window.onload = init; | |
| 25 debug("Tests a WebGL program that tries to use all of vram."); | |
| 26 | |
| 27 function init() { | |
| 28 if (confirm( | |
| 29 "after clicking ok your machine may be come unresponsive or crash")) { | |
| 30 main(); | |
| 31 } else { | |
| 32 debug("cancelled"); | |
| 33 } | |
| 34 } | |
| 35 | |
| 36 function main() { | |
| 37 debug(""); | |
| 38 debug("Canvas.getContext"); | |
| 39 | |
| 40 var gl = create3DContext(document.getElementById("canvas")); | |
| 41 if (!gl) { | |
| 42 testFailed("context does not exist"); | |
| 43 } else { | |
| 44 testPassed("context exists"); | |
| 45 | |
| 46 debug(""); | |
| 47 debug("Checking for out of memory handling."); | |
| 48 | |
| 49 var size = gl.getParameter(gl.MAX_RENDERBUFFER_SIZE); | |
| 50 debug("max render buffer size: " + size); | |
| 51 | |
| 52 var allocateFramebuffers = true; | |
| 53 var itervalId; | |
| 54 var count = 0; | |
| 55 | |
| 56 gl = WebGLDebugUtils.makeDebugContext(gl, function(err, functionName, args)
{ | |
| 57 window.clearInterval(intervalId); | |
| 58 assertMsg(err == gl.OUT_OF_MEMORY, | |
| 59 "correctly returns gl.OUT_OF_MEMORY when out of memory"); | |
| 60 finish(); | |
| 61 }); | |
| 62 | |
| 63 intervalId = window.setInterval(function() { | |
| 64 ++count; | |
| 65 var mem = count * size * size * 4; | |
| 66 debug("#" + count + " : memory allocated so far " + (mem / 1024 / 1024) +
"MB"); | |
| 67 var tex = gl.createTexture(); | |
| 68 gl.bindTexture(gl.TEXTURE_2D, tex); | |
| 69 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); | |
| 70 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); | |
| 71 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); | |
| 72 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); | |
| 73 gl.texImage2D(gl.TEXTURE_2D, | |
| 74 0, // level | |
| 75 gl.RGBA, // internalFormat | |
| 76 size, // width | |
| 77 size, // height | |
| 78 0, // border | |
| 79 gl.RGBA, // format | |
| 80 gl.UNSIGNED_BYTE, // type | |
| 81 null); // data | |
| 82 if (allocateFrameBuffers) { | |
| 83 var fb = gl.createFramebuffer(); | |
| 84 gl.bindFramebuffer(gl.FRAMEBUFFER, fb); | |
| 85 gl.framebufferTexture2D( | |
| 86 gl.FRAMEBUFFER, | |
| 87 gl.COLOR_ATTACHMENT0, | |
| 88 gl.TEXTURE_2D, | |
| 89 tex, | |
| 90 0); | |
| 91 var status = gl.checkFramebufferStatus(gl.FRAMEBUFFER); | |
| 92 if (status != gl.FRAMEBUFFER_COMPLETE) { | |
| 93 testFailed("gl.checkFramebufferStatus() returned " + WebGLDebugUtils.g
lEnumToString(status) + | |
| 94 " should have gotten gl.OUT_OF_MEMORY before getting this."
); | |
| 95 window.clearInterval(intervalId); | |
| 96 finish(); | |
| 97 } | |
| 98 } | |
| 99 }, 1000/10); | |
| 100 } | |
| 101 | |
| 102 function finish() { | |
| 103 debug(""); | |
| 104 successfullyParsed = true; | |
| 105 } | |
| 106 } | |
| 107 </script> | |
| 108 </body> | |
| 109 </html> | |
| OLD | NEW |