1
votes

I'm fairly new to OpenGL and to ES2.0. I have shared c++ opengl es2 code that i use to draw on ios and android(with ndk CMake)... it mostly works but now I need antialiasing and its kind of confusing, the solutions I'm seeing are platform dependent and android side is more confusing and has limitations. I have been searching for solutions but need some more clarity.

What should have worked on both: Apparently, the Kronos RenderBuffer description says

Renderbuffer objects also natively accommodate Multisampling (MSAA).

but es 2.0 doesn't seem to support this. iOS has its own method glRenderbufferStorageMultisampleAPPLEthat supports it on es 2.0 but android doesn't have it. Nor can android Blit the FrameBuffers while ios has own method(once again) glResolveMultisampleFramebufferAPPLE to do that.

If this is done platform specific: iOS can do setDrawableMultisample:GLKViewDrawableMultisample4X which seems to work. But android has limitations, there is EGLConfigChooser's chooseConfig to do it but I have read not all android devices support antialiasing like this(i also can't test it on the emulator), so I have to do it again in the native c++ code.

Other: I have been reading and there are some methods like drawing everything a lot of times in a circular (with more precision) or upscaling the whole view to 2x and drawing and then downscaling back to get more smoother lines... Another way I'm not sure if it works or not but drawing to a texture or image which somehow does the antialiasing or supports it (need a better understanding of this)

What I need now: My requirement is to only draw vertices with color (i do my stuff through this) using glDrawArrays method. And everything that is drawn should be smooth or antialiased. How should I approach this? I need better references or tutorials where I can read properly about any method that should work on both. I don't mind the reading and learning but I'm kind of stuck with so many options and little context with them. EDIT: I'm drawing in 2D(z=0 always), there are no issues of depth.

1
So your problem is that you can't do antialiasing on the emulator. Have you tried it on device? Especially as mid range devices have better GPUs than a few years ago, is it still a problem for the target market for your app?Morrison Chang
I have tried it on a device, it works. But the issue was to avoid the 'wont run on some devices' issue. So i am now looking for alternates. But to clarify, if a device runs opengl es 2.0 then its not guaranteed that it will run the multi-sampling as well, correct?Taimoor Abdullah Khan
Antialiasing will always take a performance hit (see 3D PC games where AA is optional to improve frame rate), so some devices won't be able to support it at all or poorly based on the app (game vs a drawing program). Developing an app for release means making that trade off about what devices will not be supported. Again test on your average customer device to see if AA on/off makes a meaningful difference.Morrison Chang

1 Answers

1
votes

OpenGL ES 2.0 targets low-end platforms and therefore does not require anti-aliasing. Extensions are often implemented however since there is lot of hardware exceeding the ES 2.0 requirements.

Assuming you need to do it on platforms that does not support it, despite being an unfair requirement (hobos should buy effing hardware if they desire visual perfection), there are a couple of things that might work depending on the rendered scene and development budget:

  1. Calculate fragment coverage manually in shader, set alpha, blend using GL_ALPHA_SATURATE; IMO the best looking AA technique there is, though opaque surfaces only (strangely enough supported on ES 2.0 despite no smooth polygons?)
  2. Temporal supersampling. Merge a few recent frames together rendered with slight offsets. If things move alot on display it might not preferable.
  3. Overdraw using transparent lines. For any surface draw its wireframe with transparency. The edges will becomes a little smoother, though the surface will also grow a little.
  4. Clamp vertices to pixel center in shader. This will slightly reduce moving sensation for near vertical/horizontal edges, but may give a less smooth feeling in some scenarios.
  5. Choosing a visual style that is more resistant to aliasing. I avoid circles when pixel-aligned quads work just as good. When there is risk of chromatic aliasing due to pixel geometry I select background and foreground colors more carefully. This is in some sense AA on design level, rather than on a rendering level, and should not be under estimated since it is often cheap and portable.

Should you implement any of above I'd be really interested in your results and more details of your scenario.