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 Canvas Conformance Tests</title> |
| 11 <link rel="stylesheet" href="../../resources/js-test-style.css"/> |
| 12 <script src="../../resources/js-test-pre.js"></script> |
| 13 <script src="../resources/webgl-test.js"></script> |
| 14 <script src="../resources/webgl-test-utils.js"></script> |
| 15 </head> |
| 16 <body> |
| 17 <div id="description"></div> |
| 18 <div id="console"></div> |
| 19 |
| 20 <script id="vshader" type="x-shader/x-vertex"> |
| 21 attribute vec4 vPosition; |
| 22 void main() |
| 23 { |
| 24 gl_Position = vPosition; |
| 25 } |
| 26 </script> |
| 27 |
| 28 <script id="fshader" type="x-shader/x-fragment"> |
| 29 void main() |
| 30 { |
| 31 gl_FragColor = vec4(1.0,0.0,0.0,1.0); |
| 32 } |
| 33 </script> |
| 34 |
| 35 <script> |
| 36 function fail(x,y, buf, shouldBe) |
| 37 { |
| 38 var i = (y*50+x) * 4; |
| 39 var reason = "pixel at ("+x+","+y+") is ("+buf[i]+","+buf[i+1]+","+buf[i+2]+",
"+buf[i+3]+"), should be "+shouldBe; |
| 40 testFailed(reason); |
| 41 } |
| 42 |
| 43 function pass() |
| 44 { |
| 45 testPassed("drawing is correct"); |
| 46 } |
| 47 |
| 48 function drawTriangleTest(gl) |
| 49 { |
| 50 gl.viewport(0, 0, 50, 50); |
| 51 var vertexObject = gl.createBuffer(); |
| 52 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); |
| 53 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0
.5,0 ]), gl.STATIC_DRAW); |
| 54 gl.enableVertexAttribArray(0); |
| 55 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0); |
| 56 |
| 57 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
| 58 gl.drawArrays(gl.TRIANGLES, 0, 3); |
| 59 |
| 60 var buf = new Uint8Array(50 * 50 * 4); |
| 61 gl.readPixels(0, 0, 50, 50, gl.RGBA, gl.UNSIGNED_BYTE, buf); |
| 62 |
| 63 // Test several locations |
| 64 // First line should be all black |
| 65 for (var i = 0; i < 50; ++i) { |
| 66 if (buf[i*4] != 0 || buf[i*4+1] != 0 || buf[i*4+2] != 0 || buf[i*4+3] != 255
) { |
| 67 fail(i, 0, buf, "(0,0,0,255)"); |
| 68 return; |
| 69 } |
| 70 } |
| 71 // Line 15 should be red for at least 10 red pixels starting 20 pixels in |
| 72 var offset = (15*50+20) * 4; |
| 73 for (var i = 0; i < 10; ++i) { |
| 74 if (buf[offset+i*4] != 255 || buf[offset+i*4+1] != 0 || buf[offset+i*4+2] !=
0 || buf[offset+i*4+3] != 255) { |
| 75 fail(20 + i, 15, buf, "(255,0,0,255)"); |
| 76 return; |
| 77 } |
| 78 } |
| 79 // Last line should be all black |
| 80 offset = (49*50) * 4; |
| 81 for (var i = 0; i < 50; ++i) { |
| 82 if (buf[offset+i*4] != 0 || buf[offset+i*4+1] != 0 || buf[offset+i*4+2] != 0
|| buf[offset+i*4+3] != 255) { |
| 83 fail(i, 49, buf, "(0,0,0,255)"); |
| 84 return; |
| 85 } |
| 86 } |
| 87 } |
| 88 |
| 89 description("This test ensures WebGL implementations correctly implement drawing
bufferWidth/Height."); |
| 90 |
| 91 debug(""); |
| 92 |
| 93 var wtu = WebGLTestUtils; |
| 94 var err; |
| 95 var maxSize; |
| 96 var canvas = document.createElement("canvas"); |
| 97 var gl = create3DContext(canvas); |
| 98 if (!gl) { |
| 99 testFailed("context does not exist"); |
| 100 } else { |
| 101 testPassed("context exists"); |
| 102 |
| 103 gl.program = createProgram(gl, "vshader", "fshader", ["vPosition"]); |
| 104 shouldBeNonNull(gl.program); |
| 105 gl.useProgram(gl.program); |
| 106 gl.enable(gl.DEPTH_TEST); |
| 107 gl.disable(gl.BLEND); |
| 108 gl.clearColor(0, 0, 0, 1); |
| 109 gl.clearDepth(1); |
| 110 shouldBe('gl.getError()', 'gl.NO_ERROR'); |
| 111 |
| 112 debug(""); |
| 113 debug("Checking drawingBufferWidth/drawingBufferHeight"); |
| 114 |
| 115 // Check that a canvas with no width or height is 300x150 pixels |
| 116 shouldBe('gl.drawingBufferWidth', 'canvas.width'); |
| 117 shouldBe('gl.drawingBufferHeight', 'canvas.height'); |
| 118 |
| 119 // Check that changing the canvas size to something too large falls back to re
asonable values. |
| 120 maxSize = gl.getParameter(gl.MAX_VIEWPORT_DIMS); |
| 121 shouldBeTrue('maxSize[0] > 0'); |
| 122 shouldBeTrue('maxSize[1] > 0'); |
| 123 |
| 124 // debug("MAX_VIEWPORT_DIMS = " + maxSize[0] + "x" + maxSize[1]); |
| 125 canvas.width = maxSize[0] * 4; |
| 126 canvas.height = maxSize[1] * 4; |
| 127 shouldBeTrue('gl.drawingBufferWidth > 0'); |
| 128 shouldBeTrue('gl.drawingBufferHeight > 0'); |
| 129 shouldBeTrue('gl.drawingBufferWidth <= maxSize[0]'); |
| 130 shouldBeTrue('gl.drawingBufferHeight <= maxSize[1]'); |
| 131 shouldBe('gl.getError()', 'gl.NO_ERROR'); |
| 132 |
| 133 debug(""); |
| 134 debug("Checking scaling up then back down to 50/50, drawing still works."); |
| 135 canvas.width = 50; |
| 136 canvas.height = 50; |
| 137 shouldBeTrue('gl.drawingBufferWidth == 50'); |
| 138 shouldBeTrue('gl.drawingBufferHeight == 50'); |
| 139 shouldBe('gl.getError()', 'gl.NO_ERROR'); |
| 140 drawTriangleTest(gl); |
| 141 shouldBe('gl.getError()', 'gl.NO_ERROR'); |
| 142 } |
| 143 debug("") |
| 144 successfullyParsed = true; |
| 145 </script> |
| 146 <script src="../../resources/js-test-post.js"></script> |
| 147 </body> |
| 148 </html> |
OLD | NEW |