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

Author Topic: VertexArray merged with culling  (Read 2130 times)

0 Members and 1 Guest are viewing this topic.

Akasata

  • Newbie
  • *
  • Posts: 6
    • View Profile
VertexArray merged with culling
« on: June 20, 2018, 11:04:27 am »
Hi guys, I have a question related to drawing objects in sf::RenderWindow. As far as I know, calling single draw of sf::VertexArray is faster than calling multiple draws. That is why I decided to implement code able to draw tilemap stored in this container. Furthermore, I have read about culling, which is simple way to omit drawing objects situated outside of sf::View. There is no way to draw only part of sf::VertexArray, so implementation of culling is more complicated. I realized that I can split my tilemap into chunks and put sf::VertexArray into all of them. This solution seems to reduce number of draw calls and number of drawn objects, but I am not convinced enough. Is there any better way to merge culling with sf::VertexArray? I am looking forward your answers.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: VertexArray merged with culling
« Reply #1 on: June 20, 2018, 11:46:27 am »
Quote
There is no way to draw only part of sf::VertexArray
This is wrong, you can draw a sub-range of a vertex array with the overload of draw() that takes a sf::Vertex pointer and a vertex count; however you can only select a range of contiguous vertices in memory, so this may not be optimal for culling tiles (this means that you can cull rows or columns, but not both).

Quote
I realized that I can split my tilemap into chunks and put sf::VertexArray into all of them
This is often the best compromise.
« Last Edit: June 20, 2018, 11:48:20 am by Laurent »
Laurent Gomila - SFML developer

Akasata

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: VertexArray merged with culling
« Reply #2 on: June 20, 2018, 12:01:40 pm »
Thank you for you response.  :D

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: VertexArray merged with culling
« Reply #3 on: June 22, 2018, 09:33:13 pm »
You could approach this differently: instead of having a vertex array that is larger than the window and not drawing some of the vertices, have level data that is larger than the window but only a vertex array large enough to fill the window (probably with some extra padding - an extra tile column and row should be enough) and that vertex array is updated from the level data.

If your tilemap is grid-like and regular, this should be pretty easy. If not, consider trying Selba Ward's Tile Map class.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: VertexArray merged with culling
« Reply #4 on: June 23, 2018, 08:27:51 am »
Quote
You could approach this differently: instead of having a vertex array that is larger than the window and not drawing some of the vertices, have level data that is larger than the window but only a vertex array large enough to fill the window (probably with some extra padding - an extra tile column and row should be enough) and that vertex array is updated from the level data.
This also works but is more intensive for the CPU and the GPU memory bus. If you use static geometry and the new sf::VertexBuffer class, you have almost zero CPU overhead and no data transfer to the GPU after init.
« Last Edit: June 23, 2018, 08:29:57 am by Laurent »
Laurent Gomila - SFML developer

 

anything