| 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 | #include "BsGLHardwareBufferManager.h" |
| 4 | #include "BsGLVertexBuffer.h" |
| 5 | #include "BsGLVertexArrayObjectManager.h" |
| 6 | #include "Profiling/BsRenderStats.h" |
| 7 | #include "BsGLCommandBuffer.h" |
| 8 | |
| 9 | namespace bs { namespace ct |
| 10 | { |
| 11 | static void deleteBuffer(HardwareBuffer* buffer) |
| 12 | { |
| 13 | bs_pool_delete(static_cast<GLHardwareBuffer*>(buffer)); |
| 14 | } |
| 15 | |
| 16 | GLVertexBuffer::GLVertexBuffer(const VERTEX_BUFFER_DESC& desc, GpuDeviceFlags deviceMask) |
| 17 | :VertexBuffer(desc, deviceMask) |
| 18 | { |
| 19 | assert((deviceMask == GDF_DEFAULT || deviceMask == GDF_PRIMARY) && "Multiple GPUs not supported natively on OpenGL."); |
| 20 | } |
| 21 | |
| 22 | GLVertexBuffer::~GLVertexBuffer() |
| 23 | { |
| 24 | while (!mVAObjects.empty()) |
| 25 | GLVertexArrayObjectManager::instance().notifyBufferDestroyed(mVAObjects[0]); |
| 26 | } |
| 27 | |
| 28 | void GLVertexBuffer::initialize() |
| 29 | { |
| 30 | mBuffer = bs_pool_new<GLHardwareBuffer>(GL_ARRAY_BUFFER, mSize, mUsage); |
| 31 | mBufferDeleter = &deleteBuffer; |
| 32 | |
| 33 | VertexBuffer::initialize(); |
| 34 | } |
| 35 | |
| 36 | void GLVertexBuffer::registerVAO(const GLVertexArrayObject& vao) |
| 37 | { |
| 38 | mVAObjects.push_back(vao); |
| 39 | } |
| 40 | |
| 41 | void GLVertexBuffer::unregisterVAO(const GLVertexArrayObject& vao) |
| 42 | { |
| 43 | const auto iterFind = std::find(mVAObjects.begin(), mVAObjects.end(), vao); |
| 44 | |
| 45 | if (iterFind != mVAObjects.end()) |
| 46 | mVAObjects.erase(iterFind); |
| 47 | } |
| 48 | }} |
| 49 |