@@ -275,25 +275,51 @@ 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+ console . log ( 'Texture already has a vgl _texture' ) ;
287+ } else {
288+ console . log ( 'Updating Texture by creating new VGL' ) ;
289+ texture = new vgl . texture ( ) ;
290+ texture . setTexture ( quad . imageTexture ) ;
291+ let nearestPixel = m_this . nearestPixel ( ) ;
292+ if ( nearestPixel !== undefined ) {
293+ if ( nearestPixel !== true && util . isNonNullFinite ( nearestPixel ) ) {
294+ const curZoom = m_this . layer ( ) . map ( ) . zoom ( ) ;
295+ nearestPixel = curZoom >= nearestPixel ;
296+ }
291297 }
298+ if ( nearestPixel ) {
299+ texture . setNearestPixel ( true ) ;
300+ }
301+ quad . texture = quad . imageTexture . _texture = texture ;
292302 }
293- if ( nearestPixel ) {
294- texture . setNearestPixel ( true ) ;
303+ } else if ( quad . image ) {
304+ // Handle regular image
305+ if ( quad . image . _texture ) {
306+ quad . texture = quad . image . _texture ;
307+ } else {
308+ texture = new vgl . texture ( ) ;
309+ console . log ( 'Setting Quad Image' ) ;
310+ texture . setImage ( quad . image ) ;
311+ let nearestPixel = m_this . nearestPixel ( ) ;
312+ if ( nearestPixel !== undefined ) {
313+ if ( nearestPixel !== true && util . isNonNullFinite ( nearestPixel ) ) {
314+ const curZoom = m_this . layer ( ) . map ( ) . zoom ( ) ;
315+ nearestPixel = curZoom >= nearestPixel ;
316+ }
317+ }
318+ if ( nearestPixel ) {
319+ texture . setNearestPixel ( true ) ;
320+ }
321+ quad . texture = quad . image . _texture = texture ;
295322 }
296- quad . texture = quad . image . _texture = texture ;
297323 }
298324 } ) ;
299325 } ;
@@ -382,7 +408,10 @@ var webgl_quadFeature = function (arg) {
382408 nearestPixel = curZoom >= nearestPixel ;
383409 }
384410 m_quads . imgQuads . forEach ( ( quad ) => {
385- if ( quad . image && quad . texture && quad . texture . nearestPixel ( ) !== nearestPixel && quad . texture . textureHandle ( ) ) {
411+ console . log ( nearestPixel ) ;
412+ console . log ( quad . texture . nearestPixel ( ) ) ;
413+ console . log ( quad . texture . textureHandle ( ) ) ;
414+ if ( ( quad . image || quad . imageTexture ) && quad . texture && quad . texture . nearestPixel ( ) !== nearestPixel && quad . texture . textureHandle ( ) ) {
386415 /* This could just be
387416 * quad.texture.setNearestPixel(nearestPixel);
388417 * but that needlessly redecodes the image. Instead, just change the
@@ -404,18 +433,25 @@ var webgl_quadFeature = function (arg) {
404433 }
405434 context . bindBuffer ( context . ARRAY_BUFFER , m_glBuffers . imgQuadsPosition ) ;
406435 $ . each ( m_quads . imgQuads , function ( idx , quad ) {
407- if ( ! quad . image ) {
436+ if ( ! quad . image && ! quad . imageTexture ) {
408437 return ;
409438 }
410439 quad . texture . bind ( renderState ) ;
411440 // only check if the context is out of memory when using modestly large
412441 // textures. The check is slow.
413- if ( quad . image . width * quad . image . height > _memoryCheckLargestTested ) {
442+ if ( quad . image && quad . image . width * quad . image . height > _memoryCheckLargestTested ) {
414443 _memoryCheckLargestTested = quad . image . width * quad . image . height ;
415444 if ( context . getError ( ) === context . OUT_OF_MEMORY ) {
416445 console . log ( 'Insufficient GPU memory for texture' ) ;
417446 }
418447 }
448+ if ( quad . imageTexture && quad . imageTexture . width * quad . imageTexture . height > _memoryCheckLargestTested ) {
449+ _memoryCheckLargestTested = quad . imageTexture . width * quad . imageTexture . height ;
450+ if ( context . getError ( ) === context . OUT_OF_MEMORY ) {
451+ console . log ( 'Insufficient GPU memory for texture' ) ;
452+ }
453+ }
454+
419455 if ( quad . opacity !== opacity ) {
420456 opacity = quad . opacity ;
421457 context . uniform1fv ( renderState . m_material . shaderProgram ( )
@@ -432,8 +468,14 @@ var webgl_quadFeature = function (arg) {
432468 context . uniform2fv ( renderState . m_material . shaderProgram ( )
433469 . uniformLocation ( 'crop' ) , new Float32Array ( [ crop . x === undefined ? 1 : crop . x , crop . y === undefined ? 1 : crop . y ] ) ) ;
434470 }
435- w = quad . image . width ;
436- h = quad . image . height ;
471+ if ( quad . image ) {
472+ w = quad . image . width ;
473+ h = quad . image . height ;
474+ }
475+ if ( quad . imageTexture ) {
476+ w = quad . imageTexture . width ;
477+ h = quad . imageTexture . height ;
478+ }
437479 quadcropsrc = quad . crop || { left : 0 , top : 0 , right : w , bottom : h } ;
438480 if ( ! cropsrc || quadcropsrc . left !== cropsrc . left || quadcropsrc . top !== cropsrc . top || quadcropsrc . right !== cropsrc . right || quadcropsrc . bottom !== cropsrc . bottom || quadw !== w || quadh !== h ) {
439481 cropsrc = quadcropsrc ;
@@ -496,6 +538,9 @@ var webgl_quadFeature = function (arg) {
496538 delete quad . texture ;
497539 delete quad . image . _texture ;
498540 }
541+ if ( quad . imageTexture ) {
542+ delete quad . imageTexture . _texture ;
543+ }
499544 } ) ;
500545 m_this . _updateTextures ( ) ;
501546 }
0 commit comments