@@ -126,7 +126,7 @@ export default class WebGLBackend extends PaddlejsBackend {
126126 program . setProgram ( this . gl , this . vertexBuffer , isRendered ) ;
127127 this . program = program ;
128128
129- this . render ( opData . inputTensors , opData . iLayer , isRendered , index , isPacked ) ;
129+ this . render ( opData . inputTensors , opData . iLayer , isRendered , index , isPacked , opData . modelName ) ;
130130 } ) ;
131131
132132 if ( query ) {
@@ -285,49 +285,50 @@ export default class WebGLBackend extends PaddlejsBackend {
285285 return this . frameBuffer ;
286286 }
287287
288- render ( data : any = [ ] , iLayer : number = 0 , isRendered : Boolean = false , index : number , isPacked : Boolean = false ) {
288+ render ( data : any = [ ] , iLayer : number = 0 , isRendered : Boolean = false , index : number , isPacked : Boolean = false , modelName : string ) {
289289 const gl = this . gl ;
290290 const that = this ;
291291 let textureIndex = 0 ;
292292 data . forEach ( item => {
293- const loc = that . getUniformLoc ( 'texture_' + item . name , iLayer , isRendered , index ) ;
293+ const loc = that . getUniformLoc ( 'texture_' + item . name , iLayer , isRendered , index , modelName ) ;
294294 if ( ! loc ) {
295295 return ;
296296 }
297- that . initTexture ( textureIndex , item , iLayer , isRendered , isPacked ) ;
297+ that . initTexture ( textureIndex , item , iLayer , isRendered , isPacked , modelName ) ;
298298 gl . uniform1i ( loc , textureIndex ++ ) ;
299299 } ) ;
300300 // gl.clearColor(.0, .0, .0, 1);
301301 // gl.clear(gl.COLOR_BUFFER_BIT);
302302 gl . drawArrays ( gl . TRIANGLE_STRIP , 0 , 4 ) ;
303303 }
304304
305- initTexture ( index , item , iLayer , isRendered , isPacked ) {
305+ initTexture ( index , item , iLayer , isRendered , isPacked , modelName ) {
306306 const gl = this . gl ;
307307 const textureConf = this . textureConf as TextureConfig ;
308308 const tensorName = item . opts . type ;
309+ const prefix = modelName + '_' ;
309310 let texture ;
310311 if ( ! item . data ) {
311312 // texture = this.prevTexture;
312313 texture = this . texturesMap [ item . opts . type ] ;
313314 }
314315 else {
315316 // texture = gl.createTexture();
316- if ( isRendered && ( iLayer > 1 || ( iLayer === 1 && tensorName !== 'image' ) ) ) {
317- const tData = this . cacheTextures [ '' + iLayer ] ;
317+ if ( isRendered && ( iLayer > 1 || ( iLayer === 1 && ! tensorName . endsWith ( '_image' ) ) ) ) {
318+ const tData = this . cacheTextures [ prefix + iLayer ] ;
318319 texture = tData [ 'texture_' + tensorName ] ;
319320 }
320321 else {
321322 texture = gl . createTexture ( ) ;
322- this . cacheTextures [ '' + iLayer ] = this . cacheTextures [ '' + iLayer ] || { } ;
323- this . cacheTextures [ '' + iLayer ] [ 'texture_' + tensorName ] = texture ;
323+ this . cacheTextures [ prefix + iLayer ] = this . cacheTextures [ prefix + iLayer ] || { } ;
324+ this . cacheTextures [ prefix + iLayer ] [ 'texture_' + tensorName ] = texture ;
324325 }
325326 }
326327
327328 gl . activeTexture ( gl [ `TEXTURE${ index } ` ] ) ;
328329 gl . bindTexture ( gl . TEXTURE_2D , texture ) ;
329330
330- if ( item . data && ( ! isRendered || ( isRendered && iLayer === 1 && tensorName === 'image' ) ) ) {
331+ if ( item . data && ( ! isRendered || ( isRendered && iLayer === 1 && tensorName . endsWith ( '_image' ) ) ) ) {
331332 gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MAG_FILTER , gl . NEAREST ) ;
332333 gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MIN_FILTER , gl . NEAREST ) ;
333334 gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_WRAP_S , gl . CLAMP_TO_EDGE ) ;
@@ -374,14 +375,15 @@ export default class WebGLBackend extends PaddlejsBackend {
374375 }
375376 }
376377
377- getUniformLoc ( name , ilayer , isRendered , index ) {
378+ getUniformLoc ( name , ilayer , isRendered , index , modelName ) {
379+ const prefix = modelName + '_' ;
378380 if ( isRendered ) {
379- return this . uniformLocations [ '' + ilayer ] [ name + index ] ;
381+ return this . uniformLocations [ prefix + ilayer ] [ name + index ] ;
380382 }
381383 const loc = this . gl . getUniformLocation ( ( this . program as GLProgram ) . program as WebGLProgram , name ) ;
382384 // 缓存
383- this . uniformLocations [ '' + ilayer ] = this . uniformLocations [ '' + ilayer ] || { } ;
384- this . uniformLocations [ '' + ilayer ] [ name + index ] = loc ;
385+ this . uniformLocations [ prefix + ilayer ] = this . uniformLocations [ prefix + ilayer ] || { } ;
386+ this . uniformLocations [ prefix + ilayer ] [ name + index ] = loc ;
385387 return loc ;
386388 }
387389
0 commit comments