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