How to enable antialiasing in opengl es 3.0

I’m drawing a set of connected lines with GL_LINE_STRIP, and by default they are not antialised.

I tried doing glEnable(GL_LINE_SMOOTH); iniView function but that constant isn’t defined in opengl ES thus it didnt work.

So how to enable it ?
Where and how should I need to set the anitialing configs ??

EDIT
I tried this code but lines are still jagged.

[scode lang=“c++”]EGLint attribs[] =
{
EGL_LEVEL, 0,
EGL_NATIVE_RENDERABLE, 0,
EGL_BUFFER_SIZE, 0,
EGL_DEPTH_SIZE, 16,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_SAMPLE_BUFFERS, 1,
EGL_SAMPLES, 4,
EGL_NONE
};

attribs[1] = 16; // 16x anti-aliasing
EGLConfig config = new EGLConfig[1];
EGLint num_config;

bool result = eglChooseConfig(eglGetDisplay(EGL_DEFAULT_DISPLAY), attribs, &config, 1, &num_config);
if (!result)
{
    this->setExitMessage("Antialiasing has not configured properly");
    return pvr::Result::Enum::InvalidData;
}[/scode]

What Am I doing wroung here ?

Hi Fname,

Firstly EGL_LEVEL does not refer to anti-aliasing level, instead it refers to overlay / underlay buffers.
You can check out the full list of attributes for eglChooseConfig here: https://www.khronos.org/registry/egl/sdk/docs/man/html/eglChooseConfig.xhtml

To anti alias your lines the simplest solution would be to use hardware MSAA, which from the code snippet you have supplied seems to be already setup correctly through the use of the EGL_SAMPLES and EGL_SAMPLE_BUFFERS attributes.

If the MSAA solution is not producing the quality you require you may have to implement your own bespoke AA solution you could take a look at this: https://www.mapbox.com/blog/drawing-antialiased-lines/

Regards,
Shaun

Hi Shaun, thanks for the help.

I will look at the custom methods you provided of antialiasing as well.

Well, the quality of the lines remains the same as before when using the code I mentioned which used MSAA - no antialiasing applied at all. I want to understand possible reasons of why it is not applying.

I just tried to remove EGL_LEVEL attribute which results eglChooseConfig returning false.
Why is this happens when removing EGL_LEVEL ?

What is the correct set of attributes for hardware accelerated MSAA ?

I’m on win 7 machine, with visual studio 2015

Hi Fname,

That is very strange indeed, I have tested the MSAA myself and I can confirm that setting the attributes EGL_SAMPLES and EGL_SAMPLE_BUFFERS does result in smoothed lines and reduced aliasing. May I suggest you take a look at the OGLESHelloAPI example which can be found in our SDK:

C:Imagination\PowerVR_Graphics\PowerVR_SDK\SDK_2016_R1.3\Examples\Beginner\01_HelloAPI\OGLES\BuildWindowsVC2010

The project above is the project I used to test MSAA, I made a few minor adjustments in order to test MSAA with lines these changes are listed below:

[scode lang="{language}"]const EGLint configurationAttributes[] =
{
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_SAMPLE_BUFFERS, 1, EGL_SAMPLES, 4,
EGL_NONE
};
//
GLfloat vertexData[] =
{
-0.4f, -0.4f, 0.0f,
0.4f, 0.4f, 0.0f,
};
//
glDrawArrays(GL_LINES, 0, 2);[/scode]

Please edit the example with the above changes and let me know if you get a smoothed line. I have attached two screenshots to this post hopefully you can see the difference I get between MSAA and no MSAA.

Regards,
Shaun

Hi Shaun,

I have just tried your changes but the line is still jagged, no antialising applied.

here’s the screenshot I made.

I have also noticed some strange behavour when running OGLESHelloAPI.exe file -
it runs successfully ether from visual studio or from the directory but closes (terminates) after 1 second of running just immideatly. I have no idea why is this happens as well.

the directory with executable contains libEGL and libGLESvs2 runtime libraries.

thanks

Hi Fname,

This is a weird one, could I ask what graphics card/adapter you have the driver version.

Thanks,
Shaun

Hi Shaun

yeah sure, my graphics card is Nvidia Geforce 7300GT, with openGL 4.5 on it.
graphics card driver version: 10.18.13.6510

Hi Fname,

Your graphics card should support MSAA. Could you add the snippet of code (below) to the HelloAPI example after the function eglChooseConfig and print out the value, this will check to see if an MSAA buffer has actually been created, an output of 1 will indicate creation was successful and an output of 0 would indicate no MSAA buffer has been created.

[scode lang="{language}"]EGLint msaaBuffers;
eglGetConfigAttrib(eglDisplay, eglConfig, EGL_SAMPLE_BUFFERS, &msaaBuffers);[/scode]

Thanks,
Shaun

Hi Shaun,

I added that snippet of code. did you mean it needs to check the return value of eglGetConfigAttrib(…) function ?

however, I did this and it returns 1 - so msaa buffer has been created !?

[scode lang="{language}"]EGLint msaaBuffers;
if (0 == eglGetConfigAttrib(eglDisplay, eglConfig, EGL_SAMPLE_BUFFERS, &msaaBuffers))
{
MessageBox(0, _T(“msaa buffer has not been created”), ERROR_TITLE, MB_OK | MB_ICONEXCLAMATION);
return false;
}[/scode]

thanks

Hi Fname,

No sorry if I was not clear could you check the value of msaaBuffers, the function itself returns a boolean, but the value we are interested in is the value it writes to msaaBuffers.

[scode lang="{language}"]EGLint msaaBuffers;
eglGetConfigAttrib(eglDisplay, eglConfig, EGL_SAMPLE_BUFFERS, &msaaBuffers);
if (msaaBuffers == 0)
{
MessageBox(0, _T(“msaa buffer has not been created”), ERROR_TITLE, MB_OK | MB_ICONEXCLAMATION);
return false;
}[/scode]

More info on the function here: https://www.khronos.org/registry/egl/sdk/docs/man/html/eglGetConfigAttrib.xhtml

Thanks,
Shaun

Hi Shaun,

just tried the last corrected code.
and after execution of [scode lang="{language}"]eglGetConfigAttrib [/scode] function, the value of [scode lang="{language}"]msaaBuffers [/scode] is 1.

Hi Fname,

This is a long shot but could you try to run my executable (see attached) with DLL’s from our github (I can’t attach them here because they are too big), just to rule out corrupt libraries etc:

https://github.com/powervr-graphics/Native_SDK/tree/4.1/Builds/Windows/x86_32/Lib

You will need libEGL.dll and libGLESv2.dll

Thanks,
Shaun

Hi Shaun,

Just run the attached executable with dlls from the github you gave.

and the line is still not antialiased - its jagged.

Can this be a graphics card driver problem ?

here’s the screen shot

thanks

Hi Fname,

This really is strange, do you happen to have PVRVFrame installed, if so could you launch it and then launch the HelloApi example, then in VFrame go to the context tab, could you then scroll down the list of extensions for the OpenGL (Host) and look for: GL_ARB_ES2_compatibility & GL_ARB_ES3_compatibility. (see attachment)

At the moment I am not really sure what else to suggest, we seem to have exhausted all possibilities (that I can think of), it’s possible that it is a driver problem but I could not say for sure.

Thanks,
Shaun

Hi Shaun,

I looked for those extensions and they are supported.

I think I will try to update the driver and check again.

the screen shot

Hi Shaun,

I have finally figured out the problem and solution.

From the NVIDIA Control Panel (if your video card is nvidia) in the Manage 3D settings section, the option for Antialiasing Mode should be set to Application Control" to allow user written applications enable hardware MSAA, otherwise any attempt (even if it is desktop OpenGL app with glfw, glew etc) will fail if that option is set to Override any application settings and from the driver side it will be changed thus no methods will work - but I think shader based antialiasing should work anyway !?

However, choosing the right setting from there still didn’t help for my app, but did help for the hello api example,
because when manually setting up the MSAA through EGL there something (I didn’t figure out what) was incorrect and incomplete compared to HelloApi source code, instead I just did [scode lang="{language}"]this->setAASamples(4);[/scode] and it set up properly antialiasing and now the lines are antialised !!!

thanks again for the help,
cheers

Hi Fname,

I am glad you found the solution to your problem, I honestly did not think about Nvidia control panel settings overriding application settings - good spot!

If you have any more queries please don’t hesitate to ask.

Thanks,
Shaun

Hi Shanun,
Because I saw this post, I wanted to ask you some questions about MSAA. Our platform is using the PowerVR® BXS 4-64 MC1 core GPU, and then we try to turn on hardware anti-aliasing during EGL inti. The following is my code diff,

However, once EGL_SAMPLE_BUFFERS, 1, EGL_SAMPLES, 4 are added, EGL will fail to initialize where eglsurface is created (eglCreatePixmapSurface) and return 0.

I also tried to print out all supported config attributes. config[3] supports EGL_SAMPLE_BUFFERS, 1, EGL_SAMPLES, 4,.
Do you have any suggestions for this?
config[0]:
EGL_RED_SIZE: 8
EGL_GREEN_SIZE: 8
EGL_BLUE_SIZE: 8
EGL_ALPHA_SIZE: 0
EGL_DEPTH_SIZE: 0
EGL_CONFIG_ID: 1
EGL_SAMPLE_BUFFERS: 0
EGL_SAMPLES: 0
EGL_SURFACE_TYPE: 1031
EGL_STENCIL_SIZE: 0
EGL_RENDERABLE_TYPE: 68
config[1]:
EGL_RED_SIZE: 8
EGL_GREEN_SIZE: 8
EGL_BLUE_SIZE: 8
EGL_ALPHA_SIZE: 0
EGL_DEPTH_SIZE: 24
EGL_CONFIG_ID: 2
EGL_SAMPLE_BUFFERS: 0
EGL_SAMPLES: 0
EGL_SURFACE_TYPE: 1031
EGL_STENCIL_SIZE: 0
EGL_RENDERABLE_TYPE: 68
config[2]:
EGL_RED_SIZE: 8
EGL_GREEN_SIZE: 8
EGL_BLUE_SIZE: 8
EGL_ALPHA_SIZE: 0
EGL_DEPTH_SIZE: 24
EGL_CONFIG_ID: 3
EGL_SAMPLE_BUFFERS: 0
EGL_SAMPLES: 0
EGL_SURFACE_TYPE: 1031
EGL_STENCIL_SIZE: 8
EGL_RENDERABLE_TYPE: 68
config[3]:
EGL_RED_SIZE: 8
EGL_GREEN_SIZE: 8
EGL_BLUE_SIZE: 8
EGL_ALPHA_SIZE: 0
EGL_DEPTH_SIZE: 24
EGL_CONFIG_ID: 4
EGL_SAMPLE_BUFFERS: 1
EGL_SAMPLES: 4
EGL_SURFACE_TYPE: 1031
EGL_STENCIL_SIZE: 8
EGL_RENDERABLE_TYPE: 68
config[4]:
EGL_RED_SIZE: 8
EGL_GREEN_SIZE: 8
EGL_BLUE_SIZE: 8
EGL_ALPHA_SIZE: 0
EGL_DEPTH_SIZE: 24
EGL_CONFIG_ID: 5
EGL_SAMPLE_BUFFERS: 1
EGL_SAMPLES: 2
EGL_SURFACE_TYPE: 1030
EGL_STENCIL_SIZE: 8
EGL_RENDERABLE_TYPE: 68
config[5]:
EGL_RED_SIZE: 8
EGL_GREEN_SIZE: 8
EGL_BLUE_SIZE: 8
EGL_ALPHA_SIZE: 0
EGL_DEPTH_SIZE: 24
EGL_CONFIG_ID: 6
EGL_SAMPLE_BUFFERS: 1
EGL_SAMPLES: 4
EGL_SURFACE_TYPE: 1030
EGL_STENCIL_SIZE: 8
EGL_RENDERABLE_TYPE: 68
config[6]:
EGL_RED_SIZE: 0
EGL_GREEN_SIZE: 0
EGL_BLUE_SIZE: 0
EGL_ALPHA_SIZE: 0
EGL_DEPTH_SIZE: 0
EGL_CONFIG_ID: 7
EGL_SAMPLE_BUFFERS: 0
EGL_SAMPLES: 0
EGL_SURFACE_TYPE: 1030
EGL_STENCIL_SIZE: 0
EGL_RENDERABLE_TYPE: 68
config[7]:
EGL_RED_SIZE: 0
EGL_GREEN_SIZE: 0
EGL_BLUE_SIZE: 0
EGL_ALPHA_SIZE: 0
EGL_DEPTH_SIZE: 24
EGL_CONFIG_ID: 8
EGL_SAMPLE_BUFFERS: 0
EGL_SAMPLES: 0
EGL_SURFACE_TYPE: 1030
EGL_STENCIL_SIZE: 0
EGL_RENDERABLE_TYPE: 68
config[8]:
EGL_RED_SIZE: 0
EGL_GREEN_SIZE: 0
EGL_BLUE_SIZE: 0
EGL_ALPHA_SIZE: 0
EGL_DEPTH_SIZE: 24
EGL_CONFIG_ID: 9
EGL_SAMPLE_BUFFERS: 0
EGL_SAMPLES: 0
EGL_SURFACE_TYPE: 1030
EGL_STENCIL_SIZE: 8
EGL_RENDERABLE_TYPE: 68
eglChooseConfig 1 1 1