diff options
author | Daria Volvenkova <d.volvenkova@corp.mail.ru> | 2017-05-16 14:42:32 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-16 14:42:32 +0300 |
commit | d2f79bd2c7004af2d1459e8d5b7748763f241a54 (patch) | |
tree | 64300bccb750e59f7c3a05800eafcd5c3b3f89cb /drape/gpu_buffer.cpp | |
parent | aa6703383e8d4c2ff8445e8b3c27728846cdab4b (diff) | |
parent | 086d6f9cf247cea07cff6bc33d5567dc7c64806b (diff) |
Merge pull request #6040 from rokuz/es3-supportbeta-810
Added OpenGL ES3 support
Diffstat (limited to 'drape/gpu_buffer.cpp')
-rw-r--r-- | drape/gpu_buffer.cpp | 81 |
1 files changed, 47 insertions, 34 deletions
diff --git a/drape/gpu_buffer.cpp b/drape/gpu_buffer.cpp index 5d91dc06f2..12afc9109c 100644 --- a/drape/gpu_buffer.cpp +++ b/drape/gpu_buffer.cpp @@ -1,24 +1,23 @@ #include "drape/gpu_buffer.hpp" -#include "drape/glfunctions.hpp" #include "drape/glextensions_list.hpp" +#include "drape/glfunctions.hpp" #include "drape/utils/gpu_mem_tracker.hpp" #include "base/assert.hpp" -#include "std/cstring.hpp" +#include <cstring> //#define CHECK_VBO_BOUNDS namespace dp { - namespace { - bool IsMapBufferSupported() - { - static bool const isSupported = GLExtensionsList::Instance().IsSupported(GLExtensionsList::MapBuffer); - return isSupported; - } +bool IsMapBufferSupported() +{ + static bool const isSupported = + GLExtensionsList::Instance().IsSupported(GLExtensionsList::MapBuffer); + return isSupported; } glConst glTarget(GPUBuffer::Target t) @@ -28,10 +27,12 @@ glConst glTarget(GPUBuffer::Target t) return gl_const::GLElementArrayBuffer; } +} // namespace GPUBuffer::GPUBuffer(Target t, void const * data, uint8_t elementSize, uint32_t capacity) : TBase(elementSize, capacity) , m_t(t) + , m_mappingOffset(0) #ifdef DEBUG , m_isMapped(false) #endif @@ -51,20 +52,22 @@ GPUBuffer::~GPUBuffer() void GPUBuffer::UploadData(void const * data, uint32_t elementCount) { - ASSERT(m_isMapped == false, ()); + ASSERT(!m_isMapped, ()); uint32_t currentSize = GetCurrentSize(); uint8_t elementSize = GetElementSize(); - ASSERT(GetCapacity() >= elementCount + currentSize, ("Not enough memory to upload ", elementCount, " elements")); + ASSERT(GetCapacity() >= elementCount + currentSize, + ("Not enough memory to upload ", elementCount, " elements")); Bind(); #if defined(CHECK_VBO_BOUNDS) int32_t size = GLFunctions::glGetBufferParameter(glTarget(m_t), gl_const::GLBufferSize); ASSERT_EQUAL(GetCapacity() * elementSize, size, ()); - ASSERT_LESS_OR_EQUAL((elementCount + currentSize) * elementSize, size,()); + ASSERT_LESS_OR_EQUAL((elementCount + currentSize) * elementSize, size, ()); #endif - GLFunctions::glBufferSubData(glTarget(m_t), elementCount * elementSize, data, currentSize * elementSize); + GLFunctions::glBufferSubData(glTarget(m_t), elementCount * elementSize, data, + currentSize * elementSize); TBase::UploadData(elementCount); #if defined(TRACK_GPU_MEM) @@ -72,46 +75,55 @@ void GPUBuffer::UploadData(void const * data, uint32_t elementCount) #endif } -void GPUBuffer::Bind() -{ - GLFunctions::glBindBuffer(m_bufferID, glTarget(m_t)); -} - -void * GPUBuffer::Map() +void GPUBuffer::Bind() { GLFunctions::glBindBuffer(m_bufferID, glTarget(m_t)); } +void * GPUBuffer::Map(uint32_t elementOffset, uint32_t elementCount) { #ifdef DEBUG - ASSERT(m_isMapped == false, ()); + ASSERT(!m_isMapped, ()); m_isMapped = true; #endif - if (IsMapBufferSupported()) - return GLFunctions::glMapBuffer(glTarget(m_t)); - - return NULL; + if (GLFunctions::CurrentApiVersion == dp::ApiVersion::OpenGLES2) + { + m_mappingOffset = elementOffset; + return IsMapBufferSupported() ? GLFunctions::glMapBuffer(glTarget(m_t)) : nullptr; + } + else if (GLFunctions::CurrentApiVersion == dp::ApiVersion::OpenGLES3) + { + ASSERT(IsMapBufferSupported(), ()); + m_mappingOffset = 0; + uint32_t const elementSize = GetElementSize(); + uint32_t const byteOffset = elementOffset * elementSize; + uint32_t const byteCount = elementCount * elementSize; + return GLFunctions::glMapBufferRange(glTarget(m_t), byteOffset, byteCount, + gl_const::GLWriteBufferBit); + } + return nullptr; } -void GPUBuffer::UpdateData(void * gpuPtr, void const * data, uint32_t elementOffset, uint32_t elementCount) +void GPUBuffer::UpdateData(void * gpuPtr, void const * data, uint32_t elementOffset, + uint32_t elementCount) { uint32_t const elementSize = GetElementSize(); - uint32_t const byteOffset = elementOffset * elementSize; + uint32_t const byteOffset = (elementOffset + m_mappingOffset) * elementSize; uint32_t const byteCount = elementCount * elementSize; uint32_t const byteCapacity = GetCapacity() * elementSize; - ASSERT(m_isMapped == true, ()); + ASSERT(m_isMapped, ()); #if defined(CHECK_VBO_BOUNDS) int32_t size = GLFunctions::glGetBufferParameter(glTarget(m_t), gl_const::GLBufferSize); ASSERT_EQUAL(size, byteCapacity, ()); - ASSERT_LESS(byteOffset + byteCount, size, ()); + ASSERT_LESS_OR_EQUAL(byteOffset + byteCount, size, ()); #endif if (IsMapBufferSupported()) { - ASSERT(gpuPtr != NULL, ()); + ASSERT(gpuPtr != nullptr, ()); memcpy((uint8_t *)gpuPtr + byteOffset, data, byteCount); } else { - ASSERT(gpuPtr == NULL, ()); + ASSERT(gpuPtr == nullptr, ()); if (byteOffset == 0 && byteCount == byteCapacity) GLFunctions::glBufferData(glTarget(m_t), byteCount, data, gl_const::GLStaticDraw); else @@ -122,9 +134,10 @@ void GPUBuffer::UpdateData(void * gpuPtr, void const * data, uint32_t elementOff void GPUBuffer::Unmap() { #ifdef DEBUG - ASSERT(m_isMapped == true, ()); + ASSERT(m_isMapped, ()); m_isMapped = false; #endif + m_mappingOffset = 0; if (IsMapBufferSupported()) GLFunctions::glUnmapBuffer(glTarget(m_t)); } @@ -133,9 +146,10 @@ void GPUBuffer::Resize(void const * data, uint32_t elementCount) { TBase::Resize(elementCount); Bind(); - GLFunctions::glBufferData(glTarget(m_t), GetCapacity() * GetElementSize(), data, gl_const::GLDynamicDraw); + GLFunctions::glBufferData(glTarget(m_t), GetCapacity() * GetElementSize(), data, + gl_const::GLDynamicDraw); - // if we have set up data already (in glBufferData), we have to call SetDataSize + // If we have set up data already (in glBufferData), we have to call SetDataSize. if (data != nullptr) SetDataSize(elementCount); @@ -147,5 +161,4 @@ void GPUBuffer::Resize(void const * data, uint32_t elementCount) dp::GPUMemTracker::Inst().SetUsed("VBO", m_bufferID, GetCurrentSize() * GetElementSize()); #endif } - -} // namespace dp +} // namespace dp |