MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / ImGui_ImplDX11_CreateDeviceObjects

Function ImGui_ImplDX11_CreateDeviceObjects

KBotExt/imgui/imgui_impl_dx11.cpp:370–522  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

368}
369
370bool ImGui_ImplDX11_CreateDeviceObjects()
371{
372 ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData();
373 if (!bd->pd3dDevice)
374 return false;
375 if (bd->pFontSampler)
376 ImGui_ImplDX11_InvalidateDeviceObjects();
377
378 // By using D3DCompile() from <d3dcompiler.h> / d3dcompiler.lib, we introduce a dependency to a given version of d3dcompiler_XX.dll (see D3DCOMPILER_DLL_A)
379 // If you would like to use this DX11 sample code but remove this dependency you can:
380 // 1) compile once, save the compiled shader blobs into a file or source code and pass them to CreateVertexShader()/CreatePixelShader() [preferred solution]
381 // 2) use code to detect any version of the DLL and grab a pointer to D3DCompile from the DLL.
382 // See https://github.com/ocornut/imgui/pull/638 for sources and details.
383
384 // Create the vertex shader
385 {
386 static const char* vertexShader =
387 "cbuffer vertexBuffer : register(b0) \
388 {\
389 float4x4 ProjectionMatrix; \
390 };\
391 struct VS_INPUT\
392 {\
393 float2 pos : POSITION;\
394 float4 col : COLOR0;\
395 float2 uv : TEXCOORD0;\
396 };\
397 \
398 struct PS_INPUT\
399 {\
400 float4 pos : SV_POSITION;\
401 float4 col : COLOR0;\
402 float2 uv : TEXCOORD0;\
403 };\
404 \
405 PS_INPUT main(VS_INPUT input)\
406 {\
407 PS_INPUT output;\
408 output.pos = mul( ProjectionMatrix, float4(input.pos.xy, 0.f, 1.f));\
409 output.col = input.col;\
410 output.uv = input.uv;\
411 return output;\
412 }";
413
414 ID3DBlob* vertexShaderBlob;
415 if (FAILED(D3DCompile(vertexShader, strlen(vertexShader), nullptr, nullptr, nullptr, "main", "vs_4_0", 0, 0, &vertexShaderBlob, nullptr)))
416 return false; // NB: Pass ID3DBlob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob!
417 if (bd->pd3dDevice->CreateVertexShader(vertexShaderBlob->GetBufferPointer(), vertexShaderBlob->GetBufferSize(), nullptr, &bd->pVertexShader) != S_OK)
418 {
419 vertexShaderBlob->Release();
420 return false;
421 }
422
423 // Create the input layout
424 D3D11_INPUT_ELEMENT_DESC local_layout[] =
425 {
426 { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (UINT)IM_OFFSETOF(ImDrawVert, pos), D3D11_INPUT_PER_VERTEX_DATA, 0 },
427 { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (UINT)IM_OFFSETOF(ImDrawVert, uv), D3D11_INPUT_PER_VERTEX_DATA, 0 },

Callers 1

ImGui_ImplDX11_NewFrameFunction · 0.85

Tested by

no test coverage detected