content/canvas/test/webgl-conformance/conformance/renderbuffers/framebuffer-test.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 <title>WebGL Framebuffer Test</title>
michael@0 11 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
michael@0 12 <script src="../../resources/js-test-pre.js"></script>
michael@0 13 <script src="../resources/webgl-test.js"></script>
michael@0 14 <script src="../../resources/desktop-gl-constants.js"></script>
michael@0 15 </head>
michael@0 16 <body>
michael@0 17 <div id="description"></div>
michael@0 18 <div id="console"></div>
michael@0 19 <canvas id="canvas" width="2" height="2"> </canvas>
michael@0 20 <script>
michael@0 21 description("This tests framebuffer/renderbuffer-related functions");
michael@0 22
michael@0 23 debug("");
michael@0 24 debug("Canvas.getContext");
michael@0 25
michael@0 26 var canvas = document.getElementById("canvas");
michael@0 27 var gl = create3DContext(canvas);
michael@0 28 if (!gl) {
michael@0 29 testFailed("context does not exist");
michael@0 30 } else {
michael@0 31 testPassed("context exists");
michael@0 32
michael@0 33 debug("");
michael@0 34 debug("Checking framebuffer/renderbuffer stuff.");
michael@0 35
michael@0 36 var value = gl.getFramebufferAttachmentParameter(
michael@0 37 gl.FRAMEBUFFER,
michael@0 38 gl.COLOR_ATTACHMENT0,
michael@0 39 gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE);
michael@0 40 glErrorShouldBe(gl, gl.INVALID_OPERATION,
michael@0 41 "calling getFramebufferAttachmentParameter on the default framebuffer should generate INVALID_OPERATION.");
michael@0 42
michael@0 43 assertMsg(gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE,
michael@0 44 "calling checkFramebufferStatus on the default framebuffer should generate FRAMEBUFFER_COMPLETE.");
michael@0 45
michael@0 46 var tex = gl.createTexture();
michael@0 47 gl.bindTexture(gl.TEXTURE_2D, tex);
michael@0 48 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
michael@0 49 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
michael@0 50 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
michael@0 51 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
michael@0 52 gl.texImage2D(gl.TEXTURE_2D,
michael@0 53 0, // level
michael@0 54 gl.RGBA, // internalFormat
michael@0 55 canvas.width, // width
michael@0 56 canvas.height, // height
michael@0 57 0, // border
michael@0 58 gl.RGBA, // format
michael@0 59 gl.UNSIGNED_BYTE, // type
michael@0 60 null); // data
michael@0 61 gl.framebufferTexture2D(
michael@0 62 gl.FRAMEBUFFER,
michael@0 63 gl.COLOR_ATTACHMENT0,
michael@0 64 gl.TEXTURE_2D,
michael@0 65 tex,
michael@0 66 0);
michael@0 67 glErrorShouldBe(gl, gl.INVALID_OPERATION,
michael@0 68 "trying to attach a texture to default framebuffer should generate INVALID_OPERATION.");
michael@0 69
michael@0 70 gl.framebufferRenderbuffer(
michael@0 71 gl.FRAMEBUFFER,
michael@0 72 gl.COLOR_ATTACHMENT0,
michael@0 73 gl.RENDERBUFFER,
michael@0 74 null);
michael@0 75 glErrorShouldBe(gl, gl.INVALID_OPERATION,
michael@0 76 "trying to detach default renderbuffer from default framebuffer should generate INVALID_OPERATION.");
michael@0 77
michael@0 78 var rb = gl.createRenderbuffer();
michael@0 79 gl.bindRenderbuffer(gl.RENDERBUFFER, rb);
michael@0 80 gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, canvas.width, canvas.height);
michael@0 81 glErrorShouldBe(gl, gl.NO_ERROR,
michael@0 82 "allocating renderbuffer storage of a newly created renderbuffer should succeed.");
michael@0 83
michael@0 84 gl.framebufferRenderbuffer(
michael@0 85 gl.FRAMEBUFFER,
michael@0 86 gl.COLOR_ATTACHMENT0,
michael@0 87 gl.RENDERBUFFER,
michael@0 88 rb);
michael@0 89 glErrorShouldBe(gl, gl.INVALID_OPERATION,
michael@0 90 "trying to attach a renderbuffer to the default framebuffer should generate INVALID_OPERATION.");
michael@0 91
michael@0 92 var fbtex = gl.createTexture();
michael@0 93 gl.bindTexture(gl.TEXTURE_2D, fbtex);
michael@0 94 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, canvas.width, canvas.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
michael@0 95 var fb = gl.createFramebuffer();
michael@0 96
michael@0 97 gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
michael@0 98 glErrorShouldBe(gl, gl.NO_ERROR,
michael@0 99 "binding a newly created framebuffer should succeed.");
michael@0 100
michael@0 101 var target = desktopGL.READ_FRAMEBUFFER
michael@0 102 gl.getFramebufferAttachmentParameter(
michael@0 103 target,
michael@0 104 gl.COLOR_ATTACHMENT0,
michael@0 105 gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE);
michael@0 106 glErrorShouldBe(gl, gl.INVALID_ENUM,
michael@0 107 "calling getFramebufferAttachmentParameter with target = READ_FRAMEBUFFER should generate INVALID_ENUM.");
michael@0 108 assertMsg(gl.checkFramebufferStatus(target) == 0,
michael@0 109 "calling checkFramebufferStatus with target = READ_FRAMEBUFFER should return 0.");
michael@0 110 glErrorShouldBe(gl, gl.INVALID_ENUM,
michael@0 111 "calling checkFramebufferStatus with target = READ_FRAMEBUFFER should generate INVALID_ENUM.");
michael@0 112 gl.bindFramebuffer(target, gl.createFramebuffer());
michael@0 113 glErrorShouldBe(gl, gl.INVALID_ENUM,
michael@0 114 "calling bindFramebuffer with target = READ_FRAMEBUFFER should generate INVALID_ENUM.");
michael@0 115 assertMsg(fb == gl.getParameter(gl.FRAMEBUFFER_BINDING),
michael@0 116 "calling bindFramebuffer with target = READ_FRAMEBUFFER should not change FRAMEBUFFER_BINDING.");
michael@0 117 gl.getFramebufferAttachmentParameter(target, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE);
michael@0 118 glErrorShouldBe(gl, gl.INVALID_ENUM,
michael@0 119 "calling getFramebufferAttachmentParameter with target = READ_FRAMEBUFFER should generate INVALID_ENUM.");
michael@0 120 gl.framebufferTexture2D(target, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, fbtex, 0);
michael@0 121 glErrorShouldBe(gl, gl.INVALID_ENUM,
michael@0 122 "calling framebufferTexImage2D with target = READ_FRAMEBUFFER should generate INVALID_ENUM.");
michael@0 123 gl.framebufferRenderbuffer(target, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, rb);
michael@0 124 glErrorShouldBe(gl, gl.INVALID_ENUM,
michael@0 125 "calling framebufferRenderbuffer with target = READ_FRAMEBUFFER should generate INVALID_ENUM.");
michael@0 126
michael@0 127 var attachment = desktopGL.COLOR_ATTACHMENT1
michael@0 128 gl.framebufferTexture2D(gl.FRAMEBUFFER, attachment, gl.TEXTURE_2D, fbtex, 0);
michael@0 129 glErrorShouldBe(gl, gl.INVALID_ENUM,
michael@0 130 "calling framebufferTexImage2D with attachment = COLOR_ATTACHMENT1 should generate INVALID_ENUM.");
michael@0 131 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment, gl.RENDERBUFFER, rb);
michael@0 132 glErrorShouldBe(gl, gl.INVALID_ENUM,
michael@0 133 "calling framebufferRenderbuffer with attachment = COLOR_ATTACHMENT1 should generate INVALID_ENUM.");
michael@0 134
michael@0 135 gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER,
michael@0 136 gl.COLOR_ATTACHMENT0,
michael@0 137 desktopGL.FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING);
michael@0 138 glErrorShouldBe(gl, gl.INVALID_ENUM,
michael@0 139 "calling getFramebufferAttachmentParameter with pname = GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING should generate INVALID_ENUM.");
michael@0 140
michael@0 141 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, fbtex, 0);
michael@0 142 glErrorShouldBe(gl, gl.NO_ERROR,
michael@0 143 "attaching a texture to a framebuffer should succeed.");
michael@0 144
michael@0 145 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, null, 0);
michael@0 146 glErrorShouldBe(gl, gl.NO_ERROR,
michael@0 147 "detaching a texture from a framebuffer should succeed.");
michael@0 148
michael@0 149 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, fbtex, 1);
michael@0 150 glErrorShouldBe(gl, gl.INVALID_VALUE,
michael@0 151 "calling framebufferTexture2D with non-zero mipmap level should generate INVALID_VALUE.");
michael@0 152
michael@0 153 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, rb);
michael@0 154 glErrorShouldBe(gl, gl.NO_ERROR,
michael@0 155 "attaching a renderbuffer to a framebuffer should succeed.");
michael@0 156
michael@0 157 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, null);
michael@0 158 glErrorShouldBe(gl, gl.NO_ERROR,
michael@0 159 "detaching a renderbuffer from a framebuffer should succeed.");
michael@0 160
michael@0 161 gl.bindFramebuffer(gl.FRAMEBUFFER, null);
michael@0 162 glErrorShouldBe(gl, gl.NO_ERROR,
michael@0 163 "binding default (null) framebuffer should succeed.");
michael@0 164 }
michael@0 165
michael@0 166 debug("");
michael@0 167 successfullyParsed = true;
michael@0 168
michael@0 169 </script>
michael@0 170 <script>finishTest();</script>
michael@0 171
michael@0 172 </body>
michael@0 173 </html>

mercurial