1

I'm using a VBO to render 2D sprites to my screen. I use a single glDrawElements call to draw a triangle strip of all my sprites connected by degenerate triangles.

I want to make my code object oriented, so I have classes representing each of the various objects I have in my game. e.g. one for my character, one for a background tile, etc.

My initial thought was to query which objects are in a single "view," or subset of a much larger level, then query the positions and texcoords of those objects and draw them as such. This would mean that I would have to build a vector every or every other frame. In addition, I assume I would have to place a sort of timer in each class to fire when the next stage of animation needs to take place.

I'm wondering about the performance implications of using a method like the one I described, and if there is a better way to do it while retaining OO properties.

green_meep
  • 119
  • 8
  • Have a look at [entity systems](https://www.google.com.au/search?q=entity+systems). With regard to particles, I just wrote [this](http://stackoverflow.com/a/30837947/1888983). For querying, you want to block up objects or you don't gain any speed. Maybe look at *occlusion culling* and *bounding volume hierarchies*. – jozxyqk Jun 15 '15 at 14:09
  • Thanks for the heads up. I'm looking into entity systems, which seem to be a depth-2 hierarchy, with entities on one level, and components on the other. The entities then inherit the fields of whatever components they need? I looked into occlusion culling as well. I think what I want is frustum culling. I will be looking into bounding volume hierarchies next. What do you mean by "blocking up" objects? – green_meep Jun 15 '15 at 16:09
  • 1
    Just that by the time you've checked if an object is in the view you may as well have just drawn it. Instead, group/block up objects (e.g. in a bounding volume hierarchy), determine if the group's bounding volume is visible and draw everything in it if it is. – jozxyqk Jun 16 '15 at 03:33
  • Okay. All these concepts make sense. I guess my actual question though was if it is efficient to reconstruct a new vertex array every frame, or if I should try and implement a more "intelligent" solution. – green_meep Jun 17 '15 at 19:09
  • Depends on what you mean by efficient. Drawing from a static array will be 100 times faster than creating one CPU side and transferring it to the GPU. But if you don't have much stuff to draw it might not matter. Getting the GPU to create the array (i.e. transform feedback) or modifying it dynamically *on* the GPU will be lots faster. – jozxyqk Jun 18 '15 at 01:19

1 Answers1

0

I finally implemented my solution.

What I did was loop through my list of "drawable" objects and ask them to add their vertices to a vector, which I then sent to the VBO. Thanks for pointing me in the right direction there, jozxyqk.

Seems simple, but I guess I got caught up in thinking about efficiency costs that shouldn't really matter anyway.

green_meep
  • 119
  • 8