Skip to content

Commit

Permalink
Fixed emscripten_glfw3.h to work as a C file
Browse files Browse the repository at this point in the history
- added create-archive target
  • Loading branch information
ypujante committed Jan 23, 2024
1 parent c9af1ba commit 302b189
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 13 deletions.
15 changes: 14 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 14 additions & 9 deletions docs/Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion include/GLFW/emscripten_glfw3.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
#include <GLFW/glfw3.h>
#include <emscripten/em_types.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
* Before calling `glfwCreateWindow` you can communicate to the library which canvas to use by calling this function.
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/cpp/emscripten/glfw3/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/glfw3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 302b189

Please sign in to comment.