imgui_impl_wgpu.h 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // dear imgui: Renderer for WebGPU
  2. // This needs to be used along with a Platform Binding (e.g. GLFW)
  3. // (Please note that WebGPU is currently experimental, will not run on non-beta browsers, and may break.)
  4. // Important note to dawn and/or wgpu users: when targeting native platforms (i.e. NOT emscripten),
  5. // one of IMGUI_IMPL_WEBGPU_BACKEND_DAWN or IMGUI_IMPL_WEBGPU_BACKEND_WGPU must be provided.
  6. // Add #define to your imconfig.h file, or as a compilation flag in your build system.
  7. // This requirement will be removed once WebGPU stabilizes and backends converge on a unified interface.
  8. //#define IMGUI_IMPL_WEBGPU_BACKEND_DAWN
  9. //#define IMGUI_IMPL_WEBGPU_BACKEND_WGPU
  10. // Implemented features:
  11. // [X] Renderer: User texture binding. Use 'WGPUTextureView' as ImTextureID. Read the FAQ about ImTextureID/ImTextureRef!
  12. // [X] Renderer: Large meshes support (64k+ vertices) even with 16-bit indices (ImGuiBackendFlags_RendererHasVtxOffset).
  13. // [X] Renderer: Expose selected render state for draw callbacks to use. Access in '(ImGui_ImplXXXX_RenderState*)GetPlatformIO().Renderer_RenderState'.
  14. // [X] Renderer: Texture updates support for dynamic font system (ImGuiBackendFlags_RendererHasTextures).
  15. // Missing features or Issues:
  16. // [ ] Renderer: Multi-viewport support (multiple windows), useful for desktop.
  17. // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
  18. // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
  19. // Learn about Dear ImGui:
  20. // - FAQ https://dearimgui.com/faq
  21. // - Getting Started https://dearimgui.com/getting-started
  22. // - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
  23. // - Introduction, links and more at the top of imgui.cpp
  24. #pragma once
  25. #include "imgui.h" // IMGUI_IMPL_API
  26. #ifndef IMGUI_DISABLE
  27. #include <webgpu/webgpu.h>
  28. // Initialization data, for ImGui_ImplWGPU_Init()
  29. struct ImGui_ImplWGPU_InitInfo
  30. {
  31. WGPUDevice Device;
  32. int NumFramesInFlight = 3;
  33. WGPUTextureFormat RenderTargetFormat = WGPUTextureFormat_Undefined;
  34. WGPUTextureFormat DepthStencilFormat = WGPUTextureFormat_Undefined;
  35. WGPUMultisampleState PipelineMultisampleState = {};
  36. ImGui_ImplWGPU_InitInfo()
  37. {
  38. PipelineMultisampleState.count = 1;
  39. PipelineMultisampleState.mask = UINT32_MAX;
  40. PipelineMultisampleState.alphaToCoverageEnabled = false;
  41. }
  42. };
  43. // Follow "Getting Started" link and check examples/ folder to learn about using backends!
  44. IMGUI_IMPL_API bool ImGui_ImplWGPU_Init(ImGui_ImplWGPU_InitInfo* init_info);
  45. IMGUI_IMPL_API void ImGui_ImplWGPU_Shutdown();
  46. IMGUI_IMPL_API void ImGui_ImplWGPU_NewFrame();
  47. IMGUI_IMPL_API void ImGui_ImplWGPU_RenderDrawData(ImDrawData* draw_data, WGPURenderPassEncoder pass_encoder);
  48. // Use if you want to reset your rendering device without losing Dear ImGui state.
  49. IMGUI_IMPL_API bool ImGui_ImplWGPU_CreateDeviceObjects();
  50. IMGUI_IMPL_API void ImGui_ImplWGPU_InvalidateDeviceObjects();
  51. // (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = NULL to handle this manually.
  52. IMGUI_IMPL_API void ImGui_ImplWGPU_UpdateTexture(ImTextureData* tex);
  53. // [BETA] Selected render state data shared with callbacks.
  54. // This is temporarily stored in GetPlatformIO().Renderer_RenderState during the ImGui_ImplWGPU_RenderDrawData() call.
  55. // (Please open an issue if you feel you need access to more data)
  56. struct ImGui_ImplWGPU_RenderState
  57. {
  58. WGPUDevice Device;
  59. WGPURenderPassEncoder RenderPassEncoder;
  60. };
  61. #endif // #ifndef IMGUI_DISABLE