How to draw anti aliased lines in OpenGL ES 2.0?

我与影子孤独终老i 提交于 2019-12-03 00:32:46

Multisampling can be enabled or disabled using the token GL_MULTISAMPLE, and by default it is enabled.

In order to find out whether multisampling is supported by the currently active EGL surface, query the value of GL_SAMPLE_ BUFFERS: here 1 means supported, 0 indicates not supported. GL_SAMPLES then tells how many samples per pixel are stored.

So all I had to do was add those 2 attributes in the context attribute list :

    EGLint attribList[] =
   {
       EGL_RED_SIZE,       8,
       EGL_GREEN_SIZE,     8,
       EGL_BLUE_SIZE,      8,
       EGL_ALPHA_SIZE,     (flags & ES_WINDOW_ALPHA) ? 8 : EGL_DONT_CARE,
       EGL_DEPTH_SIZE,     (flags & ES_WINDOW_DEPTH) ? 8 : EGL_DONT_CARE,
       EGL_STENCIL_SIZE,   (flags & ES_WINDOW_STENCIL) ? 8 : EGL_DONT_CARE,
       EGL_SAMPLE_BUFFERS, (flags & ES_WINDOW_MULTISAMPLE) ? 1 : 0,
       EGL_SAMPLES, 4,
       EGL_NONE
   };

I set EGL_SAMPLE_BUFFERS to 1 to have a multisample buffer and EGL_SAMPLES to 4 , in so having 4 samples per pixel (FSAA x4).

To be able to do multisampling, you need a multisample framebuffer. On most OpenGL-ES implementations this is done by creating a multisampled Frame Buffer Object, render to that, then copy its contents to the screen framebuffer.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!