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

Expose and document Image.get_mipmap_count() #74142

Merged
merged 1 commit into from
Sep 20, 2023

Conversation

bitsawer
Copy link
Member

@bitsawer bitsawer commented Mar 1, 2023

Adds a new method Image.get_mipmap_details() and exposes an already existing method Image.get_mipmap_count(). Also documents both. This makes it possible to efficiently manipulate raw mipmap data. It was technically possible before, but the calculations required are not trivial to do and very error prone.

Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me 🙂

Documentation-wise, these methods are likely worth referencing in the create_from_image() method's description, or whichever method lets you create a new Image with a mipmaps parameter.

@bitsawer
Copy link
Member Author

bitsawer commented Mar 1, 2023

I added some references to these new methods to Image.generate_mipmaps() method description. That is the method which both Image.create() and Image.create_from_data() point to when talking about their use_mipmaps parameter, so I feel it is a good place to put some extra info. I also added a sentence describing the renormalize-parameter as a bonus, it might be pretty mysterious to many people otherwise.

If anyone wants to tweak the wording let me know, I can write some pretty clumsy documentation sometimes.

@akien-mga akien-mga modified the milestones: 4.x, 4.2 Aug 2, 2023
Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation looks good to me, and in principle it makes sense to me to expose this information for users.
Documentation looks great.

The partial duplicate #79368 confirms that there's some demand for the mipmap count.

Neither have a proposal, so I'd like @reduz to sign off on the addition, or clarify if there are any reason he would not expose this.

@reduz
Copy link
Member

reduz commented Aug 2, 2023

I would like to avoid exposing further API as dictionaries, at least until the structs proposal is approved and implemented.

Alternatively you could have 3 functions:

  • get_mipmap_byte_offset
  • get_mipmap_byte_size
  • get_mipmap_size

@bitsawer bitsawer changed the title Add and expose more Image mipmap functions Expose and document Image.get_mipmap_count() Sep 19, 2023
@bitsawer
Copy link
Member Author

I agree with the API decision to avoid Dictionaries for now. Considering we will have to live with any exposed API for a long time, I didn't add individual getters like get_mipmap_byte_offset() yet. So this PR will only expose and document Image.get_mipmap_count() for now. Updated the commit message and PR title.

For future reference, adding the a struct API will probably make exposing these details in a more convenient easier in the future. Also, eventually exposing some version of Image.get_mipmap_offset_size_and_dimensions() as static method has also found some support. That way, you could precalculate these image parameters without actually having to create an Image object, which is often useful. Currently, most people use some sort of GDScript code snippet to calculate these, which works quite well for now.

@akien-mga akien-mga changed the title Expose and document Image.get_mipmap_count() Expose and document Image.get_mipmap_count() Sep 19, 2023
@akien-mga akien-mga merged commit 54748f2 into godotengine:master Sep 20, 2023
@akien-mga
Copy link
Member

Thanks!

@bitsawer bitsawer deleted the mipmap_api branch September 20, 2023 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants