◤ 2022๋…„ 7์›” 29์ผ ๊ธˆ์š”์ผ

● DirectXTex ์‚ฌ์šฉ

※ ์ง€๊ทนํžˆ ๊ฐœ์ธ์ ์ธ ์ผ์ƒ ๋ฉ”๋ชจ์™€ ๊ธฐ๋ก์„ ์œ„ํ•œ ๊ณณ์ž…๋‹ˆ๋‹ค.







๊นƒํ—ˆ๋ธŒ์— ๊ณต๊ฐœ๋œ ์†Œ์Šค๋ฅผ ๋‹ค์šด ๋ฐ›์•„ ์ด์šฉํ•œ๋‹ค
github.com/microsoft/directxtex ์ ‘์†ํ•˜์—ฌ ์ฝ”๋“œํŒŒ์ผ์„ ZIP์œผ๋กœ ๋‹ค์šด๋กœ๋“œ ํ•œ๋‹ค.



์••์ถ•์„ ํ’€๊ณ  DirectXTex_Desktop_2022.sln ์†”๋ฃจ์…˜ ํŒŒ์ผ์„ ๋น„์ฃผ์–ผ ์ŠคํŠœ๋””์˜ค๋กœ ์—ด๊ณ  ๋นŒ๋“œ๋ฅผ ํ•ด์ค€๋‹ค.




๋นŒ๋“œ๊ฐ€ ์ž˜ ๋๋‚˜๋ฉด ์œ„์˜ ํด๋”์—์„œ DirectXTex.lib ํŒŒ์ผ์„ ์ด์šฉ์„ ํ•  ๊ฑด๋ฐ..
 




์—ฌ๊ธฐ์— ๋ณต์‚ฌ๋ฅผ ํ•ด์ฃผ๊ณ 



ํ—ค๋” ํŒŒ์ผ์„ ๋ณต์‚ฌํ•ด์„œ..




Include ํด๋”๋ฅผ ๋งŒ๋“ค์–ด์„œ ๋ณต์‚ฌํ•ด ์ฃผ์—ˆ๋‹ค


์—”์ง„ ์†์„ฑ์—์„œ DLL๊ณผ LIB ํŒŒ์ผ์„ ๋ถˆ์–ด์˜ฌ ํŒŒ์ผ์„ ์„ค์ •ํ•ด์ฃผ๊ณ ..



ํด๋” ๊ฒฝ๋กœ ์„ค์ •๋„ ํ•ด์ค€๋‹ค



์†์„ฑ์—์„œ C/C++์€ ํ—ค๋” ํŒŒ์ผ์„ ์—ฐ๊ฒฐ, ํฌํ•จํ•ด์ค„ ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฅผ ์„ค์ •ํ•ด ์ค€๋‹ค




C/C++ ์„ค์ •์€ ํ—ค๋”ํŒŒ์ผ, ๋ง์ปค๋Š” dll. lib ์—ฐ๊ฒฐ ์„ค์ •.










ํ”„๋กœ์ ํŠธ์— ํฌํ•จ ์‹œํ‚ฌ ๋•Œ๋Š” ๋งˆ์šฐ์Šค๋กœ ํŒŒ์ผ์„ ๋Œ์–ด๋‹ค๊ฐ€ ๋น„์ฃผ์–ผ ์ŠคํŠœ๋””์˜ค ํด๋” ํŠธ๋ฆฌ ์ฐฝ์— ๋“œ๋ž˜๊ทธ&๋“œ๋กญ๋„ ๊ฐ€๋Šฅํ•˜๋‹ค.



ํ…์Šค์ณ ํŒŒ์ผ์„ ์ด์šฉํ•˜๊ธฐ ์œ„ํ•œ ID3D11ShaderResourceView ์ด์šฉ์„ ํ•  ์ˆ˜ ์žˆ๋‹ค.



์ฝ”๋“œ ์˜ˆ์ œ.

//by JSHong CodeBlock//
#include "Core.h"
#include "TextureLoader.h"
#include <DirectXTex.h>
#include <Utility/STLException.h>

namespace STL
{
std::unordered_map<std::wstring, ID3D11ShaderResourceView*> TextureLoader::textureMap;

ID3D11ShaderResourceView* TextureLoader::CreateShaderResourceView(ID3D11Device* device, const std::wstring& filename)
{
auto search = textureMap.find(filename);
if (search != textureMap.end())
{
return search->second;
}

std::wstring extension = filename.substr(filename.find_last_of(TEXT(".")) + 1);
std::transform(extension.begin(), extension.end(), extension.begin(), tolower);

static auto basePath = std::filesystem::current_path().parent_path();

auto finalPath = basePath;
finalPath /= "Content\\Textures";
finalPath /= filename;

DirectX::ScratchImage image;
HRESULT hr = E_FAIL;
if (extension == TEXT("tga") || extension == TEXT("targa"))
{
hr = DirectX::LoadFromTGAFile(
finalPath.c_str(),
nullptr,
image
);
}
else
{
hr = DirectX::LoadFromWICFile(
finalPath.c_str(),
DirectX::WIC_FLAGS_NONE,
nullptr,
image
);
}

ThrowIfFailed(hr, "Failed to load scratch image.");

ID3D11Texture2D* texture = nullptr;
hr = DirectX::CreateTexture(
device,
image.GetImages(),
image.GetImageCount(),
image.GetMetadata(),
reinterpret_cast<ID3D11Resource**>(&texture)
);

ThrowIfFailed(hr, "Failed to create texture.");

D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
memset(&srvDesc, 0, sizeof(srvDesc));
srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
srvDesc.Texture2D.MipLevels = 1;
srvDesc.Format = image.GetMetadata().format;

ID3D11ShaderResourceView* shaderResourceView = nullptr;
hr = device->CreateShaderResourceView(
texture,
&srvDesc,
&shaderResourceView
);

SafeRelease(texture);
ThrowIfFailed(hr, "Failed to shader resource view.");

textureMap.insert({ filename, shaderResourceView });

return shaderResourceView;
}

void TextureLoader::Release()
{
for (auto pair : textureMap)
{
SafeRelease(pair.second);
}
}
}


# ์…ฐ์ด๋” ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์ž…๋ฌธ ์ฑ… (http://www.yes24.com/Product/Goods/7366949)



0 comments:

๋Œ“๊ธ€ ์“ฐ๊ธฐ