content/canvas/test/webgl-conformance/conformance/textures/tex-input-validation.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/canvas/test/webgl-conformance/conformance/textures/tex-input-validation.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,361 @@
     1.4 +<!--
     1.5 +Copyright (c) 2011 The Chromium Authors. All rights reserved.
     1.6 +Use of this source code is governed by a BSD-style license that can be
     1.7 +found in the LICENSE file.
     1.8 + -->
     1.9 +<!DOCTYPE html>
    1.10 +<html>
    1.11 +<head>
    1.12 +<meta charset="utf-8">
    1.13 +<link rel="stylesheet" href="../../resources/js-test-style.css"/>
    1.14 +<script src="../../resources/js-test-pre.js"></script>
    1.15 +<script src="../resources/webgl-test.js"></script>
    1.16 +<script src="../resources/webgl-test-utils.js"></script>
    1.17 +</head>
    1.18 +<body>
    1.19 +<div id="description"></div>
    1.20 +<div id="console"></div>
    1.21 +
    1.22 +<script>
    1.23 +var wtu = WebGLTestUtils;
    1.24 +var gl = null;
    1.25 +var tex = null;
    1.26 +var error = 0;
    1.27 +
    1.28 +function enumToString(value) {
    1.29 +  return wtu.glEnumToString(gl, value);
    1.30 +}
    1.31 +
    1.32 +function testTexImage2D(testCase)
    1.33 +{
    1.34 +    var level = 0;
    1.35 +    var width = 16;
    1.36 +    var height = 16;
    1.37 +    var msg = "" +
    1.38 +      " internalFormat: " + enumToString(testCase.internalFormat) +
    1.39 +      " target: " + enumToString(testCase.target) +
    1.40 +      " format: " + enumToString(testCase.format) +
    1.41 +      " type: " + enumToString(testCase.type) +
    1.42 +      " border: " + testCase.border;
    1.43 +
    1.44 +    gl.texImage2D(testCase.target, level, testCase.internalFormat, width, height, testCase.border, testCase.format, testCase.type, null);
    1.45 +    error = testCase.expectedError;
    1.46 +    glErrorShouldBe(gl, error, msg);
    1.47 +}
    1.48 +
    1.49 +function testTexSubImage2D(testCase)
    1.50 +{
    1.51 +    var level = 0;
    1.52 +    var xoffset = 0;
    1.53 +    var yoffset = 0;
    1.54 +    var width = 16;
    1.55 +    var height = 16;
    1.56 +    var msg = ""+
    1.57 +        " format: " + enumToString(testCase.format) +
    1.58 +        " type: " + enumToString(testCase.type);
    1.59 +    var array = new Uint8Array(width * height * 4);
    1.60 +    gl.texSubImage2D(testCase.target, level, xoffset, yoffset, width, height, testCase.format, testCase.type, array);
    1.61 +    error = testCase.expectedError;
    1.62 +    glErrorShouldBe(gl, error, msg);
    1.63 +}
    1.64 +
    1.65 +function testTexParameter(testCase)
    1.66 +{
    1.67 +    var msg = "paramName: " + enumToString(testCase.pname);
    1.68 +    error = testCase.expectedError;
    1.69 +    gl.texParameteri(testCase.target, testCase.pname, testCase.param);
    1.70 +    glErrorShouldBe(gl, error, msg);
    1.71 +    gl.texParameterf(testCase.target, testCase.pname, testCase.param);
    1.72 +    glErrorShouldBe(gl, error, msg);
    1.73 +}
    1.74 +
    1.75 +function testGetTexParameter(testCase)
    1.76 +{
    1.77 +    var msg = "paramName: " + enumToString(testCase.pname);
    1.78 +    error = testCase.expectedError;
    1.79 +    gl.getTexParameter(testCase.target, testCase.pname);
    1.80 +    glErrorShouldBe(gl, error, msg);
    1.81 +}
    1.82 +
    1.83 +function testCopyTexImage2D(testCase)
    1.84 +{
    1.85 +    var level = 0;
    1.86 +    var x = 0;
    1.87 +    var y = 0;
    1.88 +    var width = 16;
    1.89 +    var height = 16;
    1.90 +
    1.91 +    var msg = "" +
    1.92 +      " colorBufferFormat: " + enumToString(testCase.colorBufferFormat) +
    1.93 +      " internalFormat: " + enumToString(testCase.internalFormat) +
    1.94 +      " target: " + enumToString(testCase.target) +
    1.95 +      " border: " + testCase.border;
    1.96 +
    1.97 +    gl.renderbufferStorage(gl.RENDERBUFFER, testCase.colorBufferFormat, width, height);
    1.98 +    glErrorShouldBe(gl, gl.NO_ERROR);
    1.99 +    shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE");
   1.100 +
   1.101 +    gl.copyTexImage2D(testCase.target, level, testCase.internalFormat, x, y, width, height, testCase.border);
   1.102 +    error = testCase.expectedError;
   1.103 +    glErrorShouldBe(gl, error, msg);
   1.104 +}
   1.105 +
   1.106 +function testCopyTexSubImage2D(testCase)
   1.107 +{
   1.108 +    var level = 0;
   1.109 +    var x = 0;
   1.110 +    var y = 0;
   1.111 +    var width = 16;
   1.112 +    var height = 16;
   1.113 +    var xoffset = 0;
   1.114 +    var yoffset = 0;
   1.115 +    var border = 0;
   1.116 +    var type = gl.UNSIGNED_BYTE;
   1.117 +    var msg = "" +
   1.118 +      " colorBufferFormat: " + enumToString(testCase.colorBufferFormat) +
   1.119 +      " internalFormat: " + enumToString(testCase.internalFormat) +
   1.120 +      " target: " + enumToString(testCase.target);
   1.121 +
   1.122 +    gl.renderbufferStorage(gl.RENDERBUFFER, testCase.colorBufferFormat, width, height);
   1.123 +    glErrorShouldBe(gl, gl.NO_ERROR);
   1.124 +    shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE");
   1.125 +
   1.126 +    gl.texImage2D(testCase.target, level, testCase.internalFormat, xoffset + width, yoffset + height, border, testCase.internalFormat, type, null);
   1.127 +    glErrorShouldBe(gl, gl.NO_ERROR);
   1.128 +
   1.129 +    gl.copyTexSubImage2D(testCase.target, level, xoffset, yoffset, x, y, width, height);
   1.130 +    error = testCase.expectedError;
   1.131 +    glErrorShouldBe(gl, error, msg);
   1.132 +}
   1.133 +
   1.134 +function testCopyFromInternalFBO(testCase)
   1.135 +{
   1.136 +    var target = gl.TEXTURE_2D;
   1.137 +    var level = 0;
   1.138 +    var x = 0;
   1.139 +    var y = 0;
   1.140 +    var width = 16;
   1.141 +    var height = 16;
   1.142 +    var xoffset = 0;
   1.143 +    var yoffset = 0;
   1.144 +    var border = 0;
   1.145 +    var type = gl.UNSIGNED_BYTE;
   1.146 +    var msg = "" +
   1.147 +      " colorBufferFormat: " + enumToString(testCase.contextAlpha ? gl.RGBA : gl.RGB) +
   1.148 +      " internalFormat: " + enumToString(testCase.internalFormat);
   1.149 +
   1.150 +    if (testCase.contextAlpha)
   1.151 +        gl = create3DContext(null, { alpha: true });
   1.152 +    else
   1.153 +        gl = create3DContext(null, { alpha: false });
   1.154 +    shouldBeNonNull("gl");
   1.155 +    shouldBeNonNull("tex = gl.createTexture()");
   1.156 +    gl.bindTexture(target, tex);
   1.157 +    if (testCase.subImage) {
   1.158 +        gl.texImage2D(target, level, testCase.internalFormat, xoffset + width, yoffset + height, border, testCase.internalFormat, type, null);
   1.159 +        glErrorShouldBe(gl, gl.NO_ERROR);
   1.160 +        gl.copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
   1.161 +    } else {
   1.162 +        glErrorShouldBe(gl, gl.NO_ERROR);
   1.163 +        gl.copyTexImage2D(target, level, testCase.internalFormat, x, y, width, height, border);
   1.164 +    }
   1.165 +    error = testCase.expectedError;
   1.166 +    glErrorShouldBe(gl, error, msg);
   1.167 +}
   1.168 +
   1.169 +description("Validate tex functions input parameters");
   1.170 +
   1.171 +shouldBeNonNull("gl = create3DContext()");
   1.172 +shouldBeNonNull("tex = gl.createTexture()");
   1.173 +gl.bindTexture(gl.TEXTURE_2D, tex);
   1.174 +glErrorShouldBe(gl, gl.NO_ERROR);
   1.175 +
   1.176 +debug("");
   1.177 +debug("Checking TexImage2D: a set of inputs that are valid in GL but invalid in GLES2");
   1.178 +
   1.179 +var testCases =
   1.180 +  [ {target: 0x8064, // GL_PROXY_TEXTURE_2D
   1.181 +     internalFormat: gl.RGBA,
   1.182 +     border: 0,
   1.183 +     format: gl.RGBA,
   1.184 +     type: gl.UNSIGNED_BYTE,
   1.185 +     expectedError: gl.INVALID_ENUM},
   1.186 +    {target: gl.TEXTURE_2D,
   1.187 +     internalFormat: 0x1903, // GL_RED
   1.188 +     border: 0,
   1.189 +     format: 0x1903, // GL_RED
   1.190 +     type: gl.UNSIGNED_BYTE,
   1.191 +     expectedError: gl.INVALID_ENUM},
   1.192 +    {target: gl.TEXTURE_2D,
   1.193 +     internalFormat: gl.RGBA,
   1.194 +     border: 1,
   1.195 +     format: gl.RGBA,
   1.196 +     type: gl.UNSIGNED_BYTE,
   1.197 +     expectedError: gl.INVALID_VALUE},
   1.198 +    {target: gl.TEXTURE_2D,
   1.199 +     internalFormat: gl.RGBA,
   1.200 +     border: 0,
   1.201 +     format: gl.RGB,
   1.202 +     type: gl.UNSIGNED_BYTE,
   1.203 +     expectedError: gl.INVALID_OPERATION},
   1.204 +    {target: gl.TEXTURE_2D,
   1.205 +     internalFormat: gl.RGBA,
   1.206 +     border: 0,
   1.207 +     format: gl.RGBA,
   1.208 +     type: gl.BYTE,
   1.209 +     expectedError: gl.INVALID_ENUM},
   1.210 +    {target: gl.TEXTURE_2D,
   1.211 +     internalFormat: gl.RGBA,
   1.212 +     border: 0,
   1.213 +     format: gl.RGBA,
   1.214 +     type: gl.UNSIGNED_BYTE,
   1.215 +     expectedError: gl.NO_ERROR} ];
   1.216 +
   1.217 +for (var ii = 0; ii < testCases.length; ++ii)
   1.218 +    testTexImage2D(testCases[ii]);
   1.219 +
   1.220 +debug("");
   1.221 +debug("Checking TexSubImage2D: a set of inputs that are valid in GL but invalid in GLES2");
   1.222 +
   1.223 +testCases =
   1.224 +  [ {target: gl.TEXTURE_2D,
   1.225 +     format: 0x1903, // GL_RED
   1.226 +     type: gl.UNSIGNED_BYTE,
   1.227 +     expectedError: gl.INVALID_ENUM},
   1.228 +    {target: gl.TEXTURE_2D,
   1.229 +     format: gl.RGBA,
   1.230 +     type: gl.BYTE,
   1.231 +     expectedError: gl.INVALID_ENUM},
   1.232 +    {target: gl.TEXTURE_2D,
   1.233 +     format: gl.RGBA,
   1.234 +     type: gl.UNSIGNED_BYTE,
   1.235 +     expectedError: gl.NO_ERROR} ];
   1.236 +
   1.237 +for (var ii = 0; ii < testCases.length; ++ii)
   1.238 +    testTexSubImage2D(testCases[ii]);
   1.239 +
   1.240 +debug("");
   1.241 +debug("Checking TexParameter: a set of inputs that are valid in GL but invalid in GLES2");
   1.242 +
   1.243 +testCases =
   1.244 +  [ {target: 0x0DE0, // GL_TEXTURE_1D
   1.245 +     pname: gl.TEXTURE_WRAP_T,
   1.246 +     param: gl.REPEAT,
   1.247 +     expectedError: gl.INVALID_ENUM},
   1.248 +    {target: gl.TEXTURE_2D,
   1.249 +     pname: 0x813A, // GL_TEXTURE_MIN_LOD
   1.250 +     param: 0,
   1.251 +     expectedError: gl.INVALID_ENUM},
   1.252 +    {target: gl.TEXTURE_2D,
   1.253 +     pname: gl.TEXTURE_WRAP_T,
   1.254 +     param: 0x2900, // GL_CLAMP
   1.255 +     expectedError: gl.INVALID_ENUM},
   1.256 +    {target: gl.TEXTURE_2D,
   1.257 +     pname: gl.TEXTURE_WRAP_T,
   1.258 +     param: gl.REPEAT,
   1.259 +     expectedError: gl.NO_ERROR} ];
   1.260 +
   1.261 +for (var ii = 0; ii < testCases.length; ++ii)
   1.262 +    testTexParameter(testCases[ii]);
   1.263 +
   1.264 +debug("");
   1.265 +debug("Checking GetTexParameter: a set of inputs that are valid in GL but invalid in GLES2");
   1.266 +
   1.267 +testCases =
   1.268 +  [ {target: 0x0DE0, // GL_TEXTURE_1D
   1.269 +     pname: gl.TEXTURE_WRAP_T,
   1.270 +     expectedError: gl.INVALID_ENUM},
   1.271 +    {target: gl.TEXTURE_2D,
   1.272 +     pname: 0x813A, // GL_TEXTURE_MIN_LOD
   1.273 +     expectedError: gl.INVALID_ENUM},
   1.274 +    {target: gl.TEXTURE_2D,
   1.275 +     pname: gl.TEXTURE_WRAP_T,
   1.276 +     expectedError: gl.NO_ERROR} ];
   1.277 +
   1.278 +for (var ii = 0; ii < testCases.length; ++ii)
   1.279 +    testGetTexParameter(testCases[ii]);
   1.280 +
   1.281 +debug("");
   1.282 +debug("Checking CopyTexImage2D: a set of inputs that are valid in GL but invalid in GLES2");
   1.283 +
   1.284 +var colorBuffer = null;
   1.285 +var fbo = null;
   1.286 +
   1.287 +shouldBeNonNull("fbo = gl.createFramebuffer()");
   1.288 +gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
   1.289 +shouldBeNonNull("colorBuffer = gl.createRenderbuffer()");
   1.290 +gl.bindRenderbuffer(gl.RENDERBUFFER, colorBuffer);
   1.291 +gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, colorBuffer);
   1.292 +glErrorShouldBe(gl, gl.NO_ERROR);
   1.293 +
   1.294 +testCases =
   1.295 +  [ {target: gl.TEXTURE_2D,
   1.296 +     colorBufferFormat: gl.RGB565,
   1.297 +     internalFormat: 0x8054, // GL_RGB16
   1.298 +     border: 0,
   1.299 +     expectedError: gl.INVALID_ENUM},
   1.300 +    {target: gl.TEXTURE_2D,
   1.301 +     colorBufferFormat: gl.RGB565,
   1.302 +     internalFormat: gl.RGBA,
   1.303 +     border: 1,
   1.304 +     expectedError: gl.INVALID_VALUE},
   1.305 +    {target: gl.TEXTURE_2D,
   1.306 +     colorBufferFormat: gl.RGB565,
   1.307 +     internalFormat: gl.RGBA,
   1.308 +     border: 0,
   1.309 +     expectedError: gl.INVALID_OPERATION},
   1.310 +    {target: gl.TEXTURE_2D,
   1.311 +     colorBufferFormat: gl.RGB565,
   1.312 +     internalFormat: gl.RGB,
   1.313 +     border: 0,
   1.314 +     expectedError: gl.NO_ERROR} ];
   1.315 +
   1.316 +for (var ii = 0; ii < testCases.length; ++ii)
   1.317 +    testCopyTexImage2D(testCases[ii]);
   1.318 +
   1.319 +debug("");
   1.320 +debug("Checking CopyTexSubImage2D: a set of inputs that are valid in GL but invalid in GLES2");
   1.321 +
   1.322 +testCases =
   1.323 +  [ {target: gl.TEXTURE_2D,
   1.324 +     colorBufferFormat: gl.RGB5_A1,
   1.325 +     internalFormat: gl.RGBA,
   1.326 +     expectedError: gl.NO_ERROR},
   1.327 +    {target: gl.TEXTURE_2D,
   1.328 +     colorBufferFormat: gl.RGB565,
   1.329 +     internalFormat: gl.RGBA,
   1.330 +     expectedError: gl.INVALID_OPERATION} ];
   1.331 +
   1.332 +for (var ii = 0; ii < testCases.length; ++ii)
   1.333 +    testCopyTexSubImage2D(testCases[ii]);
   1.334 +
   1.335 +debug("");
   1.336 +debug("Checking CopyTex{Sub}Image2D: copy from WebGL internal framebuffer");
   1.337 +
   1.338 +testCases =
   1.339 +  [ {contextAlpha: true,
   1.340 +     internalFormat: gl.RGBA,
   1.341 +     subImage: false,
   1.342 +     expectedError: gl.NO_ERROR},
   1.343 +    {contextAlpha: false,
   1.344 +     internalFormat: gl.RGBA,
   1.345 +     subImage: false,
   1.346 +     expectedError: gl.INVALID_OPERATION},
   1.347 +    {contextAlpha: true,
   1.348 +     internalFormat: gl.RGBA,
   1.349 +     subImage: true,
   1.350 +     expectedError: gl.NO_ERROR},
   1.351 +    {contextAlpha: false,
   1.352 +     internalFormat: gl.RGBA,
   1.353 +     subImage: true,
   1.354 +     expectedError: gl.INVALID_OPERATION} ];
   1.355 +
   1.356 +for (var ii = 0; ii < testCases.length; ++ii)
   1.357 +    testCopyFromInternalFBO(testCases[ii]);
   1.358 +
   1.359 +successfullyParsed = true;
   1.360 +</script>
   1.361 +
   1.362 +<script>finishTest();</script>
   1.363 +</body>
   1.364 +</html>

mercurial