How to enable antialiasing in opengl es 3.0

This topic contains 16 replies, has 2 voices, and was last updated by  Shaun 11 months, 3 weeks ago.

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #54745

    Fname
    Member

    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.

    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;
        }

    What Am I doing wroung here ?

    #54769

    Shaun
    Member

    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

    #54772

    Fname
    Member

    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

    #54786

    Shaun
    Member

    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:

    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);

    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

    Attachments:
    You must be logged in to view attached files.
    #54796

    Fname
    Member

    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

    Attachments:
    You must be logged in to view attached files.
    #54799

    Shaun
    Member

    Hi Fname,

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

    Thanks,
    Shaun

    #54800

    Fname
    Member

    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

    #54802

    Shaun
    Member

    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.

    EGLint msaaBuffers;
    eglGetConfigAttrib(eglDisplay, eglConfig, EGL_SAMPLE_BUFFERS, &msaaBuffers);

    Thanks,
    Shaun

    #54804

    Fname
    Member

    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 !?

    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;
    }

    thanks

    #54807

    Shaun
    Member

    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.

    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;
    }

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

    Thanks,
    Shaun

    #54810

    Fname
    Member

    Hi Shaun,

    just tried the last corrected code.
    and after execution of

    eglGetConfigAttrib 

    function, the value of

    msaaBuffers 

    is 1.

    #54812

    Shaun
    Member

    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

    Attachments:
    You must be logged in to view attached files.
    #54815

    Fname
    Member

    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

    Attachments:
    You must be logged in to view attached files.
    #54819

    Shaun
    Member

    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

    Attachments:
    You must be logged in to view attached files.
    #54822

    Fname
    Member

    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

    Attachments:
    You must be logged in to view attached files.
Viewing 15 posts - 1 through 15 (of 17 total)
You must be logged in to reply to this topic.