์์ :)
https://github.com/eazuooz/YamYamEngine/commit/ed27ddb9e49182c3dcf4b307336018a5376704f5
Texture · eazuooz/YamYamEngine@ed27ddb
Show file tree Showing 38 changed files with 1,505 additions and 322 deletions.
github.com
ํ ์ค์ฒ๋ ๋ค๋ฅธ ์์๊ณผ ๋ง์ฐฌ๊ฐ์ง๋ก ๋ ๋๋ง ํ์ดํ๋ผ์ธ์์ [๋ทฐ]๋ฅผ ํตํด ์์ธ์ค ๋๋ค.
[๋ทฐ]๋ [ํ ์ค์ฒ ๋ฆฌ์์ค]๊ฐ ๋ ๋๋ง ํ์ดํ๋ผ์ธ์ผ๋ก๋ถํฐ ์ด๋ ํ ๋ฐ์ดํฐ๋ก ๋ณด์ด๊ฒ ํ ๊ฒ์ธ๊ฐ๋ฅผ ์ ์ํ๋ค.
ํ ์ค์ฒ๋ฅผ ๋ค๋ฃจ๋ ๊ธฐ๋ณธ์ ์ธ ์์๋
ํ ์ค์ฒ ๋ฆฌ์์ค ์์ฑ -> ํ ์ค์ฒ ์ด๋ฏธ์ง ๋ก๋ -> ํ ์ค์ฒ์ ์์ธ์ค ํ๋ ๋ทฐ ์์ฑ
์ฐ๋ฆฌ๋ ์ด๋ฏธ์ง๋ก๋๋ฅผ ํ๊ธฐ ์ํด์ DirectX์์ ์ ๊ณต๋๋ ๋ก๋ํจ์๋์ ์ DirectXTex๋ผ๋ ์ด๋ฏธ์ง ๋ก๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ๋ค. png, bmp, jpg๋ฑ๋ฑ ๋ค์ํ ์ด๋ฏธ์ง ํ์ฅ์ ๋ก๋๋ฅผ ์ ๊ณตํด์ฃผ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ด๋ค.
์ฐ๋ฆฌ์ ํ ์ค์ฒ ํด๋์ค๋ ๋ค์๊ณผ ๊ฐ์ด ๊ตฌ์ฑ๋ ๊ฒ์ด๋ค.
class Texture : public Resource
{
public:
Texture();
~Texture();
HRESULT Load(const std::wstring& path) override;
void BindShader(eShaderStage stage, UINT startSlot);
private:
ScratchImage mImage;
Microsoft::WRL::ComPtr<ID3D11Texture2D> mTexture;
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> mSRV;
D3D11_TEXTURE2D_DESC mDesc;
};
ScrachImage๋ ์ด๋ฏธ์ง๋ฅผ ๋ก๋ํด์ ๋ณด๊ดํด๋๋ ์ฉ๋๋ก ์ฌ์ฉ์ด๋๊ณ Texture2D์ ํ ์ค์ฒ ๋ฆฌ์์ค๋ฅผ ๊ฐ์ ธ์์ ๋ณด๊ดํด๋๊ฒ์ด๋ค. ๊ทธ๋ฆฌ๊ณ ๋ง์ง๋ง์ผ๋ก ID3D11ShaderResourceView์ ํ ์ค์ฒ ๋ฆฌ์์ค์ ์์ธ์คํ ์์๋ ๋ทฐ๋ฅผ ์์ฑํ ๊ฒ์ด๋ค.
HRESULT __cdecl CreateShaderResourceView(
_In_ ID3D11Device* pDevice
, _In_reads_(nimages) const Image* srcImages
, _In_ size_t nimages
, _In_ const TexMetadata& metadata,
_Outptr_ ID3D11ShaderResourceView** ppSRV) noexcept;
CreateShaderResourceView ๋ทฐ๋ ์ ฐ์ด๋ ๋ฆฌ์์ค๋ทฐ๋ฅผ ์์ฑํจ๊ณผ ๋์์ ๋ฆฌ์์ค๋ ๊ฐ์ด ์์ฑํ๋ค.
๋ฆฌ์์ค๋ทฐ์ ํ ๋น๋ ๋ฆฌ์์ค๋ฅผ ๊ฐ์ ธ์ฌ๋๋
mSRV->GetResource((ID3D11Resource**)mTexture.GetAddressOf());
ํด๋น ๋ฆฌ์์ค๋ทฐ์์ GetResourceํจ์๋ฅผ ํตํด์ ๋ฆฌ์์ค๋ฅผ ๊ฐ์ ธ์ฌ์ ์๋ค.
ํด๋น ๋ฆฌ์์ค๋ฅผ ์ ฐ์ด๋์์ ์ฌ์ฉํ๋ ค๋ฉด ์ ฐ์ด๋์ ์ธํ ํด์ฃผ์ด์ผ ํ๋ค.
void GraphicsDevice_DX11::SetShaderResource(eShaderStage stage, UINT startSlot, ID3D11ShaderResourceView** ppSRV)
{
if ((UINT)eShaderStage::VS & (UINT)stage)
mContext->VSSetShaderResources(startSlot, 1, ppSRV);
if ((UINT)eShaderStage::HS & (UINT)stage)
mContext->HSSetShaderResources(startSlot, 1, ppSRV);
if ((UINT)eShaderStage::DS & (UINT)stage)
mContext->DSSetShaderResources(startSlot, 1, ppSRV);
if ((UINT)eShaderStage::GS & (UINT)stage)
mContext->GSSetShaderResources(startSlot, 1, ppSRV);
if ((UINT)eShaderStage::PS & (UINT)stage)
mContext->PSSetShaderResources(startSlot, 1, ppSRV);
}
// HLSL
struct VTX_OUT
{
float4 vPos : SV_Position;
float4 vColor : COLOR;
float2 vUV : TEXCOORD;
};
Texture2D triangleTexture : register(t0);
SamplerState samplerState : register(s0);
float4 PS_Test(VTX_OUT _in) : SV_Target
{
float4 color = (float) 0.0f;
color = triangleTexture.Sample(samplerState, _in.vUV);
return color;
}
ํ ์ค์ฒ ๋ฆฌ์์ค๋ ๊ธฐ๋ณธ์ ์ผ๋ก Release ์์ผ์ค ํ์๋ ์๋ค. (๋จ GetResource๋ก ์ป์ด์จ ์ธํฐํ์ด์ค๋ Release ์์ผ์ฃผ์ด์ผ ํ๋ค.
์ถ๊ฐ์ ์ผ๋ก ๋ ๋ํ๊ฒ, CPU์์ ์ฌ์ฉ ํ ์ ์๋ ํ ์ค์ฒ๋ ์์ฑ์ด ๊ฐ๋ฅํ๋ค. ์ด๊ฑด ์ถํ์ ์ฌ์ฉํด๋ณด๋๋ก ํ๊ฒ ๋ค.
'๐ Development Study > ๐ผ GameProgramming 2D' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Material ๋ฉํ ๋ฆฌ์ผ (0) | 2023.01.02 |
---|---|
Sampler ์ํ๋ฌ (0) | 2023.01.02 |
Scene, GameObject, Component (0) | 2022.12.21 |
Mesh, MeshRenderer (0) | 2022.12.21 |
Constant Buffer(์์ ๋ฒํผ), Index Buffer(์ธ๋ฑ์ค ๋ฒํผ) (1) | 2022.12.08 |
๋๊ธ