@@ -694,9 +694,8 @@ describe("Scene/TextureAtlas", function () {
694694 expect ( bigBlueIndex ) . toEqual ( 2 ) ;
695695 expect ( redIndex ) . toEqual ( 3 ) ;
696696
697- // Webgl1 textures should only be powers of 2
698- const textureWidth = scene . frameState . context . webgl2 ? 20 : 32 ;
699- const textureHeight = scene . frameState . context . webgl2 ? 32 : 16 ;
697+ const textureWidth = 32 ;
698+ const textureHeight = 16 ;
700699
701700 const texture = atlas . texture ;
702701 expect ( texture . pixelFormat ) . toEqual ( PixelFormat . RGBA ) ;
@@ -1297,6 +1296,56 @@ describe("Scene/TextureAtlas", function () {
12971296 expect ( guid1 ) . not . toEqual ( guid2 ) ;
12981297 } ) ;
12991298
1299+ it ( "allocates appropriate space on resize" , async function ( ) {
1300+ atlas = new TextureAtlas ( ) ;
1301+
1302+ // Adapted from https://github.com/CesiumGS/cesium/issues/5154, this represents a total
1303+ // of 2M pixels to be allocated.
1304+ const imageCount = 256 ;
1305+ const imageWidth = 128 ;
1306+ const imageHeight = 64 ;
1307+
1308+ const totalPixels = imageCount * imageWidth * imageHeight ;
1309+
1310+ const imageUrl = createImageDataURL ( imageWidth , imageHeight ) ;
1311+
1312+ const promises = [ ] ;
1313+ for ( let i = 0 ; i < imageCount ; i ++ ) {
1314+ promises . push ( atlas . addImage ( i . toString ( ) , imageUrl ) ) ;
1315+ }
1316+
1317+ const allPromises = Promise . all ( promises ) ;
1318+
1319+ await pollWhilePromise ( allPromises , ( ) => {
1320+ atlas . update ( scene . frameState . context ) ;
1321+ } ) ;
1322+
1323+ await allPromises ;
1324+
1325+ const atlasWidth = atlas . texture . width ;
1326+ const atlasHeight = atlas . texture . height ;
1327+
1328+ // Allocate enough space, but not >2x more.
1329+ expect ( atlasWidth * atlasHeight ) . toBeGreaterThan ( totalPixels ) ;
1330+ expect ( atlasWidth * atlasHeight ) . toBeLessThanOrEqual ( totalPixels * 2 ) ;
1331+
1332+ // Aspect ratio should be no more extreme than 1:2.
1333+ expect ( atlasWidth / atlasHeight ) . toBeGreaterThanOrEqual ( 0.5 ) ;
1334+ expect ( atlasWidth / atlasHeight ) . toBeLessThanOrEqual ( 2.0 ) ;
1335+
1336+ function createImageDataURL ( width , height ) {
1337+ const canvas = document . createElement ( "canvas" ) ;
1338+ canvas . width = width ;
1339+ canvas . height = height ;
1340+
1341+ const ctx = canvas . getContext ( "2d" ) ;
1342+ ctx . fillStyle = "green" ;
1343+ ctx . fillRect ( 0 , 0 , width , height ) ;
1344+
1345+ return canvas . toDataURL ( ) ;
1346+ }
1347+ } ) ;
1348+
13001349 it ( "destroys successfully while image is queued" , async function ( ) {
13011350 atlas = new TextureAtlas ( ) ;
13021351
0 commit comments