Is there a way to implement Antialiasing technique in OpenGL ES 2.0? I have goggled and found few methods but there was no change in the output.
In the worst case, I've planned to implement multiple pass rendering, to smooth the edges in fragment shader, by displaying average colour of the pixels around every pixel, but it costs more GPU performance.
Any suggestions?
A lot of devices support MSAA (Multi-Sample Anti-Aliasing). To take advantage of this feature, you have to choose a
EGLConfig
that has multisampling.On Android, if you use
GLSurfaceView
, you will have to implement your ownEGLConfigChooser
. You can then use EGL functions, particularlyeglChooseConfig()
to find a config you like.The following code is untested, but it should at least sketch how this can be implemented. In the constructor of your
GLSurfaceView
derived class, before callingsetRenderer()
, add:Then implement
MyConfigChooser
. You can make this a nested class inside yourGLSurfaceView
:You will obviously want to substitute the specific values you need for your configuration. In reality, it's much more robust to call
eglChooseConfig()
with a small set of strictly necessary attributes, let it enumerate all configs that match those attributes, and then implement your own logic to choose the best among them. The defined behavior ofeglChooseConfig()
is kind of odd already (see documentation), and there's no telling how GPU vendors implement it.On iOS, you can set this property on your
GLKView
to enable 4x MSAA:There are other antialiasing approaches you can consider: