aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-06-06 16:46:12 -0700
committerAlon Zakai <alonzakai@gmail.com>2014-06-06 16:46:12 -0700
commit5e981894dd503ec8767aefa9225b349a03dd2ab3 (patch)
tree4707e01a78a532f730d88d6cd649b0dd975cc250 /src
parent9d2476894382e8e71aff70f32d0c32cc9bad1b55 (diff)
remote creators, shaderSource
Diffstat (limited to 'src')
-rw-r--r--src/webGLClient.js25
-rw-r--r--src/webGLWorker.js8
2 files changed, 28 insertions, 5 deletions
diff --git a/src/webGLClient.js b/src/webGLClient.js
index a0cc7b7d..ad55acc4 100644
--- a/src/webGLClient.js
+++ b/src/webGLClient.js
@@ -1,6 +1,14 @@
// WebGLWorker client code
function WebGLClient() {
+ var objects = {};
+
+ function fixArgs(command, args) {
+ switch (command) {
+ case 'shaderSource': args[0] = objects[args[0]]; break;
+ }
+ }
+
function renderCommands(buffer) {
var ctx = Module.ctx;
var i = 0;
@@ -8,9 +16,20 @@ function WebGLClient() {
while (i < len) {
var command = buffer[i++];
var numArgs = buffer[i++];
- var args = buffer.slice(i, i+numArgs);
- i += numArgs;
- ctx[command].apply(ctx, args);
+ if (numArgs === 0) {
+ ctx[command]();
+ } else if (numArgs > 0) {
+ var args = fixArgs(command, buffer.slice(i, i+numArgs));
+ i += numArgs;
+ ctx[command].apply(ctx, args);
+ } else {
+ // negative means a constructor, last argument is the id to save as
+ numArgs = -numArgs - 1;
+ var args = fixArgs(command, buffer.slice(i, i+numArgs));
+ i += numArgs;
+ var id = buffer[i++];
+ objects[id] = ctx[command].apply(ctx, args);
+ }
}
}
diff --git a/src/webGLWorker.js b/src/webGLWorker.js
index 08b72e01..3457f097 100644
--- a/src/webGLWorker.js
+++ b/src/webGLWorker.js
@@ -489,8 +489,12 @@ function WebGLWorker() {
commandBuffer.push('clearColor', 4, r, g, b, a);
};
this.createShader = function(type) {
- commandBuffer.push('createShader', 1, type);
- return { id: nextId++, what: 'shader', type: type };
+ var id = nextId++;
+ commandBuffer.push('createShader', -2, type, id);
+ return { id: id, what: 'shader', type: type };
+ }
+ this.shaderSource = function(shader, source) {
+ commandBuffer.push('shaderSource', 2, shader.id, source);
}
// Setup