SFML community forums
Help => Graphics => Topic started by: Verteo on October 28, 2013, 01:03:59 am
-
Hello, I want do draw big isometric maps efficiently with SFML.
The maximum map size I intend at the moment is 1024*1024. But the perfomance is already bad at 512*512. It takes around 0,67s to render a frame.
The maps are randomly created and there are 20 textures for the ground each 44*27px. Every texture is in the memory once, no copies. Sprites out of view are not rendered, but i want to zoom out and see the whole map.
There has to be a faster way than calling draw() per tile.
One Tile:
(http://img571.imageshack.us/img571/1341/edet.png)
Screenshot from a 512*512 map:
(http://img24.imageshack.us/img24/9254/f86m.png) (http://imageshack.us/photo/my-images/24/f86m.png/)
-
There is. VertexArrays (http://sfml-dev.org/tutorials/2.1/graphics-vertex-array.php).
If I'm interpreting your post right you'll have to combine those 20 textures into a single file/texture, but after that it's just a question of how to generate the list of vertices.
And since this use case is related to zooming out, there's a chance that using some OpenGL calls to generate mipmaps might help, but focus on vertex arrays first.
-
Thank you for your answer.
I'm not sure how to use vertex arrays, but i'm sure i'll figure it out.
-
http://www.sfml-dev.org/tutorials/2.1/graphics-vertex-array.php
Edit: Just realized Ixrec had the same link in his reply. :P
-
After switching to vertex arrays a frame takes 0,017s (60FPS) to draw at 512*512 maps. At 1024*1024 each frame takes 0,04 (25FPS). This is a good improvement. I'm using quads in single array.
Some more Questions:
- Is there a way to improve that even more?
- Is it possible not to draw tiles out sight?
- Maybe by breaking down the single array into smaller ones?
-
Yes, yes and yes.
-
What would you do?
-
You have to ask precise questions, we're not going to post a complete code or algorithm for you ;)
-
Yes, yes and yes.
I was under the impression that the purpose of a vertex array was to use as few draw calls as possible, but you said that breaking the larger vertex array into smaller ones would help to increase performance. Can you elaborate on that for me please?
-
1 or 10 draw calls won't make a noticeable difference, however drawing 1,000,000 or 10,000 quads will. So sometimes it may be a good strategy to have a few vertex arrays rather than a big one, in order to be able to ignore parts that are not visible.
-
In this case, yeah I can see how that would improve performance. I guess I mistook it for a generalization.
-
You have to ask precise questions, we're not going to post a complete code or algorithm for you ;)
How would you draw 1024² tiles in order to get good performance?
As long as there are good tutorials I don't need complete code and SFML has good tutorials ;)
-
Why would you want to do that? With 1024 tiles in width and height, each tile would have a size of 1-2 pixels.
Only draw the tiles you really need.
-
Because I want to zoom out and see the whole map not just parts. While zooming in I won't draw tiles out of view.
Maybe implementing a LOD system would be an option. I'm open for suggestions ;)
-
Yes, you could render different zoom levels to a render texture, and then draw a sprite using this texture.