BsGLIndexBuffer.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsGLIndexBuffer.h"
  4. #include "BsGLHardwareBufferManager.h"
  5. #include "Profiling/BsRenderStats.h"
  6. #include "Error/BsException.h"
  7. #include "BsGLCommandBuffer.h"
  8. namespace bs { namespace ct
  9. {
  10. GLIndexBuffer::GLIndexBuffer(const INDEX_BUFFER_DESC& desc, GpuDeviceFlags deviceMask)
  11. :IndexBuffer(desc, deviceMask), mUsage(desc.usage)
  12. {
  13. assert((deviceMask == GDF_DEFAULT || deviceMask == GDF_PRIMARY) && "Multiple GPUs not supported natively on OpenGL.");
  14. }
  15. GLIndexBuffer::~GLIndexBuffer()
  16. {
  17. BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_IndexBuffer);
  18. }
  19. void GLIndexBuffer::initialize()
  20. {
  21. mBuffer.initialize(GL_ELEMENT_ARRAY_BUFFER, mSize, mUsage);
  22. BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_IndexBuffer);
  23. IndexBuffer::initialize();
  24. }
  25. void* GLIndexBuffer::map(UINT32 offset, UINT32 length, GpuLockOptions options, UINT32 deviceIdx, UINT32 queueIdx)
  26. {
  27. return mBuffer.lock(offset, length, options);
  28. }
  29. void GLIndexBuffer::unmap()
  30. {
  31. mBuffer.unlock();
  32. }
  33. void GLIndexBuffer::readData(UINT32 offset, UINT32 length, void* dest, UINT32 deviceIdx, UINT32 queueIdx)
  34. {
  35. mBuffer.readData(offset, length, dest);
  36. }
  37. void GLIndexBuffer::writeData(UINT32 offset, UINT32 length,
  38. const void* pSource, BufferWriteType writeFlags, UINT32 queueIdx)
  39. {
  40. mBuffer.writeData(offset, length, pSource, writeFlags);
  41. }
  42. void GLIndexBuffer::copyData(HardwareBuffer& srcBuffer, UINT32 srcOffset, UINT32 dstOffset, UINT32 length,
  43. bool discardWholeBuffer, const SPtr<ct::CommandBuffer>& commandBuffer)
  44. {
  45. auto executeRef = [this](HardwareBuffer& srcBuffer, UINT32 srcOffset, UINT32 dstOffset, UINT32 length)
  46. {
  47. GLIndexBuffer& glSrcBuffer = static_cast<GLIndexBuffer&>(srcBuffer);
  48. glSrcBuffer.mBuffer.copyData(mBuffer, srcOffset, dstOffset, length);
  49. };
  50. if (commandBuffer == nullptr)
  51. executeRef(srcBuffer, srcOffset, dstOffset, length);
  52. else
  53. {
  54. auto execute = [&]() { executeRef(srcBuffer, srcOffset, dstOffset, length); };
  55. SPtr<GLCommandBuffer> cb = std::static_pointer_cast<GLCommandBuffer>(commandBuffer);
  56. cb->queueCommand(execute);
  57. }
  58. }
  59. }}