Skip to content

Commit b6f3c97

Browse files
committed
Examples: DirectX11: explicitly set rasterizer state.
1 parent 097fe51 commit b6f3c97

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

examples/directx11_example/imgui_impl_dx11.cpp

+26-12
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ static ID3D10Blob * g_pPixelShaderBlob = NULL;
2626
static ID3D11PixelShader* g_pPixelShader = NULL;
2727
static ID3D11SamplerState* g_pFontSampler = NULL;
2828
static ID3D11ShaderResourceView*g_pFontTextureView = NULL;
29-
static ID3D11BlendState* g_blendState = NULL;
29+
static ID3D11RasterizerState* g_pRasterizerState = NULL;
30+
static ID3D11BlendState* g_pBlendState = NULL;
3031
static int VERTEX_BUFFER_SIZE = 30000; // TODO: Make vertex buffer smaller and grow dynamically as needed.
3132

3233
struct VERTEX_CONSTANT_BUFFER
@@ -100,7 +101,8 @@ static void ImGui_ImplDX11_RenderDrawLists(ImDrawList** const cmd_lists, int cmd
100101

101102
// Setup render state
102103
const float blendFactor[4] = { 0.f, 0.f, 0.f, 0.f };
103-
g_pd3dDeviceContext->OMSetBlendState(g_blendState, blendFactor, 0xffffffff);
104+
g_pd3dDeviceContext->OMSetBlendState(g_pBlendState, blendFactor, 0xffffffff);
105+
g_pd3dDeviceContext->RSSetState(g_pRasterizerState);
104106

105107
// Render command lists
106108
int vtx_offset = 0;
@@ -339,19 +341,30 @@ bool ImGui_ImplDX11_CreateDeviceObjects()
339341
desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
340342
desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
341343
desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
342-
g_pd3dDevice->CreateBlendState(&desc, &g_blendState);
344+
g_pd3dDevice->CreateBlendState(&desc, &g_pBlendState);
345+
}
346+
347+
// Create the rasterizer state
348+
{
349+
D3D11_RASTERIZER_DESC desc;
350+
ZeroMemory(&desc, sizeof(desc));
351+
desc.FillMode = D3D11_FILL_SOLID;
352+
desc.CullMode = D3D11_CULL_NONE;
353+
desc.ScissorEnable = true;
354+
desc.DepthClipEnable = true;
355+
g_pd3dDevice->CreateRasterizerState(&desc, &g_pRasterizerState);
343356
}
344357

345358
// Create the vertex buffer
346359
{
347-
D3D11_BUFFER_DESC bufferDesc;
348-
memset(&bufferDesc, 0, sizeof(D3D11_BUFFER_DESC));
349-
bufferDesc.Usage = D3D11_USAGE_DYNAMIC;
350-
bufferDesc.ByteWidth = VERTEX_BUFFER_SIZE * sizeof(ImDrawVert);
351-
bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
352-
bufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
353-
bufferDesc.MiscFlags = 0;
354-
if (g_pd3dDevice->CreateBuffer(&bufferDesc, NULL, &g_pVB) < 0)
360+
D3D11_BUFFER_DESC desc;
361+
memset(&desc, 0, sizeof(D3D11_BUFFER_DESC));
362+
desc.Usage = D3D11_USAGE_DYNAMIC;
363+
desc.ByteWidth = VERTEX_BUFFER_SIZE * sizeof(ImDrawVert);
364+
desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
365+
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
366+
desc.MiscFlags = 0;
367+
if (g_pd3dDevice->CreateBuffer(&desc, NULL, &g_pVB) < 0)
355368
return false;
356369
}
357370

@@ -369,7 +382,8 @@ void ImGui_ImplDX11_InvalidateDeviceObjects()
369382
if (g_pFontTextureView) { g_pFontTextureView->Release(); ImGui::GetIO().Fonts->TexID = 0; }
370383
if (g_pVB) { g_pVB->Release(); g_pVB = NULL; }
371384

372-
if (g_blendState) { g_blendState->Release(); g_blendState = NULL; }
385+
if (g_pBlendState) { g_pBlendState->Release(); g_pBlendState = NULL; }
386+
if (g_pRasterizerState) { g_pRasterizerState->Release(); g_pRasterizerState = NULL; }
373387
if (g_pPixelShader) { g_pPixelShader->Release(); g_pPixelShader = NULL; }
374388
if (g_pPixelShaderBlob) { g_pPixelShaderBlob->Release(); g_pPixelShaderBlob = NULL; }
375389
if (g_pVertexConstantBuffer) { g_pVertexConstantBuffer->Release(); g_pVertexConstantBuffer = NULL; }

0 commit comments

Comments
 (0)