imgui_impl_wgpu.h 3.3 KB

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