本文整理汇总了C++中IDXGIAdapter1::Release方法的典型用法代码示例。如果您正苦于以下问题:C++ IDXGIAdapter1::Release方法的具体用法?C++ IDXGIAdapter1::Release怎么用?C++ IDXGIAdapter1::Release使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDXGIAdapter1
的用法示例。
在下文中一共展示了IDXGIAdapter1::Release方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
void DesktopDuplication::init()
{
IDXGIFactory1* dxgiFactory = nullptr;
CHECKED(hr, CreateDXGIFactory1(__uuidof(IDXGIFactory1), reinterpret_cast<void**>(&dxgiFactory)));
IDXGIAdapter1* dxgiAdapter = nullptr;
CHECKED(hr, dxgiFactory->EnumAdapters1(adapter, &dxgiAdapter));
dxgiFactory->Release();
CHECKED(hr, D3D11CreateDevice(dxgiAdapter,
D3D_DRIVER_TYPE_UNKNOWN,
NULL,
NULL,
NULL,
NULL,
D3D11_SDK_VERSION,
&d3dDevice,
NULL,
&d3dContext));
IDXGIOutput* dxgiOutput = nullptr;
CHECKED(hr, dxgiAdapter->EnumOutputs(output, &dxgiOutput));
dxgiAdapter->Release();
IDXGIOutput1* dxgiOutput1 = nullptr;
CHECKED(hr, dxgiOutput->QueryInterface(__uuidof(dxgiOutput1), reinterpret_cast<void**>(&dxgiOutput1)));
dxgiOutput->Release();
IDXGIDevice* dxgiDevice = nullptr;
CHECKED(hr, d3dDevice->QueryInterface(__uuidof(IDXGIDevice), reinterpret_cast<void**>(&dxgiDevice)));
CHECKED(hr, dxgiOutput1->DuplicateOutput(dxgiDevice, &outputDuplication));
dxgiOutput1->Release();
dxgiDevice->Release();
}
示例2: GetDisplayDevices
void GetDisplayDevices(DeviceOutputs &deviceList)
{
HRESULT err;
deviceList.ClearData();
#ifdef USE_DXGI1_2
REFIID iidVal = OSGetVersion() >= 8 ? __uuidof(IDXGIFactory2) : __uuidof(IDXGIFactory1);
#else
REFIIF iidVal = __uuidof(IDXGIFactory1);
#endif
IDXGIFactory1 *factory;
if(SUCCEEDED(err = CreateDXGIFactory1(iidVal, (void**)&factory)))
{
UINT i=0;
IDXGIAdapter1 *giAdapter;
while(factory->EnumAdapters1(i++, &giAdapter) == S_OK)
{
Log(TEXT("------------------------------------------"));
DXGI_ADAPTER_DESC adapterDesc;
if(SUCCEEDED(err = giAdapter->GetDesc(&adapterDesc)))
{
if (adapterDesc.DedicatedVideoMemory != 0) {
DeviceOutputData &deviceData = *deviceList.devices.CreateNew();
deviceData.strDevice = adapterDesc.Description;
UINT j=0;
IDXGIOutput *giOutput;
while(giAdapter->EnumOutputs(j++, &giOutput) == S_OK)
{
DXGI_OUTPUT_DESC outputDesc;
if(SUCCEEDED(giOutput->GetDesc(&outputDesc)))
{
if(outputDesc.AttachedToDesktop)
{
deviceData.monitorNameList << outputDesc.DeviceName;
MonitorInfo &monitorInfo = *deviceData.monitors.CreateNew();
monitorInfo.hMonitor = outputDesc.Monitor;
mcpy(&monitorInfo.rect, &outputDesc.DesktopCoordinates, sizeof(RECT));
}
}
giOutput->Release();
}
}
}
else
AppWarning(TEXT("Could not query adapter %u"), i);
giAdapter->Release();
}
factory->Release();
}
}
示例3: LogVideoCardStats
void LogVideoCardStats()
{
HRESULT err;
#ifdef USE_DXGI1_2
REFIID iidVal = OSGetVersion() >= 8 ? __uuidof(IDXGIFactory2) : __uuidof(IDXGIFactory1);
#else
REFIIF iidVal = __uuidof(IDXGIFactory1);
#endif
IDXGIFactory1 *factory;
if(SUCCEEDED(err = CreateDXGIFactory1(iidVal, (void**)&factory)))
{
UINT i=0;
IDXGIAdapter1 *giAdapter;
while(factory->EnumAdapters1(i++, &giAdapter) == S_OK)
{
DXGI_ADAPTER_DESC adapterDesc;
if(SUCCEEDED(err = giAdapter->GetDesc(&adapterDesc)))
{
if (!(adapterDesc.VendorId == 0x1414 && adapterDesc.DeviceId == 0x8c)) { // Ignore Microsoft Basic Render Driver
Log(TEXT("------------------------------------------"));
Log(TEXT("Adapter %u"), i);
Log(TEXT(" Video Adapter: %s"), adapterDesc.Description);
Log(TEXT(" Video Adapter Dedicated Video Memory: %u"), adapterDesc.DedicatedVideoMemory);
Log(TEXT(" Video Adapter Shared System Memory: %u"), adapterDesc.SharedSystemMemory);
UINT j = 0;
IDXGIOutput *output;
while(SUCCEEDED(giAdapter->EnumOutputs(j++, &output)))
{
DXGI_OUTPUT_DESC desc;
if(SUCCEEDED(output->GetDesc(&desc)))
Log(TEXT(" Video Adapter Output %u: pos={%d, %d}, size={%d, %d}, attached=%s"), j,
desc.DesktopCoordinates.left, desc.DesktopCoordinates.top,
desc.DesktopCoordinates.right-desc.DesktopCoordinates.left, desc.DesktopCoordinates.bottom-desc.DesktopCoordinates.top,
desc.AttachedToDesktop ? L"true" : L"false");
output->Release();
}
}
}
else
AppWarning(TEXT("Could not query adapter %u"), i);
giAdapter->Release();
}
factory->Release();
}
}
示例4: FindAdapter
bool CRenderer::FindAdapter(IDXGIFactory1** factory, IDXGIAdapter1** adapter)
{
HRESULT hr = S_OK;
IDXGIAdapter1 * pCurrentAdapter = nullptr;
DXGI_ADAPTER_DESC1 Bestdesc;
if (!factory) {
Log("Cannot send in a NULL factory");
return false;
}
if (!adapter) {
Log("Cannot send in a NULL adapter");
return false;
}
// Create a factory to enumerate all of the hardware in the system.
DXCall(hr = CreateDXGIFactory1(__uuidof(IDXGIFactory), reinterpret_cast<void**>(factory)));
#pragma warning(suppress: 6102)
if (!*factory) {
Log("Could not create the factory");
return false;
}
unsigned int index = 0;
while (DXGI_ERROR_NOT_FOUND != (*factory)->EnumAdapters1(index++, &pCurrentAdapter)) {
DXGI_ADAPTER_DESC1 desc;
ZeroMemory(&desc, sizeof(desc));
DXCall(pCurrentAdapter->GetDesc1(&desc));
if (nullptr == *adapter) {
*adapter = pCurrentAdapter;
Bestdesc = desc;
}
else if (Bestdesc.DedicatedSystemMemory < desc.DedicatedSystemMemory) {
(*adapter)->Release();
*adapter = pCurrentAdapter;
Bestdesc = desc;
}
else {
pCurrentAdapter->Release();
}
}
return true;
}
示例5: LogVideoCardStats
void LogVideoCardStats()
{
HRESULT err;
#ifdef USE_DXGI1_2
REFIID iidVal = OSGetVersion() >= 8 ? __uuidof(IDXGIFactory2) : __uuidof(IDXGIFactory1);
#else
REFIIF iidVal = __uuidof(IDXGIFactory1);
#endif
IDXGIFactory1 *factory;
if(SUCCEEDED(err = CreateDXGIFactory1(iidVal, (void**)&factory)))
{
UINT i=0;
IDXGIAdapter1 *giAdapter;
while(factory->EnumAdapters1(i++, &giAdapter) == S_OK)
{
DXGI_ADAPTER_DESC adapterDesc;
if(SUCCEEDED(err = giAdapter->GetDesc(&adapterDesc)))
{
if (adapterDesc.DedicatedVideoMemory > 0) {
Log(TEXT("------------------------------------------"));
Log(TEXT("Adapter %u"), i);
Log(TEXT(" Video Adapter: %s"), adapterDesc.Description);
Log(TEXT(" Video Adapter Dedicated Video Memory: %u"), adapterDesc.DedicatedVideoMemory);
Log(TEXT(" Video Adapter Shared System Memory: %u"), adapterDesc.SharedSystemMemory);
}
}
else
AppWarning(TEXT("Could not query adapter %u"), i);
giAdapter->Release();
}
factory->Release();
}
}
示例6: OSGetVersion
D3D10System::D3D10System()
{
HRESULT err;
#ifdef USE_DXGI1_2
REFIID iidVal = OSGetVersion() >= 8 ? __uuidof(IDXGIFactory2) : __uuidof(IDXGIFactory1);
#else
REFIID iidVal = __uuidof(IDXGIFactory1);
#endif
UINT adapterID = GlobalConfig->GetInt(TEXT("Video"), TEXT("Adapter"), 0);
IDXGIFactory1 *factory;
if(FAILED(err = CreateDXGIFactory1(iidVal, (void**)&factory)))
CrashError(TEXT("Could not create DXGI factory"));
IDXGIAdapter1 *adapter;
if(FAILED(err = factory->EnumAdapters1(adapterID, &adapter)))
CrashError(TEXT("Could not get DXGI adapter"));
//------------------------------------------------------------------
DXGI_SWAP_CHAIN_DESC swapDesc;
zero(&swapDesc, sizeof(swapDesc));
swapDesc.BufferCount = 2;
swapDesc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
swapDesc.BufferDesc.Width = App->renderFrameWidth;
swapDesc.BufferDesc.Height = App->renderFrameHeight;
swapDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapDesc.Flags = 0;
swapDesc.OutputWindow = hwndRenderFrame;
swapDesc.SampleDesc.Count = 1;
swapDesc.Windowed = TRUE;
bDisableCompatibilityMode = 1;//AppConfig->GetInt(TEXT("Video"), TEXT("DisableD3DCompatibilityMode"), 1) != 0;
UINT createFlags = D3D10_CREATE_DEVICE_BGRA_SUPPORT;
if(GlobalConfig->GetInt(TEXT("General"), TEXT("UseDebugD3D")))
createFlags |= D3D10_CREATE_DEVICE_DEBUG;
D3D10_FEATURE_LEVEL1 level = bDisableCompatibilityMode ? D3D10_FEATURE_LEVEL_10_1 : D3D10_FEATURE_LEVEL_9_3;
//D3D10_CREATE_DEVICE_DEBUG
//D3D11_DRIVER_TYPE_REFERENCE, D3D11_DRIVER_TYPE_HARDWARE
err = D3D10CreateDeviceAndSwapChain1(adapter, D3D10_DRIVER_TYPE_HARDWARE, NULL, createFlags, level, D3D10_1_SDK_VERSION, &swapDesc, &swap, &d3d);
if(FAILED(err))
{
bDisableCompatibilityMode = !bDisableCompatibilityMode;
level = bDisableCompatibilityMode ? D3D10_FEATURE_LEVEL_10_1 : D3D10_FEATURE_LEVEL_9_3;
err = D3D10CreateDeviceAndSwapChain1(adapter, D3D10_DRIVER_TYPE_HARDWARE, NULL, createFlags, level, D3D10_1_SDK_VERSION, &swapDesc, &swap, &d3d);
}
if(FAILED(err))
CrashError(TEXT("Could not create D3D10 device and swap chain. This error can happen for one of the following reasons:\r\n\r\n1.) Your GPU is not supported (DirectX 10 support is required - many integrated laptop GPUs do not support DX10)\r\n2.) You're running Windows Vista without the \"Platform Update\"\r\n3.) Your video card drivers are out of date"));
adapter->Release();
factory->Release();
//------------------------------------------------------------------
Log(TEXT("Loading up D3D10..."));
D3D10_DEPTH_STENCIL_DESC depthDesc;
zero(&depthDesc, sizeof(depthDesc));
depthDesc.DepthEnable = FALSE;
err = d3d->CreateDepthStencilState(&depthDesc, &depthState);
if(FAILED(err))
CrashError(TEXT("Unable to create depth state"));
d3d->OMSetDepthStencilState(depthState, 0);
//------------------------------------------------------------------
D3D10_RASTERIZER_DESC rasterizerDesc;
zero(&rasterizerDesc, sizeof(rasterizerDesc));
rasterizerDesc.FillMode = D3D10_FILL_SOLID;
rasterizerDesc.CullMode = D3D10_CULL_NONE;
rasterizerDesc.FrontCounterClockwise = FALSE;
rasterizerDesc.DepthClipEnable = TRUE;
err = d3d->CreateRasterizerState(&rasterizerDesc, &rasterizerState);
if(FAILED(err))
CrashError(TEXT("Unable to create rasterizer state"));
d3d->RSSetState(rasterizerState);
//------------------------------------------------------------------
rasterizerDesc.ScissorEnable = TRUE;
err = d3d->CreateRasterizerState(&rasterizerDesc, &scissorState);
if(FAILED(err))
CrashError(TEXT("Unable to create scissor state"));
//------------------------------------------------------------------
ID3D10Texture2D *backBuffer = NULL;
err = swap->GetBuffer(0, IID_ID3D10Texture2D, (void**)&backBuffer);
if(FAILED(err))
//.........这里部分代码省略.........
示例7: offscreen_tex_desc
bool D3DApp::InitializeD3D()
{
// describe our SwapChain Buffer
DXGI_MODE_DESC mode_desc;
ZeroMemory(&mode_desc, sizeof(DXGI_MODE_DESC));
mode_desc.Width = m_width;
mode_desc.Height = m_height;
mode_desc.RefreshRate.Numerator = 60;
mode_desc.RefreshRate.Denominator = 1;
mode_desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
mode_desc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
mode_desc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
// describe our SwapChain
DXGI_SWAP_CHAIN_DESC swapchain_desc;
ZeroMemory(&swapchain_desc, sizeof(DXGI_SWAP_CHAIN_DESC));
swapchain_desc.BufferDesc = mode_desc;
swapchain_desc.SampleDesc.Count = 1;
swapchain_desc.SampleDesc.Quality = 0;
swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapchain_desc.BufferCount = 1;
swapchain_desc.OutputWindow = m_hwnd;
swapchain_desc.Windowed = TRUE;
swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
// create DXGI factory to enumerate adapters
IDXGIFactory1 *dxgi_factory;
HRESULT hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&dxgi_factory);
// use the first adapter
IDXGIAdapter1 *adapter;
hr = dxgi_factory->EnumAdapters1(0, &adapter);
dxgi_factory->Release();
// create our Direct3D 11 Device and SwapChain
hr = D3D11CreateDeviceAndSwapChain(adapter, D3D_DRIVER_TYPE_UNKNOWN, NULL, D3D11_CREATE_DEVICE_BGRA_SUPPORT,
NULL, NULL, D3D11_SDK_VERSION, &swapchain_desc, &m_swap_chain, &m_d3d11_device, NULL, &m_d3d11_device_context);
// initialize Direct2D, Direct3D 10.1, DirectWrite
InitializeDWrite(adapter);
// release the Adapter interface
adapter->Release();
// create our BackBuffer and Render Target
hr = m_swap_chain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&m_back_buffer);
hr = m_d3d11_device->CreateRenderTargetView(m_back_buffer, NULL, &m_back_buffer_rtv);
// describe our Depth/Stencil Buffer
D3D11_TEXTURE2D_DESC depthstencil_desc;
depthstencil_desc.Width = m_width;
depthstencil_desc.Height = m_height;
depthstencil_desc.MipLevels = 1;
depthstencil_desc.ArraySize = 1;
depthstencil_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
depthstencil_desc.SampleDesc.Count = 1;
depthstencil_desc.SampleDesc.Quality = 0;
depthstencil_desc.Usage = D3D11_USAGE_DEFAULT;
depthstencil_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
depthstencil_desc.CPUAccessFlags = 0;
depthstencil_desc.MiscFlags = 0;
// create the Depth/Stencil View
m_d3d11_device->CreateTexture2D(&depthstencil_desc, NULL, &m_depthstencil_buffer);
m_d3d11_device->CreateDepthStencilView(m_depthstencil_buffer, NULL, &m_depthstencil_view);
// set render target views and depth stencil view
m_d3d11_device_context->OMSetRenderTargets(1, &m_back_buffer_rtv, m_depthstencil_view);
// create a shader resource review from the texture D2D will render to
hr = m_d3d11_device->CreateShaderResourceView(m_shared_texture, NULL, &m_d2d_texture);
// create off-screen textures
CD3D11_TEXTURE2D_DESC offscreen_tex_desc(DXGI_FORMAT_R16G16B16A16_FLOAT, m_width, m_height);
offscreen_tex_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
offscreen_tex_desc.MipLevels = 1;
for (int i = 0; i != ARRAYSIZE(m_offscreen_textures); ++i)
{
m_d3d11_device->CreateTexture2D(&offscreen_tex_desc, NULL, &m_offscreen_textures[i]);
m_d3d11_device->CreateShaderResourceView(m_offscreen_textures[i], NULL, &m_offscreen_srvs[i]);
m_d3d11_device->CreateRenderTargetView(m_offscreen_textures[i], NULL, &m_offscreen_rtvs[i]);
}
// create a constant buffer
D3D11_BUFFER_DESC buffer_desc;
ZeroMemory(&buffer_desc, sizeof(D3D11_BUFFER_DESC));
buffer_desc.Usage = D3D11_USAGE_DYNAMIC;
buffer_desc.ByteWidth = sizeof(ShaderParameters);
buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
buffer_desc.MiscFlags = 0;
hr = m_d3d11_device->CreateBuffer(&buffer_desc, NULL, &m_parameter_buffer);
buffer_desc.ByteWidth = sizeof(float4);
hr = m_d3d11_device->CreateBuffer(&buffer_desc, NULL, &m_jitter_buffer);
hr = m_d3d11_device->CreateBuffer(&buffer_desc, NULL, &m_interleave_buffer);
// create a texture from file
D3DX11CreateShaderResourceViewFromFile(m_d3d11_device, TEXT("media/tex.bmp"), NULL, NULL, &m_custom_texture, &hr);
//.........这里部分代码省略.........
示例8: Close
bool DXGI1Device::Init(const mfxU32 adapterNum)
{
// release the object before initialization
Close();
// load up the library if it is not loaded
if (NULL == m_hModule)
{
LoadDLLModule(L"dxgi.dll");
}
if (m_hModule)
{
DXGICreateFactoryFunc pFunc;
IDXGIFactory1 *pFactory;
IDXGIAdapter1 *pAdapter;
DXGI_ADAPTER_DESC1 desc;
mfxU32 curAdapter, maxAdapters;
HRESULT hRes;
// load address of procedure to create DXGI 1.1 factory
pFunc = (DXGICreateFactoryFunc) GetProcAddress(m_hModule, "CreateDXGIFactory1");
if (NULL == pFunc)
{
return false;
}
// create the factory
#if _MSC_VER >= 1400
hRes = pFunc(__uuidof(IDXGIFactory1), (void**) (&pFactory));
#else
hRes = pFunc(IID_IDXGIFactory1, (void**) (&pFactory));
#endif
if (FAILED(hRes))
{
return false;
}
m_pDXGIFactory1 = pFactory;
// get the number of adapters
curAdapter = 0;
maxAdapters = 0;
mfxU32 outputs = 0;
do
{
// get the required adapted
hRes = pFactory->EnumAdapters1(curAdapter, &pAdapter);
if (FAILED(hRes))
{
break;
}
mfxU32 curOutput = 0;
HRESULT h;
do
{
IDXGIOutput *out;
h = pAdapter->EnumOutputs(curOutput, &out);
if(FAILED(h))
break;
// if it is the required adapter, save the interface
if (outputs == adapterNum)
m_pDXGIAdapter1 = pAdapter;
out->Release();
outputs += 1;
curOutput += 1;
} while(!m_pDXGIAdapter1 && SUCCEEDED(h));
if(!m_pDXGIAdapter1)
pAdapter->Release();
curAdapter += 1;
} while (!m_pDXGIAdapter1 && SUCCEEDED(hRes));
maxAdapters = curAdapter;
// there is no required adapter
if (adapterNum >= outputs)
{
return false;
}
pAdapter = (IDXGIAdapter1 *) m_pDXGIAdapter1;
// get the adapter's parameters
hRes = pAdapter->GetDesc1(&desc);
if (FAILED(hRes))
{
return false;
}
// save the parameters
m_vendorID = desc.VendorId;
m_deviceID = desc.DeviceId;
*((LUID *) &m_luid) = desc.AdapterLuid;
}
//.........这里部分代码省略.........
示例9: DoD3D11Hook
bool DoD3D11Hook(ID3D11Device *device)
{
HRESULT hErr;
bD3D101Hooked = true;
HMODULE hD3D10_1 = LoadLibrary(TEXT("d3d10_1.dll"));
if(!hD3D10_1)
{
RUNONCE logOutput << "DoD3D11Hook: could not load d3d10.1" << endl;
return false;
}
HMODULE hDXGI = GetModuleHandle(TEXT("dxgi.dll"));
if(!hDXGI)
{
RUNONCE logOutput << "DoD3D11Hook: could not load dxgi" << endl;
return false;
}
CREATEDXGIFACTORY1PROC createDXGIFactory1 = (CREATEDXGIFACTORY1PROC)GetProcAddress(hDXGI, "CreateDXGIFactory1");
if(!createDXGIFactory1)
{
RUNONCE logOutput << "DoD3D11Hook: could not get address of CreateDXGIFactory1" << endl;
return false;
}
PFN_D3D10_CREATE_DEVICE1 d3d10CreateDevice1 = (PFN_D3D10_CREATE_DEVICE1)GetProcAddress(hD3D10_1, "D3D10CreateDevice1");
if(!d3d10CreateDevice1)
{
RUNONCE logOutput << "DoD3D11Hook: could not get address of D3D10CreateDevice1" << endl;
return false;
}
IDXGIFactory1 *factory;
if(FAILED(hErr = (*createDXGIFactory1)(__uuidof(IDXGIFactory1), (void**)&factory)))
{
RUNONCE logOutput << "DoD3D11Hook: CreateDXGIFactory1 failed, result = " << UINT(hErr) << endl;
return false;
}
IDXGIAdapter1 *adapter;
if(FAILED(hErr = factory->EnumAdapters1(0, &adapter)))
{
RUNONCE logOutput << "DoD3D11Hook: factory->EnumAdapters1 failed, result = " << UINT(hErr) << endl;
factory->Release();
return false;
}
if(FAILED(hErr = (*d3d10CreateDevice1)(adapter, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, D3D10_FEATURE_LEVEL_10_1, D3D10_1_SDK_VERSION, &shareDevice)))
{
if(FAILED(hErr = (*d3d10CreateDevice1)(adapter, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, D3D10_FEATURE_LEVEL_9_3, D3D10_1_SDK_VERSION, &shareDevice)))
{
RUNONCE logOutput << "DoD3D11Hook: device creation failed, result = " << UINT(hErr) << endl;
adapter->Release();
factory->Release();
return false;
}
}
adapter->Release();
factory->Release();
//------------------------------------------------
D3D11_TEXTURE2D_DESC texGameDesc;
ZeroMemory(&texGameDesc, sizeof(texGameDesc));
texGameDesc.Width = d3d11CaptureInfo.cx;
texGameDesc.Height = d3d11CaptureInfo.cy;
texGameDesc.MipLevels = 1;
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;
ID3D11Texture2D *d3d11Tex;
if(FAILED(hErr = device->CreateTexture2D(&texGameDesc, NULL, &d3d11Tex)))
{
RUNONCE logOutput << "DoD3D11Hook: creation of intermediary texture failed, result = " << UINT(hErr) << endl;
return false;
}
if(FAILED(hErr = d3d11Tex->QueryInterface(__uuidof(ID3D11Resource), (void**)©TextureGame)))
{
RUNONCE logOutput << "DoD3D11Hook: d3d11Tex->QueryInterface(ID3D11Resource) failed, result = " << UINT(hErr) << endl;
d3d11Tex->Release();
return false;
}
IDXGIResource *res;
if(FAILED(hErr = d3d11Tex->QueryInterface(IID_IDXGIResource, (void**)&res)))
{
RUNONCE logOutput << "DoD3D11Hook: d3d11Tex->QueryInterface(IID_IDXGIResource) failed, result = " << UINT(hErr) << endl;
d3d11Tex->Release();
return false;
}
HANDLE handle;
if(FAILED(hErr = res->GetSharedHandle(&handle)))
//.........这里部分代码省略.........
示例10: getTitle
//.........这里部分代码省略.........
wRect.top = 0;
wRect.bottom = height;
AdjustWindowRect(&wRect, wndFlags, FALSE);
MONITORINFO monInfo;
monInfo.cbSize = sizeof(monInfo);
GetMonitorInfo(oDesc.Monitor, &monInfo);
w = min(wRect.right - wRect.left, monInfo.rcWork.right - monInfo.rcWork.left);
h = min(wRect.bottom - wRect.top, monInfo.rcWork.bottom - monInfo.rcWork.top);
x = (monInfo.rcWork.left + monInfo.rcWork.right - w) / 2;
y = (monInfo.rcWork.top + monInfo.rcWork.bottom - h) / 2;
}
hwnd = CreateWindow("Game", str, wndFlags, x, y, w, h, HWND_DESKTOP, NULL, hInstance, NULL);
RECT rect;
GetClientRect(hwnd, &rect);
// Create device and swap chain
DWORD deviceFlags = D3D11_CREATE_DEVICE_SINGLETHREADED;
#ifdef _DEBUG
deviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
D3D_FEATURE_LEVEL requested_feature_level = (api_revision == D3D11)? D3D_FEATURE_LEVEL_11_0 : (api_revision == D3D11_1)? D3D_FEATURE_LEVEL_10_1 : D3D_FEATURE_LEVEL_10_0;
D3D_FEATURE_LEVEL feature_level;
if (FAILED(D3D11CreateDevice(dxgiAdapter, D3D_DRIVER_TYPE_UNKNOWN, NULL, deviceFlags, &requested_feature_level, 1, D3D11_SDK_VERSION, &device, &feature_level, &context)))
{
ErrorMsg("Couldn't create D3D11 device");
return false;
}
while (msaaSamples > 0)
{
UINT nQuality;
if (SUCCEEDED(device->CheckMultisampleQualityLevels(backBufferFormat, msaaSamples, &nQuality)) && nQuality > 0)
{
if ((flags & NO_SETTING_CHANGE) == 0) antiAliasSamples = msaaSamples;
break;
}
else
{
msaaSamples -= 2;
}
}
DXGI_SWAP_CHAIN_DESC sd;
memset(&sd, 0, sizeof(sd));
sd.BufferDesc.Width = rect.right;
sd.BufferDesc.Height = rect.bottom;
sd.BufferDesc.Format = backBufferFormat;
sd.BufferDesc.RefreshRate = fullScreenRefresh;
sd.BufferUsage = /*DXGI_USAGE_BACK_BUFFER | */DXGI_USAGE_RENDER_TARGET_OUTPUT | (sampleBackBuffer? DXGI_USAGE_SHADER_INPUT : 0);
sd.BufferCount = 1;
sd.OutputWindow = hwnd;
sd.Windowed = (BOOL) (!fullscreen);
sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
sd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
sd.SampleDesc.Count = msaaSamples;
sd.SampleDesc.Quality = 0;
if (FAILED(dxgiFactory->CreateSwapChain(device, &sd, &swapChain)))
{
ErrorMsg("Couldn't create swapchain");
return false;
}
// We'll handle Alt-Enter ourselves thank you very much ...
dxgiFactory->MakeWindowAssociation(hwnd, DXGI_MWA_NO_WINDOW_CHANGES | DXGI_MWA_NO_ALT_ENTER);
dxgiOutput->Release();
dxgiAdapter->Release();
dxgiFactory->Release();
if (fullscreen)
{
captureMouse(!configDialog->isVisible());
}
renderer = new Direct3D11Renderer(device, context);
if (!createBuffers(sampleBackBuffer))
{
delete renderer;
return false;
}
antiAlias->selectItem(antiAliasSamples / 2);
linearClamp = renderer->addSamplerState(LINEAR, CLAMP, CLAMP, CLAMP);
defaultFont = renderer->addFont("../Textures/Fonts/Future.dds", "../Textures/Fonts/Future.font", linearClamp);
blendSrcAlpha = renderer->addBlendState(SRC_ALPHA, ONE_MINUS_SRC_ALPHA);
noDepthTest = renderer->addDepthState(false, false);
noDepthWrite = renderer->addDepthState(true, false);
cullNone = renderer->addRasterizerState(CULL_NONE);
cullBack = renderer->addRasterizerState(CULL_BACK);
cullFront = renderer->addRasterizerState(CULL_FRONT);
return true;
}
示例11: sizeof
bool D3DApp::InitializeDirect3d11App(HINSTANCE hInstance)
{
//Describe our Buffer
DXGI_MODE_DESC bufferDesc;
ZeroMemory(&bufferDesc, sizeof(DXGI_MODE_DESC));
bufferDesc.Width = Width;
bufferDesc.Height = Height;
bufferDesc.RefreshRate.Numerator = 60;
bufferDesc.RefreshRate.Denominator = 1;
bufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
bufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
bufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
//Describe our SwapChain
DXGI_SWAP_CHAIN_DESC swapChainDesc;
ZeroMemory(&swapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
swapChainDesc.BufferDesc = bufferDesc;
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.BufferCount = 1;
swapChainDesc.OutputWindow = hwnd;
swapChainDesc.Windowed = TRUE;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
// Create DXGI factory to enumerate adapters///////////////////////////////////////////////////////////////////////////
IDXGIFactory1 *DXGIFactory;
HRESULT hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&DXGIFactory);
// Use the first adapter
IDXGIAdapter1 *Adapter;
hr = DXGIFactory->EnumAdapters1(0, &Adapter);
DXGIFactory->Release();
//Create our Direct3D 11 Device and SwapChain//////////////////////////////////////////////////////////////////////////
hr = D3D11CreateDeviceAndSwapChain(Adapter, D3D_DRIVER_TYPE_UNKNOWN, NULL, D3D11_CREATE_DEVICE_DEBUG | D3D11_CREATE_DEVICE_BGRA_SUPPORT,
NULL, NULL, D3D11_SDK_VERSION, &swapChainDesc, &SwapChain, &d3d11Device, NULL, &d3d11DevCon);
//Initialize Direct2D, Direct3D 10.1, DirectWrite
InitD2D_D3D101_DWrite(Adapter);
//Release the Adapter interface
Adapter->Release();
//Create our BackBuffer and Render Target
hr = SwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&BackBuffer11);
hr = d3d11Device->CreateRenderTargetView(BackBuffer11, NULL, &renderTargetView);
//Describe our Depth/Stencil Buffer
D3D11_TEXTURE2D_DESC depthStencilDesc;
depthStencilDesc.Width = Width;
depthStencilDesc.Height = Height;
depthStencilDesc.MipLevels = 1;
depthStencilDesc.ArraySize = 1;
depthStencilDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
depthStencilDesc.SampleDesc.Count = 1;
depthStencilDesc.SampleDesc.Quality = 0;
depthStencilDesc.Usage = D3D11_USAGE_DEFAULT;
depthStencilDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
depthStencilDesc.CPUAccessFlags = 0;
depthStencilDesc.MiscFlags = 0;
//Create the Depth/Stencil View
d3d11Device->CreateTexture2D(&depthStencilDesc, NULL, &depthStencilBuffer);
d3d11Device->CreateDepthStencilView(depthStencilBuffer, NULL, &depthStencilView);
return true;
}
示例12: if
DeviceManager::DeviceManager(void)
: m_pd3dDevice(NULL),
m_pImmediateContext(NULL),
m_pDXGIFactory1(NULL)
{
// create DXGIFactory, d3d device
HRESULT hr = S_OK;
// create dxgi factory and keep it for future use.
hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)(&m_pDXGIFactory1) );
if (Logger::IsFailureLog(hr))
{
return;
}
IDXGIAdapter1* pAdapter;
// hardware vendor ID
uint32_t nvidia = 0x10DE; // NVIDIA Corporation
uint32_t ati = 0x1002; // ATI Technologies Inc. / Advanced Micro Devices, Inc.
int i = 0;
int adapterIndex = 0;
printf("Available DXGIAdapters:\n");
while(m_pDXGIFactory1->EnumAdapters1(i, &pAdapter) != DXGI_ERROR_NOT_FOUND)
{
DXGI_ADAPTER_DESC1 descr;
pAdapter->GetDesc1(&descr);
wprintf(L"\t%s\n",descr.Description);
// choose discrete graphics over integrated.
if(adapterIndex == 0 && (descr.VendorId == nvidia || descr.VendorId == ati))
{
adapterIndex = i;
}
i++;
pAdapter->Release();
pAdapter = NULL;
}
hr = m_pDXGIFactory1->EnumAdapters1(adapterIndex, &pAdapter);
if (Logger::IsFailureLog(hr))
{
return;
}
UINT createDeviceFlags = 0;
#ifdef _DEBUG
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
/*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_ADAPTER_DESC1 pdescr;
pAdapter->GetDesc1(&pdescr);
Logger::Log(OutputMessageType::Info, L"%s\n",pdescr.Description);
// Note: If you set the pAdapter parameter to a non-NULL value,
// you must also set the DriverType parameter
// to the D3D_DRIVER_TYPE_UNKNOWN
// create d3d11 device on the first graphics adapter.
hr = D3D11CreateDevice(
pAdapter,
D3D_DRIVER_TYPE_UNKNOWN,
NULL,
createDeviceFlags,
featureLevels,
numFeatureLevels,
D3D11_SDK_VERSION,
&m_pd3dDevice,
NULL,
&m_pImmediateContext);
pAdapter->Release(); // no longer needed.
if (Logger::IsFailureLog(hr))
{
return;
}
//.........这里部分代码省略.........
示例13: init
bool RenderSystem::init(void* windowHandle, const InitParams& params)
{
IDXGIFactory1* factory = 0;
IDXGIOutput* output = 0;
DXGI_MODE_DESC modeDesc;
::ZeroMemory(&modeDesc, sizeof(DXGI_MODE_DESC));
modeDesc.Format = params.srgbTarget ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB : DXGI_FORMAT_R8G8B8A8_UNORM;
modeDesc.Width = params.width;
modeDesc.Height = params.height;
if (SUCCEEDED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&factory)))
{
IDXGIAdapter1* adapter = 0;
for (UINT i = 0; factory->EnumAdapters1(i, &adapter) != DXGI_ERROR_NOT_FOUND; ++i)
{
if (adapter->CheckInterfaceSupport(__uuidof(ID3D11Device), NULL))
break;
adapter->Release();
}
D3D_FEATURE_LEVEL supportedFeatureLevels[] =
{
D3D_FEATURE_LEVEL_11_0,
};
UINT flags = 0;
#if defined (_DEBUG)
flags |= D3D11_CREATE_DEVICE_DEBUG;
#endif // _DEBUG
if (adapter)
{
if (SUCCEEDED(D3D11CreateDevice(adapter, D3D_DRIVER_TYPE_UNKNOWN, NULL, flags, supportedFeatureLevels, _countof(supportedFeatureLevels),
D3D11_SDK_VERSION, &m_device, NULL, &m_renderContext)))
{
for (UINT i = 0; adapter->EnumOutputs(i, &output) != DXGI_ERROR_NOT_FOUND; ++i)
{
if (SUCCEEDED(output->FindClosestMatchingMode(&modeDesc, &modeDesc, m_device)))
{
// additional checks??
break;
}
output->Release();
output = 0;
}
/*if (output)
output->Release();*/
}
adapter->Release();
}
if (m_device)
{
DXGI_SWAP_CHAIN_DESC sd;
::ZeroMemory(&sd, sizeof(DXGI_SWAP_CHAIN_DESC));
sd.BufferCount = 1;
sd.BufferDesc = modeDesc;
sd.BufferUsage = D3D11_BIND_RENDER_TARGET;
sd.Flags = 0;
sd.OutputWindow = (HWND)windowHandle;
sd.SampleDesc.Quality = 0;
sd.SampleDesc.Count = 1;
sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
sd.Windowed = TRUE;
if (params.msaaSamples > 0)
{
UINT numLevels = 0;
if (SUCCEEDED(m_device->CheckMultisampleQualityLevels(modeDesc.Format, params.msaaSamples, &numLevels)) && numLevels > 0)
{
sd.SampleDesc.Quality = numLevels-1;
sd.SampleDesc.Count = params.msaaSamples;
}
else
{
printf("multisample quality not supported");
}
}
VALIDATE(factory->CreateSwapChain(m_device, &sd, &m_swapChain));
}
if (params.fullscreen)
{
m_isFullScreen = SUCCEEDED(m_swapChain->SetFullscreenState(TRUE, output));
}
// setup debug queue
factory->MakeWindowAssociation((HWND)windowHandle, DXGI_MWA_NO_ALT_ENTER | DXGI_MWA_NO_WINDOW_CHANGES);
if (output)
output->Release();
//.........这里部分代码省略.........
示例14: Init
bool RenderCore::Init(int screenWidth, int screenHeight, HWND hWnd)
{
HRESULT hr;
IDXGIAdapter1 *adapter;
IDXGIOutput *adapterOutput;
IDXGIOutput1 *adapterOutput1;
DXGI_ADAPTER_DESC adapterDesc;
DXGI_MODE_DESC *displayModeList;
DXGI_SWAP_CHAIN_DESC swapChainDesc;
ID3D11Texture2D *pBackBuffer;
D3D11_TEXTURE2D_DESC depthBufferDesc;
D3D11_DEPTH_STENCIL_DESC depthStencilDesc;
D3D11_DEPTH_STENCIL_DESC depthDisabledStencilDesc;
D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc;
D3D11_RASTERIZER_DESC rasterDesc;
uint32_t numModes, fpsNumerator, fpsDenominator;
size_t stringLength;
int error;
float fov, aspect;
if (!EnumerateDisplayAdapters(&g_DXGIAdapters)) {
return false;
}
adapter = g_DXGIAdapters.at(0);
hr = adapter->EnumOutputs(0, &adapterOutput);
if (FAILED(hr)) {
return false;
}
// desktop duplication stuff
hr = adapterOutput->QueryInterface(&adapterOutput1);
hr = adapterOutput1->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, nullptr);
if (FAILED(hr)) {
return false;
}
displayModeList = new DXGI_MODE_DESC[numModes];
if (!displayModeList) {
return false;
}
hr = adapterOutput1->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, displayModeList);
if (FAILED(hr)) {
return false;
}
for (UINT i = 0; i < numModes; i++) {
if (displayModeList[i].Width == (unsigned int)screenWidth) {
if (displayModeList[i].Height == (unsigned int)screenHeight) {
fpsNumerator = displayModeList[i].RefreshRate.Numerator;
fpsDenominator = displayModeList[i].RefreshRate.Denominator;
}
}
}
hr = adapter->GetDesc(&adapterDesc);
if (FAILED(hr)) {
return false;
}
// retrieve video adapter memory and name
m_VideoMemory = (int)(adapterDesc.DedicatedVideoMemory / 1024 / 1024);
error = wcstombs_s(&stringLength, m_VideoCardDesc, 128, adapterDesc.Description, 128);
if (error != 0) {
return false;
}
DebugOut("Found graphics adapter: %s (%dMB VRAM)\n", m_VideoCardDesc, m_VideoMemory);
delete[] displayModeList;
displayModeList = nullptr;
adapterOutput->Release();
adapter->Release();
// set single back buffer
ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));
swapChainDesc.BufferCount = 1;
swapChainDesc.BufferDesc.Width = screenWidth;
swapChainDesc.BufferDesc.Height = screenHeight;
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.OutputWindow = hWnd;
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.Windowed = true;
//swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
//swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
//swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
//swapChainDesc.Flags = 0;
//.........这里部分代码省略.........
示例15: DetectGpuInfo
void DetectGpuInfo(std::ostream& os)
{
#if defined KLAYGE_PLATFORM_WINDOWS
typedef HRESULT (WINAPI *CreateDXGIFactory1Func)(REFIID riid, void** ppFactory);
#if defined KLAYGE_PLATFORM_WINDOWS_DESKTOP
HMODULE dxgi = ::LoadLibraryEx(L"dxgi.dll", nullptr, 0);
if (!dxgi)
{
os << "Unknown GPU";
return;
}
CreateDXGIFactory1Func DynamicCreateDXGIFactory1 = (CreateDXGIFactory1Func)::GetProcAddress(dxgi, "CreateDXGIFactory1");
if (!DynamicCreateDXGIFactory1)
{
os << "Unknown GPU";
return;
}
#else
CreateDXGIFactory1Func DynamicCreateDXGIFactory1 = CreateDXGIFactory1;
#endif
IDXGIFactory1* factory;
if (SUCCEEDED((*DynamicCreateDXGIFactory1)(IID_IDXGIFactory1, reinterpret_cast<void**>(&factory))))
{
UINT adapter_no = 0;
IDXGIAdapter1* adapter = nullptr;
while (factory->EnumAdapters1(adapter_no, &adapter) != DXGI_ERROR_NOT_FOUND)
{
if (adapter != nullptr)
{
DXGI_ADAPTER_DESC1 adapter_desc;
adapter->GetDesc1(&adapter_desc);
IDXGIAdapter2* adapter2;
adapter->QueryInterface(IID_IDXGIAdapter2, reinterpret_cast<void**>(&adapter2));
if (adapter2 != nullptr)
{
DXGI_ADAPTER_DESC2 desc2;
adapter2->GetDesc2(&desc2);
memcpy(adapter_desc.Description, desc2.Description, sizeof(desc2.Description));
adapter_desc.VendorId = desc2.VendorId;
adapter_desc.DeviceId = desc2.DeviceId;
adapter_desc.SubSysId = desc2.SubSysId;
adapter_desc.Revision = desc2.Revision;
adapter_desc.DedicatedVideoMemory = desc2.DedicatedVideoMemory;
adapter_desc.DedicatedSystemMemory = desc2.DedicatedSystemMemory;
adapter_desc.SharedSystemMemory = desc2.SharedSystemMemory;
adapter_desc.AdapterLuid = desc2.AdapterLuid;
adapter_desc.Flags = desc2.Flags;
adapter2->Release();
}
adapter->Release();
if (adapter_desc.Flags != DXGI_ADAPTER_FLAG_SOFTWARE)
{
os << "Adapter " << adapter_no << endl << endl;
std::string description;
Convert(description, adapter_desc.Description);
os << "Brand: " << description << endl;
os << "Vendor ID: " << std::hex << std::uppercase << adapter_desc.VendorId << endl;
os << "Device ID: " << std::hex << std::uppercase << adapter_desc.DeviceId << endl;
os << "Revision: " << std::hex << std::uppercase << adapter_desc.Revision << endl;
os << "Dedicated video memory: " << std::dec << adapter_desc.DedicatedVideoMemory / 1024 / 1024 << " MB" << endl;
os << "Dedicated system memory: " << std::dec << adapter_desc.DedicatedSystemMemory / 1024 / 1024 << " MB" << endl;
os << "Shared system memory: " << std::dec << adapter_desc.SharedSystemMemory / 1024 / 1024 << " MB" << endl;
}
}
++ adapter_no;
}
}
#if defined KLAYGE_PLATFORM_WINDOWS_DESKTOP
::FreeLibrary(dxgi);
#endif
#else
os << "Unknown GPU" << endl;
#endif
}