# all files / src/compositor/ SceneNode.js

2.94% Statements 1/34
0% Branches 0/12
0% Functions 0/2
2.94% Lines 1/34

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96

    1×

     import CompositorNode from './CompositorNode';
    import glenum from '../core/glenum';
    import FrameBuffer from '../FrameBuffer';

    /**
     * @constructor clay.compositor.SceneNode
     * @extends clay.compositor.CompositorNode
     */
    var SceneNode = CompositorNode.extend(
    /** @lends clay.compositor.SceneNode# */
    {
        name: 'scene',
        /**
         * @type {clay.Scene}
         */
        scene: null,
        /**
         * @type {clay.Camera}
         */
        camera: null,
        /**
         * @type {boolean}
         */
        autoUpdateScene: true,
        /**
         * @type {boolean}
         */
        preZ: false

    }, function() {
        this.frameBuffer = new FrameBuffer();
    }, {
        render: function(renderer) {

            this._rendering = true;
            var _gl = renderer.gl;

            this.trigger('beforerender');

            var renderInfo;

            if (!this.outputs) {

                renderInfo = renderer.render(this.scene, this.camera, !this.autoUpdateScene, this.preZ);

            }
            else {

                var frameBuffer = this.frameBuffer;
                for (var name in this.outputs) {
                    var parameters = this.updateParameter(name, renderer);
                    var outputInfo = this.outputs[name];
                    var texture = this._compositor.allocateTexture(parameters);
                    this._outputTextures[name] = texture;

                    var attachment = outputInfo.attachment || _gl.COLOR_ATTACHMENT0;
                    if (typeof(attachment) == 'string') {
                        attachment = _gl[attachment];
                    }
                    frameBuffer.attach(texture, attachment);
                }
                frameBuffer.bind(renderer);

                // MRT Support in chrome
                // https://www.khronos.org/registry/webgl/sdk/tests/conformance/extensions/ext-draw-buffers.html
                var ext = renderer.getGLExtension('EXT_draw_buffers');
                if (ext) {
                    var bufs = [];
                    for (var attachment in this.outputs) {
                        attachment = parseInt(attachment);
                        if (attachment >= _gl.COLOR_ATTACHMENT0 && attachment <= _gl.COLOR_ATTACHMENT0 + 8) {
                            bufs.push(attachment);
                        }
                    }
                    ext.drawBuffersEXT(bufs);
                }

                // Always clear
                // PENDING
                renderer.saveClear();
                renderer.clearBit = glenum.DEPTH_BUFFER_BIT | glenum.COLOR_BUFFER_BIT;
                renderInfo = renderer.render(this.scene, this.camera, !this.autoUpdateScene, this.preZ);
                renderer.restoreClear();

                frameBuffer.unbind(renderer);
            }

            this.trigger('afterrender', renderInfo);

            this._rendering = false;
            this._rendered = true;
        }
    });

    export default SceneNode;