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

Side by Side Diff: third_party/webgl/sdk/tests/conformance/resources/tex-image-and-sub-image-2d-with-image-data.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 var imageData = null;
30
31 var init = function()
32 {
33 if (window.initNonKhronosFramework) {
34 window.initNonKhronosFramework(true);
35 }
36
37 description('Verify texImage2D and texSubImage2D code paths taking Image Data (' + pixelFormat + '/' + pixelType + ')');
38
39 gl = wtu.create3DContext("example");
40
41 if (!prologue(gl)) {
42 finishTest();
43 return;
44 }
45
46 var program = wtu.setupTexturedQuad(gl);
47 gl.clearColor(0,0,0,1);
48 gl.clearDepth(1);
49 gl.disable(gl.BLEND);
50
51 textureLoc = gl.getUniformLocation(program, "tex");
52
53 var canvas2d = document.getElementById("texcanvas");
54 var context2d = canvas2d.getContext("2d");
55 imageData = context2d.createImageData(1, 2);
56 var data = imageData.data;
57 data[0] = 255;
58 data[1] = 0;
59 data[2] = 0;
60 data[3] = 255;
61 data[4] = 0;
62 data[5] = 255;
63 data[6] = 0;
64 data[7] = 0;
65
66 runTest();
67 }
68
69 function runOneIteration(useTexSubImage2D, flipY, premultiplyAlpha, topColor , bottomColor)
70 {
71 debug('Testing ' + (useTexSubImage2D ? 'texSubImage2D' : 'texImage2D') +
72 ' with flipY=' + flipY + ' and premultiplyAlpha=' + premultiplyAlp ha);
73 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
74 // Enable writes to the RGBA channels
75 gl.colorMask(1, 1, 1, 0);
76 var texture = gl.createTexture();
77 // Bind the texture to texture unit 0
78 gl.bindTexture(gl.TEXTURE_2D, texture);
79 // Set up texture parameters
80 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
81 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
82 // Set up pixel store parameters
83 gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY);
84 gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, premultiplyAlpha);
85 // Upload the image into the texture
86 if (useTexSubImage2D) {
87 // Initialize the texture to black first
88 gl.texImage2D(gl.TEXTURE_2D, 0, gl[pixelFormat], 1, 2, 0,
89 gl[pixelFormat], gl[pixelType], null);
90 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl[pixelFormat], gl[pixelTy pe], imageData);
91 } else {
92 gl.texImage2D(gl.TEXTURE_2D, 0, gl[pixelFormat], gl[pixelFormat], gl [pixelType], imageData);
93 }
94
95 // Point the uniform sampler to texture unit 0
96 gl.uniform1i(textureLoc, 0);
97 // Draw the triangles
98 wtu.drawQuad(gl, [0, 0, 0, 255]);
99
100 // Check the top pixel and bottom pixel and make sure they have
101 // the right color.
102 debug("Checking bottom pixel");
103 wtu.checkCanvasRect(gl, 0, 0, 1, 1, bottomColor, "shouldBe " + bottomCol or);
104 debug("Checking top pixel");
105 wtu.checkCanvasRect(gl, 0, 1, 1, 1, topColor, "shouldBe " + topColor);
106 }
107
108 function runTest()
109 {
110 var red = [255, 0, 0, 255];
111 var green = [0, 255, 0, 255];
112 var redPremultiplyAlpha = [255, 0, 0, 255];
113 var greenPremultiplyAlpha = [0, 0, 0, 255];
114
115 runOneIteration(false, true, false,
116 red, green);
117 runOneIteration(false, false, false,
118 green, red);
119 runOneIteration(false, true, true,
120 redPremultiplyAlpha, greenPremultiplyAlpha);
121 runOneIteration(false, false, true,
122 greenPremultiplyAlpha, redPremultiplyAlpha);
123 runOneIteration(true, true, false,
124 red, green);
125 runOneIteration(true, false, false,
126 green, red);
127 runOneIteration(true, true, true,
128 redPremultiplyAlpha, greenPremultiplyAlpha);
129 runOneIteration(true, false, true,
130 greenPremultiplyAlpha, redPremultiplyAlpha);
131
132 glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors");
133 finishTest();
134 }
135
136 return init;
137 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698