-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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
Add static methods for creating Image and ImageTexture #60739
Add static methods for creating Image and ImageTexture #60739
Conversation
38939c0
to
54f63ae
Compare
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.
I use the image and image texture operators a lot too.
Ref<Image> image; | ||
image.instantiate(); | ||
image->create(w, h, false, Image::FORMAT_RGB8, img); |
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.
This looks like another good candidate for a static method (in a follow-up PR).
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.
Needs a rebase, otherwise looks great to me.
Hopefully the rebase also fixes the godot-cpp build which seemed to choke on the static method back in May.
54f63ae
to
d290042
Compare
Seems not. CC @godotengine/gdextension
|
I can't test it right now, but it's likely caused by a typo on this line: -method_call += f"return Ref<{return_type}>::___internal_constructor(internal::_call_native_mb_ret_obj<{return_type}>(___method_bind, _nullptr"
+method_call += f"return Ref<{return_type}>::___internal_constructor(internal::_call_native_mb_ret_obj<{return_type}>(___method_bind, nullptr" |
That looked like a copy paste mistake from the I pushed the fix: godotengine/godot-cpp@bffedfe |
Thanks! |
@KoBeWi, may you perhaps make |
Implements #23782
Originally I said that it wouldn't be so useful, but then I actually had to use Image/ImageTexture a bit more. Whenever you create ImageTexture, you immediately assign an image. It gets old fast, so having a shorthand is helpful.
I didn't stop here though. Seems like
ImageTexture.create_from_image()
is used a lot in core, so I replaced all usage by the new static method. Diff numbers say it well how it simplifies the code.What changed:
ImageTexture.create_from_image()
is now staticset_image()
. It's not exposedImage.load_from_file()
, which creates Image and loads dataload()
, because sometimes it's necessary get the loading errorNow it's possible to e.g. assign a dynamically loaded texture in one line:
It saves lots of typing.