StreamBuffer.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2008 Dolphin Emulator Project
  2. // Licensed under GPLv2+
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <utility>
  6. #include "VideoBackends/OGL/FramebufferManager.h"
  7. #include "VideoBackends/OGL/GLUtil.h"
  8. #include "VideoCommon/VideoCommon.h"
  9. namespace OGL
  10. {
  11. class StreamBuffer
  12. {
  13. public:
  14. static StreamBuffer* Create(u32 type, u32 size);
  15. virtual ~StreamBuffer();
  16. /* This mapping function will return a pair of:
  17. * - the pointer to the mapped buffer
  18. * - the offset into the real GPU buffer (always multiple of stride)
  19. * On mapping, the maximum of size for allocation has to be set.
  20. * The size really pushed into this fifo only has to be known on Unmapping.
  21. * Mapping invalidates the current buffer content,
  22. * so it isn't allowed to access the old content any more.
  23. */
  24. virtual std::pair<u8*, u32> Map(u32 size) = 0;
  25. virtual void Unmap(u32 used_size) = 0;
  26. inline std::pair<u8*, u32> Map(u32 size, u32 stride)
  27. {
  28. u32 padding = m_iterator % stride;
  29. if (padding)
  30. {
  31. m_iterator += stride - padding;
  32. }
  33. return Map(size);
  34. }
  35. const u32 m_buffer;
  36. protected:
  37. StreamBuffer(u32 type, u32 size);
  38. void CreateFences();
  39. void DeleteFences();
  40. void AllocMemory(u32 size);
  41. const u32 m_buffertype;
  42. const u32 m_size;
  43. u32 m_iterator;
  44. u32 m_used_iterator;
  45. u32 m_free_iterator;
  46. private:
  47. static const int SYNC_POINTS = 16;
  48. inline int SLOT(u32 x) const { return x >> m_bit_per_slot; }
  49. const int m_bit_per_slot;
  50. GLsync fences[SYNC_POINTS];
  51. };
  52. }