ios版本下,在AppController.mm中设置multiSampling和numberOfSamples,如下
CCEAGLView *eaglView = [CCEAGLView viewWithFrame: [window bounds]
pixelFormat: (NSString*)cocos2d::GLViewImpl::_pixelFormat
depthFormat: cocos2d::GLViewImpl::_depthFormat
preserveBackbuffer: NO
sharegroup: nil
multiSampling: YES
numberOfSamples: 4 ];
android版本下,在cocos2d/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dActivity.java中加入EGL_SAMPLE_BUFFERS和EGL_SAMPLES,如下
@Override
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display)
{
int[] EGLattribs = {
EGL10.EGL_RED_SIZE, configAttribs[0],
EGL10.EGL_GREEN_SIZE, configAttribs[1],
EGL10.EGL_BLUE_SIZE, configAttribs[2],
EGL10.EGL_ALPHA_SIZE, configAttribs[3],
EGL10.EGL_DEPTH_SIZE, configAttribs[4],
EGL10.EGL_STENCIL_SIZE,configAttribs[5],
EGL10.EGL_RENDERABLE_TYPE, 4, //EGL_OPENGL_ES2_BIT
EGL10.EGL_SAMPLE_BUFFERS,1,
EGL10.EGL_SAMPLES,8,
EGL10.EGL_NONE
};
原理,开启多重采样以达到扛锯齿。缺点,对于性能要求高,在模拟机上非常卡,真机测试还行。