imgui_impl_wgpu.h 3.6 KB

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