OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 Copyright (c) 2011 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 Scissor Test</title> |
| 11 <link rel="stylesheet" href="../../resources/js-test-style.css"/> |
| 12 <script src="../../resources/desktop-gl-constants.js" type="text/javascript"></s
cript> |
| 13 <script src="../../debug/webgl-debug.js"></script> |
| 14 <script src="../../resources/js-test-pre.js"></script> |
| 15 <script src="../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" style="width: 40px; height: 40px;"> </c
anvas> |
| 21 <script> |
| 22 description("Check if glScissor setting works."); |
| 23 |
| 24 debug(""); |
| 25 debug("Canvas.getContext"); |
| 26 |
| 27 var wtu = WebGLTestUtils; |
| 28 var gl = wtu.create3DContext(document.getElementById("canvas")); |
| 29 if (!gl) { |
| 30 testFailed("context does not exist"); |
| 31 } else { |
| 32 testPassed("context exists"); |
| 33 |
| 34 debug(""); |
| 35 |
| 36 gl.clearColor(0,0,0,0); |
| 37 gl.clear(gl.COLOR_BUFFER_BIT); |
| 38 |
| 39 // clear a portion of our FBO |
| 40 gl.enable(gl.SCISSOR_TEST); |
| 41 gl.scissor(0, 0, 1, 1); |
| 42 gl.clearColor(0,1,0,1); |
| 43 gl.clear(gl.COLOR_BUFFER_BIT); |
| 44 |
| 45 var b = new Uint8Array(2 * 2 * 4); |
| 46 gl.readPixels(0, 0, 2, 2, gl.RGBA, gl.UNSIGNED_BYTE, b); |
| 47 |
| 48 function checkPixel(b, x, y, color) { |
| 49 var offset = (y * 2 + x) * 4; |
| 50 var match = true; |
| 51 for (var c = 0; c < 4; ++c) { |
| 52 if (b[offset + c] != color[c] * 255) { |
| 53 match = false; |
| 54 break; |
| 55 } |
| 56 } |
| 57 assertMsg(match, "pixel at " + x + ", " + y + " is expected value"); |
| 58 } |
| 59 |
| 60 checkPixel(b, 0, 0, [0, 1, 0, 1]); |
| 61 checkPixel(b, 1, 0, [0, 0, 0, 0]); |
| 62 checkPixel(b, 0, 1, [0, 0, 0, 0]); |
| 63 checkPixel(b, 1, 1, [0, 0, 0, 0]); |
| 64 } |
| 65 |
| 66 debug(""); |
| 67 successfullyParsed = true; |
| 68 |
| 69 </script> |
| 70 <script src="../../resources/js-test-post.js"></script> |
| 71 |
| 72 </body> |
| 73 </html> |
OLD | NEW |