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

Study possible sokol_app backend #3

Open
pthom opened this issue Sep 12, 2020 · 0 comments
Open

Study possible sokol_app backend #3

pthom opened this issue Sep 12, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@pthom
Copy link
Owner

pthom commented Sep 12, 2020

I investigated the possibility to use sokol_app as a backend for imgui_manual. I'm not sure the next version will be using sokol, but this issue it here to summarize the status.

A demo of imgui_manual that uses sokol can be seen live here:
https://pthom.github.io/imgui_manual_online/manual_sokol/imgui_manual.html?version=1

In order to use sokol, I had to do a few adaptations:

Inside hello_imgui:

Full diff here: https://github.com/pthom/hello_imgui/compare/sokol?expand=1

hello_imgui provides the following services:

  1. a backend for imgui (similarly to sokol_app.h, but limited to imgui)
  2. an easy way to organize the app docking layout and its callbacks: this part is heavily used by imgui_manual.
  3. a way to embed assets into the application being built (be it on iOS, Android, emscripten, windows, etc). This is also used by imgui_manual.

So the way I did it was to bypass completely the backend provided by hello_imgui, and instead create a sapp_desc from HelloImGui::RunnerParams: see hello_imgui_sokol.h and hello_imgui_sokol.cpp

This way a minimal app that uses sokol and hello_imgui would look like this: hello_imgui_demo_sokol.cpp

Inside imgui_manual:

Full diff here: https://github.com/pthom/imgui_manual/compare/sokol?expand=1

Once hello_imgui was adapted, the modifications were quite straightforward: the most important modification is in the main file, and it shows the difference when launching the manual via sokol_main instead of the usual main

Status:

Wasm blob and full page size:

With sokol, the wasm blob is twice smaller. However since there are lots of resources in the manual (see imgui_manual.data), the gain is not so obvious.

See below a comparison of the sizes in kilobytes:

➜  imgui_manual git:(sokol) ✗ find build_emscripten/src/ -name "imgui_manual.*" -type f |xargs du -ck
4       build_emscripten/src//imgui_manual.html
2112    build_emscripten/src//imgui_manual.wasm
3300    build_emscripten/src//imgui_manual.data
276     build_emscripten/src//imgui_manual.js
5692    total
➜  imgui_manual git:(sokol) ✗ find build_emscripten_sokol/src/ -name "imgui_manual.*" -type f |xargs du -ck
4       build_emscripten_sokol/src//imgui_manual.html
1088    build_emscripten_sokol/src//imgui_manual.wasm
3300    build_emscripten_sokol/src//imgui_manual.data
172     build_emscripten_sokol/src//imgui_manual.js
4564    total

Current limitations of the sokol emscripten version

  • At the moment, it cannot load additional fonts, so that the manual looks a bit broken (since lots of icons use font-awesome)
  • Also image loaded via OpenGL from the assets (see image_gl.cpp) are not displayed
@pthom pthom added the enhancement New feature or request label Sep 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant