Skip to content
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

free TextureAtlasNode when billboard image is changed or destroyed / prevent texture atlas overflow (allow dynamic billboards) #9429

Closed
wants to merge 13 commits into from

Conversation

Nadav42
Copy link

@Nadav42 Nadav42 commented Mar 13, 2021

related issues: #6477 #4413 #172 #2319

I want to make the TextureAtlas clear unused nodes (when no billboard is using that resource anymore).
this is in order to allow dynamic billboards with images that change very frequently, currently dynamic billboards are causing the TextureAtlas to fill very quickly and lead to atlas resize exception WebGL: INVALID_VALUE: texImage2D: width or height out of range

The test I used for the clips

50 billboards generate random canvases of width and height between 100px-300px, each billboard generates a new image 20 times per second

Current state of cesium

Rapidly changing dynamic billboard will quickly make the TextureAtlas run out of space and billboards will disappear or become black as shown in this clip:

cesium-dynamic-billboards-current-state.mp4

This can be visualized in the atlas by setting billBoardCollection.debugShowTextureAtlas to true, as shown in the following clip:

cesium-atlas-visualization-current-state.mp4

State after pull request

I made it so billboard images that are no longer used are freed from the atlas, allowing dynamic billboards to work as they should:

cesium-dynamic-billboards-after-pr-state.mp4

This atlas visualization shows how new billboards use empty spaces freed by previous billboards:

cesium-atlas-visualization-after-pr-state.mp4

PR progress:

  • only free image resources with random guid
  • free dead TextureAtlasNodes so that other billboards can use that space
  • when resizing texture atlas and reached webgl max texture size then reset the atlas
  • on node free merge children with parent if all are empty

@cesium-concierge
Copy link

Thanks for the pull request @Nadav42!

  • ✔️ Signed CLA found.
  • CHANGES.md was not updated.
    • If this change updates the public API in any way, please add a bullet point to CHANGES.md.
  • ❔ Unit tests were not updated.
    • Make sure you've updated tests to reflect your changes, added tests for any new code, and ran the code coverage tool.

Reviewers, don't forget to make sure that:

  • Cesium Viewer works.
  • Works in 2D/CV.
  • Works (or fails gracefully) in IE11.

@Nadav42 Nadav42 changed the title [WIP] Free TextureAtlasNode when billboard image is changed or destroyed [WIP] Free TextureAtlasNode when billboard image is changed or destroyed (dynamic billboards) Mar 13, 2021
- when resizing texture atlas and reached webgl max texture size then reset the atlas
- on node free merge children with parent if all are empty
@Nadav42 Nadav42 changed the title [WIP] Free TextureAtlasNode when billboard image is changed or destroyed (dynamic billboards) [Ready for review] Free TextureAtlasNode when billboard image is changed or destroyed (dynamic billboards) Apr 23, 2021
@Nadav42
Copy link
Author

Nadav42 commented Apr 23, 2021

added visualization clips to the PR, need review

@Nadav42 Nadav42 changed the title [Ready for review] Free TextureAtlasNode when billboard image is changed or destroyed (dynamic billboards) free TextureAtlasNode when billboard image is changed or destroyed / prevent texture atlas overflow (allow dynamic billboards) Aug 10, 2021
@Nadav42 Nadav42 closed this Sep 16, 2021
@ItayBa
Copy link

ItayBa commented Oct 28, 2021

Hi, why did you closed the issue? Is there any other solution?

@Nadav42
Copy link
Author

Nadav42 commented Oct 28, 2021

Hi, why did you closed the issue? Is there any other solution?

this solution works fine, I switched to using my other solution that solves this without changing cesium code

@ItayBa
Copy link

ItayBa commented Oct 28, 2021

What did you do to solve it?

@Nadav42
Copy link
Author

Nadav42 commented Oct 29, 2021

What did you do to solve it?

I posted my solution here:

#6477

@maxizrinUX
Copy link

I had the same issue of atlas overflow, but for a handful of generated images.
18 images 512*512 each, generated once.

Seems when a billboard is created with a Canvas element, it just keeps growing the atlas for no reason.
I changed this:
DrawCircle(512, 5); // Returns canvas.
To this:
DrawCircle(512, 5).toDataURL();
Initializing the Billboards with a URL solved the problem.

@Nadav42
Copy link
Author

Nadav42 commented Oct 27, 2022

I had the same issue of atlas overflow, but for a handful of generated images. 18 images 512*512 each, generated once.

Seems when a billboard is created with a Canvas element, it just keeps growing the atlas for no reason. I changed this: DrawCircle(512, 5); // Returns canvas. To this: DrawCircle(512, 5).toDataURL(); Initializing the Billboards with a URL solved the problem.

Since you only have 18 constant images then yeah, providing cesium with the toDataUri() will make cesium cache it by the URL string so it will work just fine

But in my case I need dynamic textures all different from each other (hundreds) so it won't work (the atlas will fill eventually)

@Jeggery
Copy link

Jeggery commented Feb 21, 2023

So is there a perfect solution to this problem? This is a very common function. Threejs and Babylon have dynamic textures. Why can't cesium implement them?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants