mirror of
https://github.com/opencv/opencv.git
synced 2024-11-27 12:40:05 +08:00
cmake: detect Direct 3D 11
This commit is contained in:
parent
b43d6b6858
commit
cc69d4631a
@ -155,6 +155,7 @@ OCV_OPTION(WITH_CLP "Include Clp support (EPL)" OFF
|
||||
OCV_OPTION(WITH_OPENCL "Include OpenCL Runtime support" ON IF (NOT IOS) )
|
||||
OCV_OPTION(WITH_OPENCLAMDFFT "Include AMD OpenCL FFT library support" ON IF (NOT ANDROID AND NOT IOS) )
|
||||
OCV_OPTION(WITH_OPENCLAMDBLAS "Include AMD OpenCL BLAS library support" ON IF (NOT ANDROID AND NOT IOS) )
|
||||
OCV_OPTION(WITH_DIRECTX "Include DirectX support" ON IF WIN32 )
|
||||
|
||||
|
||||
# OpenCV build components
|
||||
@ -428,6 +429,11 @@ if(WITH_OPENCL)
|
||||
include(cmake/OpenCVDetectOpenCL.cmake)
|
||||
endif()
|
||||
|
||||
# --- DirectX ---
|
||||
if(WITH_DIRECTX)
|
||||
include(cmake/OpenCVDetectDirectX.cmake)
|
||||
endif()
|
||||
|
||||
# --- Matlab/Octave ---
|
||||
include(cmake/OpenCVFindMatlab.cmake)
|
||||
|
||||
|
14
cmake/OpenCVDetectDirectX.cmake
Normal file
14
cmake/OpenCVDetectDirectX.cmake
Normal file
@ -0,0 +1,14 @@
|
||||
if(WIN32)
|
||||
try_compile(__VALID_DIRECTX
|
||||
"${OpenCV_BINARY_DIR}"
|
||||
"${OpenCV_SOURCE_DIR}/cmake/checks/directx.cpp"
|
||||
OUTPUT_VARIABLE TRY_OUT
|
||||
)
|
||||
if(NOT __VALID_DIRECTX)
|
||||
return()
|
||||
endif()
|
||||
set(HAVE_DIRECTX ON)
|
||||
set(HAVE_D3D11 ON)
|
||||
set(HAVE_D3D10 ON)
|
||||
set(HAVE_D3D9 ON)
|
||||
endif()
|
70
cmake/checks/directx.cpp
Normal file
70
cmake/checks/directx.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
#include <windows.h>
|
||||
|
||||
#include <d3d11.h>
|
||||
#pragma comment (lib, "d3d11.lib")
|
||||
|
||||
HINSTANCE g_hInst = NULL;
|
||||
D3D_DRIVER_TYPE g_driverType = D3D_DRIVER_TYPE_NULL;
|
||||
D3D_FEATURE_LEVEL g_featureLevel = D3D_FEATURE_LEVEL_11_0;
|
||||
ID3D11Device* g_pd3dDevice = NULL;
|
||||
ID3D11DeviceContext* g_pImmediateContext = NULL;
|
||||
IDXGISwapChain* g_pSwapChain = NULL;
|
||||
|
||||
static HRESULT InitDevice()
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
|
||||
UINT width = 640;
|
||||
UINT height = 480;
|
||||
|
||||
UINT createDeviceFlags = 0;
|
||||
|
||||
D3D_DRIVER_TYPE driverTypes[] =
|
||||
{
|
||||
D3D_DRIVER_TYPE_HARDWARE,
|
||||
D3D_DRIVER_TYPE_WARP,
|
||||
D3D_DRIVER_TYPE_REFERENCE,
|
||||
};
|
||||
UINT numDriverTypes = ARRAYSIZE(driverTypes);
|
||||
|
||||
D3D_FEATURE_LEVEL featureLevels[] =
|
||||
{
|
||||
D3D_FEATURE_LEVEL_11_0,
|
||||
D3D_FEATURE_LEVEL_10_1,
|
||||
D3D_FEATURE_LEVEL_10_0,
|
||||
};
|
||||
UINT numFeatureLevels = ARRAYSIZE(featureLevels);
|
||||
|
||||
DXGI_SWAP_CHAIN_DESC sd;
|
||||
ZeroMemory( &sd, sizeof( sd ) );
|
||||
sd.BufferCount = 1;
|
||||
sd.BufferDesc.Width = width;
|
||||
sd.BufferDesc.Height = height;
|
||||
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
sd.BufferDesc.RefreshRate.Numerator = 60;
|
||||
sd.BufferDesc.RefreshRate.Denominator = 1;
|
||||
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
||||
sd.OutputWindow = NULL; //g_hWnd;
|
||||
sd.SampleDesc.Count = 1;
|
||||
sd.SampleDesc.Quality = 0;
|
||||
sd.Windowed = TRUE;
|
||||
|
||||
for (UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++)
|
||||
{
|
||||
g_driverType = driverTypes[driverTypeIndex];
|
||||
hr = D3D11CreateDeviceAndSwapChain(NULL, g_driverType, NULL, createDeviceFlags, featureLevels, numFeatureLevels,
|
||||
D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext);
|
||||
if (SUCCEEDED(hr))
|
||||
break;
|
||||
}
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
int main(int /*argc*/, char** /*argv*/)
|
||||
{
|
||||
InitDevice();
|
||||
return 0;
|
||||
}
|
@ -55,6 +55,12 @@
|
||||
/* IEEE1394 capturing support - libdc1394 v2.x */
|
||||
#cmakedefine HAVE_DC1394_2
|
||||
|
||||
/* DirectX */
|
||||
#cmakedefine HAVE_DIRECTX
|
||||
#cmakedefine HAVE_D3D11
|
||||
#cmakedefine HAVE_D3D10
|
||||
#cmakedefine HAVE_D3D9
|
||||
|
||||
/* DirectShow Video Capture library */
|
||||
#cmakedefine HAVE_DSHOW
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user