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

Side by Side Diff: third_party/webgl/sdk/tests/conformance/resources/tex-image-and-sub-image-2d-with-canvas.js

Issue 10399113: Roll webgl conformance tests to r17874: part 2, adding r17874 (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/
Patch Set: Created 8 years, 7 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) 2012 The Khronos Group Inc.
3 **
4 ** Permission is hereby granted, free of charge, to any person obtaining a
5 ** copy of this software and/or associated documentation files (the
6 ** "Materials"), to deal in the Materials without restriction, including
7 ** without limitation the rights to use, copy, modify, merge, publish,
8 ** distribute, sublicense, and/or sell copies of the Materials, and to
9 ** permit persons to whom the Materials are furnished to do so, subject to
10 ** the following conditions:
11 **
12 ** The above copyright notice and this permission notice shall be included
13 ** in all copies or substantial portions of the Materials.
14 **
15 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
22 */
23
24 function generateTest(pixelFormat, pixelType, prologue) {
25 var wtu = WebGLTestUtils;
26 var gl = null;
27 var textureLoc = null;
28 var successfullyParsed = false;
29
30 var init = function()
31 {
32 if (window.initNonKhronosFramework) {
33 window.initNonKhronosFramework(true);
34 }
35
36 description('Verify texImage2D and texSubImage2D code paths taking canva s elements (' + pixelFormat + '/' + pixelType + ')');
37
38 gl = wtu.create3DContext("example");
39
40 if (!prologue(gl)) {
41 finishTest();
42 return;
43 }
44
45 var program = wtu.setupTexturedQuad(gl);
46
47 gl.clearColor(0,0,0,1);
48 gl.clearDepth(1);
49
50 var testCanvas = document.createElement('canvas');
51 testCanvas.width = 1;
52 testCanvas.height = 2;
53 var ctx = testCanvas.getContext("2d");
54 ctx.fillStyle = "#ff0000";
55 ctx.fillRect(0,0,1,1);
56 ctx.fillStyle = "#00ff00";
57 ctx.fillRect(0,1,1,1);
58 runTest(testCanvas);
59 }
60
61 function runOneIteration(image, useTexSubImage2D, flipY, topColor, bottomCol or)
62 {
63 debug('Testing ' + (useTexSubImage2D ? 'texSubImage2D' : 'texImage2D') +
64 ' with flipY=' + flipY);
65 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
66 // Disable any writes to the alpha channel
67 gl.colorMask(1, 1, 1, 0);
68 var texture = gl.createTexture();
69 // Bind the texture to texture unit 0
70 gl.bindTexture(gl.TEXTURE_2D, texture);
71 // Set up texture parameters
72 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
73 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
74 // Set up pixel store parameters
75 gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY);
76 gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
77 gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE);
78 // Upload the image into the texture
79 if (useTexSubImage2D) {
80 // Initialize the texture to black first
81 gl.texImage2D(gl.TEXTURE_2D, 0, gl[pixelFormat], image.width, image. height, 0,
82 gl[pixelFormat], gl[pixelType], null);
83 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl[pixelFormat], gl[pixelTy pe], image);
84 } else {
85 gl.texImage2D(gl.TEXTURE_2D, 0, gl[pixelFormat], gl[pixelFormat], gl [pixelType], image);
86 }
87
88 // Point the uniform sampler to texture unit 0
89 gl.uniform1i(textureLoc, 0);
90 // Draw the triangles
91 wtu.drawQuad(gl, [0, 0, 0, 255]);
92 // Check a few pixels near the top and bottom and make sure they have
93 // the right color.
94 debug("Checking lower left corner");
95 wtu.checkCanvasRect(gl, 4, 4, 2, 2, bottomColor,
96 "shouldBe " + bottomColor);
97 debug("Checking upper left corner");
98 wtu.checkCanvasRect(gl, 4, gl.canvas.height - 8, 2, 2, topColor,
99 "shouldBe " + topColor);
100 }
101
102 function runTest(image)
103 {
104 var red = [255, 0, 0];
105 var green = [0, 255, 0];
106 runOneIteration(image, false, true, red, green);
107 runOneIteration(image, false, false, green, red);
108 runOneIteration(image, true, true, red, green);
109 runOneIteration(image, true, false, green, red);
110
111 glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors");
112 finishTest();
113 }
114
115 return init;
116 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698