Ejecta
Ejecta copied to clipboard
binding gl.compressTexImage2D
Hi Dominic,
I've decided to bind the 'gl.compressTexImage2D' function which was marked as EJ_BIND_FUNCTION_NOT_IMPLEMENTED, and this is my implement:
EJ_BIND_FUNCTION(compressedTexImage2D, ctx, argc, argv) {
if( argc != 7 ) { return NULL; }
scriptView.currentRenderingContext = renderingContext;
EJ_UNPACK_ARGV(GLenum target, GLint level, GLenum internalformat);
...
EJ_UNPACK_ARGV_OFFSET(3, GLsizei width, GLsizei height, GLint border);
if( JSValueIsObject(ctx, argv[6]) ) {
NSMutableData *data = JSObjectGetTypedArrayData(ctx, (JSObjectRef)argv[6]);
NSLog(@"upload array data");
//something **WRONG** here: function JSObjectGetTypedArrayData returned a NULL OBJECT
void *pixels = data.mutableBytes;
glCompressedTexImage2D(target, level, internalformat, width, height, border, size, pixels);
}
...
return NULL;
}
I use pixi-compressed-textures to upload the compressed texture, it handled the mipmap already:
this.generateWebGLTexture = function (gl, preserveSource) {
...
// Loop through each mip level of compressed texture data provided and upload it to the given texture.
for (var i = 0; i < this.levels; ++i) {
// Determine how big this level of compressed texture data is in bytes.
var levelSize = textureLevelSize(this.internalFormat, width, height);
// Get a view of the bytes for this level of DXT data.
var dxtLevel = new Uint8Array(this.data.buffer, this.data.byteOffset + offset, levelSize);
// Upload!
gl.compressedTexImage2D(gl.TEXTURE_2D, i, this.internalFormat, width, height, 0, dxtLevel);
...
};
How can I get the correct compressed data from javascript? Thanks!