Backends: WebGPU: ImGui_ImplWGPU_Init() now takes a ImGui_ImplWGPU_InitInfo structure instead of variety of parameters, allowing for easier further changes. (#7240)
This commit is contained in:
parent
e3c7ff944d
commit
831d42c1ab
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
// CHANGELOG
|
// CHANGELOG
|
||||||
// (minor and older changes stripped away, please see git history for details)
|
// (minor and older changes stripped away, please see git history for details)
|
||||||
|
// 2024-01-22: (Breaking) ImGui_ImplWGPU_Init() now takes a ImGui_ImplWGPU_InitInfo structure instead of variety of parameters, allowing for easier further changes.
|
||||||
// 2024-01-17: Explicitly fill all of WGPUDepthStencilState since standard removed defaults.
|
// 2024-01-17: Explicitly fill all of WGPUDepthStencilState since standard removed defaults.
|
||||||
// 2023-07-13: Use WGPUShaderModuleWGSLDescriptor's code instead of source. use WGPUMipmapFilterMode_Linear instead of WGPUFilterMode_Linear. (#6602)
|
// 2023-07-13: Use WGPUShaderModuleWGSLDescriptor's code instead of source. use WGPUMipmapFilterMode_Linear instead of WGPUFilterMode_Linear. (#6602)
|
||||||
// 2023-04-11: Align buffer sizes. Use WGSL shaders instead of precompiled SPIR-V.
|
// 2023-04-11: Align buffer sizes. Use WGSL shaders instead of precompiled SPIR-V.
|
||||||
@ -73,16 +74,17 @@ struct Uniforms
|
|||||||
|
|
||||||
struct ImGui_ImplWGPU_Data
|
struct ImGui_ImplWGPU_Data
|
||||||
{
|
{
|
||||||
WGPUDevice wgpuDevice = nullptr;
|
ImGui_ImplWGPU_InitInfo initInfo;
|
||||||
WGPUQueue defaultQueue = nullptr;
|
WGPUDevice wgpuDevice = nullptr;
|
||||||
WGPUTextureFormat renderTargetFormat = WGPUTextureFormat_Undefined;
|
WGPUQueue defaultQueue = nullptr;
|
||||||
WGPUTextureFormat depthStencilFormat = WGPUTextureFormat_Undefined;
|
WGPUTextureFormat renderTargetFormat = WGPUTextureFormat_Undefined;
|
||||||
WGPURenderPipeline pipelineState = nullptr;
|
WGPUTextureFormat depthStencilFormat = WGPUTextureFormat_Undefined;
|
||||||
|
WGPURenderPipeline pipelineState = nullptr;
|
||||||
|
|
||||||
RenderResources renderResources;
|
RenderResources renderResources;
|
||||||
FrameResources* pFrameResources = nullptr;
|
FrameResources* pFrameResources = nullptr;
|
||||||
unsigned int numFramesInFlight = 0;
|
unsigned int numFramesInFlight = 0;
|
||||||
unsigned int frameIndex = UINT_MAX;
|
unsigned int frameIndex = UINT_MAX;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Backend data stored in io.BackendRendererUserData to allow support for multiple Dear ImGui contexts
|
// Backend data stored in io.BackendRendererUserData to allow support for multiple Dear ImGui contexts
|
||||||
@ -712,7 +714,7 @@ void ImGui_ImplWGPU_InvalidateDeviceObjects()
|
|||||||
SafeRelease(bd->pFrameResources[i]);
|
SafeRelease(bd->pFrameResources[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ImGui_ImplWGPU_Init(WGPUDevice device, int num_frames_in_flight, WGPUTextureFormat rt_format, WGPUTextureFormat depth_format)
|
bool ImGui_ImplWGPU_Init(ImGui_ImplWGPU_InitInfo* init_info)
|
||||||
{
|
{
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!");
|
IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!");
|
||||||
@ -723,11 +725,12 @@ bool ImGui_ImplWGPU_Init(WGPUDevice device, int num_frames_in_flight, WGPUTextur
|
|||||||
io.BackendRendererName = "imgui_impl_webgpu";
|
io.BackendRendererName = "imgui_impl_webgpu";
|
||||||
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
|
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
|
||||||
|
|
||||||
bd->wgpuDevice = device;
|
bd->initInfo = *init_info;
|
||||||
|
bd->wgpuDevice = init_info->Device;
|
||||||
bd->defaultQueue = wgpuDeviceGetQueue(bd->wgpuDevice);
|
bd->defaultQueue = wgpuDeviceGetQueue(bd->wgpuDevice);
|
||||||
bd->renderTargetFormat = rt_format;
|
bd->renderTargetFormat = init_info->RenderTargetFormat;
|
||||||
bd->depthStencilFormat = depth_format;
|
bd->depthStencilFormat = init_info->DepthStencilFormat;
|
||||||
bd->numFramesInFlight = num_frames_in_flight;
|
bd->numFramesInFlight = init_info->NumFramesInFlight;
|
||||||
bd->frameIndex = UINT_MAX;
|
bd->frameIndex = UINT_MAX;
|
||||||
|
|
||||||
bd->renderResources.FontTexture = nullptr;
|
bd->renderResources.FontTexture = nullptr;
|
||||||
@ -740,8 +743,8 @@ bool ImGui_ImplWGPU_Init(WGPUDevice device, int num_frames_in_flight, WGPUTextur
|
|||||||
bd->renderResources.ImageBindGroupLayout = nullptr;
|
bd->renderResources.ImageBindGroupLayout = nullptr;
|
||||||
|
|
||||||
// Create buffers with a default size (they will later be grown as needed)
|
// Create buffers with a default size (they will later be grown as needed)
|
||||||
bd->pFrameResources = new FrameResources[num_frames_in_flight];
|
bd->pFrameResources = new FrameResources[bd->numFramesInFlight];
|
||||||
for (int i = 0; i < num_frames_in_flight; i++)
|
for (int i = 0; i < bd->numFramesInFlight; i++)
|
||||||
{
|
{
|
||||||
FrameResources* fr = &bd->pFrameResources[i];
|
FrameResources* fr = &bd->pFrameResources[i];
|
||||||
fr->IndexBuffer = nullptr;
|
fr->IndexBuffer = nullptr;
|
||||||
|
@ -20,7 +20,16 @@
|
|||||||
|
|
||||||
#include <webgpu/webgpu.h>
|
#include <webgpu/webgpu.h>
|
||||||
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplWGPU_Init(WGPUDevice device, int num_frames_in_flight, WGPUTextureFormat rt_format, WGPUTextureFormat depth_format = WGPUTextureFormat_Undefined);
|
// Initialization data, for ImGui_ImplWGPU_Init()
|
||||||
|
struct ImGui_ImplWGPU_InitInfo
|
||||||
|
{
|
||||||
|
WGPUDevice Device;
|
||||||
|
int NumFramesInFlight = 3;
|
||||||
|
WGPUTextureFormat RenderTargetFormat = WGPUTextureFormat_Undefined;
|
||||||
|
WGPUTextureFormat DepthStencilFormat = WGPUTextureFormat_Undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplWGPU_Init(ImGui_ImplWGPU_InitInfo* init_info);
|
||||||
IMGUI_IMPL_API void ImGui_ImplWGPU_Shutdown();
|
IMGUI_IMPL_API void ImGui_ImplWGPU_Shutdown();
|
||||||
IMGUI_IMPL_API void ImGui_ImplWGPU_NewFrame();
|
IMGUI_IMPL_API void ImGui_ImplWGPU_NewFrame();
|
||||||
IMGUI_IMPL_API void ImGui_ImplWGPU_RenderDrawData(ImDrawData* draw_data, WGPURenderPassEncoder pass_encoder);
|
IMGUI_IMPL_API void ImGui_ImplWGPU_RenderDrawData(ImDrawData* draw_data, WGPURenderPassEncoder pass_encoder);
|
||||||
|
@ -43,6 +43,8 @@ Breaking changes:
|
|||||||
|
|
||||||
- Commented out ImGuiIO::ImeWindowHandle obsoleted in 1.87 in favor of writing
|
- Commented out ImGuiIO::ImeWindowHandle obsoleted in 1.87 in favor of writing
|
||||||
to 'void* ImGuiViewport::PlatformHandleRaw'.
|
to 'void* ImGuiViewport::PlatformHandleRaw'.
|
||||||
|
- Backends: WebGPU: ImGui_ImplWGPU_Init() now takes a ImGui_ImplWGPU_InitInfo structure
|
||||||
|
instead of variety of parameters, allowing for easier further changes. (#7240)
|
||||||
|
|
||||||
Other changes:
|
Other changes:
|
||||||
|
|
||||||
|
@ -96,7 +96,12 @@ int main(int, char**)
|
|||||||
#ifdef __EMSCRIPTEN__
|
#ifdef __EMSCRIPTEN__
|
||||||
ImGui_ImplGlfw_InstallEmscriptenCanvasResizeCallback("#canvas");
|
ImGui_ImplGlfw_InstallEmscriptenCanvasResizeCallback("#canvas");
|
||||||
#endif
|
#endif
|
||||||
ImGui_ImplWGPU_Init(wgpu_device, 3, wgpu_preferred_fmt, WGPUTextureFormat_Undefined);
|
ImGui_ImplWGPU_InitInfo init_info;
|
||||||
|
init_info.Device = wgpu_device;
|
||||||
|
init_info.NumFramesInFlight = 3;
|
||||||
|
init_info.RenderTargetFormat = wgpu_preferred_fmt;
|
||||||
|
init_info.DepthStencilFormat = WGPUTextureFormat_Undefined;
|
||||||
|
ImGui_ImplWGPU_Init(&init_info);
|
||||||
|
|
||||||
// Load Fonts
|
// Load Fonts
|
||||||
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
||||||
|
Loading…
Reference in New Issue
Block a user