|
@@ -13,9 +13,10 @@
|
|
|
|
|
|
// CHANGELOG
|
|
|
// (minor and older changes stripped away, please see git history for details)
|
|
|
+// 2022-11-10: Fixed rendering when a depth buffer is enabled. Added 'WGPUTextureFormat depth_format' parameter to ImGui_ImplWGPU_Init().
|
|
|
// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11.
|
|
|
// 2021-11-29: Passing explicit buffer sizes to wgpuRenderPassEncoderSetVertexBuffer()/wgpuRenderPassEncoderSetIndexBuffer().
|
|
|
-// 2021-08-24: Fix for latest specs.
|
|
|
+// 2021-08-24: Fixed for latest specs.
|
|
|
// 2021-05-24: Add support for draw_data->FramebufferScale.
|
|
|
// 2021-05-19: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement)
|
|
|
// 2021-05-16: Update to latest WebGPU specs (compatible with Emscripten 2.0.20 and Chrome Canary 92).
|
|
@@ -34,6 +35,7 @@ extern ImGuiID ImHashData(const void* data_p, size_t data_size, ImU32 seed = 0);
|
|
|
static WGPUDevice g_wgpuDevice = nullptr;
|
|
|
static WGPUQueue g_defaultQueue = nullptr;
|
|
|
static WGPUTextureFormat g_renderTargetFormat = WGPUTextureFormat_Undefined;
|
|
|
+static WGPUTextureFormat g_depthStencilFormat = WGPUTextureFormat_Undefined;
|
|
|
static WGPURenderPipeline g_pipelineState = nullptr;
|
|
|
|
|
|
struct RenderResources
|
|
@@ -602,12 +604,11 @@ bool ImGui_ImplWGPU_CreateDeviceObjects()
|
|
|
|
|
|
// Create depth-stencil State
|
|
|
WGPUDepthStencilState depth_stencil_state = {};
|
|
|
- depth_stencil_state.depthBias = 0;
|
|
|
- depth_stencil_state.depthBiasClamp = 0;
|
|
|
- depth_stencil_state.depthBiasSlopeScale = 0;
|
|
|
+ depth_stencil_state.format = g_depthStencilFormat;
|
|
|
+ depth_stencil_state.depthWriteEnabled = false;
|
|
|
|
|
|
// Configure disabled depth-stencil state
|
|
|
- graphics_pipeline_desc.depthStencil = nullptr;
|
|
|
+ graphics_pipeline_desc.depthStencil = g_depthStencilFormat == WGPUTextureFormat_Undefined ? nullptr : &depth_stencil_state;
|
|
|
|
|
|
g_pipelineState = wgpuDeviceCreateRenderPipeline(g_wgpuDevice, &graphics_pipeline_desc);
|
|
|
|
|
@@ -658,7 +659,7 @@ void ImGui_ImplWGPU_InvalidateDeviceObjects()
|
|
|
SafeRelease(g_pFrameResources[i]);
|
|
|
}
|
|
|
|
|
|
-bool ImGui_ImplWGPU_Init(WGPUDevice device, int num_frames_in_flight, WGPUTextureFormat rt_format)
|
|
|
+bool ImGui_ImplWGPU_Init(WGPUDevice device, int num_frames_in_flight, WGPUTextureFormat rt_format, WGPUTextureFormat depth_format)
|
|
|
{
|
|
|
// Setup backend capabilities flags
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
@@ -668,6 +669,7 @@ bool ImGui_ImplWGPU_Init(WGPUDevice device, int num_frames_in_flight, WGPUTextur
|
|
|
g_wgpuDevice = device;
|
|
|
g_defaultQueue = wgpuDeviceGetQueue(g_wgpuDevice);
|
|
|
g_renderTargetFormat = rt_format;
|
|
|
+ g_depthStencilFormat = depth_format;
|
|
|
g_pFrameResources = new FrameResources[num_frames_in_flight];
|
|
|
g_numFramesInFlight = num_frames_in_flight;
|
|
|
g_frameIndex = UINT_MAX;
|