imgui_impl_dx10.cpp 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. // dear imgui: Renderer Backend for DirectX10
  2. // This needs to be used along with a Platform Backend (e.g. Win32)
  3. // Implemented features:
  4. // [X] Renderer: User texture binding. Use 'ID3D10ShaderResourceView*' as texture identifier. Read the FAQ about ImTextureID/ImTextureRef!
  5. // [X] Renderer: Large meshes support (64k+ vertices) even with 16-bit indices (ImGuiBackendFlags_RendererHasVtxOffset).
  6. // [X] Renderer: Texture updates support for dynamic font atlas (ImGuiBackendFlags_RendererHasTextures).
  7. // [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
  8. // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
  9. // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
  10. // Learn about Dear ImGui:
  11. // - FAQ https://dearimgui.com/faq
  12. // - Getting Started https://dearimgui.com/getting-started
  13. // - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
  14. // - Introduction, links and more at the top of imgui.cpp
  15. // CHANGELOG
  16. // (minor and older changes stripped away, please see git history for details)
  17. // 2025-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
  18. // 2025-06-11: DirectX10: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas.
  19. // 2025-05-07: DirectX10: Honor draw_data->FramebufferScale to allow for custom backends and experiment using it (consistently with other renderer backends, even though in normal condition it is not set under Windows).
  20. // 2025-01-06: DirectX10: Expose selected render state in ImGui_ImplDX10_RenderState, which you can access in 'void* platform_io.Renderer_RenderState' during draw callbacks.
  21. // 2024-10-07: DirectX10: Changed default texture sampler to Clamp instead of Repeat/Wrap.
  22. // 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11.
  23. // 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX).
  24. // 2021-05-19: DirectX10: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement)
  25. // 2021-02-18: DirectX10: Change blending equation to preserve alpha in output buffer.
  26. // 2019-07-21: DirectX10: Backup, clear and restore Geometry Shader is any is bound when calling ImGui_ImplDX10_RenderDrawData().
  27. // 2019-05-29: DirectX10: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag.
  28. // 2019-04-30: DirectX10: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
  29. // 2018-12-03: Misc: Added #pragma comment statement to automatically link with d3dcompiler.lib when using D3DCompile().
  30. // 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window.
  31. // 2018-07-13: DirectX10: Fixed unreleased resources in Init and Shutdown functions.
  32. // 2018-06-08: Misc: Extracted imgui_impl_dx10.cpp/.h away from the old combined DX10+Win32 example.
  33. // 2018-06-08: DirectX10: Use draw_data->DisplayPos and draw_data->DisplaySize to setup projection matrix and clipping rectangle.
  34. // 2018-04-09: Misc: Fixed erroneous call to io.Fonts->ClearInputData() + ClearTexData() that was left in DX10 example but removed in 1.47 (Nov 2015) on other backends.
  35. // 2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback and exposed ImGui_ImplDX10_RenderDrawData() in the .h file so you can call it yourself.
  36. // 2018-02-06: Misc: Removed call to ImGui::Shutdown() which is not available from 1.60 WIP, user needs to call CreateContext/DestroyContext themselves.
  37. // 2016-05-07: DirectX10: Disabling depth-write.
  38. #include "imgui.h"
  39. #ifndef IMGUI_DISABLE
  40. #include "imgui_impl_dx10.h"
  41. // DirectX
  42. #include <stdio.h>
  43. #include <d3d10_1.h>
  44. #include <d3d10.h>
  45. #include <d3dcompiler.h>
  46. #ifdef _MSC_VER
  47. #pragma comment(lib, "d3dcompiler") // Automatically link with d3dcompiler.lib as we are using D3DCompile() below.
  48. #endif
  49. // Clang/GCC warnings with -Weverything
  50. #if defined(__clang__)
  51. #pragma clang diagnostic ignored "-Wold-style-cast" // warning: use of old-style cast // yes, they are more terse.
  52. #pragma clang diagnostic ignored "-Wsign-conversion" // warning: implicit conversion changes signedness
  53. #endif
  54. // DirectX10 data
  55. struct ImGui_ImplDX10_Texture
  56. {
  57. ID3D10Texture2D* pTexture;
  58. ID3D10ShaderResourceView* pTextureView;
  59. };
  60. struct ImGui_ImplDX10_Data
  61. {
  62. ID3D10Device* pd3dDevice;
  63. IDXGIFactory* pFactory;
  64. ID3D10Buffer* pVB;
  65. ID3D10Buffer* pIB;
  66. ID3D10VertexShader* pVertexShader;
  67. ID3D10InputLayout* pInputLayout;
  68. ID3D10Buffer* pVertexConstantBuffer;
  69. ID3D10PixelShader* pPixelShader;
  70. ID3D10SamplerState* pFontSampler;
  71. ID3D10RasterizerState* pRasterizerState;
  72. ID3D10BlendState* pBlendState;
  73. ID3D10DepthStencilState* pDepthStencilState;
  74. int VertexBufferSize;
  75. int IndexBufferSize;
  76. ImGui_ImplDX10_Data() { memset((void*)this, 0, sizeof(*this)); VertexBufferSize = 5000; IndexBufferSize = 10000; }
  77. };
  78. struct VERTEX_CONSTANT_BUFFER_DX10
  79. {
  80. float mvp[4][4];
  81. };
  82. // Backend data stored in io.BackendRendererUserData to allow support for multiple Dear ImGui contexts
  83. // It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts.
  84. static ImGui_ImplDX10_Data* ImGui_ImplDX10_GetBackendData()
  85. {
  86. return ImGui::GetCurrentContext() ? (ImGui_ImplDX10_Data*)ImGui::GetIO().BackendRendererUserData : nullptr;
  87. }
  88. // Forward Declarations
  89. static void ImGui_ImplDX10_InitMultiViewportSupport();
  90. static void ImGui_ImplDX10_ShutdownMultiViewportSupport();
  91. // Functions
  92. static void ImGui_ImplDX10_SetupRenderState(ImDrawData* draw_data, ID3D10Device* device)
  93. {
  94. ImGui_ImplDX10_Data* bd = ImGui_ImplDX10_GetBackendData();
  95. // Setup viewport
  96. D3D10_VIEWPORT vp = {};
  97. vp.Width = (UINT)(draw_data->DisplaySize.x * draw_data->FramebufferScale.x);
  98. vp.Height = (UINT)(draw_data->DisplaySize.y * draw_data->FramebufferScale.y);
  99. vp.MinDepth = 0.0f;
  100. vp.MaxDepth = 1.0f;
  101. vp.TopLeftX = vp.TopLeftY = 0;
  102. device->RSSetViewports(1, &vp);
  103. // Setup orthographic projection matrix into our constant buffer
  104. // 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.
  105. void* mapped_resource;
  106. if (bd->pVertexConstantBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, &mapped_resource) == S_OK)
  107. {
  108. VERTEX_CONSTANT_BUFFER_DX10* constant_buffer = (VERTEX_CONSTANT_BUFFER_DX10*)mapped_resource;
  109. float L = draw_data->DisplayPos.x;
  110. float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x;
  111. float T = draw_data->DisplayPos.y;
  112. float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y;
  113. float mvp[4][4] =
  114. {
  115. { 2.0f/(R-L), 0.0f, 0.0f, 0.0f },
  116. { 0.0f, 2.0f/(T-B), 0.0f, 0.0f },
  117. { 0.0f, 0.0f, 0.5f, 0.0f },
  118. { (R+L)/(L-R), (T+B)/(B-T), 0.5f, 1.0f },
  119. };
  120. memcpy(&constant_buffer->mvp, mvp, sizeof(mvp));
  121. bd->pVertexConstantBuffer->Unmap();
  122. }
  123. // Setup shader and vertex buffers
  124. unsigned int stride = sizeof(ImDrawVert);
  125. unsigned int offset = 0;
  126. device->IASetInputLayout(bd->pInputLayout);
  127. device->IASetVertexBuffers(0, 1, &bd->pVB, &stride, &offset);
  128. device->IASetIndexBuffer(bd->pIB, sizeof(ImDrawIdx) == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT, 0);
  129. device->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
  130. device->VSSetShader(bd->pVertexShader);
  131. device->VSSetConstantBuffers(0, 1, &bd->pVertexConstantBuffer);
  132. device->PSSetShader(bd->pPixelShader);
  133. device->PSSetSamplers(0, 1, &bd->pFontSampler);
  134. device->GSSetShader(nullptr);
  135. // Setup render state
  136. const float blend_factor[4] = { 0.f, 0.f, 0.f, 0.f };
  137. device->OMSetBlendState(bd->pBlendState, blend_factor, 0xffffffff);
  138. device->OMSetDepthStencilState(bd->pDepthStencilState, 0);
  139. device->RSSetState(bd->pRasterizerState);
  140. }
  141. // Render function
  142. void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data)
  143. {
  144. // Avoid rendering when minimized
  145. if (draw_data->DisplaySize.x <= 0.0f || draw_data->DisplaySize.y <= 0.0f)
  146. return;
  147. ImGui_ImplDX10_Data* bd = ImGui_ImplDX10_GetBackendData();
  148. ID3D10Device* device = bd->pd3dDevice;
  149. // Catch up with texture updates. Most of the times, the list will have 1 element with an OK status, aka nothing to do.
  150. // (This almost always points to ImGui::GetPlatformIO().Textures[] but is part of ImDrawData to allow overriding or disabling texture updates).
  151. if (draw_data->Textures != nullptr)
  152. for (ImTextureData* tex : *draw_data->Textures)
  153. if (tex->Status != ImTextureStatus_OK)
  154. ImGui_ImplDX10_UpdateTexture(tex);
  155. // Create and grow vertex/index buffers if needed
  156. if (!bd->pVB || bd->VertexBufferSize < draw_data->TotalVtxCount)
  157. {
  158. if (bd->pVB) { bd->pVB->Release(); bd->pVB = nullptr; }
  159. bd->VertexBufferSize = draw_data->TotalVtxCount + 5000;
  160. D3D10_BUFFER_DESC desc = {};
  161. desc.Usage = D3D10_USAGE_DYNAMIC;
  162. desc.ByteWidth = bd->VertexBufferSize * sizeof(ImDrawVert);
  163. desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
  164. desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
  165. desc.MiscFlags = 0;
  166. if (device->CreateBuffer(&desc, nullptr, &bd->pVB) < 0)
  167. return;
  168. }
  169. if (!bd->pIB || bd->IndexBufferSize < draw_data->TotalIdxCount)
  170. {
  171. if (bd->pIB) { bd->pIB->Release(); bd->pIB = nullptr; }
  172. bd->IndexBufferSize = draw_data->TotalIdxCount + 10000;
  173. D3D10_BUFFER_DESC desc = {};
  174. desc.Usage = D3D10_USAGE_DYNAMIC;
  175. desc.ByteWidth = bd->IndexBufferSize * sizeof(ImDrawIdx);
  176. desc.BindFlags = D3D10_BIND_INDEX_BUFFER;
  177. desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
  178. if (device->CreateBuffer(&desc, nullptr, &bd->pIB) < 0)
  179. return;
  180. }
  181. // Copy and convert all vertices into a single contiguous buffer
  182. ImDrawVert* vtx_dst = nullptr;
  183. ImDrawIdx* idx_dst = nullptr;
  184. bd->pVB->Map(D3D10_MAP_WRITE_DISCARD, 0, (void**)&vtx_dst);
  185. bd->pIB->Map(D3D10_MAP_WRITE_DISCARD, 0, (void**)&idx_dst);
  186. for (int n = 0; n < draw_data->CmdListsCount; n++)
  187. {
  188. const ImDrawList* draw_list = draw_data->CmdLists[n];
  189. memcpy(vtx_dst, draw_list->VtxBuffer.Data, draw_list->VtxBuffer.Size * sizeof(ImDrawVert));
  190. memcpy(idx_dst, draw_list->IdxBuffer.Data, draw_list->IdxBuffer.Size * sizeof(ImDrawIdx));
  191. vtx_dst += draw_list->VtxBuffer.Size;
  192. idx_dst += draw_list->IdxBuffer.Size;
  193. }
  194. bd->pVB->Unmap();
  195. bd->pIB->Unmap();
  196. // Backup DX state that will be modified to restore it afterwards (unfortunately this is very ugly looking and verbose. Close your eyes!)
  197. struct BACKUP_DX10_STATE
  198. {
  199. UINT ScissorRectsCount, ViewportsCount;
  200. D3D10_RECT ScissorRects[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
  201. D3D10_VIEWPORT Viewports[D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
  202. ID3D10RasterizerState* RS;
  203. ID3D10BlendState* BlendState;
  204. FLOAT BlendFactor[4];
  205. UINT SampleMask;
  206. UINT StencilRef;
  207. ID3D10DepthStencilState* DepthStencilState;
  208. ID3D10ShaderResourceView* PSShaderResource;
  209. ID3D10SamplerState* PSSampler;
  210. ID3D10PixelShader* PS;
  211. ID3D10VertexShader* VS;
  212. ID3D10GeometryShader* GS;
  213. D3D10_PRIMITIVE_TOPOLOGY PrimitiveTopology;
  214. ID3D10Buffer* IndexBuffer, *VertexBuffer, *VSConstantBuffer;
  215. UINT IndexBufferOffset, VertexBufferStride, VertexBufferOffset;
  216. DXGI_FORMAT IndexBufferFormat;
  217. ID3D10InputLayout* InputLayout;
  218. };
  219. BACKUP_DX10_STATE old = {};
  220. old.ScissorRectsCount = old.ViewportsCount = D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
  221. device->RSGetScissorRects(&old.ScissorRectsCount, old.ScissorRects);
  222. device->RSGetViewports(&old.ViewportsCount, old.Viewports);
  223. device->RSGetState(&old.RS);
  224. device->OMGetBlendState(&old.BlendState, old.BlendFactor, &old.SampleMask);
  225. device->OMGetDepthStencilState(&old.DepthStencilState, &old.StencilRef);
  226. device->PSGetShaderResources(0, 1, &old.PSShaderResource);
  227. device->PSGetSamplers(0, 1, &old.PSSampler);
  228. device->PSGetShader(&old.PS);
  229. device->VSGetShader(&old.VS);
  230. device->VSGetConstantBuffers(0, 1, &old.VSConstantBuffer);
  231. device->GSGetShader(&old.GS);
  232. device->IAGetPrimitiveTopology(&old.PrimitiveTopology);
  233. device->IAGetIndexBuffer(&old.IndexBuffer, &old.IndexBufferFormat, &old.IndexBufferOffset);
  234. device->IAGetVertexBuffers(0, 1, &old.VertexBuffer, &old.VertexBufferStride, &old.VertexBufferOffset);
  235. device->IAGetInputLayout(&old.InputLayout);
  236. // Setup desired DX state
  237. ImGui_ImplDX10_SetupRenderState(draw_data, device);
  238. // Setup render state structure (for callbacks and custom texture bindings)
  239. ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
  240. ImGui_ImplDX10_RenderState render_state;
  241. render_state.Device = bd->pd3dDevice;
  242. render_state.SamplerDefault = bd->pFontSampler;
  243. render_state.VertexConstantBuffer = bd->pVertexConstantBuffer;
  244. platform_io.Renderer_RenderState = &render_state;
  245. // Render command lists
  246. // (Because we merged all buffers into a single one, we maintain our own offset into them)
  247. int global_vtx_offset = 0;
  248. int global_idx_offset = 0;
  249. ImVec2 clip_off = draw_data->DisplayPos;
  250. ImVec2 clip_scale = draw_data->FramebufferScale;
  251. for (int n = 0; n < draw_data->CmdListsCount; n++)
  252. {
  253. const ImDrawList* draw_list = draw_data->CmdLists[n];
  254. for (int cmd_i = 0; cmd_i < draw_list->CmdBuffer.Size; cmd_i++)
  255. {
  256. const ImDrawCmd* pcmd = &draw_list->CmdBuffer[cmd_i];
  257. if (pcmd->UserCallback != nullptr)
  258. {
  259. // User callback, registered via ImDrawList::AddCallback()
  260. // (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
  261. if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
  262. ImGui_ImplDX10_SetupRenderState(draw_data, device);
  263. else
  264. pcmd->UserCallback(draw_list, pcmd);
  265. }
  266. else
  267. {
  268. // Project scissor/clipping rectangles into framebuffer space
  269. ImVec2 clip_min((pcmd->ClipRect.x - clip_off.x) * clip_scale.x, (pcmd->ClipRect.y - clip_off.y) * clip_scale.y);
  270. ImVec2 clip_max((pcmd->ClipRect.z - clip_off.x) * clip_scale.x, (pcmd->ClipRect.w - clip_off.y) * clip_scale.y);
  271. if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y)
  272. continue;
  273. // Apply scissor/clipping rectangle
  274. const D3D10_RECT r = { (LONG)clip_min.x, (LONG)clip_min.y, (LONG)clip_max.x, (LONG)clip_max.y };
  275. device->RSSetScissorRects(1, &r);
  276. // Bind texture, Draw
  277. ID3D10ShaderResourceView* texture_srv = (ID3D10ShaderResourceView*)pcmd->GetTexID();
  278. device->PSSetShaderResources(0, 1, &texture_srv);
  279. device->DrawIndexed(pcmd->ElemCount, pcmd->IdxOffset + global_idx_offset, pcmd->VtxOffset + global_vtx_offset);
  280. }
  281. }
  282. global_idx_offset += draw_list->IdxBuffer.Size;
  283. global_vtx_offset += draw_list->VtxBuffer.Size;
  284. }
  285. platform_io.Renderer_RenderState = nullptr;
  286. // Restore modified DX state
  287. device->RSSetScissorRects(old.ScissorRectsCount, old.ScissorRects);
  288. device->RSSetViewports(old.ViewportsCount, old.Viewports);
  289. device->RSSetState(old.RS); if (old.RS) old.RS->Release();
  290. device->OMSetBlendState(old.BlendState, old.BlendFactor, old.SampleMask); if (old.BlendState) old.BlendState->Release();
  291. device->OMSetDepthStencilState(old.DepthStencilState, old.StencilRef); if (old.DepthStencilState) old.DepthStencilState->Release();
  292. device->PSSetShaderResources(0, 1, &old.PSShaderResource); if (old.PSShaderResource) old.PSShaderResource->Release();
  293. device->PSSetSamplers(0, 1, &old.PSSampler); if (old.PSSampler) old.PSSampler->Release();
  294. device->PSSetShader(old.PS); if (old.PS) old.PS->Release();
  295. device->VSSetShader(old.VS); if (old.VS) old.VS->Release();
  296. device->GSSetShader(old.GS); if (old.GS) old.GS->Release();
  297. device->VSSetConstantBuffers(0, 1, &old.VSConstantBuffer); if (old.VSConstantBuffer) old.VSConstantBuffer->Release();
  298. device->IASetPrimitiveTopology(old.PrimitiveTopology);
  299. device->IASetIndexBuffer(old.IndexBuffer, old.IndexBufferFormat, old.IndexBufferOffset); if (old.IndexBuffer) old.IndexBuffer->Release();
  300. device->IASetVertexBuffers(0, 1, &old.VertexBuffer, &old.VertexBufferStride, &old.VertexBufferOffset); if (old.VertexBuffer) old.VertexBuffer->Release();
  301. device->IASetInputLayout(old.InputLayout); if (old.InputLayout) old.InputLayout->Release();
  302. }
  303. static void ImGui_ImplDX10_DestroyTexture(ImTextureData* tex)
  304. {
  305. ImGui_ImplDX10_Texture* backend_tex = (ImGui_ImplDX10_Texture*)tex->BackendUserData;
  306. if (backend_tex == nullptr)
  307. return;
  308. IM_ASSERT(backend_tex->pTextureView == (ID3D10ShaderResourceView*)(intptr_t)tex->TexID);
  309. backend_tex->pTexture->Release();
  310. backend_tex->pTextureView->Release();
  311. IM_DELETE(backend_tex);
  312. // Clear identifiers and mark as destroyed (in order to allow e.g. calling InvalidateDeviceObjects while running)
  313. tex->SetTexID(ImTextureID_Invalid);
  314. tex->SetStatus(ImTextureStatus_Destroyed);
  315. tex->BackendUserData = nullptr;
  316. }
  317. void ImGui_ImplDX10_UpdateTexture(ImTextureData* tex)
  318. {
  319. ImGui_ImplDX10_Data* bd = ImGui_ImplDX10_GetBackendData();
  320. if (tex->Status == ImTextureStatus_WantCreate)
  321. {
  322. // Create and upload new texture to graphics system
  323. //IMGUI_DEBUG_LOG("UpdateTexture #%03d: WantCreate %dx%d\n", tex->UniqueID, tex->Width, tex->Height);
  324. IM_ASSERT(tex->TexID == ImTextureID_Invalid && tex->BackendUserData == nullptr);
  325. IM_ASSERT(tex->Format == ImTextureFormat_RGBA32);
  326. unsigned int* pixels = (unsigned int*)tex->GetPixels();
  327. ImGui_ImplDX10_Texture* backend_tex = IM_NEW(ImGui_ImplDX10_Texture)();
  328. // Create texture
  329. D3D10_TEXTURE2D_DESC desc;
  330. ZeroMemory(&desc, sizeof(desc));
  331. desc.Width = (UINT)tex->Width;
  332. desc.Height = (UINT)tex->Height;
  333. desc.MipLevels = 1;
  334. desc.ArraySize = 1;
  335. desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
  336. desc.SampleDesc.Count = 1;
  337. desc.Usage = D3D10_USAGE_DEFAULT;
  338. desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
  339. desc.CPUAccessFlags = 0;
  340. D3D10_SUBRESOURCE_DATA subResource;
  341. subResource.pSysMem = pixels;
  342. subResource.SysMemPitch = desc.Width * 4;
  343. subResource.SysMemSlicePitch = 0;
  344. bd->pd3dDevice->CreateTexture2D(&desc, &subResource, &backend_tex->pTexture);
  345. IM_ASSERT(backend_tex->pTexture != nullptr && "Backend failed to create texture!");
  346. // Create texture view
  347. D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
  348. ZeroMemory(&srv_desc, sizeof(srv_desc));
  349. srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
  350. srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
  351. srv_desc.Texture2D.MipLevels = desc.MipLevels;
  352. srv_desc.Texture2D.MostDetailedMip = 0;
  353. bd->pd3dDevice->CreateShaderResourceView(backend_tex->pTexture, &srv_desc, &backend_tex->pTextureView);
  354. IM_ASSERT(backend_tex->pTextureView != nullptr && "Backend failed to create texture!");
  355. // Store identifiers
  356. tex->SetTexID((ImTextureID)(intptr_t)backend_tex->pTextureView);
  357. tex->SetStatus(ImTextureStatus_OK);
  358. tex->BackendUserData = backend_tex;
  359. }
  360. else if (tex->Status == ImTextureStatus_WantUpdates)
  361. {
  362. // Update selected blocks. We only ever write to textures regions which have never been used before!
  363. // This backend choose to use tex->Updates[] but you can use tex->UpdateRect to upload a single region.
  364. ImGui_ImplDX10_Texture* backend_tex = (ImGui_ImplDX10_Texture*)tex->BackendUserData;
  365. IM_ASSERT(backend_tex->pTextureView == (ID3D10ShaderResourceView*)(intptr_t)tex->TexID);
  366. for (ImTextureRect& r : tex->Updates)
  367. {
  368. D3D10_BOX box = { (UINT)r.x, (UINT)r.y, (UINT)0, (UINT)(r.x + r.w), (UINT)(r.y + r.h), (UINT)1 };
  369. bd->pd3dDevice->UpdateSubresource(backend_tex->pTexture, 0, &box, tex->GetPixelsAt(r.x, r.y), (UINT)tex->GetPitch(), 0);
  370. }
  371. tex->SetStatus(ImTextureStatus_OK);
  372. }
  373. if (tex->Status == ImTextureStatus_WantDestroy && tex->UnusedFrames > 0)
  374. ImGui_ImplDX10_DestroyTexture(tex);
  375. }
  376. bool ImGui_ImplDX10_CreateDeviceObjects()
  377. {
  378. ImGui_ImplDX10_Data* bd = ImGui_ImplDX10_GetBackendData();
  379. if (!bd->pd3dDevice)
  380. return false;
  381. ImGui_ImplDX10_InvalidateDeviceObjects();
  382. // By using D3DCompile() from <d3dcompiler.h> / d3dcompiler.lib, we introduce a dependency to a given version of d3dcompiler_XX.dll (see D3DCOMPILER_DLL_A)
  383. // If you would like to use this DX10 sample code but remove this dependency you can:
  384. // 1) compile once, save the compiled shader blobs into a file or source code and pass them to CreateVertexShader()/CreatePixelShader() [preferred solution]
  385. // 2) use code to detect any version of the DLL and grab a pointer to D3DCompile from the DLL.
  386. // See https://github.com/ocornut/imgui/pull/638 for sources and details.
  387. // Create the vertex shader
  388. {
  389. static const char* vertexShader =
  390. "cbuffer vertexBuffer : register(b0) \
  391. {\
  392. float4x4 ProjectionMatrix; \
  393. };\
  394. struct VS_INPUT\
  395. {\
  396. float2 pos : POSITION;\
  397. float4 col : COLOR0;\
  398. float2 uv : TEXCOORD0;\
  399. };\
  400. \
  401. struct PS_INPUT\
  402. {\
  403. float4 pos : SV_POSITION;\
  404. float4 col : COLOR0;\
  405. float2 uv : TEXCOORD0;\
  406. };\
  407. \
  408. PS_INPUT main(VS_INPUT input)\
  409. {\
  410. PS_INPUT output;\
  411. output.pos = mul( ProjectionMatrix, float4(input.pos.xy, 0.f, 1.f));\
  412. output.col = input.col;\
  413. output.uv = input.uv;\
  414. return output;\
  415. }";
  416. ID3DBlob* vertexShaderBlob;
  417. if (FAILED(D3DCompile(vertexShader, strlen(vertexShader), nullptr, nullptr, nullptr, "main", "vs_4_0", 0, 0, &vertexShaderBlob, nullptr)))
  418. return false; // NB: Pass ID3DBlob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob!
  419. if (bd->pd3dDevice->CreateVertexShader(vertexShaderBlob->GetBufferPointer(), vertexShaderBlob->GetBufferSize(), &bd->pVertexShader) != S_OK)
  420. {
  421. vertexShaderBlob->Release();
  422. return false;
  423. }
  424. // Create the input layout
  425. D3D10_INPUT_ELEMENT_DESC local_layout[] =
  426. {
  427. { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (UINT)offsetof(ImDrawVert, pos), D3D10_INPUT_PER_VERTEX_DATA, 0 },
  428. { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (UINT)offsetof(ImDrawVert, uv), D3D10_INPUT_PER_VERTEX_DATA, 0 },
  429. { "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, (UINT)offsetof(ImDrawVert, col), D3D10_INPUT_PER_VERTEX_DATA, 0 },
  430. };
  431. if (bd->pd3dDevice->CreateInputLayout(local_layout, 3, vertexShaderBlob->GetBufferPointer(), vertexShaderBlob->GetBufferSize(), &bd->pInputLayout) != S_OK)
  432. {
  433. vertexShaderBlob->Release();
  434. return false;
  435. }
  436. vertexShaderBlob->Release();
  437. // Create the constant buffer
  438. {
  439. D3D10_BUFFER_DESC desc = {};
  440. desc.ByteWidth = sizeof(VERTEX_CONSTANT_BUFFER_DX10);
  441. desc.Usage = D3D10_USAGE_DYNAMIC;
  442. desc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
  443. desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
  444. desc.MiscFlags = 0;
  445. bd->pd3dDevice->CreateBuffer(&desc, nullptr, &bd->pVertexConstantBuffer);
  446. }
  447. }
  448. // Create the pixel shader
  449. {
  450. static const char* pixelShader =
  451. "struct PS_INPUT\
  452. {\
  453. float4 pos : SV_POSITION;\
  454. float4 col : COLOR0;\
  455. float2 uv : TEXCOORD0;\
  456. };\
  457. sampler sampler0;\
  458. Texture2D texture0;\
  459. \
  460. float4 main(PS_INPUT input) : SV_Target\
  461. {\
  462. float4 out_col = input.col * texture0.Sample(sampler0, input.uv); \
  463. return out_col; \
  464. }";
  465. ID3DBlob* pixelShaderBlob;
  466. if (FAILED(D3DCompile(pixelShader, strlen(pixelShader), nullptr, nullptr, nullptr, "main", "ps_4_0", 0, 0, &pixelShaderBlob, nullptr)))
  467. return false; // NB: Pass ID3DBlob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob!
  468. if (bd->pd3dDevice->CreatePixelShader(pixelShaderBlob->GetBufferPointer(), pixelShaderBlob->GetBufferSize(), &bd->pPixelShader) != S_OK)
  469. {
  470. pixelShaderBlob->Release();
  471. return false;
  472. }
  473. pixelShaderBlob->Release();
  474. }
  475. // Create the blending setup
  476. {
  477. D3D10_BLEND_DESC desc;
  478. ZeroMemory(&desc, sizeof(desc));
  479. desc.AlphaToCoverageEnable = false;
  480. desc.BlendEnable[0] = true;
  481. desc.SrcBlend = D3D10_BLEND_SRC_ALPHA;
  482. desc.DestBlend = D3D10_BLEND_INV_SRC_ALPHA;
  483. desc.BlendOp = D3D10_BLEND_OP_ADD;
  484. desc.SrcBlendAlpha = D3D10_BLEND_ONE;
  485. desc.DestBlendAlpha = D3D10_BLEND_INV_SRC_ALPHA;
  486. desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
  487. desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
  488. bd->pd3dDevice->CreateBlendState(&desc, &bd->pBlendState);
  489. }
  490. // Create the rasterizer state
  491. {
  492. D3D10_RASTERIZER_DESC desc;
  493. ZeroMemory(&desc, sizeof(desc));
  494. desc.FillMode = D3D10_FILL_SOLID;
  495. desc.CullMode = D3D10_CULL_NONE;
  496. desc.ScissorEnable = true;
  497. desc.DepthClipEnable = true;
  498. bd->pd3dDevice->CreateRasterizerState(&desc, &bd->pRasterizerState);
  499. }
  500. // Create depth-stencil State
  501. {
  502. D3D10_DEPTH_STENCIL_DESC desc;
  503. ZeroMemory(&desc, sizeof(desc));
  504. desc.DepthEnable = false;
  505. desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
  506. desc.DepthFunc = D3D10_COMPARISON_ALWAYS;
  507. desc.StencilEnable = false;
  508. desc.FrontFace.StencilFailOp = desc.FrontFace.StencilDepthFailOp = desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
  509. desc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
  510. desc.BackFace = desc.FrontFace;
  511. bd->pd3dDevice->CreateDepthStencilState(&desc, &bd->pDepthStencilState);
  512. }
  513. // Create texture sampler
  514. // (Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling)
  515. {
  516. D3D10_SAMPLER_DESC desc;
  517. ZeroMemory(&desc, sizeof(desc));
  518. desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
  519. desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
  520. desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
  521. desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
  522. desc.MipLODBias = 0.f;
  523. desc.ComparisonFunc = D3D10_COMPARISON_ALWAYS;
  524. desc.MinLOD = 0.f;
  525. desc.MaxLOD = 0.f;
  526. bd->pd3dDevice->CreateSamplerState(&desc, &bd->pFontSampler);
  527. }
  528. return true;
  529. }
  530. void ImGui_ImplDX10_InvalidateDeviceObjects()
  531. {
  532. ImGui_ImplDX10_Data* bd = ImGui_ImplDX10_GetBackendData();
  533. if (!bd->pd3dDevice)
  534. return;
  535. // Destroy all textures
  536. for (ImTextureData* tex : ImGui::GetPlatformIO().Textures)
  537. if (tex->RefCount == 1)
  538. ImGui_ImplDX10_DestroyTexture(tex);
  539. if (bd->pFontSampler) { bd->pFontSampler->Release(); bd->pFontSampler = nullptr; }
  540. if (bd->pIB) { bd->pIB->Release(); bd->pIB = nullptr; }
  541. if (bd->pVB) { bd->pVB->Release(); bd->pVB = nullptr; }
  542. if (bd->pBlendState) { bd->pBlendState->Release(); bd->pBlendState = nullptr; }
  543. if (bd->pDepthStencilState) { bd->pDepthStencilState->Release(); bd->pDepthStencilState = nullptr; }
  544. if (bd->pRasterizerState) { bd->pRasterizerState->Release(); bd->pRasterizerState = nullptr; }
  545. if (bd->pPixelShader) { bd->pPixelShader->Release(); bd->pPixelShader = nullptr; }
  546. if (bd->pVertexConstantBuffer) { bd->pVertexConstantBuffer->Release(); bd->pVertexConstantBuffer = nullptr; }
  547. if (bd->pInputLayout) { bd->pInputLayout->Release(); bd->pInputLayout = nullptr; }
  548. if (bd->pVertexShader) { bd->pVertexShader->Release(); bd->pVertexShader = nullptr; }
  549. }
  550. bool ImGui_ImplDX10_Init(ID3D10Device* device)
  551. {
  552. ImGuiIO& io = ImGui::GetIO();
  553. IMGUI_CHECKVERSION();
  554. IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!");
  555. // Setup backend capabilities flags
  556. ImGui_ImplDX10_Data* bd = IM_NEW(ImGui_ImplDX10_Data)();
  557. io.BackendRendererUserData = (void*)bd;
  558. io.BackendRendererName = "imgui_impl_dx10";
  559. io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
  560. io.BackendFlags |= ImGuiBackendFlags_RendererHasTextures; // We can honor ImGuiPlatformIO::Textures[] requests during render.
  561. io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional)
  562. ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
  563. platform_io.Renderer_TextureMaxWidth = platform_io.Renderer_TextureMaxHeight = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
  564. // Get factory from device
  565. IDXGIDevice* pDXGIDevice = nullptr;
  566. IDXGIAdapter* pDXGIAdapter = nullptr;
  567. IDXGIFactory* pFactory = nullptr;
  568. if (device->QueryInterface(IID_PPV_ARGS(&pDXGIDevice)) == S_OK)
  569. if (pDXGIDevice->GetParent(IID_PPV_ARGS(&pDXGIAdapter)) == S_OK)
  570. if (pDXGIAdapter->GetParent(IID_PPV_ARGS(&pFactory)) == S_OK)
  571. {
  572. bd->pd3dDevice = device;
  573. bd->pFactory = pFactory;
  574. }
  575. if (pDXGIDevice) pDXGIDevice->Release();
  576. if (pDXGIAdapter) pDXGIAdapter->Release();
  577. bd->pd3dDevice->AddRef();
  578. ImGui_ImplDX10_InitMultiViewportSupport();
  579. return true;
  580. }
  581. void ImGui_ImplDX10_Shutdown()
  582. {
  583. ImGui_ImplDX10_Data* bd = ImGui_ImplDX10_GetBackendData();
  584. IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
  585. ImGuiIO& io = ImGui::GetIO();
  586. ImGui_ImplDX10_ShutdownMultiViewportSupport();
  587. ImGui_ImplDX10_InvalidateDeviceObjects();
  588. if (bd->pFactory) { bd->pFactory->Release(); }
  589. if (bd->pd3dDevice) { bd->pd3dDevice->Release(); }
  590. io.BackendRendererName = nullptr;
  591. io.BackendRendererUserData = nullptr;
  592. io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasTextures | ImGuiBackendFlags_RendererHasViewports);
  593. IM_DELETE(bd);
  594. }
  595. void ImGui_ImplDX10_NewFrame()
  596. {
  597. ImGui_ImplDX10_Data* bd = ImGui_ImplDX10_GetBackendData();
  598. IM_ASSERT(bd != nullptr && "Context or backend not initialized! Did you call ImGui_ImplDX10_Init()?");
  599. if (!bd->pVertexShader)
  600. if (!ImGui_ImplDX10_CreateDeviceObjects())
  601. IM_ASSERT(0 && "ImGui_ImplDX10_CreateDeviceObjects() failed!");
  602. }
  603. //--------------------------------------------------------------------------------------------------------
  604. // MULTI-VIEWPORT / PLATFORM INTERFACE SUPPORT
  605. // This is an _advanced_ and _optional_ feature, allowing the backend to create and handle multiple viewports simultaneously.
  606. // If you are new to dear imgui or creating a new binding for dear imgui, it is recommended that you completely ignore this section first..
  607. //--------------------------------------------------------------------------------------------------------
  608. // Helper structure we store in the void* RendererUserData field of each ImGuiViewport to easily retrieve our backend data.
  609. struct ImGui_ImplDX10_ViewportData
  610. {
  611. IDXGISwapChain* SwapChain;
  612. ID3D10RenderTargetView* RTView;
  613. ImGui_ImplDX10_ViewportData() { SwapChain = nullptr; RTView = nullptr; }
  614. ~ImGui_ImplDX10_ViewportData() { IM_ASSERT(SwapChain == nullptr && RTView == nullptr); }
  615. };
  616. static void ImGui_ImplDX10_CreateWindow(ImGuiViewport* viewport)
  617. {
  618. ImGui_ImplDX10_Data* bd = ImGui_ImplDX10_GetBackendData();
  619. ImGui_ImplDX10_ViewportData* vd = IM_NEW(ImGui_ImplDX10_ViewportData)();
  620. viewport->RendererUserData = vd;
  621. // PlatformHandleRaw should always be a HWND, whereas PlatformHandle might be a higher-level handle (e.g. GLFWWindow*, SDL's WindowID).
  622. // Some backends will leave PlatformHandleRaw == 0, in which case we assume PlatformHandle will contain the HWND.
  623. HWND hwnd = viewport->PlatformHandleRaw ? (HWND)viewport->PlatformHandleRaw : (HWND)viewport->PlatformHandle;
  624. IM_ASSERT(hwnd != 0);
  625. // Create swap chain
  626. DXGI_SWAP_CHAIN_DESC sd;
  627. ZeroMemory(&sd, sizeof(sd));
  628. sd.BufferDesc.Width = (UINT)viewport->Size.x;
  629. sd.BufferDesc.Height = (UINT)viewport->Size.y;
  630. sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
  631. sd.SampleDesc.Count = 1;
  632. sd.SampleDesc.Quality = 0;
  633. sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
  634. sd.BufferCount = 1;
  635. sd.OutputWindow = hwnd;
  636. sd.Windowed = TRUE;
  637. sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
  638. sd.Flags = 0;
  639. IM_ASSERT(vd->SwapChain == nullptr && vd->RTView == nullptr);
  640. bd->pFactory->CreateSwapChain(bd->pd3dDevice, &sd, &vd->SwapChain);
  641. // Create the render target
  642. if (vd->SwapChain)
  643. {
  644. ID3D10Texture2D* pBackBuffer;
  645. vd->SwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer));
  646. bd->pd3dDevice->CreateRenderTargetView(pBackBuffer, nullptr, &vd->RTView);
  647. pBackBuffer->Release();
  648. }
  649. }
  650. static void ImGui_ImplDX10_DestroyWindow(ImGuiViewport* viewport)
  651. {
  652. // The main viewport (owned by the application) will always have RendererUserData == 0 here since we didn't create the data for it.
  653. if (ImGui_ImplDX10_ViewportData* vd = (ImGui_ImplDX10_ViewportData*)viewport->RendererUserData)
  654. {
  655. if (vd->SwapChain)
  656. vd->SwapChain->Release();
  657. vd->SwapChain = nullptr;
  658. if (vd->RTView)
  659. vd->RTView->Release();
  660. vd->RTView = nullptr;
  661. IM_DELETE(vd);
  662. }
  663. viewport->RendererUserData = nullptr;
  664. }
  665. static void ImGui_ImplDX10_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
  666. {
  667. ImGui_ImplDX10_Data* bd = ImGui_ImplDX10_GetBackendData();
  668. ImGui_ImplDX10_ViewportData* vd = (ImGui_ImplDX10_ViewportData*)viewport->RendererUserData;
  669. if (vd->RTView)
  670. {
  671. vd->RTView->Release();
  672. vd->RTView = nullptr;
  673. }
  674. if (vd->SwapChain)
  675. {
  676. ID3D10Texture2D* pBackBuffer = nullptr;
  677. vd->SwapChain->ResizeBuffers(0, (UINT)size.x, (UINT)size.y, DXGI_FORMAT_UNKNOWN, 0);
  678. vd->SwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer));
  679. if (pBackBuffer == nullptr) { fprintf(stderr, "ImGui_ImplDX10_SetWindowSize() failed creating buffers.\n"); return; }
  680. bd->pd3dDevice->CreateRenderTargetView(pBackBuffer, nullptr, &vd->RTView);
  681. pBackBuffer->Release();
  682. }
  683. }
  684. static void ImGui_ImplDX10_RenderViewport(ImGuiViewport* viewport, void*)
  685. {
  686. ImGui_ImplDX10_Data* bd = ImGui_ImplDX10_GetBackendData();
  687. ImGui_ImplDX10_ViewportData* vd = (ImGui_ImplDX10_ViewportData*)viewport->RendererUserData;
  688. ImVec4 clear_color = ImVec4(0.0f, 0.0f, 0.0f, 1.0f);
  689. bd->pd3dDevice->OMSetRenderTargets(1, &vd->RTView, nullptr);
  690. if (!(viewport->Flags & ImGuiViewportFlags_NoRendererClear))
  691. bd->pd3dDevice->ClearRenderTargetView(vd->RTView, (float*)&clear_color);
  692. ImGui_ImplDX10_RenderDrawData(viewport->DrawData);
  693. }
  694. static void ImGui_ImplDX10_SwapBuffers(ImGuiViewport* viewport, void*)
  695. {
  696. ImGui_ImplDX10_ViewportData* vd = (ImGui_ImplDX10_ViewportData*)viewport->RendererUserData;
  697. vd->SwapChain->Present(0, 0); // Present without vsync
  698. }
  699. void ImGui_ImplDX10_InitMultiViewportSupport()
  700. {
  701. ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
  702. platform_io.Renderer_CreateWindow = ImGui_ImplDX10_CreateWindow;
  703. platform_io.Renderer_DestroyWindow = ImGui_ImplDX10_DestroyWindow;
  704. platform_io.Renderer_SetWindowSize = ImGui_ImplDX10_SetWindowSize;
  705. platform_io.Renderer_RenderWindow = ImGui_ImplDX10_RenderViewport;
  706. platform_io.Renderer_SwapBuffers = ImGui_ImplDX10_SwapBuffers;
  707. }
  708. void ImGui_ImplDX10_ShutdownMultiViewportSupport()
  709. {
  710. ImGui::DestroyPlatformWindows();
  711. }
  712. //-----------------------------------------------------------------------------
  713. #endif // #ifndef IMGUI_DISABLE