Closed jeffguy closed 5 years ago
Emscripten has partial support for emulating various GL methods not in ES2. As mentioned in that output, you need to compile with -s LEGACY_GL_EMULATION=1
to enable that. That should get rid of most of those errors.
I would also strongly recommend using a new version of emscripten, based on the output that one looks quite old.
Good catch. I'm using emscripten 1.10, which is the version in the Ubuntu 14.04 repo. I'm trying to get llvm-3.7 to build so I can use emscripten 1.34. Then I'll give it another shot.
Just to be sure, you need not stock llvm 3.7, but emscripten's fork of llvm, or get the sdk.
Oh! I was going down the wrong path. I'll look at that tonight. Thanks!
On Tue, Sep 8, 2015 at 2:30 PM, Alon Zakai notifications@github.com wrote:
Just to be sure, you need not stock llvm 3.7, but emscripten's fork of llvm http://kripken.github.io/emscripten-site/docs/building_from_source/building_fastcomp_manually_from_source.html, or get the sdk.
— Reply to this email directly or view it on GitHub https://github.com/kripken/emscripten/issues/3753#issuecomment-138661946 .
Summary: I got further, but am having trouble with getting emcc to recognize "-s LEGACY_GL_EMULATION=1". Where should I put this flag? Thanks!
Details: Thanks for your help! I was able to download and build emscripten and dependencies from emsdk_portable. libphysfs needed a minor modification to point at emsdk_portable/emscripten/tag-1.34.7/tests/zlib/zlib.h. emcc --version says: emcc (Emscripten gcc/clang-like replacement) 1.34.7 () Copyright (C) 2014 the Emscripten authors (see AUTHORS.txt) This is free and open source software under the MIT license. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Then i tried compiling descent, one step was: $ emcc -o arch/ogl/ogl.o -c -std=gnu99 -Wall -funsigned-char -Werror=implicit-int -Werror=implicit-function-declaration -pthread -O2 -DLINUX -DHAVE_STRUCT_TIMESPEC -DHAVE_STRUCT_TIMEVAL -D_GNU_SOURCE=1 -D_REENTRANT -DNETWORK -DDXX_VERSION_MAJORi=0 -DDXX_VERSION_MINORi=58 -DDXX_VERSION_MICROi=1 -DOGL -DNO_ASM -DUSE_SDLMIXER -DNDEBUG -DRELEASE -DUSE_UDP -DUSE_TRACKER -DSHAREPATH=\"/usr/local/share/games/d1x-rebirth/\" -I../physfs-2.0.3 -Iarch/linux/include -Iinclude -Imain -Iarch/include arch/ogl/ogl.c In file included from arch/ogl/ogl.c:53: In file included from main/playsave.h:24: In file included from main/kconfig.h:26: arch/include/key.h:190:2: error: unknown type name 'SDLKey' SDLKey sym; ^ 1 error generated. ERROR root: compiler frontend failed to generate LLVM bitcode, halting
I remember you mentioning LEGACY_GL_EMULATION=1, and I ran $ grep -R SDLKey emsdk_portable emsdk_portable/emscripten/tag-1.34.7/system/include/SDL/SDL_compat.h:#define SDLKey SDL_Keycode
That seems to confirm that I want legacy gl emulation, so I tried: $ emcc -s LEGACY_GL_EMULATION=1 -o arch/ogl/ogl.o -c -std=gnu99 -Wall -funsigned-char -Werror=implicit-int -Werror=implicit-function-declaration -pthread -O2 -DLINUX -DHAVE_STRUCT_TIMESPEC -DHAVE_STRUCT_TIMEVAL -D_GNU_SOURCE=1 -D_REENTRANT -DNETWORK -DDXX_VERSION_MAJORi=0 -DDXX_VERSION_MINORi=58 -DDXX_VERSION_MICROi=1 -DOGL -DNO_ASM -DUSE_SDLMIXER -DNDEBUG -DRELEASE -DUSE_UDP -DUSE_TRACKER -DSHAREPATH=\"/usr/local/share/games/d1x-rebirth/\" -I../physfs-2.0.3 -Iarch/linux/include -Iinclude -Imain -Iarch/include arch/ogl/ogl.c In file included from arch/ogl/ogl.c:53: In file included from main/playsave.h:24: In file included from main/kconfig.h:26: arch/include/key.h:190:2: error: unknown type name 'SDLKey' SDLKey sym; ^ 1 error generated. ERROR root: compiler frontend failed to generate LLVM bitcode, halting
This looks rather the same, as though I'm not successfully enabling LEGACY_GL_EMULATION. Where should I put the -s flag?
Thanks again for all your help!
On Tue, Sep 8, 2015 at 2:30 PM, Alon Zakai notifications@github.com wrote:
Just to be sure, you need not stock llvm 3.7, but emscripten's fork of llvm http://kripken.github.io/emscripten-site/docs/building_from_source/building_fastcomp_manually_from_source.html, or get the sdk.
— Reply to this email directly or view it on GitHub https://github.com/kripken/emscripten/issues/3753#issuecomment-138661946 .
SDL and GL emulation are not related. I'm not sure what that SDLKey problem is - is sdl1 or 2 being used? And is it using the sdl headers from emscripten, or something in the local system (which would be bad)?
emcc -s LEGACY_GL_EMULATION=1
should be done for GL emulation, when compiling bitcode to JS, in the "link" stage. It has no effect when building to bitcode (with commands like -o arch/ogl/ogl.o
, .o
files contain bitcode).
Thanks for making that distinction. SDLKey is only referenced in two files. I think I should be able to patch that out. I'll try tomorrow, after some good sleep.
I've made much progress, thanks to the IRC folks. I think I've commented out all the code related to audio, and the game loads far enough to create a black rectangle that looks like it will be used to render the screen. Then it crashes, saying, "missing function: glPrioritizeTextures". Is this something emscripten should support, or do I need to find a way to work around this function call?
When I compiled Descent in C, I used these options: "opengl=1 opengles=0 sdlmixer=0" (which was a guess at what would work best with emscripten).
I'm running emcc with "-s SAFE_HEAP=1 -s LEGACY_GL_EMULATION=1 -s TOTAL_MEMORY=33554432 -s GL_UNSAFE_OPTS=0".
Also, in case it's relevant, emscripten prints "WARNING: using emscripten GL emulation. This is a collection of limited workarounds, do not expect it to work." and "WARNING: using emscripten GL immediate mode emulation. This is very limited in what it supports" on the console.
glPrioritizeTextures
is not present in WebGL, and I'm not sure how we could emulate it. It's best to avoid calling it if possible.
Does the codebase have an OpenGL ES2 rendering option? That would be much easier than relying on emulation. Emscripten's GL emulation is basically good enough to render Cube 2, it's very likely in a non-trivial rendering engine you'd find plenty that we don't support. See http://kripken.github.io/emscripten-site/docs/porting/multimedia_and_graphics/OpenGL-support.html
I don't know much about OpenGL, but these two things make me doubt it supports ES 2.0.
===== D1X-Rebirth v0.58.1 =====
'opengl=[0/1]' build with OpenGL support [default: 1]
'opengles=[0/1]' build with OpenGL ES support [default: 0]
'sdlmixer=[0/1]' build with SDL_Mixer support for sound and music (includes external music support) [default: 1]
'asm=[0/1]' build with ASSEMBLER code (only with opengl=0, requires NASM and x86) [default: 0]
'debug=[0/1]' build DEBUG binary which includes asserts, debugging output, cheats and more output [default: 0]
'use_tracker=[0/1]' enable Tracker support (requires udp) [default :1]
'verbosebuild=[0/1]' print out all compiler/linker messages during building [default: 0]
Do you agree with my assessment? If so, how different are ES 1.0 and ES 2.0? Perhaps I could port Descent in less than 16 man hours? Or are there other c++ -> browser converters I should consider? Or am I maybe biting off more than I can chew? Thanks for your help!
OpenGL ES1 is quite different from ES2, but much closer to it than normal OpenGL. Probably worth trying that path. There's a higher chance we support the necessary emulation for that.
If that happens to use emulation features we support, it might just work. If not, we could look into adding the missing pieces, but it could potentially be very hard.
In that case, an option is to use Regal, which emulates legacy GL. Last I checked it was very close to working on Emscripten, and if it did, GL like this should no longer be a problem.
I eventually got Descent to compile with GL ES 1. It didn't link successfully (missing a library), but I figure that shouldn't matter for emcc, since emcc provides its own libraries.
Descent calls glViewport several times. Emscripten implements as "function _glViewport(x0, x1, x2, x3) { GLctx.viewport(x0, x1, x2, x3) }", and firefox complains "GLctx is undefined".
Some googling suggests GL ES 2 still uses glViewport, so I'm surprised this didn't work. Any idea what I've done wrong? Thanks agoin for your help!!
Here are the relevant glViewport lines: include/internal.h:#define OGL_VIEWPORT(x,y,w,h){if (w!=last_width || h!=last_height){glViewport(x,grd_curscreen->sc_canvas.cv_bitmap.bm_h-y-h,w,h);last_width=w;last_height=h;}} arch/ogl/ogl.c: OGL_VIEWPORT(grd_curcanv->cv_bitmap.bm_x,grd_curcanv->cv_bitmap.bm_y,Canvas_width,Canvas_height); arch/ogl/ogl.c: OGL_VIEWPORT(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h); arch/ogl/gr.c: OGL_VIEWPORT(0,0,w,h);
On Sun, Sep 13, 2015 at 12:34 AM, Alon Zakai notifications@github.com wrote:
OpenGL ES1 is quite different from ES2, but much closer to it than normal OpenGL. Probably worth trying that path. There's a higher chance we support the necessary emulation for that.
If that happens to use emulation features we support, it might just work. If not, we could look into adding the missing pieces, but it could potentially be very hard.
In that case, an option is to use Regal https://github.com/p3/regal, which emulates legacy GL. Last I checked it was very close to working on Emscripten, and if it did, GL like this should no longer be a problem.
— Reply to this email directly or view it on GitHub https://github.com/kripken/emscripten/issues/3753#issuecomment-139843997 .
clb helped me figure out that: eglCreateContext() calls to glutCreateWindow(), which calls to Browser.createContext(Module['canvas'], true, true, contextAttributes);, which calls to GL.makeContextCurrent(contextHandle);, which should set GLctx = non-null;
Indeed, I'm calling eglCreateContext before glViewport, but I hadn't noticed my eglCreateContext is tripping over if (glesContextVersion != 2) {EGL.setErrorCode(0x3005 /* EGL_BAD_CONFIG */);
I'll see if I can figure out a way to hard code glesContextVersion==2
On Mon, Sep 14, 2015 at 4:35 PM, Jeff Guy jeffguy@gmail.com wrote:
I eventually got Descent to compile with GL ES 1. It didn't link successfully (missing a library), but I figure that shouldn't matter for emcc, since emcc provides its own libraries.
Descent calls glViewport several times. Emscripten implements as "function _glViewport(x0, x1, x2, x3) { GLctx.viewport(x0, x1, x2, x3) }", and firefox complains "GLctx is undefined".
Some googling suggests GL ES 2 still uses glViewport, so I'm surprised this didn't work. Any idea what I've done wrong? Thanks agoin for your help!!
Here are the relevant glViewport lines: include/internal.h:#define OGL_VIEWPORT(x,y,w,h){if (w!=last_width || h!=last_height){glViewport(x,grd_curscreen->sc_canvas.cv_bitmap.bm_h-y-h,w,h);last_width=w;last_height=h;}} arch/ogl/ogl.c: OGL_VIEWPORT(grd_curcanv->cv_bitmap.bm_x,grd_curcanv->cv_bitmap.bm_y,Canvas_width,Canvas_height); arch/ogl/ogl.c: OGL_VIEWPORT(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h); arch/ogl/gr.c: OGL_VIEWPORT(0,0,w,h);
On Sun, Sep 13, 2015 at 12:34 AM, Alon Zakai notifications@github.com wrote:
OpenGL ES1 is quite different from ES2, but much closer to it than normal OpenGL. Probably worth trying that path. There's a higher chance we support the necessary emulation for that.
If that happens to use emulation features we support, it might just work. If not, we could look into adding the missing pieces, but it could potentially be very hard.
In that case, an option is to use Regal https://github.com/p3/regal, which emulates legacy GL. Last I checked it was very close to working on Emscripten, and if it did, GL like this should no longer be a problem.
— Reply to this email directly or view it on GitHub https://github.com/kripken/emscripten/issues/3753#issuecomment-139843997 .
This issue has been automatically marked as stale because there has been no activity in the past 2 years. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant.
@jeffguy I've ported Descent 1 in my fork https://github.com/midzer/dxx-rebirth/tree/emscripten
Thanks, @midzer! I appreciate your hard work :)
@midzer can we try it online somewhere? I loved that game back in the day!
@sbc100 Sure -> https://midzer.de/games#descent-i
Probably gonna update the port soon as upstream repo has many new changes.
Wow, amazing! I did run into a Uncaught RuntimeError: memory access out of bounds
eventually.. but so great to see that game again.
I don't know if this is the right place to post. If not, where would you suggest asking this question?
I'm trying to port Descent 1 (google dxx rebirth) to the browser. I have worked through a bunch of issues, and am getting errors in the link step. In summary, my errors follow these patterns:
I see references on the web that mention glAlphaFunc not being implemented, but when I look at emscripten's source (which I used to build), I see it defined.
I'd appreciate any help you can give!
My link command is:
My full error list is: