-
Notifications
You must be signed in to change notification settings - Fork 0
Add WebGPU/WebAssembly build infrastructure and documentation #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
7
commits into
main
Choose a base branch
from
copilot/reimplement-webgpu-webasm-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a65c41b
Initial plan
Copilot 43425ed
Add WebGPU/WebASM build infrastructure and documentation
Copilot b71af00
Add environment check script, quickstart guide, and migration roadmap
Copilot 747f31d
Address code review feedback: fix emscripten.cmake, improve portabili…
Copilot 7e0882e
Improve code quality: add comments, fix escaping, clarify logic
Copilot 859da66
Add explicit permissions to GitHub Actions workflows for security
Copilot b98df92
Add comprehensive PR summary document
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| name: Build Native | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ main, develop ] | ||
| pull_request: | ||
| branches: [ main ] | ||
| workflow_dispatch: | ||
|
|
||
| # Limit permissions of GITHUB_TOKEN to minimum required | ||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| build-linux: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| # Specific permissions for this job | ||
| permissions: | ||
| contents: read | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| submodules: recursive | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y \ | ||
| libxinerama-dev \ | ||
| libglu1-mesa-dev \ | ||
| libxi-dev \ | ||
| libxrandr-dev \ | ||
| libxcursor-dev \ | ||
| ninja-build | ||
|
|
||
| - name: Configure CMake | ||
| run: cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release | ||
|
|
||
| - name: Build | ||
| run: cmake --build build --config Release | ||
|
|
||
| - name: Upload build artifacts | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: linux-build | ||
| path: build/app | ||
| retention-days: 7 | ||
|
|
||
| build-windows: | ||
| runs-on: windows-latest | ||
|
|
||
| # Specific permissions for this job | ||
| permissions: | ||
| contents: read | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| submodules: recursive | ||
|
|
||
| - name: Configure CMake | ||
| run: cmake -B build -DCMAKE_BUILD_TYPE=Release | ||
|
|
||
| - name: Build | ||
| run: cmake --build build --config Release | ||
|
|
||
| - name: Upload build artifacts | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: windows-build | ||
| path: build/Release/app.exe | ||
| retention-days: 7 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| name: Build WebAssembly | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ main, develop ] | ||
| pull_request: | ||
| branches: [ main ] | ||
| workflow_dispatch: | ||
|
|
||
| # Limit permissions of GITHUB_TOKEN to minimum required | ||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| build-wasm: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| # Specific permissions for this job | ||
| permissions: | ||
| contents: write # Needed for gh-pages deployment | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| submodules: recursive | ||
|
|
||
| - name: Setup Emscripten | ||
| uses: mymindstorm/setup-emsdk@v14 | ||
| with: | ||
| # Using 3.1.51 as a stable, tested version | ||
| # Update periodically to newer versions after testing | ||
| # To always use latest: change to 'latest' | ||
| version: '3.1.51' | ||
| actions-cache-folder: 'emsdk-cache' | ||
|
|
||
| - name: Verify Emscripten installation | ||
| run: | | ||
| emcc --version | ||
| em++ --version | ||
|
|
||
| - name: Create build directory | ||
| run: mkdir -p build-wasm | ||
|
|
||
| - name: Configure CMake for WebAssembly | ||
| run: | | ||
| cd build-wasm | ||
| emcmake cmake .. \ | ||
| -DCMAKE_BUILD_TYPE=Release \ | ||
| -DCMAKE_TOOLCHAIN_FILE=${EMSDK}/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake | ||
|
|
||
| - name: Build WebAssembly | ||
| run: | | ||
| cd build-wasm | ||
| emmake make -j$(nproc) | ||
|
|
||
| - name: Prepare artifacts | ||
| run: | | ||
| mkdir -p dist | ||
| cp build-wasm/app.* dist/ 2>/dev/null || true | ||
| cp -r resources dist/ 2>/dev/null || true | ||
|
|
||
| - name: Upload WebAssembly artifacts | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: webassembly-build | ||
| path: dist/ | ||
| retention-days: 30 | ||
|
|
||
| - name: Deploy to GitHub Pages (on main branch) | ||
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | ||
| uses: peaceiris/actions-gh-pages@v3 | ||
| with: | ||
| github_token: ${{ secrets.GITHUB_TOKEN }} | ||
| publish_dir: ./dist | ||
| publish_branch: gh-pages | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,192 @@ | ||
| # GL Playground - Project Overview | ||
|
|
||
| ## Project Description | ||
|
|
||
| GL Playground is an OpenGL-based 3D graphics application developed for Interactive Computer Graphics, Physics-Based Animation, and Computational Geometry courses. It serves as a learning platform and demonstration of various computer graphics techniques and physics simulations. | ||
|
|
||
| ## Current Architecture | ||
|
|
||
| ### Technology Stack | ||
| - **Graphics API**: OpenGL (native desktop) | ||
| - **Language**: C++20 | ||
| - **Build System**: CMake | ||
| - **Window Management**: GLFW 3.3.8 | ||
| - **Math Library**: Eigen | ||
| - **UI**: ImGui | ||
| - **Logging**: spdlog | ||
| - **Entity Component System**: EnTT | ||
|
|
||
| ### Key Features | ||
| 1. **Lighting System** | ||
| - Directional lights | ||
| - Spot lights | ||
| - Point lights | ||
| - Basic shadow-mapping support | ||
|
|
||
| 2. **Physics Simulation** | ||
| - Interactive rigid body physics | ||
| - Soft-body physics solver | ||
|
|
||
| 3. **Rendering** | ||
| - Multi-material objects | ||
| - Basic shading models | ||
| - Surface nets generated in compute shaders | ||
| - Wireframe rendering | ||
| - Shadow mapping | ||
|
|
||
| 4. **Model Support** | ||
| - OBJ file loading (using cyTriMesh) | ||
| - Multiple pre-loaded models (teapot, suzanne, cube, sphere, quad) | ||
|
|
||
| ## Project Structure | ||
|
|
||
| ``` | ||
| gl_playground/ | ||
| ├── src/ # Source files | ||
| │ ├── main.cpp # Entry point, initialization, main loop | ||
| │ ├── app.cpp # Main application class and render loop | ||
| │ ├── camera.cpp # Camera system | ||
| │ ├── gfx.cpp # Graphics utilities (texture generation) | ||
| │ ├── light.cpp # Light entity management | ||
| │ ├── mesh.cpp # Mesh rendering and geometry | ||
| │ ├── model.cpp # Model loading utilities | ||
| │ ├── physics.cpp # Physics simulation | ||
| │ ├── texture.cpp # Texture loading from PNG files | ||
| │ └── extmath.cpp # Extended math utilities | ||
| │ | ||
| ├── include/ # Header files (mirrors src/ structure) | ||
| │ ├── app.hpp | ||
| │ ├── camera.hpp | ||
| │ ├── gfx.hpp | ||
| │ ├── light.hpp | ||
| │ ├── mesh.hpp | ||
| │ ├── model.hpp | ||
| │ ├── physics.hpp | ||
| │ ├── texture.hpp | ||
| │ └── extmath.hpp | ||
| │ | ||
| ├── lib/ # Third-party libraries (included in repo) | ||
| │ ├── include/ | ||
| │ │ ├── glad/ # OpenGL loader | ||
| │ │ ├── KHR/ # Khronos headers | ||
| │ │ ├── cyCore.h # cyCodeBase core | ||
| │ │ ├── cyVector.h # cyCodeBase vectors | ||
| │ │ ├── cyTriMesh.h # cyCodeBase mesh utilities | ||
| │ │ ├── cyGL.h # cyCodeBase OpenGL utilities | ||
| │ │ └── gleq.h # GLFW event queue | ||
| │ └── src/ | ||
| │ └── glad.c # OpenGL loader implementation | ||
| │ | ||
| ├── cmake/ # CMake dependency configurations | ||
| │ ├── eigen.cmake.in # Eigen linear algebra library | ||
| │ ├── glfw.cmake.in # GLFW windowing library | ||
| │ ├── spdlog.cmake.in # Logging library | ||
| │ ├── imgui.cmake.in # ImGui UI library | ||
| │ ├── entt.cmake.in # Entity component system | ||
| │ ├── libspng.cmake.in # PNG image loading | ||
| │ └── cxxopts.cmake.in # Command-line option parsing | ||
| │ | ||
| ├── resources/ # Runtime assets | ||
| │ ├── models/ # 3D model files (.obj, .mtl) | ||
| │ │ ├── teapot.obj | ||
| │ │ ├── suzanne.obj | ||
| │ │ ├── cube.obj | ||
| │ │ ├── sphere.obj | ||
| │ │ └── quad.obj | ||
| │ └── shaders/ # GLSL shader files | ||
| │ ├── basic.vert # Basic vertex shader | ||
| │ ├── basic.frag # Basic fragment shader | ||
| │ ├── wireframe.* # Wireframe rendering shaders | ||
| │ ├── wires.* # Wire rendering shaders | ||
| │ ├── sky.* # Skybox shaders | ||
| │ └── shadow.frag # Shadow mapping shader | ||
| │ | ||
| ├── .vscode/ # VS Code configuration | ||
| │ ├── settings.json | ||
| │ ├── tasks.json | ||
| │ └── launch.json | ||
| │ | ||
| ├── CMakeLists.txt # Main CMake build configuration | ||
| ├── README.md # User documentation | ||
| ├── .gitignore # Git ignore rules | ||
| ├── download_assets.sh # Script to download external assets | ||
| ├── package_assets.sh # Script to package assets | ||
| └── upload_assets.sh # Script to upload assets | ||
| ``` | ||
|
|
||
| ## Build Process (Current) | ||
|
|
||
| ### Dependencies | ||
| The project uses CMake's FetchContent to automatically download and build: | ||
| - GLFW (window management) | ||
| - Eigen (linear algebra) | ||
| - spdlog (logging) | ||
| - ImGui (UI) | ||
| - EnTT (entity component system) | ||
| - libspng (PNG loading) | ||
| - cxxopts (CLI parsing) | ||
|
|
||
| ### Platform Support (Current) | ||
| - **Linux**: Primary development platform | ||
| - Requires: libxinerama-dev, libglu1-mesa-dev, libxi-dev, ninja-build | ||
| - **Windows**: CMake project support | ||
| - Recommended: Ninja build system | ||
|
|
||
| ### Build Commands | ||
| ```bash | ||
| cmake -B build | ||
| cmake --build build | ||
| ./build/app | ||
| ``` | ||
|
|
||
| ## WebGPU/WebASM Migration Plan | ||
|
|
||
| To make this project work on the web, the following changes are needed: | ||
|
|
||
| ### 1. Graphics API Migration | ||
| - Replace OpenGL calls with WebGPU API | ||
| - Port shaders from GLSL to WGSL (WebGPU Shading Language) | ||
| - Adapt rendering pipeline to WebGPU's explicit state management | ||
|
|
||
| ### 2. Build System | ||
| - Add Emscripten toolchain support | ||
| - Configure CMake for WebAssembly compilation | ||
| - Set up asset embedding for web deployment | ||
|
|
||
| ### 3. Platform Abstraction | ||
| - Abstract windowing (GLFW works with Emscripten but needs configuration) | ||
| - Handle input differences between native and web | ||
| - Manage resource loading (async for web) | ||
|
|
||
| ### 4. Dependencies | ||
| All major dependencies have WebAssembly support: | ||
| - GLFW: Has Emscripten backend | ||
| - Eigen: Header-only, works with Emscripten | ||
| - ImGui: Has WebGPU backend available | ||
| - EnTT: Header-only, works with Emscripten | ||
|
|
||
| ### 5. Deployment | ||
| - Generate HTML5 application | ||
| - Host assets appropriately | ||
| - Set up GitHub Pages or similar for hosting | ||
|
|
||
| ## Development Notes | ||
|
|
||
| ### Code Style | ||
| - C++20 features used throughout | ||
| - Smart pointers for resource management | ||
| - Entity-Component-System architecture via EnTT | ||
| - GLFW for cross-platform windowing | ||
|
|
||
| ### Key Classes | ||
| - `App`: Main application class, manages render loop and state | ||
| - `Camera`: Camera system with view/projection matrices | ||
| - `Mesh`: Geometry and rendering data | ||
| - `Model`: Model loading and management | ||
| - Various physics-related structures in physics.hpp | ||
|
|
||
| ### Logging | ||
| Uses spdlog with custom error handling that raises SIGINT on error messages. | ||
|
|
||
| ### Asset Management | ||
| External assets are hosted separately and downloaded via script (from cs.utah.edu/~benpm/assets.zip). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The wildcard copy
cp build-wasm/app.* dist/combined with error suppression (2>/dev/null || true) could silently fail if the expected build artifacts are missing or named differently than expected. This makes debugging build failures more difficult.Consider being more explicit about which files are required vs. optional:
This provides better visibility into what's actually being copied and what's optional.