Add input layout

This commit is contained in:
2026-11-27 11:27:52 +01:00
parent 204c55e915
commit ead7463b8e
6 changed files with 81 additions and 33 deletions
+67 -20
View File
@@ -6,39 +6,57 @@
UINT Material::init(ID3D11Device* pD3DDevice, LPCTSTR textureFileName)
{
HRESULT hr = DirectX::CreateWICTextureFromFile(pD3DDevice, textureFileName, &_pTexture, 0, DirectX::WIC_LOADER_MIP_AUTOGEN);
CheckFailed(hr, 600);
//HRESULT hr = DirectX::CreateWICTextureFromFile(pD3DDevice, textureFileName, &_pTexture, 0, DirectX::WIC_LOADER_MIP_AUTOGEN);
//CheckFailed(hr, 600);
UINT error = 0;
error = createVertexShader(pD3DDevice);
CheckError(error);
error = createPixelShader(pD3DDevice);
CheckError(error);
return 0;
}
void Material::render(ID3D11DeviceContext* pD3DDeviceContext)
{
// set texture
pD3DDevice->SetTexture(0, _pTexture);
//// set texture
//pD3DDevice->SetTexture(0, _pTexture);
// set sampler state
pD3DDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
pD3DDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
pD3DDevice->SetSamplerState(0, D3DSAMP_BORDERCOLOR, D3DCOLOR_XRGB(200, 0, 200));
pD3DDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
pD3DDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
pD3DDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
pD3DDevice->SetSamplerState(0, D3DSAMP_MAXMIPLEVEL, 0);
//// set sampler state
//pD3DDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
//pD3DDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
//pD3DDevice->SetSamplerState(0, D3DSAMP_BORDERCOLOR, D3DCOLOR_XRGB(200, 0, 200));
//pD3DDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
//pD3DDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
//pD3DDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
//pD3DDevice->SetSamplerState(0, D3DSAMP_MAXMIPLEVEL, 0);
// set material
D3DMATERIAL9 material = {};
material.Diffuse = { 1.0f, 1.0f, 1.0f, 1.0f };
material.Specular = { 1.0f, 1.0f, 1.0f, 1.0f };
material.Power = 100.0f;
material.Ambient = { 1.0f, 1.0f, 1.0f, 1.0f };
material.Emissive = { 0.0f, 0.0f, 0.0f, 1.0f };
//// set material
//D3DMATERIAL9 material = {};
//material.Diffuse = { 1.0f, 1.0f, 1.0f, 1.0f };
//material.Specular = { 1.0f, 1.0f, 1.0f, 1.0f };
//material.Power = 100.0f;
//material.Ambient = { 1.0f, 1.0f, 1.0f, 1.0f };
//material.Emissive = { 0.0f, 0.0f, 0.0f, 1.0f };
pD3DDevice->SetMaterial(&material);
//pD3DDevice->SetMaterial(&material);
// set shaders
pD3DDeviceContext->VSSetShader(_pVertexShader, nullptr, 0);
pD3DDeviceContext->PSSetShader(_pPixelShader, nullptr, 0);
// set input layoyt
pD3DDeviceContext->IASetInputLayout(_pInputLayout);
}
void Material::deInit()
{
safeRelease(_pInputLayout);
safeRelease(_pPixelShader);
safeRelease(_pVertexShader);
}
UINT Material::createVertexShader(ID3D11Device* pD3DDevice)
@@ -100,5 +118,34 @@ UINT Material::createPixelShader(ID3D11Device* pD3DDevice)
UINT Material::createInputLayout(ID3D11Device* pD3DDevice, ID3DBlob* pVertexShaderCode)
{
// https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-semantics
D3D11_INPUT_ELEMENT_DESC inputs[4] = {};
// position
inputs[0].SemanticName = "POSITION";
inputs[0].Format = DXGI_FORMAT_R32G32B32_FLOAT;
// normal
inputs[1].SemanticName = "NORMAL";
inputs[1].Format = DXGI_FORMAT_R32G32B32_FLOAT;
inputs[1].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
// uv
inputs[2].SemanticName = "TEXCOORD";
inputs[2].Format = DXGI_FORMAT_R32G32_FLOAT;
inputs[2].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
// color
inputs[3].SemanticName = "COLOR";
inputs[3].Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
inputs[3].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
HRESULT hr = pD3DDevice->CreateInputLayout(
inputs, std::size(inputs), // element description array and array size
pVertexShaderCode->GetBufferPointer(), pVertexShaderCode->GetBufferSize(), // vertex shader code to check compatability with vertex
&_pInputLayout
);
CheckFailed(hr, 640);
return 0;
}