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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trade: support mip levels in image import #369

Draft
wants to merge 1 commit into
base: master
from

Conversation

@mosra
Copy link
Owner

mosra commented Aug 27, 2019

There's a new level option in each imageND() API, plus an imageNDLevelCount() query to get image level count. The level defaults to 0, in which case it behaves exactly like before. For levels above 0, the abstract importer checks against the reported level count and asserts if it's out of bounds.

Things left to do:

  • changelog entry
  • adapt DdsImporter, use the levels instead of reporting N images
  • adapt BasisImporter (currently it opens just the base level)
  • adapt other image importer plugins
  • adapt AssimpImporter, OpenGexImporter and TinyGltfImporter plugins
    • they need to properly propagate this to AnyImageImporter and should cache the importer instance to avoid a single image file being read multiple times for each level (and with assertions enabled, once more for the check in each imageND() call)
    • doing this in a clean way may need to have AnyImageImporter movable
    • reuse mipmap test files from DdsImporter and test level propagation on those

@Squareys since you're working on mosra/magnum-plugins#62, could you have a quick look at this to see if it fits your expectations or needs design changes? Thanks! 馃檹

There's a new level option in each imageND() API, plus an
imageNDLevelCount() query to get image level count.

TODO: changelog entry
TODO: update all plugins
@mosra mosra added this to the 2019.0b milestone Aug 27, 2019
@mosra mosra self-assigned this Aug 27, 2019
@mosra mosra added this to TODO in Asset management via automation Aug 27, 2019
@Squareys

This comment has been minimized.

Copy link
Contributor

Squareys commented Aug 27, 2019

At first I was concerned whether image2d(index, level) would enforce anti-patterns in the implementations, but I think quite the opposite is true, this is pretty great, actually :)

Looks good to me! 馃憤

@mosra

This comment has been minimized.

Copy link
Owner Author

mosra commented Aug 27, 2019

would enforce anti-patterns in the implementations

I'm interested, what exactly? Just so I can be sure that I'm doing it correctly.

@Squareys

This comment has been minimized.

Copy link
Contributor

Squareys commented Aug 27, 2019

what exactly?

I was thinking that this might require doing per-image work per mip level. So if you'd call:

for(int level = 0; level < maxLevel; ++level) {
    importer->image2D(0, level);
    /* this might do work maxLevel-1 times that would only need
       to be done once. E.g. figure out image metadata etc. */
}

But it turns out that in Basis and in DDS that part is already done in doOpenData() usually. Except for some light image info stuff in basis maybe.
Imagine a format that compressess over multiple mips and uncompresses all of them for every image2D call... per-image state would need to be either cached in the importer's state or re-computed for every mip. (I wouldn't think this really needs to be accounted for, since most formats don't seem to work this way?)

@mosra

This comment has been minimized.

Copy link
Owner Author

mosra commented Aug 27, 2019

Imagine a format that compressess over multiple mips and uncompresses all of them for every image2D call

Yeah, then the importer would need to be more clever and cache the uncompressed data for subsequent runs (or move some work from doImage() into the doOpen*() function). That's the same AssimpImporter & co. need to do as well -- avoid instantiating, opening and parsing the images for each subsequent loaded level.

@mosra mosra referenced this pull request Sep 28, 2019
@mosra mosra modified the milestones: 2019.0b, 2019.0c Oct 2, 2019
@mosra mosra referenced this pull request Nov 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
2 participants
You can鈥檛 perform that action at this time.