From 9393a2b4b34fc11266e2f1ae5f898b64546ce0a8 Mon Sep 17 00:00:00 2001 From: "Eduardo P. Gomez" Date: Wed, 6 Mar 2024 04:13:49 -0300 Subject: [PATCH] Update file paths and fix code in d3d9.cpp and idirect3ddevice9.hpp --- include/config.hpp | 2 +- include/winbase.h | 5 ++++ libs/d3d9/d3d9.cpp | 52 +++++++++++++++++++++++++++++++--- libs/d3d9/idirect3ddevice9.hpp | 8 ++++-- prod_include/d3d9.h | 8 +++++- run.sh | 4 +-- tests/basic_window.cpp | 3 +- 7 files changed, 70 insertions(+), 12 deletions(-) diff --git a/include/config.hpp b/include/config.hpp index 5b071b03..5a101984 100644 --- a/include/config.hpp +++ b/include/config.hpp @@ -3,4 +3,4 @@ #define DEBUG true //PREPROCESSING ONLY!!! -#define PROJECT_SOURCE_DIR "/workspaces/OpenDX/" +#define PROJECT_SOURCE_DIR "/home/eduardo/git/eduapps/OpenDX/" diff --git a/include/winbase.h b/include/winbase.h index d4ef4aeb..f73eeda7 100644 --- a/include/winbase.h +++ b/include/winbase.h @@ -5,3 +5,8 @@ inline LONG InterlockedIncrement(LONG volatile *p) { return __sync_add_and_fetch(p, 1); } + +inline LONG InterlockedDecrement(LONG volatile *p) +{ + return __sync_sub_and_fetch(p, 1); +} diff --git a/libs/d3d9/d3d9.cpp b/libs/d3d9/d3d9.cpp index d5407a5e..68037e64 100644 --- a/libs/d3d9/d3d9.cpp +++ b/libs/d3d9/d3d9.cpp @@ -15,7 +15,7 @@ //TODO: add ifdefs when implementing another gpu #include -IDirect3D9::IDirect3D9 (UINT SDKVersion) { +IDirect3D9::IDirect3D9(UINT SDKVersion) { #ifdef DEBUG std::cout << "libd3d9.so: IDirect3D9::IDirect3D9()" << std::endl; #endif @@ -100,9 +100,16 @@ HRESULT IDirect3D9::CreateDevice( std::cout << "libd3d9.so: IDirect3D9::CreateDevice()" << std::endl; #endif - //get hwnd size - RECT rect; - GetClientRect(hFocusWindow, &rect); + //get GtkWindow specs and put them into D3DPRESENT_PARAMETERS + pPresentationParameters->hDeviceWindow = hFocusWindow; + pPresentationParameters->BackBufferWidth = gtk_widget_get_size(hFocusWindow,GTK_ORIENTATION_HORIZONTAL); + pPresentationParameters->BackBufferHeight = gtk_widget_get_size(hFocusWindow,GTK_ORIENTATION_VERTICAL); + + //create the device + IDirect3DDevice9 device = IDirect3DDevice9(/*this, pPresentationParameters*/); + *ppReturnedDeviceInterface = &device; + + return 0; } ULONG IDirect3D9::Release() { @@ -138,3 +145,40 @@ IDirect3D9* Direct3DCreate9(UINT SDKVersion) { return r; } + +IDirect3DDevice9::IDirect3DDevice9(/*IDirect3D9* d3d, D3DPRESENT_PARAMETERS* pp*/) { + #ifdef DEBUG + std::cout << "libd3d9.so: IDirect3DDevice9::IDirect3DDevice9()" << std::endl; + #endif + + refCount = 1; +} + +ULONG IDirect3DDevice9::AddRef() { + DXGASSERT(((ULONG_PTR)(&refCount) & 3) == 0); + + InterlockedIncrement((LONG *)&refCount); + return refCount; +} + +ULONG IDirect3DDevice9::Release() { + InterlockedDecrement((LONG *)&refCount); + return refCount; +} + +HRESULT IDirect3DDevice9::QueryInterface(REFIID riid, void** ppvObj) { + *ppvObj = this; + + IDirect3DDevice9::AddRef(); + return 0; +} + +HRESULT IDirect3DDevice9::Clear(DWORD Count, const void/*D3DRECT*/ *pRects, DWORD Flags, int/*D3DCOLOR*/ Color, float Z, DWORD Stencil) { + #ifdef DEBUG + std::cout << "libd3d9.so: IDirect3DDevice9::Clear()" << std::endl; + #endif + + //intel code + + return 0; +} \ No newline at end of file diff --git a/libs/d3d9/idirect3ddevice9.hpp b/libs/d3d9/idirect3ddevice9.hpp index 2c10487c..49b08aea 100644 --- a/libs/d3d9/idirect3ddevice9.hpp +++ b/libs/d3d9/idirect3ddevice9.hpp @@ -2,6 +2,8 @@ #include #include -// struct IDirect3DDevice9:IUnknown { - -// }; \ No newline at end of file +/*IDirect3DDevice9::IDirect3DDevice9(IDirect3D9* d3d, D3DPRESENT_PARAMETERS* pp) { + #ifdef DEBUG + std::cout << "libd3d9.so: IDirect3DDevice9::IDirect3DDevice9()" << std::endl; + #endif +}*/ \ No newline at end of file diff --git a/prod_include/d3d9.h b/prod_include/d3d9.h index 4be071ed..7e2260e3 100644 --- a/prod_include/d3d9.h +++ b/prod_include/d3d9.h @@ -191,12 +191,18 @@ struct D3DPRESENT_PARAMETERS { }; typedef struct D3DPRESENT_PARAMETERS D3DPRESENT_PARAMETERS, *LPD3DPRESENT_PARAMETERS; -struct IDirect3DDevice9 : public IUnknown { +struct IDirect3DDevice9 { + IDirect3DDevice9(); + virtual HRESULT QueryInterface(REFIID riid, void** ppvObj); virtual ULONG AddRef(); virtual ULONG Release(); + HRESULT Clear(DWORD Count, const void/*D3DRECT*/ *pRects, DWORD Flags, int/*D3DCOLOR*/ Color, float Z, DWORD Stencil); + // Define other methods required by IDirect3D9 interface + + private:ULONG refCount; }; typedef struct IDirect3DDevice9 *LPDIRECT3DDEVICE9, *PDIRECT3DDEVICE9; diff --git a/run.sh b/run.sh index 90df45d8..51e4d608 100755 --- a/run.sh +++ b/run.sh @@ -1,3 +1,3 @@ # Run dxdiag from build directory -cd build -./tests/sample \ No newline at end of file +cd build/opendx +./bin/sample \ No newline at end of file diff --git a/tests/basic_window.cpp b/tests/basic_window.cpp index 44fd8c9d..aa151290 100644 --- a/tests/basic_window.cpp +++ b/tests/basic_window.cpp @@ -2,7 +2,8 @@ * Windows API codes were commented to focus * on what's important: OpenDX. * - * Code that doesn't work is also commented. + * Code that doesn't work is also commented and will be gradually + * fixed. This is a work in progress. */ #include #include