layabox / LayaAir

LayaAir is a fully platform rendering engine with rich 2D/3D rendering capabilities and a mature integrated development platform

Home Page:https://www.layaair.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

支持自定义shader类型,或者支持扩展渲染节点类型?

yanyuling opened this issue · comments

因技术方案需要通过shader实现渲染效果,查询若干资料无果后,打算参照 Particle2D 扩展新的节点类型;在renderSubmit 接口逻辑的实现中,无法从全局拿到 WebGLContext.mainContext ,导致拓展流程无法进行下去;希望官方抛出 Laya.WebGLContext ,或者其他更好的方案来支持自动以扩展shader的技术方案;以上,不胜感激;
一下源码摘自 ParticleTemplate2D.ts;

`

renderSubmit(): number {
if (this.texture && this.texture.getIsReady()) {
this.update(ILaya.timer._delta);
this.sv.u_CurrentTime = this._currentTime;
if (this._firstNewElement != this._firstFreeElement) {
this.addNewParticlesToVertexBuffer();
}

        this.blend();

        if (this._firstActiveElement != this._firstFreeElement) {
            var gl: WebGLRenderingContext = WebGLContext.mainContext;
            this._mesh.useMesh(gl);
            //_vertexBuffer2D.bind();
            //_indexBuffer2D.bind();
            this.sv.u_texture = this.texture._getSource();
            this.sv.upload();


            if (this._firstActiveElement < this._firstFreeElement) {
                gl.drawElements(gl.TRIANGLES, (this._firstFreeElement - this._firstActiveElement) * 6, gl.UNSIGNED_SHORT, this._firstActiveElement * 6 * 2);
            }
            else {

                WebGLContext.mainContext.drawElements(gl.TRIANGLES, (this.settings.maxPartices - this._firstActiveElement) * 6, gl.UNSIGNED_SHORT, this._firstActiveElement * 6 * 2);
                if (this._firstFreeElement > 0)
                    gl.drawElements(gl.TRIANGLES, this._firstFreeElement * 6, gl.UNSIGNED_SHORT, 0);
            }

            Stat.renderBatches++;
        }
        this._drawCounter++;
    }
    return 1;
}

`