Skip to content

Commit

Permalink
Hydrogent: load textures as 2D array as expected by PBR renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Sep 16, 2023
1 parent 3d2b1bb commit caaad88
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
10 changes: 7 additions & 3 deletions Hydrogent/src/HnMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ void HnMaterial::UpdateSRB(IRenderDevice* pDevice,
if (pTexHandle->pTexture)
{
const auto& TexDesc = pTexHandle->pTexture->GetDesc();
if (TexDesc.Type == RESOURCE_DIM_TEX_2D_ARRAY)
pTexSRV = pTexHandle->pTexture->GetDefaultView(TEXTURE_VIEW_SHADER_RESOURCE);
else
if (TexDesc.Type == RESOURCE_DIM_TEX_2D)
{
UNEXPECTED("2D textures should be loaded as single-slice 2D array textures");

const auto Name = std::string{"Tex2DArray view of texture '"} + TexDesc.Name + "'";

TextureViewDesc SRVDesc;
Expand All @@ -197,6 +197,10 @@ void HnMaterial::UpdateSRB(IRenderDevice* pDevice,

pTexSRV->SetSampler(pTexHandle->pSampler);
}
else
{
pTexSRV = pTexHandle->pTexture->GetDefaultView(TEXTURE_VIEW_SHADER_RESOURCE);
}
}
}

Expand Down
16 changes: 15 additions & 1 deletion Hydrogent/src/HnTextureRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,20 @@ HnTextureRegistry::~HnTextureRegistry()
static void InitializeHandle(IRenderDevice* pDevice, ITextureLoader* pLoader, const SamplerDesc& SamDesc, HnTextureRegistry::TextureHandle& Handle)
{
VERIFY_EXPR(!Handle.pTexture);
pLoader->CreateTexture(pDevice, &Handle.pTexture);
if (pLoader->GetTextureDesc().Type == RESOURCE_DIM_TEX_2D)
{
auto TexDesc = pLoader->GetTextureDesc();
// PBR Renderer expects 2D textures to be 2D array textures
TexDesc.Type = RESOURCE_DIM_TEX_2D_ARRAY;
TexDesc.ArraySize = 1;

TextureData InitData = pLoader->GetTextureData();
pDevice->CreateTexture(TexDesc, &InitData, &Handle.pTexture);
}
else
{
pLoader->CreateTexture(pDevice, &Handle.pTexture);
}
if (!Handle.pTexture)
return;

Expand All @@ -64,6 +77,7 @@ void HnTextureRegistry::Commit(IDeviceContext* pContext)
{
InitializeHandle(m_pDevice, tex_it.second.pLoader, tex_it.second.SamDesc, *tex_it.second.Handle);
}
m_PendingTextures.clear();
}

HnTextureRegistry::TextureHandleSharedPtr HnTextureRegistry::Allocate(const HnTextureIdentifier& TexId,
Expand Down

0 comments on commit caaad88

Please sign in to comment.