imgui_impl_wgpu.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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!
  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. // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
  15. // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
  16. // Learn about Dear ImGui:
  17. // - FAQ https://dearimgui.com/faq
  18. // - Getting Started https://dearimgui.com/getting-started
  19. // - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
  20. // - Introduction, links and more at the top of imgui.cpp
  21. #pragma once
  22. #include "imgui.h" // IMGUI_IMPL_API
  23. #ifndef IMGUI_DISABLE
  24. #include <webgpu/webgpu.h>
  25. // Initialization data, for ImGui_ImplWGPU_Init()
  26. struct ImGui_ImplWGPU_InitInfo
  27. {
  28. WGPUDevice Device;
  29. int NumFramesInFlight = 3;
  30. WGPUTextureFormat RenderTargetFormat = WGPUTextureFormat_Undefined;
  31. WGPUTextureFormat DepthStencilFormat = WGPUTextureFormat_Undefined;
  32. WGPUMultisampleState PipelineMultisampleState = {};
  33. ImGui_ImplWGPU_InitInfo()
  34. {
  35. PipelineMultisampleState.count = 1;
  36. PipelineMultisampleState.mask = UINT32_MAX;
  37. PipelineMultisampleState.alphaToCoverageEnabled = false;
  38. }
  39. };
  40. // Follow "Getting Started" link and check examples/ folder to learn about using backends!
  41. IMGUI_IMPL_API bool ImGui_ImplWGPU_Init(ImGui_ImplWGPU_InitInfo* init_info);
  42. IMGUI_IMPL_API void ImGui_ImplWGPU_Shutdown();
  43. IMGUI_IMPL_API void ImGui_ImplWGPU_NewFrame();
  44. IMGUI_IMPL_API void ImGui_ImplWGPU_RenderDrawData(ImDrawData* draw_data, WGPURenderPassEncoder pass_encoder);
  45. // Use if you want to reset your rendering device without losing Dear ImGui state.
  46. IMGUI_IMPL_API bool ImGui_ImplWGPU_CreateDeviceObjects();
  47. IMGUI_IMPL_API void ImGui_ImplWGPU_InvalidateDeviceObjects();
  48. // [BETA] Selected render state data shared with callbacks.
  49. // This is temporarily stored in GetPlatformIO().Renderer_RenderState during the ImGui_ImplWGPU_RenderDrawData() call.
  50. // (Please open an issue if you feel you need access to more data)
  51. struct ImGui_ImplWGPU_RenderState
  52. {
  53. WGPUDevice Device;
  54. WGPURenderPassEncoder RenderPassEncoder;
  55. };
  56. #endif // #ifndef IMGUI_DISABLE