BsGLBuffer.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 "RenderAPI/BsVertexBuffer.h"
  6. #include "BsGLVertexArrayObjectManager.h"
  7. namespace bs { namespace ct
  8. {
  9. /** @addtogroup GL
  10. * @{
  11. */
  12. /** Wrapper around a generic OpenGL buffer. */
  13. class GLBuffer
  14. {
  15. public:
  16. /** Creates an uninitialized buffer object. You must call initialize() before using it. */
  17. GLBuffer();
  18. /** Creates and initializes the buffer object. */
  19. GLBuffer(GLenum target, UINT32 size, GpuBufferUsage usage);
  20. ~GLBuffer();
  21. /**
  22. * Initializes the internal buffer object. Done automatically if the buffer was constructed using non-zero
  23. * parameter constructor.
  24. */
  25. void initialize(GLenum target, UINT32 size, GpuBufferUsage usage);
  26. /**
  27. * Locks a portion of the buffer and returns pointer to the locked area. You must call unlock() when done.
  28. *
  29. * @param[in] offset Offset in bytes from which to lock the buffer.
  30. * @param[in] length Length of the area you want to lock, in bytes.
  31. * @param[in] options Signifies what you want to do with the returned pointer. Caller must ensure not to do
  32. * anything he hasn't requested (for example don't try to read from the buffer unless you
  33. * requested it here).
  34. */
  35. void* lock(UINT32 offset, UINT32 length, GpuLockOptions options);
  36. /** Releases the lock on this buffer. */
  37. void unlock();
  38. /**
  39. * Reads data from a portion of the buffer and copies it to the destination buffer. Caller must ensure destination
  40. * buffer is large enough.
  41. *
  42. * @param[in] offset Offset in bytes from which to copy the data.
  43. * @param[in] length Length of the area you want to copy, in bytes.
  44. * @param[in] dest Destination buffer large enough to store the read data.
  45. */
  46. void readData(UINT32 offset, UINT32 length, void* dest);
  47. /**
  48. * Writes data into a portion of the buffer from the source memory.
  49. *
  50. * @param[in] offset Offset in bytes from which to copy the data.
  51. * @param[in] length Length of the area you want to copy, in bytes.
  52. * @param[in] source Source buffer containing the data to write.
  53. * @param[in] writeFlags Optional write flags that may affect performance.
  54. */
  55. void writeData(UINT32 offset, UINT32 length, const void* source,
  56. BufferWriteType writeFlags = BWT_NORMAL);
  57. /**
  58. * Copies data from a specific portion of this buffer into a specific portion of the provided buffer.
  59. *
  60. * @param[in] dstBuffer Buffer to copy from.
  61. * @param[in] srcOffset Offset into the source buffer to start copying from, in bytes.
  62. * @param[in] dstOffset Offset into this buffer to start copying to, in bytes.
  63. * @param[in] length Size of the data to copy, in bytes.
  64. */
  65. void copyData(GLBuffer& dstBuffer, UINT32 srcOffset, UINT32 dstOffset, UINT32 length);
  66. /** Returns internal OpenGL buffer ID. */
  67. GLuint getGLBufferId() const { return mBufferId; }
  68. private:
  69. GLenum mTarget;
  70. GLuint mBufferId;
  71. bool mZeroLocked;
  72. };
  73. /** @} */
  74. }}