Hello,
I've been doing some development in Direct3D 11 and C++ and I can't seem to be able to enable MSAA. I am getting horrible jagged lines when rendering a simple primitive. Here is what I have done so far:
SwapChain Creation
// Display Mode
// --------------------------------------------------------------------
DXGI_RATIONAL RefreshRate = {60, 1};
DXGI_MODE_DESC DisplayMode = {0};
DisplayMode.Width = Width;
DisplayMode.Height = Height;
DisplayMode.RefreshRate = RefreshRate;
DisplayMode.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
// --------------------------------------------------------------------
// SwapChain Description
// --------------------------------------------------------------------
DXGI_SAMPLE_DESC Sampling = {4, 0};
DXGI_SWAP_CHAIN_DESC SCDescription = {0};
SCDescription.BufferCount = 1;
SCDescription.BufferDesc = DisplayMode;
SCDescription.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
SCDescription.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
SCDescription.OutputWindow = RenderWindow;
SCDescription.SampleDesc = Sampling;
SCDescription.Windowed = TRUE;
// --------------------------------------------------------------------
RenderTarget and DepthStencil and Rasterizer
// Create RenderTarget
// --------------------------------------------------------------------
ID3D11Texture2D *Resource = NULL;
m_SwapChain->GetBuffer(0, IID_ID3D11Texture2D, (void**)&Resource);
D3D11_RENDER_TARGET_VIEW_DESC RTDescription;
ZeroMemory(&RTDescription, sizeof(D3D11_RENDER_TARGET_VIEW_DESC));
RTDescription.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
RTDescription.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS;
m_Device->CreateRenderTargetView(Resource, &RTDescription,
&m_RenderTarget);
Resource->Release();
Resource = NULL;
// --------------------------------------------------------------------
// Create DepthStencil
// --------------------------------------------------------------------
D3D11_TEXTURE2D_DESC TextureDescription = {0};
TextureDescription.BindFlags = D3D11_BIND_DEPTH_STENCIL;
TextureDescription.Width = Width;
TextureDescription.Height = Height;
TextureDescription.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
TextureDescription.SampleDesc = Sampling;
TextureDescription.ArraySize = 1;
TextureDescription.MipLevels = 1;
ID3D11Texture2D *DepthResource = NULL;
m_Device->CreateTexture2D(&TextureDescription,
NULL, &DepthResource);
D3D11_DEPTH_STENCIL_VIEW_DESC DSDescription;
ZeroMemory(&DSDescription, sizeof(D3D11_DEPTH_STENCIL_VIEW_DESC));
DSDescription.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
DSDescription.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMS;
m_Device->CreateDepthStencilView(DepthResource,
&DSDescription, &m_DepthStencil);
DepthResource->Release();
DepthResource = NULL;
// --------------------------------------------------------------------
m_DeviceContext->
OMSetRenderTargets(1, &m_RenderTarget, m_DepthStencil);
// Customize Rasterizer
// --------------------------------------------------------------------
D3D11_RASTERIZER_DESC RasterizerDescription;
ZeroMemory(&RasterizerDescription, sizeof(D3D11_RASTERIZER_DESC));
RasterizerDescription.AntialiasedLineEnable = TRUE;
RasterizerDescription.CullMode = D3D11_CULL_BACK;
RasterizerDescription.DepthClipEnable = TRUE;
RasterizerDescription.FillMode = D3D11_FILL_SOLID;
RasterizerDescription.MultisampleEnable = TRUE;
ID3D11RasterizerState *RasterizerState = NULL;
m_Device->CreateRasterizerState
(&RasterizerDescription, &RasterizerState);
m_DeviceContext->RSSetState(RasterizerState);
RasterizerState->Release();
RasterizerState = NULL;
// --------------------------------------------------------------------
Am I missing something? It should be noted that I am targeting D3D_FEATURE_LEVEL_9_3 and that my graphics card is capable of handling the above sampling count and quality.
Any help would be greatly appreciated!