本文整理汇总了C++中MaterialManager::AddResource方法的典型用法代码示例。如果您正苦于以下问题:C++ MaterialManager::AddResource方法的具体用法?C++ MaterialManager::AddResource怎么用?C++ MaterialManager::AddResource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MaterialManager
的用法示例。
在下文中一共展示了MaterialManager::AddResource方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateMaterials
void FbxRender::CreateMaterials(MaterialManager& materialMgr)
{
std::vector<StandardMaterial> materialsVector;
int defaultIdx = 0;
// Try to use a default texture,
// when we are unable to load a texture.
for (unsigned int i = 0; i < materialMgr.GetTextureResource().size(); i++)
{
if (materialMgr.GetTextureResource()[i].name == "Default")
{
defaultIdx = i;
break;
}
}
for (unsigned int matIdx = 0; matIdx < m_fbxLoader.m_MaterialList.size(); matIdx++)
{
StandardMaterial material;
// Use reinterpret_cast to load data for a material type.
StandardMaterial* pConveter = reinterpret_cast<StandardMaterial*>(m_fbxLoader.m_MaterialList[matIdx].rawData);
unsigned int texIdx = pConveter->albedoMapIdx;
if (texIdx < m_fbxLoader.m_TextureList.size())
{
ComPtr<ID3D12Resource> Texture;
std::string path = m_fbxLoader.m_TextureList[texIdx].name;
if (path.size() > 10)
{
bool repeatTexture = false;
// Search the textures in the material manager.
for (unsigned int i = 0; i < materialMgr.GetTextureResource().size(); i++)
{
if (materialMgr.GetTextureResource()[i].name == path)
{
repeatTexture = true;
texIdx = i;
break;
}
}
// Create a new texture resource, if we don't find the same one in the material manager.
if (!repeatTexture)
{
HRESULT hr = CreateWICTextureFromFileEx(g_d3dObjects->GetD3DDevice(), std::wstring(path.begin(), path.end()).c_str(), 0, 0, 0, 0, 0, &Texture);
materialMgr.AddResource(Texture, path);
texIdx = materialMgr.GetTextureResource().size() - 1;
}
}
else {
// This filename is invalid.
texIdx = defaultIdx;
}
}
else {
// No any texture in the FBX model.
texIdx = defaultIdx;
}
// Store the material data into this manager.
material.albedoColor = pConveter->albedoColor;
material.specularColor = pConveter->specularColor;
material.albedoMapIdx = texIdx;
materialsVector.push_back(material);
}
if (materialsVector.size())
{
// Create a material buffer.
ComPtr<ID3D12Resource> materialBuffer;
CD3DX12_HEAP_PROPERTIES heapProperty(D3D12_HEAP_TYPE_UPLOAD);
D3D12_RESOURCE_DESC resourceDesc;
ZeroMemory(&resourceDesc, sizeof(resourceDesc));
resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
resourceDesc.Alignment = 0;
resourceDesc.SampleDesc.Count = 1;
resourceDesc.SampleDesc.Quality = 0;
resourceDesc.MipLevels = 1;
resourceDesc.Format = DXGI_FORMAT_UNKNOWN;
resourceDesc.DepthOrArraySize = 1;
resourceDesc.Height = 1;
resourceDesc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
resourceDesc.Width = sizeof(materialsVector[0])*materialsVector.size();
ThrowIfFailed(g_d3dObjects->GetD3DDevice()->CreateCommittedResource(&heapProperty, D3D12_HEAP_FLAG_NONE, &resourceDesc, D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(materialBuffer.GetAddressOf())));
void* mapped = nullptr;
materialBuffer->Map(0, nullptr, &mapped);
memcpy(mapped, &materialsVector[0], sizeof(materialsVector[0])*materialsVector.size());
materialBuffer->Unmap(0, nullptr);
materialMgr.UpdateMaterialBuffer(materialBuffer, materialsVector.size(), sizeof(materialsVector[0]));
}
}