diff --git a/DXCore.h b/DXCore.h index 534cc1c..4880a06 100644 --- a/DXCore.h +++ b/DXCore.h @@ -44,6 +44,13 @@ public: virtual void Update(float deltaTime, float totalTime) = 0; virtual void Draw(float deltaTime, float totalTime) = 0; + // Helpers for determining the actual path to the executable + static std::string GetExePath(); + static std::wstring GetExePath_Wide(); + + static std::string GetFullPathTo(std::string relativeFilePath); + static std::wstring GetFullPathTo_Wide(std::wstring relativeFilePath); + protected: HINSTANCE hInstance; // The handle to the application HWND hWnd; // The handle to the window itself @@ -70,13 +77,6 @@ protected: // Helper function for allocating a console window void CreateConsoleWindow(int bufferLines, int bufferColumns, int windowLines, int windowColumns); - // Helpers for determining the actual path to the executable - std::string GetExePath(); - std::wstring GetExePath_Wide(); - - std::string GetFullPathTo(std::string relativeFilePath); - std::wstring GetFullPathTo_Wide(std::wstring relativeFilePath); - private: // Timing related data diff --git a/Game.cpp b/Game.cpp index 3cfb69f..a01cf77 100644 --- a/Game.cpp +++ b/Game.cpp @@ -105,32 +105,15 @@ void Game::LoadTextures() sampDesc.MaxLOD = D3D11_FLOAT32_MAX; device->CreateSamplerState(&sampDesc, sampler.GetAddressOf()); - Microsoft::WRL::ComPtr - deepFloorEmissive, - deepFloorSpecular, - deepFloorAlbedo, - floorEmissive, - floorSpecular, - floorAlbedo; - - // taking the preprocessor macro from the demo because I don't like typing - #define GetTex(pathToTexture, shaderResourceView) CreateWICTextureFromFile(device.Get(), context.Get(), GetFullPathTo_Wide(pathToTexture).c_str(), 0, shaderResourceView.GetAddressOf()); - - GetTex(L"Assets/Textures/HQGame/structure-endgame-deepfloor_emissive.png", deepFloorEmissive); - GetTex(L"Assets/Textures/HQGame/structure-endgame-deepfloor_specular.png", deepFloorSpecular); - GetTex(L"Assets/Textures/HQGame/structure-endgame-deepfloor_albedo.png", deepFloorAlbedo); - GetTex(L"Assets/Textures/HQGame/structure-endgame-floor_emissive.png", floorEmissive); - GetTex(L"Assets/Textures/HQGame/structure-endgame-floor_specular.png", floorSpecular); - GetTex(L"Assets/Textures/HQGame/structure-endgame-floor_albedo.png", floorAlbedo); - materials[0]->PushSampler("BasicSampler", sampler); - materials[0]->PushTexture("Albedo", deepFloorAlbedo); - materials[0]->PushTexture("Specular", deepFloorSpecular); - materials[0]->PushTexture("Emissive", deepFloorEmissive); + materials[0]->LoadTexture(L"Assets/Textures/HQGame/structure-endgame-deepfloor_albedo.png", TEXTYPE_ALBEDO, device.Get(), context.Get()); + materials[0]->LoadTexture(L"Assets/Textures/HQGame/structure-endgame-deepfloor_specular.png", TEXTYPE_SPECULAR, device.Get(), context.Get()); + materials[0]->LoadTexture(L"Assets/Textures/HQGame/structure-endgame-deepfloor_emissive.png", TEXTYPE_EMISSIVE, device.Get(), context.Get()); + materials[1]->PushSampler("BasicSampler", sampler); - materials[1]->PushTexture("Albedo", floorAlbedo); - materials[1]->PushTexture("Specular", floorSpecular); - materials[1]->PushTexture("Emissive", floorEmissive); + materials[1]->LoadTexture(L"Assets/Textures/HQGame/structure-endgame-floor_albedo.png", TEXTYPE_ALBEDO, device.Get(), context.Get()); + materials[1]->LoadTexture(L"Assets/Textures/HQGame/structure-endgame-floor_specular.png", TEXTYPE_SPECULAR, device.Get(), context.Get()); + materials[1]->LoadTexture(L"Assets/Textures/HQGame/structure-endgame-floor_emissive.png", TEXTYPE_EMISSIVE, device.Get(), context.Get()); } void Game::LoadLighting() diff --git a/Material.cpp b/Material.cpp index 25a2bfd..1d3b832 100644 --- a/Material.cpp +++ b/Material.cpp @@ -129,6 +129,13 @@ void Material::SetPixelShader(std::shared_ptr _pixelShader) pixelShader = _pixelShader; } +void Material::LoadTexture(const wchar_t* _path, const char* _type, ID3D11Device* _device, ID3D11DeviceContext* _context) +{ + Microsoft::WRL::ComPtr shaderResourceView; + DirectX::CreateWICTextureFromFile(_device, _context, DXCore::GetFullPathTo_Wide(_path).c_str(), 0, shaderResourceView.GetAddressOf()); + PushTexture(_type, shaderResourceView); +} + void Material::PushSampler(std::string _name, Microsoft::WRL::ComPtr _sampler) { samplers.insert({ _name, _sampler }); diff --git a/Material.h b/Material.h index c3df313..cdbd90b 100644 --- a/Material.h +++ b/Material.h @@ -2,10 +2,17 @@ #include #include +#include "DXCore.h" #include "SimpleShader.h" #include "Transform.h" #include "Camera.h" #include "Lights.h" +#include "WICTextureLoader.h" + +constexpr auto TEXTYPE_ALBEDO = "Albedo"; +constexpr auto TEXTYPE_NORMAL = "Normal"; +constexpr auto TEXTYPE_EMISSIVE = "Emissive"; +constexpr auto TEXTYPE_SPECULAR = "Specular"; class Material { @@ -39,6 +46,7 @@ public: void SetVertexShader(std::shared_ptr _vertexShader); void SetPixelShader(std::shared_ptr _pixelShader); + void LoadTexture(const wchar_t* _path, const char* _type, ID3D11Device* _device, ID3D11DeviceContext* _context); void PushSampler(std::string _name, Microsoft::WRL::ComPtr _sampler); void PushTexture(std::string _name, Microsoft::WRL::ComPtr _texture);