mirror of
https://github.com/qtkite/defender-control.git
synced 2024-11-04 12:00:15 +00:00
create device
This commit is contained in:
parent
e7862bf253
commit
7dd30d5c0e
@ -2,11 +2,51 @@
|
||||
|
||||
namespace gui::dx11
|
||||
{
|
||||
static ID3D11Device* g_device = NULL;
|
||||
static ID3D11DeviceContext* g_context = NULL;
|
||||
static IDXGISwapChain* g_swapchain = NULL;
|
||||
static ID3D11RenderTargetView* g_render_target = NULL;
|
||||
|
||||
bool create_device(HWND hwnd)
|
||||
{
|
||||
// Setup a swapchain
|
||||
// create swapchain
|
||||
DXGI_SWAP_CHAIN_DESC sd;
|
||||
ZeroMemory(&sd, sizeof(sd));
|
||||
sd.BufferCount = 2;
|
||||
sd.BufferDesc.Width = 0;
|
||||
sd.BufferDesc.Height = 0;
|
||||
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
sd.BufferDesc.RefreshRate.Numerator = 60;
|
||||
sd.BufferDesc.RefreshRate.Denominator = 1;
|
||||
sd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
|
||||
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
||||
sd.OutputWindow = hwnd;
|
||||
sd.SampleDesc.Count = 1;
|
||||
sd.SampleDesc.Quality = 0;
|
||||
sd.Windowed = TRUE;
|
||||
sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
|
||||
|
||||
return false;
|
||||
D3D_FEATURE_LEVEL featureLevel;
|
||||
const D3D_FEATURE_LEVEL featureLevelArray[2] = {
|
||||
D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_0,
|
||||
};
|
||||
|
||||
if (D3D11CreateDeviceAndSwapChain(
|
||||
NULL, D3D_DRIVER_TYPE_HARDWARE, NULL,0, featureLevelArray,
|
||||
2, D3D11_SDK_VERSION, &sd, &g_swapchain, &g_device, &featureLevel, &g_context) != S_OK)
|
||||
return false;
|
||||
|
||||
// create render target
|
||||
ID3D11Texture2D* pBackBuffer = nullptr;
|
||||
g_swapchain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer));
|
||||
|
||||
if (!pBackBuffer)
|
||||
return false;
|
||||
|
||||
g_device->CreateRenderTargetView(pBackBuffer, NULL, &g_render_target);
|
||||
pBackBuffer->Release();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void cleanup()
|
||||
|
Loading…
Reference in New Issue
Block a user