Skip to content

Commit

Permalink
fix(shader-ast-glsl): fix #319, update uint handling
Browse files Browse the repository at this point in the history
- add 'u' prefix for uint literals
- add/update tests
  • Loading branch information
postspectacular committed Oct 7, 2021
1 parent 936cdcb commit d8d1b96
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/shader-ast-glsl/src/target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,9 @@ export const targetGLSL = (opts?: Partial<GLSLOpts>) => {
case "float":
return isNumber(v) ? ff(v) : `float(${emit(v)})`;
case "int":
case "uint":
return isNumber(v) ? String(v) : `${t.type}(${emit(v)})`;
case "uint":
return isNumber(v) ? `${v}u` : `${t.type}(${emit(v)})`;
default: {
if (isVec(t) || isMat(t)) {
return `${t.type}(${$list(v)})`;
Expand Down
16 changes: 13 additions & 3 deletions packages/shader-ast-glsl/test/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
$,
bool,
FALSE,
float,
input,
Expand Down Expand Up @@ -42,15 +43,24 @@ group("shader-ast (glsl)", {
lit: () => {
assert.strictEqual(fs300(TRUE), "true");
assert.strictEqual(fs300(FALSE), "false");
assert.strictEqual(fs300(bool(1)), "true");
assert.strictEqual(fs300(bool(int(1))), "bool(1)");
assert.strictEqual(fs300(bool(uint(1))), "bool(1u)");
assert.strictEqual(fs300(bool(float(1))), "bool(1.0)");
assert.strictEqual(fs300(float(0)), "0.0");
assert.strictEqual(fs300(float(-1)), "-1.0");
assert.strictEqual(fs300(float(uint(1))), "float(1u)");
assert.strictEqual(fs300(float(3.1415)), "3.1415");
assert.strictEqual(fs300(int(false)), "0");
assert.strictEqual(fs300(int(true)), "1");
assert.strictEqual(fs300(int(0)), "0");
assert.strictEqual(fs300(int(-1)), "-1");
assert.strictEqual(fs300(int(3.1415)), "3");
assert.strictEqual(fs300(uint(0)), "0");
assert.strictEqual(fs300(uint(-1)), "4294967295");
assert.strictEqual(fs300(uint(3.1415)), "3");
assert.strictEqual(fs300(uint(false)), "0u");
assert.strictEqual(fs300(uint(true)), "1u");
assert.strictEqual(fs300(uint(0)), "0u");
assert.strictEqual(fs300(uint(-1)), "4294967295u");
assert.strictEqual(fs300(uint(3.1415)), "3u");
},

vec2: () => {
Expand Down

0 comments on commit d8d1b96

Please sign in to comment.