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

Author Topic: Can i link VertexArray for drawing in one call?  (Read 3184 times)

0 Members and 1 Guest are viewing this topic.

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Can i link VertexArray for drawing in one call?
« on: June 04, 2014, 08:23:13 pm »
Hello.
Currently i am trying to design multy level height.

So i have a map that has 4 layers,(Floor,low,middle,high), i am not doing base layer for ground i am making objects, and i want them to be able to stack one up on other.
So if i made one vertex for each 320x320 pixel region, my issue is that whenever i add object, i don't want to reposition the whole vertex array if it is bellow another object.

If i add object to position x=0,y=0, with size w=32,h=32 at layer middle. vertexArray(VA) position will be 0-3
Now when i add another object at same position, but at layer floor VA(4-7), i need to switch those around so i will draw in correct order.
That is not issue on small scale, but i am not in small scale, and repositioning hundred vertices, for only one object is passable, but in case 10 objects tumbles from middle layer to low...

So if i make one vertexArray for each layer, i can just add intro it without any checks because objects cannot overlap, problem is that i do not know how to link the VertexArrays together for faster drawing or is it even possible, they will use same texture and renderStates.

I don't know a way to make this efficient atm.
Any suggestions would be gladly appreciated.
The point is to add and remove objects at runtime, and have them show per layer,(Draw order, floor->low->middle->high)) So if at one position we would have, (Candle-Floor, chair-low, bread-middle)
i would see chair with bread on it, no candle what so ever, and because i don't want to have over hundred of vertexArray draw calls i am asking for help.
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Can i link VertexArray for drawing in one call?
« Reply #1 on: June 04, 2014, 08:58:12 pm »
You've probably seen others say this quite a few times but I think it applies to this post as well.

Do the simple and easy thing first (ie, have the layers totally separate and don't bother trying to link them), and see if there's a performance problem.  If there is, then use a profiler, and it'll probably tell you which bit needs optimizing.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Can i link VertexArray for drawing in one call?
« Reply #2 on: June 04, 2014, 09:02:30 pm »
If I understand correctly, tou group several dynamic entities into vertex arrays. This is usually not a good idea. Can't you just use sprites for dynamic entities, and vertex arrays for the static background?
Laurent Gomila - SFML developer

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: Can i link VertexArray for drawing in one call?
« Reply #3 on: June 05, 2014, 04:30:35 pm »
If I understand correctly, tou group several dynamic entities into vertex arrays. This is usually not a good idea. Can't you just use sprites for dynamic entities, and vertex arrays for the static background?
I am expecting large amounts(there will be no less then 50 at time and can go up to 500 easily,there will be case where it will reach about 2500 but that is the maximum) of objects on screen at any given time.
I was just wondering if it is possible to link vertexArrays together for drawing in one call.

I failed to find such feature in documentation, and if there was such a feature as linking vertexArrays togeder, in one draw call, that would increase performance, thus i searched for it.
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Can i link VertexArray for drawing in one call?
« Reply #4 on: June 05, 2014, 04:37:53 pm »
500 sprites is not a lot. Even 2500. Today's games draw millions of polygons.
Laurent Gomila - SFML developer

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: Can i link VertexArray for drawing in one call?
« Reply #5 on: June 06, 2014, 10:59:32 am »
500 sprites is not a lot. Even 2500. Today's games draw millions of polygons.
I couldn't get too acurate data, but from little program i made i gotten:
Drawing 2500 sprites, 60fps, 13%cpu, is ~ to 95000 size vertexArray. of drawing at 60fps, and 10-20cpu usage.
That may be just my gpu, but that is a huge difference.
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11049
    • View Profile
    • development blog
    • Email
Re: Can i link VertexArray for drawing in one call?
« Reply #6 on: June 06, 2014, 11:06:15 am »
Yes there will be a noticeable difference and yes, it's certainly possible to "somehow" batch sprites into VertexArrays, however it's not the most straight forward task and you might loose some flexibility code-wise, as such it's advised to go the simple path first and only if the performance is bad switch to "sprite batching". ;)

Also what exactly are you doing that would required 2500 non-static sprites?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: Can i link VertexArray for drawing in one call?
« Reply #7 on: June 06, 2014, 01:22:51 pm »
2500 come from, non static cause physics, i have now 5 layers for collision, and its all just objects.
To illustrate, Terrain, 32x32 sprites, 800x600 screen = 450 tiles on screen, i will show tavern example.

Walls, carpets, candles on wall, Many (tables, chairs, on tables(candles, drinks, pouches with gold, gold coins)), units and all their cosmetics(armor, weapon), windows on tavern... It pretty much piles up.
I do not want static tables like (Table with glass on in) i have raw table then i place glass on top of the table.
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

lezebulon

  • Full Member
  • ***
  • Posts: 235
    • View Profile
Re: Can i link VertexArray for drawing in one call?
« Reply #8 on: June 06, 2014, 09:05:07 pm »
I'm pretty sure PC can handle 2500 draw calls if it's done right, I remember that in 2011 I made something similar and it was on an old laptop with an integrated graphics card.

Anyway, from the desription the problem you are facing is mainly because you have defined no hard-rule on what you are doing. Obviously the more things you allow to happen, the more sprites you will need, and since you don't define coupling between things everything can happen independently so you need indeed need a lot of sprites.

But consider this : do you actually expect to have 2500 sprites moving, in different ways, at every frame? Probably not, so I think you need to define some hard-rule about what you are going to do, and use this to reduce the overall level of complexity.

 

anything