-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
Enable Glfw + Emscripten + OpenGLES 3.0/WebGL 2.0 #1941
Conversation
Thank you Omar :) this is super useful and detailed. A few things below:
According to https://kripken.github.io/emscripten-site/docs/compiling/Building-Projects.html section "Detecting Emscripten in Preprocessor" we could use
Therefore those header could probably be included directly if they are standard?
(Also note the approach in https://github.com/ocornut/imgui/pull/1945/files were gl3w.cpp has been modified to support GL ES functions.) |
Thanks Omar for the review :)
|
Hello. I'l porting some examples to Emscripten too. See my patch for bindings. Looks like we have problems with input mose events for current window - this is Emscripten bug. |
Yep, currently emscripten has marked that as a bug specifically related to glfw, the SDL version has the input working fine. I think once the whole application is going to run in browser, there is always a solution. My solution was to use the browser callback functions and call my own C++ code passing the current information of the mouse, keyboard, window size ... etc |
@ziecleto Moved from #1984
It is Do you know if there are standard defines that could allow us to detect OpenGL ES ? |
The official preprocessor define is I am not aware unfortunately of any OPENGL_ES defined, but I've found a nicer fix, more API oriented and I think it's the correct fix:
So openGL ES does not define GL_POLYGON_MODE so instead of EMSCRIPTEN using GL_POLYGON_MODE on those 3 functions that are using glPolyMode features will achieve the correct implementation. Cheers, |
That's a good point, we can test for Similar the |
I merged this with minor tweaks.
and
Seems like we could rely on those for further testing? |
Yes I think that's the right approach, in fact I have fixed also few other compiler errors, in particular:
Fails on Clang5.0+ (C++17) with warning as errors:
And equally the "fix":
Will fail on GCC 8.1.0+ (and probably earlier)
Using Also there are a couple of other warning as errors on C++17 which are relatively easy to fix, I can prepare a PR with all of this if you prefer. Cheers, |
@ziocleto Yes, I would appreciate a PR, thank you. |
I'll create che other "warnings as errors" c++17 PR fixes later as I think it's better to have 1 fix per PR to keep a good atomic repository! |
…n't seem to handle focus related calls. (#1941)
@podgorskiy I have pushed your focus workaround too. |
Sorry, I had to create a new github account, I would be glad to help maintain that pull request if any changes need to be made in the future. |
Thank you @osheriff ! Btw we now have a Emscripten example and GL code has been massaged enough (with your help above and other PR) into supporting ES2 and ES3. When I tried to setup Emscripten with ES3/WebGL it wouldn't work on my Firefox. I switched the demo to ES2 thinking it would maximize compatability anyway? Feedback/corrections welcome. |
Yeah sure, I have a couple of demos that I've made before one for WebGL2 GLSL v3.0ES and the other for WebGL with GLSL v1.0, I will get back to the code, clean it and will provide you with demos for each. |
@osheriff You shouldn't need to speficially work on your old demo (as there's enough in the current repo and the GL code itself support now WebGL 1.0 and WebGL 2.0. I'm just stating we are now including an Emscripten exemple in master, so anyone interested in Emscripten tech will be more likely to help improve the demo further, and you might have feedback if you happen to use it later. |
@ocornut Ok great, thanks Omar for your work :) |
This commit will allow ImGui to be built using Emscripten and ported to WebGL2 OpenGLES3
So generally one can build the same source to a normal desktop app and be able to have the same source built to WebGL2 and have it working inside chrome.
Here is a demo project https://github.com/o-micron/OpenWebGL
See the Makefile, I use -D EMSCRIPTEN_BUILD when porting to WebGL2 using Emscripten
I added vertex and fragment shaders version 300 es
I added vertex and fragment shaders version 410 core
I added EMSCRIPTEN_BUILD ifdefs to allow/block some options because not everything is supported etc ...
1 issue yet to be solved is the input callbacks in browser, I cannot for example expand the ImGui TrreeNode in the WebGL2 app. I have to investigate more on that, maybe it is a MacOs bug. I have no idea. According to emscripten docs glfw has a limited input support https://kripken.github.io/emscripten-site/docs/porting/emscripten-runtime-environment.html#input-output
Please review and correct me if there is a design issue or something I am not aware of