summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance/glsl/misc/shader-with-reserved-words.html
blob: fd6953e0fe83660226f0a22e02d03ff775fdb32d (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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<!--
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 GLSL Conformance Tests - Reserved Words</title>
<link rel="stylesheet" href="../../../resources/js-test-style.css"/>
<link rel="stylesheet" href="../../../resources/glsl-feature-tests.css"/>
<script src="../../../js/js-test-pre.js"></script>
<script src="../../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script id="vertexShader0" type="text/something-not-javascript">
struct $replaceMe {
  vec4 $replaceMe;
};
struct Foo {
  $replaceMe $replaceMe;
};
attribute vec4 position;
void main()
{
    Foo f;
    f.$replaceMe.$replaceMe = position;
    gl_Position = f.$replaceMe.$replaceMe;
}
</script>
<script id="fragmentShader0" type="text/something-not-javascript">
precision mediump float;
vec4 $replaceMe() {
    return vec4(0,1,0,1);
}
void main()
{
    gl_FragColor = $replaceMe();
}
</script>
<script id="vertexShader1" type="text/something-not-javascript">
attribute vec4 $replaceMe;
void main()
{
    gl_Position = $replaceMe;
}
</script>
<script id="fragmentShader1" type="text/something-not-javascript">
precision mediump float;
vec4 foo(vec4 $replaceMe) {
  return $replaceMe;
}
void main()
{
    gl_FragColor = foo(vec4(1,0,1,1));
}
</script>
<script id="vertexShader2" type="text/something-not-javascript">
varying vec4 $replaceMe;
attribute vec4 position;
void main()
{
    gl_Position = position;
    $replaceMe = position;
}
</script>
<script id="fragmentShader2" type="text/something-not-javascript">
precision mediump float;
varying vec4 $replaceMe;
void main()
{
    gl_FragColor = $replaceMe;
}
</script>
<script id="vertexShader3" type="text/something-not-javascript">
attribute vec4 position;
void main()
{
    gl_Position = position;
}
</script>
<script id="fragmentShader3" type="text/something-not-javascript">
precision mediump float;
uniform vec4 $replaceMe;
void main()
{
    gl_FragColor = $replaceMe;
}
</script>
<script>
"use strict";
var GLSL_1_0_17_words = [
  "attribute",
  "const",
  "uniform",
  "varying",
  "break",
  "continue",
  "do",
  "for",
  "while",
  "if",
  "else",
  "in",
  "out",
  "inout",
  "float",
  "int",
  "void",
  "bool",
  "true",
  "false",
  "lowp",
  "mediump",
  "highp",
  "precision",
  "invariant",
  "discard",
  "return",
  "mat2",
  "mat3",
  "mat4",
  "vec2",
  "vec3",
  "vec4",
  "ivec2",
  "ivec3",
  "ivec4",
  "bvec2",
  "bvec3",
  "bvec4",
  "sampler2D",
  "samplerCube",
  "struct"
]

var GLSL_1_0_17_FutureWords = [
  "asm",
  "class",
  "union",
  "enum",
  "typedef",
  "template",
  "this",
  "packed",
  "goto",
  "switch",
  "default",
  "inline",
  "noinline",
  "volatile",
  "public",
  "static",
  "extern",
  "external",
  "interface",
  "flat",
  "long",
  "short",
  "double",
  "half",
  "fixed",
  "unsigned",
  "superp",
  "input",
  "output",
  "hvec2",
  "hvec3",
  "hvec4",
  "dvec2",
  "dvec3",
  "dvec4",
  "fvec2",
  "fvec3",
  "fvec4",
  "sampler1D",
  "sampler3D",
  "sampler1DShadow",
  "sampler2DShadow",
  "sampler2DRect",
  "sampler3DRect",
  "sampler2DRectShadow",
  "sizeof",
  "cast",
  "namespace",
  "using",
  "__foo",      // something that has 2 underscores
  "foo__bar",   // something that has 2 underscores
  "gl_foo",     // something that starts with gl_
  "webgl_foo"   // something that starts with webgl_
];

description();

var wtu = WebGLTestUtils;
var gl = wtu.create3DContext();

var reservedWordsLists = [
  GLSL_1_0_17_words,
  GLSL_1_0_17_FutureWords
];

var reservedWords = [];
for (var ii = 0; ii < reservedWordsLists.length; ++ii) {
  var list = reservedWordsLists[ii];
  for (var jj = 0; jj < list.length; ++jj) {
    reservedWords.push(list[jj]);
  }
}

var src = [];
for (var ii = 0; ii < 4; ++ii) {
  var vsrc = document.getElementById("vertexShader" + ii).text;
  var fsrc = document.getElementById("fragmentShader" + ii).text;
  src.push({vsrc: vsrc, fsrc: fsrc});
}

var wordNdx = 0;

function testNextWord() {
  if (wordNdx >= reservedWords.length) {
    finishTest();
    return;
  }
  testWord(reservedWords[wordNdx]);
  ++wordNdx;
  setTimeout(testNextWord, 0);
}
testNextWord();

function testWord(word) {
  debug("");
  debug("testing: " + word);

  for (var ii = 0; ii < src.length; ++ii) {
    var vs = src[ii].vsrc.replace(/\$replaceMe/g, word);
    var fs = src[ii].fsrc.replace(/\$replaceMe/g, word);

    var success = true;
    var program = wtu.loadProgram(gl, vs, fs, function(msg) {
      //debug(msg);
      success = false;
    }, true);
    if (success) {
      testFailed("shader with: '" + word + "' compiled even though it should not");
    } else {
      testPassed("shader with: '" + word + "' correctly failed to compile");
    }
    if (program) {
      gl.deleteProgram(program);
    }
    wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no GL errors");
  }
}

var successfullyParsed = true;
</script>
</body>
</html>