Initial directx example.

This commit is contained in:
jmsgrogan 2023-01-03 20:33:18 +00:00
parent 1dfbcc61c4
commit 92d1f24613
28 changed files with 683 additions and 212 deletions

View file

@ -1,11 +1,6 @@
add_subdirectory(notes_tk)
add_subdirectory(website-generator)
# Experimental Below
if(WIN32)
add_subdirectory(directx-practice)
endif()
# Sample Console
add_executable(notes_tk_console main.cpp)
target_link_libraries(notes_tk_console PUBLIC console core network database geometry audio web)

View file

@ -1,16 +0,0 @@
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

@ -1,111 +0,0 @@
#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

@ -16,8 +16,8 @@
#include "DesktopManager.h"
#include "MainApplication.h"
NotesTk::NotesTk(std::unique_ptr<CommandLineArgs> args)
: GuiApplication(std::move(args))
NotesTk::NotesTk(std::unique_ptr<CommandLineArgs> args, std::unique_ptr<MainApplication> mainApp)
: GuiApplication(std::move(args), std::move(mainApp))
{
}

View file

@ -5,7 +5,7 @@
class NotesTk : public GuiApplication
{
public:
NotesTk(std::unique_ptr<CommandLineArgs> args);
NotesTk(std::unique_ptr<CommandLineArgs> args = nullptr, std::unique_ptr<MainApplication> mainApp = nullptr);
protected:
void initializeViews() override;

View file

@ -3,11 +3,12 @@
#endif
#include "MainApplication.h"
#include "GuiApplication.h"
#include "NotesTk.h"
#include "CommandLineArgs.h"
#include "Win32WindowInterface.h"
#include "FileLogger.h"
#include "StringUtils.h"
#include "Widget.h"
#include "windows.h"
@ -55,13 +56,11 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
MLOG_INFO("Creating GUI Application");
// Start the gui application
auto gui_app = GuiApplication();
//gui_app.setMainApplication(main_app);
auto gui_app = NotesTk(nullptr, std::move(main_app));
MLOG_INFO("Running GUI Application");
gui_app.run();
main_app->shutDown();
return 0;
}