| 84 | } |
| 85 | |
| 86 | void Initialize(Window& window) |
| 87 | { |
| 88 | window.RegisterMessageCallback(WindowMessageCallback, nullptr); |
| 89 | |
| 90 | ImGuiIO& io = ImGui::GetIO(); |
| 91 | io.KeyMap[ImGuiKey_Tab] = VK_TAB; |
| 92 | io.KeyMap[ImGuiKey_LeftArrow] = VK_LEFT; |
| 93 | io.KeyMap[ImGuiKey_RightArrow] = VK_RIGHT; |
| 94 | io.KeyMap[ImGuiKey_UpArrow] = VK_UP; |
| 95 | io.KeyMap[ImGuiKey_DownArrow] = VK_DOWN; |
| 96 | io.KeyMap[ImGuiKey_PageUp] = VK_PRIOR; |
| 97 | io.KeyMap[ImGuiKey_PageDown] = VK_NEXT; |
| 98 | io.KeyMap[ImGuiKey_Home] = VK_HOME; |
| 99 | io.KeyMap[ImGuiKey_End] = VK_END; |
| 100 | io.KeyMap[ImGuiKey_Delete] = VK_DELETE; |
| 101 | io.KeyMap[ImGuiKey_Backspace] = VK_BACK; |
| 102 | io.KeyMap[ImGuiKey_Enter] = VK_RETURN; |
| 103 | io.KeyMap[ImGuiKey_Escape] = VK_ESCAPE; |
| 104 | io.KeyMap[ImGuiKey_A] = 'A'; |
| 105 | io.KeyMap[ImGuiKey_C] = 'C'; |
| 106 | io.KeyMap[ImGuiKey_V] = 'V'; |
| 107 | io.KeyMap[ImGuiKey_X] = 'X'; |
| 108 | io.KeyMap[ImGuiKey_Y] = 'Y'; |
| 109 | io.KeyMap[ImGuiKey_Z] = 'Z'; |
| 110 | |
| 111 | io.RenderDrawListsFn = nullptr; |
| 112 | io.ImeWindowHandle = window.GetHwnd(); |
| 113 | |
| 114 | const std::wstring shaderPath = SampleFrameworkDir() + L"Shaders\\ImGui.hlsl"; |
| 115 | VS = CompileFromFile(shaderPath.c_str(), "ImGuiVS", ShaderType::Vertex, ShaderProfile::SM51); |
| 116 | PS = CompileFromFile(shaderPath.c_str(), "ImGuiPS", ShaderType::Pixel, ShaderProfile::SM51); |
| 117 | |
| 118 | CBuffer.Initialize(BufferLifetime::Temporary); |
| 119 | |
| 120 | unsigned char* pixels = nullptr; |
| 121 | int32 texWidth = 0; |
| 122 | int32 texHeight = 0; |
| 123 | io.Fonts->GetTexDataAsRGBA32(&pixels, &texWidth, &texHeight); |
| 124 | |
| 125 | Create2DTexture(FontTexture, texWidth, texHeight, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM, false, pixels); |
| 126 | io.Fonts->TexID = &FontTexture; |
| 127 | |
| 128 | { |
| 129 | D3D12_DESCRIPTOR_RANGE ranges[1] = {}; |
| 130 | ranges[0].RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV; |
| 131 | ranges[0].NumDescriptors = 1; |
| 132 | ranges[0].BaseShaderRegister = 0; |
| 133 | ranges[0].RegisterSpace = 0; |
| 134 | ranges[0].OffsetInDescriptorsFromTableStart = 0; |
| 135 | |
| 136 | D3D12_ROOT_PARAMETER rootParameters[2] = {}; |
| 137 | rootParameters[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE; |
| 138 | rootParameters[0].ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL; |
| 139 | rootParameters[0].DescriptorTable.pDescriptorRanges = ranges; |
| 140 | rootParameters[0].DescriptorTable.NumDescriptorRanges = 1; |
| 141 | |
| 142 | rootParameters[1].ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV; |
| 143 | rootParameters[1].ShaderVisibility = D3D12_SHADER_VISIBILITY_VERTEX; |
no test coverage detected