| 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 |
|
| 5 |
// Important note to dawn and/or wgpu users: when targeting native platforms (i.e. NOT emscripten), |
| 6 |
// one of IMGUI_IMPL_WEBGPU_BACKEND_DAWN or IMGUI_IMPL_WEBGPU_BACKEND_WGPU must be provided. |
| 7 |
// Add #define to your imconfig.h file, or as a compilation flag in your build system. |
| 8 |
// This requirement will be removed once WebGPU stabilizes and backends converge on a unified interface. |
| 9 |
//#define IMGUI_IMPL_WEBGPU_BACKEND_DAWN |
| 10 |
//#define IMGUI_IMPL_WEBGPU_BACKEND_WGPU |
| 11 |
|
| 12 |
// Implemented features: |
| 13 |
// [X] Renderer: User texture binding. Use 'WGPUTextureView' as ImTextureID. Read the FAQ about ImTextureID! |
| 14 |
// [X] Renderer: Large meshes support (64k+ vertices) even with 16-bit indices (ImGuiBackendFlags_RendererHasVtxOffset). |
| 15 |
// [X] Renderer: Expose selected render state for draw callbacks to use. Access in '(ImGui_ImplXXXX_RenderState*)GetPlatformIO().Renderer_RenderState'. |
| 16 |
|
| 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 |
|
| 25 |
#pragma once |
| 26 |
#include "imgui.h" // IMGUI_IMPL_API |
| 27 |
#ifndef IMGUI_DISABLE |
| 28 |
|
| 29 |
#include <webgpu/webgpu.h> |
| 30 |
|
| 31 |
// Initialization data, for ImGui_ImplWGPU_Init() |
| 32 |
struct ImGui_ImplWGPU_InitInfo |
| 33 |
{ |
| 34 |
WGPUDevice Device; |
| 35 |
int NumFramesInFlight = 3; |
| 36 |
WGPUTextureFormat RenderTargetFormat = WGPUTextureFormat_Undefined; |
| 37 |
WGPUTextureFormat DepthStencilFormat = WGPUTextureFormat_Undefined; |
| 38 |
WGPUMultisampleState PipelineMultisampleState = {}; |
| 39 |
|
| 40 |
ImGui_ImplWGPU_InitInfo() |
| 41 |
{ |
| 42 |
PipelineMultisampleState.count = 1; |
| 43 |
PipelineMultisampleState.mask = UINT32_MAX; |
| 44 |
PipelineMultisampleState.alphaToCoverageEnabled = false; |
| 45 |
} |
| 46 |
}; |
| 47 |
|
| 48 |
// Follow "Getting Started" link and check examples/ folder to learn about using backends! |
| 49 |
IMGUI_IMPL_API bool ImGui_ImplWGPU_Init(ImGui_ImplWGPU_InitInfo* init_info); |
| 50 |
IMGUI_IMPL_API void ImGui_ImplWGPU_Shutdown(); |
| 51 |
IMGUI_IMPL_API void ImGui_ImplWGPU_NewFrame(); |
| 52 |
IMGUI_IMPL_API void ImGui_ImplWGPU_RenderDrawData(ImDrawData* draw_data, WGPURenderPassEncoder pass_encoder); |
| 53 |
|
| 54 |
// Use if you want to reset your rendering device without losing Dear ImGui state. |
| 55 |
IMGUI_IMPL_API bool ImGui_ImplWGPU_CreateDeviceObjects(); |
| 56 |
IMGUI_IMPL_API void ImGui_ImplWGPU_InvalidateDeviceObjects(); |
| 57 |
|
| 58 |
// [BETA] Selected render state data shared with callbacks. |
| 59 |
// This is temporarily stored in GetPlatformIO().Renderer_RenderState during the ImGui_ImplWGPU_RenderDrawData() call. |
| 60 |
// (Please open an issue if you feel you need access to more data) |
| 61 |
struct ImGui_ImplWGPU_RenderState |
| 62 |
{ |
| 63 |
WGPUDevice Device; |
| 64 |
WGPURenderPassEncoder RenderPassEncoder; |
| 65 |
}; |
| 66 |
|
| 67 |
#endif // #ifndef IMGUI_DISABLE |