@@ -32,6 +32,8 @@ import type Tile from '../source/tile';
3232import type { DynamicDefinesType } from '../render/program/program_uniforms' ;
3333import type { GlobeRasterUniformsType } from './globe_raster_program' ;
3434import type { TerrainRasterUniformsType } from './terrain_raster_program' ;
35+ import type { UserManagedTexture } from '../render/texture' ;
36+ import type Texture from '../render/texture' ;
3537
3638export {
3739 drawTerrainRaster
@@ -194,10 +196,8 @@ function drawTerrainForGlobe(painter: Painter, terrain: Terrain, sourceCache: So
194196 vertexMorphing . newMorphing ( coord . key , prevDemTile , nextDemTile , now , defaultDuration ) ;
195197 }
196198
197- if ( tile . emissiveTexture ) {
198- context . activeTexture . set ( gl . TEXTURE1 ) ;
199- tile . emissiveTexture . bind ( gl . LINEAR , gl . CLAMP_TO_EDGE ) ;
200- }
199+ bindEmissiveTexture ( painter , tile . emissiveTexture ) ;
200+
201201 // Bind the main draped texture
202202 context . activeTexture . set ( gl . TEXTURE0 ) ;
203203 if ( tile . texture ) {
@@ -256,10 +256,8 @@ function drawTerrainForGlobe(painter: Painter, terrain: Terrain, sourceCache: So
256256 if ( segment && ( topCap || bottomCap ) ) {
257257 const tile = sourceCache . getTile ( coord ) ;
258258
259- if ( tile . emissiveTexture ) {
260- context . activeTexture . set ( gl . TEXTURE1 ) ;
261- tile . emissiveTexture . bind ( gl . LINEAR , gl . CLAMP_TO_EDGE ) ;
262- }
259+ bindEmissiveTexture ( painter , tile . emissiveTexture ) ;
260+
263261 // Bind the main draped texture
264262 context . activeTexture . set ( gl . TEXTURE0 ) ;
265263 if ( tile . texture ) {
@@ -356,10 +354,8 @@ function drawTerrainRaster(painter: Painter, terrain: Terrain, sourceCache: Sour
356354 vertexMorphing . newMorphing ( coord . key , prevDemTile , nextDemTile , now , defaultDuration ) ;
357355 }
358356
359- if ( tile . emissiveTexture ) {
360- context . activeTexture . set ( gl . TEXTURE1 ) ;
361- tile . emissiveTexture . bind ( gl . LINEAR , gl . CLAMP_TO_EDGE ) ;
362- }
357+ bindEmissiveTexture ( painter , tile . emissiveTexture ) ;
358+
363359 // Bind the main draped texture
364360 context . activeTexture . set ( gl . TEXTURE0 ) ;
365361 if ( tile . texture ) {
@@ -412,6 +408,24 @@ function isEdgeTile(cid: CanonicalTileID, renderWorldCopies: boolean): boolean {
412408 return ( ! renderWorldCopies && ( cid . x === 0 || cid . x === numTiles - 1 ) ) || cid . y === 0 || cid . y === numTiles - 1 ;
413409}
414410
411+ function bindEmissiveTexture ( painter : Painter , texture : Texture | UserManagedTexture ) {
412+ // Only bind if 3D lights are enabled
413+ if ( ! painter . style || ! painter . style . enable3dLights ( ) ) {
414+ return ;
415+ }
416+
417+ const context = painter . context ;
418+ const gl = context . gl ;
419+ // Bind the emissive texture
420+ context . activeTexture . set ( gl . TEXTURE1 ) ;
421+ if ( texture ) {
422+ texture . bind ( gl . LINEAR , gl . CLAMP_TO_EDGE ) ;
423+ } else {
424+ // Bind an empty texture to avoid WebGL warnings
425+ painter . emptyTexture . bind ( gl . LINEAR , gl . CLAMP_TO_EDGE ) ;
426+ }
427+ }
428+
415429export {
416430 VertexMorphing
417431} ;
0 commit comments