Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

iPhone OpenGL ES anti-aliasing?

Is it possible to enable anti-aliasing for OpenGL ES on the iPhone? I've tried a few different things:

glBlendFunc(GL SRCALPHA, GL ONE_MINUS_SRCALPHA);
glEnable(GL_BLEND);

glEnable(GL_SMOOTH);

glEnable(GL_MULTISAMPLE);

and a few others, but none of them work. I'm not exactly an OpenGL heavy, so I wouldn't know if these were even the right kinds of things to enable for anti-aliasing content (it seems like GL_SMOOTH or GL_MULTISAMPLE would work). It seems like the general consensus for OpenGL ES is that anti-aliasing is platform-dependent, but I haven't seen anything which says whether it's possible on the iPhone. I would assume that it would be possible on the iPhone, considering that things drawn with the Quartz CG methods are anti-aliased by default. It looks to me, though, like the only way to do it would be to render into a buffer with two times the width and height, and then scale it down to fit the display. That seems a little bit processor heavy, though, especially on a mobile device. Any input would be greatly appreciated 🙂.

Sonny Jim

Mac OS X (10.5.4)

Posted on Aug 11, 2008 9:16 PM

Reply
13 replies

Aug 12, 2008 9:21 AM in response to jimFrobel

The chip Apple uses is based on the PowerVR MBX design (although I think it is actually built by Samsung) and their developer site is here: http://www.imgtec.com/powervr/insider/sdk/KhronosOpenGLES1xMBX.asp

The SDK is Windows but the technical information about the chips capabilities are on the site as well.

The general Khronos ES site is here: http://www.khronos.org/opengles/

HTH,

=Tod

Sep 1, 2008 5:24 PM in response to jimFrobel

Has anyone gotten any further on this? I have checked out the SDK, and apparently the way they get multisampling is with EGL, which (AFAIK) is not supported on the iphone. (Will EGL ever come to the iphone? How about OpenGL ES 2.0? The underlying chip supports both, I think, so it's sad we can't use them.)

I did manage to "fake" some AA by rendering to a 512x512 texture offscreen, then using that texture to draw on-screen, but I ran into some problems - the normal mipmap filters don't seem to work on texture-buffers. Using GL_LINEAR as a the filter produces visible results, but not nearly good enough to justify the performance penalty.

Sep 19, 2008 2:10 PM in response to jimFrobel

I've accomplished FSAA(full screen antialiasing) on the iPhone by rendering the same scene multiple times and jittering the perspective matrix.

The technique has been used since the 70s. Details on the technique can be found at http://www.opengl.org/resources/code/samples/advanced/advanced97/notes/node63.ht ml

The iPhone doesn't have an accumulation buffer, but you can still use the same idea by faking an accumulation buffer by copying the contents of the color buffer and blending the passes together yourself. If you depth-sort your scene you can just blend everything together and forget about an accumulation buffer.

There are variations on this technique where you re-render the scene several times in wireframe mode and use the results to antialias just the edges of polygons.

I'm doing a puzzle game that never has a front-facing polygon behind another front-facing polygon, so I don't have to mess around with faking an accumulation buffer or worry about depth sorting. Remember that this will make your fps drop by whatever factor you antialias.

Sep 19, 2008 3:38 PM in response to gabebear

If you want to see what this looks like I posted a short movie of the game I am working on. I'm dynamically adjusting the level of antialiasing by the speed at which the cube is spinning.

The cube contains 3072 textured triangles.
http://ghearing.com/iphonecube.mov

At high speed antialiasing is disabled, at low speeds I switch to 2x antialiasing and then when the cube stops I do final 8x antialiasing.

The main problem I had to overcome was preempting the anti-aliased rendering if user input was encountered. You can't have the user wait 8x as long for the controls to respond just because you are trying to make things prettier.

Overall I think the antialiasing and coasting I have are very acceptable... Still a lot of work to do though

Sep 20, 2008 8:17 AM in response to wallclimber21

Nice catch... I don't have mipmaps turned on. When I was originally making this game I was creating it for the Nintendo-DS, which doesn't have texture-filtering or mipmapping so I just slightly blurred the texture. I need to create a new texture and turn mipmapping on.

After thinking about the problem a bit more I should be able to use the technique described at http://homepage.mac.com/arekkusu/bugs/invariance/TexAA.html to get constant anti-aliasing. I've personally never used alpha textures to anti-alias, but it looks pretty simple and should only increase my triangle count by 384.

Sep 20, 2008 9:48 AM in response to gabebear

Maybe you know this, but if you already have a non-mipmapped texture, you can let your iPhone to the work for you.

Just set this:
glTexParameteri(GL TEXTURE2D, GL TEXTURE_MINFILTER, GL LINEAR_MIPMAPLINEAR);
glTexParameteri(GL TEXTURE2D, GL TEXTURE_MAGFILTER, GL LINEAR_MIPMAPLINEAR);

*at the moment of first texture creation*, that is, before calling glTexImage2D, and it will just work.

The quality of the mipmap may be slightly less than if you create them manually (depends on the donwsampling algorithm), but it's probably not worth being concerned over...

Sep 20, 2008 3:42 PM in response to wallclimber21

Bleck, I hadn't played with mipmapping in OpenGL-ES yet, but evidently you can't set min/max levels(i.e. it always goes down to a 1x1 pixel texture). I guess this is fine for photo-type textures(where mipmaps always shine), but for me this means I have a blur where a number should be.

I'm enabling/disabling mipmaps along with 8x fsaa(depending on how fast the cube is spinning), and it looks pretty good, but it adds to the "pop" when the cube stops spinning.

Any better ideas?

Mar 6, 2009 11:11 AM in response to gabebear

Your game looks awesome, the pop for 8x antialiasing is quite subtle especially for layusers.

You mention "The iPhone doesn't have an accumulation buffer, but you can still use the same idea by faking an accumulation buffer by copying the contents of the color buffer and blending the passes together yourself."

This is a newb Q I'm sure, but how does one easily copy the color buffers around? I've also seen mention in this thread of rendering to textures. I'm fairly new to GL and still struggling with the limits of GL-es, so I'm not sure what's possible. Any hints are appreciated.

iPhone OpenGL ES anti-aliasing?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.