d3d11-indexbuffer.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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_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,
  30. void *indices, size_t num, 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: indexSize = 2; break;
  39. case GS_UNSIGNED_LONG: indexSize = 4; break;
  40. }
  41. InitBuffer();
  42. }