OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 |
| 3 /* |
| 4 ** Copyright (c) 2012 The Khronos Group Inc. |
| 5 ** |
| 6 ** Permission is hereby granted, free of charge, to any person obtaining a |
| 7 ** copy of this software and/or associated documentation files (the |
| 8 ** "Materials"), to deal in the Materials without restriction, including |
| 9 ** without limitation the rights to use, copy, modify, merge, publish, |
| 10 ** distribute, sublicense, and/or sell copies of the Materials, and to |
| 11 ** permit persons to whom the Materials are furnished to do so, subject to |
| 12 ** the following conditions: |
| 13 ** |
| 14 ** The above copyright notice and this permission notice shall be included |
| 15 ** in all copies or substantial portions of the Materials. |
| 16 ** |
| 17 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 20 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 21 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 22 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 23 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
| 24 */ |
| 25 |
| 26 --> |
| 27 |
| 28 <!DOCTYPE html> |
| 29 <html> |
| 30 <head> |
| 31 <meta charset="utf-8"> |
| 32 <title>WebGL Out Of Memory Test</title> |
| 33 <link rel="stylesheet" href="../resources/js-test-style.css"/> |
| 34 <script src="../resources/desktop-gl-constants.js" type="text/javascript"></scri
pt> |
| 35 <script src="../resources/js-test-pre.js"></script> |
| 36 <script src="../conformance/resources/webgl-test.js"></script> |
| 37 </head> |
| 38 <body> |
| 39 <div id="description"></div> |
| 40 <div id="console"></div> |
| 41 <canvas id="canvas" width="2" height="2"> </canvas> |
| 42 <script> |
| 43 debug("This tests WebGL running out of memory."); |
| 44 |
| 45 debug(""); |
| 46 debug("Canvas.getContext"); |
| 47 |
| 48 var gl = create3DContext(document.getElementById("canvas")); |
| 49 if (!gl) { |
| 50 testFailed("context does not exist"); |
| 51 } else { |
| 52 testPassed("context exists"); |
| 53 |
| 54 debug(""); |
| 55 debug("Allocating shaders."); |
| 56 |
| 57 function makeBigShader() { |
| 58 var lines = []; |
| 59 var line = "// "; |
| 60 for (var ii = 0; ii < 1024; ++ii) { |
| 61 line += String.fromCharCode(48 + ii % 10); |
| 62 } |
| 63 for (var ii = 0; ii < 1024; ++ii) { |
| 64 lines[ii] = line; |
| 65 } |
| 66 var oneMB = lines.join(); |
| 67 for (var ii = 0; ii < 64; ++ii) { |
| 68 lines[ii] = oneMB; |
| 69 } |
| 70 return lines.join("\n"); |
| 71 } |
| 72 |
| 73 var shaderSource = makeBigShader(); |
| 74 debug("created " + Math.floor(shaderSource.length / 1024 / 1024) + "MB shader"
); |
| 75 |
| 76 var intervalId; |
| 77 var count = 0; |
| 78 |
| 79 function makeShader() { |
| 80 ++count; |
| 81 debug ("creating shader #" + count + " mem = " + Math.floor(shaderSource.len
gth * count / 1024 / 1024) + "MB"); |
| 82 var shader = gl.createShader(gl.VERTEX_SHADER); |
| 83 if (shader == null) { |
| 84 window.clearInterval(intervalId); |
| 85 testPassed("createShader returns null"); // not sure this is a passing |
| 86 finish(); |
| 87 } else { |
| 88 gl.shaderSource(shader, shaderSource); |
| 89 var err = gl.getError(); |
| 90 if (err != gl.NO_ERROR) { |
| 91 window.clearInterval(intervalId); |
| 92 assertMsg(err == gl.OUT_OF_MEMORY, "shaderSource returns OUT_OF_MEMORY")
; |
| 93 finish(); |
| 94 } |
| 95 } |
| 96 } |
| 97 |
| 98 intervalId = window.setInterval(makeShader, 1000/15); |
| 99 } |
| 100 |
| 101 function finish() { |
| 102 debug(""); |
| 103 successfullyParsed = true; |
| 104 } |
| 105 |
| 106 </script> |
| 107 <!-- <script src="../resources/js-test-post.js"></script> --> |
| 108 |
| 109 <script> |
| 110 </script> |
| 111 |
| 112 </body> |
| 113 </html> |
OLD | NEW |