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

Side by Side Diff: conformance/textures/tex-image-and-sub-image-2d-with-canvas.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 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
11 <script src="../../resources/js-test-pre.js"></script>
12 <script src="../resources/webgl-test.js"></script>
13 <script src="../resources/webgl-test-utils.js"></script>
14 <script>
15 var wtu = WebGLTestUtils;
16 var gl = null;
17 var textureLoc = null;
18 var successfullyParsed = false;
19
20 function init()
21 {
22 if (window.initNonKhronosFramework) {
23 window.initNonKhronosFramework(true);
24 }
25
26 description('Verify texImage2D and texSubImage2D code paths taking Images');
27
28 var canvas = document.getElementById("example");
29 gl = wtu.create3DContext(canvas);
30 var program = wtu.setupTexturedQuad(gl);
31
32 gl.clearColor(0,0,0,1);
33 gl.clearDepth(1);
34
35 var testCanvas = document.createElement('canvas');
36 testCanvas.width = 1;
37 testCanvas.height = 2;
38 var ctx = testCanvas.getContext("2d");
39 ctx.fillStyle = "#ff0000";
40 ctx.fillRect(0,0,1,1);
41 ctx.fillStyle = "#00ff00";
42 ctx.fillRect(0,1,1,1);
43 runTest(testCanvas);
44 }
45
46 // These two declarations need to be global for "shouldBe" to see them
47 var buf = null;
48 var idx = 0;
49 var pixel = [0, 0, 0];
50 var correctColor = null;
51
52 function runOneIteration(image, useTexSubImage2D, flipY, topColor, bottomColor)
53 {
54 debug('Testing ' + (useTexSubImage2D ? 'texSubImage2D' : 'texImage2D') +
55 ' with flipY=' + flipY);
56 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
57 // Disable any writes to the alpha channel
58 gl.colorMask(1, 1, 1, 0);
59 var texture = gl.createTexture();
60 // Bind the texture to texture unit 0
61 gl.bindTexture(gl.TEXTURE_2D, texture);
62 // Set up texture parameters
63 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
64 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
65 // Set up pixel store parameters
66 gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY);
67 gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
68 gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE);
69 // Upload the image into the texture
70 if (useTexSubImage2D) {
71 // Initialize the texture to black first
72 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, image.width, image.height, 0,
73 gl.RGBA, gl.UNSIGNED_BYTE, null);
74 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, imag e);
75 } else {
76 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, imag e);
77 }
78
79 // Point the uniform sampler to texture unit 0
80 gl.uniform1i(textureLoc, 0);
81 // Draw the triangles
82 wtu.drawQuad(gl, [0, 0, 0, 255]);
83 // Check a few pixels near the top and bottom and make sure they have
84 // the right color.
85 debug("Checking lower left corner");
86 wtu.checkCanvasRect(gl, 4, 4, 2, 2, bottomColor,
87 "shouldBe " + bottomColor);
88 debug("Checking upper left corner");
89 wtu.checkCanvasRect(gl, 4, gl.canvas.height - 8, 2, 2, topColor,
90 "shouldBe " + topColor);
91 }
92
93 function runTest(image)
94 {
95 var red = [255, 0, 0];
96 var green = [0, 255, 0];
97 runOneIteration(image, false, true, red, green);
98 runOneIteration(image, false, false, green, red);
99 runOneIteration(image, true, true, red, green);
100 runOneIteration(image, true, false, green, red);
101
102 glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors");
103 finishTest();
104 }
105
106 </script>
107 </head>
108 <body onload="init()">
109 <canvas id="example" width="32px" height="32px"></canvas>
110 <div id="description"></div>
111 <div id="console"></div>
112 </body>
113 </html>
114
115
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698