|
| 1 | +# Engine Backend & Feature Level Info |
| 2 | + |
| 3 | +`react-native-filament` exposes three read-only getters from the underlying Filament engine that describe the GPU backend and its capabilities. These are useful for adaptive quality, diagnostics, and telemetry. |
| 4 | + |
| 5 | +## API |
| 6 | + |
| 7 | +### `engine.getBackend()` |
| 8 | + |
| 9 | +Returns the resolved graphics backend as a string: |
| 10 | + |
| 11 | +| Value | Meaning | |
| 12 | +|-------|---------| |
| 13 | +| `"metal"` | Apple Metal (default on iOS/macOS) | |
| 14 | +| `"opengl"` | OpenGL ES (default on Android) | |
| 15 | +| `"vulkan"` | Vulkan (opt-in on Android/Linux/Windows) | |
| 16 | +| `"default"` | Should not appear at runtime -- the engine always resolves to a concrete backend | |
| 17 | + |
| 18 | +### `engine.getSupportedFeatureLevel()` |
| 19 | + |
| 20 | +Returns the highest feature level the device's GPU supports, as an integer `0`-`3`: |
| 21 | + |
| 22 | +| Level | Capabilities | |
| 23 | +|-------|-------------| |
| 24 | +| `0` | OpenGL ES 2.0 features only | |
| 25 | +| `1` | OpenGL ES 3.0 features (default on most modern devices) | |
| 26 | +| `2` | OpenGL ES 3.1 + 16 texture units + cubemap arrays | |
| 27 | +| `3` | OpenGL ES 3.1 + 31 texture units + cubemap arrays | |
| 28 | + |
| 29 | +On iOS with Metal, devices typically report feature level `3`. On Android the level depends on the GPU -- budget GPUs may report `1`, while mid-range and flagship GPUs report `2` or `3`. |
| 30 | + |
| 31 | +### `engine.getActiveFeatureLevel()` |
| 32 | + |
| 33 | +Returns the currently active feature level. This equals the supported level unless a lower level was explicitly set via `Engine.Builder.featureLevel()`. |
| 34 | + |
| 35 | +## Example: Adaptive Quality |
| 36 | + |
| 37 | +```tsx |
| 38 | +import { useFilamentContext } from 'react-native-filament'; |
| 39 | +import { useEffect } from 'react'; |
| 40 | + |
| 41 | +function AdaptiveScene() { |
| 42 | + const { engine } = useFilamentContext(); |
| 43 | + |
| 44 | + useEffect(() => { |
| 45 | + const backend = engine.getBackend(); |
| 46 | + const featureLevel = engine.getSupportedFeatureLevel(); |
| 47 | + |
| 48 | + console.log(`Backend: ${backend}, Feature Level: ${featureLevel}`); |
| 49 | + |
| 50 | + // Use feature level as a GPU capability signal: |
| 51 | + // Level 0-1: budget GPU -- use lower-poly models, fewer draw calls |
| 52 | + // Level 2+: capable GPU -- enable full-quality rendering |
| 53 | + }, [engine]); |
| 54 | + |
| 55 | + return ( |
| 56 | + // ... your scene |
| 57 | + ); |
| 58 | +} |
| 59 | +``` |
| 60 | + |
| 61 | +## Example: Device Diagnostics Screen |
| 62 | + |
| 63 | +```tsx |
| 64 | +import { useFilamentContext } from 'react-native-filament'; |
| 65 | +import { Text, View } from 'react-native'; |
| 66 | + |
| 67 | +function DiagnosticsPanel() { |
| 68 | + const { engine } = useFilamentContext(); |
| 69 | + |
| 70 | + return ( |
| 71 | + <View> |
| 72 | + <Text>Backend: {engine.getBackend()}</Text> |
| 73 | + <Text>Supported Feature Level: {engine.getSupportedFeatureLevel()}</Text> |
| 74 | + <Text>Active Feature Level: {engine.getActiveFeatureLevel()}</Text> |
| 75 | + </View> |
| 76 | + ); |
| 77 | +} |
| 78 | +``` |
| 79 | + |
| 80 | +## Background |
| 81 | + |
| 82 | +Filament's C++ `Engine` class has always had `getBackend()`, `getSupportedFeatureLevel()`, and `getActiveFeatureLevel()` -- zero-cost const getters that return immediately. This change bridges them through the JSI layer so they are accessible from JavaScript, following the same `EngineImpl` -> `EngineWrapper` -> TypeScript pattern used by all other Engine methods. |
0 commit comments