MSAA on WebGL is not working for me.

Hello,

I'm trying to apply MSAA on WebGL. I'm on 7.7.2, so the workaround with InitRenderBuffer() should work, but NbMsaaSamples simply doesn't do anything and shows jagged edges (MRE below).

I'm wondering if I'm building via Emscripten with missing options or something. (If we had examples in C++ it would be of great help, but there are only Draw Harness versions...)

Thanks,

Yunku

#include <AIS_InteractiveContext.hxx>
#include <AIS_ViewCube.hxx>
#include <OpenGl_GraphicDriver.hxx>
#include <V3d_View.hxx>
#include <V3d_Viewer.hxx>
#include <Wasm_Window.hxx>
#include <emscripten/html5.h>

//! Dummy main loop callback for a single shot.
extern "C" void onMainLoop() {
    // do nothing here - viewer updates are handled on demand
    emscripten_cancel_main_loop();
}

int main() {
    // setup a dummy single-shot main loop callback just to shut up a useless Emscripten error message on calling eglSwapInterval()
    emscripten_set_main_loop(onMainLoop, -1, 0);

    Handle(Wasm_Window) window = new Wasm_Window("canvas");

    Handle(OpenGl_GraphicDriver) driver = new OpenGl_GraphicDriver(nullptr, false);
    driver->InitContext();
    Handle(V3d_Viewer) viewer = new V3d_Viewer(driver);
    viewer->SetDefaultLights();
    Handle(V3d_View) view = viewer->CreateView();
    view->ChangeRenderingParams().NbMsaaSamples = 4;

    double width, height;
    emscripten_get_element_css_size("canvas", &width, &height);
    double devicePixelRatio = emscripten_get_device_pixel_ratio();
    emscripten_set_canvas_element_size("canvas", width * devicePixelRatio, height * devicePixelRatio);

    Handle(AIS_ViewCube) viewCube = new AIS_ViewCube();
    Handle(AIS_InteractiveContext) context = new AIS_InteractiveContext(viewer);
    context->Display(viewCube, false);

    view->SetWindow(window);

    return 0;
}
Attachments: 
gkv311 n's picture

Try displaying some common objects instead of ViewCube.
ViewCube is displayed within immediate top level by default, which cannot use MSAA on WebGL - you will need to move it to another ZLayer or change properties of ZLayer to disable immediate flag.

Yunku Kang's picture

Ah, all of your suggestions work. Thank you very much.