1

设备创建成功后

    DXGI_SWAP_CHAIN_DESC sd;
    sd.BufferDesc.Width  = kClientWidth;
    sd.BufferDesc.Height = kClientHeight;
    sd.BufferDesc.RefreshRate.Numerator = 60;
    sd.BufferDesc.RefreshRate.Denominator = 1;
    sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    sd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
    sd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;

    // No multisampling.
    sd.SampleDesc.Count   = 1;
    sd.SampleDesc.Quality = 0;

    sd.BufferUsage  = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    sd.BufferCount  = 1;
    sd.OutputWindow = static_cast<HWND>(m_CreationParam.wnd);
    sd.Windowed     = true;
    sd.SwapEffect   = DXGI_SWAP_EFFECT_DISCARD;
    sd.Flags        = 0;

    UINT createDeviceFlags = 0;
#if defined(DEBUG) || defined(_DEBUG)  
    createDeviceFlags |= D3D10_CREATE_DEVICE_DEBUG;
#endif

    HRESULT hRes = D3D11CreateDeviceAndSwapChain(
            NULL,                 //default adapter
            D3D_DRIVER_TYPE_HARDWARE,
            NULL,
            createDeviceFlags,  
            NULL,
            NULL,
            D3D11_SDK_VERSION,
            &sd,
            &m_SwapChain,
            &m_d3dDevice,
            NULL,
            &m_d3dDevCon);

    if (FAILED(hRes))
    {
        m_SwapChain = NULL;
        m_d3dDevice = NULL;
        m_d3dDevCon = NULL;
        assert(0 && "Failed to create Device and SwapChain");
    }

当我调用 RSGetState 我得到空指针

    // Fill state
    m_d3dDevCon->RSGetState(&m_RasterState);
    m_RasterState->GetDesc(&m_rsDesc);

怎么了?

4

2 回答 2

1

我相信我已经找到了答案,必须使用 CreateRasterizerState 来创建初始的 direct3d 状态,因为一开始它是 NULL。

例子:

 rasterDesc.AntialiasedLineEnable = false;
 rasterDesc.CullMode = D3D11_CULL_BACK;
 rasterDesc.DepthBias = 0;
 rasterDesc.DepthBiasClamp = 0.0f;
 rasterDesc.DepthClipEnable = true;
 rasterDesc.FillMode = D3D11_FILL_SOLID;
 rasterDesc.FrontCounterClockwise = false;
 rasterDesc.MultisampleEnable = false;
 rasterDesc.ScissorEnable = false;
 rasterDesc.SlopeScaledDepthBias = 0.0f;

 result = m_device->CreateRasterizerState(&rasterDesc, &m_rasterState);
 if(FAILED(result))
 {
  return;
 }

 m_deviceContext->RSSetState(m_rasterState);
于 2013-06-01T16:01:13.793 回答
1

设备上下文所处的默认状态将提供定义的行为,即使尚未设置状态。所以看起来光栅化器状态正在工作,即使那里还没有状态对象。

您正在调用的 API 将直接检索已为光栅器绑定的任何状态对象,因此您将返回 NULL,除非在 API 调用之前的某个时间点绑定了状态。

于 2013-06-03T14:31:57.233 回答