-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathglslminify_demo.html
104 lines (82 loc) · 2.38 KB
/
glslminify_demo.html
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
<!doctype html>
<html>
<head>
<title>glslminify demo / smoke test</title>
<meta charset="utf-8"></meta>
<style>
body { text-align: center; }
fieldset { display: inline-block; }
.io { display: block; float: left; min-width: 380px; margin-left: 4px; }
label {display: block; }
textarea { display: inline-block; min-width: 370px; height: 350px; }
button { margin: 15px; }
</style>
<!--
<script src="src/goog/base.js"></script>
<script src="src/goog/deps.js"></script>
<script>
goog.ENABLE_DEBUG_LOADER = true;
goog.require('glslminify');
</script>
-->
<!-- -->
<script src="glslminify.min.js"></script>
<!-- -->
</head>
<body>
<form name="input">
<fieldset>
<legend>Input</legend>
<div class="io">
<label for="vertexShader">Vertex Shader:</label>
<textarea name="vertexShader">void main(void) {
gl_Position = vec4(0.0);
}</textarea>
</div>
<div class="io">
<label for="fragmentShader">Fragment Shader:</label>
<textarea name="fragmentShader">void main(void) {
gl_FragColor = vec4(0.0);
}</textarea>
</div>
</fieldset>
</form>
<button>Minify</button>
<form name="output">
<fieldset>
<legend>Output</legend>
<div class="io">
<label for="vertexShaderOut">Vertex Shader (output):</label>
<textarea name="vertexShaderOut" readonly="readonly"></textarea>
</div>
<div class="io">
<label for="fragmentShaderOut">Fragment Shader (output):</label>
<textarea name="fragmentShaderOut" readonly="readonly"></textarea>
</div>
</fieldset>
</form>
<script>
function run() {
var shader = [
document.getElementsByName('vertexShader')[0].value,
document.getElementsByName('fragmentShader')[0].value
];
var defines = { ANSWER: 42 };
try {
glslminify.minifyGlsl(shader, defines);
} catch (e) {
if (e instanceof glslminify.SyntaxError)
window.alert(e.line + ":" + e.column + ": " + e.message);
else {
console.error(e.stack || e);
window.alert("Unexpected error (see console for details).");
}
}
document.getElementsByName('vertexShaderOut')[0].value = shader[glslminify.Shader.VERTEX];
document.getElementsByName('fragmentShaderOut')[0].value = shader[glslminify.Shader.FRAGMENT];
}
run();
document.getElementsByTagName('button')[0].addEventListener('click', run);
</script>
</body>
</html>