成功创建设备后
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);
有什么问题?
答案 0 :(得分: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);
答案 1 :(得分:1)
设备上下文所处的默认状态将提供已定义的行为,即使没有设置状态也是如此。因此,即使当时还没有状态对象,光栅化器状态也会起作用。
您正在调用的API将直接检索已绑定到光栅化器的任何状态对象,因此除非在API调用之前某个点绑定了状态,否则将返回NULL。