diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index 4c06224..47b9f8f 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -16,6 +16,9 @@ target_include_directories(sample_gui PUBLIC target_link_libraries(sample_gui_win PUBLIC client windows console core network database geometry audio web) set_property(TARGET sample_gui_win PROPERTY FOLDER apps) + +add_subdirectory(directx-practice) + endif() # Sample Console diff --git a/apps/directx-practice/CMakeLists.txt b/apps/directx-practice/CMakeLists.txt new file mode 100644 index 0000000..46d253f --- /dev/null +++ b/apps/directx-practice/CMakeLists.txt @@ -0,0 +1,16 @@ + +list(APPEND directx_practice_LIB_INCLUDES + +) + + +add_executable(directx-practice WIN32 directx-practice.cpp ${directx_practice_LIB_INCLUDES}) + +target_include_directories(directx-practice PUBLIC + "${CMAKE_CURRENT_SOURCE_DIR}" + ) + +target_link_libraries(directx-practice PUBLIC core D3D12.lib DXGI.lib) + +set_property(TARGET directx-practice PROPERTY FOLDER apps/directx-practice) + diff --git a/apps/directx-practice/directx-practice.cpp b/apps/directx-practice/directx-practice.cpp new file mode 100644 index 0000000..678e5c0 --- /dev/null +++ b/apps/directx-practice/directx-practice.cpp @@ -0,0 +1,111 @@ +#include "loggers/FileLogger.h" + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + + +void GetHardwareAdapter(IDXGIFactory7* pFactory, IDXGIAdapter1** ppAdapter) +{ + *ppAdapter = nullptr; + for (UINT adapterIndex = 0; ; ++adapterIndex) + { + IDXGIAdapter1* pAdapter = nullptr; + if (DXGI_ERROR_NOT_FOUND == pFactory->EnumAdapters1(adapterIndex, &pAdapter)) + { + // No more adapters to enumerate. + break; + } + + // Check to see if the adapter supports Direct3D 12, but don't create the + // actual device yet. + if (SUCCEEDED(D3D12CreateDevice(pAdapter, D3D_FEATURE_LEVEL_11_0, _uuidof(ID3D12Device), nullptr))) + { + *ppAdapter = pAdapter; + return; + } + pAdapter->Release(); + } +} + +int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) +{ + FileLogger::GetInstance().Open(); + MLOG_INFO("Test"); + + if (!DirectX::XMVerifyCPUSupport()) + { + MLOG_ERROR("Directx math not supported"); + return 0; + } + + auto n = DirectX::XMVectorSet(1.0f, 0.0f, 0.0f, 0.0f); + //auto u = DirectX::XMVectorSet(1.0f, 2.0f, 3.0f, 0.0f); + //auto v = DirectX::XMVectorSet(-2.0f, 1.0f, -3.0f, 0.0f); + //auto w = DirectX::XMVectorSet(0.707f, 0.707f, 0.0f, 0.0f); + + auto p = DirectX::XMVectorZero(); + auto q = DirectX::XMVectorSplatOne(); + auto u = DirectX::XMVectorSet(1.0f, 2.0f, 3.0f, 0.0f); + auto v = DirectX::XMVectorReplicate(-2.0f); + auto w = DirectX::XMVectorSplatZ(u); + + DirectX::XMMATRIX A(1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 2.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 4.0f, 0.0f, + 1.0f, 2.0f, 3.0f, 1.0f); + DirectX::XMMATRIX B = DirectX::XMMatrixIdentity(); + + IDXGIAdapter* adapter = nullptr; + std::vector adapterList; + + Microsoft::WRL::ComPtr commandQueue; + D3D12_COMMAND_QUEUE_DESC queueDesc = {}; + queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT; + +#if defined(DEBUG) || defined(_DEBUG) + // Enable the D3D12 debug layer. + { + ID3D12Debug* debugController; + D3D12GetDebugInterface(IID_PPV_ARGS(&debugController)); + debugController->EnableDebugLayer(); + } +#endif + + IDXGIFactory7* pFactory{ nullptr }; + HRESULT hr = CreateDXGIFactory1(__uuidof(IDXGIFactory7), (void**)(&pFactory)); + if (hr == S_OK) + { + MLOG_INFO("FACTORY IS OK"); + } + + IDXGIAdapter1* pAdapter{ nullptr }; + GetHardwareAdapter(pFactory, &pAdapter); + + ID3D12Device* pDevice{ nullptr }; + if (pAdapter) + { + MLOG_INFO("Found adapter"); + if (SUCCEEDED(D3D12CreateDevice(pAdapter, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&pDevice)))) + { + MLOG_INFO("Got device"); + } + + } + else + { + MLOG_INFO("No adapter found"); + return 0; + } + + return 0; +} \ No newline at end of file diff --git a/src/core/loggers/FileLogger.cpp b/src/core/loggers/FileLogger.cpp index 6d7da28..2532aca 100644 --- a/src/core/loggers/FileLogger.cpp +++ b/src/core/loggers/FileLogger.cpp @@ -1,7 +1,9 @@ #include "FileLogger.h" + #include #include #include +#include FileLogger::~FileLogger() { @@ -20,6 +22,10 @@ void FileLogger::SetFileName(const std::string& fileName) void FileLogger::Open() { + if (mWorkDirectory.empty()) + { + mWorkDirectory = std::filesystem::current_path().string(); + } mFileStream.open(mWorkDirectory + "/" + mFileName); } @@ -30,6 +36,10 @@ void FileLogger::Close() void FileLogger::LogLine(const std::ostringstream& line) { + if (!mFileStream.is_open()) + { + Open(); + } mFileStream << line.str() << std::endl; }