From 4fd52c1567b0b91ca164c27e6324f2405b39e874 Mon Sep 17 00:00:00 2001 From: David Hackbarth Date: Wed, 3 Sep 2025 12:18:51 +0200 Subject: [PATCH] add direct3d device init (WIP) --- GDP/D3D9/Direct3D.cpp | 34 ++++++++++++++++++++++++++++++++++ GDP/D3D9/Direct3D.h | 3 ++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/GDP/D3D9/Direct3D.cpp b/GDP/D3D9/Direct3D.cpp index fd7e02f..dfaec76 100644 --- a/GDP/D3D9/Direct3D.cpp +++ b/GDP/D3D9/Direct3D.cpp @@ -1,16 +1,49 @@ #include "Direct3D.h" +#include "Utilities.h" INT Direct3D::init(HWND hWnd, UINT width, UINT height, BOOL isFullscreen) { // 1. create connection to Direct3D API + IDirect3D9* pD3D = Direct3DCreate9(D3D_SDK_VERSION); + if (pD3D == nullptr) return 200; // 2. check compatibility + UINT adapter = D3DADAPTER_DEFAULT; + D3DDEVTYPE devType = D3DDEVTYPE_HAL; + D3DCAPS9 caps = {}; + HRESULT hr = pD3D->GetDeviceCaps(adapter, devType, &caps); + CheckFailed(hr, 210); + + DWORD vertexProcessing = D3DCREATE_SOFTWARE_VERTEXPROCESSING; // fallback software fixed function pipeline + if (caps.VertexProcessingCaps == D3DDEVCAPS_HWTRANSFORMANDLIGHT) + { + // hardware support for fixed function pipeline + vertexProcessing = D3DCREATE_HARDWARE_VERTEXPROCESSING; + } // 3. define presentation parameters + D3DPRESENT_PARAMETERS d3dpp = {}; + d3dpp.hDeviceWindow = hWnd; // target render window + d3dpp.Windowed = !isFullscreen; // window or fullscreen mode + d3dpp.BackBufferCount = 1; // at least 1 + d3dpp.BackBufferWidth = width; + d3dpp.BackBufferHeight = height; + d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8; + d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; // 4. create Direct3D device + hr = pD3D->CreateDevice( + adapter, + devType, + hWnd, + vertexProcessing, // optional parameters + &d3dpp, + &_pD3DDevice + ); + CheckFailed(hr, 220); // 5. tidy up + safeRelease(pD3D); return 0; } @@ -25,4 +58,5 @@ void Direct3D::endScene() void Direct3D::deInit() { + safeRelease(_pD3DDevice); } diff --git a/GDP/D3D9/Direct3D.h b/GDP/D3D9/Direct3D.h index f8c0a26..eee05a9 100644 --- a/GDP/D3D9/Direct3D.h +++ b/GDP/D3D9/Direct3D.h @@ -14,6 +14,7 @@ public: IDirect3DDevice9* getDevice() const { return _pD3DDevice; } private: - IDirect3DDevice9* _pD3DDevice = nullptr; // our interface for api communication + // COM object - Component Object Model + IDirect3DDevice9* _pD3DDevice = nullptr; // our interface for graphic card communication };