summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance2/textures/misc/texture-npot.html
blob: 1d63130eebb25c6c8cd797d3e7944b59d72c14ee (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<!--
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>WebGL2 Non-Power of 2 texture 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="5" height="3" style="width: 40px; height: 30px;"></canvas>
<div id="description"></div>
<div id="console"></div>
<script id="vshader" type="x-shader/x-vertex">
attribute vec4 vPosition;
attribute vec2 texCoord0;
varying vec2 texCoord;
void main()
{
    gl_Position = vPosition;
    texCoord = texCoord0;
}
</script>

<script id="fshader" type="x-shader/x-fragment">
precision mediump float;
uniform samplerCube tex;
varying vec2 texCoord;
void main()
{
    gl_FragColor = textureCube(tex, normalize(vec3(texCoord, 1)));
}
</script>
<script>
"use strict";
description(document.title);
var wtu = WebGLTestUtils;
var gl = wtu.create3DContext("example", undefined, 2);
var program = wtu.setupTexturedQuad(gl);

wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup.");

var tests = [
  { format: gl.RGBA,
    type: gl.UNSIGNED_BYTE,
    color: [192, 0, 128, 64],
    expected: [192, 0, 128, 64],
    tolerance: 0,
  },
  { format: gl.RGB,
    type: gl.UNSIGNED_BYTE,
    color: [192, 0, 128],
    expected: [192, 0, 128, 255],
    tolerance: 0,
  },
  { format: gl.LUMINANCE,
    type: gl.UNSIGNED_BYTE,
    color: [192],
    expected: [192, 192, 192, 255],
    tolerance: 0,
  },
  { format: gl.ALPHA,
    type: gl.UNSIGNED_BYTE,
    color: [64],
    expected: [0, 0, 0, 64],
    tolerance: 0,
  },
  { format: gl.LUMINANCE_ALPHA,
    type: gl.UNSIGNED_BYTE,
    color: [192, 64],
    expected: [192, 192, 192, 64],
    tolerance: 0,
  },
];

tests.forEach(function(test) {
  debug("");
  debug("test " + wtu.glEnumToString(gl, test.format) + "/" + wtu.glEnumToString(gl, test.type));
  var tex = gl.createTexture();

  // Check that an NPOT texture not on level 0 does not generate INVALID_VALUE
  wtu.fillTexture(gl, tex, 5, 3, test.color, 1, test.format, test.type);
  wtu.glErrorShouldBe(gl, gl.NO_ERROR,
      "gl.texImage2D with NPOT texture with level > 0 should succeed");

  // Check that an NPOT texture on level 0 succeeds
  wtu.fillTexture(gl, tex, 5, 3, test.color, 0, test.format, test.type);
  wtu.glErrorShouldBe(gl, gl.NO_ERROR,
      "gl.texImage2D with NPOT texture at level 0 should succeed");

  // Check that generateMipmap succeeds on NPOT
  gl.generateMipmap(gl.TEXTURE_2D);
  wtu.glErrorShouldBe(gl, gl.NO_ERROR,
      "gl.generateMipmap with NPOT texture should succeed");

  // 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.clearAndDrawUnitQuad(gl);
  wtu.checkCanvas(
      gl, test.expected,
      "NPOT texture with TEXTURE_WRAP set to REPEAT should draw");
  wtu.glErrorShouldBe(gl, 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.clearAndDrawUnitQuad(gl);
  wtu.checkCanvas(
      gl, test.expected,
      "NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw");
  wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup.");

  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);

  wtu.clearAndDrawUnitQuad(gl);
  wtu.checkCanvas(
      gl, test.expected,
      "NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw.");

  gl.copyTexImage2D(gl.TEXTURE_2D, 1, test.format, 0, 0, 5, 3, 0);
  wtu.glErrorShouldBe(gl, gl.NO_ERROR,
      "copyTexImage2D with NPOT texture with level > 0 should succeed.");

  // Check that generateMipmap for an POT texture succeeds
  wtu.fillTexture(gl, tex, 2, 2, test.color, 0, test.format);
  gl.generateMipmap(gl.TEXTURE_2D);
  wtu.glErrorShouldBe(gl, gl.NO_ERROR,
      "gl.texImage2D and gl.generateMipmap with POT texture at level 0 should succeed");

  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);

  wtu.clearAndDrawUnitQuad(gl);
  wtu.checkCanvas(
      gl, test.expected,
      "POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw.");
  wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup.");
});

var successfullyParsed = true;

</script>
<script src="../../../js/js-test-post.js"></script>

</body>
</html>