MCPcopy Create free account
hub / github.com/DiligentGraphics/DiligentFX / InitializeHandle

Method InitializeHandle

Hydrogent/src/HnTextureRegistry.cpp:54–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52}
53
54void HnTextureRegistry::InitializeHandle(IRenderDevice* pDevice,
55 IDeviceContext* pContext,
56 ITextureLoader* pLoader,
57 const SamplerDesc& SamDesc,
58 TextureHandle& Handle)
59{
60 if (Handle.pAtlasSuballocation != nullptr)
61 {
62 VERIFY_EXPR(pContext != nullptr);
63
64 IDynamicTextureAtlas* pAtlas = Handle.pAtlasSuballocation->GetAtlas();
65 ITexture* pDstTex = pAtlas->GetTexture();
66 const TextureDesc& AtlasDesc = pAtlas->GetAtlasDesc();
67 const TextureData UploadData = pLoader->GetTextureData();
68 const TextureDesc& SrcDataDesc = pLoader->GetTextureDesc();
69 const uint2& Origin = Handle.pAtlasSuballocation->GetOrigin();
70 const Uint32 Slice = Handle.pAtlasSuballocation->GetSlice();
71
72 const Uint32 MipsToUpload = std::min(UploadData.NumSubresources, AtlasDesc.MipLevels);
73 for (Uint32 mip = 0; mip < MipsToUpload; ++mip)
74 {
75 const TextureSubResData& LevelData = UploadData.pSubResources[mip];
76 const MipLevelProperties MipProps = GetMipLevelProperties(SrcDataDesc, mip);
77
78 Box UpdateBox;
79 UpdateBox.MinX = Origin.x >> mip;
80 UpdateBox.MaxX = UpdateBox.MinX + MipProps.LogicalWidth;
81 UpdateBox.MinY = Origin.y >> mip;
82 UpdateBox.MaxY = UpdateBox.MinY + MipProps.LogicalHeight;
83 pContext->UpdateTexture(pDstTex, mip, Slice, UpdateBox, LevelData, RESOURCE_STATE_TRANSITION_MODE_NONE, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
84 }
85 }
86 else
87 {
88 if (!Handle)
89 {
90 if (pLoader->GetTextureDesc().Type == RESOURCE_DIM_TEX_2D)
91 {
92 auto TexDesc = pLoader->GetTextureDesc();
93 // PBR Renderer expects 2D textures to be 2D array textures
94 TexDesc.Type = RESOURCE_DIM_TEX_2D_ARRAY;
95 TexDesc.ArraySize = 1;
96
97 TextureData InitData = pLoader->GetTextureData();
98 pDevice->CreateTexture(TexDesc, &InitData, &Handle.pTexture);
99 }
100 else
101 {
102 pLoader->CreateTexture(pDevice, &Handle.pTexture);
103 }
104 if (!Handle.pTexture)
105 {
106 UNEXPECTED("Failed to create texture");
107 return;
108 }
109
110 pDevice->CreateSampler(SamDesc, &Handle.pSampler);
111 VERIFY_EXPR(Handle.pSampler);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected