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

Author Topic: using VertexArray, am i rigth?? (SOLVED)  (Read 1699 times)

0 Members and 1 Guest are viewing this topic.

beto

  • Newbie
  • *
  • Posts: 2
    • View Profile
using VertexArray, am i rigth?? (SOLVED)
« 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  ;)
« Last Edit: June 19, 2015, 02:56:24 am by beto »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: using VertexArray, am i rigth??
« Reply #1 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...
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

DarkRoku12

  • Full Member
  • ***
  • Posts: 203
  • Lua coder.
    • View Profile
    • Email
Re: using VertexArray, am i rigth??
« Reply #2 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.
I would like a spanish/latin community...
Problems building for Android? Look here

beto

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: using VertexArray, am i rigth?? (SOLVED)
« Reply #3 on: June 19, 2015, 02:48:15 am »
very thnaks, i thought it was the same but i wasn't sure  ;D ;D