/content/canvas/test/webgl/extra/out-of-vram.html

http://github.com/zpao/v8monkey · HTML · 115 lines · 94 code · 16 blank · 5 comment · 0 complexity · 08d9deef636fd9a574009cef3649f95d MD5 · raw file

  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>
  7. <html>
  8. <head>
  9. <meta charset="utf-8">
  10. <title>WebGL Out Of VRAM Test</title>
  11. <link rel="stylesheet" href="../resources/js-test-style.css"/>
  12. <script src="../resources/desktop-gl-constants.js" type="text/javascript"></script>
  13. <script src="../resources/js-test-pre.js"></script>
  14. <script src="../conformance/resources/webgl-test.js"></script>
  15. <script src="../conformance/resources/webgl-test-utils.js"></script>
  16. </head>
  17. <body>
  18. <div id="description"></div>
  19. <div id="console"></div>
  20. <canvas id="canvas" width="2" height="2"> </canvas>
  21. <script>
  22. debug("This tests WebGL running out of vram.");
  23. debug("");
  24. debug("Canvas.getContext");
  25. var wtu = WebGLTestUtils;
  26. var canvas = document.getElementById("canvas");
  27. try {
  28. var gl = create3DContext(canvas);
  29. } catch(e) {
  30. }
  31. if (!gl) {
  32. testFailed("could not create context");
  33. } else {
  34. testPassed("context exists");
  35. var args = wtu.getUrlArguments();
  36. canvas.addEventListener('webglcontextlost', contextLost, false);
  37. function contextLost(e) {
  38. e.preventDefault();
  39. debug("***context lost***");
  40. }
  41. function contextRestored(e) {
  42. debug("***context restored***");
  43. }
  44. debug("");
  45. debug("Allocating textures.");
  46. var intervalId;
  47. var count = 0;
  48. var textureMem = 0;
  49. var textures = [];
  50. var size = 2048;
  51. var limit = (args.limit ? args.limit : 8192) * 1024 * 1024;
  52. debug("limit: " + InMB(limit))
  53. function InMB(v) {
  54. return "" + Math.floor(v / 1024 / 1024) + "MB";
  55. }
  56. function makeTexture() {
  57. if (gl.isContextLost()) {
  58. stop("out of memory");
  59. return;
  60. }
  61. ++count;
  62. textureMem += size * size * 4;
  63. if (textureMem > limit) {
  64. stop("reached limit");
  65. return;
  66. }
  67. debug ("creating texture #" + count + " mem = " + InMB(textureMem));
  68. var texture = gl.createTexture();
  69. textures.push(texture);
  70. gl.bindTexture(gl.TEXTURE_2D, texture);
  71. gl.texImage2D(gl.TEXTURE_2D,
  72. 0, // level
  73. gl.RGBA, // internalFormat
  74. size, // width
  75. size, // height
  76. 0, // border
  77. gl.RGBA, // format
  78. gl.UNSIGNED_BYTE, // type
  79. null); // data
  80. var err = gl.getError();
  81. if (err != gl.NO_ERROR) {
  82. stop("out of memory");
  83. return;
  84. }
  85. }
  86. intervalId = window.setInterval(makeTexture, 1000 / 15);
  87. }
  88. function stop(msg) {
  89. window.clearInterval(intervalId);
  90. testPassed(msg);
  91. finish();
  92. }
  93. function finish() {
  94. debug("");
  95. successfullyParsed = true;
  96. }
  97. </script>
  98. </body>
  99. </html>