Jump to content
  • Advertisement
Sign in to follow this  
ChazH

OpenGL sprite animation Performance Issues

This topic is 599 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,
I am getting ready to start working on sprite animations and had a few concerns about what would be the best route to go. I am currently working with a few VBO's tied to a single VAO and am torn between rebinding the texture coords every x number of frames to switch to a new frame in the animation. The other option that I was thinking about was updating the shader to use a variable to calculate the texture coordinates. The only issue is I believe setting the variable every frame would cause more of a performance hit then updating the texture coords every x number of frames. I am relatively new to OpenGL and everything I have read is that moving the data to the GPU is very expensive and that updating shader information often is expensive as well. So, as you can see I am torn between the two options and am not sure what direction to go.

 

On a side note. If I set a shaders matrix information for positions. Does that need to be done every frame or only after the object moves?

 

Any help would be greatly appreciated.

Thank you,
Chaz H

Share this post


Link to post
Share on other sites
Advertisement

updating the shader to use a variable to calculate the texture coordinates
 

 

Performance wise, I'd say absolutely not. You need to set the value of the uniform (I assume this is what you're referring to) for every sprite that is at a different point. That means either instanced draw calls or a drawcall each. Even 10k objects with the same animation might have to be in a separate drawcall each this way, simply because they're at a different aniimation frame (illustration, 10k frames is obviously not realistic). 

 

Uploading data for sprites is rarely an issue honestly. How many animated sprites are we even talking about? Plenty systems can easily handle 10k sprites a frame without much optimization. 

 

But as with any such performance question:

 

1. Implement it

2. Profile

3. ???

4. Profit

 

You can worry all you want in your head, never find your optimal solution and stay stuck, while just editing the vertex data, is likely your best option. It's really not that slow, my system allows over 100k at 60 fps, all per frame data, and the data transfer is far from the main bottleneck. Unless you need these kind of amounts, probably not something to worry about  :wink:

 

On a side note. If I set a shaders matrix information for positions. Does that need to be done every frame or only after the object moves?
 

 

You don't need to update it every frame, but you're likely multiplying the view and projection transformation matrices on the CPU side, so you would have to keep track of all of them, probably not worth it. Probably not really for position matrices either, it's not really something to worry about.

 

By the way, are you using a model (i.e. location tranformation, position + scale + rotation) matrix for sprites? You might be better off multiplying the model matrix on the CPU side. Being able to batch sprites can help quite severely with performance, while multiplying matrices on the CPU side is not too big of a deal for sprites. 

 

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!