blob: da7b877bb0ff8348bfba8fbd530d40cac7c9a99b [file] [log] [blame]
<html>
<head>
<script src="../../../resources/js-test.js"></script>
<script src="resources/webgl-test.js"></script>
<script src="resources/webgl-test-utils.js"></script>
<script>
var wtu = WebGLTestUtils;
var gl = null;
var textureLoc = null;
function init()
{
if (window.initNonKhronosFramework) {
window.initNonKhronosFramework(true);
}
description('Tests there is no garbage in transparent regions of images uploaded as textures');
wtu = WebGLTestUtils;
var canvas = document.getElementById("example");
gl = wtu.create3DContext(canvas);
var program = wtu.setupTexturedQuad(gl);
gl.clearColor(0.5,0.5,0.5,1);
gl.clearDepth(1);
textureLoc = gl.getUniformLocation(program, "tex");
// The input texture has 8 characters; take the leftmost one
var coeff = 1.0 / 8.0;
var texCoords = new Float32Array([
coeff, 1.0,
0.0, 1.0,
0.0, 0.0,
coeff, 1.0,
0.0, 0.0,
coeff, 0.0]);
var vbo = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
gl.bufferData(gl.ARRAY_BUFFER, texCoords, gl.STATIC_DRAW);
gl.enableVertexAttribArray(1);
gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 0, 0);
texture = wtu.loadTexture(gl, "resources/bug-32888-texture.png", runTest);
}
// These two declarations need to be global for "shouldBe" to see them
var buf = null;
var idx = 0;
function runTest()
{
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.enable(gl.BLEND);
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
// Bind the texture to texture unit 0
gl.bindTexture(gl.TEXTURE_2D, texture);
// Point the uniform sampler to texture unit 0
gl.uniform1i(textureLoc, 0);
// Draw the triangles
wtu.drawQuad(gl, [0, 0, 0, 255]);
// Spot check a couple of 2x2 regions in the upper and lower left
// corners; they should be the rgb values in the texture.
color = [0, 0, 0];
debug("Checking lower left corner");
wtu.checkCanvasRect(gl, 1, gl.canvas.height - 3, 2, 2, color,
"shouldBe " + color);
debug("Checking upper left corner");
wtu.checkCanvasRect(gl, 1, 1, 2, 2, color,
"shouldBe " + color);
var epilogue = document.createElement("script");
epilogue.onload = finish;
epilogue.src = "../../../resources/js-test-post.js";
document.body.appendChild(epilogue);
}
function finish() {
if (window.nonKhronosFrameworkNotifyDone) {
window.nonKhronosFrameworkNotifyDone();
}
}
</script>
</head>
<body onload="init()">
<canvas id="example" width="32px" height="32px"></canvas>
<div id="description"></div>
<div id="console"></div>
</body>
</html>