Davidobot / love.js

LÖVE ported to the web using Emscripten, updated to the latest Emscripten and LÖVE (v11.5)
MIT License
605 stars 27 forks source link

Build for WebGL 2.0 #30

Open Davidobot opened 3 years ago

Davidobot commented 3 years ago

Should be as simple as adding -s MAX_WEBGL_VERSION=2

Davidobot commented 3 years ago

Not as trivial as I thought...

image

Had to edit OpenGL::rawTexStorage to contain

#if !defined(LOVE_EMSCRIPTEN)
  if (fmt.swizzled)
  {
    glTexParameteri(gltarget, GL_TEXTURE_SWIZZLE_R, fmt.swizzle[0]);
    glTexParameteri(gltarget, GL_TEXTURE_SWIZZLE_G, fmt.swizzle[1]);
    glTexParameteri(gltarget, GL_TEXTURE_SWIZZLE_B, fmt.swizzle[2]);
    glTexParameteri(gltarget, GL_TEXTURE_SWIZZLE_A, fmt.swizzle[3]);
  }
#endif

and include extra linker arguments:

"-s MAX_WEBGL_VERSION=2" # build for WebGL 2.0
"-s USE_WEBGL2=1"
"-s FULL_ES3=1" # needed for WebGL 2.0

Looks like WebGL2.0 doesn't support swizzling, hence the really bizarre colour scheme.

image

Seems to affect fonts primarily.

slime73 commented 1 year ago

You should just be able to add an extra check here so the RG8 codepath doesn't run on webgl: https://github.com/love2d/love/blob/c8e7d4e28a060d8e9f13b7fee549cf270995360a/src/modules/graphics/opengl/OpenGL.cpp#L1454