content/canvas/test/webgl-conformance/conformance/renderbuffers/renderbuffer-initialization.html

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

michael@0 1 <!--
michael@0 2 Copyright (c) 2011 The Chromium Authors. All rights reserved.
michael@0 3 Use of this source code is governed by a BSD-style license that can be
michael@0 4 found in the LICENSE file.
michael@0 5 -->
michael@0 6 <!DOCTYPE html>
michael@0 7 <html>
michael@0 8 <head>
michael@0 9 <meta charset="utf-8">
michael@0 10 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
michael@0 11 <script src="../../resources/js-test-pre.js"></script>
michael@0 12 <script src="../resources/webgl-test.js"></script>
michael@0 13 <script src="../resources/webgl-test-utils.js"></script>
michael@0 14 </head>
michael@0 15 <body>
michael@0 16 <canvas id="testbed" width="400" height="400" style="width: 40px; height: 40px;"></canvas>
michael@0 17 <div id="description"></div>
michael@0 18 <div id="console"></div>
michael@0 19 <script>
michael@0 20 var wtu = WebGLTestUtils;
michael@0 21 description('Verify renderbuffers are initialized to 0 before being read in WebGL');
michael@0 22
michael@0 23 var gl = wtu.create3DContext("testbed");
michael@0 24 if (!gl) {
michael@0 25 testFailed('canvas.getContext() failed');
michael@0 26 } else {
michael@0 27 // Set the clear color to green. It should never show up.
michael@0 28 gl.clearColor(0, 1, 0, 1);
michael@0 29
michael@0 30 runTest(gl, gl.canvas.width, gl.canvas.height, 0);
michael@0 31 runTest(gl, gl.canvas.width, gl.canvas.height, 1);
michael@0 32 runTest(gl, gl.canvas.width, gl.canvas.height, 0);
michael@0 33 runTest(gl, gl.canvas.width, gl.canvas.height, 1);
michael@0 34
michael@0 35 // Testing buffer clearing won't change the clear values.
michael@0 36 var clearColor = gl.getParameter(gl.COLOR_CLEAR_VALUE);
michael@0 37 shouldBe("clearColor", "[0, 1, 0, 1]");
michael@0 38 glErrorShouldBe(gl, gl.NO_ERROR, 'should be no errors');
michael@0 39 }
michael@0 40
michael@0 41 function runTest(gl, width, height, order)
michael@0 42 {
michael@0 43 wtu.checkCanvasRect(gl, 0, 0, width, height, [0,0,0,0],
michael@0 44 "internal buffers have been initialized to 0");
michael@0 45
michael@0 46 // fill the back buffer so we know that reading below happens from
michael@0 47 // the renderbuffer.
michael@0 48 gl.clear(gl.COLOR_BUFFER_BIT);
michael@0 49
michael@0 50 var fbo = gl.createFramebuffer();
michael@0 51 gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
michael@0 52 var colorbuffer = gl.createRenderbuffer();
michael@0 53 gl.bindRenderbuffer(gl.RENDERBUFFER, colorbuffer);
michael@0 54 switch (order) {
michael@0 55 case 0:
michael@0 56 allocStorage(width, height);
michael@0 57 attachBuffer(colorbuffer);
michael@0 58 break;
michael@0 59 case 1:
michael@0 60 attachBuffer(colorbuffer);
michael@0 61 allocStorage(width, height);
michael@0 62 break;
michael@0 63 }
michael@0 64
michael@0 65 function allocStorage(width, height) {
michael@0 66 gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, width, height);
michael@0 67 glErrorShouldBe(gl, gl.NO_ERROR, 'should be no error after renderbufferStorage(internalformat = RGBA4).');
michael@0 68 }
michael@0 69
michael@0 70 function attachBuffer(colorbuffer) {
michael@0 71 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, colorbuffer);
michael@0 72 }
michael@0 73
michael@0 74 if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) {
michael@0 75 testFailed('Framebuffer incomplete.');
michael@0 76 return;
michael@0 77 }
michael@0 78
michael@0 79 wtu.checkCanvasRect(gl, 0, 0, width, height, [0,0,0,0],
michael@0 80 "user buffers have been initialized to 0");
michael@0 81
michael@0 82 gl.deleteFramebuffer(fbo);
michael@0 83 gl.deleteRenderbuffer(colorbuffer);
michael@0 84
michael@0 85 // this clear should not matter we are about to resize
michael@0 86 gl.clear(gl.COLOR_BUFFER_BIT);
michael@0 87
michael@0 88 gl.canvas.width += 1;
michael@0 89 gl.canvas.height += 1;
michael@0 90
michael@0 91 debug('');
michael@0 92 }
michael@0 93
michael@0 94 successfullyParsed = true;
michael@0 95 </script>
michael@0 96 <script>finishTest();</script>
michael@0 97 </body>
michael@0 98 </html>

mercurial