初始化完毕 并添加debug
This commit is contained in:
101
src/Device/WinDeviceManager.cpp
Normal file
101
src/Device/WinDeviceManager.cpp
Normal file
@@ -0,0 +1,101 @@
|
||||
#include "WinDeviceManager.h"
|
||||
|
||||
namespace WinMedia
|
||||
{
|
||||
WinDeviceManager::WinDeviceManager()
|
||||
{
|
||||
}
|
||||
|
||||
WinDeviceManager::~WinDeviceManager()
|
||||
{
|
||||
}
|
||||
|
||||
bool WinDeviceManager::IsDirectDrawAccelerationAvailable()
|
||||
{
|
||||
IDirectDraw* pDirectDraw = nullptr;
|
||||
|
||||
HRESULT hr = DirectDrawCreate(nullptr, &pDirectDraw, nullptr);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
// DirectDraw 创建失败,可能是不支持或没有安装 DirectX
|
||||
return false;
|
||||
}
|
||||
|
||||
// 获取 DirectDraw 加速信息
|
||||
DDCAPS ddcaps;
|
||||
ZeroMemory(&ddcaps, sizeof(ddcaps));
|
||||
ddcaps.dwSize = sizeof(ddcaps);
|
||||
|
||||
hr = pDirectDraw->GetCaps(&ddcaps, nullptr);
|
||||
pDirectDraw->Release();
|
||||
|
||||
if (FAILED(hr))
|
||||
{
|
||||
// 获取 DirectDraw 加速信息失败
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查是否支持硬件加速
|
||||
return (ddcaps.dwCaps & DDCAPS_NOHARDWARE) == 0;
|
||||
}
|
||||
|
||||
bool WinDeviceManager::IsDirect3DAccelerationAvailable()
|
||||
{
|
||||
D3D_FEATURE_LEVEL featureLevel;
|
||||
|
||||
// 尝试创建硬件设备,如果失败,尝试创建支持较低特性级别的设备
|
||||
HRESULT hr = D3D11CreateDevice(
|
||||
nullptr,
|
||||
D3D_DRIVER_TYPE_HARDWARE,
|
||||
nullptr,
|
||||
0,
|
||||
nullptr,
|
||||
0,
|
||||
D3D11_SDK_VERSION,
|
||||
nullptr,
|
||||
&featureLevel,
|
||||
nullptr
|
||||
);
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// 依次尝试创建支持较低特性级别的设备
|
||||
hr = D3D10CreateDevice(
|
||||
nullptr,
|
||||
D3D10_DRIVER_TYPE_HARDWARE,
|
||||
nullptr,
|
||||
0,
|
||||
D3D10_SDK_VERSION,
|
||||
nullptr
|
||||
);
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
IDirect3D9* pD3D = Direct3DCreate9(D3D_SDK_VERSION);
|
||||
|
||||
if (pD3D == nullptr)
|
||||
{
|
||||
// DirectX is not installed or not available
|
||||
return false;
|
||||
}
|
||||
D3DCAPS9 caps;
|
||||
if (FAILED(pD3D->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps)))
|
||||
{
|
||||
// Failed to get device capabilities
|
||||
pD3D->Release();
|
||||
return false;
|
||||
}
|
||||
// Check if Direct3D acceleration is supported
|
||||
const bool accelerationAvailable = (caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) != 0;
|
||||
|
||||
pD3D->Release();
|
||||
|
||||
return accelerationAvailable;
|
||||
}
|
||||
}
|
13
src/Device/WinDeviceManager.h
Normal file
13
src/Device/WinDeviceManager.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
namespace WinMedia
|
||||
{
|
||||
class WinDeviceManager {
|
||||
public:
|
||||
WinDeviceManager();
|
||||
~WinDeviceManager();
|
||||
|
||||
static bool IsDirectDrawAccelerationAvailable();
|
||||
static bool IsDirect3DAccelerationAvailable();
|
||||
};
|
||||
}
|
13
src/main.cpp
Normal file
13
src/main.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <iostream>
|
||||
|
||||
// Your library header(s)
|
||||
#include "Device/WinDeviceManager.h"
|
||||
|
||||
int main() {
|
||||
// Your test code here
|
||||
bool draw = WinMedia::WinDeviceManager::IsDirectDrawAccelerationAvailable();
|
||||
std::cout << "direct draw available:" << draw << std::endl;
|
||||
bool d3d = WinMedia::WinDeviceManager::IsDirect3DAccelerationAvailable();
|
||||
std::cout << "d3d available:" << d3d << std::endl;
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user