| 1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
| 2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
| 3 | #pragma once |
| 4 | |
| 5 | #include "BsGLPrerequisites.h" |
| 6 | #include "Allocators/BsPoolAlloc.h" |
| 7 | #include "RenderAPI/BsVertexBuffer.h" |
| 8 | #include "BsGLVertexArrayObjectManager.h" |
| 9 | |
| 10 | namespace bs { namespace ct |
| 11 | { |
| 12 | /** @addtogroup GL |
| 13 | * @{ |
| 14 | */ |
| 15 | |
| 16 | /** Wrapper around a generic OpenGL buffer. */ |
| 17 | class GLHardwareBuffer : public HardwareBuffer |
| 18 | { |
| 19 | public: |
| 20 | /** Creates and initializes the buffer object. */ |
| 21 | GLHardwareBuffer(GLenum target, UINT32 size, GpuBufferUsage usage); |
| 22 | ~GLHardwareBuffer(); |
| 23 | |
| 24 | /** @copydoc HardwareBuffer::readData */ |
| 25 | void readData(UINT32 offset, UINT32 length, void* dest, UINT32 deviceIdx = 0, UINT32 queueIdx = 0) override; |
| 26 | |
| 27 | /** @copydoc HardwareBuffer::writeData */ |
| 28 | void writeData(UINT32 offset, UINT32 length, const void* source, BufferWriteType writeFlags = BWT_NORMAL, |
| 29 | UINT32 queueIdx = 0) override; |
| 30 | |
| 31 | /** @copydoc HardwareBuffer::copyData */ |
| 32 | void copyData(HardwareBuffer& srcBuffer, UINT32 srcOffset, UINT32 dstOffset, UINT32 length, |
| 33 | bool discardWholeBuffer = false, const SPtr<ct::CommandBuffer>& commandBuffer = nullptr) override; |
| 34 | |
| 35 | /** Returns internal OpenGL buffer ID. */ |
| 36 | GLuint getGLBufferId() const { return mBufferId; } |
| 37 | |
| 38 | private: |
| 39 | /** @copydoc HardwareBuffer::map */ |
| 40 | void* map(UINT32 offset, UINT32 length, GpuLockOptions options, UINT32 deviceIdx, UINT32 queueIdx) override; |
| 41 | |
| 42 | /** @copydoc HardwareBuffer::unmap */ |
| 43 | void unmap() override; |
| 44 | |
| 45 | GLenum mTarget; |
| 46 | GLuint mBufferId = 0; |
| 47 | |
| 48 | bool mZeroLocked = false; |
| 49 | }; |
| 50 | |
| 51 | /** @} */ |
| 52 | }} |
| 53 | |
| 54 | namespace bs |
| 55 | { |
| 56 | IMPLEMENT_GLOBAL_POOL(ct::GLHardwareBuffer, 32) |
| 57 | } |