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

Author Topic: Dynamic vertexarray  (Read 2067 times)

0 Members and 1 Guest are viewing this topic.

Irksome Ninja

  • Newbie
  • *
  • Posts: 2
    • View Profile
Dynamic vertexarray
« on: February 06, 2015, 10:18:15 pm »
For a long time, I have been using static tilemaps, where I only once create and fill my vertexarray with tile information, by using sf::Quads, but say I want to add/remove certain tiles now and then, do I throw away the old array and refills a new? Or should I just append to the vertexarray?
I guess rebuilding the vertexarray often, is not so optimal?

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Dynamic vertexarray
« Reply #1 on: February 06, 2015, 10:29:10 pm »
My guess would be - it doesn't actually matter.
But, have you tried and benchmarked it?

Nyrox

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Dynamic vertexarray
« Reply #2 on: February 08, 2015, 02:40:38 pm »
The awnser to that is creating a sf::Vertex*. Something like this:

sf::Vertex* v = vertexarray[4 * xCoords + (yCoords * mapHeight)];

Then you have a pointer to the first vertex of the quad that you wan't to edit and can access the folliing with:

v[0].pos....
v[1].pos....
etc. etc.

The code might defer a bit depending on how you map is laid out.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Dynamic vertexarray
« Reply #3 on: February 09, 2015, 01:40:24 am »
Rebuilding the vertex array often doesn't cause any particular performance hit. Resizing the vertex array each frame and then setting each vertex can be done rather efficiently as resizing the vertex array doesn't change the actual memory allocation. Only if it resizes larger than it was does this occur. You can avoid this by setting it to the maximum size required in advance but occasional increasing of size shouldn't be noticable.

This is the technique I used in my Faux Car tests. The track is over 250 segments, each requiring 4 triangles, plus any number of road marks, road-side objects, and opponents (each requiring two triangles). It's all one vertex array that is rebuilt from scratch every frame. Some optimisations are in place so that back-facing road triangles are not added to the vertex array so the vertex array changes size constantly.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything