d3d11-zstencilbuffer.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /******************************************************************************
  2. Copyright (C) 2023 by Lain 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. HRESULT hr;
  18. memset(&td, 0, sizeof(td));
  19. td.Width = width;
  20. td.Height = height;
  21. td.MipLevels = 1;
  22. td.ArraySize = 1;
  23. td.Format = dxgiFormat;
  24. td.BindFlags = D3D11_BIND_DEPTH_STENCIL;
  25. td.SampleDesc.Count = 1;
  26. td.Usage = D3D11_USAGE_DEFAULT;
  27. hr = device->device->CreateTexture2D(&td, NULL, texture.Assign());
  28. if (FAILED(hr))
  29. throw HRError("Failed to create depth stencil texture", hr);
  30. memset(&dsvd, 0, sizeof(dsvd));
  31. dsvd.Format = dxgiFormat;
  32. dsvd.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
  33. hr = device->device->CreateDepthStencilView(texture, &dsvd, view.Assign());
  34. if (FAILED(hr))
  35. throw HRError("Failed to create depth stencil view", hr);
  36. }
  37. gs_zstencil_buffer::gs_zstencil_buffer(gs_device_t *device, uint32_t width, uint32_t height, gs_zstencil_format format)
  38. : gs_obj(device, gs_type::gs_zstencil_buffer),
  39. width(width),
  40. height(height),
  41. format(format),
  42. dxgiFormat(ConvertGSZStencilFormat(format))
  43. {
  44. InitBuffer();
  45. }