gecko/content/canvas/test/webgl/conformance/framebuffer-test.html
2010-06-04 12:03:40 -07:00

134 lines
4.9 KiB
HTML

<!--
Copyright (c) 2009 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>WebGL Framebuffer Test</title>
<link rel="stylesheet" href="../resources/js-test-style.css"/>
<script src="../resources/desktop-gl-constants.js" type="text/javascript"></script>
<script src="../resources/js-test-pre.js"></script>
<script src="resources/webgl-test.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas" width="2" height="2"> </canvas>
<script>
description("This tests framebuffer/renderbuffer-related functions");
debug("");
debug("Canvas.getContext");
var canvas = document.getElementById("canvas");
var gl = create3DContext(canvas);
if (!gl) {
testFailed("context does not exist");
} else {
testPassed("context exists");
debug("");
debug("Checking framebuffer/renderbuffer stuff.");
var value = gl.getFramebufferAttachmentParameter(
gl.FRAMEBUFFER,
gl.COLOR_ATTACHMENT0,
gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE);
assertMsg(gl.getError() == gl.INVALID_OPERATION,
"calling getFramebufferAttachmentParameter on the default framebuffer should generate INVALID_OPERATION.");
var tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.texImage2D(gl.TEXTURE_2D,
0, // level
gl.RGBA, // internalFormat
canvas.width, // width
canvas.height, // height
0, // border
gl.RGBA, // format
gl.UNSIGNED_BYTE, // type
null); // data
gl.framebufferTexture2D(
gl.FRAMEBUFFER,
gl.COLOR_ATTACHMENT0,
gl.TEXTURE_2D,
tex,
0);
assertMsg(gl.getError() == gl.INVALID_OPERATION,
"trying to attach a texture to default framebuffer should generate INVALID_OPERATION.");
gl.framebufferRenderbuffer(
gl.FRAMEBUFFER,
gl.COLOR_ATTACHMENT0,
gl.RENDERBUFFER,
null);
assertMsg(gl.getError() == gl.INVALID_OPERATION,
"trying to detach default renderbuffer from default framebuffer should generate INVALID_OPERATION.");
var rb = gl.createRenderbuffer();
gl.bindRenderbuffer(gl.RENDERBUFFER, rb);
gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, canvas.width, canvas.height);
assertMsg(gl.getError() == gl.NO_ERROR,
"allocating renderbuffer storage of a newly created renderbuffer should succeed.");
gl.framebufferRenderbuffer(
gl.FRAMEBUFFER,
gl.COLOR_ATTACHMENT0,
gl.RENDERBUFFER,
rb);
assertMsg(gl.getError() == gl.INVALID_OPERATION,
"trying to attach a renderbuffer to the default framebuffer should generate INVALID_OPERATION.");
var fbtex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, fbtex);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, canvas.width, canvas.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
var fb = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
assertMsg(gl.getError() == gl.NO_ERROR,
"binding a newly created framebuffer should succeed.");
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, fbtex, 0);
assertMsg(gl.getError() == gl.NO_ERROR,
"attaching a texture to a framebuffer should succeed.");
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, null, 0);
assertMsg(gl.getError() == gl.NO_ERROR,
"detaching a texture from a framebuffer should succeed.");
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, fbtex, 1);
assertMsg(gl.getError() == gl.INVALID_VALUE,
"calling framebufferTexture2D with non-zero mipmap level should generate INVALID_VALUE.");
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, rb);
assertMsg(gl.getError() == gl.NO_ERROR,
"attaching a renderbuffer to a framebuffer should succeed.");
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, null);
assertMsg(gl.getError() == gl.NO_ERROR,
"detaching a renderbuffer from a framebuffer should succeed.");
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
assertMsg(gl.getError() == gl.NO_ERROR,
"binding default (null) framebuffer should succeed.");
}
debug("");
successfullyParsed = true;
</script>
<script src="../resources/js-test-post.js"></script>
<script>
</script>
</body>
</html>