-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Emscripten full screen and antialiasing of 2d-shapes do not work anymore #6758
Comments
Maybe the full screen issue is related to that: |
Regarding the fullscreen issue (not sure if it is helpful): If I use Module.requestFullscreen with a lower case "s" like in my example above, I can enter a black fullscreen without an error message, but if I switch back the webassembly canvas is gone (or minimized to the size 0x0). |
Thank you for digging into this. I added this to our 0.12.0 tracking issue. |
From the forum this works for me for the fullscreen issue: I can toggle back and forth and things work as expected. |
You can also use pointerlock with "Module['canvas'].requestPointerLock()". What does not work with this method is recalculating the mouse position and resizing the canvas. For that I had to change set_canvas_element_size to set_canvas_size in ofxAppEmscriptenWindow.cpp (and use Module.requestFullscreen()). set_canvas_size is deprecated, but it is still used for fullscreen in https://github.com/emscripten-core/emscripten/blob/main/src/library_browser.js:
And in the Emscripten library library_html5.js I changed this, so the mouse is also recalculated if the canvas is not resized:
|
wow thanks @Jonathhhan ! |
@ofTheo thanks. Here you can test how fullscreen works with the changes from above: https://simplesequencer.handmadeproductions.de/ Not really related, but I also found a way to use DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1. |
And antialiasing works again if I add antialias = true to webGLContextAttributes in https://github.com/emscripten-core/emscripten/blob/main/src/library_webgl.js (I also needed to change webgl to webgl2, because I use webgl2):
Only maybe not very practical to change a lot of Emscripten files... |
Maybe it would make sense to change a few additional webGLContextAttributes parameters (not sure, but I have the feeling it improves the performance slightly)?
console.log(webGLContextAttributes):
About alpha I found: Most applications, even those requiring alpha blending, can be structured to produce 1.0 for the alpha channel. The primary exception is any application requiring destination alpha in the blending function. If feasible, it is recommended to do this rather than using alpha:false." And about powerPreference: |
@Jonathhhan Yeah, I wonder if it is possible to pass through these things from OF so we don't have to set them inside of emscripten. In the .js file generate by emmake in bin/ ( ie: I tried setting it to true there, but it didn't seem to make a difference. The window / context creation is done in here: I think whatever we did would have to account for if antialias is supported on the client side - so it might need to be something at the javascript level or maybe using a similar approach to how we handled the depth resolution here: |
@ofTheo Your suggestion works great. This is the result:
Here is the updated ofxAppEmscriptenWindow.cpp (it also works if I just set 8 for EGL_ALPHA_SIZE and 1 for EGL_SAMPLE_BUFFERS but like you said, that could be problematic): Only not sure if it is possible to set the majorVersion to 2 in ofxAppEmscriptenWindow.cpp and if it is even necessary (seems to work like it is, only that I have to select webgl2 manually - if used). And I wonder how to define the webgl context id name in ofxAppEmscriptenWindow.cpp (for changing the argument "target" in https://github.com/emscripten-core/emscripten/blob/main/src/library_html5.js from 0 to "#canvas"), so that DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1 works without editing the emscripten file. |
Thanks so much @Jonathhhan for figuring this out! 🤘 |
Now it works also without -s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=0
And and replaced canvasX / canvasY with targetX / targetY. Only thing for now that the recalculation of the mouse value in fullscreen mode still happens (with my edit) in https://github.com/emscripten-core/emscripten/blob/main/src/library_html5.js not sure how I can get the css canvas size into Open Frameworks. The other big issue (maybe more an improvement) is, that it would be really great, if audio could run in a seperate JS thread for reducing latency and audio artifacts. Like with audioworkletprocessor https://developer.mozilla.org/en-US/docs/Web/API/AudioWorkletProcessor and not with ScriptProcessorNode https://developer.mozilla.org/en-US/docs/Web/API/ScriptProcessorNode. Maybe also pthreads https://emscripten.org/docs/porting/pthreads.html could be a solution? I think I understand the basic concept of audioworkletprocessor, but I dont know how to pass the wasm module (already tried a few things, without much success). Also not sure, if the bottleneck is somewhere else, but I guess its the fact that everything happens in the main JS thread. Anyhow, with a buffersize of 4096 audio is quite stable right now, but with a lower buffer size it depends on the browser and the CPU/GPU. |
changing this:
in https://github.com/Jonathhhan/openFrameworks/blob/master/addons/ofxEmscripten/src/ofxAppEmscriptenWindow.cpp and adding the flag -s USE_WEBGL2=1 to config.emscripten.default.mk enables webgl2 without editing any Emscripten file (in addition I use -s WEBGL2_BACKWARDS_COMPATIBILITY_EMULATION=1 for backwards compatibility with webgl1 https://emscripten.org/docs/optimizing/Optimizing-WebGL.html). |
Thanks @Jonathhhan ! I think ideally you would be able to set the GL version via the |
@ofTheo Yes, that would be better. Just dont know how to set ofGLESWindowSettings::glesVersion (or can I just use
?) and pass it to the EGL context (I guess, I still need the -s USE_WEBGL2=1 and -s WEBGL2_BACKWARDS_COMPATIBILITY_EMULATION=1 flags). Edit: Tried to get the glesVersion without success (I think I set it right). On the other hand: Maybe I can always use webgl2 with the -s WEBGL2_BACKWARDS_COMPATIBILITY_EMULATION=1 flag, but the device / browser needs to support webgl2 then (which would also be the case if ofGLESWindowSettings::glesVersion is set to GLES 3). |
@ofTheo thank you very much for your help. I would say, that basically this issues (and some others) are solved. Only the question, how to implement the solutions in the best way for the pull requests (hard for me to judge, because I am really not a experienced c++ programmer). One small thing, that isnt really an issue: The mouse events do not work, if the mouse is outside of the Emscripten canvas (I guess it works with the normal OF apps). |
Thanks @Jonathhhan ! I will probably pull in everything from your PR and maybe do a bit of cleanup and small fixes to make it more modular as you suggested. I can change the workflows now to use 2.0.6 and we can change the site docs to suggest that version too. Thanks!! |
@ofTheo just testet it with the current OF nightly built for Linux (I always use Linux / Ubuntu for the Emscripten stuff) and it works well. And I tried to use pthreads with this in mind:
and: Almost everything compiles fine, but then i get the error message: One last thing: In https://github.com/openframeworks/openFrameworks/blob/master/addons/ofxEmscripten/libs/html5audio/lib/emscripten/library_html5audio.js I define the samplerate for the audioContext like:
Otherwise the samplerate is set to the samplerate of the sound device (which results in different pitch and tempo). In the best case it could also be set as an argument. |
Some new findings: It is possible to compile OF patches with Emscripten with c++17, and to use std::filesystem instead of boost::filesystem (so boost isnt necessary anymore?). For that I had to set
In ofFileUtils.h I added Here is a temporary example (the graphicsExample) compiled with pthreads, std::filesystem and c++17, but not sure how to use the worker / sharedArrayBuffer: https://gameoflife3d.handmadeproductions.de/ Edit: Actually my changes broke the filesystem: |
I get this message when i press full screen:
And the circle isnt antialiased, while it is when I compile for desktop. And both were working with Emscripten before (I guess until OF 0.11.0). Here for example works both: https://arturocastro.net/files/of-emscripten/polygonExample/
And here not (my example - but it seems the same for the other examples): http://puredatagui.handmadeproductions.de/
Antialiasing fonts does work now, after I made this change: #6745
Tested with OF 0.11.2 / Emscripten 1.40.1 / Ubuntu 20.04
The text was updated successfully, but these errors were encountered: