aboutsummaryrefslogtreecommitdiff
path: root/src/library_gl.js
diff options
context:
space:
mode:
authorEhsan Akhgari <ehsan.akhgari@gmail.com>2012-02-11 18:55:31 -0500
committerEhsan Akhgari <ehsan.akhgari@gmail.com>2012-03-28 10:54:23 -0700
commit69638af60262c11b88802d6b8c1e53433d1baf45 (patch)
tree98d3fc83607353a7f95510d63b0f37805d31c1b6 /src/library_gl.js
parent8625bc968b4f85366eaefafb6556d549040bdb3e (diff)
Implement GL texture functions
Diffstat (limited to 'src/library_gl.js')
-rw-r--r--src/library_gl.js101
1 files changed, 96 insertions, 5 deletions
diff --git a/src/library_gl.js b/src/library_gl.js
index f7c8ca0e..e5fe1c49 100644
--- a/src/library_gl.js
+++ b/src/library_gl.js
@@ -196,16 +196,90 @@ var LibraryGL = {
}
},
+ glCompressedTexImage2D: function(target, level, internalformat, width, height, border, imageSize, data) {
+ if (data) {
+ data = new Uint8Array(Array_copy(data, imageSize));
+ }
+ Module.ctx.compressedTexImage2D(target, level, internalformat, width, height, border, data);
+ },
+
+ glCompressedTexSubImage2D: function(target, level, xoffset, yoffset, width, height, format, imageSize, data) {
+ if (data) {
+ data = new Uint8Array(Array_copy(data, imageSize));
+ }
+ Module.ctx.compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, data);
+ },
+
glTexImage2D: function(target, level, internalformat, width, height, border, format, type, pixels) {
if (pixels) {
- pixels = new Uint8Array(Array_copy(pixels, pixels + width*height*4)); // TODO: optimize
+ var sizePerPixel;
+ switch (type) {
+ case 0x1401 /* GL_UNSIGNED_BYTE */:
+ switch (format) {
+ case 0x1906 /* GL_ALPHA */:
+ case 0x1909 /* GL_LUMINANCE */:
+ sizePerPixel = 1;
+ break;
+ case 0x1907 /* GL_RGB */:
+ sizePerPixel = 3;
+ break;
+ case 0x1908 /* GL_RGBA */:
+ sizePerPixel = 4;
+ break;
+ case 0x190A /* GL_LUMINANCE_ALPHA */:
+ sizePerPixel = 2;
+ break;
+ default:
+ throw 'Invalid format (' + format + ') passed to glTexImage2D';
+ }
+ pixels = new Uint8Array(Array_copy(pixels, width*height*sizePerPixel));
+ break;
+ case 0x8363 /* GL_UNSIGNED_SHORT_5_6_5 */:
+ case 0x8033 /* GL_UNSIGNED_SHORT_4_4_4_4 */:
+ case 0x8034 /* GL_UNSIGNED_SHORT_5_5_5_1 */:
+ sizePerPixel = 2;
+ pixels = new Uint16Array(new ArrayBuffer(Array_copy(pixels, width*height*sizePerPixel*2)));
+ break;
+ default:
+ throw 'Invalid type (' + type + ') passed to glTexImage2D';
+ }
}
Module.ctx.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(Array_copy(pixels, pixels + width*height*4)); // TODO: optimize
+ var sizePerPixel;
+ switch (type) {
+ case 0x1401 /* GL_UNSIGNED_BYTE */:
+ switch (format) {
+ case 0x1906 /* GL_ALPHA */:
+ case 0x1909 /* GL_LUMINANCE */:
+ sizePerPixel = 1;
+ break;
+ case 0x1907 /* GL_RGB */:
+ sizePerPixel = 3;
+ break;
+ case 0x1908 /* GL_RGBA */:
+ sizePerPixel = 4;
+ break;
+ case 0x190A /* GL_LUMINANCE_ALPHA */:
+ sizePerPixel = 2;
+ break;
+ default:
+ throw 'Invalid format (' + format + ') passed to glTexSubImage2D';
+ }
+ pixels = new Uint8Array(Array_copy(pixels, (width-xoffset+1)*(height-yoffset+1)*sizePerPixel));
+ break;
+ case 0x8363 /* GL_UNSIGNED_SHORT_5_6_5 */:
+ case 0x8033 /* GL_UNSIGNED_SHORT_4_4_4_4 */:
+ case 0x8034 /* GL_UNSIGNED_SHORT_5_5_5_1 */:
+ sizePerPixel = 2;
+ pixels = new Uint16Array(new ArrayBuffer(Array_copy(pixels, (width-xoffset+1)*(height-yoffset+1)*sizePerPixel*2)));
+ break;
+ default:
+ throw 'Invalid type (' + type + ') passed to glTexSubImage2D';
+ }
}
Module.ctx.texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
},
@@ -214,6 +288,23 @@ var LibraryGL = {
Module.ctx.bindTexture(target, GL.hashtable("texture").get(texture));
},
+ glGetTexParameterfv: function(target, pname, params) {
+ {{{ makeSetValue('params', '0', 'Module.getTexParameter(target, pname)', 'float') }}};
+ },
+
+ glGetTexParameteriv: function(target, pname, params) {
+ {{{ makeSetValue('params', '0', 'Module.getTexParameter(target, pname)', 'i32') }}};
+ },
+
+ glIsTexture_deps: ['$GL'],
+ glIsTexture: function(texture) {
+ var fb = GL.hashtable("texture").get(texture);
+ if (typeof(fb) == 'undefined') {
+ return false;
+ }
+ return Module.ctx.isTexture(fb);
+ },
+
glGenBuffers__deps: ['$GL'],
glGenBuffers: function(n, buffers) {
for (var i = 0; i < n; i++) {
@@ -582,12 +673,12 @@ var LibraryGL = {
// Simple pass-through functions
[[0, 'shadeModel fogi fogfv getError finish flush'],
- [1, 'clearDepth depthFunc enable disable frontFace cullFace clear enableVertexAttribArray disableVertexAttribArray lineWidth clearStencil depthMask stencilMask stencilMaskSeparate checkFramebufferStatus activeTexture'],
- [2, 'pixelStorei vertexAttrib1f depthRange polygonOffset blendFunc'],
+ [1, 'clearDepth depthFunc enable disable frontFace cullFace clear enableVertexAttribArray disableVertexAttribArray lineWidth clearStencil depthMask stencilMask stencilMaskSeparate checkFramebufferStatus generateMipmap activeTexture'],
[3, 'texParameteri texParameterf drawArrays vertexAttrib2f'],
[4, 'viewport clearColor scissor vertexAttrib3f colorMask drawElements renderbufferStorage'],
[5, 'vertexAttrib4f'],
- [6, 'vertexAttribPointer']].forEach(function(data) {
+ [6, 'vertexAttribPointer'],
+ [8, 'copyTexImage2D copyTexSubImage2D']].forEach(function(data) {
var num = data[0];
var names = data[1];
var args = range(num).map(function(i) { return 'x' + i }).join(', ');