Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-15-2010, 07:30 AM   #1 (permalink)
Divine avenger
 
Johanovski's Avatar
 
Join Date: Nov 2009
Location: Vic, Catalunya (Spain)
Posts: 320
Default OpenGL 2D performance question...

Hi there!

I'm working in a 2D OpenGL project and I'm wondering if it's better to use various images for an animation or use a single imageSet containing all the sprites and then drawing a sub-image each time...
So for example let's say I have 3 kinds of characters with 4 sprites each one (and each sprite is 64 x 64). Which is the better option (for OpenGL performance)?

Option1:
Code:
// Three arrays of four images each one:
for(int i=0; i<4; i++)
{
     spritesChar1[i] = [[Image alloc] initWithImage:[...]];
     spritesChar2[i] = [[Image alloc] initWithImage:[...]];
     spritesChar3[i] = [[Image alloc] initWithImage:[...]];
}
// So I have 12 (64 x 64) images allocated, but each time I have to render one I do it for the entire image:

(...)

[spritesChar1[sprite] renderAtPoint:p];
Option2:
Code:
// Three images containing each one the four sprites:

spritesChar1 = [[Image alloc] initWithImage:[...]];
spritesChar2 = [[Image alloc] initWithImage:[...]];
spritesChar3 = [[Image alloc] initWithImage:[...]];

// So I have 3 (256 x 64) images allocated, but each time I have to render one I have to get a sub-image to draw only the sprite:

(...)

[spritesChar1 renderSubImageAtPoint:p WithOffset:offset AndSpriteSize:size];
Option3:
Code:
// A single image containing the three characters and each character's sprites:

spritesChars = [[Image alloc] initWithImage:[...]];

// So I have 3 (256 x 196) images allocated, but each time I have to render one I have to get a sub-image to draw only the sprite:

(...)

[spritesChar1 renderSubImageAtPoint:p WithOffset:offset AndSpriteSize:size];
Which is the best way for performance?

Thanks for your time!
Johanovski is offline   Reply With Quote
Old 04-16-2010, 11:39 AM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
Default

Whichever method has the fewest number of calls to glDrawArrays or glDrawElements should have the better performance, and whichever method has the fewest calls to glBindTexture.

I don't know what renderSubImageAtPoint looks like, but I assume it calls both glBindTexture and glDrawArrays; in that case you probably won't see much difference between these three methods.

In the long term, a single image with all of the textures has the biggest chance of speedup in the future. With a single texture it's possible to batch all of your sprites together to draw all or most of them with a single call to glDrawArrays. That would give you a tremendous speedup. You'd probably have to rewrite your drawing class, though.
__________________

Free Games!
smasher is offline   Reply With Quote
Reply

Bookmarks

Tags
image, opengl, performance, spriteset, subimage

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Stats
Members: 158,884
Threads: 89,229
Posts: 380,763
Top Poster: BrianSlick (7,129)
Welcome to our newest member, karlam963
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:13 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0