Skip to content

Commit f4f7851

Browse files
committed
Fix web responsive issues
1 parent 874b18d commit f4f7851

File tree

5 files changed

+29
-13
lines changed

5 files changed

+29
-13
lines changed

.justfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ alias f := format
1515
default:
1616
@just --list
1717

18+
# Get the number of cores
19+
CORES := if os() == "macos" { `sysctl -n hw.ncpu` } else if os() == "linux" { `nproc` } else { "1" }
20+
1821
# Run a package
1922
run *package='bunny':
2023
@./target/release/{{package}}
@@ -25,7 +28,7 @@ build *build_type='Release':
2528
@echo "Configuring the build system..."
2629
@cd build && cmake -S .. -B . -DCMAKE_BUILD_TYPE={{build_type}}
2730
@echo "Building the project..."
28-
@cd build && cmake --build . -j$(nproc)
31+
@cd build && cmake --build . -j{{CORES}}
2932

3033
# Build the project for the web
3134
web *build_type='Release':
@@ -34,7 +37,7 @@ web *build_type='Release':
3437
@echo "Configuring the build system..."
3538
@cd build && emcmake cmake -S .. -B . -DCMAKE_BUILD_TYPE={{build_type}}
3639
@echo "Building the project..."
37-
@cd build && cmake --build . -j$(nproc)
40+
@cd build && cmake --build . -j{{CORES}}
3841
@mkdir -p public/assets/
3942
@# Find and copy WASM, JS and data files to the public directory
4043
@find target/release/web -name "*.wasm" -exec cp {} ./public/ \;

CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ else()
8585
GIT_PROGRESS TRUE
8686
GIT_SHALLOW TRUE)
8787
FetchContent_MakeAvailable(metal-cpp)
88+
89+
# Add metal-cpp include directories
90+
target_include_directories(${PROJECT_NAME} INTERFACE ${metal-cpp_SOURCE_DIR})
91+
8892
target_link_libraries(
8993
${PROJECT_NAME} INTERFACE "-framework Metal" "-framework Foundation"
9094
"-framework QuartzCore" "-framework MetalKit")
@@ -140,7 +144,11 @@ else()
140144
INTERFACE ${SDL3_SOURCE_DIR}/include)
141145

142146
# Link SDL3 libraries
143-
target_link_libraries(${PROJECT_NAME} INTERFACE SDL3::SDL3)
147+
if(EMSCRIPTEN)
148+
target_link_libraries(${PROJECT_NAME} INTERFACE SDL3::SDL3-static)
149+
else()
150+
target_link_libraries(${PROJECT_NAME} INTERFACE SDL3::SDL3)
151+
endif()
144152
endif()
145153

146154
# Examples

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ To get a local copy of the project up and running on your machine, follow these
7474
2. Install the project dependencies
7575

7676
```sh
77-
nix-shell
77+
nix-shell --max-jobs $(nproc) # Linux / Windows (WSL)
78+
nix-shell --max-jobs $(sysctl -n hw.ncpu) # macOS
7879
```
7980

8081
3. Build the project

include/kiwigl/graphics/display.hpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
#ifdef __CUDA__
2323
#include "display.cuh"
2424
#elif __METAL__
25-
#include "display.mm"
25+
#define NS_PRIVATE_IMPLEMENTATION
26+
#define MTL_PRIVATE_IMPLEMENTATION
27+
#include "Metal/Metal.hpp"
28+
2629
#endif
2730

2831
namespace kiwigl {
@@ -107,7 +110,7 @@ class Display {
107110
Triangle* d_projectedTriangles = nullptr;
108111
InitalizeCuda();
109112
#elif __METAL__
110-
InitalizeMetal();
113+
// InitalizeMetal();
111114
#endif
112115

113116
#ifndef BENCHMARK_MODE
@@ -200,7 +203,7 @@ class Display {
200203
#ifdef __CUDA__
201204
LaunchCuda(frameBuffer->getWidth(), frameBuffer->getHeight());
202205
#elif __METAL__
203-
LaunchMetal();
206+
// LaunchMetal();
204207
#else
205208
for (int i = 0; i < mesh.faces.size(); i++) {
206209
// Transform the vertices of the face
@@ -300,14 +303,14 @@ class Display {
300303
// Method to launch CUDA
301304
virtual void LaunchCuda(int width, int height);
302305
#elif __METAL__
303-
// Method to initialize Metal
304-
virtual void InitalizeMetal();
306+
// // Method to initialize Metal
307+
// virtual void InitalizeMetal();
305308

306-
// Method to free Metal
307-
virtual void FreeMetal();
309+
// // Method to free Metal
310+
// virtual void FreeMetal();
308311

309-
// Method to launch Metal
310-
virtual void LaunchMetal();
312+
// // Method to launch Metal
313+
// virtual void LaunchMetal();
311314
#endif
312315

313316
// Method to load a mesh

public/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<head>
44
<meta charset="utf-8">
55
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
67
<style>
78
html, body {
89
margin: 0%;

0 commit comments

Comments
 (0)