CmD3D11DepthStencilBuffer.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "CmD3D11DepthStencilBuffer.h"
  2. #include "CmD3D11RenderSystem.h"
  3. #include "CmD3D11Device.h"
  4. #include "CmD3D11Mappings.h"
  5. #include "CmException.h"
  6. namespace CamelotEngine
  7. {
  8. D3D11DepthStencilBuffer::D3D11DepthStencilBuffer(DepthStencilFormat format, UINT32 width, UINT32 height, UINT32 fsaa, const String &fsaaHint)
  9. : DepthStencilBuffer(format, width, height, fsaa, fsaaHint)
  10. , mDepthStencil(nullptr)
  11. , mDepthStencilView(nullptr)
  12. {
  13. // Create depth stencil texture
  14. D3D11_TEXTURE2D_DESC descDepth;
  15. descDepth.Width = width;
  16. descDepth.Height = height;
  17. descDepth.MipLevels = 1;
  18. descDepth.ArraySize = 1;
  19. descDepth.Format = D3D11Mappings::get(format);
  20. descDepth.Usage = D3D11_USAGE_DEFAULT;
  21. descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL;
  22. descDepth.CPUAccessFlags = 0;
  23. descDepth.MiscFlags = 0;
  24. D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
  25. rs->determineFSAASettings(fsaa, fsaaHint, descDepth.Format, &descDepth.SampleDesc);
  26. D3D11Device& device = D3D11RenderSystem::getPrimaryDevice();
  27. HRESULT hr = device.getD3D11Device()->CreateTexture2D(&descDepth, NULL, &mDepthStencil);
  28. if( FAILED(hr) || device.hasError())
  29. {
  30. String errorDescription = device.getErrorDescription();
  31. CM_EXCEPT(RenderingAPIException, "Unable to create depth texture\nError Description:" + errorDescription);
  32. }
  33. // Create the depth stencil view
  34. D3D11_DEPTH_STENCIL_VIEW_DESC descDSV;
  35. ZeroMemory(&descDSV, sizeof(D3D11_DEPTH_STENCIL_VIEW_DESC));
  36. descDSV.Format = descDepth.Format;
  37. descDSV.ViewDimension = (fsaa != 0) ? D3D11_DSV_DIMENSION_TEXTURE2DMS : D3D11_DSV_DIMENSION_TEXTURE2D;
  38. descDSV.Texture2D.MipSlice = 0;
  39. hr = device.getD3D11Device()->CreateDepthStencilView(mDepthStencil, &descDSV, &mDepthStencilView);
  40. if(FAILED(hr))
  41. {
  42. String errorDescription = device.getErrorDescription();
  43. CM_EXCEPT(RenderingAPIException, "Unable to create depth stencil view\nError Description:" + errorDescription);
  44. }
  45. }
  46. D3D11DepthStencilBuffer::~D3D11DepthStencilBuffer()
  47. {
  48. SAFE_RELEASE(mDepthStencilView);
  49. SAFE_RELEASE(mDepthStencil);
  50. }
  51. bool D3D11DepthStencilBuffer::isCompatible(RenderTarget* renderTarget) const
  52. {
  53. // Implement once I have RenderTarget properly implemented
  54. CM_EXCEPT(NotImplementedException, "Not implemented");
  55. }
  56. }