Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Qt for WebAssembly] WebGL1 support #49

Open
birkskyum opened this issue Sep 9, 2022 · 20 comments
Open

[Qt for WebAssembly] WebGL1 support #49

birkskyum opened this issue Sep 9, 2022 · 20 comments
Labels
enhancement New feature or request platform: WASM WASM platform issues
Milestone

Comments

@birkskyum
Copy link
Member

birkskyum commented Sep 9, 2022

Ticket to demonstrate utilizing Qt for WebAssembly, to run the OpenGL2 legacy branch of MapLibre Native as a WebGL1 build in the browsers.

Update

This is working now, and the findings are documented in a separate repo:

Working demo here

Build instructions and binaries here

MapLibre Native WASM overview here

@birkskyum birkskyum added the enhancement New feature or request label Sep 9, 2022
@ntadej
Copy link
Collaborator

ntadej commented Sep 9, 2022

The code already builds with emscripten (using Qt platform). The problem is threading is generally not supported by wasm yet and the codebase uses a lot of it.

@birkskyum
Copy link
Member Author

Do you have any pointers on how I can run this build? The GL JS is also really slow without the web workers, but it runs.

@ntadej
Copy link
Collaborator

ntadej commented Sep 9, 2022

No, Qt wasm does not run unfortunately. It crashes somewhere where threading wants to be used as Qt is nominally not built with the support for that (but maybe this has changed since).

You can build it the same as for other Qt platforms, you just use the wasm build of Qt. See https://doc.qt.io/qt-6/wasm.html

@birkskyum birkskyum changed the title Emscripten / wasm build Emscripten / wasm build for web Sep 10, 2022
@ankurvdev
Copy link

FWIW I managed to get it working with a few patches by statically linking with Qt6-wasm built via vcpkg (with pthread and asyncify)
The only major issue was getting the QEventLoop to play well with the JS event loop (which arguably is a Qt issue)

@birkskyum birkskyum reopened this Aug 29, 2023
@amirtu
Copy link

amirtu commented Sep 12, 2023

poc
Indeed, it is possible to make it work with the above-mentioned way.

@wipfli
Copy link

wipfli commented Sep 13, 2023

@amirtu do you have a public demo of this?

@birkskyum
Copy link
Member Author

birkskyum commented Sep 13, 2023

so many opportunities here - let's add a compilation target for this in the repo

@birkskyum
Copy link
Member Author

birkskyum commented Sep 18, 2023

Qt has some serious implications in terms of licensing (LGPLv3 or commercial license). What paths can we take to end up with a more permission license?

@birkskyum birkskyum changed the title Emscripten / wasm build for web Qt for WebAssembly (webgl2) demo w/ Emscripten Sep 26, 2023
@birkskyum birkskyum transferred this issue from maplibre/maplibre-native Oct 14, 2023
@birkskyum
Copy link
Member Author

Update: In order to get multithreading working properly, we're awaiting bugfix in Qt that'll allow the QNetworkAccessManager to make requests from within threads in wasm. https://bugreports.qt.io/browse/QTBUG-109396

@amirtu
Copy link

amirtu commented Nov 18, 2023

@amirtu do you have a public demo of this?

https://sophomore.solutions/app.html

UPD.: https://amirtu.netlify.app/mapbox-qt-wasm/app.htm

@birkskyum
Copy link
Member Author

@amirtu do you have a public demo of this?

https://sophomore.solutions/app.html

Tiles are found by zooming to Almaty in Kazakhstan

@ntadej ntadej added this to the Future milestone Apr 18, 2024
@birkskyum
Copy link
Member Author

birkskyum commented May 7, 2024

Tried again with latest versions. It says that this check returns false / that vertexArray doesn't exist:

bool Context::supportsVertexArrays() const {
    return vertexArray && vertexArray->genVertexArrays && vertexArray->bindVertexArray &&
           vertexArray->deleteVertexArrays;
}

This check was removed from MapLibre Native a year ago, as part of the shift to OpenGL 3+

maplibre/maplibre-native@8ff6704#diff-25e92576a5706afc614df2db9c0a00c25bc1636aefb081dde7d2b35aceb6b069L216-L228

Would be interesting to see how this faires after the maplibre-native-qt has been reconciled with latest maplibre-native

@birkskyum
Copy link
Member Author

birkskyum commented May 8, 2024

When the style is downloaded, the callback that should fire isn't firing. That's where things are now.

@andreamancuso
Copy link

andreamancuso commented Jun 23, 2024

Hello folks - are there plans to add support for emscripten - no Qt dependencies? I'd like to embed Maplibre Native with Dear Imgui + emscripten.

Looks like this is already achievable as part of https://github.com/maplibre/maplibre-rs ?

@birkskyum birkskyum changed the title Qt for WebAssembly (webgl2) demo w/ Emscripten Qt for WebAssembly/WASM (webgl2) demo w/ Emscripten Jul 25, 2024
@birkskyum
Copy link
Member Author

birkskyum commented Jul 26, 2024

After two years of working on this, I finally have a POC running!

More info here

Screen.Recording.2024-07-27.at.00.34.26.mov

@ntadej
Copy link
Collaborator

ntadej commented Jul 27, 2024

Can you open a draft PR with your fixes/hacks?

@birkskyum
Copy link
Member Author

birkskyum commented Jul 27, 2024

@ntadej , what gave a visual output in the end was changing this reply-> url in the opengl2 branch of Native. After that the map kept crashing due to duplicate requests, but then changing deleteLater(); to abort(); fixed that.

void HTTPFileSource::Impl::onReplyFinished() {
    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
--     const QUrl& url = reply->request().url();
++     const QUrl& url = reply->url();

    auto it = m_pending.find(url);
    if (it == m_pending.end()) {
--        reply->deleteLater();
++        reply->abort();
        return;
    }

    QByteArray data = reply->readAll();
    QVector<HTTPRequest*>& requestsVector = it.value().second;

    // Cannot use the iterator to walk the requestsVector
    // because calling handleNetworkReply() might get
    // requests added to the requestsVector.
    while (!requestsVector.isEmpty()) {
        requestsVector.takeFirst()->handleNetworkReply(reply, data);
    }

    m_pending.erase(it);
--    reply->deleteLater();
++    reply->abort();
}

Apart from that I just remove everything else from the example than the map, and added a defaultPitch function, but those changes are less interesting.

@ntadej
Copy link
Collaborator

ntadej commented Jul 27, 2024

Let's keep this open until it properly works

@ntadej ntadej reopened this Jul 27, 2024
@birkskyum birkskyum changed the title Qt for WebAssembly/WASM (webgl2) demo w/ Emscripten Qt for WebAssembly/WASM (webgl1) demo w/ Emscripten Jul 27, 2024
@birkskyum birkskyum changed the title Qt for WebAssembly/WASM (webgl1) demo w/ Emscripten MapLibre Native Qt - WebAssembly demo (webgl1 / opengl2-branch) Jul 27, 2024
@birkskyum birkskyum changed the title MapLibre Native Qt - WebAssembly demo (webgl1 / opengl2-branch) WebAssembly demo (webgl1 / opengl2-branch) Jul 27, 2024
@birkskyum
Copy link
Member Author

birkskyum commented Jul 27, 2024

Regarding performance, I find it more feasible to invest in getting a webgl2 build going using the latest OpenGL 3/4 backend from MapLibre Native Core, rather than spending a lot of time optimizing on the opengl2 legacy branch.

@birkskyum birkskyum changed the title WebAssembly demo (webgl1 / opengl2-branch) Qt WebAssembly demo (webgl1 / opengl2-branch) Jul 30, 2024
@birkskyum birkskyum removed this from the Future milestone Jul 31, 2024
@birkskyum birkskyum changed the title Qt WebAssembly demo (webgl1 / opengl2-branch) Qt WebGL1 demo Aug 3, 2024
@birkskyum birkskyum removed the enhancement New feature or request label Aug 5, 2024
@birkskyum
Copy link
Member Author

birkskyum commented Aug 5, 2024

@ntadej Can you elaborate on what you find is not working here? Is it the 3 line changes to the opengl-2 branch in MapLibre Native? I've made a pr here to fix those with conditionals and reduce the steps needed for compilation.

Since this opengl2 work will be obsoleted by #59 / #147 rather soon, I suggest we focus on getting that updated version in the CI rather than this webgl1 version which has little-to-no practical use anyway due to resource usage.

@birkskyum birkskyum changed the title Qt WebGL1 demo Qt WebGL1 support Aug 5, 2024
@birkskyum birkskyum changed the title Qt WebGL1 support [Qt for WebAssembly] WebGL1 support Aug 5, 2024
@ntadej ntadej added enhancement New feature or request platform: WASM WASM platform issues labels Aug 16, 2024
@ntadej ntadej added this to the Future milestone Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request platform: WASM WASM platform issues
Projects
None yet
Development

No branches or pull requests

6 participants