Right now I’m trying to freshen up what little I know of OpenGL ES 1.1 so I’m up to speed with OpenGL ES 2.0. I keep using the old ES 1.1 functions, so I thought I’d take the opportunity to re-learn OpenGL ES 2.0 from the ground up.
This OpenGL ES 2.0 Primer is helpful if you want to gain an understanding what’s different (and cool) about OpenGL ES 2.0 when compared to 1.1. It won’t teach you how to use OpenGL ES 2.0 though. The High-End 3D Graphics with OpenGL ES 2.0 PDF covers the concepts in greater detail, and quickly runs you through all important processes from initialization to compiling shaders to shutting down OpenGL ES 2.0. Again I didn’t learn how to program but it helped me understand the GL ES 2.0 concepts.
But what I really wanted was to learn how to do things with OpenGL in the context of cocos2d. Which means I just need to draw stuff, I don’t need to know how to load textures and setup the viewport and things like that. Nevertheless, Ray Wenderlich has done a great job explaining how to create a OpenGL ES 2.0 iPhone project from scratch. And Jeff LaMarche covered ES 2.0 shaders in great detail. Continue reading »
While writing the Learn Cocos2D book I was surprised to find that Cocos2D’s CCSpriteBatchNode was only able to increase the performance of several hundred bullet sprites on screen by about 10-15% (20 to 22.5 fps). I wanted to re-visit that scenario for a long time because as far as I understood, the more sprites I was drawing the greater the impact of CCSpriteBatchNode should be.
But even Cocos2D’s own sprite performance tests (compare columns 9 and 10) revealed a performance difference of under 20% (39 to 42 fps). It’s only when all sprites are scaled and rotated, or most of them are outside the screen area, that sprite batching seems to have a bigger impact (25 to 60 fps). Surely that scenario is not applicable to most games. So I started investigating.
Update: please find the iOS Device Sales Statistics for Q1 2012 here.
Currently Cocos2D is being overhauled for a v2.0 release. It will only support OpenGL ES 2.x and thus games made with Cocos2D v2.x will not run on 1st & 2nd generation devices (iPhone, iPhone 3G, iPod Touch 1 & 2).
The two development threads in the Cocos2D forum here and here are full of users expressing their disappointment (among other emotions/criticism) not to support a rendering core that supports both GL ES 1.x and 2.x. Even though it was said that if you still need to support all devices, you can simply continue to use the Cocos2D v1.x branch.
I’ve run some numbers and came to the following conclusion: if your game only supports OpenGL ES 2.x and comes out in Q1 2012, you will lose less than 10% of customers!
Here’s why I think OpenGL ES v1.x is currently in the process of dropping dead, and close to hitting the ground within the coming ~6 months.
iPhone Sales Statistics Q1 2011
Wikipedia has a nice list of iPhone sales statistics (totals) as they were reported by Apple each quarter. These statistics range from Q3 2007 to Q1 2011. Unfortunately, sales by Apple are not reported by device, so some quarterly sales are combined sales of iPhone 3G + iPhone 3GS respectively iPhone 3GS + iPhone 4.
I tried to extrapolate individual device sales by making the assumption that over time periods where two different iPhone devices were being sold, the newer one was likely to have sold more. Since we’re talking about Apple I choose a 70/30 split, meaning I assumed that 70% of the sales were for the newer device. This seems about right since newer devices have always sold better than the previous generation, but also according to some developer statistics.
For example the Bump developers reporting an iOS 4 adoption rate of 90% in January 2011 across all iOS devices (1st generation devices can not install iOS 4). Or the Surgeworks iOS 4 Adoption report which contains usage statistics of 1st generation device users of only 2.5% for one app, and 5% iPhone 3G users for another app.
The left side of the following pie charts shows the total number of iPhone devices sold to that date, with sales periods of two devices combined. The pie charts on the right show the extrapolated sales statistics for individual iPhone device generations, and which OpenGL ES version they support.
Download the Excel sheet I used to create these charts:
Notice how in Q1 2010 about two third of all iPhone devices supported only OpenGL ES 1.x, but within a year the picture turned just the other way. In Q1 2011 two thirds of iPhone devices sold were capable of running OpenGL ES 2.x code!
This has a lot to do with two factors: the iPhone 4 sold like crazy, whereas the last OpenGL ES 1.1 iPhone being sold (iPhone 3G) was discontinued in June 2010. Meaning since Q3 2010 Apple does no longer sell OpenGL ES 1.1 iPhone devices. And OpenGL ES 1.1 iPod Touches stopped selling in Q4 2010 as well.
All iOS Device Sales Statistics Q2 2011
According to Unwired, Apple reported to have sold 200 million iOS Devices during the iOS 5 announcement. 25 Million of those were iPads. These are the most up to date sales stats, which I assume to be the Q2 2011 statistics.
Based on Wikipedia’s numbers which states 83 Mio. iPhone devices sold vs. over 60 Mio. iPod Touch devices sold, the remaining 175 Mio. should be 42% iPod Touch (74 Mio) and 58% iPhone (102 Mio).
The percentage of OpenGL ES 2.x capable iPhone devices to those only supporting OpenGL ES 1.1 was 31% in Q1 2010 and jumped to 64% in Q1 2011. Assuming the 1.1 to 2.x ratio is the same for iPod Touch, that gives us 137 Mio iOS devices (iPhone, iPod Touch, iPad) with OpenGL ES 2.x capability versus 63 Mio devices (1st & 2nd generation iPhone / iPod Touch) which don’t support 2.x.
This pie chart includes all iOS Devices and which OpenGL ES version they support:
That means 70% of all iOS devices sold to date support OpenGL ES 2.x. This leaves us with only 30% of iOS devices not capable of running OpenGL ES 2.x code.
I don’t want to lose 30% of my customers!
You won’t!
Keep in mind that these statistics are only about devices sold. They do not reflect what has happened to these devices since, or how they are being used today.
I can also assert that older devices are disappearing fast from the market. Even though 30% of the devices sold support only OpenGL ES 1.1, your potential customer base will be significantly less than the number of devices sold. This is for a variety of reasons:
- device has been lost or was stolen
- device broken beyond use/repair
- device simply no longer in use
- device owned by a person who is unlikely to buy new apps
Particularly the last item must be considered: the device user. Again, the user is your potential customer, not the device. And in general all of these items are more likely to happen the older the device is.
One commenter in one of the two GL ES 2.0 threads on the Cocos2D forum reported how happy users were to see a game running smoothly on their 1st generation devices. For me that is not proof that support for older devices is beneficial. To the contrary, I think it clearly shows us that old generation device users are much more selective about their purchases, are already giving up their love for their devices, and may be considering an upgrade because they may have stopped enjoying their devices. This contributes to the “less likely to buy new apps” factor.
You can also assume that users of older devices have less expendable income, or are satisfied with the device as it is. If a user is actually happy with an old iOS device, it’s likely that person prefers to use apps and plays few(er) games or just keeps using the apps & games already owned.
The number of potential customers you would lose - if you released an OpenGL ES 2.0 game right now - is maybe around 10% to 20% at most. Far less if your game is complex and visually rich, and would suffer some performance or visual degradation on older devices anyway.
What about the near future? (Q1 2012)
Considering that 6 months from now, in Q1 2012, we will have seen the release of new iPhone devices (iPhone 5, possibly iPod 5) and thus another boom in sales, it is a better deal to start making some cool visual effects with shaders that look great on iPhone 4 and 5 rather than trying to still support 1st and 2nd generation devices.
In particular if you need to put in some (or a lot of) effort to support the older devices, for example if you have to optimize the performance, reduce the feature set (eg no or limited Game Center support) or (god forbid) you need to ensure compatibility with iOS 3.0.1 or lower (CADisplayLink unavailable!). That time and effort are better spent on making a better OpenGL ES 2.x game!
Obviously the decision also depends on how visually rich your game is going to be and whether you can expect to run into performance and other issues on older devices anyhow.
Summary
I fully expect the market share of OpenGL ES 1.1 devices sold to drop to around 20% by Q1 2012. That puts the number of potential customers (for game developers) still using those devices and buying games to certainly much less than 10%. Then consider that the iPhone 5 may even already account for up to 5% (~10 Mio) of all iOS devices sold by Q1 2012.
By the end of 2012 the potential customer base (for game developers) still using 1st and 2nd generation devices will have become entirely negligible.
That means, if you start developing an OpenGL ES 2.x game within the next 3 months, and your game takes 3+ months to complete, you will lose very few customers by only supporting 3rd generation and newer devices. And you may actually be able to win more customers by cleverly supporting the new devices!
I think it’s wise to start using Cocos2D v2.0 as soon as it is production-ready, which may be in around 3-6 months according to the comments and current progress.
Game On, Cocos2D 2.x!
Chapter 11 - Isometric Tilemaps
After Chapter 10 introduced Tiled and working with orthogonal tilemaps it’s time to step things up a notch and delve into isometric tilemaps. It starts with basic principles of isometric tilemaps and editing before going into detail on what’s different code-wise compared to orthogonal tilemaps. Obviously this has to include how to determine which isometric tile was touched and how to move a character across an isometric tilemap.
Summary of working on Chapter 10 - Working with Tilemaps
This chapter introduces you to tilemaps, what they are and what benefits and tradeoffs they provide. Without a doubt the most popular editor for tilemaps for use with cocos2d is the Tiled Map Editor. I explain how to use it over several pages before going into code and actually loading your first tilemap using cocos2d’s CCTMXTiledMap class.
Loading a tilemap is just half the story. You’ll also learn how to manipulate the tilemap layers and individual tiles, as well as scrolling the tilemap and centering the touched tile on screen. The code takes care that the tilemap is never scrolled outside its boundaries.
While working with the Object Layer feature of Tiled (CCTMXObjectGroup in cocos2d) I noticed it’ll be handy to display the rectangles on the screen. So you’ll also learn a little custom drawing using OpenGL ES respectively cocos2d’s wrapper functions in CCDrawPrimitives.