1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
2 "http://www.w3.org/TR/html4/loose.dtd">
5 <meta http-equiv=
"Content-Type" content=
"text/html; charset=utf-8">
6 <title>WebGL Framebuffer Test
</title>
7 <script src=
"../../../resources/js-test.js"></script>
8 <script src=
"resources/webgl-test.js"></script>
11 <div id=
"description"></div>
12 <div id=
"console"></div>
13 <canvas id=
"canvas" width=
"2" height=
"2"> </canvas>
15 description("This tests framebuffer/renderbuffer-related functions");
18 debug("Canvas.getContext");
21 window
.internals
.settings
.setWebGLErrorsToConsoleEnabled(false);
23 var canvas
= document
.getElementById("canvas");
24 var gl
= create3DContext(canvas
);
26 testFailed("context does not exist");
28 testPassed("context exists");
31 debug("Checking framebuffer/renderbuffer stuff.");
33 var value
= gl
.getFramebufferAttachmentParameter(
36 gl
.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
);
37 assertMsg(gl
.getError() == gl
.INVALID_OPERATION
,
38 "calling getFramebufferAttachmentParameter on the default framebuffer should generate INVALID_OPERATION.");
40 assertMsg(gl
.checkFramebufferStatus(gl
.FRAMEBUFFER
) == gl
.FRAMEBUFFER_COMPLETE
,
41 "calling checkFramebufferStatus on the default framebuffer should generate FRAMEBUFFER_COMPLETE.");
43 var tex
= gl
.createTexture();
44 gl
.bindTexture(gl
.TEXTURE_2D
, tex
);
45 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MIN_FILTER
, gl
.NEAREST
);
46 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MAG_FILTER
, gl
.NEAREST
);
47 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_WRAP_S
, gl
.CLAMP_TO_EDGE
);
48 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_WRAP_T
, gl
.CLAMP_TO_EDGE
);
49 gl
.texImage2D(gl
.TEXTURE_2D
,
51 gl
.RGBA
, // internalFormat
52 canvas
.width
, // width
53 canvas
.height
, // height
56 gl
.UNSIGNED_BYTE
, // type
58 gl
.framebufferTexture2D(
64 assertMsg(gl
.getError() == gl
.INVALID_OPERATION
,
65 "trying to attach a texture to default framebuffer should generate INVALID_OPERATION.");
67 gl
.framebufferRenderbuffer(
72 assertMsg(gl
.getError() == gl
.INVALID_OPERATION
,
73 "trying to detach default renderbuffer from default framebuffer should generate INVALID_OPERATION.");
75 var rb
= gl
.createRenderbuffer();
76 gl
.bindRenderbuffer(gl
.RENDERBUFFER
, rb
);
77 gl
.renderbufferStorage(gl
.RENDERBUFFER
, gl
.RGBA4
, canvas
.width
, canvas
.height
);
78 assertMsg(gl
.getError() == gl
.NO_ERROR
,
79 "allocating renderbuffer storage of a newly created renderbuffer should succeed.");
81 gl
.framebufferRenderbuffer(
86 assertMsg(gl
.getError() == gl
.INVALID_OPERATION
,
87 "trying to attach a renderbuffer to the default framebuffer should generate INVALID_OPERATION.");
89 var fbtex
= gl
.createTexture();
90 gl
.bindTexture(gl
.TEXTURE_2D
, fbtex
);
91 gl
.texImage2D(gl
.TEXTURE_2D
, 0, gl
.RGBA
, canvas
.width
, canvas
.height
, 0, gl
.RGBA
, gl
.UNSIGNED_BYTE
, null);
92 var fb
= gl
.createFramebuffer();
94 gl
.bindFramebuffer(gl
.FRAMEBUFFER
, fb
);
95 assertMsg(gl
.getError() == gl
.NO_ERROR
,
96 "binding a newly created framebuffer should succeed.");
98 var target
= 0x8CA8; // GL_READ_FRAMEBUFFER
99 gl
.getFramebufferAttachmentParameter(
101 gl
.COLOR_ATTACHMENT0
,
102 gl
.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
);
103 assertMsg(gl
.getError() == gl
.INVALID_ENUM
,
104 "calling getFramebufferAttachmentParameter with target = READ_FRAMEBUFFER should generate INVALID_ENUM.");
105 assertMsg(gl
.checkFramebufferStatus(target
) == 0,
106 "calling checkFramebufferStatus with target = READ_FRAMEBUFFER should return 0.");
107 assertMsg(gl
.getError() == gl
.INVALID_ENUM
,
108 "calling checkFramebufferStatus with target = READ_FRAMEBUFFER should generate INVALID_ENUM.");
109 gl
.bindFramebuffer(target
, gl
.createFramebuffer());
110 assertMsg(gl
.getError() == gl
.INVALID_ENUM
,
111 "calling bindFramebuffer with target = READ_FRAMEBUFFER should generate INVALID_ENUM.");
112 assertMsg(fb
== gl
.getParameter(gl
.FRAMEBUFFER_BINDING
),
113 "calling bindFramebuffer with target = READ_FRAMEBUFFER should not change FRAMEBUFFER_BINDING.");
114 gl
.getFramebufferAttachmentParameter(target
, gl
.COLOR_ATTACHMENT0
, gl
.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
);
115 assertMsg(gl
.getError() == gl
.INVALID_ENUM
,
116 "calling getFramebufferAttachmentParameter with target = READ_FRAMEBUFFER should generate INVALID_ENUM.");
117 gl
.framebufferTexture2D(target
, gl
.COLOR_ATTACHMENT0
, gl
.TEXTURE_2D
, fbtex
, 0);
118 assertMsg(gl
.getError() == gl
.INVALID_ENUM
,
119 "calling framebufferTexImage2D with target = READ_FRAMEBUFFER should generate INVALID_ENUM.");
120 gl
.framebufferRenderbuffer(target
, gl
.COLOR_ATTACHMENT0
, gl
.RENDERBUFFER
, rb
);
121 assertMsg(gl
.getError() == gl
.INVALID_ENUM
,
122 "calling framebufferRenderbuffer with target = READ_FRAMEBUFFER should generate INVALID_ENUM.");
124 var attachment
= 0x8CE1; // GL_COLOR_ATTACHMENT1
125 gl
.framebufferTexture2D(gl
.FRAMEBUFFER
, attachment
, gl
.TEXTURE_2D
, fbtex
, 0);
126 assertMsg(gl
.getError() == gl
.INVALID_ENUM
,
127 "calling framebufferTexImage2D with attachment = COLOR_ATTACHMENT1 should generate INVALID_ENUM.");
128 gl
.framebufferRenderbuffer(gl
.FRAMEBUFFER
, attachment
, gl
.RENDERBUFFER
, rb
);
129 assertMsg(gl
.getError() == gl
.INVALID_ENUM
,
130 "calling framebufferRenderbuffer with attachment = COLOR_ATTACHMENT1 should generate INVALID_ENUM.");
132 gl
.getFramebufferAttachmentParameter(gl
.FRAMEBUFFER
,
133 gl
.COLOR_ATTACHMENT0
,
134 0x8210); // GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
135 assertMsg(gl
.getError() == gl
.INVALID_ENUM
,
136 "calling getFramebufferAttachmentParameter with pname = GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING should generate INVALID_ENUM.");
138 gl
.framebufferTexture2D(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, gl
.TEXTURE_2D
, fbtex
, 0);
139 assertMsg(gl
.getError() == gl
.NO_ERROR
,
140 "attaching a texture to a framebuffer should succeed.");
142 gl
.framebufferTexture2D(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, gl
.TEXTURE_2D
, null, 0);
143 assertMsg(gl
.getError() == gl
.NO_ERROR
,
144 "detaching a texture from a framebuffer should succeed.");
146 gl
.framebufferTexture2D(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, gl
.TEXTURE_2D
, fbtex
, 1);
147 assertMsg(gl
.getError() == gl
.INVALID_VALUE
,
148 "calling framebufferTexture2D with non-zero mipmap level should generate INVALID_VALUE.");
150 gl
.framebufferRenderbuffer(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, gl
.RENDERBUFFER
, rb
);
151 assertMsg(gl
.getError() == gl
.NO_ERROR
,
152 "attaching a renderbuffer to a framebuffer should succeed.");
154 gl
.framebufferRenderbuffer(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, gl
.RENDERBUFFER
, null);
155 assertMsg(gl
.getError() == gl
.NO_ERROR
,
156 "detaching a renderbuffer from a framebuffer should succeed.");
158 gl
.bindFramebuffer(gl
.FRAMEBUFFER
, null);
159 assertMsg(gl
.getError() == gl
.NO_ERROR
,
160 "binding default (null) framebuffer should succeed.");