Add BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES CMake option#1677
Merged
CedricGuillemet merged 9 commits intoApr 28, 2026
Conversation
When enabled, this option strips all bimg/bx/stb/webp image-decoding code from the NativeEngine plugin: - bimg, bimg_encode, bimg_decode are no longer linked - libwebp build is forced off - All bimg includes and helpers (ParseImage, PrepareImage, LoadTextureFromImage, LoadCubeTextureFromImages, etc.) are guarded out - LoadTexture, LoadRawTexture, LoadRawTexture2DArray, LoadCubeTexture, LoadCubeTextureWithMips, CreateImageBitmap, ResizeImageBitmap, and the format-conversion path of ReadTexture throw a Napi::Error at runtime Useful for embedders that supply their own decoded textures via LoadRawTexture-equivalent native paths and want to reduce binary size. Measured on Windows x64 Release Playground.exe: Image loading ON : 3,610,112 bytes Image loading OFF : 3,330,048 bytes Saved : 280,064 bytes (~7.8%) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an opt-in CMake build flag to compile the NativeEngine plugin without image decoding support (bimg/stb/WebP code paths), reducing binary size for embedders that handle texture decoding externally.
Changes:
- Introduces
BABYLON_NATIVE_DISABLE_IMAGE_LOADINGtop-level CMake option (defaultOFF) and forcesBABYLON_NATIVE_PLUGIN_NATIVEENGINE_WEBP=OFFwhen enabled. - Guards bimg/stb/WebP includes and helper implementations in
NativeEngineand makes image-loading-related NAPI entrypoints throw when invoked in a disabled build. - Stops explicitly linking
bimg*intoNativeEnginewhen the option is enabled.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| Plugins/NativeEngine/Source/NativeEngine.h | Guards bimg/bx includes behind BABYLON_NATIVE_DISABLE_IMAGE_LOADING. |
| Plugins/NativeEngine/Source/NativeEngine.cpp | Guards image-loading implementation; keeps APIs but throws when disabled; disables format conversion path when disabled. |
| Plugins/NativeEngine/CMakeLists.txt | Conditionally links bimg* and adds the compile definition when image loading is disabled. |
| CMakeLists.txt | Adds the new option and forces WebP support off when image loading is disabled. |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
bghgary
reviewed
Apr 27, 2026
…abylonNative into NoImageLoading
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
bkaradzic-microsoft
approved these changes
Apr 27, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds a new CMake option
BABYLON_NATIVE_PLUGIN_NATIVEENGINE_LOAD_IMAGES(defaultON) that enables all bimg / bx / stb / WebP image-decoding code from theNativeEngineplugin. Useful for embedders that decode textures themselves and want to reduce binary size.What it does when
OFFbimg,bimg_encode,bimg_decodeare no longer linked intoNativeEngine.BABYLON_NATIVE_PLUGIN_NATIVEENGINE_WEBPis forcedOFF(libwebp is not fetched/built).<bimg/...>,<bx/...>,<stb/...>,<webp/...>includes are guarded out.Cast,TransformImage,GetPixelMapper,ReorientImage,ParseImage,PrepareImage,LoadTextureFromImage,LoadCubeTextureFromImages, relatedstatic_asserts) are excluded from compilation.NativeEngineinstance methods stay registered but throw aNapi::Error("Image loading is disabled in this build (BABYLON_NATIVE_DISABLE_IMAGE_LOADING).") when invoked:loadTextureloadRawTextureloadRawTexture2DArrayloadCubeTextureloadCubeTextureWithMipscreateImageBitmapresizeImageBitmapReadTexture's bimg-based format-conversion path also throws; raw readback when source/target formats match continues to work.FlipImageis kept available because it's also used byReadTexture.Binary size impact
Measured on Windows x64 Release
Playground.exe(MSVC, default options):Playground.exeON(default)OFFHow to use