OLD | NEW |
| (Empty) |
1 <!-- | |
2 Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
3 Use of this source code is governed by a BSD-style license that can be | |
4 found in the LICENSE file. | |
5 --> | |
6 <!DOCTYPE html> | |
7 <html> | |
8 <head> | |
9 <meta charset="utf-8"> | |
10 <title>WebGL Framebuffer Test</title> | |
11 <link rel="stylesheet" href="../../resources/js-test-style.css"/> | |
12 <script src="../../resources/js-test-pre.js"></script> | |
13 <script src="../resources/webgl-test.js"></script> | |
14 </head> | |
15 <body> | |
16 <div id="description"></div> | |
17 <div id="console"></div> | |
18 <canvas id="canvas" width="2" height="2"> </canvas> | |
19 <script> | |
20 description("This tests framebuffer/renderbuffer-related functions"); | |
21 | |
22 debug(""); | |
23 debug("Canvas.getContext"); | |
24 | |
25 var canvas = document.getElementById("canvas"); | |
26 var gl = create3DContext(canvas); | |
27 if (!gl) { | |
28 testFailed("context does not exist"); | |
29 } else { | |
30 testPassed("context exists"); | |
31 | |
32 debug(""); | |
33 debug("Checking framebuffer/renderbuffer stuff."); | |
34 | |
35 var value = gl.getFramebufferAttachmentParameter( | |
36 gl.FRAMEBUFFER, | |
37 gl.COLOR_ATTACHMENT0, | |
38 gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE); | |
39 glErrorShouldBe(gl, gl.INVALID_OPERATION, | |
40 "calling getFramebufferAttachmentParameter on the default framebuffe
r should generate INVALID_OPERATION."); | |
41 | |
42 assertMsg(gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE
, | |
43 "calling checkFramebufferStatus on the default framebuffer should ge
nerate FRAMEBUFFER_COMPLETE."); | |
44 | |
45 var tex = gl.createTexture(); | |
46 gl.bindTexture(gl.TEXTURE_2D, tex); | |
47 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); | |
48 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); | |
49 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); | |
50 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); | |
51 gl.texImage2D(gl.TEXTURE_2D, | |
52 0, // level | |
53 gl.RGBA, // internalFormat | |
54 canvas.width, // width | |
55 canvas.height, // height | |
56 0, // border | |
57 gl.RGBA, // format | |
58 gl.UNSIGNED_BYTE, // type | |
59 null); // data | |
60 gl.framebufferTexture2D( | |
61 gl.FRAMEBUFFER, | |
62 gl.COLOR_ATTACHMENT0, | |
63 gl.TEXTURE_2D, | |
64 tex, | |
65 0); | |
66 glErrorShouldBe(gl, gl.INVALID_OPERATION, | |
67 "trying to attach a texture to default framebuffer should generate I
NVALID_OPERATION."); | |
68 | |
69 gl.framebufferRenderbuffer( | |
70 gl.FRAMEBUFFER, | |
71 gl.COLOR_ATTACHMENT0, | |
72 gl.RENDERBUFFER, | |
73 null); | |
74 glErrorShouldBe(gl, gl.INVALID_OPERATION, | |
75 "trying to detach default renderbuffer from default framebuffer shou
ld generate INVALID_OPERATION."); | |
76 | |
77 var rb = gl.createRenderbuffer(); | |
78 gl.bindRenderbuffer(gl.RENDERBUFFER, rb); | |
79 gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, canvas.width, canvas.height)
; | |
80 glErrorShouldBe(gl, gl.NO_ERROR, | |
81 "allocating renderbuffer storage of a newly created renderbuffer sho
uld succeed."); | |
82 | |
83 gl.framebufferRenderbuffer( | |
84 gl.FRAMEBUFFER, | |
85 gl.COLOR_ATTACHMENT0, | |
86 gl.RENDERBUFFER, | |
87 rb); | |
88 glErrorShouldBe(gl, gl.INVALID_OPERATION, | |
89 "trying to attach a renderbuffer to the default framebuffer should g
enerate INVALID_OPERATION."); | |
90 | |
91 var fbtex = gl.createTexture(); | |
92 gl.bindTexture(gl.TEXTURE_2D, fbtex); | |
93 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, canvas.width, canvas.height, 0, gl.RG
BA, gl.UNSIGNED_BYTE, null); | |
94 var fb = gl.createFramebuffer(); | |
95 | |
96 gl.bindFramebuffer(gl.FRAMEBUFFER, fb); | |
97 glErrorShouldBe(gl, gl.NO_ERROR, | |
98 "binding a newly created framebuffer should succeed."); | |
99 | |
100 var target = 0x8CA8; // GL_READ_FRAMEBUFFER | |
101 gl.getFramebufferAttachmentParameter( | |
102 target, | |
103 gl.COLOR_ATTACHMENT0, | |
104 gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE); | |
105 glErrorShouldBe(gl, gl.INVALID_ENUM, | |
106 "calling getFramebufferAttachmentParameter with target = READ_FRAMEB
UFFER should generate INVALID_ENUM."); | |
107 assertMsg(gl.checkFramebufferStatus(target) == 0, | |
108 "calling checkFramebufferStatus with target = READ_FRAMEBUFFER shoul
d return 0."); | |
109 glErrorShouldBe(gl, gl.INVALID_ENUM, | |
110 "calling checkFramebufferStatus with target = READ_FRAMEBUFFER shoul
d generate INVALID_ENUM."); | |
111 gl.bindFramebuffer(target, gl.createFramebuffer()); | |
112 glErrorShouldBe(gl, gl.INVALID_ENUM, | |
113 "calling bindFramebuffer with target = READ_FRAMEBUFFER should gener
ate INVALID_ENUM."); | |
114 assertMsg(fb == gl.getParameter(gl.FRAMEBUFFER_BINDING), | |
115 "calling bindFramebuffer with target = READ_FRAMEBUFFER should not c
hange FRAMEBUFFER_BINDING."); | |
116 gl.getFramebufferAttachmentParameter(target, gl.COLOR_ATTACHMENT0, gl.FRAMEBUF
FER_ATTACHMENT_OBJECT_TYPE); | |
117 glErrorShouldBe(gl, gl.INVALID_ENUM, | |
118 "calling getFramebufferAttachmentParameter with target = READ_FRAMEB
UFFER should generate INVALID_ENUM."); | |
119 gl.framebufferTexture2D(target, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, fbtex, 0)
; | |
120 glErrorShouldBe(gl, gl.INVALID_ENUM, | |
121 "calling framebufferTexImage2D with target = READ_FRAMEBUFFER should
generate INVALID_ENUM."); | |
122 gl.framebufferRenderbuffer(target, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, rb); | |
123 glErrorShouldBe(gl, gl.INVALID_ENUM, | |
124 "calling framebufferRenderbuffer with target = READ_FRAMEBUFFER shou
ld generate INVALID_ENUM."); | |
125 | |
126 var attachment = 0x8CE1; // GL_COLOR_ATTACHMENT1 | |
127 gl.framebufferTexture2D(gl.FRAMEBUFFER, attachment, gl.TEXTURE_2D, fbtex, 0); | |
128 glErrorShouldBe(gl, gl.INVALID_ENUM, | |
129 "calling framebufferTexImage2D with attachment = COLOR_ATTACHMENT1 s
hould generate INVALID_ENUM."); | |
130 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment, gl.RENDERBUFFER, rb); | |
131 glErrorShouldBe(gl, gl.INVALID_ENUM, | |
132 "calling framebufferRenderbuffer with attachment = COLOR_ATTACHMENT1
should generate INVALID_ENUM."); | |
133 | |
134 gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, | |
135 gl.COLOR_ATTACHMENT0, | |
136 0x8210); // GL_FRAMEBUFFER_ATTACHMENT_COL
OR_ENCODING | |
137 glErrorShouldBe(gl, gl.INVALID_ENUM, | |
138 "calling getFramebufferAttachmentParameter with pname = GL_FRAMEBUFF
ER_ATTACHMENT_COLOR_ENCODING should generate INVALID_ENUM."); | |
139 | |
140 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, f
btex, 0); | |
141 glErrorShouldBe(gl, gl.NO_ERROR, | |
142 "attaching a texture to a framebuffer should succeed."); | |
143 | |
144 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, n
ull, 0); | |
145 glErrorShouldBe(gl, gl.NO_ERROR, | |
146 "detaching a texture from a framebuffer should succeed."); | |
147 | |
148 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, f
btex, 1); | |
149 glErrorShouldBe(gl, gl.INVALID_VALUE, | |
150 "calling framebufferTexture2D with non-zero mipmap level should gene
rate INVALID_VALUE."); | |
151 | |
152 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFF
ER, rb); | |
153 glErrorShouldBe(gl, gl.NO_ERROR, | |
154 "attaching a renderbuffer to a framebuffer should succeed."); | |
155 | |
156 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFF
ER, null); | |
157 glErrorShouldBe(gl, gl.NO_ERROR, | |
158 "detaching a renderbuffer from a framebuffer should succeed."); | |
159 | |
160 gl.bindFramebuffer(gl.FRAMEBUFFER, null); | |
161 glErrorShouldBe(gl, gl.NO_ERROR, | |
162 "binding default (null) framebuffer should succeed."); | |
163 } | |
164 | |
165 debug(""); | |
166 successfullyParsed = true; | |
167 | |
168 </script> | |
169 <script src="../../resources/js-test-post.js"></script> | |
170 | |
171 </body> | |
172 </html> | |
OLD | NEW |