Skip to content

Commit 7b51cc2

Browse files
committed
upgraded to latest versions
- ImGui / emscripten-glfw
1 parent 09e17f6 commit 7b51cc2

File tree

4 files changed

+81
-61
lines changed

4 files changed

+81
-61
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ set(PORTS_OPTIMIZATION_LEVEL "$<IF:$<CONFIG:Debug>,0,2>")
9393

9494
#set(wgpu_shader_toy_options "--use-port=contrib.glfw3" "--use-port=${CMAKE_SOURCE_DIR}/external/emscripten-ports/imgui.py:backend=glfw:renderer=wgpu:disableDemo=$<IF:$<CONFIG:Debug>,false,true>")
9595
set(wgpu_shader_toy_options
96-
"--use-port=${CMAKE_SOURCE_DIR}/external/emscripten-ports/emscripten-glfw3.py:optimizationLevel=${PORTS_OPTIMIZATION_LEVEL}"
97-
"--use-port=${CMAKE_SOURCE_DIR}/external/emscripten-ports/imgui.py:backend=glfw:renderer=wgpu:disableDemo=${IMGUI_DISABLE_DEMO}:optimizationLevel=${PORTS_OPTIMIZATION_LEVEL}")
96+
"--use-port=${CMAKE_SOURCE_DIR}/external/emscripten-ports/emscripten-glfw3.py:optimizationLevel=${PORTS_OPTIMIZATION_LEVEL}:disableWebGL2=true"
97+
"--use-port=${CMAKE_SOURCE_DIR}/external/emscripten-ports/imgui.py:backend=glfw:renderer=wgpu:disableDemo=${IMGUI_DISABLE_DEMO}:optimizationLevel=${PORTS_OPTIMIZATION_LEVEL}:disableDefaultFont=true")
9898

9999
target_compile_options(wgpu_shader_toy PUBLIC
100100
"${wgpu_shader_toy_options}"

external/emscripten-ports/emscripten-glfw3.py

Lines changed: 57 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
import os
1818
from typing import Union, Dict
1919

20-
TAG = '3.4.0.20240907'
21-
HASH = '48aba179ef50b5efd564535cd549528d06f74d18f7028a06212fccc425b784106b0efb3aa7bf72da6fb80c32a31b410f13a87d4599417cad8dc3af15664fa1b2'
20+
TAG = '3.4.0.20250209'
21+
HASH = '4acf0fdff680952cd6d6cbf0efaaa9b6347d21049e8c119a2cbd44b2b10d36dd94d3e3b3ef2e8f5c4afe93ff23f9aad5e917d08c52df7ca12d35843a926f1f0c'
2222
ZIP_URL = f'https://github.com/pongasoft/emscripten-glfw/releases/download/v{TAG}/emscripten-glfw3-{TAG}.zip'
2323

2424
# contrib port information (required)
@@ -27,75 +27,84 @@
2727
LICENSE = 'Apache 2.0 license'
2828

2929
VALID_OPTION_VALUES = {
30-
'disableWarning': ['true', 'false'],
31-
'disableJoystick': ['true', 'false'],
32-
'disableMultiWindow': ['true', 'false'],
33-
'optimizationLevel': ['0', '1', '2', '3', 'g', 's', 'z'] # all -OX possibilities
30+
'disableWarning': ['true', 'false'],
31+
'disableJoystick': ['true', 'false'],
32+
'disableMultiWindow': ['true', 'false'],
33+
'disableWebGL2': ['true', 'false'],
34+
'optimizationLevel': ['0', '1', '2', '3', 'g', 's', 'z'] # all -OX possibilities
3435
}
3536

3637
OPTIONS = {
37-
'disableWarning': 'Boolean to disable warnings emitted by the library',
38-
'disableJoystick': 'Boolean to disable support for joystick entirely',
39-
'disableMultiWindow': 'Boolean to disable multi window support which makes the code smaller and faster',
40-
'optimizationLevel': f'Optimization level: {VALID_OPTION_VALUES["optimizationLevel"]} (default to 2)',
38+
'disableWarning': 'Boolean to disable warnings emitted by the library',
39+
'disableJoystick': 'Boolean to disable support for joystick entirely',
40+
'disableMultiWindow': 'Boolean to disable multi window support',
41+
'disableWebGL2': 'Boolean to disable WebGL2 support',
42+
'optimizationLevel': f'Optimization level: {VALID_OPTION_VALUES["optimizationLevel"]} (default to 2)',
4143
}
4244

4345
# user options (from --use-port)
4446
opts: Dict[str, Union[str, bool]] = {
45-
'disableWarning': False,
46-
'disableJoystick': False,
47-
'disableMultiWindow': False,
48-
'optimizationLevel': '2'
47+
'disableWarning': False,
48+
'disableJoystick': False,
49+
'disableMultiWindow': False,
50+
'disableWebGL2': False,
51+
'optimizationLevel': '2'
4952
}
5053

5154
port_name = 'emscripten-glfw3'
5255

5356

5457
def get_lib_name(settings):
55-
return (f'lib_{port_name}_{TAG}-O{opts["optimizationLevel"]}' +
56-
('-nw' if opts['disableWarning'] else '') +
57-
('-nj' if opts['disableJoystick'] else '') +
58-
('-sw' if opts['disableMultiWindow'] else '') +
59-
'.a')
58+
return (f'lib_{port_name}_{TAG}-O{opts["optimizationLevel"]}' +
59+
('-nw' if opts['disableWarning'] else '') +
60+
('-nj' if opts['disableJoystick'] else '') +
61+
('-sw' if opts['disableMultiWindow'] else '') +
62+
('-mt' if settings.PTHREADS else '') +
63+
'.a')
6064

6165

6266
def get(ports, settings, shared):
63-
# get the port
64-
ports.fetch_project(port_name, ZIP_URL, sha512hash=HASH)
67+
# get the port
68+
ports.fetch_project(port_name, ZIP_URL, sha512hash=HASH)
6569

66-
def create(final):
67-
root_path = os.path.join(ports.get_dir(), port_name)
68-
source_path = os.path.join(root_path, 'src', 'cpp')
69-
source_include_paths = [os.path.join(root_path, 'external'), os.path.join(root_path, 'include')]
70+
def create(final):
71+
root_path = os.path.join(ports.get_dir(), port_name)
72+
source_path = os.path.join(root_path, 'src', 'cpp')
73+
source_include_paths = [os.path.join(root_path, 'external'), os.path.join(root_path, 'include')]
74+
75+
flags = [f'-O{opts["optimizationLevel"]}']
7076

71-
flags = [f'-O{opts["optimizationLevel"]}']
77+
if opts['disableWarning']:
78+
flags += ['-DEMSCRIPTEN_GLFW3_DISABLE_WARNING']
7279

73-
if opts['disableWarning']:
74-
flags += ['-DEMSCRIPTEN_GLFW3_DISABLE_WARNING']
80+
if opts['disableJoystick']:
81+
flags += ['-DEMSCRIPTEN_GLFW3_DISABLE_JOYSTICK']
7582

76-
if opts['disableJoystick']:
77-
flags += ['-DEMSCRIPTEN_GLFW3_DISABLE_JOYSTICK']
83+
if opts['disableMultiWindow']:
84+
flags += ['-DEMSCRIPTEN_GLFW3_DISABLE_MULTI_WINDOW_SUPPORT']
7885

79-
if opts['disableMultiWindow']:
80-
flags += ['-DEMSCRIPTEN_GLFW3_DISABLE_MULTI_WINDOW_SUPPORT']
86+
if settings.PTHREADS:
87+
flags += ['-pthread']
8188

82-
ports.build_port(source_path, final, port_name, includes=source_include_paths, flags=flags)
89+
ports.build_port(source_path, final, port_name, includes=source_include_paths, flags=flags)
8390

91+
lib = shared.cache.get_lib(get_lib_name(settings), create, what='port')
92+
if os.path.getmtime(lib) < os.path.getmtime(__file__):
93+
clear(ports, settings, shared)
8494
lib = shared.cache.get_lib(get_lib_name(settings), create, what='port')
85-
if os.path.getmtime(lib) < os.path.getmtime(__file__):
86-
clear(ports, settings, shared)
87-
lib = shared.cache.get_lib(get_lib_name(settings), create, what='port')
88-
return [lib]
95+
return [lib]
8996

9097

9198
def clear(ports, settings, shared):
92-
shared.cache.erase_lib(get_lib_name(settings))
99+
shared.cache.erase_lib(get_lib_name(settings))
93100

94101

95102
def linker_setup(ports, settings):
96-
root_path = os.path.join(ports.get_dir(), port_name)
97-
source_js_path = os.path.join(root_path, 'src', 'js', 'lib_emscripten_glfw3.js')
98-
settings.JS_LIBRARIES += [source_js_path]
103+
root_path = os.path.join(ports.get_dir(), port_name)
104+
source_js_path = os.path.join(root_path, 'src', 'js', 'lib_emscripten_glfw3.js')
105+
settings.JS_LIBRARIES += [source_js_path]
106+
if not opts['disableWebGL2']:
107+
settings.MAX_WEBGL_VERSION = 2
99108

100109

101110
# Makes GLFW includes accessible without installing them (ex: #include <GLFW/glfw3.h>)
@@ -110,13 +119,13 @@ def process_args(ports):
110119

111120

112121
def check_option(option, value, error_handler):
113-
if value not in VALID_OPTION_VALUES[option]:
114-
error_handler(f'[{option}] can be {list(VALID_OPTION_VALUES[option])}, got [{value}]')
115-
if isinstance(opts[option], bool):
116-
value = value == 'true'
117-
return value
122+
if value not in VALID_OPTION_VALUES[option]:
123+
error_handler(f'[{option}] can be {list(VALID_OPTION_VALUES[option])}, got [{value}]')
124+
if isinstance(opts[option], bool):
125+
value = value == 'true'
126+
return value
118127

119128

120129
def handle_options(options, error_handler):
121-
for option, value in options.items():
122-
opts[option] = check_option(option, value.lower(), error_handler)
130+
for option, value in options.items():
131+
opts[option] = check_option(option, value.lower(), error_handler)

external/emscripten-ports/imgui.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
# Copyright (c) 2024 pongasoft
22
#
3-
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4-
# use this file except in compliance with the License. You may obtain a copy of
5-
# the License at
3+
# Licensed under the MIT License. You may obtain a copy of the License at
64
#
7-
# http://www.apache.org/licenses/LICENSE-2.0
5+
# https://opensource.org/licenses/MIT
86
#
97
# Unless required by applicable law or agreed to in writing, software
108
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
@@ -17,15 +15,15 @@
1715
import os
1816
from typing import Union, Dict, Optional
1917

20-
TAG = '1.91.1'
18+
TAG = '1.91.8'
2119

2220
# Run this file as a script to see which command to run to generate the checksums
2321
DISTRIBUTIONS = {
2422
'master': {
25-
'hash': 'd810eb37336379b4ed106c7f02eb7a5b5f3603ec07426e23539787b0d3e6602db320aafb908a81041ef4c9bb1a810bb2d845b10fe6d0412a28d90daec7c582cb'
23+
'hash': '4f4a95d879b5bbd15bc33a4ac3fd8d32554b521b2c18d7cc71f9d27e19eae7c52559963f572d1693b62cc5eb2fd56f2d58fa0e75f818296cb7e04f7014f43ddd'
2624
},
2725
'docking': {
28-
'hash': '402ae1c33cbe13312052297a7d8aa657326dff8279460288e8991937c118f7028639cb9801101569472e56964c22e9e1a319ad1a21ecefbeffca8cac1a08488c'
26+
'hash': '27441ed64868993fc9d89296081ac6bea9233f66ac1b748ed82491ec7dea3f4160fd072db2b59d3d9876323be380ff9b0617d0a89c2db8ae8a96c91852f158ab'
2927
}
3028
}
3129

@@ -40,6 +38,7 @@
4038
'branch': DISTRIBUTIONS.keys(),
4139
'disableDemo': ['true', 'false'],
4240
'disableImGuiStdLib': ['true', 'false'],
41+
'disableDefaultFont': ['true', 'false'],
4342
'optimizationLevel': ['0', '1', '2', '3', 'g', 's', 'z'] # all -OX possibilities
4443
}
4544

@@ -52,9 +51,10 @@
5251
OPTIONS = {
5352
'renderer': f'Which renderer to use: {VALID_OPTION_VALUES["renderer"]} (required)',
5453
'backend': f'Which backend to use: {VALID_OPTION_VALUES["backend"]} (required)',
55-
'branch': 'Which branch to use: master (default) or docking',
54+
'branch': 'Which branch to use: master or docking (default to master)',
5655
'disableDemo': 'A boolean to disable ImGui demo (enabled by default)',
5756
'disableImGuiStdLib': 'A boolean to disable misc/cpp/imgui_stdlib.cpp (enabled by default)',
57+
'disableDefaultFont': 'A boolean to disable the default font (enabled by default)',
5858
'optimizationLevel': f'Optimization level: {VALID_OPTION_VALUES["optimizationLevel"]} (default to 2)',
5959
}
6060

@@ -65,6 +65,7 @@
6565
'branch': 'master',
6666
'disableDemo': False,
6767
'disableImGuiStdLib': False,
68+
'disableDefaultFont': False,
6869
'optimizationLevel': '2'
6970
}
7071

@@ -87,6 +88,7 @@ def get_lib_name(settings):
8788
return (f'lib_{port_name}_{get_tag()}-{opts["backend"]}-{opts["renderer"]}-O{opts["optimizationLevel"]}' +
8889
('-nd' if opts['disableDemo'] else '') +
8990
('-nl' if opts['disableImGuiStdLib'] else '') +
91+
('-nf' if opts['disableDefaultFont'] else '') +
9092
'.a')
9193

9294

@@ -116,6 +118,10 @@ def create(final):
116118

117119
flags = [f'--use-port={value}' for value in build_deps.values()]
118120
flags.append(f'-O{opts["optimizationLevel"]}')
121+
flags.append('-Wno-nontrivial-memaccess')
122+
123+
if opts['disableDefaultFont']:
124+
flags.append('-DIMGUI_DISABLE_DEFAULT_FONT')
119125

120126
ports.build_port(source_path, final, port_name, srcs=srcs, flags=flags)
121127

@@ -176,8 +182,11 @@ def handle_options(options, error_handler):
176182
if opts['backend'] == 'glfw':
177183
deps.append('emscripten-glfw3')
178184
patch_src_directory = os.path.join(os.path.dirname(os.path.abspath(__file__)))
179-
build_deps['emscripten-glfw3'] = \
180-
f"{os.path.join(patch_src_directory, 'emscripten-glfw3.py')}:optimizationLevel={opts['optimizationLevel']}"
185+
glfw3_options = {'optimizationLevel': opts['optimizationLevel']}
186+
if opts['renderer'] == 'wgpu':
187+
glfw3_options['disableWebGL2'] = 'true'
188+
glfw3_options = ':'.join(f"{key}={value}" for key, value in glfw3_options.items())
189+
build_deps['emscripten-glfw3'] = f"{os.path.join(patch_src_directory, 'emscripten-glfw3.py')}:{glfw3_options}"
181190
else:
182191
deps.append('sdl2')
183192
build_deps['sdl2'] = 'sdl2'

src/cpp/Application.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <GLFW/glfw3.h>
2020
#include "Application.h"
2121
#include "Errors.h"
22+
#include <emscripten/version.h>
2223

2324
namespace shader_toy {
2425

@@ -39,7 +40,8 @@ Application::Application()
3940
glfwSetErrorCallback(consoleErrorHandler);
4041

4142
// print the version on the console
42-
printf("%s\n", glfwGetVersionString());
43+
printf("GLFW: %s\n", glfwGetVersionString());
44+
printf("Emscripten: %d.%d.%d\n", __EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__);
4345

4446
// initialize the library
4547
WST_INTERNAL_ASSERT(glfwInit() == GLFW_TRUE);

0 commit comments

Comments
 (0)