1 function generateTest(pixelFormat
, pixelType
, prologue
) {
2 var wtu
= WebGLTestUtils
;
5 var successfullyParsed
= false;
10 if (window
.initNonKhronosFramework
) {
11 window
.initNonKhronosFramework(true);
14 description('Verify texImage2D and texSubImage2D code paths taking ImageData (' + pixelFormat
+ '/' + pixelType
+ ')');
16 gl
= wtu
.create3DContext("example");
23 var program
= wtu
.setupTexturedQuad(gl
);
24 gl
.clearColor(0,0,0,1);
28 textureLoc
= gl
.getUniformLocation(program
, "tex");
30 var canvas2d
= document
.getElementById("texcanvas");
31 var context2d
= canvas2d
.getContext("2d");
32 imageData
= context2d
.createImageData(1, 2);
33 var data
= imageData
.data
;
46 function runOneIteration(useTexSubImage2D
, flipY
, premultiplyAlpha
, topColor
, bottomColor
)
48 debug('Testing ' + (useTexSubImage2D
? 'texSubImage2D' : 'texImage2D') +
49 ' with flipY=' + flipY
+ ' and premultiplyAlpha=' + premultiplyAlpha
);
50 gl
.clear(gl
.COLOR_BUFFER_BIT
| gl
.DEPTH_BUFFER_BIT
);
51 // Enable writes to the RGBA channels
52 gl
.colorMask(1, 1, 1, 0);
53 var texture
= gl
.createTexture();
54 // Bind the texture to texture unit 0
55 gl
.bindTexture(gl
.TEXTURE_2D
, texture
);
56 // Set up texture parameters
57 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MIN_FILTER
, gl
.NEAREST
);
58 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MAG_FILTER
, gl
.NEAREST
);
59 // Set up pixel store parameters
60 gl
.pixelStorei(gl
.UNPACK_FLIP_Y_WEBGL
, flipY
);
61 gl
.pixelStorei(gl
.UNPACK_PREMULTIPLY_ALPHA_WEBGL
, premultiplyAlpha
);
62 // Upload the image into the texture
63 if (useTexSubImage2D
) {
64 // Initialize the texture to black first
65 gl
.texImage2D(gl
.TEXTURE_2D
, 0, gl
[pixelFormat
], 1, 2, 0,
66 gl
[pixelFormat
], gl
[pixelType
], null);
67 gl
.texSubImage2D(gl
.TEXTURE_2D
, 0, 0, 0, gl
[pixelFormat
], gl
[pixelType
], imageData
);
69 gl
.texImage2D(gl
.TEXTURE_2D
, 0, gl
[pixelFormat
], gl
[pixelFormat
], gl
[pixelType
], imageData
);
72 // Point the uniform sampler to texture unit 0
73 gl
.uniform1i(textureLoc
, 0);
75 wtu
.drawQuad(gl
, [0, 0, 0, 255]);
77 // Check the top pixel and bottom pixel and make sure they have
79 debug("Checking bottom pixel");
80 wtu
.checkCanvasRect(gl
, 0, 0, 1, 1, bottomColor
, "shouldBe " + bottomColor
);
81 debug("Checking top pixel");
82 wtu
.checkCanvasRect(gl
, 0, 1, 1, 1, topColor
, "shouldBe " + topColor
);
87 var red
= [255, 0, 0, 255];
88 var green
= [0, 255, 0, 255];
89 var redPremultiplyAlpha
= [255, 0, 0, 255];
90 var greenPremultiplyAlpha
= [0, 0, 0, 255];
92 runOneIteration(false, true, false,
94 runOneIteration(false, false, false,
96 runOneIteration(false, true, true,
97 redPremultiplyAlpha
, greenPremultiplyAlpha
);
98 runOneIteration(false, false, true,
99 greenPremultiplyAlpha
, redPremultiplyAlpha
);
100 runOneIteration(true, true, false,
102 runOneIteration(true, false, false,
104 runOneIteration(true, true, true,
105 redPremultiplyAlpha
, greenPremultiplyAlpha
);
106 runOneIteration(true, false, true,
107 greenPremultiplyAlpha
, redPremultiplyAlpha
);
109 glErrorShouldBe(gl
, gl
.NO_ERROR
, "should be no errors");