GS_D3D11IndexBuffer.cpp 1.8 KB

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