Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: extra/fbo-lost-context.html

Issue 8342021: Add webgl conformance tests r15841. (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/webgl/sdk/tests/
Patch Set: Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « extra/canvas-compositing-test.png ('k') | extra/lots-of-polys-example.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 <!--
2 Copyright (c) 2009 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 PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
7 "http://www.w3.org/TR/html4/loose.dtd">
8 <html>
9 <head>
10 <meta charset="utf-8">
11 <title>WebGL FBO Lost Context Test</title>
12 <link rel="stylesheet" href="../resources/js-test-style.css"/>
13 <script src="../resources/desktop-gl-constants.js" type="text/javascript"></scri pt>
14 <script src="../../debug/webgl-debug.js"></script>
15 <script src="../resources/js-test-pre.js"></script>
16 <script src="../conformance/resources/webgl-test.js"></script>
17 </head>
18 <body>
19 <div id="description"></div>
20 <div id="console"></div>
21 <script id="vshader" type="x-shader/x-vertex">
22 attribute vec4 vPosition;
23 attribute vec2 texCoord0;
24 uniform mat4 world;
25 varying vec2 texCoord;
26 void main()
27 {
28 gl_Position = vPosition * world;
29 texCoord = texCoord0;
30 }
31 </script>
32
33 <script id="fshader" type="x-shader/x-fragment">
34 precision mediump float;
35 uniform sampler2D tex;
36 varying vec2 texCoord;
37 void main()
38 {
39 gl_FragColor = texture2D(tex, texCoord);
40 }
41 </script>
42 <canvas id="canvas" width="1024" height="1024"> </canvas>
43 <script>
44 description("This test is to help see if an WebGL app *can* get lost context.");
45
46 debug("");
47 debug("Canvas.getContext");
48 var g_worldLoc;
49 var g_texLoc;
50 var g_textures = [];
51 gl = initWebGL("canvas", "vshader", "fshader", [ "vPosition", "texCoord0"], [ 0, 0, 0, 1 ], 1);
52 if (!gl) {
53 testFailed("context does not exist");
54 } else {
55 testPassed("context exists");
56
57 debug("");
58 debug("Checking for out of memory handling.");
59
60 var size = gl.getParameter(gl.MAX_RENDERBUFFER_SIZE);
61 debug("max render buffer size: " + size);
62 size = size / 2;
63 debug("size used: " + size);
64
65 var allocateFramebuffers = true;
66 var itervalId;
67 var count = 0;
68
69 gl = WebGLDebugUtils.makeDebugContext(gl, function(err, functionName, args) {
70 window.clearInterval(intervalId);
71 assertMsg(err == gl.OUT_OF_MEMORY,
72 "correctly returns gl.OUT_OF_MEMORY when out of memory");
73 finish();
74 });
75
76 function createFBO() {
77 var tex = gl.createTexture();
78 gl.bindTexture(gl.TEXTURE_2D, tex);
79 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
80 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
81 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
82 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
83 gl.texImage2D(gl.TEXTURE_2D,
84 0, // level
85 gl.RGBA, // internalFormat
86 size, // width
87 size, // height
88 0, // border
89 gl.RGBA, // format
90 gl.UNSIGNED_BYTE, // type
91 null); // data
92 var fb = gl.createFramebuffer();
93 gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
94 gl.framebufferTexture2D(
95 gl.FRAMEBUFFER,
96 gl.COLOR_ATTACHMENT0,
97 gl.TEXTURE_2D,
98 tex,
99 0);
100 var status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
101 if (status != gl.FRAMEBUFFER_COMPLETE) {
102 testFailed("gl.checkFramebufferStatus() returned " + WebGLDebugUtils.glEnu mToString(status));
103 }
104 return { fb: fb, tex: tex };
105 }
106
107 gl.disable(gl.DEPTH_TEST);
108
109 var numFBOs = 32;
110 for (var ii = 0; ii < numFBOs; ++ii) {
111 createFBO();
112 var t = createFBO();
113 tex = t.tex;
114 fb = t.fb;
115
116 gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
117 gl.scissor(0, 0, size, size);
118 gl.clearColor(0, ii / numFBOs, 1 - ii / numFBOs, 1);
119 gl.clear(gl.COLOR_BUFFER_BIT);
120 g_textures.push(tex);
121 }
122
123 gl.bindFramebuffer(gl.FRAMEBUFFER, null);
124
125 var vertexObject = gl.createBuffer();
126 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
127 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
128 -1,1,0, 1,1,0, -1,-1,0,
129 -1,-1,0, 1,1,0, 1,-1,0
130 ]), gl.STATIC_DRAW);
131 gl.enableVertexAttribArray(0);
132 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
133
134 var vertexObject = gl.createBuffer();
135 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
136 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
137 0,0, 1,0, 0,1,
138 0,1, 1,0, 1,1
139 ]), gl.STATIC_DRAW);
140 gl.enableVertexAttribArray(1);
141 gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 0, 0);
142
143 gl.bindTexture(gl.TEXTURE_2D, tex);
144 g_texLoc = gl.getUniformLocation(gl.program, "tex");
145 gl.uniform1i(g_texLoc, 0);
146 g_worldLoc = gl.getUniformLocation(gl.program, "world");
147 gl.uniformMatrix4fv(g_worldLoc, false, [
148 0, 0, 0, 0,
149 0, 0, 0, 0,
150 0, 0, 1, 0,
151 0, 0, 0, 1]);
152
153 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
154 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
155 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
156
157 setInterval(render, 1000/60);
158 }
159
160 var g_angle = 0;
161 var g_texIndex = 0;
162 function render() {
163 g_angle += 0.1;
164 g_texIndex++;
165 if (g_texIndex >= g_textures.length) {
166 g_texIndex = 0;
167 }
168 gl.bindTexture(gl.TEXTURE_2D, g_textures[g_texIndex]);
169 gl.uniformMatrix4fv(g_worldLoc, false, rotationZ(g_angle));
170 gl.clearColor(1,0,0,1);
171 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
172 gl.drawArrays(gl.TRIANGLES, 0, 6);
173 }
174
175 /**
176 * Creates a 4-by-4 matrix which rotates around the z-axis by the given angle.
177 * @param {number} angle The angle by which to rotate (in radians).
178 * @return {!o3djs.math.Matrix4} The rotation matrix.
179 */
180 function rotationZ(angle) {
181 var c = Math.cos(angle);
182 var s = Math.sin(angle);
183
184 return [
185 c, s, 0, 0,
186 -s, c, 0, 0,
187 0, 0, 1, 0,
188 0, 0, 0, 1
189 ];
190 };
191
192 debug("");
193 successfullyParsed = true;
194 </script>
195 <script>
196 </script>
197
198 </body>
199 </html>
OLDNEW
« no previous file with comments | « extra/canvas-compositing-test.png ('k') | extra/lots-of-polys-example.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698