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

Author Topic: sf::VertexArray for multiple Tilesets.  (Read 10310 times)

0 Members and 2 Guests are viewing this topic.

deadmau5

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: sf::VertexArray for multiple Tilesets.
« Reply #15 on: May 22, 2013, 10:08:48 pm »
But what are these tileIDs, and what do they mean at the vertex array level? Is it just another way to refer to specific texture coordinates inside a specific tileset?
Yes it is. And I have no idea how to go with it in terms of VertexArrays and a vector of tileset textures.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::VertexArray for multiple Tilesets.
« Reply #16 on: May 22, 2013, 11:24:56 pm »
Associate a sf::Texture and a sf::VertexArray to each tileset. Then for every tile, add a quad to the vertex array that matches the tileset. That's it.
Laurent Gomila - SFML developer

deadmau5

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: sf::VertexArray for multiple Tilesets.
« Reply #17 on: May 23, 2013, 02:00:30 am »
Associate a sf::Texture and a sf::VertexArray to each tileset. Then for every tile, add a quad to the vertex array that matches the tileset. That's it.
I still fail to see how this could be done in one draw call to render the entire map to the screen.

Example:
Mapdata from file contains tileIDs (seperated by spaces): "1 50 51 100 101 200"
1 = first tile in first tileset.
50 = last tile in first tileset.
51 = first tile in second tileset.
100 = last tile in second tileset.
etc.

I could add quads to the VertexArray containing all tile coordinates of the textures. No problem, these are just vertices that have nothing to do with the actual texture until you decide to render it?

But my problem is that I need an alternative way to draw the entire map with one window.draw call like its supposed to with one tileset texture but instead with multiple. But as stated before this is not possible with multiple textures:
window.draw(VertexArray, &vTilesetTextures[0]);// <- Here one texture. (vTilesetTextures = std::vector<sf::Texture>)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::VertexArray for multiple Tilesets.
« Reply #18 on: May 23, 2013, 08:07:39 am »
Ok, I think I was not clear enough. When I say "one vertex array per texture", it implies "one draw call per vertex array". You won't be able to draw everything in one call. Just iterate over your array of sf::VertexArray and draw them one by one using the corresponding tileset.
Laurent Gomila - SFML developer

deadmau5

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: sf::VertexArray for multiple Tilesets.
« Reply #19 on: May 23, 2013, 05:10:25 pm »
Ok, I think I was not clear enough. When I say "one vertex array per texture", it implies "one draw call per vertex array". You won't be able to draw everything in one call. Just iterate over your array of sf::VertexArray and draw them one by one using the corresponding tileset.
Wouldn't this be as inefficient as drawing the sprites individually?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::VertexArray for multiple Tilesets.
« Reply #20 on: May 23, 2013, 06:03:33 pm »
No, because you obviously have less tilesets than tiles. Thus you have less draw calls with vertex arrays. To be more precise, if you have 50 tiles per tileset, that's 50x less calls, so approximately 50x more performant.

By the way, out of curiosity, what kind of map requires more than 25000 different tiles (500 tilesets * 5x10 tiles) to be loaded at the same time? It seems really huge.
Laurent Gomila - SFML developer

deadmau5

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: sf::VertexArray for multiple Tilesets.
« Reply #21 on: May 23, 2013, 06:40:50 pm »
No, because you obviously have less tilesets than tiles. Thus you have less draw calls with vertex arrays. To be more precise, if you have 50 tiles per tileset, that's 50x less calls, so approximately 50x more performant.

By the way, out of curiosity, what kind of map requires more than 25000 different tiles (500 tilesets * 5x10 tiles) to be loaded at the same time? It seems really huge.
It's not one map of 25000 different tiles but multiple maps. Every map will be loaded when needed (which can range from 10x25 or 45x10 tiles for example). The map dimensions are dynamic but tiles of different tilesets are needed for each map.
My window resolution is 800x600, which can store 475 visible tiles ( (800 / 32) = 25 x (600 / 32) = 18,75 = 19 ). And will only draw the visible tiles.

Now when I understand correctly I would need 500 draw calls with using VertexArrays and 475 draw calls for sprites individually.

Which is inefficient. Your (and anyone elses) help is ofcourse appreciated :-)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::VertexArray for multiple Tilesets.
« Reply #22 on: May 23, 2013, 06:54:16 pm »
Quote
Now when I understand correctly I would need 500 draw calls with using VertexArrays and 475 draw calls for sprites individually.
How can you need more textures (tilesets) than sprites (tiles)... ??? There's at most one different texture per tile, not more.
Laurent Gomila - SFML developer

deadmau5

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: sf::VertexArray for multiple Tilesets.
« Reply #23 on: May 23, 2013, 07:03:42 pm »
How can you need more textures (tilesets) than sprites (tiles)... ??? There's at most one different texture per tile, not more.
You won't be able to draw everything in one call. Just iterate over your array of sf::VertexArray and draw them one by one using the corresponding tileset.
Meaning that I need to iterate through all tilesets (500) for my map to draw? Or do I completely miss the point here.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::VertexArray for multiple Tilesets.
« Reply #24 on: May 23, 2013, 07:07:36 pm »
But you obviously don't need the whole set of 500 tilesets to draw 475 tiles. Some tilesets (at least 25) will never be used in this case.

I think you should play with what SFML has to offer, to find the best solution for your specific case. This discussion is getting too long, actually trying something, and understanding vertex arrays would probably be more efficient for you now. What I say will always be too abstract for you until you get your hands into it ;)

That's just an advice, of course I'll continue to answer your questions.
« Last Edit: May 23, 2013, 07:12:53 pm by Laurent »
Laurent Gomila - SFML developer