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

Side by Side Diff: conformance/textures/texture-active-bind.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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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 ActiveTexture BindTexture conformance 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/webgl-test-utils.js"></script>
15 </head>
16 <body>
17 <canvas id="example" width="2" height="2" style="width: 40px; height: 40px;"></c anvas>
18 <canvas id="canvas2d" width="1" height="1" style="width: 40px; height: 40px;"></ canvas>
19 <div id="description"></div>
20 <div id="console"></div>
21 <script id="vshader" type="x-shader/x-vertex">
22 uniform mat4 world;
23 attribute vec3 vPosition;
24 attribute vec2 texCoord0;
25 varying vec2 texCoord;
26 void main()
27 {
28 gl_Position = world * vec4(vPosition, 1);
29 texCoord = texCoord0;
30 }
31 </script>
32 <script>
33 var gl;
34
35 function init()
36 {
37 if (window.initNonKhronosFramework) {
38 window.initNonKhronosFramework(false);
39 }
40
41 debug("Tests that glActiveTexture and glBindTexture work as expected");
42 debug("Specifically texture targets are per active texture unit.");
43 debug("");
44
45 var canvas2d = document.getElementById("canvas2d");
46 var ctx2d = canvas2d.getContext("2d");
47
48 var wtu = WebGLTestUtils;
49 var canvas = document.getElementById("example");
50 gl = wtu.create3DContext(canvas);
51 var program = wtu.setupProgram(
52 gl,
53 [wtu.loadShaderFromScript(gl, "vshader"),
54 wtu.setupSimpleTextureFragmentShader(gl)],
55 ['vPosition', 'texCoord0']);
56 wtu.setupUnitQuad(gl);
57 gl.disable(gl.DEPTH_TEST);
58 gl.disable(gl.BLEND);
59 glErrorShouldBe(gl, gl.NO_ERROR);
60
61 var colors = [
62 [0,192,128,255],
63 [128,64,255,255],
64 [192,255,64,255],
65 [200,0,255,255]];
66
67 // Make 4 textures by using 4 active texture units if available.
68 var texunits = Math.min(colors.length, gl.getParameter(gl.MAX_COMBINED_TEXTURE _IMAGE_UNITS))
69 var textures = [];
70 for (var ii = 0; ii < texunits; ++ii) {
71 var tex = gl.createTexture();
72 gl.activeTexture(gl.TEXTURE0 + ii);
73 gl.bindTexture(gl.TEXTURE_2D, tex);
74 textures[ii] = tex;
75 }
76 glErrorShouldBe(gl, gl.NO_ERROR);
77
78 // now use each texture unit to write into the textures,
79 for (var ii = 0; ii < texunits; ++ii) {
80 var c = colors[ii];
81 ctx2d.fillStyle =
82 "rgba(" + c[0] + "," + c[1] + "," + c[2] + "," + c[3] + ")";
83 ctx2d.fillRect(0, 0, 1, 1);
84 gl.activeTexture(gl.TEXTURE0 + ii);
85 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2d );
86 }
87 glErrorShouldBe(gl, gl.NO_ERROR);
88
89 var textureLoc = gl.getUniformLocation(program, "tex");
90 var worldLoc = gl.getUniformLocation(program, "world");
91 glErrorShouldBe(gl, gl.NO_ERROR);
92
93 gl.clearColor(1,0,0,1);
94 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
95
96 for (var ii = 0; ii < texunits; ++ii) {
97 var x = ii % 2;
98 var y = Math.floor(ii / 2);
99 gl.uniform1i(textureLoc, ii);
100 gl.uniformMatrix4fv(
101 worldLoc, false,
102 [0.5, 0, 0, 0,
103 0, 0.5, 0, 0,
104 0, 0, 1, 0,
105 -0.5 + x, -0.5 + y, 0, 1]);
106 gl.drawArrays(gl.TRIANGLES, 0, 6);
107 }
108 glErrorShouldBe(gl, gl.NO_ERROR);
109
110 for (var ii = 0; ii < texunits; ++ii) {
111 var c = colors[ii];
112 var x = ii % 2;
113 var y = Math.floor(ii / 2);
114 var buf = new Uint8Array(4);
115 gl.readPixels(x, y, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, buf);
116 var msg = 'expected:' +
117 c[0] + ', ' + c[1] + ', ' + c[2] + ', ' + c[3] + ' found: ' +
118 buf[0] + ', ' +
119 buf[1] + ', ' +
120 buf[2] + ', ' +
121 buf[3];
122 if (buf[0] != c[0] ||
123 buf[1] != c[1] ||
124 buf[2] != c[2] ||
125 buf[3] != c[3])
126 testFailed(msg);
127 else
128 testPassed(msg);
129 }
130 }
131
132 init();
133 successfullyParsed = true;
134 </script>
135
136 <script src="../../resources/js-test-post.js"></script>
137
138 </body>
139 </html>
140
OLDNEW
« no previous file with comments | « conformance/textures/texparameter-test.html ('k') | conformance/textures/texture-active-bind-2.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698