isle-portable icon indicating copy to clipboard operation
isle-portable copied to clipboard

Add experimental WebGL support to Emscripten

Open foxtacles opened this issue 6 months ago • 4 comments

Open GL ES 2.0 renderer works on Emscripten out of the box, except for 2D rendering:

image image

The main modification here is that it should be possible to provide a static description for a device we know is "always" available (such as WebGL in browsers). It is not possible to enumerate devices and test renderers in Emscripten the way we do it on other platforms. Even if we knew the SDL_Window at the time of enumeration, this still won't work since contexts can't be created multiple times, i.e. once a OpenGL ES context is established it's not possible to go back to software renderer anymore.

The interface modification as seen in this PR essentially turns the enumeration for Emscripten into providing a static list of available devices (Software, OpenGL ES 2.0).

I'm not sure if fixing the 2D rendering would necessitate creating a completely new renderer backend, since I have no idea why it isn't working. In that case we could change this again later.

foxtacles avatar Jun 28 '25 18:06 foxtacles

Skulde i look into 2d rendering it seems like it fails in your screen shot.

Sure, that would be great. I don't really know where to start looking. 3D seems to work perfectly.

foxtacles avatar Jun 28 '25 18:06 foxtacles

One thing I've already tried is enabling -sFULL_ES2=1: https://emscripten.org/docs/porting/multimedia_and_graphics/OpenGL-support.html#opengl-support-opengl-es2-0-emulation

but it didn't make a difference (except now the Infocenter background is black instead of blue)

Use of glDrawArrays etc. is present in the current OpenGL ES renderer so maybe we need it though.

foxtacles avatar Jun 28 '25 18:06 foxtacles

2d rendering ended up being implemented using different rendering modes for most drivers as it was easier to position vertex like you would 2d surfaces, but that's not possible for sdl_gpu so I did have to implement it using 3d transformation there, I can likely just port that over to es.

Regarding the descriptors I'm doing the same for 3ds but much less invasive so I would like to see if that's possible here as well. Really nice that you got it up and running though.

AJenbo avatar Jun 28 '25 18:06 AJenbo

Regarding the descriptors I'm doing the same for 3ds but much less invasive so I would like to see if that's possible here as well.

Sounds great, feel free to open a PR on top of this one, or a new one. I'll leave this PR open for now.

foxtacles avatar Jun 28 '25 18:06 foxtacles

Things looks grate now when this is enabled, mostly it was just missing proper texture initialization which WebGL is very strict about, except for missing transitions. The issue is that glReadPixels() isn't able to read from the canvas in WebGL, using an FBO works fine, but when switching to FBO we start seeing rendering bugs specifically on WebGL (not OpenGL ES 2.0), I have no idea why they are happening it seems to be culling random things even outside of the renderer, my best guess is a race condition, I saw similar issues with DirectX9 and RTX Remix.

AJenbo avatar Jul 02 '25 01:07 AJenbo