Last active
September 28, 2017 12:47
-
-
Save shaderjp/15df605e428a464852b786857b0d6839 to your computer and use it in GitHub Desktop.
DirectXTexのDDSロードサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load texture from DDS. | |
{ | |
std::unique_ptr<uint8_t[]> ddsData; | |
std::vector<D3D12_SUBRESOURCE_DATA> subresouceData; | |
ThrowIfFailed(LoadDDSTextureFromFile(m_device.Get(), | |
L"test.DDS", | |
&m_texture, | |
ddsData, | |
subresouceData)); | |
D3D12_RESOURCE_DESC textureDesc = m_texture->GetDesc(); | |
const UINT subresoucesize | |
= static_cast<UINT>(subresouceData.size()); | |
const UINT64 uploadBufferSize | |
= GetRequiredIntermediateSize(m_texture.Get(), 0, subresoucesize); | |
// Create the GPU upload buffer. | |
ThrowIfFailed(m_device->CreateCommittedResource( | |
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD), | |
D3D12_HEAP_FLAG_NONE, | |
&CD3DX12_RESOURCE_DESC::Buffer(uploadBufferSize), | |
D3D12_RESOURCE_STATE_GENERIC_READ, | |
nullptr, | |
IID_PPV_ARGS(&textureUploadHeap))); | |
UpdateSubresources(m_commandList.Get(), | |
m_texture.Get(), | |
textureUploadHeap.Get(), | |
0, | |
0, | |
subresoucesize, | |
&subresouceData[0]); | |
m_commandList->ResourceBarrier(1, | |
&CD3DX12_RESOURCE_BARRIER::Transition(m_texture.Get(), | |
D3D12_RESOURCE_STATE_COPY_DEST, | |
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE)); | |
// Describe and create a SRV for the texture. | |
D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {}; | |
srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; | |
srvDesc.Format = textureDesc.Format; | |
srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; | |
srvDesc.Texture2D.MipLevels = subresoucesize; | |
m_device->CreateShaderResourceView(m_texture.Get(), | |
&srvDesc, | |
m_srvHeap->GetCPUDescriptorHandleForHeapStart()); | |
m_commandList->DiscardResource(textureUploadHeap.Get(), nullptr); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment