-
-
Save anonymous/4bbf109900cd744458b0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This snippet is from void DirectXBase::CreateWindowSizeDependentResources(), a function that was automagically generated | |
// for me when I created the project. I've done minimal editting in it, other than adding my stereo3d code. | |
ComPtr<ID3D11Texture2D> backBuffer; | |
DX::ThrowIfFailed( swapChain->GetBuffer(0, IID_PPV_ARGS(&backBuffer)) ); | |
CD3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc( | |
D3D11_RTV_DIMENSION_TEXTURE2DARRAY, | |
DXGI_FORMAT_B8G8R8A8_UNORM, | |
0, | |
0, | |
1 | |
); | |
DX::ThrowIfFailed( direct3d.device->CreateRenderTargetView( backBuffer.Get(), &renderTargetViewDesc, &direct3d.renderTarget[0] ) ); | |
if (m_stereoEnabled) | |
{ | |
CD3D11_RENDER_TARGET_VIEW_DESC renderTargetViewRightDesc( | |
D3D11_RTV_DIMENSION_TEXTURE2DARRAY, | |
DXGI_FORMAT_B8G8R8A8_UNORM, | |
0, | |
1, | |
1 | |
); | |
DX::ThrowIfFailed( direct3d.device->CreateRenderTargetView( backBuffer.Get(), &renderTargetViewRightDesc, &direct3d.renderTarget[1] ) ); | |
} | |
D3D11_TEXTURE2D_DESC backBufferDesc = {0}; | |
backBuffer->GetDesc(&backBufferDesc); | |
m_renderTargetSize.Width = static_cast<float>(backBufferDesc.Width); | |
m_renderTargetSize.Height = static_cast<float>(backBufferDesc.Height); | |
CD3D11_TEXTURE2D_DESC depthStencilDesc( | |
DXGI_FORMAT_D24_UNORM_S8_UINT, | |
backBufferDesc.Width, | |
backBufferDesc.Height, | |
1, | |
1, | |
D3D11_BIND_DEPTH_STENCIL | |
); | |
Microsoft::WRL::ComPtr<ID3D11BlendState1> blendState; | |
D3D11_BLEND_DESC1 desc; | |
ZeroMemory( &desc, sizeof( desc ) ); | |
desc.IndependentBlendEnable = FALSE; | |
desc.AlphaToCoverageEnable = FALSE; | |
desc.RenderTarget[0].BlendEnable = TRUE; | |
desc.RenderTarget[0].LogicOpEnable = FALSE; | |
desc.RenderTarget[0].SrcBlend = D3D11_BLEND::D3D11_BLEND_SRC_ALPHA; | |
desc.RenderTarget[0].DestBlend = D3D11_BLEND::D3D11_BLEND_INV_SRC_ALPHA; | |
desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP::D3D11_BLEND_OP_ADD; | |
desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND::D3D11_BLEND_ONE; | |
desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND::D3D11_BLEND_ONE; | |
desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP::D3D11_BLEND_OP_ADD; | |
desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; | |
direct3d.device->CreateBlendState1( &desc, blendState.GetAddressOf() ); | |
direct3d.context->OMSetBlendState( blendState.Get(), NULL, 0xffffffff ); | |
ComPtr<ID3D11Texture2D> depthStencil; | |
DX::ThrowIfFailed( direct3d.device->CreateTexture2D( &depthStencilDesc, nullptr, &depthStencil ) ); | |
auto viewDesc = CD3D11_DEPTH_STENCIL_VIEW_DESC(D3D11_DSV_DIMENSION_TEXTURE2D); | |
DX::ThrowIfFailed( direct3d.device->CreateDepthStencilView( depthStencil.Get(), &viewDesc, &direct3d.depthStencil ) ); | |
Microsoft::WRL::ComPtr<ID3D11DepthStencilState> DepthDefault; | |
D3D11_DEPTH_STENCIL_DESC depthstencilDesc; | |
ZeroMemory(&depthstencilDesc, sizeof(depthstencilDesc)); | |
depthstencilDesc.DepthEnable = TRUE; | |
depthstencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK::D3D11_DEPTH_WRITE_MASK_ZERO; | |
depthstencilDesc.DepthFunc = D3D11_COMPARISON_ALWAYS; //D3D11_COMPARISON_NOT_EQUAL; | |
depthstencilDesc.StencilEnable = TRUE; | |
depthstencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS; | |
depthstencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_REPLACE; | |
depthstencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_REPLACE; | |
depthstencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_REPLACE; | |
depthstencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS; | |
depthstencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_REPLACE; | |
depthstencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_REPLACE; | |
depthstencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_REPLACE; | |
DX::ThrowIfFailed( direct3d.device->CreateDepthStencilState(&depthstencilDesc, DepthDefault.GetAddressOf() ) ); | |
direct3d.context->OMSetDepthStencilState(DepthDefault.Get(), 1); | |
CD3D11_VIEWPORT viewport( | |
0.0f, | |
0.0f, | |
static_cast<float>(backBufferDesc.Width), | |
static_cast<float>(backBufferDesc.Height) | |
); | |
direct3d.context->RSSetViewports(1, &viewport); | |
D2D1_BITMAP_PROPERTIES1 bitmapProperties = | |
BitmapProperties1( | |
D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW, | |
PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED), | |
m_dpi, | |
m_dpi | |
); | |
ComPtr<IDXGIResource1> dxgiBackBuffer; | |
DX::ThrowIfFailed( swapChain->GetBuffer(0, IID_PPV_ARGS(&dxgiBackBuffer)) ); | |
ComPtr<IDXGISurface2> dxgiSurface; | |
DX::ThrowIfFailed( dxgiBackBuffer->CreateSubresourceSurface(0, &dxgiSurface) ); | |
DX::ThrowIfFailed( | |
direct2d.context->CreateBitmapFromDxgiSurface( | |
dxgiSurface.Get(), | |
&bitmapProperties, | |
&direct2d.renderTarget[0] | |
) | |
); | |
if (m_stereoEnabled) | |
{ | |
DX::ThrowIfFailed( | |
dxgiBackBuffer->CreateSubresourceSurface(1, &dxgiSurface) | |
); | |
DX::ThrowIfFailed( | |
direct2d.context->CreateBitmapFromDxgiSurface( | |
dxgiSurface.Get(), | |
&bitmapProperties, | |
&direct2d.renderTarget[1] | |
) | |
); | |
} | |
direct2d.context->SetTarget( direct2d.renderTarget[0].Get()); | |
direct2d.context->SetTextAntialiasMode(D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment