diff options
author | Alon Zakai <alonzakai@gmail.com> | 2011-05-14 21:09:37 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2011-05-14 21:09:37 -0700 |
commit | f66293c6affe4e4c4ddb5ec40dff802dee989094 (patch) | |
tree | 1b30939eae7599027c35e215e22dc6d05cc4916c /src/library_gl.js | |
parent | 9d376d8bde5816e357c702fea6dc463992dab02a (diff) |
library stuff
Diffstat (limited to 'src/library_gl.js')
-rw-r--r-- | src/library_gl.js | 61 |
1 files changed, 51 insertions, 10 deletions
diff --git a/src/library_gl.js b/src/library_gl.js index 3da67c80..8e4159af 100644 --- a/src/library_gl.js +++ b/src/library_gl.js @@ -1,34 +1,75 @@ +// XXX FIXME Hardcoded '4' in many places, here and in library_SDL, for RGBA + var LibraryGL = { + $GL: { + textures: {}, + textureCounter: 0, + }, + glGetString: function(name_) { switch(name_) { - case Module.contextGL.VENDOR: - case Module.contextGL.RENDERER: - case Module.contextGL.VERSION: - return Pointer_make(intArrayFromString(Module.contextGL.getParameter(name_)), null, ALLOC_NORMAL); + case Module.ctxGL.VENDOR: + case Module.ctxGL.RENDERER: + case Module.ctxGL.VERSION: + return Pointer_make(intArrayFromString(Module.ctxGL.getParameter(name_)), null, ALLOC_NORMAL); case 0x1F03: // Extensions - return Pointer_make(intArrayFromString(Module.contextGL.getSupportedExtensions().join(' ')), null, ALLOC_NORMAL); + return Pointer_make(intArrayFromString(Module.ctxGL.getSupportedExtensions().join(' ')), null, ALLOC_NORMAL); default: throw 'Failure: Invalid glGetString value: ' + name_; } }, - glGetIntegerv: function(name_) { + glGetIntegerv: function(name_, p) { switch(name_) { - case Module.contextGL.MAX_TEXTURE_SIZE: - return Module.contextGL.getParameter(name_); + case Module.ctxGL.MAX_TEXTURE_SIZE: + IHEAP[p] = Module.ctxGL.getParameter(name_); + break; default: throw 'Failure: Invalid glGetIntegerv value: ' + name_; } - } + }, + + glGenTextures__deps: ['$GL'], + glGenTextures: function(n, textures) { + for (var i = 0; i < n; i++) { + var id = GL.textureCounter++; + GL.textures[id] = Module.ctxGL.createTexture(); + IHEAP[textures+QUANTUM_SIZE*i] = id; + } + }, + + glDeleteTextures: function(n, textures) { + for (var i = 0; i < n; i++) { + var id = IHEAP[textures+QUANTUM_SIZE*i]; + Module.ctxGL.deleteTexture(GL.textures[id]); + delete GL.textures[id]; + } + }, + + glTexImage2D: function(target, level, internalformat, width, height, border, format, type, pixels) { + if (pixels) { + pixels = new Uint8Array(IHEAP.slice(pixels, pixels + width*height*4)); // TODO: optimize + } + Module.ctxGL.texImage2D(target, level, internalformat, width, height, border, format, type, pixels); + }, + + glTexSubImage2D: function(target, level, xoffset, yoffset, width, height, format, type, pixels) { + if (pixels) { + pixels = new Uint8Array(IHEAP.slice(pixels, pixels + width*height*4)); // TODO: optimize + } + Module.ctxGL.texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels); + }, }; +// Simple pass-through functions [[0, 'shadeModel fogi fogfv'], [1, 'clearDepth depthFunc enable disable frontFace cullFace'], + [2, 'pixelStorei'], [4, 'viewport clearColor']].forEach(function(data) { var num = data[0]; var names = data[1]; var args = range(num).map(function(i) { return 'x' + i }).join(', '); - var stub = '(function(' + args + ') { ' + (num > 0 ? 'Module.contextGL.NAME(' + args + ')' : '') + ' })'; + var stub = '(function(' + args + ') { ' + (num > 0 ? 'Module.ctxGL.NAME(' + args + ')' : '') + ' })'; names.split(' ').forEach(function(name_) { var cName = 'gl' + name_[0].toUpperCase() + name_.substr(1); LibraryGL[cName] = eval(stub.replace('NAME', name_)); |