Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Maximum size of VertexArray  (Read 2125 times)

0 Members and 1 Guest are viewing this topic.

smguyk

  • Jr. Member
  • **
  • Posts: 79
    • View Profile
Maximum size of VertexArray
« on: September 15, 2015, 02:53:57 pm »
I'm working on a game where I use the tilemap class from SFML's tutorial, and I was wondering if it's a bad idea to make the map really huge.

By huge I mean dimensions of 80,000x800 (40,000 quads at 40x40 each). Willl that be a problem?

Here's the thing: Due to how my game works, I have to have one big tilemap and can't split it up into smaller parts, or even use e.g. a vector of tiles to make rendering easier.

So if I draw the big tilemap, only whatever can be displayed in the window's size will be rendered, and the rest automatically culled anyway, right? I'm afraid the answer is going to be no...

Yeah.. this is giving me a headache

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Maximum size of VertexArray
« Reply #1 on: September 15, 2015, 03:23:07 pm »
Quote
By huge I mean dimensions of 80,000x800 (40,000 quads at 40x40 each). Willl that be a problem?

If you draw all of that every frame then yes you will probably have performance issues. And your math is wrong, a 80,000x800 map is 64,000,000 quads.

20 bytes (sizeof sf::VertexArray) x 64,000,000 x 4 (each quad has 4 vertices) = 5.12GB

You are asking the GPU to upload 5.12GB of data each frame which is just an insane amount of data.

Quote
Here's the thing: Due to how my game works, I have to have one big tilemap and can't split it up into smaller parts

No you don't, I'm 100% positive that you can break it into smaller chunks. Maybe you just need to rethink your design but it can be done.

Quote
or even use e.g. a vector of tiles to make rendering easier

You do realize all sf::VertexArray is just a wrapper around a vector?

Quote
So if I draw the big tilemap, only whatever can be displayed in the window's size will be rendered, and the rest automatically culled anyway, right?

Will SFML cull it? No. SFML will upload all of the vertex data on each draw call to the GPU and ask it to draw it. Maybe the GPU will be smart and not attempt to draw what is outside the current view, but the bottleneck will be uploading all that vertex data every frame.
« Last Edit: September 15, 2015, 03:28:14 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Maximum size of VertexArray
« Reply #2 on: September 15, 2015, 03:28:13 pm »
Just  do what pretty much all games with huge tile maps do: Split your map into "chunks" and only render those in sight.

For example, make each and every chunk just 10 x 10 tiles big.

Bonus: If you don't mind using render textures, you can use one render texture per (visible) chunk and only rerender them, when something changes. Otherwise just render the prerendered texture, which will speed up things even more.

 

anything