The Platform Layer in Godot provides the essential abstraction between the engine's core logic and the underlying Operating System (OS) and hardware. This layer handles window management, input events, file system access, and specialized hardware integrations like XR.
Godot utilizes a specialized inheritance structure where the OS class provides a generic interface, and platform-specific implementations (e.g., OS_Android, OS_MacOS, OS_Web) handle the concrete logic for each environment.
The platform layer bridges the "Godot World" (Main Loop, Servers) to the "Host World" (Android Activity, Web Browser, macOS Window). Each platform implements a DisplayServer to manage graphical surfaces and a platform-specific OS class for system-level services.
The following diagram maps engine-level abstractions to their concrete Android and macOS implementations.
Sources: platform/android/os_android.h43-110 platform/android/java_godot_lib_jni.cpp165-186 platform/macos/os_macos.mm31-50 platform/macos/display_server_macos.h71-100
The Android implementation relies heavily on a JNI (Java Native Interface) bridge. The engine is initialized through Java_org_godotengine_godot_GodotLib_initialize, which sets up the OS_Android instance and connects it to the Java-side wrappers platform/android/java_godot_lib_jni.cpp165-186
java_godot_lib_jni.cpp, facilitating communication between C++ and the Java Virtual Machine. The GodotJavaWrapper class platform/android/java_godot_wrapper.h43 provides C++ access to Java methods, while GodotIOJavaWrapper platform/android/java_godot_io_wrapper.h34 handles I/O specific calls.AndroidInputHandler, converting Android motion events into Godot InputEvent types platform/android/java_godot_lib_jni.cpp33FileAccessAndroid and DirAccessJAndroid allow Godot to read from APK assets and internal storage platform/android/os_android.cpp107-135For details, see Android Platform.
Sources: platform/android/os_android.cpp107-135 platform/android/java_godot_lib_jni.cpp165-186 platform/android/display_server_android.cpp75-105
The Web platform targets WebAssembly (WASM) via the Emscripten toolchain. It translates Godot's C++ calls into JavaScript browser APIs.
Engine class in engine.js which manages the WASM module lifecycle. The OS_Web class platform/web/os_web.h35 provides the core OS abstraction.DisplayServerWeb interfaces with the HTML5 Canvas and handles DOM events (keys, mouse, touch) platform/web/display_server_web.cpp67-185editor.html or full-size.html to define the environment where the canvas and status overlays reside misc/dist/html/full-size.html96-108For details, see Web Platform.
Sources: platform/web/display_server_web.cpp31-185 platform/web/os_web.h35 misc/dist/html/full-size.html112-214
The XR system is integrated into the platform layer through the XRServer and the OpenXR module. It provides a unified interface for VR/AR hardware using the OpenXR standard.
XrInstance), session state (XrSession), and swapchains.OpenXRExtensionWrapper) allows Godot to support vendor-specific features like Hand Tracking or Foveated Rendering.This diagram bridges the engine's generic XR abstractions to the concrete OpenXR implementation.
Sources: platform/android/java_godot_lib_jni.cpp58-60 platform/android/display_server_android.cpp44-51
For details, see XR & OpenXR.
| Platform | OS Implementation | Display Server | Entry Point / Bridge |
|---|---|---|---|
| Android | OS_Android platform/android/os_android.h43 | DisplayServerAndroid platform/android/display_server_android.h43 | java_godot_lib_jni.cpp platform/android/java_godot_lib_jni.cpp165 |
| Web | OS_Web platform/web/os_web.h35 | DisplayServerWeb platform/web/display_server_web.cpp31 | engine.js / WASM |
| macOS | OS_MacOS platform/macos/os_macos.h42 | DisplayServerMacOS platform/macos/display_server_macos.h71 | godot_main_macos.mm |
| Windows | OS_Windows | DisplayServerWindows platform/windows/display_server_windows.h195 | godot_windows.cpp |
| Linux/BSD | OS_Unix | DisplayServerX11 / DisplayServerWayland | godot_linuxbsd.cpp |
Sources: platform/android/os_android.h43 platform/android/display_server_android.h43 platform/macos/display_server_macos.h71 platform/web/display_server_web.cpp31 platform/windows/display_server_windows.h195 platform/linuxbsd/x11/display_server_x11.cpp181 platform/linuxbsd/wayland/display_server_wayland.cpp126
Refresh this wiki
This wiki was recently refreshed. Please wait 3 days to refresh again.