evanw / glfx.js

An image effects library for JavaScript using WebGL
https://evanw.github.io/glfx.js/
MIT License
3.28k stars 403 forks source link

Wrong global context with multiple canvases and dynamic textures #11

Closed inear closed 11 years ago

inear commented 12 years ago

Hi!

When using multiple instances and updating textures the global active context can be wrong if loadContentsOf is fired before the global context has been updated. I solved it by adding a parameter to the texture object and assign it in the wrapper.

In the Texture constructor:

this.gl = gl;

and modify this method:

function wrapTexture(texture) {

return {
    _: texture,
    loadContentsOf: function(element) { 

        //set correct global gl
        gl = this._.gl;

        this._.loadContentsOf(element); 
    },
    clear: function() { this._.clear(); },
    width: function() { return this._.width; },
    height: function() { return this._.height; },
    destroy: function() { this._.destroy(); }
};

}

/ Einar