Advertisement
Ember

agegefefe

May 3rd, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.22 KB | None | 0 0
  1. // Get the pointer to the back buffer
  2. result = mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBufferPtr);
  3. if(FAILED(result)) { return false; }
  4.  
  5. // Create the render target view with the back buffer pointer
  6. result = Device->CreateRenderTargetView(backBufferPtr, NULL, &mRenderTargetView);
  7. if(FAILED(result)) { return false; }
  8.  
  9. // Release pointer to the back buffer as we no longer need it
  10. backBufferPtr->Release();
  11. backBufferPtr = 0;
  12.  
  13. // Initialize the description of the depth buffer
  14. ZeroMemory(&depthBufferDesc, sizeof(depthBufferDesc));
  15.  
  16. // Set up the description of the depth buffer
  17. depthBufferDesc.Width = windowDesc.width;
  18. depthBufferDesc.Height = windowDesc.height;
  19. depthBufferDesc.MipLevels = 1;
  20. depthBufferDesc.ArraySize = 1;
  21. depthBufferDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
  22. depthBufferDesc.SampleDesc.Count = 1;
  23. depthBufferDesc.SampleDesc.Quality = 0;
  24. depthBufferDesc.Usage = D3D11_USAGE_DEFAULT;
  25. depthBufferDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
  26. depthBufferDesc.CPUAccessFlags = 0;
  27. depthBufferDesc.MiscFlags = 0;
  28.  
  29. // Create the texture for the depth buffer using the filled out description
  30. result = Device->CreateTexture2D(&depthBufferDesc, NULL, &mDepthStencilBuffer);
  31. if(FAILED(result)) { return false; }
  32.  
  33. // Initialize the description of the stencil state
  34. ZeroMemory(&depthStencilDesc, sizeof(depthStencilDesc));
  35.  
  36. // Set up the description of the stencil state
  37. depthStencilDesc.DepthEnable = true;
  38. depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
  39. depthStencilDesc.DepthFunc = D3D11_COMPARISON_LESS;
  40.  
  41. depthStencilDesc.StencilEnable = true;
  42. depthStencilDesc.StencilReadMask = 0xFF;
  43. depthStencilDesc.StencilWriteMask = 0xFF;
  44.  
  45. // Stencil operations if pixel is front-facing
  46. depthStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
  47. depthStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
  48. depthStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
  49. depthStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
  50.  
  51. // Stencil operations if pixel is back-facing
  52. depthStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
  53. depthStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
  54. depthStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
  55. depthStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
  56.  
  57. // Create the depth stencil state
  58. result = Device->CreateDepthStencilState(&depthStencilDesc, &mDepthStencilState);
  59. if(FAILED(result)) { return false; }
  60.  
  61. // Set the depth stencil state
  62. DeviceContext->OMSetDepthStencilState(mDepthStencilState, 1);
  63.  
  64. // Initialize the depth stencil view
  65. ZeroMemory(&depthStencilViewDesc, sizeof(depthStencilViewDesc));
  66.  
  67. // Set up the depth stencil view description
  68. depthStencilViewDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
  69. depthStencilViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
  70. depthStencilViewDesc.Texture2D.MipSlice = 0;
  71.  
  72. // Create the depth stencil view
  73. result = Device->CreateDepthStencilView(mDepthStencilBuffer, &depthStencilViewDesc, &mDepthStencilView);
  74. if(FAILED(result)) { return false; }
  75.  
  76. // Bind the render target view and depth stencil buffer to the output render pipeline
  77. DeviceContext->OMSetRenderTargets(1, &mRenderTargetView, mDepthStencilView);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement