Jump to content
  • Advertisement
Sign in to follow this  
feti

OpenGL Enabling/Disabling alpha blending

This topic is 4006 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

I'm writing a tile-based game using opengl. Some of my tiles have no alpha layer and I'm wondering if it would be advantageous for me to disable blending before I write these tiles, or if that's overkill. I don't have a certain ratio of tiles with alpha layers vs tiles without.

Share this post


Link to post
Share on other sites
Advertisement
Yes, if you have layers of tiles which do not need alpha blending (such as background tiles), disabling alpha blending is an easy optimisation which could make a pretty good performance enhancement. However, if your game is not graphics-extensive, you might not even see the difference. Maybe you should complete a basic level of your game before starting to optimize, you might event realize that you're running over 200 FPS and that the optimizaton isn't necessary.

Remember to be careful about premature optimisation, if the changes in your code are simple, go for it, but don't go making big changes in your code structure before knowing that alpha blending is a bottleneck.

EDIT : I'll add that performance improvement depends on how you're sorting your tiles before rendering, a good example where you could get a performance improvement would be :

- Disable alpha blending
- Draw background tiles
- Enable alpha blending
- Draw entities

A bad example which could kill your performance would be :

- For each tile
- If tile uses alpha then enable alpha blending
- Else disable alpha blending
- Draw tile

Share this post


Link to post
Share on other sites
Thank you for the reply. It's much appreciated. I'll take this into consideration. Maybe I'll store and alpha blending flag in the map file (per tile) in case it comes in handy down the road.

Share this post


Link to post
Share on other sites
Quote:
Original post by feti
Thank you for the reply. It's much appreciated.


No problem!

Quote:
Original post by feti
Maybe I'll store and alpha blending flag in the map file (per tile) in case it comes in handy down the road.


I would advise against doing so because you'll end up like the "bad" code in my post EDIT. It would be much better to group together tiles which use alpha blending in layers. Your approach would work only if you read the map data by splitting it into two arrays : one for the tiles using blending, one for the tiles not using it.

Remember : What kills performance is often state changes, so try to minimize them.

Share this post


Link to post
Share on other sites
Wow, this is great advice. I can definitely group my tiles into a separate pile for rendering now that you said that. Thank you for the advice.

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!