Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

binding gl.compressTexImage2D #643

Open
sleep2death opened this issue Aug 16, 2016 · 0 comments
Open

binding gl.compressTexImage2D #643

sleep2death opened this issue Aug 16, 2016 · 0 comments

Comments

@sleep2death
Copy link

sleep2death commented Aug 16, 2016

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!

@sleep2death sleep2death changed the title bing gl.compressTexImage2D binding gl.compressTexImage2D Aug 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant