6 Copyright (c) 2019 The Khronos Group Inc.
7 Use of this source code is governed by an MIT-style license that can be
8 found in the LICENSE.txt file.
10 <link rel=
"stylesheet" type=
"text/css" href=
"../unit.css" />
11 <script type=
"application/javascript" src=
"../unit.js"></script>
12 <script type=
"application/javascript" src=
"../util.js"></script>
13 <script type=
"application/javascript">
15 Tests.startUnit = function () {
16 var canvas = document.getElementById('gl');
17 var gl = getGLContext(canvas);
21 Tests.testOk = function(gl) {
22 var sh = new Filter(gl, 'okvert', 'frag');
23 assertOk(function(){sh.apply();});
26 var sh = new Filter(gl, 'vert', 'okfrag');
27 assertOk(function(){sh.apply();});
30 var sh = new Filter(gl, 'vert', 'frag');
31 assertOk(function(){sh.apply();});
35 var arr = ['cr', 'cw', 'vr', 'vw'];
36 arr.forEach(function(e){
37 if (e == 'cr' || e == 'cw') {
38 Tests['test'+e+'vert'] = function(gl) {
39 var sh = new Filter(gl, e+'vert', 'frag');
40 assertFail(function(){sh.apply();});
44 Tests['test'+e+'frag'] = function(gl) {
45 var sh = new Filter(gl, 'vert', e+'frag');
46 assertFail(function(){sh.apply();});
53 <script id=
"okvert" type=
"x-shader/x-vertex">
56 attribute vec3 Vertex;
58 varying vec2 TexCoord;
66 gl_Position = vec4(Vertex, x[
2]);
69 <script id=
"crvert" type=
"x-shader/x-vertex">
72 attribute vec3 Vertex;
74 varying vec2 TexCoord;
82 gl_Position = vec4(Vertex, x[
4]);
85 <script id=
"cwvert" type=
"x-shader/x-vertex">
88 attribute vec3 Vertex;
90 varying vec2 TexCoord;
99 gl_Position = vec4(Vertex, x[
4]);
102 <!-- This one can't be required to fail compilation, because vertex shaders must support arbitrary array indexing -->
103 <script id=
"vrvert" type=
"x-shader/x-vertex">
106 attribute vec3 Vertex;
108 varying vec2 TexCoord;
116 int idx =
4 * int(max(
1.0, Vertex.x*
20.0));
117 gl_Position = vec4(Vertex, x[idx]);
120 <!-- This one can't be required to fail compilation, because vertex shaders must support arbitrary array indexing -->
121 <script id=
"vwvert" type=
"x-shader/x-vertex">
124 attribute vec3 Vertex;
126 varying vec2 TexCoord;
134 int idx =
4 * int(max(
1.0, Vertex.x*
20.0));
136 gl_Position = vec4(Vertex, x[idx]);
139 <script id=
"vert" type=
"x-shader/x-vertex">
142 attribute vec3 Vertex;
144 varying vec2 TexCoord;
148 gl_Position = vec4(Vertex,
0.0);
152 <script id=
"okfrag" type=
"x-shader/x-fragment">
155 precision mediump float;
157 varying vec2 TexCoord;
165 gl_FragColor = vec4(
1.0,
0.0, TexCoord.s, x[
2]);
168 <script id=
"crfrag" type=
"x-shader/x-fragment">
171 precision mediump float;
173 varying vec2 TexCoord;
181 gl_FragColor = vec4(
1.0,
0.0, TexCoord.s, x[
4]);
184 <script id=
"cwfrag" type=
"x-shader/x-fragment">
187 precision mediump float;
189 varying vec2 TexCoord;
199 gl_FragColor = vec4(
1.0,
0.0, TexCoord.s, x[
4]);
202 <!-- This one actually fails because of WebGL's restrictions on indexing expressions in fragment shaders -->
203 <script id=
"vrfrag" type=
"x-shader/x-fragment">
206 precision mediump float;
208 varying vec2 TexCoord;
217 int idx =
4 * int(max(
1.0, TexCoord.x*
20.0));
218 gl_FragColor = vec4(
1.0,
0.0, TexCoord.s, x[idx]);
221 <!-- This one actually fails because of WebGL's restrictions on indexing expressions in fragment shaders -->
222 <script id=
"vwfrag" type=
"x-shader/x-fragment">
225 precision mediump float;
227 varying vec2 TexCoord;
236 int idx =
4 * int(max(
1.0, TexCoord.x*
20.0));
238 gl_FragColor = vec4(
1.0,
0.0, TexCoord.s, x[idx]);
241 <script id=
"frag" type=
"x-shader/x-fragment">
244 precision mediump float;
246 varying vec2 TexCoord;
250 gl_FragColor = vec4(
1.0,
0.0, TexCoord.s,
1.0);
255 <style>canvas{ position:absolute; }
</style>
257 <canvas id=
"gl" width=
"16" height=
"16"></canvas>