Question

After successful device creation

    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");
    }

when i call RSGetState i get back null pointer

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

What is wrong?

Was it helpful?

Solution

The default state that the device context is in will provide a defined behavior even if there hasn't been a state set into it. So it will appear that the rasterizer state is working, even if there isn't a state object there yet.

The API that you are calling will directly retrieve any state object that has been bound for the rasterizer, so you will get NULL back unless a state was bound at some point prior to the API call.

OTHER TIPS

I believe i have found the answer, one must use CreateRasterizerState to create initial direct3d state, because it is NULL in the begining.

Example:

 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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top