BsGLBuffer.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsGLPrerequisites.h"
  5. #include "BsVertexBuffer.h"
  6. #include "BsGLVertexArrayObjectManager.h"
  7. namespace BansheeEngine
  8. {
  9. /** @addtogroup GL
  10. * @{
  11. */
  12. /** Wrapper around a generic OpenGL buffer. */
  13. class BS_RSGL_EXPORT GLBuffer
  14. {
  15. public:
  16. GLBuffer();
  17. GLBuffer(GLenum target, UINT32 size, GpuBufferUsage usage);
  18. ~GLBuffer();
  19. /**
  20. * Locks a portion of the buffer and returns pointer to the locked area. You must call unlock() when done.
  21. *
  22. * @param[in] offset Offset in bytes from which to lock the buffer.
  23. * @param[in] length Length of the area you want to lock, in bytes.
  24. * @param[in] options Signifies what you want to do with the returned pointer. Caller must ensure not to do
  25. * anything he hasn't requested (for example don't try to read from the buffer unless you
  26. * requested it here).
  27. */
  28. void* lock(UINT32 offset, UINT32 length, GpuLockOptions options);
  29. /** Releases the lock on this buffer. */
  30. void unlock();
  31. /**
  32. * Reads data from a portion of the buffer and copies it to the destination buffer. Caller must ensure destination
  33. * buffer is large enough.
  34. *
  35. * @param[in] offset Offset in bytes from which to copy the data.
  36. * @param[in] length Length of the area you want to copy, in bytes.
  37. * @param[in] dest Destination buffer large enough to store the read data.
  38. */
  39. void readData(UINT32 offset, UINT32 length, void* dest);
  40. /**
  41. * Writes data into a portion of the buffer from the source memory.
  42. *
  43. * @param[in] offset Offset in bytes from which to copy the data.
  44. * @param[in] length Length of the area you want to copy, in bytes.
  45. * @param[in] source Source buffer containing the data to write.
  46. * @param[in] writeFlags Optional write flags that may affect performance.
  47. */
  48. void writeData(UINT32 offset, UINT32 length, const void* source,
  49. BufferWriteType writeFlags = BufferWriteType::Normal);
  50. /** Returns internal OpenGL buffer ID. */
  51. GLuint getGLBufferId() const { return mBufferId; }
  52. private:
  53. GLenum mTarget;
  54. GLuint mBufferId;
  55. bool mZeroLocked;
  56. };
  57. /** @} */
  58. }