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

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     1 <!--
     2 Copyright (c) 2011 The Chromium Authors. All rights reserved.
     3 Use of this source code is governed by a BSD-style license that can be
     4 found in the LICENSE file.
     5  -->
     6 <!DOCTYPE html>
     7 <html>
     8 <head>
     9 <meta charset="utf-8">
    10 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
    11 <script src="../../resources/js-test-pre.js"></script>
    12 <script src="../resources/webgl-test.js"></script>
    13 <script src="../resources/webgl-test-utils.js"></script>
    14 </head>
    15 <body>
    16 <div id="description"></div>
    17 <div id="console"></div>
    19 <script>
    20 var wtu = WebGLTestUtils;
    21 var gl = null;
    22 var tex = null;
    23 var error = 0;
    25 function enumToString(value) {
    26   return wtu.glEnumToString(gl, value);
    27 }
    29 function testTexImage2D(testCase)
    30 {
    31     var level = 0;
    32     var width = 16;
    33     var height = 16;
    34     var msg = "" +
    35       " internalFormat: " + enumToString(testCase.internalFormat) +
    36       " target: " + enumToString(testCase.target) +
    37       " format: " + enumToString(testCase.format) +
    38       " type: " + enumToString(testCase.type) +
    39       " border: " + testCase.border;
    41     gl.texImage2D(testCase.target, level, testCase.internalFormat, width, height, testCase.border, testCase.format, testCase.type, null);
    42     error = testCase.expectedError;
    43     glErrorShouldBe(gl, error, msg);
    44 }
    46 function testTexSubImage2D(testCase)
    47 {
    48     var level = 0;
    49     var xoffset = 0;
    50     var yoffset = 0;
    51     var width = 16;
    52     var height = 16;
    53     var msg = ""+
    54         " format: " + enumToString(testCase.format) +
    55         " type: " + enumToString(testCase.type);
    56     var array = new Uint8Array(width * height * 4);
    57     gl.texSubImage2D(testCase.target, level, xoffset, yoffset, width, height, testCase.format, testCase.type, array);
    58     error = testCase.expectedError;
    59     glErrorShouldBe(gl, error, msg);
    60 }
    62 function testTexParameter(testCase)
    63 {
    64     var msg = "paramName: " + enumToString(testCase.pname);
    65     error = testCase.expectedError;
    66     gl.texParameteri(testCase.target, testCase.pname, testCase.param);
    67     glErrorShouldBe(gl, error, msg);
    68     gl.texParameterf(testCase.target, testCase.pname, testCase.param);
    69     glErrorShouldBe(gl, error, msg);
    70 }
    72 function testGetTexParameter(testCase)
    73 {
    74     var msg = "paramName: " + enumToString(testCase.pname);
    75     error = testCase.expectedError;
    76     gl.getTexParameter(testCase.target, testCase.pname);
    77     glErrorShouldBe(gl, error, msg);
    78 }
    80 function testCopyTexImage2D(testCase)
    81 {
    82     var level = 0;
    83     var x = 0;
    84     var y = 0;
    85     var width = 16;
    86     var height = 16;
    88     var msg = "" +
    89       " colorBufferFormat: " + enumToString(testCase.colorBufferFormat) +
    90       " internalFormat: " + enumToString(testCase.internalFormat) +
    91       " target: " + enumToString(testCase.target) +
    92       " border: " + testCase.border;
    94     gl.renderbufferStorage(gl.RENDERBUFFER, testCase.colorBufferFormat, width, height);
    95     glErrorShouldBe(gl, gl.NO_ERROR);
    96     shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE");
    98     gl.copyTexImage2D(testCase.target, level, testCase.internalFormat, x, y, width, height, testCase.border);
    99     error = testCase.expectedError;
   100     glErrorShouldBe(gl, error, msg);
   101 }
   103 function testCopyTexSubImage2D(testCase)
   104 {
   105     var level = 0;
   106     var x = 0;
   107     var y = 0;
   108     var width = 16;
   109     var height = 16;
   110     var xoffset = 0;
   111     var yoffset = 0;
   112     var border = 0;
   113     var type = gl.UNSIGNED_BYTE;
   114     var msg = "" +
   115       " colorBufferFormat: " + enumToString(testCase.colorBufferFormat) +
   116       " internalFormat: " + enumToString(testCase.internalFormat) +
   117       " target: " + enumToString(testCase.target);
   119     gl.renderbufferStorage(gl.RENDERBUFFER, testCase.colorBufferFormat, width, height);
   120     glErrorShouldBe(gl, gl.NO_ERROR);
   121     shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE");
   123     gl.texImage2D(testCase.target, level, testCase.internalFormat, xoffset + width, yoffset + height, border, testCase.internalFormat, type, null);
   124     glErrorShouldBe(gl, gl.NO_ERROR);
   126     gl.copyTexSubImage2D(testCase.target, level, xoffset, yoffset, x, y, width, height);
   127     error = testCase.expectedError;
   128     glErrorShouldBe(gl, error, msg);
   129 }
   131 function testCopyFromInternalFBO(testCase)
   132 {
   133     var target = gl.TEXTURE_2D;
   134     var level = 0;
   135     var x = 0;
   136     var y = 0;
   137     var width = 16;
   138     var height = 16;
   139     var xoffset = 0;
   140     var yoffset = 0;
   141     var border = 0;
   142     var type = gl.UNSIGNED_BYTE;
   143     var msg = "" +
   144       " colorBufferFormat: " + enumToString(testCase.contextAlpha ? gl.RGBA : gl.RGB) +
   145       " internalFormat: " + enumToString(testCase.internalFormat);
   147     if (testCase.contextAlpha)
   148         gl = create3DContext(null, { alpha: true });
   149     else
   150         gl = create3DContext(null, { alpha: false });
   151     shouldBeNonNull("gl");
   152     shouldBeNonNull("tex = gl.createTexture()");
   153     gl.bindTexture(target, tex);
   154     if (testCase.subImage) {
   155         gl.texImage2D(target, level, testCase.internalFormat, xoffset + width, yoffset + height, border, testCase.internalFormat, type, null);
   156         glErrorShouldBe(gl, gl.NO_ERROR);
   157         gl.copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
   158     } else {
   159         glErrorShouldBe(gl, gl.NO_ERROR);
   160         gl.copyTexImage2D(target, level, testCase.internalFormat, x, y, width, height, border);
   161     }
   162     error = testCase.expectedError;
   163     glErrorShouldBe(gl, error, msg);
   164 }
   166 description("Validate tex functions input parameters");
   168 shouldBeNonNull("gl = create3DContext()");
   169 shouldBeNonNull("tex = gl.createTexture()");
   170 gl.bindTexture(gl.TEXTURE_2D, tex);
   171 glErrorShouldBe(gl, gl.NO_ERROR);
   173 debug("");
   174 debug("Checking TexImage2D: a set of inputs that are valid in GL but invalid in GLES2");
   176 var testCases =
   177   [ {target: 0x8064, // GL_PROXY_TEXTURE_2D
   178      internalFormat: gl.RGBA,
   179      border: 0,
   180      format: gl.RGBA,
   181      type: gl.UNSIGNED_BYTE,
   182      expectedError: gl.INVALID_ENUM},
   183     {target: gl.TEXTURE_2D,
   184      internalFormat: 0x1903, // GL_RED
   185      border: 0,
   186      format: 0x1903, // GL_RED
   187      type: gl.UNSIGNED_BYTE,
   188      expectedError: gl.INVALID_ENUM},
   189     {target: gl.TEXTURE_2D,
   190      internalFormat: gl.RGBA,
   191      border: 1,
   192      format: gl.RGBA,
   193      type: gl.UNSIGNED_BYTE,
   194      expectedError: gl.INVALID_VALUE},
   195     {target: gl.TEXTURE_2D,
   196      internalFormat: gl.RGBA,
   197      border: 0,
   198      format: gl.RGB,
   199      type: gl.UNSIGNED_BYTE,
   200      expectedError: gl.INVALID_OPERATION},
   201     {target: gl.TEXTURE_2D,
   202      internalFormat: gl.RGBA,
   203      border: 0,
   204      format: gl.RGBA,
   205      type: gl.BYTE,
   206      expectedError: gl.INVALID_ENUM},
   207     {target: gl.TEXTURE_2D,
   208      internalFormat: gl.RGBA,
   209      border: 0,
   210      format: gl.RGBA,
   211      type: gl.UNSIGNED_BYTE,
   212      expectedError: gl.NO_ERROR} ];
   214 for (var ii = 0; ii < testCases.length; ++ii)
   215     testTexImage2D(testCases[ii]);
   217 debug("");
   218 debug("Checking TexSubImage2D: a set of inputs that are valid in GL but invalid in GLES2");
   220 testCases =
   221   [ {target: gl.TEXTURE_2D,
   222      format: 0x1903, // GL_RED
   223      type: gl.UNSIGNED_BYTE,
   224      expectedError: gl.INVALID_ENUM},
   225     {target: gl.TEXTURE_2D,
   226      format: gl.RGBA,
   227      type: gl.BYTE,
   228      expectedError: gl.INVALID_ENUM},
   229     {target: gl.TEXTURE_2D,
   230      format: gl.RGBA,
   231      type: gl.UNSIGNED_BYTE,
   232      expectedError: gl.NO_ERROR} ];
   234 for (var ii = 0; ii < testCases.length; ++ii)
   235     testTexSubImage2D(testCases[ii]);
   237 debug("");
   238 debug("Checking TexParameter: a set of inputs that are valid in GL but invalid in GLES2");
   240 testCases =
   241   [ {target: 0x0DE0, // GL_TEXTURE_1D
   242      pname: gl.TEXTURE_WRAP_T,
   243      param: gl.REPEAT,
   244      expectedError: gl.INVALID_ENUM},
   245     {target: gl.TEXTURE_2D,
   246      pname: 0x813A, // GL_TEXTURE_MIN_LOD
   247      param: 0,
   248      expectedError: gl.INVALID_ENUM},
   249     {target: gl.TEXTURE_2D,
   250      pname: gl.TEXTURE_WRAP_T,
   251      param: 0x2900, // GL_CLAMP
   252      expectedError: gl.INVALID_ENUM},
   253     {target: gl.TEXTURE_2D,
   254      pname: gl.TEXTURE_WRAP_T,
   255      param: gl.REPEAT,
   256      expectedError: gl.NO_ERROR} ];
   258 for (var ii = 0; ii < testCases.length; ++ii)
   259     testTexParameter(testCases[ii]);
   261 debug("");
   262 debug("Checking GetTexParameter: a set of inputs that are valid in GL but invalid in GLES2");
   264 testCases =
   265   [ {target: 0x0DE0, // GL_TEXTURE_1D
   266      pname: gl.TEXTURE_WRAP_T,
   267      expectedError: gl.INVALID_ENUM},
   268     {target: gl.TEXTURE_2D,
   269      pname: 0x813A, // GL_TEXTURE_MIN_LOD
   270      expectedError: gl.INVALID_ENUM},
   271     {target: gl.TEXTURE_2D,
   272      pname: gl.TEXTURE_WRAP_T,
   273      expectedError: gl.NO_ERROR} ];
   275 for (var ii = 0; ii < testCases.length; ++ii)
   276     testGetTexParameter(testCases[ii]);
   278 debug("");
   279 debug("Checking CopyTexImage2D: a set of inputs that are valid in GL but invalid in GLES2");
   281 var colorBuffer = null;
   282 var fbo = null;
   284 shouldBeNonNull("fbo = gl.createFramebuffer()");
   285 gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
   286 shouldBeNonNull("colorBuffer = gl.createRenderbuffer()");
   287 gl.bindRenderbuffer(gl.RENDERBUFFER, colorBuffer);
   288 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, colorBuffer);
   289 glErrorShouldBe(gl, gl.NO_ERROR);
   291 testCases =
   292   [ {target: gl.TEXTURE_2D,
   293      colorBufferFormat: gl.RGB565,
   294      internalFormat: 0x8054, // GL_RGB16
   295      border: 0,
   296      expectedError: gl.INVALID_ENUM},
   297     {target: gl.TEXTURE_2D,
   298      colorBufferFormat: gl.RGB565,
   299      internalFormat: gl.RGBA,
   300      border: 1,
   301      expectedError: gl.INVALID_VALUE},
   302     {target: gl.TEXTURE_2D,
   303      colorBufferFormat: gl.RGB565,
   304      internalFormat: gl.RGBA,
   305      border: 0,
   306      expectedError: gl.INVALID_OPERATION},
   307     {target: gl.TEXTURE_2D,
   308      colorBufferFormat: gl.RGB565,
   309      internalFormat: gl.RGB,
   310      border: 0,
   311      expectedError: gl.NO_ERROR} ];
   313 for (var ii = 0; ii < testCases.length; ++ii)
   314     testCopyTexImage2D(testCases[ii]);
   316 debug("");
   317 debug("Checking CopyTexSubImage2D: a set of inputs that are valid in GL but invalid in GLES2");
   319 testCases =
   320   [ {target: gl.TEXTURE_2D,
   321      colorBufferFormat: gl.RGB5_A1,
   322      internalFormat: gl.RGBA,
   323      expectedError: gl.NO_ERROR},
   324     {target: gl.TEXTURE_2D,
   325      colorBufferFormat: gl.RGB565,
   326      internalFormat: gl.RGBA,
   327      expectedError: gl.INVALID_OPERATION} ];
   329 for (var ii = 0; ii < testCases.length; ++ii)
   330     testCopyTexSubImage2D(testCases[ii]);
   332 debug("");
   333 debug("Checking CopyTex{Sub}Image2D: copy from WebGL internal framebuffer");
   335 testCases =
   336   [ {contextAlpha: true,
   337      internalFormat: gl.RGBA,
   338      subImage: false,
   339      expectedError: gl.NO_ERROR},
   340     {contextAlpha: false,
   341      internalFormat: gl.RGBA,
   342      subImage: false,
   343      expectedError: gl.INVALID_OPERATION},
   344     {contextAlpha: true,
   345      internalFormat: gl.RGBA,
   346      subImage: true,
   347      expectedError: gl.NO_ERROR},
   348     {contextAlpha: false,
   349      internalFormat: gl.RGBA,
   350      subImage: true,
   351      expectedError: gl.INVALID_OPERATION} ];
   353 for (var ii = 0; ii < testCases.length; ++ii)
   354     testCopyFromInternalFBO(testCases[ii]);
   356 successfullyParsed = true;
   357 </script>
   359 <script>finishTest();</script>
   360 </body>
   361 </html>

mercurial