Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm writing a 2D side-scrolling style game in C++ and openGL. In this game I have several cloud sprites which are rendered across the top of the screen. They rotate and scale and such so they're not static. I'm wondering if there is any way that I can optimize this, because currently every time one of these sprites is rendered, GL has to perform blending between everything already rendered (like the background, etc) and these sprites.

I'm thinking something along the lines of rendering ONLY the clouds together all at once, and then performing a single call where the final result is rendered and blended into the main scene. Not sure how to even go about that or if it will even result in a performance gain. Any suggestions would be greatly appreciated!

Just for clarity, here is what a final render looks like. The clouds are formed by several smaller sprites being populated close together around certain points.

enter image description here

share|improve this question

2 Answers 2

up vote 0 down vote accepted

I dont know much about OpenGL, but in DirectX there is alot of speed to be gained by render to texture techniques

http://ogltotd.blogspot.com/2006/12/render-to-texture.html

share|improve this answer
    
Thanks for this, this is along the lines of what I was thinking I just have yet to see if this will actually give a decent increase in performance on mobile. I'll get back to you. –  Digital Architect Feb 25 '12 at 18:08
1  
I can tell you that when I created my 3D drag and drop level editor in DirectX, with a custom shader pipeline using Alpha Blending and Antiscopic filtering, it almost tripled my frames, –  Jacob Clark Feb 25 '12 at 18:16
    
Marked as correct since you actually pointed me in the right direction. For some reason when I read the other answer, I feel like I'm being lectured by my step father. There was indeed a huge performance bottleneck and although I didn't end up using this exact technique, you still pointed me down the road where I eventually ended up using batching and an alternative GL call to render these batched objects, which greatly increased performance. Not such a waste of time after all I guess, premature optimization that is. –  Digital Architect Mar 3 '12 at 23:26

because currently every time one of these sprites is rendered, GL has to perform blending between everything already rendered (like the background, etc) and these sprites.

While rendering with blending isn't the fastest possible rendering mode, it isn't exactly slow either. It doesn't go to each "thing" it has rendered before and blend with it. It's just blending with the destination color in the framebuffer.

I'm thinking something along the lines of rendering ONLY the clouds together all at once, and then performing a single call where the final result is rendered and blended into the main scene.

This is a prime example of premature optimization being the root of all evil. You're "solving" an optimization problem, and your "solution" will not in fact solve the problem. It will create a new problem: overlapped blended objects won't work right. OpenGL's blending functions will only work when you're directly compositing with an opaque destination value. Composting with a transparent value, which you then layer on top of the destination, is not going to provide the correct results.

Don't optimize unless you know something is a performance bottleneck already. That knowledge can only be gained in one of two ways: having a lot of experience in a problem domain or having actual profiling data that shows where the bottleneck is. Just keep making your game; if it turns out to be a problem, you can find a way to solve it later. And you'll know that it is a problem rather than just guessing.

share|improve this answer
    
Thanks for the post. I do know for a fact that it is an issue, since I'm testing my game on 3 different mobile devices and 2 different desktops and this specific rendering call absolutely murders the framerate, unless I knock down the number of clouds to about 20 or so. They're not massive textures either. I understand that in the blending function it's performing ops with the destination colour. Does the "size" of the destination, that is both dimensions and the data it's already populated with, not have any effect on the blend performance? –  Digital Architect Feb 25 '12 at 16:05
    
I should clarify - the call murders the framerate on mobile. They're not crappy devices either, dual core tablet and phone etc etc. –  Digital Architect Feb 25 '12 at 16:06
2  
@AscensionSystems: Blending is a per-sample/pixel operation. The performance of blending (minus other factors like texture access and bandwidth issues) only depends on the area being covered, not the data that it's blending with. –  Nicol Bolas Feb 25 '12 at 16:10
    
@AscensionSystems: "unless I knock down the number of clouds to about 20 or so." You were rendering more than 20? How many were you rendering? Are these 2D images of clouds or a particle system? –  Nicol Bolas Feb 25 '12 at 16:10
    
Yes I was rendering 50. I suppose in a way it is a particle system, I'm trying to render fairly realistic clouds. The clouds are formed by the merging of several smaller textured sprites. –  Digital Architect Feb 25 '12 at 16:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.