Skip to content

Commit 036bc66

Browse files
committed
Merge commit 'ee0fe215121c8da9625b6e9fe68fbea6248e4c4e' into eugene-gpujs#4-async-api
2 parents d4271ed + ee0fe21 commit 036bc66

2 files changed

Lines changed: 33 additions & 8 deletions

File tree

src/backend/functionNode_webgl.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var functionNode_webgl = (function() {
44
var gpu, opt, jsFunctionString;
55

66
function isIdentifierConstant(paramName) {
7+
if (!opt.constants) return false;
78
return opt.constants.indexOf(paramName) != -1;
89
}
910

@@ -38,6 +39,9 @@ var functionNode_webgl = (function() {
3839
function functionNode_webgl( inNode, _opt ) {
3940
gpu = inNode.gpu;
4041
opt = _opt;
42+
if (opt.debug) {
43+
console.log(inNode);
44+
}
4145
jsFunctionString = inNode.jsFunctionString;
4246
inNode.webglFunctionString_array = ast_generic( inNode.getJS_AST(), [], inNode );
4347
inNode.webglFunctionString = webgl_regex_optimize(
@@ -289,6 +293,8 @@ var functionNode_webgl = (function() {
289293
///
290294
/// @returns the appened retArr
291295
function ast_BinaryExpression(ast, retArr, funcParam) {
296+
retArr.push("(");
297+
292298
if (ast.operator == "%") {
293299
retArr.push("mod(");
294300
ast_generic(ast.left, retArr, funcParam);
@@ -301,6 +307,8 @@ var functionNode_webgl = (function() {
301307
ast_generic(ast.right, retArr, funcParam);
302308
}
303309

310+
retArr.push(")");
311+
304312
return retArr;
305313
}
306314

@@ -377,8 +385,12 @@ var functionNode_webgl = (function() {
377385
retArr.push(forNode.test.operator);
378386
ast_generic(forNode.test.right, retArr, funcParam);
379387
retArr.push(") {\n");
380-
for (var i = 0; i < forNode.body.body.length; i++) {
381-
ast_generic(forNode.body.body[i], retArr, funcParam);
388+
if (forNode.body.type == "BlockStatement") {
389+
for (var i = 0; i < forNode.body.body.length; i++) {
390+
ast_generic(forNode.body.body[i], retArr, funcParam);
391+
}
392+
} else {
393+
ast_generic(forNode.body, retArr, funcParam);
382394
}
383395
retArr.push("} else {\n");
384396
retArr.push("break;\n");
@@ -494,11 +506,23 @@ var functionNode_webgl = (function() {
494506
retArr.push("if(");
495507
ast_generic(ifNode.test, retArr, funcParam);
496508
retArr.push(")");
497-
ast_generic(ifNode.consequent, retArr, funcParam);
509+
if (ifNode.consequent.type == "BlockStatement") {
510+
ast_generic(ifNode.consequent, retArr, funcParam);
511+
} else {
512+
retArr.push(" {\n");
513+
ast_generic(ifNode.consequent, retArr, funcParam);
514+
retArr.push("\n}\n");
515+
}
498516

499517
if (ifNode.alternate) {
500518
retArr.push("else ");
501-
ast_generic(ifNode.alternate, retArr, funcParam);
519+
if (ifNode.alternate.type == "BlockStatement") {
520+
ast_generic(ifNode.alternate, retArr, funcParam);
521+
} else {
522+
retArr.push(" {\n");
523+
ast_generic(ifNode.alternate, retArr, funcParam);
524+
retArr.push("\n}\n");
525+
}
502526
}
503527
return retArr;
504528

src/backend/mode_gpu.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,8 @@
449449
var textureCount = 0;
450450
for (textureCount=0; textureCount<paramNames.length; textureCount++) {
451451
var paramDim, paramSize, texture;
452-
if (Array.isArray(arguments[textureCount])) {
452+
var argType = getArgumentType(arguments[textureCount]);
453+
if (argType == "Array") {
453454
paramDim = getDimensions(arguments[textureCount], true);
454455
paramSize = dimToTexSize(gpu, paramDim);
455456

@@ -489,11 +490,11 @@
489490
gl.uniform2fv(paramSizeLoc, paramSize);
490491
}
491492
gl.uniform1i(paramLoc, textureCount);
492-
} else if (typeof arguments[textureCount] == "number") {
493+
} else if (argType == "Number") {
493494
var argLoc = gl.getUniformLocation(program, "user_"+paramNames[textureCount]);
494495
gl.uniform1f(argLoc, arguments[textureCount]);
495-
} else if (arguments[textureCount] instanceof GPUTexture) {
496-
paramDim = getDimensions(arguments[textureCount]);
496+
} else if (argType == "Texture") {
497+
paramDim = getDimensions(arguments[textureCount], true);
497498
paramSize = arguments[textureCount].size;
498499
texture = arguments[textureCount].texture;
499500
textures[textureCount] = texture;

0 commit comments

Comments
 (0)