Buffer.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include <AnKi/Gr/Buffer.h>
  6. #include <AnKi/Gr/GrManager.h>
  7. #include <AnKi/Gr/gl/BufferImpl.h>
  8. #include <AnKi/Gr/gl/CommandBufferImpl.h>
  9. namespace anki
  10. {
  11. Buffer* Buffer::newInstance(GrManager* manager, const BufferInitInfo& inf)
  12. {
  13. class BufferCreateCommand final : public GlCommand
  14. {
  15. public:
  16. BufferPtr m_buff;
  17. BufferCreateCommand(Buffer* buff)
  18. : m_buff(buff)
  19. {
  20. }
  21. Error operator()(GlState&)
  22. {
  23. BufferImpl& impl = static_cast<BufferImpl&>(*m_buff);
  24. impl.init();
  25. GlObject::State oldState = impl.setStateAtomically(GlObject::State::CREATED);
  26. (void)oldState;
  27. ANKI_ASSERT(oldState == GlObject::State::TO_BE_CREATED);
  28. return Error::NONE;
  29. }
  30. };
  31. BufferImpl* impl = manager->getAllocator().newInstance<BufferImpl>(manager, inf.getName());
  32. impl->getRefcount().fetchAdd(1); // Hold a reference in case the command finishes and deletes quickly
  33. impl->preInit(inf);
  34. CommandBufferPtr cmdb = manager->newCommandBuffer(CommandBufferInitInfo());
  35. static_cast<CommandBufferImpl&>(*cmdb).pushBackNewCommand<BufferCreateCommand>(impl);
  36. static_cast<CommandBufferImpl&>(*cmdb).flush();
  37. return impl;
  38. }
  39. void* Buffer::map(PtrSize offset, PtrSize range, BufferMapAccessBit access)
  40. {
  41. ANKI_GL_SELF(BufferImpl);
  42. return self.map(offset, range, access);
  43. }
  44. void Buffer::unmap()
  45. {
  46. ANKI_GL_SELF(BufferImpl);
  47. self.unmap();
  48. }
  49. } // end namespace anki