blob: 17f8f4d506fdc73be9faacf6924cf07142294da6 [file] [log] [blame]
<html>
<head>
<meta charset="utf-8">
<title>WebGL sampler uniforms conformance test.</title>
<script src="../../../resources/js-test.js"></script>
<script src="resources/webgl-test.js"> </script>
<script src="resources/webgl-test-utils.js"></script>
</head>
<body>
<canvas id="example" width="2" height="2" style="width: 40px; height: 40px;"></canvas>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
function init()
{
description(
"Tests that only Uniform1i and Uniform1iv can be used to set" +
"sampler uniforms.");
if (window.internals)
window.internals.settings.setWebGLErrorsToConsoleEnabled(false);
var canvas2d = document.getElementById("canvas2d");
var wtu = WebGLTestUtils;
var gl = wtu.create3DContext("example");
var program = wtu.setupTexturedQuad(gl);
var textureLoc = gl.getUniformLocation(program, "tex");
var testInt32Array = new Int32Array(1);
gl.uniform1i(textureLoc, 1);
glErrorShouldBe(gl, gl.NO_ERROR,
"uniform1i can set a sampler uniform");
gl.uniform1iv(textureLoc, [1]);
glErrorShouldBe(gl, gl.NO_ERROR,
"uniform1iv can set a sampler uniform");
gl.uniform1iv(textureLoc, testInt32Array);
glErrorShouldBe(gl, gl.NO_ERROR,
"uniform1iv can set a sampler uniform");
gl.uniform1f(textureLoc, 1);
glErrorShouldBe(gl, gl.INVALID_OPERATION,
"uniform1f returns INVALID_OPERATION if attempting to set a sampler uniform");
gl.uniform1fv(textureLoc, [1]);
glErrorShouldBe(gl, gl.INVALID_OPERATION,
"uniform1fv returns INVALID_OPERATION if attempting to set a sampler uniform");
var maxTextureUnits = gl.getParameter(gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS);
var success = true;
for (var ii = 0; ii < maxTextureUnits; ++ii) {
gl.uniform1i(textureLoc, ii);
success = success && (gl.getError() == gl.NO_ERROR);
}
expectTrue(success, "uniform1i works for any valid texture unit");
var success = true;
for (var ii = 0; ii < maxTextureUnits; ++ii) {
gl.uniform1iv(textureLoc, [ii]);
success = success && (gl.getError() == gl.NO_ERROR);
}
expectTrue(success, "uniform1iv works for any valid texture unit");
var success = true;
for (var ii = maxTextureUnits; ii < 0x10000; ++ii) {
gl.uniform1i(textureLoc, ii);
success = success && (gl.getError() == gl.INVALID_VALUE);
}
expectTrue(success, "uniform1i generates INVALID_VALUE for invalid texture units");
var success = true;
for (var ii = maxTextureUnits; ii < 0x10000; ++ii) {
gl.uniform1iv(textureLoc, [ii]);
success = success && (gl.getError() == gl.INVALID_VALUE);
}
expectTrue(success, "uniform1iv generates INVALID_VALUE for invalid texture units");
}
init();
</script>
</body>
</html>