@@ -704,56 +704,16 @@ describe("Scene/TextureAtlas", function () {
704704 expect ( index2 ) . toEqual ( 2 ) ;
705705 expect ( index3 ) . toEqual ( 3 ) ;
706706
707- // Webgl1 textures should only be powers of 2
708- const isWebGL2 = scene . frameState . context . webgl2 ;
709- const textureWidth = isWebGL2 ? 20 : 32 ;
710- const textureHeight = isWebGL2 ? 32 : 16 ;
707+ const textureWidth = 32 ;
708+ const textureHeight = 16 ;
711709
712710 const texture = atlas . texture ;
713711 expect ( texture . pixelFormat ) . toEqual ( PixelFormat . RGBA ) ;
714712 expect ( texture . width ) . toEqual ( textureWidth ) ;
715713 expect ( texture . height ) . toEqual ( textureHeight ) ;
716714
717- if ( isWebGL2 ) {
718- expect ( drawAtlas ( atlas , [ index0 , index1 , index2 , index3 ] ) ) . toBe (
719- `
720- ....................
721- ....................
722- ....................
723- ....................
724- ....................
725- ....................
726- 2222222222..........
727- 2222222222..........
728- 2222222222..........
729- 2222222222..........
730- 2222222222..........
731- 2222222222..........
732- 2222222222..........
733- 2222222222..........
734- 2222222222..........
735- 2222222222..........
736- 3333333333333333....
737- 3333333333333333....
738- 3333333333333333....
739- 3333333333333333....
740- 3333333333333333....
741- 3333333333333333....
742- 3333333333333333....
743- 3333333333333333....
744- 3333333333333333....
745- 3333333333333333....
746- 3333333333333333....
747- 3333333333333333....
748- 33333333333333330...
749- 33333333333333330...
750- 33333333333333330...
751- 333333333333333301..
752- ` . trim ( ) ,
753- ) ;
754- } else {
755- expect ( drawAtlas ( atlas , [ index0 , index1 , index2 , index3 ] ) ) . toBe (
756- `
715+ expect ( drawAtlas ( atlas , [ index0 , index1 , index2 , index3 ] ) ) . toBe (
716+ `
7577173333333333333333................
7587183333333333333333................
7597193333333333333333................
@@ -771,8 +731,7 @@ describe("Scene/TextureAtlas", function () {
771731333333333333333322222222220.....
7727323333333333333333222222222201....
773733 ` . trim ( ) ,
774- ) ;
775- }
734+ ) ;
776735
777736 let textureCoordinates = atlas . computeTextureCoordinates ( index0 ) ;
778737 expect (
@@ -1456,6 +1415,71 @@ describe("Scene/TextureAtlas", function () {
14561415 expect ( guid1 ) . not . toEqual ( guid2 ) ;
14571416 } ) ;
14581417
1418+ it ( "allocates appropriate space on resize" , async function ( ) {
1419+ const imageWidth = 128 ;
1420+ const imageHeight = 64 ;
1421+
1422+ await addImages ( 25 ) ;
1423+ let inputPixels = 25 * imageWidth * imageHeight ;
1424+ let atlasWidth = atlas . texture . width ;
1425+ let atlasHeight = atlas . texture . height ;
1426+
1427+ // Allocate enough space, but not >>2x more. Aspect ratio should be 1:1, 1:2, or 2:1.
1428+ expect ( atlasWidth * atlasHeight ) . toBeGreaterThan ( inputPixels ) ;
1429+ expect ( atlasWidth * atlasHeight ) . toBeLessThanOrEqual ( inputPixels * 3 ) ;
1430+ expect ( atlasWidth / atlasHeight ) . toBeGreaterThanOrEqual ( 0.5 ) ;
1431+ expect ( atlasWidth / atlasHeight ) . toBeLessThanOrEqual ( 2.0 ) ;
1432+
1433+ await addImages ( 75 ) ;
1434+ inputPixels = 75 * imageWidth * imageHeight ;
1435+ atlasWidth = atlas . texture . width ;
1436+ atlasHeight = atlas . texture . height ;
1437+
1438+ expect ( atlasWidth * atlasHeight ) . toBeGreaterThan ( inputPixels ) ;
1439+ expect ( atlasWidth * atlasHeight ) . toBeLessThanOrEqual ( inputPixels * 3 ) ;
1440+ expect ( atlasWidth / atlasHeight ) . toBeGreaterThanOrEqual ( 0.5 ) ;
1441+ expect ( atlasWidth / atlasHeight ) . toBeLessThanOrEqual ( 2.0 ) ;
1442+
1443+ await addImages ( 256 ) ;
1444+ inputPixels = 256 * imageWidth * imageHeight ;
1445+ atlasWidth = atlas . texture . width ;
1446+ atlasHeight = atlas . texture . height ;
1447+
1448+ expect ( atlasWidth * atlasHeight ) . toBeGreaterThan ( inputPixels ) ;
1449+ expect ( atlasWidth * atlasHeight ) . toBeLessThanOrEqual ( inputPixels * 3 ) ;
1450+ expect ( atlasWidth / atlasHeight ) . toBeGreaterThanOrEqual ( 0.5 ) ;
1451+ expect ( atlasWidth / atlasHeight ) . toBeLessThanOrEqual ( 2.0 ) ;
1452+
1453+ async function addImages ( count ) {
1454+ atlas = new TextureAtlas ( ) ;
1455+
1456+ const imageUrl = createImageDataURL ( imageWidth , imageHeight ) ;
1457+
1458+ const promises = [ ] ;
1459+ for ( let i = 0 ; i < count ; i ++ ) {
1460+ promises . push ( atlas . addImage ( i . toString ( ) , imageUrl ) ) ;
1461+ }
1462+
1463+ await pollWhilePromise ( Promise . all ( promises ) , ( ) => {
1464+ atlas . update ( scene . frameState . context ) ;
1465+ } ) ;
1466+
1467+ return count * imageWidth * imageHeight ;
1468+ }
1469+
1470+ function createImageDataURL ( width , height ) {
1471+ const canvas = document . createElement ( "canvas" ) ;
1472+ canvas . width = width ;
1473+ canvas . height = height ;
1474+
1475+ const ctx = canvas . getContext ( "2d" ) ;
1476+ ctx . fillStyle = "green" ;
1477+ ctx . fillRect ( 0 , 0 , width , height ) ;
1478+
1479+ return canvas . toDataURL ( ) ;
1480+ }
1481+ } ) ;
1482+
14591483 it ( "destroys successfully while image is queued" , async function ( ) {
14601484 atlas = new TextureAtlas ( ) ;
14611485
0 commit comments