@@ -275,25 +275,48 @@ var webgl_quadFeature = function (arg) {
275275 var texture ;
276276
277277 $ . each ( m_quads . imgQuads , function ( idx , quad ) {
278- if ( ! quad . image ) {
278+ if ( ! quad . image && ! quad . imageTexture ) {
279279 return ;
280280 }
281- if ( quad . image . _texture ) {
282- quad . texture = quad . image . _texture ;
283- } else {
284- texture = new vgl . texture ( ) ;
285- texture . setImage ( quad . image ) ;
286- let nearestPixel = m_this . nearestPixel ( ) ;
287- if ( nearestPixel !== undefined ) {
288- if ( nearestPixel !== true && util . isNonNullFinite ( nearestPixel ) ) {
289- const curZoom = m_this . layer ( ) . map ( ) . zoom ( ) ;
290- nearestPixel = curZoom >= nearestPixel ;
281+
282+ // Handle custom imageTexture (from texture property)
283+ if ( quad . imageTexture ) {
284+ if ( quad . imageTexture . _texture ) {
285+ quad . texture = quad . imageTexture . _texture ;
286+ } else {
287+ texture = new vgl . texture ( ) ;
288+ texture . setTexture ( quad . imageTexture ) ;
289+ let nearestPixel = m_this . nearestPixel ( ) ;
290+ if ( nearestPixel !== undefined ) {
291+ if ( nearestPixel !== true && util . isNonNullFinite ( nearestPixel ) ) {
292+ const curZoom = m_this . layer ( ) . map ( ) . zoom ( ) ;
293+ nearestPixel = curZoom >= nearestPixel ;
294+ }
291295 }
296+ if ( nearestPixel ) {
297+ texture . setNearestPixel ( true ) ;
298+ }
299+ quad . texture = quad . imageTexture . _texture = texture ;
292300 }
293- if ( nearestPixel ) {
294- texture . setNearestPixel ( true ) ;
301+ } else if ( quad . image ) {
302+ // Handle regular image
303+ if ( quad . image . _texture ) {
304+ quad . texture = quad . image . _texture ;
305+ } else {
306+ texture = new vgl . texture ( ) ;
307+ texture . setImage ( quad . image ) ;
308+ let nearestPixel = m_this . nearestPixel ( ) ;
309+ if ( nearestPixel !== undefined ) {
310+ if ( nearestPixel !== true && util . isNonNullFinite ( nearestPixel ) ) {
311+ const curZoom = m_this . layer ( ) . map ( ) . zoom ( ) ;
312+ nearestPixel = curZoom >= nearestPixel ;
313+ }
314+ }
315+ if ( nearestPixel ) {
316+ texture . setNearestPixel ( true ) ;
317+ }
318+ quad . texture = quad . image . _texture = texture ;
295319 }
296- quad . texture = quad . image . _texture = texture ;
297320 }
298321 } ) ;
299322 } ;
@@ -382,7 +405,7 @@ var webgl_quadFeature = function (arg) {
382405 nearestPixel = curZoom >= nearestPixel ;
383406 }
384407 m_quads . imgQuads . forEach ( ( quad ) => {
385- if ( quad . image && quad . texture && quad . texture . nearestPixel ( ) !== nearestPixel && quad . texture . textureHandle ( ) ) {
408+ if ( ( quad . image || quad . imageTexture ) && quad . texture && quad . texture . nearestPixel ( ) !== nearestPixel && quad . texture . textureHandle ( ) ) {
386409 /* This could just be
387410 * quad.texture.setNearestPixel(nearestPixel);
388411 * but that needlessly redecodes the image. Instead, just change the
@@ -404,18 +427,25 @@ var webgl_quadFeature = function (arg) {
404427 }
405428 context . bindBuffer ( context . ARRAY_BUFFER , m_glBuffers . imgQuadsPosition ) ;
406429 $ . each ( m_quads . imgQuads , function ( idx , quad ) {
407- if ( ! quad . image ) {
430+ if ( ! quad . image && ! quad . imageTexture ) {
408431 return ;
409432 }
410433 quad . texture . bind ( renderState ) ;
411434 // only check if the context is out of memory when using modestly large
412435 // textures. The check is slow.
413- if ( quad . image . width * quad . image . height > _memoryCheckLargestTested ) {
436+ if ( quad . image && quad . image . width * quad . image . height > _memoryCheckLargestTested ) {
414437 _memoryCheckLargestTested = quad . image . width * quad . image . height ;
415438 if ( context . getError ( ) === context . OUT_OF_MEMORY ) {
416439 console . log ( 'Insufficient GPU memory for texture' ) ;
417440 }
418441 }
442+ if ( quad . imageTexture && quad . imageTexture . width * quad . imageTexture . height > _memoryCheckLargestTested ) {
443+ _memoryCheckLargestTested = quad . imageTexture . width * quad . imageTexture . height ;
444+ if ( context . getError ( ) === context . OUT_OF_MEMORY ) {
445+ console . log ( 'Insufficient GPU memory for texture' ) ;
446+ }
447+ }
448+
419449 if ( quad . opacity !== opacity ) {
420450 opacity = quad . opacity ;
421451 context . uniform1fv ( renderState . m_material . shaderProgram ( )
@@ -432,8 +462,14 @@ var webgl_quadFeature = function (arg) {
432462 context . uniform2fv ( renderState . m_material . shaderProgram ( )
433463 . uniformLocation ( 'crop' ) , new Float32Array ( [ crop . x === undefined ? 1 : crop . x , crop . y === undefined ? 1 : crop . y ] ) ) ;
434464 }
435- w = quad . image . width ;
436- h = quad . image . height ;
465+ if ( quad . image ) {
466+ w = quad . image . width ;
467+ h = quad . image . height ;
468+ }
469+ if ( quad . imageTexture ) {
470+ w = quad . imageTexture . width ;
471+ h = quad . imageTexture . height ;
472+ }
437473 quadcropsrc = quad . crop || { left : 0 , top : 0 , right : w , bottom : h } ;
438474 if ( ! cropsrc || quadcropsrc . left !== cropsrc . left || quadcropsrc . top !== cropsrc . top || quadcropsrc . right !== cropsrc . right || quadcropsrc . bottom !== cropsrc . bottom || quadw !== w || quadh !== h ) {
439475 cropsrc = quadcropsrc ;
@@ -496,6 +532,9 @@ var webgl_quadFeature = function (arg) {
496532 delete quad . texture ;
497533 delete quad . image . _texture ;
498534 }
535+ if ( quad . imageTexture ) {
536+ delete quad . imageTexture . _texture ;
537+ }
499538 } ) ;
500539 m_this . _updateTextures ( ) ;
501540 }
0 commit comments