SFML community forums

Help => Graphics => Topic started by: beto on June 18, 2015, 10:45:32 pm

Title: using VertexArray, am i rigth?? (SOLVED)
Post by: beto on June 18, 2015, 10:45:32 pm
Hi guys, i was reading the tutorials from SFML page, in the tutorial "Designing your own entities with vertex array" they explain that performance depend from number of calls of "draw" function. I created a class to draw batches of entities with different texture, this class inherit from "sf::Drawable" class and, in her method "virtual void draw (RenderTarget &target, RenderStates states) const;" i wrote the next code:
void Menu::draw (RenderTarget &target, RenderStates states) const
{
    for (i = 0; i < quantityVertex; i++)
    {
        states.texture = &textures [i];
        target.draw (vertexArray [i[, states);
    }
}
this also can be done with the next code inside main game loop
for (i = 0; i < quantitySprites; i++)
   window.draw (sprites [i]);
 

ok, my question is, which is more efficient??  ;D ;D

thank so much for your answers  ;), i don't know english  ???

Conclusion:
   The performance of the function "draw" is given from the number of calls of the function "RenderTarget::draw (const Drawable &drawable, const RenderStates &states), that if someone serves you  ;)
Title: Re: using VertexArray, am i rigth??
Post by: Hapax on June 19, 2015, 01:04:33 am
These are effectively equal. You are not reducing draw calls; the multiple draw calls are just taking place in the virtual draw method.

Do you really need so many different textures? I wouldn't say that it's particular clean design to need a lot of textures (not sure how many you are actually using here) inside one object.

Your loop suggests that you're iterating through vertices and then drawing each vertex separately with its own texture. Is this your intention?

The performance increase described in the tutorial about vertex arrays is from the ability to draw multiple primitives with a single draw call, all using the same texture. Of course, one object can have multiple vertex arrays following this design...
Title: Re: using VertexArray, am i rigth??
Post by: DarkRoku12 on June 19, 2015, 01:35:42 am
As Hapax said VertexArray is for reduce the calls to one for drawing a group of primitives.

The best method could be:


void Menu::draw (RenderTarget &target, RenderStates states) const
{
        states.texture = &sprite_sheet ;  
        target.draw ( vertexArray , states);
}

 

You can fuse multiple textures in a single sprite sheet , set the primitive type of the VertexArray sf::Quads.
The tutorial and the reference page explain how to apply the sprites and texture coordinates to the primitives.

If you don't understand well the tutorial , you can contact me for PM.
Title: Re: using VertexArray, am i rigth?? (SOLVED)
Post by: beto on June 19, 2015, 02:48:15 am
very thnaks, i thought it was the same but i wasn't sure  ;D ;D