IFACEMETHODIMP CanvasSwapChain::get_AlphaMode(CanvasAlphaMode* value) { return ExceptionBoundary( [&] { CheckInPointer(value); auto lock = GetResourceLock(); auto desc = GetSwapChainDesc(lock); *value = FromDxgiAlphaMode(desc.AlphaMode); }); }
IFACEMETHODIMP CanvasSwapChain::get_BufferCount(int32_t* value) { return ExceptionBoundary( [&] { CheckInPointer(value); auto lock = GetResourceLock(); auto desc = GetSwapChainDesc(lock); *value = desc.BufferCount; }); }
IFACEMETHODIMP CanvasSwapChain::get_Format(DirectXPixelFormat* value) { return ExceptionBoundary( [&] { CheckInPointer(value); auto lock = GetResourceLock(); auto desc = GetSwapChainDesc(lock); *value = static_cast<DirectXPixelFormat>(desc.Format); }); }
IFACEMETHODIMP CanvasSwapChain::get_SizeInPixels(BitmapSize* value) { return ExceptionBoundary( [&] { CheckInPointer(value); auto lock = GetResourceLock(); auto desc = GetSwapChainDesc(lock); *value = BitmapSize{ desc.Width, desc.Height }; }); }
IFACEMETHODIMP CanvasSwapChain::get_Size(Size* value) { return ExceptionBoundary( [&] { CheckInPointer(value); auto lock = GetResourceLock(); auto desc = GetSwapChainDesc(lock); *value = Size{ PixelsToDips(desc.Width, m_dpi), PixelsToDips(desc.Height, m_dpi) }; }); }
IFACEMETHODIMP CanvasSwapChain::ResizeBuffersWithWidthAndHeight( float newWidth, float newHeight) { return ExceptionBoundary( [&] { auto lock = GetResourceLock(); auto desc = GetSwapChainDesc(lock); ResizeBuffersImpl( lock, newWidth, newHeight, m_dpi, static_cast<DirectXPixelFormat>(desc.Format), desc.BufferCount); }); }
bool DXDriver::Init(Resolution _res) { HRESULT result; RenderTargetInit rti; #ifdef _PERFTRACK m_perfLib.Init(); // performance counter lib #endif D3D11_VIEWPORT viewport; // Query DXGI about system m_videoCardDescription = VNEW char[128]; result = QueryDXGI(_res, m_videoCardMemory, m_videoCardDescription); if (FAILED(result)) return false; // Create the swap chain, Direct3D device, and Direct3D device context. DXGI_SWAP_CHAIN_DESC swapChainDesc = GetSwapChainDesc(_res, true, g_pCoreSystem->GetHwnd()); UINT deviceFlags = 0; #ifdef _DEBUG deviceFlags |= D3D11_CREATE_DEVICE_DEBUG; #endif D3D_FEATURE_LEVEL featureLevelsToTry[] = { D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0 }; D3D_DRIVER_TYPE driverTypes[] = { D3D_DRIVER_TYPE_HARDWARE, D3D_DRIVER_TYPE_REFERENCE, }; UINT numDriverTypes = sizeof(driverTypes) / sizeof(driverTypes[0]); D3D_DRIVER_TYPE driverType; D3D_FEATURE_LEVEL initiatedFeatureLevel; for (uint i = 0; i < numDriverTypes; ++i) { driverType = driverTypes[i]; result = D3D11CreateDeviceAndSwapChain(NULL, driverType, NULL, deviceFlags, featureLevelsToTry, ARRAYSIZE(featureLevelsToTry), D3D11_SDK_VERSION, &swapChainDesc, &m_swapChain, &m_device, &initiatedFeatureLevel, &m_context); if (SUCCEEDED(result)) { D3D_FEATURE_LEVEL_11_1 == initiatedFeatureLevel ? printf("feature level: D3D_11_1\n") : printf("feature level: D3D_11_0\n"); 0 == i ? printf("driver type: hardware\n") : printf("driver type: reference\n"); break; } } if (FAILED(result)) { _com_error err(result); PrintError(AT, err.ErrorMessage()); return false; } // create backbuffer render target m_pbackBufferRenderTarget = VNEW RenderTarget("BackBuffer"); // Get the pointer to the back buffer texture from the swapchain result = m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&m_pbackBufferRenderTarget->m_pTexture); if (FAILED(result)) { return false; } m_pbackBufferRenderTarget->m_pTexture->GetDesc(&rti.TexDesc); rti.RTVDesc.Format = rti.TexDesc.Format; rti.RTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; rti.RTVDesc.Texture2D.MipSlice = 0; rti.formats = RTFS_TEXTURE; if (false == m_pbackBufferRenderTarget->Init(rti, m_device)) { PrintError(AT, "failed to create backbuffer rendertarget"); return false; } // Create the texture for the depth buffer using the filled out description. D3D11_TEXTURE2D_DESC depthBufferDesc = GetDepthBufferDesc(_res); result = m_device->CreateTexture2D(&depthBufferDesc, NULL, &m_depthStencilBuffer); if (FAILED(result)) { return false; } // Create the depth stencil state. D3D11_DEPTH_STENCIL_DESC depthStencilDesc = GetDepthStencilDesc(); result = m_device->CreateDepthStencilState(&depthStencilDesc, &m_depthStencilState); if (FAILED(result)) { return false; } depthStencilDesc.DepthEnable = false; result = m_device->CreateDepthStencilState(&depthStencilDesc, &m_pDepthStateDisabled); if (FAILED(result)) { return false; } // Create the depth stencil view. D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc = GetDepthStencilViewDesc(); result = m_device->CreateDepthStencilView(m_depthStencilBuffer, &depthStencilViewDesc, &m_depthStencilView); if (FAILED(result)) { return false; } // Create the rasterizer state from the description we just filled out. D3D11_RASTERIZER_DESC rasterDesc = GetRasterizerDesc(); result = m_device->CreateRasterizerState(&rasterDesc, &m_rasterState); if (FAILED(result)) { return false; } // Set the rasterizer state. m_context->RSSetState(m_rasterState); D3D11_BLEND_DESC blendDesc = GetBlendDesc(RENDERTARGET_COUNT); result = m_device->CreateBlendState(&blendDesc, &m_blendState); if (FAILED(result)) { return false; } // Setup the viewport for rendering. viewport.Width = (float)_res.width; viewport.Height = (float)_res.height; viewport.MinDepth = 0.0f; viewport.MaxDepth = 1.0f; viewport.TopLeftX = 0.0f; viewport.TopLeftY = 0.0f; float fieldOfView = (float)M_PI / 4.0f; float screenAspect = (float)_res.width / (float)_res.height; m_context->RSSetViewports(1, &viewport); #ifdef FDEBUG printf("Driver: Ok\n"); #endif return true; }