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

Function ImGui_ImplDX11_CreateFontsTexture

KBotExt/imgui/imgui_impl_dx11.cpp:308–368  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

306}
307
308static void ImGui_ImplDX11_CreateFontsTexture()
309{
310 // Build texture atlas
311 ImGuiIO& io = ImGui::GetIO();
312 ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData();
313 unsigned char* pixels;
314 int width, height;
315 io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
316
317 // Upload texture to graphics system
318 {
319 D3D11_TEXTURE2D_DESC desc;
320 ZeroMemory(&desc, sizeof(desc));
321 desc.Width = width;
322 desc.Height = height;
323 desc.MipLevels = 1;
324 desc.ArraySize = 1;
325 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
326 desc.SampleDesc.Count = 1;
327 desc.Usage = D3D11_USAGE_DEFAULT;
328 desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
329 desc.CPUAccessFlags = 0;
330
331 ID3D11Texture2D* pTexture = nullptr;
332 D3D11_SUBRESOURCE_DATA subResource;
333 subResource.pSysMem = pixels;
334 subResource.SysMemPitch = desc.Width * 4;
335 subResource.SysMemSlicePitch = 0;
336 bd->pd3dDevice->CreateTexture2D(&desc, &subResource, &pTexture);
337 IM_ASSERT(pTexture != nullptr);
338
339 // Create texture view
340 D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
341 ZeroMemory(&srvDesc, sizeof(srvDesc));
342 srvDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
343 srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
344 srvDesc.Texture2D.MipLevels = desc.MipLevels;
345 srvDesc.Texture2D.MostDetailedMip = 0;
346 bd->pd3dDevice->CreateShaderResourceView(pTexture, &srvDesc, &bd->pFontTextureView);
347 pTexture->Release();
348 }
349
350 // Store our identifier
351 io.Fonts->SetTexID((ImTextureID)bd->pFontTextureView);
352
353 // Create texture sampler
354 // (Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling)
355 {
356 D3D11_SAMPLER_DESC desc;
357 ZeroMemory(&desc, sizeof(desc));
358 desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
359 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
360 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
361 desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
362 desc.MipLODBias = 0.f;
363 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
364 desc.MinLOD = 0.f;
365 desc.MaxLOD = 0.f;

Callers 1

Calls 3

GetTexDataAsRGBA32Method · 0.80
SetTexIDMethod · 0.80

Tested by

no test coverage detected