floooh / sokol

minimal cross-platform standalone C headers
https://floooh.github.io/sokol-html5
zlib License
6.93k stars 487 forks source link

ifdef out GL_FRAMEBUFFER_UNDEFINED from webgl builds #933

Closed danielchasehooper closed 7 months ago

danielchasehooper commented 11 months ago

GL_FRAMEBUFFER_UNDEFINED doesn't exist in webgl2, ifdef it out.

danielchasehooper commented 11 months ago

Not sure if #if !defined(SOKOL_GLES3) would be better? Not that it matters right now, but maybe that would be more robust to future gl versions?

floooh commented 11 months ago

Strange, sokol_gfx.h includes GLES3/gl3.h on Emscripten:

https://github.com/floooh/sokol/blob/bd7fa9300dc2e2edca087cf436d1c5c07bd754fc/sokol_gfx.h#L4217-L4221

...and this includes the definition:

https://github.com/emscripten-core/emscripten/blob/4de99429ecb854e346b32edc04cfa261c37b05d9/system/include/GLES3/gl3.h#L830

The Emscripten builds are also working fine in CI (and of course locally on my machine):

https://github.com/floooh/sokol-samples/actions/runs/6697850493

https://github.com/floooh/sokol/actions/runs/6697703312

No idea how it could fail tbh...

PS: ignore the confusion with the various edits of this comment, I was confusing OpenGL's GL_FRAMEBUFFER_UNDEFINED, with sokol_gfx.h's GL_FRAMEBUFFER_STATUS_UNDEFINED.

But still, GL_FRAMEBUFFER_UNDEFINED is defined in GLES3/gl3.h, ...so I still don't have any idea what could go wrong :)

What's you Emscripten SDK version?

floooh commented 11 months ago

Ah, now I see, the WebGL2 spec removed it (see: https://registry.khronos.org/webgl/specs/latest/2.0/)

5.8 Default Framebuffer
WebGL always has a default framebuffer. The FRAMEBUFFER_UNDEFINED enumerant is removed from the WebGL 2.0 API.

Since Emscripten uses the GLES3/gl3.h header it compiles though even if WebGL2 doesn't have that error value. Are you using different headers than what Emscripten provides?

(apart from that, the best define to check for would probably be __EMSCRIPTEN__, since it's purely a WebGL2 thing, but only if there are headers flying around for WebGL2 C shims which differ from the GLES3 headers)

danielchasehooper commented 11 months ago

Ah, yeah we're not using emscripten. we use clang's wasm target directly and wrote our own webgl headers and javascript glue. I guess we'll go the route of matching GLES3 headers. Thanks for the comments!

floooh commented 7 months ago

FYI I have solved this a bit differently (will be part of https://github.com/floooh/sokol/pull/985):

#if defined(SOKOL_GLES3)
    // on WebGL2, GL_FRAMEBUFFER_UNDEFINED technically doesn't exist (it is defined
    // in the Emscripten headers, but may not exist in other WebGL2 shims)
    // see: https://github.com/floooh/sokol/pull/933
    #ifndef GL_FRAMEBUFFER_UNDEFINED
    #define GL_FRAMEBUFFER_UNDEFINED 0x8219
    #endif
#endi

(the WebGL2 APIs will never return GL_FRAMEBUFFER_UNDEFINED, so the define just exists to make the code compile, even if that specific error code will never be returned)