bunch of emscripten crap

This commit is contained in:
Andrei Alexeyev 2020-03-19 08:58:51 +02:00
parent 051f061b93
commit 5435971a08
No known key found for this signature in database
GPG key ID: 363707CD4C7FE8A4
7 changed files with 77 additions and 19 deletions

View file

@ -121,19 +121,17 @@ function SyncFS(is_load, ccptr) {
// https://github.com/emscripten-ports/SDL2/issues/57
function resumeAudio() {
if(
typeof Module === 'undefined' ||
typeof Module.SDL2 == 'undefined' ||
typeof Module.SDL2.audioContext == 'undefined'
) {
var sdl2 = Module['SDL2'];
if(typeof sdl2 === 'undefined') {
return;
}
if(Module.SDL2.audioContext.state == 'suspended') {
Module.SDL2.audioContext.resume();
if(sdl2.audioContext.state == 'suspended') {
sdl2.audioContext.resume();
}
if(Module.SDL2.audioContext.state == 'running') {
if(sdl2.audioContext.state == 'running') {
canvasElement.removeEventListener('click', resumeAudio);
document.removeEventListener('keydown', resumeAudio);
}

View file

@ -193,11 +193,12 @@ if host_machine.system() == 'emscripten'
taisei_c_args += ['-s', 'STRICT=1']
if em_debug
# em_link_output_suffixes += ['wasm.map']
em_link_output_suffixes += ['wasm.map']
em_link_args += [
'--emrun',
'--profiling',
'-g3',
'-g4',
'--source-map-base', meson.get_cross_property('source_map_base', 'http://0.0.0.0:6931/'),
'-s', 'ASSERTIONS=2',
'-s', 'GL_DEBUG=1',
'-s', 'GL_ASSERTIONS=1',
@ -210,13 +211,9 @@ if host_machine.system() == 'emscripten'
'-s', 'ASSERTIONS=0',
'-s', 'GL_TRACK_ERRORS=0',
]
endif
if get_option('optimization') != '0'
em_link_args += ['--closure', '1']
if em_debug
em_link_args += ['-g1']
if get_option('optimization') != '0'
em_link_args += ['--closure', '1']
endif
endif

View file

@ -283,7 +283,7 @@ static void gl33_init_context(SDL_Window *window) {
glPixelStorei(GL_PACK_ALIGNMENT, 1);
GLVT.get_viewport(&R.viewport.default_framebuffer);
if(glReadBuffer != NULL) {
if(HAVE_GL_FUNC(glReadBuffer)) {
glReadBuffer(GL_BACK);
}
@ -1080,7 +1080,9 @@ static void gl33_swap(SDL_Window *window) {
Framebuffer *prev_fb = r_framebuffer_current();
r_framebuffer(NULL);
gl33_sync_framebuffer();
#ifndef __EMSCRIPTEN__
SDL_GL_SwapWindow(window);
#endif
r_framebuffer(prev_fb);
gl33_stats_post_frame();

View file

@ -111,7 +111,7 @@ static void gl33_vertex_array_update_layout(VertexArray *varr) {
default: UNREACHABLE;
}
if(glVertexAttribDivisor != NULL) {
if(HAVE_GL_FUNC(glVertexAttribDivisor)) {
glVertexAttribDivisor(i, a->spec.divisor);
} else if(a->spec.divisor != 0) {
log_fatal("Renderer backend does not support instance attributes");

View file

@ -94,6 +94,9 @@ static ext_flag_t glcommon_ext_flag(const char *ext) {
}
ext_flag_t glcommon_check_extension(const char *ext) {
assert(*ext != 0);
assert(strchr(ext, ' ') == NULL);
const char *overrides = env_get("TAISEI_GL_EXT_OVERRIDES", "");
ext_flag_t flag = glcommon_ext_flag(ext);
@ -118,7 +121,57 @@ ext_flag_t glcommon_check_extension(const char *ext) {
}
}
return SDL_GL_ExtensionSupported(ext) ? flag : 0;
// SDL_GL_ExtensionSupported is stupid and requires dlopen() with emscripten.
// Let's reinvent it!
// SDL does this
if(env_get_int(ext, 1) == 0) {
return 0;
}
#ifndef STATIC_GLES3
if(GL_ATLEAST(3, 0) || GLES_ATLEAST(3, 0))
#endif
{
GLint num_exts = 0;
glGetIntegerv(GL_NUM_EXTENSIONS, &num_exts);
for(GLint i = 0; i < num_exts; ++i) {
const char *e = (const char*)glGetStringi(GL_EXTENSIONS, i);
if(!strcmp(ext, e)) {
return flag;
}
}
return 0;
}
#ifndef STATIC_GLES3
// The legacy way
const char *extensions = (const char*)glGetString(GL_EXTENSIONS);
if(!extensions) {
return 0;
}
const char *start = extensions;
size_t ext_len = strlen(ext);
for(;;) {
const char *where = strstr(start, ext);
if(!where) {
return 0;
}
const char *term = where + ext_len;
if(
(where == extensions || where[-1] == ' ') &&
(*term == ' ' || *term == ' ')
) {
return flag;
}
}
#endif
}
ext_flag_t glcommon_require_extension(const char *ext) {
@ -915,6 +968,7 @@ void glcommon_unload_library(void) {
glcommon_free_shader_lang_table();
}
attr_unused
static inline void (*load_func(const char *name))(void) {
union {
void *vp;

View file

@ -259,4 +259,10 @@ struct glext_s {
#undef GLES_ATLEAST
#define GLES_ATLEAST(mjr, mnr) (glext.version.is_es && GLANY_ATLEAST(mjr, mnr))
#ifdef STATIC_GLESS
#define HAVE_GL_FUNC(func) (&(func) != NULL)
#else
#define HAVE_GL_FUNC(func) ((func) != NULL)
#endif
#endif // IGUARD_renderer_glcommon_opengl_h

View file

@ -209,6 +209,7 @@ GLTexFormatCapabilities gles_texture_format_caps(GLenum internal_fmt) {
caps |= GLTEX_COLOR_RENDERABLE;
}
// fallthrough
case GL_RGB16F:
if(glext.texture_half_float_linear) {
caps |= GLTEX_FILTERABLE;