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

Author Topic: VertexArray  (Read 8464 times)

0 Members and 1 Guest are viewing this topic.

dydya-stepa

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
Re: VertexArray
« Reply #15 on: November 21, 2012, 11:49:43 am »
What I found with VertexArray is that it's static so to speak. For my particle system I had to create my own vertex array implementation which reuses already allocated memory for vertex array. So I don't have to allocate it every frame. Is that intended behavior of VertexArray? Which makes it not very useful. As e.g. I might suspect tile engine probably would require also some sort of dynamic allocation. Which probably not that performance bad as with particles.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: VertexArray
« Reply #16 on: November 21, 2012, 12:02:12 pm »
Quote
For my particle system I had to create my own vertex array implementation which reuses already allocated memory for vertex array. So I don't have to allocate it every frame.
What was wrong with sf::VertexArray? You can allocate the vertices once (with the constructor or resize function) and then overwrite them every frame without touching the allocated memory.

And don't forget that sf::VertexArray is just provided for convenience, it's nothing more that a std::vector<sf::Vertex>. Use your own container if it doesn't fit your needs (that's why I always use the generic words "vertex array", not "sf::VertexArray").
« Last Edit: November 21, 2012, 12:03:57 pm by Laurent »
Laurent Gomila - SFML developer

dydya-stepa

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
Re: VertexArray
« Reply #17 on: November 21, 2012, 12:30:31 pm »
The number of particles goes back and forth so when number decreases I don't remove the particles from array. So I have always maximum amount in array but track the number of used. And I'm using sf::Vertex.

gyscos

  • Jr. Member
  • **
  • Posts: 69
    • View Profile
Re: VertexArray
« Reply #18 on: November 21, 2012, 01:50:40 pm »
A VertexArray is a vector of vertex, meaning you can easily add and remove elements from its back.

You can also remove a vertex from anywhere in the array. To make it a little less slow, since order doesn't matter, you can swap it with the last element from the array, then pop the last element.

 

anything