SFML community forums

Help => Graphics => Topic started by: Martin Sand on February 18, 2018, 09:28:58 am

Title: [SOLVED] Best approach for rendering footprints
Post by: Martin Sand on February 18, 2018, 09:28:58 am
I am currently working on an implementation for footprints etc.

To get this working I have created a struct which I keep in a vector and let it render every frame.
Since the texture does not change but is kept in the GPU memory, I assume it is quite fast although the game will produce thousands of footprints during a level. Every footprint is 1 sprite.

int vectorsize = m_Tracks.size();
for(int iterator = 0; iterator < vectorsize; ++iterator;){
  m_Window.draw(m_Tracks[iterator]->getComponent<RenderComponent>()->getSprite());
}

What is the best optimization (rendering time) for this?

I coudl not find any good result in the forum search.

Best regards
Martin
Title: Re: Best approach for rendering footprints
Post by: Laurent on February 18, 2018, 09:42:15 am
Use a single vertex array with all the footprints inside.
Title: Re: Best approach for rendering footprints
Post by: Martin Sand on February 21, 2018, 11:58:15 pm
Perfect, did the job  :)

I measured the difference. By design my m_Tracks vector was faster than the VertexArray when it was below ~ 3k sprites. The VertexArray always stayed at the constant render time (at least what I measured through sf::Clock in microseconds). The vector was getting slower and slower beyond 3k sprites (sprite is 21x3 px).