SFML community forums

Help => Graphics => Topic started by: tsterin on June 19, 2020, 07:07:37 pm

Title: [SOLVED]Maximum number of quads in a sf::VertexArray ?
Post by: tsterin on June 19, 2020, 07:07:37 pm
Hello,

I am working on a Cellular Automota simulation project (Game Of Life type).

I allow the user to zoom in and out, and when they zoom out, more cells of the simulation are computed.

I was drawing all cells individually and I, very quickly, encountered performance issues as I was calling draw so many times.

I would like to use sf::VertexArray to display my cells (each cell is a quad). However, I wondered if it is not dangerous that the number of cells I use can be unbounded (since the user can zoom out).

Put it in an other way, is there a maximal size above which it is not safe/performant to use sf::VertexArray ? Will SFML or OpenGL automatically split my sf::VertexArray if it is too big for the buffer of my GPU ?

Would you recommend I fix a maximal limit in number of quads in a sf::VertexArray and potentially use several of them ? If yes, what would you recommend that maximal size to be ?

Thank very much in advance,
Title: Re: Maximum number of quads in a sf::VertexArray ?
Post by: eXpl0it3r on June 21, 2020, 02:28:15 pm
Everything is built with certain limits. Sometimes it's a fixed limit, sometimes a physical one and other times it really depends on a mix of hardware and software.
I don't know if OpenGL sets a limit (maybe limited by an overflowing integer number), but your hardware/driver setup will slowly reach a frametime of 1s or more, so you have 1fps or less.
Instead of thinking of how to make sure to render everything, it would be probably better to think about, what you don't need to render once you're zoomed out. At one point a line is smaller than a pixel line anyways and then you have to decide how to merge these lines. Plus you also have to deal with some limits, then at some point you may not be GPU limited by rather CPU limited. ;)
Title: Re: Maximum number of quads in a sf::VertexArray ?
Post by: Nexus on June 21, 2020, 02:59:20 pm
To extend eXpl0it3r's answer:

Quote
Put it in an other way, is there a maximal size above which it is not safe/performant to use sf::VertexArray ? Will SFML or OpenGL automatically split my sf::VertexArray if it is too big for the buffer of my GPU ?
No, SFML/OpenGL will not split the vertex array.

Apart from VRAM, you also are limited by RAM -- since sf::VertexArray is backed by an std::vector, you need enough contiguous memory to store all the cells. Even if modern machines come with lots of RAM, you need a big enough chunk of memory at once.

What I would probably do is hierarchical rendering. Split the world into regions, where one region is e.g. 100x100 cells. Render each region separately, and only if it's in view.

There are futher optimizations you can do:
Title: Re: Maximum number of quads in a sf::VertexArray ?
Post by: tsterin on June 21, 2020, 09:25:48 pm
Thank you very much both for your help, that's very very helpful.

@Nexus: in your example you choose 100x100 cells because 10^4 quads is what the average gpu can handle easily at once?

Thanks again,
Title: Re: Maximum number of quads in a sf::VertexArray ?
Post by: Nexus on June 21, 2020, 09:43:17 pm
@Nexus: in your example you choose 100x100 cells because 10^4 quads is what the average gpu can handle easily at once?
No, it was just an example with arbitrary numbers. I don't know how many quads can be handled.

You may need to experiment to find what works best. With smaller regions, you are on the safer side, but it costs you some extra drawcalls.
Title: Re: Maximum number of quads in a sf::VertexArray ?
Post by: tsterin on June 22, 2020, 10:33:06 am
Ok, sounds great thank you!