Add directx practice

This commit is contained in:
jmsgrogan 2022-11-09 19:54:25 +00:00
parent 30e30c8a7b
commit 92a35a5bc9
4 changed files with 140 additions and 0 deletions

View file

@ -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

View file

@ -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)

View file

@ -0,0 +1,111 @@
#include "loggers/FileLogger.h"
#include <DirectXMath.h>
#include <DirectXPackedVector.h>
#include <iostream>
#include <vector>
#include <windows.h>
#include <wrl.h>
#include <dxgi.h>
#include <dxgi1_6.h>
#include <d3d12.h>
#include <d3d12sdklayers.h>
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<IDXGIAdapter*> adapterList;
Microsoft::WRL::ComPtr<ID3D12CommandQueue> 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;
}

View file

@ -1,7 +1,9 @@
#include "FileLogger.h"
#include <time.h>
#include <iomanip>
#include <iostream>
#include <filesystem>
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;
}