Skip to content

Commit 849f8f6

Browse files
committed
fix(glsl): fix array for glsl 1.0
1 parent 8b3f916 commit 849f8f6

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/glsl/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ function handleAssign(node) {
290290
typeAnnotation = init.returnType;
291291
allocation = handleNode(init);
292292
} else {
293-
allocation = handleAlloc(init, typeAnnotation);
293+
allocation = handleAlloc(init, typeAnnotation, name);
294294
}
295295
}
296296

@@ -301,7 +301,7 @@ function handleAssign(node) {
301301
return `${qualifier}${typeAnnotation} ${name}${allocation}`;
302302
}
303303

304-
function handleAlloc(init, typeAnnotation) {
304+
function handleAlloc(init, typeAnnotation, name) {
305305
let allocation = '';
306306
if (init.type === 'CallExpression') {
307307

@@ -325,7 +325,7 @@ function handleAlloc(init, typeAnnotation) {
325325
if (init.arguments.length === 1) {
326326
const [first] = init.arguments;
327327
if (first.type === 'ArrayExpression') {
328-
allocation = ` = ${typeAnnotation}(${first.elements.map(handleNode).join(', ')})`;
328+
allocation = `; ${first.elements.map((n, i) => `${name}[${i}] = ${handleNode(n)}`).join('; ')};`;
329329
} else {
330330
allocation = ` = ${handleNode(init.arguments[0])}`;
331331
}

test/glsl/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ MyType bar;
196196
});
197197

198198
const expected = `
199-
float[2] foo = float[2](1.0, 2.0);
199+
float[2] foo; foo[0] = 1.0; foo[1] = 2.0;
200200
`;
201201

202202
assert.equal(glsl.trim(), expected.trim());
@@ -208,7 +208,7 @@ float[2] foo = float[2](1.0, 2.0);
208208
});
209209

210210
const expected = `
211-
vec2[2] foo = vec2[2](vec2(1.0, 2.0), vec(3.0, 4.0));
211+
vec2[2] foo; foo[0] = vec2(1.0, 2.0); foo[1] = vec(3.0, 4.0);
212212
`;
213213

214214
assert.equal(glsl.trim(), expected.trim());

0 commit comments

Comments
 (0)