Sign in to follow this  
Belkacem

createswapchain always fail

Recommended Posts

hello

i have a problem with create swapchain , and it is always fail , and i dont why i try more than one code and more than way and always fail

first

if i use something like this , it will fail ( the swap chain not create )

[code] ::DXGI_SWAP_CHAIN_DESC desc ;
desc.BufferCount = 1 ;
desc.BufferDesc.Format = Buf.Format;
desc.BufferDesc.Height = Buf.Height ;
desc.BufferDesc.RefreshRate = _Mode_Desc->RefreshRate ;
desc.BufferDesc.Scaling = _Mode_Desc->Scaling ;
desc.BufferDesc.ScanlineOrdering = _Mode_Desc->ScanlineOrdering ;
desc.BufferDesc.Width= Buf.Width ;
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
desc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH ;
desc.OutputWindow = hwnd ;
desc.SampleDesc = Sample_Desc ;
desc.SwapEffect = ::DXGI_SWAP_EFFECT_DISCARD ;
desc.Windowed= true ;


if ( FAILED (::D3D11CreateDevice ( NULL , D3D_DRIVER_TYPE_HARDWARE , NULL ,D3D11_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS| D3D11_CREATE_DEVICE_BGRA_SUPPORT, Feature_Level_List
,_Number_Feature_Level_List , D3D11_SDK_VERSION ,&_Device ,&_featureLevel , &_DeviceContext )))


{
ZeroMemory (&MyError , sizeof(Error));
MyError.Error_Message = L"Sorry ! We Can't Create Device or (and) SwapChain! , we must close";
ErrorMessage ( MyError , __WFILE__ , __LINE__);
return E_FAIL ;
exit(0);
}

IDXGIFactory *pFactory;

CreateDXGIFactory (__uuidof(IDXGIFactory), (void**)&pFactory);

::IDXGISwapChain *Cahin = NULL ;
HRESULT hr = pFactory->CreateSwapChain ( _Device , &desc , &Cahin); [/code]


second

but this is work

[code]desc.BufferCount = 1 ;
desc.BufferDesc.Format = Buf.Format;
desc.BufferDesc.Height = Buf.Height ;
desc.BufferDesc.RefreshRate = _Mode_Desc->RefreshRate ;
desc.BufferDesc.Scaling = _Mode_Desc->Scaling ;
desc.BufferDesc.ScanlineOrdering = _Mode_Desc->ScanlineOrdering ;
desc.BufferDesc.Width= Buf.Width ;
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
desc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH ;
desc.OutputWindow = hwnd ;
desc.SampleDesc = Sample_Desc ;
desc.SwapEffect = ::DXGI_SWAP_EFFECT_DISCARD ;
desc.Windowed= true ;



/*if ( FAILED (::D3D11CreateDeviceAndSwapChain ( NULL , D3D_DRIVER_TYPE_HARDWARE , NULL ,D3D11_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS| D3D11_CREATE_DEVICE_BGRA_SUPPORT, Feature_Level_List
,_Number_Feature_Level_List , D3D11_SDK_VERSION , &_Swp_Chain_desc,&_SwapChain,&_Device ,&_featureLevel , &_DeviceContext )))


{
ZeroMemory (&MyError , sizeof(Error));
MyError.Error_Message = L"Sorry ! We Can't Create Device or (and) SwapChain! , we must close";
ErrorMessage ( MyError , __WFILE__ , __LINE__);
return E_FAIL ;
exit(0);
}*/[/code]

whats the wrong in my code i think evry thing is correct !!

another question , can i create more than one swap chain in the same application ??

Share this post


Link to post
Share on other sites
I have a GraphicsDevice class which amongst other things has an IDXGISwapChain* member.

[code]bool GraphicsDevice::Init()
{
UINT flags = 0;
#ifdef _DEBUG
flags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
HRESULT hr = D3D11CreateDevice(
NULL,
D3D_DRIVER_TYPE_HARDWARE,
NULL,
flags,
NULL,
0,
D3D11_SDK_VERSION,
&_pDevice,
&_featureLevel,
&_pImmediateContext);

if(SUCCEEDED(hr)) hr = _pDevice->QueryInterface(__uuidof(IDXGIDevice), reinterpret_cast<void**>(&_pDXGIDevice));

IDXGIAdapter* pDXGIAdapter = NULL;
if(SUCCEEDED(hr)) hr = _pDXGIDevice->GetParent(__uuidof(IDXGIAdapter), reinterpret_cast<void**>(&pDXGIAdapter));

if(SUCCEEDED(hr)) hr = pDXGIAdapter->GetParent(__uuidof(IDXGIFactory), reinterpret_cast<void**>(&_pDXGIFactory));

SAFE_RELEASE(pDXGIAdapter);

return CheckError(hr);
}

IDXGISwapChain* GraphicsDevice::CreateSwapChain(HWND windowHandle, DXGI_FORMAT format, UINT width, UINT height, bool windowed)
{
DXGI_SWAP_CHAIN_DESC sc;
ZeroMemory(&sc, sizeof(DXGI_SWAP_CHAIN_DESC));

sc.BufferCount = 1;
sc.BufferDesc.Width = width;
sc.BufferDesc.Height = height;
sc.BufferDesc.Format = format;
sc.BufferDesc.RefreshRate.Numerator = 60;
sc.BufferDesc.RefreshRate.Denominator = 1;
sc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sc.OutputWindow = windowHandle;
sc.SampleDesc.Count = 1;
sc.SampleDesc.Quality = 0;
sc.Windowed = windowed;

IDXGISwapChain* pSwapChain = NULL;

HRESULT hr = _pDXGIFactory->CreateSwapChain(_pDXGIDevice, &sc, &pSwapChain);

if(CheckError(hr))
{
return pSwapChain;
}
else
{
return NULL;
}
}[/code]

Share this post


Link to post
Share on other sites
thanks for your reply

about desc and _swp_chain_dec are equals



[code]_Swp_Chain_desc.BufferCount = 1 ;
_Swp_Chain_desc.BufferDesc.Format = Buf.Format;
_Swp_Chain_desc.BufferDesc.Height = Buf.Height ;
_Swp_Chain_desc.BufferDesc.RefreshRate = _Mode_Desc->RefreshRate ;
_Swp_Chain_desc.BufferDesc.Scaling = _Mode_Desc->Scaling ;
_Swp_Chain_desc.BufferDesc.ScanlineOrdering = _Mode_Desc->ScanlineOrdering ;
_Swp_Chain_desc.BufferDesc.Width= Buf.Width ;
_Swp_Chain_desc.BufferUsage = DXGI_USAGE_BACK_BUFFER;
_Swp_Chain_desc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH ;
_Swp_Chain_desc.OutputWindow = hwnd ;
_Swp_Chain_desc.SampleDesc = Sample_Desc ;
_Swp_Chain_desc.SwapEffect = ::DXGI_SWAP_EFFECT_DISCARD ;
_Swp_Chain_desc.Windowed= Windowed ;


::DXGI_SWAP_CHAIN_DESC desc ;
desc.BufferCount = 1 ;
desc.BufferDesc.Format = Buf.Format;
desc.BufferDesc.Height = Buf.Height ;
desc.BufferDesc.RefreshRate = _Mode_Desc->RefreshRate ;
desc.BufferDesc.Scaling = _Mode_Desc->Scaling ;
desc.BufferDesc.ScanlineOrdering = _Mode_Desc->ScanlineOrdering ;
desc.BufferDesc.Width= Buf.Width ;
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
desc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH ;
desc.OutputWindow = hwnd ;
desc.SampleDesc = Sample_Desc ;
desc.SwapEffect = ::DXGI_SWAP_EFFECT_DISCARD ;
desc.Windowed= Windowed ; [/code]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this