Compare commits

...

5 commits

7 changed files with 74 additions and 1 deletions

3
.gitmodules vendored
View file

@ -4,3 +4,6 @@
[submodule "3rdparty/libbacktrace"]
path = 3rdparty/libbacktrace
url = https://github.com/ianlancetaylor/libbacktrace.git
[submodule "3rdparty/boost"]
path = 3rdparty/boost
url = https://github.com/boostorg/boost

1
3rdparty/boost vendored Submodule

@ -0,0 +1 @@
Subproject commit 5dfae19bf919476ce2ff28e2a9b5e03561e9c0ef

View file

@ -803,10 +803,12 @@ namespace gl
if (!internal::glGetQueryiv) return false;
internal::glGetQueryObjectuiv = reinterpret_cast<void (*)(GLuint , GLenum , GLuint *)>(internal::get_proc_address("glGetQueryObjectuiv"));
if (!internal::glGetQueryObjectuiv) return false;
#if !defined(__EMSCRIPTEN__)
internal::glUnmapBuffer = reinterpret_cast<GLboolean (*)(GLenum )>(internal::get_proc_address("glUnmapBuffer"));
if (!internal::glUnmapBuffer) return false;
internal::glGetBufferPointerv = reinterpret_cast<void (*)(GLenum , GLenum , void **)>(internal::get_proc_address("glGetBufferPointerv"));
if (!internal::glGetBufferPointerv) return false;
#endif
internal::glDrawBuffers = reinterpret_cast<void (*)(GLsizei , const GLenum *)>(internal::get_proc_address("glDrawBuffers"));
if (!internal::glDrawBuffers) return false;
internal::glUniformMatrix2x3fv = reinterpret_cast<void (*)(GLint , GLsizei , GLboolean , const GLfloat *)>(internal::get_proc_address("glUniformMatrix2x3fv"));
@ -827,10 +829,12 @@ namespace gl
if (!internal::glRenderbufferStorageMultisample) return false;
internal::glFramebufferTextureLayer = reinterpret_cast<void (*)(GLenum , GLenum , GLuint , GLint , GLint )>(internal::get_proc_address("glFramebufferTextureLayer"));
if (!internal::glFramebufferTextureLayer) return false;
#if !defined(__EMSCRIPTEN__)
internal::glMapBufferRange = reinterpret_cast<void *(*)(GLenum , GLintptr , GLsizeiptr , GLbitfield )>(internal::get_proc_address("glMapBufferRange"));
if (!internal::glMapBufferRange) return false;
internal::glFlushMappedBufferRange = reinterpret_cast<void (*)(GLenum , GLintptr , GLsizeiptr )>(internal::get_proc_address("glFlushMappedBufferRange"));
if (!internal::glFlushMappedBufferRange) return false;
#endif
internal::glBindVertexArray = reinterpret_cast<void (*)(GLuint )>(internal::get_proc_address("glBindVertexArray"));
if (!internal::glBindVertexArray) return false;
internal::glDeleteVertexArrays = reinterpret_cast<void (*)(GLsizei , const GLuint *)>(internal::get_proc_address("glDeleteVertexArrays"));
@ -984,6 +988,10 @@ namespace gl
internal::glGetInternalformativ = reinterpret_cast<void (*)(GLenum , GLenum , GLenum , GLsizei , GLint *)>(internal::get_proc_address("glGetInternalformativ"));
if (!internal::glGetInternalformativ) return false;
#if defined(__EMSCRIPTEN__)
return true;
#endif
// OpenGL ES 3.1
internal::glDispatchCompute = reinterpret_cast<void (*)(GLuint , GLuint , GLuint )>(internal::get_proc_address("glDispatchCompute"));
@ -1259,7 +1267,13 @@ namespace gl
int major_version(){ return 3; }
int minor_version(){ return 2; }
int minor_version(){
#if defined(__EMSCRIPTEN__)
return 0;
#else
return 2;
#endif
}
bool has_extension(const char * name){ return extensions.contains(name); }
@ -1269,6 +1283,16 @@ namespace gl
const char * shader_prefix()
{
#if defined(__EMSCRIPTEN__)
return R"(#version 300 es
precision highp int;
precision highp float;
precision highp sampler2D;
precision highp usampler2D;
)";
#else
return R"(#version 320 es
precision highp int;
@ -1277,6 +1301,7 @@ precision highp sampler2D;
precision highp usampler2D;
)";
#endif
}
} // namespace sys

View file

@ -11,6 +11,18 @@
#include <psemek/util/exception.hpp>
#include <psemek/util/terminal_color.hpp>
#ifdef __EMSCRIPTEN__
#include <emscripten/emscripten.h>
#include <emscripten/html5.h>
#include <emscripten.h>
struct em_state
{
std::unique_ptr<psemek::app::application> application;
std::unique_ptr<psemek::sdl2::window> window;
} em_state;
#endif
#undef main
int main(int argc, char ** argv) try
@ -40,7 +52,12 @@ int main(int argc, char ** argv) try
auto const factory = app::make_application_factory();
auto const options = factory->options();
#ifdef __EMSCRIPTEN__
em_state.window = std::make_unique<sdl2::window>(options);
auto & window = *em_state.window;
#else
sdl2::window window(options);
#endif
app::application::context context;
for (int i = 0; i < argc; ++i)
@ -61,7 +78,13 @@ int main(int argc, char ** argv) try
context.device = window.wgpu_device();
#endif
#ifdef __EMSCRIPTEN__
em_state.application = factory->create(options, context);
auto application = em_state.application.get();
#else
auto application = factory->create(options, context);
#endif
if (!application)
return EXIT_FAILURE;
@ -75,6 +98,21 @@ int main(int argc, char ** argv) try
SDL_StopTextInput();
#ifdef __EMSCRIPTEN__
emscripten_request_animation_frame_loop([](double, void*) -> EM_BOOL {
if (sdl2::poll_events(*em_state.application))
em_state.application->stop();
if (!em_state.application->running())
return EM_FALSE;
em_state.application->update();
em_state.application->present();
em_state.window->swap();
return EM_TRUE;
}, nullptr);
#else
while (application->running())
{
if (sdl2::poll_events(*application))
@ -84,6 +122,7 @@ int main(int argc, char ** argv) try
application->present();
window.swap();
}
#endif
log::info() << "Quitting";
return EXIT_SUCCESS;

View file

@ -27,6 +27,7 @@ namespace psemek::sdl2
if (options.highdpi) flags |= SDL_WINDOW_ALLOW_HIGHDPI;
#if defined(PSEMEK_GRAPHICS_API_OPENGL)
#if !defined(__EMSCRIPTEN__)
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, gl::sys::major_version());
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, gl::sys::minor_version());
@ -46,6 +47,7 @@ namespace psemek::sdl2
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, options.multisampling);
}
#endif
flags |= SDL_WINDOW_OPENGL;
#endif

View file

@ -39,6 +39,8 @@ namespace psemek::util
std::string path(path_length, '\0');
_NSGetExecutablePath(path.data(), &path_length);
return std::filesystem::path(std::move(path));
#elif defined __EMSCRIPTEN__
return std::filesystem::canonical("");
#else
throw exception("executable_path() is not implemented for this platform");
#endif

View file

@ -24,6 +24,7 @@ if(PSEMEK_PACKAGE_MODE)
if(CMAKE_SYSTEM_NAME STREQUAL Emscripten)
list(APPEND PSEMEK_PACKAGE_LINK_FLAGS_RAW "-sMIN_WEBGL_VERSION=2" "-sNO_DISABLE_EXCEPTION_CATCHING")
list(APPEND PSEMEK_PACKAGE_LINK_FLAGS_RAW "-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE='$autoResumeAudioContext','$dynCall'")
if(CMAKE_BUILD_TYPE STREQUAL Debug)
list(APPEND PSEMEK_PACKAGE_LINK_FLAGS_RAW "-g")
endif()