d3d11-zstencilbuffer.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /******************************************************************************
  2. Copyright (C) 2013 by Hugh Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include "d3d11-subsystem.hpp"
  15. void gs_zstencil_buffer::InitBuffer()
  16. {
  17. D3D11_TEXTURE2D_DESC td;
  18. D3D11_DEPTH_STENCIL_VIEW_DESC dsvd;
  19. HRESULT hr;
  20. memset(&td, 0, sizeof(td));
  21. td.Width = width;
  22. td.Height = height;
  23. td.MipLevels = 1;
  24. td.ArraySize = 1;
  25. td.Format = dxgiFormat;
  26. td.BindFlags = D3D11_BIND_DEPTH_STENCIL;
  27. td.SampleDesc.Count = 1;
  28. td.Usage = D3D11_USAGE_DEFAULT;
  29. hr = device->device->CreateTexture2D(&td, NULL, texture.Assign());
  30. if (FAILED(hr))
  31. throw HRError("Failed to create depth stencil texture", hr);
  32. memset(&dsvd, 0, sizeof(dsvd));
  33. dsvd.Format = dxgiFormat;
  34. dsvd.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
  35. hr = device->device->CreateDepthStencilView(texture, &dsvd,
  36. view.Assign());
  37. if (FAILED(hr))
  38. throw HRError("Failed to create depth stencil view", hr);
  39. }
  40. gs_zstencil_buffer::gs_zstencil_buffer(gs_device_t *device,
  41. uint32_t width, uint32_t height,
  42. gs_zstencil_format format)
  43. : device (device),
  44. width (width),
  45. height (height),
  46. format (format),
  47. dxgiFormat (ConvertGSZStencilFormat(format))
  48. {
  49. InitBuffer();
  50. }