diff --git a/.github/workflows/config.yml b/.github/workflows/config.yml index 3e51e0a0..a95e0b6f 100644 --- a/.github/workflows/config.yml +++ b/.github/workflows/config.yml @@ -155,3 +155,33 @@ 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 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) diff --git a/src/threepp/renderers/GLRenderer.cpp b/src/threepp/renderers/GLRenderer.cpp index c5b03bb7..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,8 +1139,11 @@ struct GLRenderer::Impl { const auto newSize = image.width * image.height * (texture.format == Format::RGB || texture.format == Format::BGR ? 3 : 4); data.resize(newSize); + + // Only run this on desktop OpenGL, not in WebGL glGetTexImage(GL_TEXTURE_2D, 0, gl::toGLFormat(texture.format), gl::toGLType(texture.type), data.data()); + state.unbindTexture(); }