1
0

d3d11-zstencilbuffer.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. 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,
  34. view.Assign());
  35. if (FAILED(hr))
  36. throw HRError("Failed to create depth stencil view", hr);
  37. }
  38. gs_zstencil_buffer::gs_zstencil_buffer(gs_device_t *device, uint32_t width,
  39. uint32_t height,
  40. gs_zstencil_format format)
  41. : gs_obj(device, gs_type::gs_zstencil_buffer),
  42. width(width),
  43. height(height),
  44. format(format),
  45. dxgiFormat(ConvertGSZStencilFormat(format))
  46. {
  47. InitBuffer();
  48. }