-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Added Image::load_svg_from_(buffer|string)
#78248
Conversation
load_svg_from_(buffer|string)
Image::load_svg_from_(buffer|string)
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
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.
Tested locally, it works. I can confirm this works in a release export template build too, as the SVG module in 4.0 and later is also enabled in non-editor builds.
The exposed API looks good to me.
This is pretty cool! I imagined this when we got svg in. |
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 mostly good, but note that it creates a dependency in core on a module. We like to avoid core depending on modules as much as possible, especially for niche features.
Instead this function should be implemented the same as load_tga_from_buffer()
. In that case Image
exposes a function pointer that is assigned in the module.
I started doing as you said (following the other Agree, that's an interesting consideration about the Thanks. |
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.
The implementation looks good to me. The only thing I am unsure about (and I invite comment on from other reviewers) is whether we need to expose both load_from_string and load_from_buffer. Looking at the other formats we only expose load_from_buffer. Additionally since to_utf8_buffer()
is exposed to users, users can trivially use load_from_buffer whether they have the svg in binary or in a string.
I don't have a strong opinion either way as it is only a few lines of code and this is not my area of expertise.
This is enough justification for me to only expose load_from_buffer. I support this because string is svg's native format unlike png or jpg as an ease of use. |
I've added I don't have a strong opinion on this either, I'm fine with just exposing |
No core dependency to the svg module.
I think it's correct to offer a |
Thanks! |
Hi, just to understand. Does this allow to load SVG inside godot, and scale it as an SVG dynamically in the game ? Or should it be done in another proposal / PR ? |
Indeed, this allows loading SVGs in exported projects even if they weren't imported beforehand. They are still rasterized to an image (at the specified scale) though. This process is performed on the CPU and is relatively slow, so you don't want it to happen every frame when camera zoom changes. |
OK I see so it is no handled by the graphic card. So we won't be able to use svg everywhere instead of textures and it will still be rasterized. |
Yes, but you'll have to do it manually using the newly exposed method. Rasterizing during gameplay can be slow and cause stutters, so I recommend doing it at load-time.
Mipmaps in Godot are generated with a box filter, which isn't ideal but this isn't the biggest issue for using mipmaps in 2D. There are arguably better filters out there, but they also come with their downsides. The more prominent issue is that trilinear filtering is used by default, which isn't ideal for most mipmap usage in 2D. You can switch to bilinear filtering in the Project Settings (Use Nearest Mipmap Filter), but this will also affect 3D rendering which may be undesired. In a 2D-only project, you should be able to safely enable that setting. See godotengine/godot-proposals#7411. |
Fixes #3422
This PR adds two methods:
Image::load_svg_from_buffer(buffer, scale)
;Image::load_svg_from_string(svg_str, scale)
.The methods are mostly compatible with
3.x
for cherrypick, but the changes introduced by migrating from nanosvg to thorvg should be accounted for.You can use the snippet bellow to test both methods:
Expand to show the code
The SVG at the variable
test_svg
is like this:Expand to show an output example