diff --git a/GraphicsCapture/GraphicsCaptureHook/D3D9Capture.cpp b/GraphicsCapture/GraphicsCaptureHook/D3D9Capture.cpp index 3169c3d2..18f47933 100644 --- a/GraphicsCapture/GraphicsCaptureHook/D3D9Capture.cpp +++ b/GraphicsCapture/GraphicsCaptureHook/D3D9Capture.cpp @@ -20,7 +20,7 @@ #include "GraphicsCaptureHook.h" #include -#include +#include typedef HRESULT (WINAPI *PRESENTPROC)(IDirect3DDevice9*, const RECT*, const RECT*, HWND, const RGNDATA*); typedef HRESULT (WINAPI *PRESENTEXPROC)(IDirect3DDevice9*, const RECT*, const RECT*, HWND, const RGNDATA*, DWORD); @@ -76,9 +76,8 @@ BOOL bUseSharedTextures = FALSE; IDirect3DSurface9 *copyD3D9TextureGame = NULL; extern SharedTexData *texData; extern DXGI_FORMAT dxgiFormat; -ID3D11Device *shareDevice = NULL; -ID3D11DeviceContext *shareContext = NULL; -ID3D11Resource *copyTextureIntermediary = NULL; +ID3D10Device1 *shareDevice = NULL; +ID3D10Resource *copyTextureIntermediary = NULL; extern HANDLE sharedHandle; HMODULE hD3D9Dll = NULL; @@ -263,7 +262,6 @@ void ClearD3D9Data() SafeRelease(copyD3D9TextureGame); SafeRelease(copyTextureIntermediary); SafeRelease(shareDevice); - SafeRelease(shareContext); DestroySharedMemory(); texData = NULL; @@ -312,14 +310,6 @@ void SetupD3D9(IDirect3DDevice9 *device); typedef HRESULT (WINAPI *CREATEDXGIFACTORY1PROC)(REFIID riid, void **ppFactory); -const static D3D_FEATURE_LEVEL featureLevels[] = -{ - D3D_FEATURE_LEVEL_11_0, - D3D_FEATURE_LEVEL_10_1, - D3D_FEATURE_LEVEL_10_0, - D3D_FEATURE_LEVEL_9_3, -}; - void DoD3D9GPUHook(IDirect3DDevice9 *device) { BYTE *savedData = nullptr; @@ -329,10 +319,10 @@ void DoD3D9GPUHook(IDirect3DDevice9 *device) HRESULT hErr; - HMODULE hD3D11 = LoadLibrary(TEXT("d3d11.dll")); - if(!hD3D11) + HMODULE hD3D10_1 = LoadLibrary(TEXT("d3d10_1.dll")); + if(!hD3D10_1) { - RUNEVERYRESET logOutput << CurrentTimeString() << "DoD3D9GPUHook: Could not load D3D11" << endl; + RUNEVERYRESET logOutput << CurrentTimeString() << "DoD3D9GPUHook: Could not load D3D10.1" << endl; goto finishGPUHook; } @@ -350,10 +340,10 @@ void DoD3D9GPUHook(IDirect3DDevice9 *device) goto finishGPUHook; } - PFN_D3D11_CREATE_DEVICE d3d11CreateDevice = (PFN_D3D11_CREATE_DEVICE)GetProcAddress(hD3D11, "D3D11CreateDevice"); - if(!d3d11CreateDevice) + PFN_D3D10_CREATE_DEVICE1 d3d10CreateDevice1 = (PFN_D3D10_CREATE_DEVICE1)GetProcAddress(hD3D10_1, "D3D10CreateDevice1"); + if(!d3d10CreateDevice1) { - RUNEVERYRESET logOutput << CurrentTimeString() << "DoD3D9GPUHook: Could not load 'D3D11CreateDevice'" << endl; + RUNEVERYRESET logOutput << CurrentTimeString() << "DoD3D9GPUHook: Could not load 'D3D10CreateDevice1'" << endl; goto finishGPUHook; } @@ -372,12 +362,15 @@ void DoD3D9GPUHook(IDirect3DDevice9 *device) goto finishGPUHook; } - if(FAILED(hErr = (*d3d11CreateDevice)(adapter, D3D_DRIVER_TYPE_UNKNOWN, NULL, 0, featureLevels, sizeof(featureLevels) / sizeof(featureLevels[0]), D3D11_SDK_VERSION, &shareDevice, NULL, &shareContext))) + if(FAILED(hErr = (*d3d10CreateDevice1)(adapter, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, D3D10_FEATURE_LEVEL_10_1, D3D10_1_SDK_VERSION, &shareDevice))) { - RUNEVERYRESET logOutput << CurrentTimeString() << "DoD3D9GPUHook: Could not create D3D11 device, result = " << (UINT)hErr << endl; - adapter->Release(); - factory->Release(); - goto finishGPUHook; + if(FAILED(hErr = (*d3d10CreateDevice1)(adapter, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, D3D10_FEATURE_LEVEL_9_3, D3D10_1_SDK_VERSION, &shareDevice))) + { + RUNEVERYRESET logOutput << CurrentTimeString() << "DoD3D9GPUHook: Could not create D3D10.1 device, result = " << (UINT)hErr << endl; + adapter->Release(); + factory->Release(); + goto finishGPUHook; + } } adapter->Release(); @@ -385,7 +378,7 @@ void DoD3D9GPUHook(IDirect3DDevice9 *device) //------------------------------------------------ - D3D11_TEXTURE2D_DESC texGameDesc; + D3D10_TEXTURE2D_DESC texGameDesc; ZeroMemory(&texGameDesc, sizeof(texGameDesc)); texGameDesc.Width = d3d9CaptureInfo.cx; texGameDesc.Height = d3d9CaptureInfo.cy; @@ -393,41 +386,41 @@ void DoD3D9GPUHook(IDirect3DDevice9 *device) texGameDesc.ArraySize = 1; texGameDesc.Format = dxgiFormat; texGameDesc.SampleDesc.Count = 1; - texGameDesc.BindFlags = D3D11_BIND_RENDER_TARGET|D3D11_BIND_SHADER_RESOURCE; - texGameDesc.Usage = D3D11_USAGE_DEFAULT; - texGameDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED; + texGameDesc.BindFlags = D3D10_BIND_RENDER_TARGET|D3D10_BIND_SHADER_RESOURCE; + texGameDesc.Usage = D3D10_USAGE_DEFAULT; + texGameDesc.MiscFlags = D3D10_RESOURCE_MISC_SHARED; - ID3D11Texture2D *d3d11Tex; - if(FAILED(hErr = shareDevice->CreateTexture2D(&texGameDesc, NULL, &d3d11Tex))) + ID3D10Texture2D *d3d101Tex; + if(FAILED(hErr = shareDevice->CreateTexture2D(&texGameDesc, NULL, &d3d101Tex))) { RUNEVERYRESET logOutput << CurrentTimeString() << "DoD3D9GPUHook: shareDevice->CreateTexture2D failed, result = " << (UINT)hErr << endl; goto finishGPUHook; } - if(FAILED(hErr = d3d11Tex->QueryInterface(__uuidof(ID3D11Resource), (void**)©TextureIntermediary))) + if(FAILED(hErr = d3d101Tex->QueryInterface(__uuidof(ID3D10Resource), (void**)©TextureIntermediary))) { - RUNEVERYRESET logOutput << CurrentTimeString() << "DoD3D9GPUHook: d3d11Tex->QueryInterface(ID3D11Resource) failed, result = " << (UINT)hErr << endl; - d3d11Tex->Release(); + RUNEVERYRESET logOutput << CurrentTimeString() << "DoD3D9GPUHook: d3d101Tex->QueryInterface(ID3D10Resource) failed, result = " << (UINT)hErr << endl; + d3d101Tex->Release(); goto finishGPUHook; } IDXGIResource *res; - if(FAILED(hErr = d3d11Tex->QueryInterface(IID_IDXGIResource, (void**)&res))) + if(FAILED(hErr = d3d101Tex->QueryInterface(IID_IDXGIResource, (void**)&res))) { - RUNEVERYRESET logOutput << CurrentTimeString() << "DoD3D9GPUHook: d3d11Tex->QueryInterface(IDXGIResource) failed, result = " << (UINT)hErr << endl; - d3d11Tex->Release(); + RUNEVERYRESET logOutput << CurrentTimeString() << "DoD3D9GPUHook: d3d101Tex->QueryInterface(IDXGIResource) failed, result = " << (UINT)hErr << endl; + d3d101Tex->Release(); goto finishGPUHook; } if(FAILED(res->GetSharedHandle(&sharedHandle))) { RUNEVERYRESET logOutput << CurrentTimeString() << "DoD3D9GPUHook: res->GetSharedHandle failed, result = " << (UINT)hErr << endl; - d3d11Tex->Release(); + d3d101Tex->Release(); res->Release(); goto finishGPUHook; } - d3d11Tex->Release(); + d3d101Tex->Release(); res->Release(); res = NULL; diff --git a/GraphicsCapture/GraphicsCaptureHook/OpenGLCapture.cpp b/GraphicsCapture/GraphicsCaptureHook/OpenGLCapture.cpp index 12f65ce0..7c97d6bc 100644 --- a/GraphicsCapture/GraphicsCaptureHook/OpenGLCapture.cpp +++ b/GraphicsCapture/GraphicsCaptureHook/OpenGLCapture.cpp @@ -24,7 +24,7 @@ #ifdef USE_D3D9_GL_INTEROP #include #else -#include +#include #endif @@ -228,9 +228,8 @@ static IDirect3DDevice9Ex *d3d9exDevice = NULL; static IDirect3DTexture9 *d3d9exTexture = NULL; extern bool bD3D9Hooked; #else -extern ID3D11Device *shareDevice; -extern ID3D11DeviceContext *shareContext; -extern ID3D11Resource *copyTextureIntermediary; +extern ID3D10Device1 *shareDevice; +extern ID3D10Resource *copyTextureIntermediary; IDXGISwapChain *swapChain = NULL; extern bool bDXGIHooked; #endif @@ -504,18 +503,8 @@ finishGPUHook: typedef HRESULT (WINAPI *CREATEDXGIFACTORY1PROC)(REFIID riid, void **ppFactory); -const static D3D_FEATURE_LEVEL featureLevels[] = -{ - D3D_FEATURE_LEVEL_11_0, - D3D_FEATURE_LEVEL_10_1, - D3D_FEATURE_LEVEL_10_0, - D3D_FEATURE_LEVEL_9_3, -}; - static bool DoGLGPUHook(RECT &rc) { - D3D_FEATURE_LEVEL level; - bUseSharedTextures = true; glcaptureInfo.cx = rc.right; glcaptureInfo.cy = rc.bottom; @@ -537,10 +526,10 @@ static bool DoGLGPUHook(RECT &rc) swapDesc.Windowed = TRUE; swapDesc.OutputWindow = hwndD3DDummyWindow; - HMODULE hD3D11 = LoadLibrary(TEXT("d3d11.dll")); - if(!hD3D11) + HMODULE hD3D10_1 = LoadLibrary(TEXT("d3d10_1.dll")); + if(!hD3D10_1) { - RUNEVERYRESET logOutput << CurrentTimeString() << "DoGLGPUHook: Could not load D3D11" << endl; + RUNEVERYRESET logOutput << CurrentTimeString() << "DoGLGPUHook: Could not load D3D10.1" << endl; goto finishGPUHook; } @@ -558,10 +547,10 @@ static bool DoGLGPUHook(RECT &rc) goto finishGPUHook; } - PFN_D3D11_CREATE_DEVICE_AND_SWAP_CHAIN d3d11CreateDeviceAndSwapChain = (PFN_D3D11_CREATE_DEVICE_AND_SWAP_CHAIN)GetProcAddress(hD3D11, "D3D11CreateDeviceAndSwapChain"); - if(!d3d11CreateDeviceAndSwapChain) + PFN_D3D10_CREATE_DEVICE_AND_SWAP_CHAIN1 d3d10CreateDeviceAndSwapChain1 = (PFN_D3D10_CREATE_DEVICE_AND_SWAP_CHAIN1)GetProcAddress(hD3D10_1, "D3D10CreateDeviceAndSwapChain1"); + if(!d3d10CreateDeviceAndSwapChain1) { - RUNEVERYRESET logOutput << CurrentTimeString() << "DoGLGPUHook: Could not load 'D3D11CreateDeviceAndSwapChain'" << endl; + RUNEVERYRESET logOutput << CurrentTimeString() << "DoGLGPUHook: Could not load 'D3D10CreateDeviceAndSwapChain1'" << endl; goto finishGPUHook; } @@ -580,12 +569,15 @@ static bool DoGLGPUHook(RECT &rc) goto finishGPUHook; } - if(FAILED(hErr = (*d3d11CreateDeviceAndSwapChain)(adapter, D3D_DRIVER_TYPE_UNKNOWN, NULL, 0, featureLevels, sizeof(featureLevels) / sizeof(featureLevels[0]), D3D11_SDK_VERSION, &swapDesc, &swapChain, &shareDevice, &level, &shareContext))) + if(FAILED(hErr = (*d3d10CreateDeviceAndSwapChain1)(adapter, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, D3D10_FEATURE_LEVEL_10_1, D3D10_1_SDK_VERSION, &swapDesc, &swapChain, &shareDevice))) { - RUNEVERYRESET logOutput << CurrentTimeString() << "DoGLGPUHook: Could not create D3D10.1 device, result = " << (UINT)hErr << endl; - adapter->Release(); - factory->Release(); - goto finishGPUHook; + if(FAILED(hErr = (*d3d10CreateDeviceAndSwapChain1)(adapter, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, D3D10_FEATURE_LEVEL_9_3, D3D10_1_SDK_VERSION, &swapDesc, &swapChain, &shareDevice))) + { + RUNEVERYRESET logOutput << CurrentTimeString() << "DoGLGPUHook: Could not create D3D10.1 device, result = " << (UINT)hErr << endl; + adapter->Release(); + factory->Release(); + goto finishGPUHook; + } } adapter->Release(); @@ -593,7 +585,7 @@ static bool DoGLGPUHook(RECT &rc) //------------------------------------------------ - D3D11_TEXTURE2D_DESC texGameDesc; + D3D10_TEXTURE2D_DESC texGameDesc; ZeroMemory(&texGameDesc, sizeof(texGameDesc)); texGameDesc.Width = glcaptureInfo.cx; texGameDesc.Height = glcaptureInfo.cy; @@ -601,36 +593,36 @@ static bool DoGLGPUHook(RECT &rc) texGameDesc.ArraySize = 1; texGameDesc.Format = DXGI_FORMAT_B8G8R8X8_UNORM; texGameDesc.SampleDesc.Count = 1; - texGameDesc.BindFlags = D3D11_BIND_RENDER_TARGET|D3D11_BIND_SHADER_RESOURCE; - texGameDesc.Usage = D3D11_USAGE_DEFAULT; - texGameDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED; + texGameDesc.BindFlags = D3D10_BIND_RENDER_TARGET|D3D10_BIND_SHADER_RESOURCE; + texGameDesc.Usage = D3D10_USAGE_DEFAULT; + texGameDesc.MiscFlags = D3D10_RESOURCE_MISC_SHARED; - ID3D11Texture2D *d3d11Tex; - if(FAILED(hErr = shareDevice->CreateTexture2D(&texGameDesc, NULL, &d3d11Tex))) + ID3D10Texture2D *d3d101Tex; + if(FAILED(hErr = shareDevice->CreateTexture2D(&texGameDesc, NULL, &d3d101Tex))) { RUNEVERYRESET logOutput << CurrentTimeString() << "DoGLGPUHook: shareDevice->CreateTexture2D failed, result = " << (UINT)hErr << endl; goto finishGPUHook; } - if(FAILED(hErr = d3d11Tex->QueryInterface(__uuidof(ID3D10Resource), (void**)©TextureIntermediary))) + if(FAILED(hErr = d3d101Tex->QueryInterface(__uuidof(ID3D10Resource), (void**)©TextureIntermediary))) { - RUNEVERYRESET logOutput << CurrentTimeString() << "DoGLGPUHook: d3d11Tex->QueryInterface(ID3D10Resource) failed, result = " << (UINT)hErr << endl; - d3d11Tex->Release(); + RUNEVERYRESET logOutput << CurrentTimeString() << "DoGLGPUHook: d3d101Tex->QueryInterface(ID3D10Resource) failed, result = " << (UINT)hErr << endl; + d3d101Tex->Release(); goto finishGPUHook; } IDXGIResource *res; - if(FAILED(hErr = d3d11Tex->QueryInterface(IID_IDXGIResource, (void**)&res))) + if(FAILED(hErr = d3d101Tex->QueryInterface(IID_IDXGIResource, (void**)&res))) { - RUNEVERYRESET logOutput << CurrentTimeString() << "DoGLGPUHook: d3d11Tex->QueryInterface(IDXGIResource) failed, result = " << (UINT)hErr << endl; - d3d11Tex->Release(); + RUNEVERYRESET logOutput << CurrentTimeString() << "DoGLGPUHook: d3d101Tex->QueryInterface(IDXGIResource) failed, result = " << (UINT)hErr << endl; + d3d101Tex->Release(); goto finishGPUHook; } if(FAILED(res->GetSharedHandle(&sharedHandle))) { RUNEVERYRESET logOutput << CurrentTimeString() << "DoGLGPUHook: res->GetSharedHandle failed, result = " << (UINT)hErr << endl; - d3d11Tex->Release(); + d3d101Tex->Release(); res->Release(); goto finishGPUHook; } @@ -639,7 +631,7 @@ static bool DoGLGPUHook(RECT &rc) gl_dxDevice = wglDXOpenDeviceNV(shareDevice); if (gl_dxDevice == NULL) { RUNEVERYRESET logOutput << CurrentTimeString() << "DoGLGPUHook: wglDXOpenDeviceNV failed" << endl; - d3d11Tex->Release(); + d3d101Tex->Release(); res->Release(); goto finishGPUHook; } @@ -649,7 +641,7 @@ static bool DoGLGPUHook(RECT &rc) if (gl_handle == NULL) { RUNEVERYRESET logOutput << CurrentTimeString() << "DoGLGPUHook: wglDXRegisterObjectNV failed" << endl; - d3d11Tex->Release(); + d3d101Tex->Release(); res->Release(); goto finishGPUHook; } @@ -662,7 +654,7 @@ static bool DoGLGPUHook(RECT &rc) glGenFramebuffers(1, &gl_fbo); - d3d11Tex->Release(); + d3d101Tex->Release(); res->Release(); res = NULL;