gecko/content/canvas/test/webgl/conformance/texture-npot.html

87 lines
3.0 KiB
HTML
Executable File

<!--
Copyright (c) 2009 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>WebGL Non-Power of 2 texture conformance test.</title>
<link rel="stylesheet" href="../resources/js-test-style.css"/>
<script src="../resources/js-test-pre.js"></script>
<script src="resources/webgl-test-utils.js"> </script>
</head>
<body>
<canvas id="example" width="4" height="4" style="width: 40px; height: 30px;"></canvas>
<div id="description"></div>
<div id="console"></div>
<script>
var wtu = WebGLTestUtils;
var canvas = document.getElementById("example");
var gl = wtu.create3DContext(canvas);
var program = wtu.setupTexturedQuad(gl);
assertMsg(gl.getError() == gl.NO_ERROR, "Should be no errors from setup.");
var tex = gl.createTexture();
// Check that an NPOT texture not on level 0 generates INVALID_VALUE
wtu.fillTexture(gl, tex, 5, 3, [0, 192, 128, 255], 1);
assertMsg(gl.getError() == gl.INVALID_VALUE,
"gl.texImage2D with NPOT texture with level > 0 should return INVALID_VALUE");
// Check that an NPOT texture on level 0 succeeds
wtu.fillTexture(gl, tex, 5, 3, [0, 192, 128, 255]);
assertMsg(gl.getError() == gl.NO_ERROR,
"gl.texImage2D with NPOT texture at level 0 should succeed");
// Check that generateMipmap fails on NPOT
gl.generateMipmap(gl.TEXTURE_2D);
assertMsg(gl.getError() == gl.INVALID_OPERATION,
"gl.generateMipmap with NPOT texture should return INVALID_OPERATION");
var loc = gl.getUniformLocation(program, "tex");
gl.uniform1i(loc, 0);
// Check that nothing is drawn if filtering is not correct for NPOT
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
wtu.drawQuad(gl);
wtu.checkCanvas(
gl, [0, 0, 0, 255],
"NPOT texture with TEXTURE_WRAP set to REPEAT should draw with 0,0,0,255");
assertMsg(gl.getError() == gl.NO_ERROR, "Should be no errors from setup.");
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_LINEAR);
wtu.drawQuad(gl);
wtu.checkCanvas(
gl, [0, 0, 0, 255],
"NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255");
assertMsg(gl.getError() == gl.NO_ERROR, "Should be no errors from setup.");
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
wtu.drawQuad(gl);
wtu.checkCanvas(
gl, [0, 192, 128, 255],
"NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw.");
successfullyParsed = true;
</script>
</body>
<script src="../resources/js-test-post.js"></script>
<script>
</script>
</body>
</html>