Skip to content

Commit 51d994e

Browse files
committed
ResourceManager: Texture loading finished
1 parent 8a8c5b8 commit 51d994e

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/private/Core/GameObject/Component/Mesh.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ void Mesh::LoadModel(std::string filename) {
7979
if (material->GetTextureCount(aiTextureType_DIFFUSE) > 0 && material->GetTexture(aiTextureType_DIFFUSE, 0, &texPath) == AI_SUCCESS) {
8080
const aiTexture* texture = scene->GetEmbeddedTexture(texPath.C_Str());
8181
ResourceManager* resMgr = ResourceManager::GetInstance();
82-
resMgr->LoadTexture((BYTE*)texture->pcData, texture->mWidth, nullptr);
82+
ComPtr<ID3D12Resource> resource;
83+
resMgr->LoadTexture((BYTE*)texture->pcData, texture->mWidth, resource.GetAddressOf());
84+
85+
std::cout << "ASD" << std::endl;
8386
}
8487
}
8588
}

src/private/Core/Renderer/ResourceManager.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,37 @@ void ResourceManager::LoadTexture(const uint8_t* pData, DWORD dwDataSize, ID3D12
335335
ThrowIfFailed(FC->Initialize(frame.Get(), convertGUID, WICBitmapDitherTypeErrorDiffusion, nullptr, 0, WICBitmapPaletteTypeMedianCut));
336336
ThrowIfFailed(FC->CopyPixels(nullptr, static_cast<UINT>(rowPitch), static_cast<UINT>(imageSize), decodedData.get()));
337337
}
338+
339+
/* Count the number of mips */
340+
const uint32_t mipCount = 1u; // TODO: Calculate.
341+
342+
D3D12_RESOURCE_DESC resDesc = { };
343+
resDesc.Width = width;
344+
resDesc.Height = height;
345+
resDesc.MipLevels = static_cast<UINT16>(mipCount);
346+
resDesc.DepthOrArraySize = 1;
347+
resDesc.Format = format;
348+
resDesc.SampleDesc.Count = 1;
349+
resDesc.Flags = D3D12_RESOURCE_FLAG_NONE;
350+
resDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
351+
352+
D3D12_HEAP_PROPERTIES heapProps = { };
353+
heapProps.Type = D3D12_HEAP_TYPE_DEFAULT;
354+
355+
ComPtr<ID3D12Resource> tex;
356+
ThrowIfFailed(this->m_dev->CreateCommittedResource(
357+
&heapProps, D3D12_HEAP_FLAG_NONE,
358+
&resDesc,
359+
D3D12_RESOURCE_STATE_COPY_DEST,
360+
nullptr,
361+
IID_PPV_ARGS(tex.GetAddressOf())
362+
));
363+
364+
initData.pData = decodedData.get();
365+
initData.RowPitch = static_cast<LONG>(rowPitch);
366+
initData.SlicePitch = static_cast<LONG>(imageSize);
367+
368+
*resource = tex.Get();
338369
}
339370

340371
ResourceManager* ResourceManager::GetInstance() {

0 commit comments

Comments
 (0)