From 302b189fe50eba1b8fd694998f66e73f1f9e06c6 Mon Sep 17 00:00:00 2001 From: Yan Pujante Date: Tue, 23 Jan 2024 11:05:12 -0800 Subject: [PATCH] Fixed emscripten_glfw3.h to work as a C file - added create-archive target --- CMakeLists.txt | 15 ++++++++++++++- README.md | 5 +++++ docs/Usage.md | 23 ++++++++++++++--------- include/GLFW/emscripten_glfw3.h | 7 ++++++- src/cpp/emscripten/glfw3/Context.cpp | 2 +- src/cpp/glfw3.cpp | 2 +- 6 files changed, 41 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 52b630c..40d3720 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,11 @@ cmake_minimum_required(VERSION 3.5) -project(emscripten_glfw LANGUAGES CXX) +set(emscripten-glfw_VERSION_MAJOR 1) +set(emscripten-glfw_VERSION_MINOR 0) +set(emscripten-glfw_VERSION_PATCH 3) +set(emscripten-glfw_VERSION "${emscripten-glfw_VERSION_MAJOR}.${emscripten-glfw_VERSION_MINOR}.${emscripten-glfw_VERSION_PATCH}") + +project(emscripten-glfw VERSION "${emscripten-glfw_VERSION}" LANGUAGES CXX) if(NOT EMSCRIPTEN) message(FATAL_ERROR "This library must be compiled with emscripten") @@ -58,6 +63,14 @@ target_compile_definitions(${target} PUBLIC target_link_options(${target} PUBLIC "-lGL" "--js-library" "${CMAKE_CURRENT_LIST_DIR}/src/js/lib_emscripten_glfw3.js") if(CMAKE_CURRENT_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) + set(ARCHIVE_DIR "${CMAKE_CURRENT_BINARY_DIR}/archive") + add_custom_target("create-archive" + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + COMMAND ${CMAKE_COMMAND} -E remove_directory ${ARCHIVE_DIR} + COMMAND ${CMAKE_COMMAND} -E make_directory ${ARCHIVE_DIR} + COMMAND ${CMAKE_COMMAND} -E tar "cfv" "${ARCHIVE_DIR}/emscripten-glfw3.v${emscripten-glfw_VERSION}.zip" "--format=zip" "external" "include" "src" + ) + add_subdirectory("test/demo" EXCLUDE_FROM_ALL) add_subdirectory("examples/example_asyncify" EXCLUDE_FROM_ALL) add_subdirectory("examples/example_hi_dpi" EXCLUDE_FROM_ALL) diff --git a/README.md b/README.md index ed1ebc0..2a56941 100644 --- a/README.md +++ b/README.md @@ -171,6 +171,11 @@ LDFLAGS += -s USE_WEBGPU=1 --js-library $(EMS_GLFW3_DIR)/src/js/lib_emscripten_g Release Notes ------------- +#### 1.0.3 - 2024/01/23 + +- Fixed `emscripten_glfw3.h` to work as a C file +- Added `create-archive` target + #### 1.0.2 - 2024/01/22 - Added `EMSCRIPTEN_GLFW3_DISABLE_JOYSTICK` as a CMake option diff --git a/docs/Usage.md b/docs/Usage.md index fa348be..621fba1 100644 --- a/docs/Usage.md +++ b/docs/Usage.md @@ -318,15 +318,20 @@ This implementation being in C++ and implementing far more features than the `li implementation, it has an impact on size. As of this writing, I ran the following experiment on both implementations using [`example_minimal`](../examples/example_minimal) -| Mode | `library_glfw.js` | This implementation | Delta | -|---------|----------------------------------------|------------------------------------------|-------| -| Debug | js: 170775, wasm: 75789, total: 246564 | js: 99559, wasm: 4492007, total: 4591566 | 18.8x | -| Release | js: 135433, wasm: 8448, total: 143881 | js: 81285, wasm: 80506, total: 161791 | 1.12x | - -From these numbers, and for obvious reasons, there is more wasm code than javascript code in this implementation (which -is a good thing). -Although the size is pretty terrible in `Debug` mode (almost a 19x size increase), in `Release` -mode it is actually only a 12% increase which shows that wasm optimizes quite well :) +| Mode | `library_glfw.js` | This implementation | Delta | +|-------------------|----------------------------------------|------------------------------------------|-------| +| Debug | js: 170775, wasm: 75789, total: 246564 | js: 99559, wasm: 4492007, total: 4591566 | 18.8x | +| Release | js: 135433, wasm: 8448, total: 143881 | js: 81285, wasm: 80506, total: 161791 | 1.12x | +| Release (minimal) | - | js: 79402, wasm: 71195, total: 150197 | 1.04x | + +* From these numbers, and for obvious reasons, there is more wasm code than javascript code in this implementation (which + is a good thing). +* Although the size is pretty terrible in `Debug` mode (almost a 19x size increase), in `Release` + mode it is actually only a 12% increase which shows that wasm optimizes quite well :) +* The last entry in the table shows the same results when compiling with all _disable_ options turned on + (`EMSCRIPTEN_GLFW3_DISABLE_JOYSTICK`, `EMSCRIPTEN_GLFW3_DISABLE_MULTI_WINDOW_SUPPORT` and + `EMSCRIPTEN_GLFW3_DISABLE_WARNING`) for an even smaller footprint +* Lastly, `.wasm` files compress extremely well, so it is worth serving them compressed ## Supported functions diff --git a/include/GLFW/emscripten_glfw3.h b/include/GLFW/emscripten_glfw3.h index 0d01295..54e12f1 100644 --- a/include/GLFW/emscripten_glfw3.h +++ b/include/GLFW/emscripten_glfw3.h @@ -22,7 +22,9 @@ #include #include +#ifdef __cplusplus extern "C" { +#endif /** * Before calling `glfwCreateWindow` you can communicate to the library which canvas to use by calling this function. @@ -130,7 +132,10 @@ EM_BOOL emscripten_glfw_is_window_fullscreen(GLFWwindow *window); * @param lockPointer whether to lock the pointer or not * @param resizeCanvas whether to resize the canvas to match the fullscreen size or not * @return `EMSCRIPTEN_RESULT_SUCCESS` if there was no issue, or an emscripten error code otherwise */ -int emscripten_glfw_request_fullscreen(GLFWwindow *window, bool lockPointer, bool resizeCanvas); +int emscripten_glfw_request_fullscreen(GLFWwindow *window, EM_BOOL lockPointer, EM_BOOL resizeCanvas); + +#ifdef __cplusplus } +#endif #endif //EMSCRIPTEN_GLFW_EMSCRIPTEN_GLFW3_H diff --git a/src/cpp/emscripten/glfw3/Context.cpp b/src/cpp/emscripten/glfw3/Context.cpp index 5de6e06..42661b4 100644 --- a/src/cpp/emscripten/glfw3/Context.cpp +++ b/src/cpp/emscripten/glfw3/Context.cpp @@ -30,7 +30,7 @@ extern "C" { using ScaleChangeCallback = void (*)(emscripten::glfw3::Context *); using WindowResizeCallback = void (*)(emscripten::glfw3::Context *, GLFWwindow *, int, int); -using RequestFullscreen = int (*)(GLFWwindow *, bool, bool); +using RequestFullscreen = int (*)(GLFWwindow *, EM_BOOL, EM_BOOL); using ErrorHandler = void (*)(int, char const *); void emscripten_glfw3_context_init(emscripten::glfw3::Context *iContext, float iScale, diff --git a/src/cpp/glfw3.cpp b/src/cpp/glfw3.cpp index 7367b7d..dda724d 100644 --- a/src/cpp/glfw3.cpp +++ b/src/cpp/glfw3.cpp @@ -727,7 +727,7 @@ int emscripten_glfw_is_window_fullscreen(GLFWwindow* window) //------------------------------------------------------------------------ // emscripten_glfw_request_fullscreen //------------------------------------------------------------------------ -int emscripten_glfw_request_fullscreen(GLFWwindow *window, bool lockPointer, bool resizeCanvas) +int emscripten_glfw_request_fullscreen(GLFWwindow *window, EM_BOOL lockPointer, EM_BOOL resizeCanvas) { auto context = getContext(); if(context)