无法创建DX11渲染目标视图

时间:2015-05-08 16:55:31

标签: directx texture2d rendertarget

我试图开始使用DirectX 11游戏编程,但出于某种原因,我无法使用ID3D11Device :: CreateRenderTargetView()创建渲染目标视图。

(顺便说一句,我使用VS for Desktop 2013,我的GPU支持的最高功能级别是11_0。我正在运行Windows 8.1。)

以下是我认为相关的代码:

D3D11_TEXTURE2D_DESC backBufferDesc;
    ZeroMemory(&backBufferDesc, sizeof(backBufferDesc));
    backBufferDesc.ArraySize = 1;
    backBufferDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
    backBufferDesc.CPUAccessFlags = 0;
    backBufferDesc.Format = DXGI_FORMAT_R32_FLOAT;
    backBufferDesc.Height = nHeight;
    backBufferDesc.Width = nWidth;
    backBufferDesc.MipLevels = 1;
    backBufferDesc.MiscFlags = 0;
    backBufferDesc.SampleDesc.Count = 1;
    backBufferDesc.SampleDesc.Quality = 0;
    backBufferDesc.Usage = D3D11_USAGE_DEFAULT;

    ID3D11Texture2D* backBufferTexture;
    result = d3dDevice_ -> CreateTexture2D(&backBufferDesc, 0, &backBufferTexture);
    if (FAILED(result))
    {
        MessageBox(0, "Failed to create the back buffer texture!", "DirectX Error", MB_OK);
        return false;
    }

    result = swapChain_->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBufferTexture);
    if (FAILED(result))
    {
        MessageBox(0, "Failed to get the swap chain back buffer!", "DirectX Error", MB_OK);
        return false;
    }

    D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
    ZeroMemory(&rtvDesc, sizeof(rtvDesc));
    rtvDesc.Format = backBufferDesc.Format;

    result = d3dDevice_->CreateRenderTargetView(backBufferTexture, &rtvDesc, &backBufferTarget_);
    if (backBufferTexture)
        backBufferTexture->Release();
    if (FAILED(result))
    {
        MessageBox(0, "Failed to create the render target view!", "DirectX Error", MB_OK);
        return false;
    }

1 个答案:

答案 0 :(得分:0)

使用调试设备会给您一个人类可读的错误。

根据我对代码的阅读,您还没有填写rtvDesc的ViewDimension字段。