|
@@ -16,6 +16,7 @@
|
|
|
|
|
|
// CHANGELOG
|
|
|
// (minor and older changes stripped away, please see git history for details)
|
|
|
+// 2025-01-06: DirectX11: Expose VertexConstantBuffer in ImGui_ImplDX11_RenderState. Reset projection matrix in ImDrawCallback_ResetRenderState handler.
|
|
|
// 2024-10-07: DirectX11: Changed default texture sampler to Clamp instead of Repeat/Wrap.
|
|
|
// 2024-10-07: DirectX11: Expose selected render state in ImGui_ImplDX11_RenderState, which you can access in 'void* platform_io.Renderer_RenderState' during draw callbacks.
|
|
|
// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11.
|
|
@@ -98,6 +99,27 @@ static void ImGui_ImplDX11_SetupRenderState(ImDrawData* draw_data, ID3D11DeviceC
|
|
|
vp.TopLeftX = vp.TopLeftY = 0;
|
|
|
device_ctx->RSSetViewports(1, &vp);
|
|
|
|
|
|
+ // Setup orthographic projection matrix into our constant buffer
|
|
|
+ // Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps.
|
|
|
+ D3D11_MAPPED_SUBRESOURCE mapped_resource;
|
|
|
+ if (device_ctx->Map(bd->pVertexConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_resource) == S_OK)
|
|
|
+ {
|
|
|
+ VERTEX_CONSTANT_BUFFER_DX11* constant_buffer = (VERTEX_CONSTANT_BUFFER_DX11*)mapped_resource.pData;
|
|
|
+ float L = draw_data->DisplayPos.x;
|
|
|
+ float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x;
|
|
|
+ float T = draw_data->DisplayPos.y;
|
|
|
+ float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y;
|
|
|
+ float mvp[4][4] =
|
|
|
+ {
|
|
|
+ { 2.0f/(R-L), 0.0f, 0.0f, 0.0f },
|
|
|
+ { 0.0f, 2.0f/(T-B), 0.0f, 0.0f },
|
|
|
+ { 0.0f, 0.0f, 0.5f, 0.0f },
|
|
|
+ { (R+L)/(L-R), (T+B)/(B-T), 0.5f, 1.0f },
|
|
|
+ };
|
|
|
+ memcpy(&constant_buffer->mvp, mvp, sizeof(mvp));
|
|
|
+ device_ctx->Unmap(bd->pVertexConstantBuffer, 0);
|
|
|
+ }
|
|
|
+
|
|
|
// Setup shader and vertex buffers
|
|
|
unsigned int stride = sizeof(ImDrawVert);
|
|
|
unsigned int offset = 0;
|
|
@@ -179,28 +201,6 @@ void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data)
|
|
|
device->Unmap(bd->pVB, 0);
|
|
|
device->Unmap(bd->pIB, 0);
|
|
|
|
|
|
- // Setup orthographic projection matrix into our constant buffer
|
|
|
- // Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps.
|
|
|
- {
|
|
|
- D3D11_MAPPED_SUBRESOURCE mapped_resource;
|
|
|
- if (device->Map(bd->pVertexConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_resource) != S_OK)
|
|
|
- return;
|
|
|
- VERTEX_CONSTANT_BUFFER_DX11* constant_buffer = (VERTEX_CONSTANT_BUFFER_DX11*)mapped_resource.pData;
|
|
|
- float L = draw_data->DisplayPos.x;
|
|
|
- float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x;
|
|
|
- float T = draw_data->DisplayPos.y;
|
|
|
- float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y;
|
|
|
- float mvp[4][4] =
|
|
|
- {
|
|
|
- { 2.0f/(R-L), 0.0f, 0.0f, 0.0f },
|
|
|
- { 0.0f, 2.0f/(T-B), 0.0f, 0.0f },
|
|
|
- { 0.0f, 0.0f, 0.5f, 0.0f },
|
|
|
- { (R+L)/(L-R), (T+B)/(B-T), 0.5f, 1.0f },
|
|
|
- };
|
|
|
- memcpy(&constant_buffer->mvp, mvp, sizeof(mvp));
|
|
|
- device->Unmap(bd->pVertexConstantBuffer, 0);
|
|
|
- }
|
|
|
-
|
|
|
// Backup DX state that will be modified to restore it afterwards (unfortunately this is very ugly looking and verbose. Close your eyes!)
|
|
|
struct BACKUP_DX11_STATE
|
|
|
{
|
|
@@ -255,6 +255,7 @@ void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data)
|
|
|
render_state.Device = bd->pd3dDevice;
|
|
|
render_state.DeviceContext = bd->pd3dDeviceContext;
|
|
|
render_state.SamplerDefault = bd->pFontSampler;
|
|
|
+ render_state.VertexConstantBuffer = bd->pVertexConstantBuffer;
|
|
|
platform_io.Renderer_RenderState = &render_state;
|
|
|
|
|
|
// Render command lists
|