P/Invoke Bridge
Overview
bridge.cpp is the interface layer between C# (Mono) and C++. It contains:
- A global
static VulkanRenderer g_renderer;instance extern "C"functions that delegate tog_renderermethods- Try/catch wrappers for functions that may throw
C# calls these functions via [DllImport("renderer")] in managed/rendering/NativeBridge.cs.
Bridge Functions by Category
Lifecycle
Input
Mesh
Procedural Primitives
Camera
Lighting
Time
Debug
Debug Wireframe Entities
Type Mapping (C# → C++)
NativeBridge.cs Convenience Wrappers
The C# side provides both raw [DllImport] declarations and convenience wrappers:
IsKeyPressed(key)→ convertsintreturn toboolSetCursorLocked(bool)→ convertsbooltointparameter- Overloaded primitives with default color (0.7, 0.7, 0.7) and segment counts (32 segments, 16 rings)
- GLFW key/mouse button constants defined as
const int
:::tip Where to Edit Adding a new bridge function (3-file checklist):
native/renderer.h— Declare the method onVulkanRenderer(public section)native/renderer/,native/scene/, ornative/ui/— Implement the method in the appropriate.cppfilenative/bridge.cpp— Addextern "C"wrapper callingg_renderer.method(). Use try/catch if it can throw.managed/rendering/NativeBridge.cs— Add[DllImport(LIB)]declaration + optional convenience wrapper :::