Mercurial > hg > orthanc-stone
changeset 2048:a05b03f45289 deep-learning
added ORTHANC_WEBGL2_HEAP_COMPAT
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 08 Mar 2023 17:46:04 +0100 |
parents | 0b596428e60c |
children | 85ab86f10d01 |
files | Applications/Samples/WebAssembly/CMakeLists.txt Applications/StoneWebViewer/WebAssembly/CMakeLists.txt Applications/StoneWebViewer/WebAssembly/StoneModule/CMakeLists.txt OrthancStone/Resources/WebAssemblySharedLibrary/CMakeLists.txt OrthancStone/Resources/WebAssemblyUnitTests/CMakeLists.txt OrthancStone/Sources/OpenGL/OpenGLTexture.cpp |
diffstat | 6 files changed, 46 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/Applications/Samples/WebAssembly/CMakeLists.txt Mon Mar 06 11:00:55 2023 +0100 +++ b/Applications/Samples/WebAssembly/CMakeLists.txt Wed Mar 08 17:46:04 2023 +0100 @@ -45,12 +45,14 @@ set(WASM_FLAGS "${WASM_FLAGS} -s SAFE_HEAP=1") endif() +set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s ENVIRONMENT=web") set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s EXTRA_EXPORTED_RUNTIME_METHODS='[\"ccall\", \"cwrap\"]'") set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s ERROR_ON_UNDEFINED_SYMBOLS=1") set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s ALLOW_MEMORY_GROWTH=1 -s TOTAL_MEMORY=268435456") # 256MB + resize set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1") add_definitions( -DDISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1 + -DORTHANC_WEBGL2_HEAP_COMPAT=0 )
--- a/Applications/StoneWebViewer/WebAssembly/CMakeLists.txt Mon Mar 06 11:00:55 2023 +0100 +++ b/Applications/StoneWebViewer/WebAssembly/CMakeLists.txt Wed Mar 08 17:46:04 2023 +0100 @@ -36,14 +36,17 @@ set(WASM_FLAGS "${WASM_FLAGS} -s WASM=1 -s FETCH=1 -s ASSERTIONS=1 -s DISABLE_EXCEPTION_CATCHING=0") if (CMAKE_BUILD_TYPE STREQUAL "Debug") set(WASM_FLAGS "${WASM_FLAGS} -s SAFE_HEAP=1") + set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s GL_DEBUG=1 -s GL_ASSERTIONS=1 -s TRACE_WEBGL_CALLS=1") endif() +set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s ENVIRONMENT=web") set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s EXTRA_EXPORTED_RUNTIME_METHODS='[\"ccall\", \"cwrap\"]'") set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s ERROR_ON_UNDEFINED_SYMBOLS=1") set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s ALLOW_MEMORY_GROWTH=1 -s TOTAL_MEMORY=268435456") # 256MB + resize set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1") add_definitions( -DDISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1 + -DORTHANC_WEBGL2_HEAP_COMPAT=0 )
--- a/Applications/StoneWebViewer/WebAssembly/StoneModule/CMakeLists.txt Mon Mar 06 11:00:55 2023 +0100 +++ b/Applications/StoneWebViewer/WebAssembly/StoneModule/CMakeLists.txt Wed Mar 08 17:46:04 2023 +0100 @@ -46,6 +46,7 @@ set(WASM_FLAGS "${WASM_FLAGS} -s SAFE_HEAP=1") endif() +set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s ENVIRONMENT=web") set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s EXTRA_EXPORTED_RUNTIME_METHODS='[\"ccall\", \"cwrap\"]'") set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s ERROR_ON_UNDEFINED_SYMBOLS=1") set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s ASSERTIONS=1 -s DISABLE_EXCEPTION_CATCHING=0") @@ -53,6 +54,7 @@ set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1") add_definitions( -DDISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1 + -DORTHANC_WEBGL2_HEAP_COMPAT=0 )
--- a/OrthancStone/Resources/WebAssemblySharedLibrary/CMakeLists.txt Mon Mar 06 11:00:55 2023 +0100 +++ b/OrthancStone/Resources/WebAssemblySharedLibrary/CMakeLists.txt Wed Mar 08 17:46:04 2023 +0100 @@ -54,6 +54,7 @@ set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1") add_definitions( -DDISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1 + -DORTHANC_WEBGL2_HEAP_COMPAT=0 )
--- a/OrthancStone/Resources/WebAssemblyUnitTests/CMakeLists.txt Mon Mar 06 11:00:55 2023 +0100 +++ b/OrthancStone/Resources/WebAssemblyUnitTests/CMakeLists.txt Wed Mar 08 17:46:04 2023 +0100 @@ -39,6 +39,7 @@ set(WASM_FLAGS "${WASM_FLAGS} -s SAFE_HEAP=1") endif() +set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s ENVIRONMENT=web") set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s EXTRA_EXPORTED_RUNTIME_METHODS='[\"ccall\", \"cwrap\"]'") set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s ERROR_ON_UNDEFINED_SYMBOLS=1") set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s ALLOW_MEMORY_GROWTH=1 -s TOTAL_MEMORY=268435456") # 256MB + resize @@ -46,6 +47,7 @@ add_definitions( -DDISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1 -DORTHANC_BUILD_UNIT_TESTS=1 + -DORTHANC_WEBGL2_HEAP_COMPAT=0 )
--- a/OrthancStone/Sources/OpenGL/OpenGLTexture.cpp Mon Mar 06 11:00:55 2023 +0100 +++ b/OrthancStone/Sources/OpenGL/OpenGLTexture.cpp Wed Mar 08 17:46:04 2023 +0100 @@ -28,6 +28,12 @@ #include <Logging.h> #include <OrthancException.h> +#if defined(__EMSCRIPTEN__) +# if !defined(ORTHANC_WEBGL2_HEAP_COMPAT) +# error The macro ORTHANC_WEBGL2_HEAP_COMPAT must be defined +# endif +#endif + namespace OrthancStone { namespace OpenGL @@ -114,8 +120,38 @@ GLint interpolation = (isLinearInterpolation ? GL_LINEAR : GL_NEAREST); // Load the texture from the image buffer + +#if defined(__EMSCRIPTEN__) && (ORTHANC_WEBGL2_HEAP_COMPAT == 1) + /** + * This compatibility implementation seems to be necessary + * with WebGL2, at least in Web workers. In such a situation, + * the calls that are referred to as the "new garbage-free + * entry points" in the Emscripten source file + * "upstream/emscripten/src/library_webgl.js" seem to fail, + * because the "Uint8Array" and "Float32Array" seem to be + * incorrectly created. This compatibility reverts to the + * WebGL1 behavior of "library_webgl.js", which requires the + * function "emscriptenWebGLGetTexPixelData" that is defined + * in "upstream/emscripten/src/library_webgl.js" to be + * exported in the linker using option + * "EXTRA_EXPORTED_RUNTIME_METHODS" or + * "EXPORTED_RUNTIME_METHODS". + **/ + EM_ASM({ + var ptr = $0 ? emscriptenWebGLGetTexPixelData($5, $4, $2, $3, $0, $1) : null; + GLctx.texImage2D(GLctx.TEXTURE_2D, 0, $1, $2, $3, 0, $4, $5, ptr); + }, + data, // $0 + internalFormat, // $1 + width, // $2 + height, // $3 + sourceFormat, // $4 + pixelType); // $5 +#else glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height, 0, sourceFormat, pixelType, data); +#endif + ORTHANC_OPENGL_CHECK("glTexImage2D()"); #if !defined(__EMSCRIPTEN__)