Re: Drawing a lot of SVG images is slow
Quentin Cosendey <[email protected]> Wed, 2 Apr 2025 06:36:27 +0200
| Newsgroups | gmane.comp.lib.wxwindows.general |
|---|---|
| Message-ID | <[email protected]> |
Hello, VZ> This will certainly be slow if you rasterize SVG every time, so you should definitely cache the bitmaps generated for the given size. From the code given, it's not clear whether or not this is the case. VZ> If you reuse the same wxBitmapBundle, this should be the case, but perhaps something goes wrong somewhere... How can I check if I'm always returned the same cached bitmap or not ? / if caching works as expected ? VZ> Also, under Windows, using D2D-based wxGraphicsContext could be much faster than using the default GDI+-based one or GDI. What should I do to use D2D instead of GDI ? I already create a wxGraphicsContext from the DC, is that incorrect / insufficient ? Is that in fact just a facade and GDI is still used anyway ? EJ> At least when using GDI+, conversion from wxBitmap to wxGraphicsBitmap is slow and should be avoided at all costs. It's possible that this is not the case with the D2D renderer, but if in doubt, you should cache the bitmaps as wxGraphicsBitmap, not wxBitmap. I'll check that, but I don't think wxBitmapBundle allows that easily. If it effectively doesn't, probably that I should try to find another way to draw my SVG images. VZ> You could try using LunaSVG, but normally SVG rasterizing performance shouldn't count anyhow, as the bitmaps should be cached. Drawing 1000 bitmaps is not going to be fast neither, unfortunately, so if you can find a way to precombine them, consider doing this. I'll have a look at LunaSVG. Combining is maybe the key point, I'll also try to find a way to improve that as well. QC> Isn't there a more direct way to draw SVG images ? VZ> Not currently, no. OK, sad! Is rasterization an obligation ? Or it's just that WXWidgets currently don't give another way around it ? Would it be technically possible and interesting to translate directly from SVG commands to wxGraphicsContext or DC calls on the window, without drawing first to an intermediate bitmap ? Sorry for the newbie question. Thank you very much. Regards. Le 01.04.2025 à 21:50, Vadim Zeitlin a écrit : > On Tue, 1 Apr 2025 19:36:31 +0200 Quentin Cosendey wrote: > > QC> I'm developing a game. I'm trying to use SVG images to draw the board > QC> and all game elements (tokens, dice, etc.). > > This will certainly be slow if you rasterize SVG every time, so you should > definitely cache the bitmaps generated for the given size. From the code > given, it's not clear whether or not this is the case. > > QC> As far as I understand, the method wxImageBundle::GetBitmap basically > QC> renders the SVG in a traditional in-memory bitmap. Is that really > QC> necessary ? Isn't there a more direct way to draw SVG images ? > > Not currently, no. > > QC> The documentation says that generated bitmaps are cached, so since the > QC> size don't change unless the window is resized, it shouldn't be a > QC> problem, right ? > > If you reuse the same wxBitmapBundle, this should be the case, but perhaps > something goes wrong somewhere... > > QC> Is SVG support in WX just not made for that kind of thing ? > > Performance definitely wasn't an important factor when choosing the SVG > rendering library for wx -- rather, the simplicity of integration it was. > > QC> In this case do you have an alternate SVG library integrable with WX to > QC> advise ? > > You could try using LunaSVG, but normally SVG rasterizing performance > shouldn't count anyhow, as the bitmaps should be cached. Drawing 1000 > bitmaps is not going to be fast neither, unfortunately, so if you can find > a way to precombine them, consider doing this. > > Also, under Windows, using D2D-based wxGraphicsContext could be much > faster than using the default GDI+-based one or GDI. > > Regards, > VZ > -- Please read https://www.wxwidgets.org/support/mlhowto.htm before posting. --- You received this message because you are subscribed to the Google Groups "wx-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/wx-users/6df25bdc-408d-4df9-9a80-b84000676955%40bluewin.ch.