Changed D3D9 to D3D11 api connection

Changed mesh to D3D11
Changed material to D3D11 (WIP)
This commit is contained in:
2026-11-23 12:31:31 +01:00
parent abb8da9cff
commit 204c55e915
14 changed files with 288 additions and 182 deletions
+67 -3
View File
@@ -1,8 +1,10 @@
#include "Material.h"
#include "Utilities.h"
#include "WICTextureLoader9.h"
//#include "WICTextureLoader9.h"
UINT Material::init(IDirect3DDevice9* pD3DDevice, LPCTSTR textureFileName)
//using namespace DirectX;
UINT Material::init(ID3D11Device* pD3DDevice, LPCTSTR textureFileName)
{
HRESULT hr = DirectX::CreateWICTextureFromFile(pD3DDevice, textureFileName, &_pTexture, 0, DirectX::WIC_LOADER_MIP_AUTOGEN);
CheckFailed(hr, 600);
@@ -10,7 +12,7 @@ UINT Material::init(IDirect3DDevice9* pD3DDevice, LPCTSTR textureFileName)
return 0;
}
void Material::render(IDirect3DDevice9* pD3DDevice)
void Material::render(ID3D11DeviceContext* pD3DDeviceContext)
{
// set texture
pD3DDevice->SetTexture(0, _pTexture);
@@ -38,3 +40,65 @@ void Material::render(IDirect3DDevice9* pD3DDevice)
void Material::deInit()
{
}
UINT Material::createVertexShader(ID3D11Device* pD3DDevice)
{
HRESULT hr = {};
ID3DBlob* pCompiledShaderCode = nullptr;
// two options of creating a shader object
// option 1: compile at runtime
//hr = D3DCompileFromFile(
// L"VertexShader.hlsl", // shader filename
// nullptr, nullptr, // additional shared shader code (optional)
// "main", // shader entry function name
// "vs_4_0", // shader type & model (version)
// 0, 0, // optional flags
// &pCompiledShaderCode,
// nullptr // optional blob for error messages
//);
// option 2: load compiled shader
hr = D3DReadFileToBlob(L"VertexShader.cso", &pCompiledShaderCode);
CheckFailed(hr, 600);
// create shader object
hr = pD3DDevice->CreateVertexShader(
pCompiledShaderCode->GetBufferPointer(), pCompiledShaderCode->GetBufferSize(), // compiled shader code
nullptr, // again shared shader informations
&_pVertexShader
);
CheckFailed(hr, 605);
UINT error = createInputLayout(pD3DDevice, pCompiledShaderCode);
CheckError(error);
safeRelease(pCompiledShaderCode);
return 0;
}
UINT Material::createPixelShader(ID3D11Device* pD3DDevice)
{
HRESULT hr = {};
ID3DBlob* pCompiledShaderCode = nullptr;
hr = D3DReadFileToBlob(L"PixelShader.cso", &pCompiledShaderCode);
CheckFailed(hr, 620);
// create shader object
hr = pD3DDevice->CreatePixelShader(
pCompiledShaderCode->GetBufferPointer(), pCompiledShaderCode->GetBufferSize(), // compiled shader code
nullptr, // again shared shader informations
&_pPixelShader
);
CheckFailed(hr, 625);
return 0;
}
UINT Material::createInputLayout(ID3D11Device* pD3DDevice, ID3DBlob* pVertexShaderCode)
{
return 0;
}