dist/claygl.es.js
function (renderer) {

        if (renderer.__currentFrameBuffer) {
            // Already bound
            if (renderer.__currentFrameBuffer === this) {
                return;
            }

            console.warn('Renderer already bound with another framebuffer. Unbind it first');
        }
        renderer.__currentFrameBuffer = this;

        var _gl = renderer.gl;

        _gl.bindFramebuffer(GL_FRAMEBUFFER, this._getFrameBufferGL(renderer));
        this._boundRenderer = renderer;
        var cache = this._cache;

        cache.put('viewport', renderer.viewport);

        var hasTextureAttached = false;
        var width;
        var height;
        for (var attachment in this._textures) {
            hasTextureAttached = true;
            var obj = this._textures[attachment];
            if (obj) {
                // TODO Do width, height checking, make sure size are same
                width = obj.texture.width;
                height = obj.texture.height;
                // Attach textures
                this._doAttach(renderer, obj.texture, attachment, obj.target);
            }
        }

        this._width = width;
        this._height = height;

        if (!hasTextureAttached && this.depthBuffer) {
            console.error('Must attach texture before bind, or renderbuffer may have incorrect width and height.');
        }

        if (this.viewport) {
            renderer.setViewport(this.viewport);
        }
        else {
            renderer.setViewport(0, 0, width, height, 1);
        }

        var attachedTextures = cache.get('attached_textures');
        if (attachedTextures) {
            for (var attachment in attachedTextures) {
                if (!this._textures[attachment]) {
                    var target = attachedTextures[attachment];
                    this._doDetach(_gl, attachment, target);
                }
            }
        }
        if (!cache.get(KEY_DEPTHTEXTURE_ATTACHED) && this.depthBuffer) {
            // Create a new render buffer
            if (cache.miss(KEY_RENDERBUFFER)) {
                cache.put(KEY_RENDERBUFFER, _gl.createRenderbuffer());
            }
            var renderbuffer = cache.get(KEY_RENDERBUFFER);

            if (width !== cache.get(KEY_RENDERBUFFER_WIDTH)
                    || height !== cache.get(KEY_RENDERBUFFER_HEIGHT)) {
                _gl.bindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
                _gl.renderbufferStorage(GL_RENDERBUFFER, _gl.DEPTH_COMPONENT16, width, height);
                cache.put(KEY_RENDERBUFFER_WIDTH, width);
                cache.put(KEY_RENDERBUFFER_HEIGHT, height);
                _gl.bindRenderbuffer(GL_RENDERBUFFER, null);
            }
            if (!cache.get(KEY_RENDERBUFFER_ATTACHED)) {
                _gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderbuffer);
                cache.put(KEY_RENDERBUFFER_ATTACHED, true);
            }
        }
    }
function (renderer) {

        if (renderer.__currentFrameBuffer) {
            // Already bound
            if (renderer.__currentFrameBuffer === this) {
                return;
            }

            console.warn('Renderer already bound with another framebuffer. Unbind it first');
        }
        renderer.__currentFrameBuffer = this;

        var _gl = renderer.gl;

        _gl.bindFramebuffer(GL_FRAMEBUFFER, this._getFrameBufferGL(renderer));
        this._boundRenderer = renderer;
        var cache = this._cache;

        cache.put('viewport', renderer.viewport);

        var hasTextureAttached = false;
        var width;
        var height;
        for (var attachment in this._textures) {
            hasTextureAttached = true;
            var obj = this._textures[attachment];
            if (obj) {
                // TODO Do width, height checking, make sure size are same
                width = obj.texture.width;
                height = obj.texture.height;
                // Attach textures
                this._doAttach(renderer, obj.texture, attachment, obj.target);
            }
        }

        this._width = width;
        this._height = height;

        if (!hasTextureAttached && this.depthBuffer) {
            console.error('Must attach texture before bind, or renderbuffer may have incorrect width and height.');
        }

        if (this.viewport) {
            renderer.setViewport(this.viewport);
        }
        else {
            renderer.setViewport(0, 0, width, height, 1);
        }

        var attachedTextures = cache.get('attached_textures');
        if (attachedTextures) {
            for (var attachment in attachedTextures) {
                if (!this._textures[attachment]) {
                    var target = attachedTextures[attachment];
                    this._doDetach(_gl, attachment, target);
                }
            }
        }
        if (!cache.get(KEY_DEPTHTEXTURE_ATTACHED) && this.depthBuffer) {
            // Create a new render buffer
            if (cache.miss(KEY_RENDERBUFFER)) {
                cache.put(KEY_RENDERBUFFER, _gl.createRenderbuffer());
            }
            var renderbuffer = cache.get(KEY_RENDERBUFFER);

            if (width !== cache.get(KEY_RENDERBUFFER_WIDTH)
                    || height !== cache.get(KEY_RENDERBUFFER_HEIGHT)) {
                _gl.bindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
                _gl.renderbufferStorage(GL_RENDERBUFFER, _gl.DEPTH_COMPONENT16, width, height);
                cache.put(KEY_RENDERBUFFER_WIDTH, width);
                cache.put(KEY_RENDERBUFFER_HEIGHT, height);
                _gl.bindRenderbuffer(GL_RENDERBUFFER, null);
            }
            if (!cache.get(KEY_RENDERBUFFER_ATTACHED)) {
                _gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderbuffer);
                cache.put(KEY_RENDERBUFFER_ATTACHED, true);
            }
        }
    }
function ( renderer ) { if ( renderer . __currentFrameBuffer ) { // Already bound if ( renderer . __currentFrameBuffer === this ) { return ; } console . warn ( 'Renderer already bound with another framebuffer. Unbind it first' ) ; } renderer . __currentFrameBuffer = this ; var _gl = renderer . gl ; _gl . bindFramebuffer ( GL_FRAMEBUFFER , this . _getFrameBufferGL ( renderer ) ) ; this . _boundRenderer = renderer ; var cache = this . _cache ; cache . put ( 'viewport' , renderer . viewport ) ; var hasTextureAttached = false ; var width ; var height ; for ( var attachment in this . _textures ) { hasTextureAttached = true ; var obj = this . _textures [ attachment ] ; if ( obj ) { // TODO Do width, height checking, make sure size are same width = obj . texture . width ; height = obj . texture . height ; // Attach textures this . _doAttach ( renderer , obj . texture , attachment , obj . target ) ; } } this . _width = width ; this . _height = height ; if ( ! hasTextureAttached && this . depthBuffer ) { console . error ( 'Must attach texture before bind, or renderbuffer may have incorrect width and height.' ) ; } if ( this . viewport ) { renderer . setViewport ( this . viewport ) ; } else { renderer . setViewport ( 0 , 0 , width , height , 1 ) ; } var attachedTextures = cache . get ( 'attached_textures' ) ; if ( attachedTextures ) { for ( var attachment in attachedTextures ) { if ( ! this . _textures [ attachment ] ) { var target = attachedTextures [ attachment ] ; this . _doDetach ( _gl , attachment , target ) ; } } } if ( ! cache . get ( KEY_DEPTHTEXTURE_ATTACHED ) && this . depthBuffer ) { // Create a new render buffer if ( cache . miss ( KEY_RENDERBUFFER ) ) { cache . put ( KEY_RENDERBUFFER , _gl . createRenderbuffer ( ) ) ; } var renderbuffer = cache . get ( KEY_RENDERBUFFER ) ; if ( width !== cache . get ( KEY_RENDERBUFFER_WIDTH ) || height !== cache . get ( KEY_RENDERBUFFER_HEIGHT ) ) { _gl . bindRenderbuffer ( GL_RENDERBUFFER , renderbuffer ) ; _gl . renderbufferStorage ( GL_RENDERBUFFER , _gl . DEPTH_COMPONENT16 , width , height ) ; cache . put ( KEY_RENDERBUFFER_WIDTH , width ) ; cache . put ( KEY_RENDERBUFFER_HEIGHT , height ) ; _gl . bindRenderbuffer ( GL_RENDERBUFFER , null ) ; } if ( ! cache . get ( KEY_RENDERBUFFER_ATTACHED ) ) { _gl . framebufferRenderbuffer ( GL_FRAMEBUFFER , GL_DEPTH_ATTACHMENT , GL_RENDERBUFFER , renderbuffer ) ; cache . put ( KEY_RENDERBUFFER_ATTACHED , true ) ; } } }
Bind the framebuffer to given renderer before rendering
@param  {clay.Renderer} renderer
Bind the framebuffer to given renderer before rendering