From 59362f2494e836aae5e5fbd67f5b5ffdd30d5ee7 Mon Sep 17 00:00:00 2001 From: Bertil Chapuis Date: Tue, 12 Nov 2024 22:51:41 +0100 Subject: [PATCH 1/5] Add emscripten job --- .github/workflows/config.yml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/.github/workflows/config.yml b/.github/workflows/config.yml index 3e51e0a0..37c5c8a9 100644 --- a/.github/workflows/config.yml +++ b/.github/workflows/config.yml @@ -155,3 +155,38 @@ jobs: run: | cmake . -B build -DTHREEPP_BUILD_EXAMPLES=OFF -DTHREEPP_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE="Release" cmake --build build + + linux-emscripten: + runs-on: ${{ matrix.os }} + env: + CC: gcc-${{ matrix.compiler_version }} + CXX: g++-${{ matrix.compiler_version }} + strategy: + fail-fast: false + matrix: + os: [ ubuntu-22.04 ] + compiler_version: [ 11 ] + + steps: + - uses: actions/checkout@v3 + + - name: Install prerequisites + run: | + sudo apt-get update && sudo apt-get install -y \ + libxinerama-dev \ + libxcursor-dev \ + xorg-dev \ + libglu1-mesa-dev \ + pkg-config + + - uses: mymindstorm/setup-emsdk@v14 + + - name: Configure and build + run: | + cmake . -B build -DCMAKE_TOOLCHAIN_FILE=${{env.EM_CACHE_FOLDER}}/libexec/cmake/Modules/Platform/Emscripten.cmake -DTHREEPP_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE="Release" + cmake --build build + + - name: Test + run: | + cd build/tests + ctest --output-on-failure From d0639fcacf43b3a681ad35b25eb8edea8e7bc5c9 Mon Sep 17 00:00:00 2001 From: Bertil Chapuis Date: Wed, 13 Nov 2024 08:24:34 +0100 Subject: [PATCH 2/5] glGetTexImage method is not available in webgl --- src/threepp/renderers/GLRenderer.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/threepp/renderers/GLRenderer.cpp b/src/threepp/renderers/GLRenderer.cpp index c5b03bb7..cbb29287 100644 --- a/src/threepp/renderers/GLRenderer.cpp +++ b/src/threepp/renderers/GLRenderer.cpp @@ -1136,7 +1136,10 @@ struct GLRenderer::Impl { const auto newSize = image.width * image.height * (texture.format == Format::RGB || texture.format == Format::BGR ? 3 : 4); data.resize(newSize); + #ifndef __EMSCRIPTEN__ + // Only run this on desktop OpenGL, not in WebGL glGetTexImage(GL_TEXTURE_2D, 0, gl::toGLFormat(texture.format), gl::toGLType(texture.type), data.data()); + #endif state.unbindTexture(); } From 2900c2f0998c5331152101d654caf4aca21b94c8 Mon Sep 17 00:00:00 2001 From: Lars Ivar Hatledal Date: Wed, 13 Nov 2024 09:16:40 +0100 Subject: [PATCH 3/5] remove em test run --- .github/workflows/config.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/config.yml b/.github/workflows/config.yml index 37c5c8a9..a95e0b6f 100644 --- a/.github/workflows/config.yml +++ b/.github/workflows/config.yml @@ -185,8 +185,3 @@ jobs: run: | cmake . -B build -DCMAKE_TOOLCHAIN_FILE=${{env.EM_CACHE_FOLDER}}/libexec/cmake/Modules/Platform/Emscripten.cmake -DTHREEPP_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE="Release" cmake --build build - - - name: Test - run: | - cd build/tests - ctest --output-on-failure From d32cd85716866ef0ea1cd1dd4bf5653d2e42f2dd Mon Sep 17 00:00:00 2001 From: Lars Ivar Hatledal Date: Wed, 13 Nov 2024 09:19:31 +0100 Subject: [PATCH 4/5] use absolute path for em files --- examples/AddExample.cmake | 2 +- examples/CMakeLists.txt | 2 +- examples/controls/CMakeLists.txt | 2 +- examples/extras/core/CMakeLists.txt | 2 +- examples/geometries/CMakeLists.txt | 2 +- examples/loaders/CMakeLists.txt | 6 +++--- examples/objects/CMakeLists.txt | 6 +++--- examples/projects/Crane3R/CMakeLists.txt | 4 ++-- examples/textures/CMakeLists.txt | 10 +++++----- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/examples/AddExample.cmake b/examples/AddExample.cmake index c670366f..cde897f7 100644 --- a/examples/AddExample.cmake +++ b/examples/AddExample.cmake @@ -46,7 +46,7 @@ function(add_example) set(LINK_FLAGS " --bind -sUSE_GLFW=3 -sGL_DEBUG=1 -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2 -sFULL_ES3 -sASSERTIONS -sALLOW_MEMORY_GROWTH -sNO_DISABLE_EXCEPTION_CATCHING -sWASM=1") if (arg_WEB_EMBED) foreach (path ${arg_WEB_EMBED}) - set(LINK_FLAGS "${LINK_FLAGS} --embed-file ${path}") + set(LINK_FLAGS "${LINK_FLAGS} --embed-file \"${path}\"") endforeach () endif () diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index bdc38ce7..e71a6ca6 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -5,7 +5,7 @@ include(LibConfig.cmake) add_subdirectory(libs) add_example(NAME "demo" LINK_IMGUI WEB WEB_EMBED - "../data/fonts@data/fonts" + "${PROJECT_SOURCE_DIR}/data/fonts@data/fonts" ) add_subdirectory(animation) diff --git a/examples/controls/CMakeLists.txt b/examples/controls/CMakeLists.txt index 14a125b2..049d9b73 100644 --- a/examples/controls/CMakeLists.txt +++ b/examples/controls/CMakeLists.txt @@ -1,5 +1,5 @@ add_example(NAME "drag" WEB) add_example(NAME "fly" WEB WEB_EMBED - "../data/textures/planets@data/textures/planets" + "${PROJECT_SOURCE_DIR}/data/textures/planets@data/textures/planets" ) diff --git a/examples/extras/core/CMakeLists.txt b/examples/extras/core/CMakeLists.txt index f8c1d2e2..7a685e4e 100644 --- a/examples/extras/core/CMakeLists.txt +++ b/examples/extras/core/CMakeLists.txt @@ -1,4 +1,4 @@ add_example(NAME "fonts" LINK_IMGUI WEB WEB_EMBED - "../data/fonts@data/fonts" + "${PROJECT_SOURCE_DIR}/data/fonts@data/fonts" ) diff --git a/examples/geometries/CMakeLists.txt b/examples/geometries/CMakeLists.txt index 64035310..0b41bd4e 100644 --- a/examples/geometries/CMakeLists.txt +++ b/examples/geometries/CMakeLists.txt @@ -1,6 +1,6 @@ add_example(NAME "geometries" WEB WEB_EMBED - "../data/textures/uv_grid_opengl.jpg@/data/textures/uv_grid_opengl.jpg" + "${PROJECT_SOURCE_DIR}/data/textures/uv_grid_opengl.jpg@/data/textures/uv_grid_opengl.jpg" ) add_example(NAME "lathe_geometry" WEB) add_example(NAME "tube_geometry" WEB) diff --git a/examples/loaders/CMakeLists.txt b/examples/loaders/CMakeLists.txt index f7f59637..d36fde70 100644 --- a/examples/loaders/CMakeLists.txt +++ b/examples/loaders/CMakeLists.txt @@ -1,10 +1,10 @@ add_example(NAME "stl_loader" WEB WEB_EMBED - "../data/models/stl/pr2_head_pan.stl@data/models/stl/pr2_head_pan.stl" + "${PROJECT_SOURCE_DIR}/data/models/stl/pr2_head_pan.stl@data/models/stl/pr2_head_pan.stl" ) add_example(NAME "obj_loader" WEB WEB_EMBED - "../data/models/obj/female02@data/models/obj/female02" - "../data/textures/uv_grid_opengl.jpg@data/textures/uv_grid_opengl.jpg" + "${PROJECT_SOURCE_DIR}/data/models/obj/female02@data/models/obj/female02" + "${PROJECT_SOURCE_DIR}/data/textures/uv_grid_opengl.jpg@data/textures/uv_grid_opengl.jpg" ) add_example(NAME "assimp_loader" LINK_ASSIMP) add_example(NAME "urdf_loader" LINK_ASSIMP LINK_IMGUI) diff --git a/examples/objects/CMakeLists.txt b/examples/objects/CMakeLists.txt index 8c962065..728fc9aa 100644 --- a/examples/objects/CMakeLists.txt +++ b/examples/objects/CMakeLists.txt @@ -1,6 +1,6 @@ add_example(NAME "instancing" LINK_IMGUI WEB WEB_EMBED - "../data/fonts@data/fonts" + "${PROJECT_SOURCE_DIR}/data/fonts@data/fonts" ) if (TARGET "instancing") target_include_directories("instancing" PRIVATE "${PROJECT_SOURCE_DIR}/examples/libs") @@ -8,14 +8,14 @@ endif () add_example(NAME "sprite") add_example(NAME "lod" WEBWEB_EMBED - "../data/fonts@data/fonts" + "${PROJECT_SOURCE_DIR}/data/fonts@data/fonts" ) add_example(NAME "points" WEB) add_example(NAME "bones" LINK_IMGUI) add_example(NAME "decal" LINK_IMGUI LINK_ASSIMP) add_example(NAME "water" LINK_IMGUI WEB WEB_EMBED - "../data/textures/waternormals.jpg@data/textures/waternormals.jpg" + "${PROJECT_SOURCE_DIR}/data/textures/waternormals.jpg@data/textures/waternormals.jpg" ) add_example(NAME "particle_system" LINK_IMGUI) diff --git a/examples/projects/Crane3R/CMakeLists.txt b/examples/projects/Crane3R/CMakeLists.txt index 99fd0630..d870eb43 100644 --- a/examples/projects/Crane3R/CMakeLists.txt +++ b/examples/projects/Crane3R/CMakeLists.txt @@ -1,7 +1,7 @@ add_example(NAME "crane3R" SOURCES main.cpp Crane3R.cpp LINK_IMGUI WEB WEB_EMBED - "../data/fonts@data/fonts" - "../data/models/obj/Crane3R@data/models/obj/Crane3R" + "${PROJECT_SOURCE_DIR}/data/fonts@data/fonts" + "${PROJECT_SOURCE_DIR}/data/models/obj/Crane3R@data/models/obj/Crane3R" ) if (TARGET "crane3R") target_link_libraries("crane3R" PRIVATE kine) diff --git a/examples/textures/CMakeLists.txt b/examples/textures/CMakeLists.txt index d36fdca7..99c56d1b 100644 --- a/examples/textures/CMakeLists.txt +++ b/examples/textures/CMakeLists.txt @@ -2,12 +2,12 @@ add_example(NAME "cubemap") add_example(NAME "texture3d") add_example(NAME "texture2d" WEB WEB_EMBED - "../data/textures/crate.gif@data/textures/crate.gif" - "../data/textures/checker.png@data/textures/checker.png" - "../data/textures/brick_bump.jpg@data/textures/brick_bump.jpg" + "${PROJECT_SOURCE_DIR}/data/textures/crate.gif@data/textures/crate.gif" + "${PROJECT_SOURCE_DIR}/data/textures/checker.png@data/textures/checker.png" + "${PROJECT_SOURCE_DIR}/data/textures/brick_bump.jpg@data/textures/brick_bump.jpg" ) add_example(NAME "data_texture" WEB WEB_EMBED - "../data/textures/checker.png@data/textures/checker.png" - "../data/textures/crate.gif@data/textures/crate.gif" + "${PROJECT_SOURCE_DIR}/data/textures/checker.png@data/textures/checker.png" + "${PROJECT_SOURCE_DIR}/data/textures/crate.gif@data/textures/crate.gif" ) add_example(NAME "imgui_framebuffer" LINK_IMGUI WEB) From d4605573b50f927fe009086d471c59947e170cab Mon Sep 17 00:00:00 2001 From: Lars Ivar Hatledal Date: Wed, 13 Nov 2024 09:23:33 +0100 Subject: [PATCH 5/5] ignore copyTextureToImage logic on emscripten --- src/threepp/renderers/GLRenderer.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/threepp/renderers/GLRenderer.cpp b/src/threepp/renderers/GLRenderer.cpp index cbb29287..a9946871 100644 --- a/src/threepp/renderers/GLRenderer.cpp +++ b/src/threepp/renderers/GLRenderer.cpp @@ -1128,7 +1128,10 @@ struct GLRenderer::Impl { } void copyTextureToImage(Texture& texture) { - +#ifdef __EMSCRIPTEN__ + std::cerr << "[GLRenderer] copyTextureToImage not available with Emscripten" << std::endl; + return; +#endif textures.setTexture2D(texture, 0); auto& image = texture.image(); @@ -1136,10 +1139,10 @@ struct GLRenderer::Impl { const auto newSize = image.width * image.height * (texture.format == Format::RGB || texture.format == Format::BGR ? 3 : 4); data.resize(newSize); - #ifndef __EMSCRIPTEN__ + // Only run this on desktop OpenGL, not in WebGL glGetTexImage(GL_TEXTURE_2D, 0, gl::toGLFormat(texture.format), gl::toGLType(texture.type), data.data()); - #endif + state.unbindTexture(); }