diff options
-rw-r--r-- | drape/batcher_helpers.cpp | 4 | ||||
-rw-r--r-- | drape/buffer_base.hpp | 3 | ||||
-rw-r--r-- | drape/cpu_buffer.cpp | 14 | ||||
-rw-r--r-- | drape/cpu_buffer.hpp | 4 | ||||
-rw-r--r-- | drape/data_buffer.cpp | 100 | ||||
-rw-r--r-- | drape/data_buffer.hpp | 26 | ||||
-rw-r--r-- | drape/drape_tests/batcher_tests.cpp | 52 | ||||
-rw-r--r-- | drape/drape_tests/buffer_tests.cpp | 27 | ||||
-rw-r--r-- | drape/gpu_buffer.cpp | 23 | ||||
-rw-r--r-- | drape/gpu_buffer.hpp | 4 | ||||
-rw-r--r-- | drape/index_buffer.cpp | 4 | ||||
-rw-r--r-- | drape/index_buffer.hpp | 4 | ||||
-rw-r--r-- | drape/vertex_array_buffer.cpp | 21 |
13 files changed, 217 insertions, 69 deletions
diff --git a/drape/batcher_helpers.cpp b/drape/batcher_helpers.cpp index 037a4ed261..277273d201 100644 --- a/drape/batcher_helpers.cpp +++ b/drape/batcher_helpers.cpp @@ -374,7 +374,7 @@ void TriangleFanBatch::BatchData(RefPointer<AttributeProvider> streams) { CPUBuffer & cpuBuffer = cpuBuffers[i]; ASSERT(cpuBuffer.GetCurrentElementNumber() == 1, ()); - cpuBuffer.UploadData(streams->GetRawPointer(i), batchVertexCount); + cpuBuffer.UploadData(streams->GetRawPointer(i), batchVertexCount, false /* advanceCursor */); // now in cpuBuffer we have correct "fan" created from second part of data // first vertex of cpuBuffer if the first vertex of params, second vertex is @@ -421,7 +421,7 @@ void TriangleFanBatch::BatchData(RefPointer<AttributeProvider> streams) /// + last vertex of currently uploaded data. cpuBuffers.push_back(CPUBuffer(binding.GetElementSize(), (vertexCount + 2) - batchVertexCount)); CPUBuffer & cpuBuffer = cpuBuffers.back(); - cpuBuffer.UploadData(rawDataPointer, 1); + cpuBuffer.UploadData(rawDataPointer, 1, false /* advanceCursor */); } // advance on uploadVertexCount - 1 to copy last vertex also into next VAO with diff --git a/drape/buffer_base.hpp b/drape/buffer_base.hpp index bc7234a1e6..aa3ece57e5 100644 --- a/drape/buffer_base.hpp +++ b/drape/buffer_base.hpp @@ -14,9 +14,10 @@ public: uint16_t GetCurrentSize() const; uint16_t GetAvailableSize() const; + uint8_t GetElementSize() const; + protected: void Resize(uint16_t elementCount); - uint8_t GetElementSize() const; void Seek(uint16_t elementNumber); void UploadData(uint16_t elementCount); diff --git a/drape/cpu_buffer.cpp b/drape/cpu_buffer.cpp index c22d38502d..65763661f0 100644 --- a/drape/cpu_buffer.cpp +++ b/drape/cpu_buffer.cpp @@ -10,7 +10,7 @@ namespace dp { CPUBuffer::CPUBuffer(uint8_t elementSize, uint16_t capacity) - : base_t(elementSize, capacity) + : TBase(elementSize, capacity) { uint32_t memorySize = my::NextPowOf2(GetCapacity() * GetElementSize()); m_memory = SharedBufferManager::instance().reserveSharedBuffer(memorySize); @@ -23,7 +23,7 @@ CPUBuffer::~CPUBuffer() SharedBufferManager::instance().freeSharedBuffer(m_memory->size(), m_memory); } -void CPUBuffer::UploadData(void const * data, uint16_t elementCount) +void CPUBuffer::UploadData(void const * data, uint16_t elementCount, bool const advanceCursor) { uint32_t byteCountToCopy = GetElementSize() * elementCount; #ifdef DEBUG @@ -32,14 +32,20 @@ void CPUBuffer::UploadData(void const * data, uint16_t elementCount) #endif memcpy(GetCursor(), data, byteCountToCopy); - base_t::UploadData(elementCount); + TBase::UploadData(elementCount); + + if (advanceCursor) + { + uint32_t offsetFromBegin = GetElementSize() * GetCurrentSize(); + m_memoryCursor = NonConstData() + offsetFromBegin; + } } void CPUBuffer::Seek(uint16_t elementNumber) { uint32_t offsetFromBegin = GetElementSize() * elementNumber; ASSERT(Data() + offsetFromBegin <= Data() + m_memory->size(), ()); - base_t::Seek(elementNumber); + TBase::Seek(elementNumber); m_memoryCursor = NonConstData() + offsetFromBegin; } diff --git a/drape/cpu_buffer.hpp b/drape/cpu_buffer.hpp index d0836919b9..88cd7d5c1e 100644 --- a/drape/cpu_buffer.hpp +++ b/drape/cpu_buffer.hpp @@ -10,12 +10,12 @@ namespace dp class CPUBuffer : public BufferBase { - typedef BufferBase base_t; + typedef BufferBase TBase; public: CPUBuffer(uint8_t elementSize, uint16_t capacity); ~CPUBuffer(); - void UploadData(void const * data, uint16_t elementCount); + void UploadData(void const * data, uint16_t elementCount, bool const advanceCursor); // Set memory cursor on element with number == "elementNumber" // Element numbers start from 0 void Seek(uint16_t elementNumber); diff --git a/drape/data_buffer.cpp b/drape/data_buffer.cpp index e5180739d7..5f40a967a5 100644 --- a/drape/data_buffer.cpp +++ b/drape/data_buffer.cpp @@ -3,9 +3,105 @@ namespace dp { -DataBuffer::DataBuffer(uint8_t elementSize, uint16_t capacity) - : GPUBuffer(GPUBuffer::ElementBuffer, elementSize, capacity) +DataBuffer::DataBuffer(GPUBuffer::Target target, uint8_t elementSize, uint16_t capacity) : + m_target(target) { + m_cpuBuffer.Reset(new CPUBuffer(elementSize, capacity)); +} + +DataBuffer::~DataBuffer() +{ + if (!m_cpuBuffer.IsNull()) + m_cpuBuffer.Destroy(); + + if (!m_gpuBuffer.IsNull()) + m_gpuBuffer.Destroy(); +} + +void DataBuffer::UploadData(void const * data, uint16_t elementCount) +{ + if (!m_cpuBuffer.IsNull()) + { + ASSERT(m_gpuBuffer.IsNull(), ("GPU buffer must not exist until CPU buffer is alive")); + m_cpuBuffer->UploadData(data, elementCount, true /* advanceCursor */); + } + else + { + ASSERT(m_cpuBuffer.IsNull(), ("CPU buffer must not exist if GPU buffer is created")); + m_gpuBuffer->UploadData(data, elementCount); + } +} + +void DataBuffer::Seek(uint16_t elementNumber) +{ + if (!m_cpuBuffer.IsNull()) + m_cpuBuffer->Seek(elementNumber); + else + m_gpuBuffer->Seek(elementNumber); +} + +uint16_t DataBuffer::GetCapacity() const +{ + if (!m_cpuBuffer.IsNull()) + { + return m_cpuBuffer->GetCapacity(); + } + + return m_gpuBuffer->GetCapacity(); +} + +uint16_t DataBuffer::GetCurrentSize() const +{ + if (!m_cpuBuffer.IsNull()) + { + return m_cpuBuffer->GetCurrentSize(); + } + + return m_gpuBuffer->GetCurrentSize(); +} + +uint16_t DataBuffer::GetAvailableSize() const +{ + if (!m_cpuBuffer.IsNull()) + { + return m_cpuBuffer->GetAvailableSize(); + } + + return m_gpuBuffer->GetAvailableSize(); +} + +void DataBuffer::Bind() +{ + ASSERT(!m_gpuBuffer.IsNull(), ("GPU buffer must be alive here")); + m_gpuBuffer->Bind(); +} + +dp::RefPointer<GPUBuffer> DataBuffer::GetGpuBuffer() const +{ + ASSERT(!m_gpuBuffer.IsNull(), ("GPU buffer must be alive here")); + return m_gpuBuffer.GetRefPointer(); +} + +dp::RefPointer<CPUBuffer> DataBuffer::GetСpuBuffer() const +{ + ASSERT(!m_cpuBuffer.IsNull(), ("CPU buffer must be alive here")); + return m_cpuBuffer.GetRefPointer(); +} + +void DataBuffer::MoveToGPU() +{ + ASSERT(m_gpuBuffer.IsNull() && !m_cpuBuffer.IsNull(), ("Duplicate buffer's moving from CPU to GPU")); + + uint8_t const elementSize = m_cpuBuffer->GetElementSize(); + + // if currentSize is 0 buffer hasn't been filled on preparation stage, let it be filled further + uint16_t const currentSize = m_cpuBuffer->GetCurrentSize(); + if (currentSize != 0) + m_gpuBuffer.Reset(new GPUBuffer(m_target, m_cpuBuffer->Data(), elementSize, currentSize)); + else + m_gpuBuffer.Reset(new GPUBuffer(m_target, nullptr, elementSize, m_cpuBuffer->GetAvailableSize())); + + m_cpuBuffer.Destroy(); } } diff --git a/drape/data_buffer.hpp b/drape/data_buffer.hpp index f22c7a31c9..b0614e2066 100644 --- a/drape/data_buffer.hpp +++ b/drape/data_buffer.hpp @@ -1,14 +1,36 @@ #pragma once +#include "drape/cpu_buffer.hpp" #include "drape/gpu_buffer.hpp" namespace dp { -class DataBuffer : public GPUBuffer +/// This class works as proxy. It contains CPU-buffer or GPU-buffer inside at a moment +/// and redirects invocations of methods to one or another buffer. Initially it's configured +/// as CPU-buffer and is able to move data from CPU to GPU only once. +class DataBuffer { public: - DataBuffer(uint8_t elementSize, uint16_t capacity); + DataBuffer(GPUBuffer::Target target, uint8_t elementSize, uint16_t capacity); + ~DataBuffer(); + + uint16_t GetCapacity() const; + uint16_t GetCurrentSize() const; + uint16_t GetAvailableSize() const; + + void UploadData(void const * data, uint16_t elementCount); + void Seek(uint16_t elementNumber); + void Bind(); + void MoveToGPU(); + + dp::RefPointer<GPUBuffer> GetGpuBuffer() const; + dp::RefPointer<CPUBuffer> GetСpuBuffer() const; + +private: + dp::MasterPointer<GPUBuffer> m_gpuBuffer; + dp::MasterPointer<CPUBuffer> m_cpuBuffer; + GPUBuffer::Target m_target; }; } // namespace dp diff --git a/drape/drape_tests/batcher_tests.cpp b/drape/drape_tests/batcher_tests.cpp index 56c0d15f25..d4eb0c2419 100644 --- a/drape/drape_tests/batcher_tests.cpp +++ b/drape/drape_tests/batcher_tests.cpp @@ -84,31 +84,23 @@ public: vaoAcceptor.m_vao[i].Destroy(); } - void ExpectBufferCreation(uint16_t vertxeCount, uint16_t indexCount, + void ExpectBufferCreation(uint16_t vertexCount, uint16_t indexCount, MemoryComparer const & indexCmp, MemoryComparer const & vertexCmp) { InSequence seq; - // Index buffer creation - EXPECTGL(glGenBuffer()).WillOnce(Return(m_indexBufferID)); - EXPECTGL(glBindBuffer(m_indexBufferID, gl_const::GLElementArrayBuffer)); - EXPECTGL(glBufferData(gl_const::GLElementArrayBuffer, _, NULL, _)); - - // upload indexes - EXPECTGL(glBindBuffer(m_indexBufferID, gl_const::GLElementArrayBuffer)); - EXPECTGL(glBufferSubData(gl_const::GLElementArrayBuffer, indexCount * sizeof(unsigned short), _, 0)) - .WillOnce(Invoke(&indexCmp, &MemoryComparer::cmpSubBuffer)); - // data buffer creation EXPECTGL(glGenBuffer()).WillOnce(Return(m_dataBufferID)); EXPECTGL(glBindBuffer(m_dataBufferID, gl_const::GLArrayBuffer)); - EXPECTGL(glBufferData(gl_const::GLArrayBuffer, _, NULL, _)); - - // upload data - EXPECTGL(glBindBuffer(m_dataBufferID, gl_const::GLArrayBuffer)); - EXPECTGL(glBufferSubData(gl_const::GLArrayBuffer, vertxeCount * sizeof(float), _, 0)) + EXPECTGL(glBufferData(gl_const::GLArrayBuffer, vertexCount * sizeof(float), _, gl_const::GLDynamicDraw)) .WillOnce(Invoke(&vertexCmp, &MemoryComparer::cmpSubBuffer)); + // Index buffer creation + EXPECTGL(glGenBuffer()).WillOnce(Return(m_indexBufferID)); + EXPECTGL(glBindBuffer(m_indexBufferID, gl_const::GLElementArrayBuffer)); + EXPECTGL(glBufferData(gl_const::GLElementArrayBuffer, indexCount * sizeof(unsigned short), _, gl_const::GLDynamicDraw)) + .WillOnce(Invoke(&indexCmp, &MemoryComparer::cmpSubBuffer)); + EXPECTGL(glBindBuffer(0, gl_const::GLElementArrayBuffer)); EXPECTGL(glBindBuffer(0, gl_const::GLArrayBuffer)); } @@ -265,30 +257,26 @@ namespace currentNode.m_indexBufferID = m_bufferIDCounter++; currentNode.m_vertexBufferID = m_bufferIDCounter++; - // Index buffer creation - EXPECTGL(glGenBuffer()).WillOnce(Return(currentNode.m_indexBufferID)); - EXPECTGL(glBindBuffer(currentNode.m_indexBufferID, gl_const::GLElementArrayBuffer)); - EXPECTGL(glBufferData(gl_const::GLElementArrayBuffer, _, NULL, _)); - - m_comparators.push_back(new MemoryComparer(currentNode.m_indexData, currentNode.m_indexByteCount)); - MemoryComparer * indexComparer = m_comparators.back(); - // upload indexes - EXPECTGL(glBindBuffer(currentNode.m_indexBufferID, gl_const::GLElementArrayBuffer)); - EXPECTGL(glBufferSubData(gl_const::GLElementArrayBuffer, currentNode.m_indexByteCount, _, 0)) - .WillOnce(Invoke(indexComparer, &MemoryComparer::cmpSubBuffer)); - // data buffer creation EXPECTGL(glGenBuffer()).WillOnce(Return(currentNode.m_vertexBufferID)); EXPECTGL(glBindBuffer(currentNode.m_vertexBufferID, gl_const::GLArrayBuffer)); - EXPECTGL(glBufferData(gl_const::GLArrayBuffer, _, NULL, _)); m_comparators.push_back(new MemoryComparer(currentNode.m_vertexData, currentNode.m_vertexByteCount)); MemoryComparer * vertexComparer = m_comparators.back(); - // upload data - EXPECTGL(glBindBuffer(currentNode.m_vertexBufferID, gl_const::GLArrayBuffer)); - EXPECTGL(glBufferSubData(gl_const::GLArrayBuffer, currentNode.m_vertexByteCount, _, 0)) + + EXPECTGL(glBufferData(gl_const::GLArrayBuffer, currentNode.m_vertexByteCount, _, gl_const::GLDynamicDraw)) .WillOnce(Invoke(vertexComparer, &MemoryComparer::cmpSubBuffer)); + // Index buffer creation + EXPECTGL(glGenBuffer()).WillOnce(Return(currentNode.m_indexBufferID)); + EXPECTGL(glBindBuffer(currentNode.m_indexBufferID, gl_const::GLElementArrayBuffer)); + + m_comparators.push_back(new MemoryComparer(currentNode.m_indexData, currentNode.m_indexByteCount)); + MemoryComparer * indexComparer = m_comparators.back(); + + EXPECTGL(glBufferData(gl_const::GLElementArrayBuffer, currentNode.m_indexByteCount, _, gl_const::GLDynamicDraw)) + .WillOnce(Invoke(indexComparer, &MemoryComparer::cmpSubBuffer)); + EXPECTGL(glBindBuffer(0, gl_const::GLElementArrayBuffer)); EXPECTGL(glBindBuffer(0, gl_const::GLArrayBuffer)); } diff --git a/drape/drape_tests/buffer_tests.cpp b/drape/drape_tests/buffer_tests.cpp index 37d2c098d0..5bca53250a 100644 --- a/drape/drape_tests/buffer_tests.cpp +++ b/drape/drape_tests/buffer_tests.cpp @@ -25,7 +25,8 @@ UNIT_TEST(CreateDestroyDataBufferTest) EXPECTGL(glBindBuffer(0, gl_const::GLArrayBuffer)); EXPECTGL(glDeleteBuffer(1)); - GPUBuffer * buffer = new DataBuffer(3 * sizeof(float), 100); + DataBuffer * buffer = new DataBuffer(GPUBuffer::ElementBuffer, 3 * sizeof(float), 100); + buffer->MoveToGPU(); delete buffer; } @@ -38,7 +39,8 @@ UNIT_TEST(CreateDestroyIndexBufferTest) EXPECTGL(glBindBuffer(0, gl_const::GLElementArrayBuffer)); EXPECTGL(glDeleteBuffer(1)); - GPUBuffer * buffer = new IndexBuffer(100); + DataBuffer * buffer = new IndexBuffer(100); + buffer->MoveToGPU(); delete buffer; } @@ -48,17 +50,17 @@ UNIT_TEST(UploadDataTest) for (int i = 0; i < 3 * 100; ++i) data[i] = (float)i; + DataBuffer * buffer = new DataBuffer(GPUBuffer::ElementBuffer, 3 * sizeof(float), 100); + InSequence s; EXPECTGL(glGenBuffer()).WillOnce(Return(1)); EXPECTGL(glBindBuffer(1, gl_const::GLArrayBuffer)); - EXPECTGL(glBufferData(gl_const::GLArrayBuffer, 3 * 100 * sizeof(float), NULL, gl_const::GLDynamicDraw)); - EXPECTGL(glBindBuffer(1, gl_const::GLArrayBuffer)); - EXPECTGL(glBufferSubData(gl_const::GLArrayBuffer, 3 * 100 * sizeof(float), data, 0)); + EXPECTGL(glBufferData(gl_const::GLArrayBuffer, 3 * 100 * sizeof(float), buffer->GetСpuBuffer()->Data(), gl_const::GLDynamicDraw)); EXPECTGL(glBindBuffer(0, gl_const::GLArrayBuffer)); EXPECTGL(glDeleteBuffer(1)); - GPUBuffer * buffer = new GPUBuffer(GPUBuffer::ElementBuffer, 3 * sizeof(float), 100); buffer->UploadData(data, 100); + buffer->MoveToGPU(); delete buffer; } @@ -74,18 +76,15 @@ UNIT_TEST(ParticalUploadDataTest) for (int i = 0; i < kPart2Size; ++i) part2Data[i] = (float)i; + DataBuffer * buffer = new DataBuffer(GPUBuffer::ElementBuffer, 3 * sizeof(float), 100); + InSequence s; EXPECTGL(glGenBuffer()).WillOnce(Return(1)); EXPECTGL(glBindBuffer(1, gl_const::GLArrayBuffer)); - EXPECTGL(glBufferData(gl_const::GLArrayBuffer, 3 * 100 * sizeof(float), NULL, gl_const::GLDynamicDraw)); - EXPECTGL(glBindBuffer(1, gl_const::GLArrayBuffer)); - EXPECTGL(glBufferSubData(gl_const::GLArrayBuffer, 3 * 30 * sizeof(float), part1Data, 0)); - EXPECTGL(glBindBuffer(1, gl_const::GLArrayBuffer)); - EXPECTGL(glBufferSubData(gl_const::GLArrayBuffer, 3 * 70 * sizeof(float), part2Data, 3 * 30 * sizeof(float))); + EXPECTGL(glBufferData(gl_const::GLArrayBuffer, 3 * 100 * sizeof(float), buffer->GetСpuBuffer()->Data(), gl_const::GLDynamicDraw)); EXPECTGL(glBindBuffer(0, gl_const::GLArrayBuffer)); EXPECTGL(glDeleteBuffer(1)); - GPUBuffer * buffer = new GPUBuffer(GPUBuffer::ElementBuffer, 3 * sizeof(float), 100); TEST_EQUAL(buffer->GetCapacity(), 100, ()); TEST_EQUAL(buffer->GetAvailableSize(), 100, ()); TEST_EQUAL(buffer->GetCurrentSize(), 0, ()); @@ -95,10 +94,12 @@ UNIT_TEST(ParticalUploadDataTest) TEST_EQUAL(buffer->GetAvailableSize(), 70, ()); TEST_EQUAL(buffer->GetCurrentSize(), 30, ()); - buffer->UploadData(part2Data , 70); + buffer->UploadData(part2Data, 70); TEST_EQUAL(buffer->GetCapacity(), 100, ()); TEST_EQUAL(buffer->GetAvailableSize(), 0, ()); TEST_EQUAL(buffer->GetCurrentSize(), 100, ()); + buffer->MoveToGPU(); + delete buffer; } diff --git a/drape/gpu_buffer.cpp b/drape/gpu_buffer.cpp index 20ec19c2f3..12afbdc44e 100644 --- a/drape/gpu_buffer.cpp +++ b/drape/gpu_buffer.cpp @@ -30,6 +30,11 @@ glConst glTarget(GPUBuffer::Target t) } GPUBuffer::GPUBuffer(Target t, uint8_t elementSize, uint16_t capacity) + : GPUBuffer(t, nullptr, elementSize, capacity) +{ +} + +GPUBuffer::GPUBuffer(Target t, void const * data, uint8_t elementSize, uint16_t capacity) : TBase(elementSize, capacity) , m_t(t) #ifdef DEBUG @@ -37,9 +42,8 @@ GPUBuffer::GPUBuffer(Target t, uint8_t elementSize, uint16_t capacity) #endif { m_bufferID = GLFunctions::glGenBuffer(); - Resize(capacity); + Resize(data, capacity); } - GPUBuffer::~GPUBuffer() { GLFunctions::glBindBuffer(0, glTarget(m_t)); @@ -73,6 +77,11 @@ void GPUBuffer::UploadData(void const * data, uint16_t elementCount) #endif } +void GPUBuffer::Seek(uint16_t elementNumber) +{ + TBase::Seek(elementNumber); +} + void GPUBuffer::Bind() { GLFunctions::glBindBuffer(m_bufferID, glTarget(m_t)); @@ -130,15 +139,21 @@ void GPUBuffer::Unmap() GLFunctions::glUnmapBuffer(glTarget(m_t)); } -void GPUBuffer::Resize(uint16_t elementCount) +void GPUBuffer::Resize(void const * data, uint16_t elementCount) { TBase::Resize(elementCount); Bind(); - GLFunctions::glBufferData(glTarget(m_t), GetCapacity() * GetElementSize(), NULL, gl_const::GLDynamicDraw); + GLFunctions::glBufferData(glTarget(m_t), GetCapacity() * GetElementSize(), data, gl_const::GLDynamicDraw); + + if (data != nullptr) + TBase::UploadData(elementCount); + #if defined(TRACK_GPU_MEM) dp::GPUMemTracker & memTracker = dp::GPUMemTracker::Inst(); memTracker.RemoveDeallocated("VBO", m_bufferID); memTracker.AddAllocated("VBO", m_bufferID, GetCapacity() * GetElementSize()); + if (data != nullptr) + dp::GPUMemTracker::Inst().SetUsed("VBO", m_bufferID, GetCurrentSize() * GetElementSize()); #endif } diff --git a/drape/gpu_buffer.hpp b/drape/gpu_buffer.hpp index 4762c71e80..0cd8a87123 100644 --- a/drape/gpu_buffer.hpp +++ b/drape/gpu_buffer.hpp @@ -18,10 +18,12 @@ public: public: GPUBuffer(Target t, uint8_t elementSize, uint16_t capacity); + GPUBuffer(Target t, void const * data, uint8_t elementSize, uint16_t capacity); ~GPUBuffer(); void UploadData(void const * data, uint16_t elementCount); void Bind(); + void Seek(uint16_t elementNumber); protected: void * Map(); @@ -29,7 +31,7 @@ protected: void Unmap(); /// discard old data - void Resize(uint16_t elementCount); + void Resize(void const * data, uint16_t elementCount); private: friend class GPUBufferMapper; diff --git a/drape/index_buffer.cpp b/drape/index_buffer.cpp index 839bc9d22d..13fbbfcc88 100644 --- a/drape/index_buffer.cpp +++ b/drape/index_buffer.cpp @@ -4,13 +4,13 @@ namespace dp { IndexBuffer::IndexBuffer(uint16_t capacity) - : GPUBuffer(GPUBuffer::IndexBuffer, sizeof(uint16_t), capacity) + : DataBuffer(GPUBuffer::IndexBuffer, sizeof(uint16_t), capacity) { } void IndexBuffer::UploadData(uint16_t const * data, uint16_t size) { - GPUBuffer::UploadData((void *)data, size); + DataBuffer::UploadData((void *)data, size); } void IndexBuffer::UpdateData(uint16_t const * data, uint16_t size) diff --git a/drape/index_buffer.hpp b/drape/index_buffer.hpp index 7572854d30..922d9516dd 100644 --- a/drape/index_buffer.hpp +++ b/drape/index_buffer.hpp @@ -1,11 +1,11 @@ #pragma once -#include "drape/gpu_buffer.hpp" +#include "drape/data_buffer.hpp" namespace dp { -class IndexBuffer : public GPUBuffer +class IndexBuffer : public DataBuffer { public: IndexBuffer(uint16_t capacity); diff --git a/drape/vertex_array_buffer.cpp b/drape/vertex_array_buffer.cpp index 663fff9093..41e43821ae 100644 --- a/drape/vertex_array_buffer.cpp +++ b/drape/vertex_array_buffer.cpp @@ -34,6 +34,19 @@ VertexArrayBuffer::~VertexArrayBuffer() void VertexArrayBuffer::Preflush() { + /// buffers are ready, so moving them from CPU to GPU + for(auto & buffer : m_staticBuffers) + { + buffer.second->MoveToGPU(); + } + + for(auto & buffer : m_dynamicBuffers) + { + buffer.second->MoveToGPU(); + } + + m_indexBuffer->MoveToGPU(); + GLFunctions::glBindBuffer(0, gl_const::GLElementArrayBuffer); GLFunctions::glBindBuffer(0, gl_const::GLArrayBuffer); } @@ -76,9 +89,13 @@ void VertexArrayBuffer::UploadData(BindingInfo const & bindingInfo, void const * { RefPointer<DataBuffer> buffer; if (!bindingInfo.IsDynamic()) + { buffer = GetOrCreateStaticBuffer(bindingInfo); + } else + { buffer = GetOrCreateDynamicBuffer(bindingInfo); + } buffer->UploadData(data, count); } @@ -124,7 +141,7 @@ RefPointer<DataBuffer> VertexArrayBuffer::GetOrCreateBuffer(BindingInfo const & if (it == buffers->end()) { MasterPointer<DataBuffer> & buffer = (*buffers)[bindingInfo]; - buffer.Reset(new DataBuffer(bindingInfo.GetElementSize(), m_dataBufferSize)); + buffer.Reset(new DataBuffer(GPUBuffer::ElementBuffer, bindingInfo.GetElementSize(), m_dataBufferSize)); return buffer.GetRefPointer(); } @@ -198,7 +215,7 @@ void VertexArrayBuffer::ApplyMutation(RefPointer<IndexBufferMutator> indexMutato { RefPointer<DataBuffer> buffer = GetDynamicBuffer(it->first); ASSERT(!buffer.IsNull(), ()); - GPUBufferMapper mapper(buffer); + GPUBufferMapper mapper(buffer->GetGpuBuffer()); TMutateNodes const & nodes = it->second; for (size_t i = 0; i < nodes.size(); ++i) |