d3d11-indexbuffer.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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_index_buffer::InitBuffer()
  16. {
  17. HRESULT hr;
  18. memset(&bd, 0, sizeof(bd));
  19. memset(&srd, 0, sizeof(srd));
  20. bd.Usage = dynamic ? D3D11_USAGE_DYNAMIC : D3D11_USAGE_DEFAULT;
  21. bd.CPUAccessFlags = dynamic ? D3D11_CPU_ACCESS_WRITE : 0;
  22. bd.BindFlags = D3D11_BIND_INDEX_BUFFER;
  23. bd.ByteWidth = UINT(indexSize * num);
  24. srd.pSysMem = indices.data;
  25. hr = device->device->CreateBuffer(&bd, &srd, indexBuffer.Assign());
  26. if (FAILED(hr))
  27. throw HRError("Failed to create buffer", hr);
  28. }
  29. gs_index_buffer::gs_index_buffer(gs_device_t *device, enum gs_index_type type, void *indices, size_t num,
  30. uint32_t flags)
  31. : gs_obj(device, gs_type::gs_index_buffer),
  32. dynamic((flags & GS_DYNAMIC) != 0),
  33. type(type),
  34. num(num),
  35. indices(indices)
  36. {
  37. switch (type) {
  38. case GS_UNSIGNED_SHORT:
  39. indexSize = 2;
  40. break;
  41. case GS_UNSIGNED_LONG:
  42. indexSize = 4;
  43. break;
  44. }
  45. InitBuffer();
  46. }