Re: Drawing a lot of SVG images is slow

Vadim Zeitlin <[email protected]> Tue, 1 Apr 2025 21:50:01 +0200
Newsgroups gmane.comp.lib.wxwindows.general
Message-ID <[email protected]>
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

-- 
TT-Solutions: wxWidgets consultancy and technical support
              https://www.tt-solutions.com/
signature.asc (application/pgp-signature, 195 B)
-----BEGIN PGP SIGNATURE-----

iF0EABECAB0WIQQx+vLQdOwioQqkxtoG6kHeT2wehgUCZ+xDaQAKCRAG6kHeT2we
ht8ZAJ96ZCl7m1/owiOlWyC3vnyd1Bc0hACfYuw/V9suAyRBJGf6OxPJgGcC54I=
=I0/L
-----END PGP SIGNATURE-----