-
Notifications
You must be signed in to change notification settings - Fork 3.7k
fix(textureatlas): Allocate texture space more incrementally on resize #13042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -364,26 +364,17 @@ TextureAtlas.prototype._resize = function (context, queueOffset = 0) { | |
| toPack.push(queue[i]); | ||
| } | ||
|
|
||
| // At minimum, the texture will need to scale to accommodate the largest width and height | ||
| width = Math.max(maxWidth, width); | ||
| height = Math.max(maxHeight, height); | ||
| // At minimum, atlas must fit its largest input images. Texture coordinates are | ||
| // compressed to 0–1 with 12-bit precision, so use power-of-two size to align pixels. | ||
| width = CesiumMath.nextPowerOfTwo(Math.max(maxWidth, width)); | ||
| height = CesiumMath.nextPowerOfTwo(Math.max(maxHeight, height)); | ||
|
|
||
| if (!context.webgl2) { | ||
| width = CesiumMath.nextPowerOfTwo(width); | ||
| height = CesiumMath.nextPowerOfTwo(height); | ||
| } | ||
|
|
||
| // Determine by what factor the texture need to be scaled by at minimum | ||
| const areaDifference = areaQueued; | ||
| let scalingFactor = 1.0; | ||
| while (areaDifference / width / height >= 1.0) { | ||
| scalingFactor *= 2.0; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In practice this loop can't spend more than 28 iterations for the largest supportable atlas size, because we'll have ... ahem, other challenges ... if the texture atlas size exceeds 16K x 16K. No need to use an increasing scaling factor (which may cause us to skip smaller qualifying atlas sizes) to reduce the number of iterations. |
||
|
|
||
| // Resize by one dimension | ||
| // Iteratively double the smallest dimension until atlas area is (approximately) sufficient. | ||
| while (areaQueued >= width * height) { | ||
| if (width > height) { | ||
| height *= scalingFactor; | ||
| height *= 2; | ||
| } else { | ||
| width *= scalingFactor; | ||
| width *= 2; | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@donmccurdy sorry I missed this earlier: this changelog entry should have been under a new heading for the January release (1.137).
I can fix it in the next PR.