无法创建渲染目标视图DirectX 11

时间:2017-01-15 20:27:16

标签: c++ directx-11

这是我的代码。最后的if是真的,所以我得到的messageBox告诉我createRenderTargetView失败了。我对此很新,我在网上搜索了很多,但一无所获,你有什么提示吗?谢谢。 这是一个概率性的部分

    //feature levels
    D3D_FEATURE_LEVEL featureLevels[6]{
        D3D_FEATURE_LEVEL_11_0,
        D3D_FEATURE_LEVEL_10_1,
        D3D_FEATURE_LEVEL_10_0,
        D3D_FEATURE_LEVEL_9_3,
        D3D_FEATURE_LEVEL_9_2,
        D3D_FEATURE_LEVEL_9_1,
    };
    //swap chain
    ZeroMemory(&m_swapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));


        m_swapChainDesc.BufferDesc.Height = 600;
        m_swapChainDesc.BufferDesc.Width = 800;
        m_swapChainDesc.Windowed = true;


    m_swapChainDesc.BufferCount = 1;
    m_swapChainDesc.OutputWindow = hwnd; 
    m_swapChainDesc.Flags = 0;
    m_swapChainDesc.SampleDesc.Count = 1;
    m_swapChainDesc.SampleDesc.Quality = 0;
    m_swapChainDesc.BufferUsage = DXGI_USAGE_DISCARD_ON_PRESENT;
    m_swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    m_swapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
    m_swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
    UINT createDeviceFlags = 0; 

    m_swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
    m_swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;

    m_swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
#if defined(DEBUG) || defined
    (_DEBUG)createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; 
#endif*/
    //creazione device e swapchain
    /*hr=D3D11CreateDeviceAndSwapChain(nullptr, D3D_DRIVER_TYPE_HARDWARE, 0, 0, 0, ARRAYSIZE(featureLevels), D3D11_SDK_VERSION, 
                                    &m_swapChainDesc, &m_swapChain, &m_device, featureLevels, &m_deviceContext );
*/
    D3D_FEATURE_LEVEL featureLevel;

    hr = D3D11CreateDevice(0, D3D_DRIVER_TYPE_HARDWARE, 0, createDeviceFlags, featureLevels, 6, D3D11_SDK_VERSION, &m_device, &featureLevel, &m_deviceContext);

    if (FAILED(hr))  
        MessageBox(0, L"D3D11CreateDevice Failed.", 0, 0);  

    IDXGIDevice *dxgiDevice = 0;

    hr=m_device->QueryInterface(__uuidof(IDXGIDevice), (void**)&dxgiDevice);
    if (FAILED(hr))
        MessageBox(0, L"Fallita queryInterface", 0, 0);
    IDXGIAdapter *dxgiAdapter = 0;
    hr=dxgiDevice->GetParent(__uuidof(IDXGIAdapter), (void**)&dxgiAdapter);
    if (FAILED(hr))
        MessageBox(0, L"Fallito getParent", 0, 0);
    IDXGIFactory *dxgiFactory = 0;
    hr=dxgiAdapter->GetParent(__uuidof(IDXGIFactory), (void**)&dxgiFactory);
    if (FAILED(hr))
        MessageBox(0, L"Fallito getParent", 0, 0);


    IDXGISwapChain *m_swapChain;
    hr=dxgiFactory->CreateSwapChain(m_device, &m_swapChainDesc, &m_swapChain);
    if (FAILED(hr))
        MessageBox(0, L"Failed crating the swap chain", 0, 0);

    dxgiAdapter->Release();
    dxgiDevice->Release();
    dxgiFactory->Release();

    ID3D11RenderTargetView *m_renderTargetView;
    ID3D11Texture2D *m_backBuffer;
    hr=m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&m_backBuffer));
    if (FAILED(hr))
        MessageBox(0, L"Failed get buffer", 0, 0);

    hr=m_device->CreateRenderTargetView(m_backBuffer, NULL, &m_renderTargetView);
    if (FAILED(hr))
        MessageBox(0, L"Failed to create rendertargetview", 0, 0);

0 个答案:

没有答案