1
0

d3d11-stagesurf.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. gs_stage_surface::gs_stage_surface(gs_device_t *device, uint32_t width, uint32_t height, gs_color_format colorFormat)
  16. : gs_obj(device, gs_type::gs_stage_surface),
  17. width(width),
  18. height(height),
  19. format(colorFormat),
  20. dxgiFormat(ConvertGSTextureFormatView(colorFormat))
  21. {
  22. HRESULT hr;
  23. memset(&td, 0, sizeof(td));
  24. td.Width = width;
  25. td.Height = height;
  26. td.MipLevels = 1;
  27. td.ArraySize = 1;
  28. td.Format = dxgiFormat;
  29. td.SampleDesc.Count = 1;
  30. td.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
  31. td.Usage = D3D11_USAGE_STAGING;
  32. hr = device->device->CreateTexture2D(&td, NULL, texture.Assign());
  33. if (FAILED(hr))
  34. throw HRError("Failed to create staging surface", hr);
  35. }
  36. gs_stage_surface::gs_stage_surface(gs_device_t *device, uint32_t width, uint32_t height, bool p010)
  37. : gs_obj(device, gs_type::gs_stage_surface),
  38. width(width),
  39. height(height),
  40. format(GS_UNKNOWN),
  41. dxgiFormat(p010 ? DXGI_FORMAT_P010 : DXGI_FORMAT_NV12)
  42. {
  43. HRESULT hr;
  44. memset(&td, 0, sizeof(td));
  45. td.Width = width;
  46. td.Height = height;
  47. td.MipLevels = 1;
  48. td.ArraySize = 1;
  49. td.Format = dxgiFormat;
  50. td.SampleDesc.Count = 1;
  51. td.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
  52. td.Usage = D3D11_USAGE_STAGING;
  53. hr = device->device->CreateTexture2D(&td, NULL, texture.Assign());
  54. if (FAILED(hr))
  55. throw HRError("Failed to create staging surface", hr);
  56. }