diff --git a/cocos/gfx/input-assembler.ts b/cocos/gfx/input-assembler.ts index d9a98d9bb8..d6c7242819 100644 --- a/cocos/gfx/input-assembler.ts +++ b/cocos/gfx/input-assembler.ts @@ -138,6 +138,19 @@ export abstract class GFXInputAssembler extends GFXObject { drawInfo.firstInstance = this._firstInstance; } + /** + * update VB data on the fly. + * @param vbuffer - an ArrayBuffer containing the full VB + * @param attr - name of the attribute to update (default names are specified in GFXAttributeName) + * @param data - the new VB attribute data to be uploaded + * @example + * // get VB array buffer from mesh, better to cache this somewhere convenient + * const vbInfo = mesh.struct.vertexBundles[0].data; + * const vbuffer = mesh.data.buffer.slice(vbInfo.offset, vbInfo.offset + vbInfo.length); + * const submodel = someModelComponent.model.getSubModel(0); + * // say the new positions is stored in 'data' as a plain array + * submodel.inputAssembler.updateVertexBuffer(vbuffer, cc.GFXAttributeName.ATTR_POSITION, data); + */ public updateVertexAttr (vbuffer: GFXBufferSource, attr: string, data: number[]) { let offset = 0; let count = 0; @@ -166,6 +179,19 @@ export abstract class GFXInputAssembler extends GFXObject { vb.update(vbuffer); } + /** + * update IB data on the fly. + * need to call submodel.updateCommandBuffer after this if index count changed + * @param ibuffer - an ArrayBuffer containing the full IB + * @param data - the new IB data to be uploaded + * @example + * // get IB array buffer from mesh, better to cache this somewhere convenient + * const ibInfo = mesh.struct.primitives[0].indices.range; + * submesh.ibuffer = mesh.data.buffer.slice(ibInfo.offset, ibInfo.offset + ibInfo.length); + * const submodel = someModelComponent.model.getSubModel(0); + * submodel.inputAssembler.updateIndexBuffer(ibuffer, [0, 1, 2]); + * submodel.updateCommandBuffer(); // index count changed + */ public updateIndexBuffer (ibuffer: GFXBufferSource, data: number[]) { const count = this._indexCount; const ib = this._indexBuffer; diff --git a/cocos/renderer/core/program-lib.ts b/cocos/renderer/core/program-lib.ts index f3136b1c5c..1f18050afc 100644 --- a/cocos/renderer/core/program-lib.ts +++ b/cocos/renderer/core/program-lib.ts @@ -100,7 +100,7 @@ class ProgramLib { * programLib.define(program); */ public define (prog: IShaderInfo) { - const tmpl = Object.assign({ id: ++_shdID }, prog) as IProgramInfo; + const tmpl = Object.assign(this._templates[prog.name] || { id: ++_shdID }, prog) as IProgramInfo; if (!tmpl.localsInited) { insertBuiltinBindings(tmpl, localBindingsDesc, 'locals'); tmpl.localsInited = true; } // calculate option mask offset