1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/test/webgl-conformance/conformance/renderbuffers/renderbuffer-initialization.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,98 @@ 1.4 +<!-- 1.5 +Copyright (c) 2011 The Chromium Authors. All rights reserved. 1.6 +Use of this source code is governed by a BSD-style license that can be 1.7 +found in the LICENSE file. 1.8 + --> 1.9 +<!DOCTYPE html> 1.10 +<html> 1.11 +<head> 1.12 +<meta charset="utf-8"> 1.13 +<link rel="stylesheet" href="../../resources/js-test-style.css"/> 1.14 +<script src="../../resources/js-test-pre.js"></script> 1.15 +<script src="../resources/webgl-test.js"></script> 1.16 +<script src="../resources/webgl-test-utils.js"></script> 1.17 +</head> 1.18 +<body> 1.19 +<canvas id="testbed" width="400" height="400" style="width: 40px; height: 40px;"></canvas> 1.20 +<div id="description"></div> 1.21 +<div id="console"></div> 1.22 +<script> 1.23 +var wtu = WebGLTestUtils; 1.24 +description('Verify renderbuffers are initialized to 0 before being read in WebGL'); 1.25 + 1.26 +var gl = wtu.create3DContext("testbed"); 1.27 +if (!gl) { 1.28 + testFailed('canvas.getContext() failed'); 1.29 +} else { 1.30 + // Set the clear color to green. It should never show up. 1.31 + gl.clearColor(0, 1, 0, 1); 1.32 + 1.33 + runTest(gl, gl.canvas.width, gl.canvas.height, 0); 1.34 + runTest(gl, gl.canvas.width, gl.canvas.height, 1); 1.35 + runTest(gl, gl.canvas.width, gl.canvas.height, 0); 1.36 + runTest(gl, gl.canvas.width, gl.canvas.height, 1); 1.37 + 1.38 + // Testing buffer clearing won't change the clear values. 1.39 + var clearColor = gl.getParameter(gl.COLOR_CLEAR_VALUE); 1.40 + shouldBe("clearColor", "[0, 1, 0, 1]"); 1.41 + glErrorShouldBe(gl, gl.NO_ERROR, 'should be no errors'); 1.42 +} 1.43 + 1.44 +function runTest(gl, width, height, order) 1.45 +{ 1.46 + wtu.checkCanvasRect(gl, 0, 0, width, height, [0,0,0,0], 1.47 + "internal buffers have been initialized to 0"); 1.48 + 1.49 + // fill the back buffer so we know that reading below happens from 1.50 + // the renderbuffer. 1.51 + gl.clear(gl.COLOR_BUFFER_BIT); 1.52 + 1.53 + var fbo = gl.createFramebuffer(); 1.54 + gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); 1.55 + var colorbuffer = gl.createRenderbuffer(); 1.56 + gl.bindRenderbuffer(gl.RENDERBUFFER, colorbuffer); 1.57 + switch (order) { 1.58 + case 0: 1.59 + allocStorage(width, height); 1.60 + attachBuffer(colorbuffer); 1.61 + break; 1.62 + case 1: 1.63 + attachBuffer(colorbuffer); 1.64 + allocStorage(width, height); 1.65 + break; 1.66 + } 1.67 + 1.68 + function allocStorage(width, height) { 1.69 + gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, width, height); 1.70 + glErrorShouldBe(gl, gl.NO_ERROR, 'should be no error after renderbufferStorage(internalformat = RGBA4).'); 1.71 + } 1.72 + 1.73 + function attachBuffer(colorbuffer) { 1.74 + gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, colorbuffer); 1.75 + } 1.76 + 1.77 + if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) { 1.78 + testFailed('Framebuffer incomplete.'); 1.79 + return; 1.80 + } 1.81 + 1.82 + wtu.checkCanvasRect(gl, 0, 0, width, height, [0,0,0,0], 1.83 + "user buffers have been initialized to 0"); 1.84 + 1.85 + gl.deleteFramebuffer(fbo); 1.86 + gl.deleteRenderbuffer(colorbuffer); 1.87 + 1.88 + // this clear should not matter we are about to resize 1.89 + gl.clear(gl.COLOR_BUFFER_BIT); 1.90 + 1.91 + gl.canvas.width += 1; 1.92 + gl.canvas.height += 1; 1.93 + 1.94 + debug(''); 1.95 +} 1.96 + 1.97 +successfullyParsed = true; 1.98 +</script> 1.99 +<script>finishTest();</script> 1.100 +</body> 1.101 +</html>