summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance/uniforms/uniform-samplers-test.html
blob: fc680c0eaae90c2ae57d1ce959d78b848ce7a9ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!--
Copyright (c) 2019 The Khronos Group Inc.
Use of this source code is governed by an MIT-style license that can be
found in the LICENSE.txt file.
-->

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL sampler uniforms conformance test.</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/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.");

  var canvas2d = document.getElementById("canvas2d");

  var wtu = WebGLTestUtils;
  var gl = wtu.create3DContext("example");
  var program = wtu.setupTexturedQuad(gl);

  var textureLoc = gl.getUniformLocation(program, "tex");

  gl.uniform1i(textureLoc, 1);
  wtu.glErrorShouldBe(gl, gl.NO_ERROR,
      "uniform1i can set a sampler uniform");
  gl.uniform1iv(textureLoc, [1]);
  wtu.glErrorShouldBe(gl, gl.NO_ERROR,
      "uniform1iv can set a sampler uniform");
  gl.uniform1f(textureLoc, 1);
  wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION,
      "uniform1f returns INVALID_OPERATION if attempting to set a sampler uniform");
  gl.uniform1fv(textureLoc, [1]);
  wtu.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 testUniformi = function() {
    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 testUniformiv = function() {
    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 steps = [
    testUniformi,
    testUniformiv,
  ];

  var generateInvalidUniformiTests = function(start, end) {
    return function() {
      var success = true;
      for (var ii = start; ii < end; ++ii) {
        gl.uniform1i(textureLoc, ii);
        success = success && (gl.getError() == gl.INVALID_VALUE);
      }
      expectTrue(success, "uniform1i generates INVALID_VALUE for invalid texture units 0x" + start.toString(16) + " to 0x" + end.toString(16));
    };
  };

  var generateInvalidUniformivTests = function(start, end) {
    return function() {
      var success = true;
      for (var ii = start; ii < end; ++ii) {
        gl.uniform1iv(textureLoc, [ii]);
        success = success && (gl.getError() == gl.INVALID_VALUE);
      }
      expectTrue(success, "uniform1iv generates INVALID_VALUE for invalid texture units 0x" + start.toString(16) + " to 0x" + end.toString(16));
    };
  };

  var step = 0x1000;
  for (var ii = maxTextureUnits; ii < 0x10000; ii += step) {
    steps.push(generateInvalidUniformiTests(ii, ii + step));
    steps.push(generateInvalidUniformivTests(ii, ii + step));
  }

  steps.push(finishTest);
  wtu.runSteps(steps);
}

init();
var successfullyParsed = true;
</script>
</body>
</html>