Skip to content

Commit 1cc035f

Browse files
chore: cleanup
1 parent 342a7b7 commit 1cc035f

File tree

1 file changed

+66
-12
lines changed

1 file changed

+66
-12
lines changed

tests/generator.test.ts

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,76 @@
1-
import { generate, parse } from 'shaderkit'
21
import { describe, it, expect } from 'vitest'
2+
import { generate, parse, minify } from 'shaderkit'
33

44
const glsl = /* glsl */ `#version 300 es
5-
precision mediump float;
6-
#define PLUS(n) n+=1
7-
#define TEST
8-
#if defined(TEST)
9-
const bool isTest=true;
10-
#endif
11-
uniform float foo,bar;uniform sampler2D map;in vec2 vUv;out vec4 pc_FragColor;
12-
#include <three_test>
13-
layout(std140)uniform Uniforms1{mat4 projectionMatrix;mat4 modelViewMatrix;mat3 normalMatrix;float one,two;};layout(std140)uniform Uniforms2{mat4 projectionMatrix;mat4 modelViewMatrix;mat3 normalMatrix;float one,two;}globals;struct LightData{float intensity;vec3 position;float one,two;};uniform LightData Light[4];void main(){vec4 lightNormal=vec4(Light[0].position.xyz*Light[0].intensity,0.0);vec4 clipPosition=projectionMatrix*modelViewMatrix*vec4(0,0,0,1);vec4 clipPositionGlobals=globals.projectionMatrix*globals.modelViewMatrix*vec4(0,0,0,1);if(false){}pc_FragColor=vec4(texture(map,vUv).rgb,0.0);float bar=0.0;pc_FragColor.a+=1.0+bar;}
14-
`.trim()
5+
precision mediump float;
6+
7+
// single line
8+
9+
/*
10+
multiline
11+
*/
12+
13+
#define PLUS (n) \
14+
n += 1
15+
16+
#define TEST // inline comment
17+
#if defined( TEST )
18+
const bool isTest = true;
19+
#endif
20+
21+
uniform float foo, bar;
22+
23+
uniform sampler2D map;
24+
in vec2 vUv;
25+
out vec4 pc_FragColor;
26+
27+
#include <three_test>
28+
29+
layout(std140) uniform Uniforms1 {
30+
mat4 projectionMatrix;
31+
mat4 modelViewMatrix;
32+
mat3 normalMatrix;
33+
float one, two;
34+
};
35+
36+
layout(std140) uniform Uniforms2 {
37+
mat4 projectionMatrix;
38+
mat4 modelViewMatrix;
39+
mat3 normalMatrix;
40+
float one, two;
41+
} globals;
42+
43+
44+
// struct X {
45+
// #if !defined(BLA)
46+
// int y;
47+
// #else
48+
// float z;
49+
// #endif
50+
// };
51+
52+
struct LightData {
53+
float intensity;
54+
vec3 position;
55+
float one, two;
56+
};
57+
uniform LightData Light[4];
58+
59+
void main() {
60+
vec4 lightNormal = vec4(Light[0].position.xyz * Light[0].intensity, 0.0);
61+
vec4 clipPosition = projectionMatrix * modelViewMatrix * vec4(0, 0, 0, 1);
62+
vec4 clipPositionGlobals = globals.projectionMatrix * globals.modelViewMatrix * vec4(0, 0, 0, 1);
63+
if (false) {}
64+
pc_FragColor = vec4(texture(map, vUv).rgb, 0.0);
65+
float bar = 0.0;
66+
pc_FragColor.a += 1.0+bar;
67+
}
68+
`
1569

1670
describe('generator', () => {
1771
it('can handle GLSL', () => {
1872
const program = parse(glsl)
1973
const output = generate(program, { target: 'GLSL' })
20-
expect(output).toBe(glsl)
74+
expect(output).toBe(minify(glsl))
2175
})
2276
})

0 commit comments

Comments
 (0)