diff --git a/qt_tstfrm/tstwidgets.cpp b/qt_tstfrm/tstwidgets.cpp index 761e464190..3c4838e65d 100644 --- a/qt_tstfrm/tstwidgets.cpp +++ b/qt_tstfrm/tstwidgets.cpp @@ -122,7 +122,6 @@ void GLDrawWidget::initializeGL() 0); rmp.m_useSingleThreadedOGL = false; - rmp.m_useVA = !yg::gl::g_isBufferObjectsSupported; rmp.m_rtFormat = yg::Data8Bpp; rmp.m_texFormat = yg::Data8Bpp; diff --git a/yg/blitter.cpp b/yg/blitter.cpp index 0c80428546..abb8b2be8d 100644 --- a/yg/blitter.cpp +++ b/yg/blitter.cpp @@ -4,8 +4,7 @@ #include "framebuffer.hpp" #include "base_texture.hpp" #include "resource_manager.hpp" -#include "vertexbuffer.hpp" -#include "indexbuffer.hpp" +#include "buffer_object.hpp" #include "utils.hpp" #include "storage.hpp" #include "vertex.hpp" diff --git a/yg/blitter.hpp b/yg/blitter.hpp index 2302ef1c7c..3e86fc584c 100644 --- a/yg/blitter.hpp +++ b/yg/blitter.hpp @@ -19,8 +19,6 @@ namespace yg namespace gl { class BaseTexture; - class VertexBuffer; - class IndexBuffer; struct BlitInfo { diff --git a/yg/buffer_object.cpp b/yg/buffer_object.cpp new file mode 100644 index 0000000000..50c60a4645 --- /dev/null +++ b/yg/buffer_object.cpp @@ -0,0 +1,147 @@ +#include "../base/SRC_FIRST.hpp" +#include "../base/logging.hpp" +#include "../base/assert.hpp" +#include "../base/shared_buffer_manager.hpp" + +#include "internal/opengl.hpp" + +#include "buffer_object.hpp" +#include "../std/list.hpp" + +namespace yg +{ + namespace gl + { + BufferObject::BufferObject(unsigned target) + : m_target(target), m_size(0), m_gpuData(0), m_isLocked(false) + { + if (g_isBufferObjectsSupported) + OGLCHECK(glGenBuffersFn(1, &m_id)); + } + + BufferObject::BufferObject(size_t size, unsigned target) + : m_target(target), m_size(0), m_gpuData(0), m_isLocked(false) + { + if (g_isBufferObjectsSupported) + OGLCHECK(glGenBuffersFn(1, &m_id)); + resize(size); + } + + void BufferObject::resize(size_t size) + { + ASSERT(!m_isLocked, ()); + + if (size != m_size) + { + discard(); + + m_size = size; + makeCurrent(); + if (g_isBufferObjectsSupported) + OGLCHECK(glBufferDataFn(m_target, m_size, 0, GL_DYNAMIC_DRAW)); + } + } + + size_t BufferObject::size() const + { + return m_size; + } + + BufferObject::~BufferObject() + { + if (g_isBufferObjectsSupported && (g_hasContext)) + OGLCHECK(glDeleteBuffersFn(1, &m_id)); + } + + bool BufferObject::isLocked() const + { + return m_isLocked; + } + + void * BufferObject::data() + { + ASSERT(m_isLocked, ("BufferObject is not locked")); + return m_gpuData; + } + + void * BufferObject::lock() + { + ASSERT(!m_isLocked, ()); + m_isLocked = true; + + if (g_isMapBufferSupported) + { + makeCurrent(); + /// orphaning the old copy of the buffer data. + /// this provides that the glMapBuffer will not wait. + OGLCHECK(glBufferDataFn(m_target, m_size, 0, GL_DYNAMIC_DRAW)); + m_gpuData = glMapBufferFn(m_target, GL_WRITE_ONLY_MWM); + OGLCHECKAFTER; + return m_gpuData; + } + + if (!m_sharedBuffer) + m_sharedBuffer = SharedBufferManager::instance().reserveSharedBuffer(m_size); + + m_gpuData = &m_sharedBuffer->at(0); + return m_gpuData; + } + + void BufferObject::unlock() + { + ASSERT(m_isLocked, ()); + m_isLocked = false; + + if (g_isBufferObjectsSupported) + { + ASSERT(m_gpuData != 0, ("BufferObject is not locked")); + + makeCurrent(); + + if (g_isMapBufferSupported) + OGLCHECK(glUnmapBufferFn(m_target)); + else + { + OGLCHECK(glBufferSubDataFn(m_target, 0, m_size, m_gpuData)); + SharedBufferManager::instance().freeSharedBuffer(m_size, m_sharedBuffer); + m_sharedBuffer.reset(); + } + + m_gpuData = 0; + } + } + + void BufferObject::discard() + { + if (!g_isBufferObjectsSupported) + { + if (m_sharedBuffer) + { + SharedBufferManager::instance().freeSharedBuffer(m_size, m_sharedBuffer); + m_sharedBuffer.reset(); + m_gpuData = 0; + } + } + } + + void * BufferObject::glPtr() + { + if (!g_isBufferObjectsSupported) + return m_gpuData; + else + return 0; + } + + void BufferObject::makeCurrent() + { + if (!g_isBufferObjectsSupported) + return; + +/*#ifndef OMIM_OS_ANDROID + if (m_id != current()) +#endif*/ + OGLCHECK(glBindBufferFn(m_target, m_id)); + } + + } +} diff --git a/yg/indexbuffer.hpp b/yg/buffer_object.hpp similarity index 76% rename from yg/indexbuffer.hpp rename to yg/buffer_object.hpp index 1121d3f56e..1791758d7f 100644 --- a/yg/indexbuffer.hpp +++ b/yg/buffer_object.hpp @@ -7,22 +7,22 @@ namespace yg { namespace gl { - class IndexBuffer + class BufferObject { private: + unsigned m_target; unsigned int m_id; unsigned int m_size; void * m_gpuData; - bool m_useVA; bool m_isLocked; shared_ptr > m_sharedBuffer; public: - IndexBuffer(bool useVA); - IndexBuffer(size_t size, bool useVA); - ~IndexBuffer(); + BufferObject(unsigned target); + BufferObject(size_t size, unsigned target); + ~BufferObject(); void resize(size_t size); size_t size() const; @@ -36,8 +36,6 @@ namespace yg void * glPtr(); void * data(); bool isLocked() const; - - static int current(); }; } } diff --git a/yg/geometry_batcher.hpp b/yg/geometry_batcher.hpp index f67022649c..cb389e0f75 100644 --- a/yg/geometry_batcher.hpp +++ b/yg/geometry_batcher.hpp @@ -1,8 +1,7 @@ #pragma once #include "vertex.hpp" -#include "vertexbuffer.hpp" -#include "indexbuffer.hpp" +#include "buffer_object.hpp" #include "renderbuffer.hpp" #include "framebuffer.hpp" #include "render_state_updater.hpp" diff --git a/yg/geometry_renderer.cpp b/yg/geometry_renderer.cpp index 3d840d4416..9809b38edd 100644 --- a/yg/geometry_renderer.cpp +++ b/yg/geometry_renderer.cpp @@ -3,8 +3,7 @@ #include "resource_style.hpp" #include "base_texture.hpp" #include "texture.hpp" -#include "vertexbuffer.hpp" -#include "indexbuffer.hpp" +#include "buffer_object.hpp" #include "managed_texture.hpp" #include "display_list.hpp" #include "vertex.hpp" diff --git a/yg/geometry_renderer.hpp b/yg/geometry_renderer.hpp index 788f053e2d..ee48a84f55 100644 --- a/yg/geometry_renderer.hpp +++ b/yg/geometry_renderer.hpp @@ -14,8 +14,6 @@ namespace yg namespace gl { - class VertexBuffer; - class IndexBuffer; class BaseTexture; class DisplayList; diff --git a/yg/indexbuffer.cpp b/yg/indexbuffer.cpp deleted file mode 100644 index fa050f6657..0000000000 --- a/yg/indexbuffer.cpp +++ /dev/null @@ -1,147 +0,0 @@ -#include "../base/SRC_FIRST.hpp" -#include "../base/logging.hpp" -#include "../base/assert.hpp" -#include "../base/shared_buffer_manager.hpp" - -#include "internal/opengl.hpp" - -#include "indexbuffer.hpp" -#include "../std/list.hpp" - -namespace yg -{ - namespace gl - { - list indexBufferStack; - - int IndexBuffer::current() - { - int id; - OGLCHECK(glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &id)); - return id; - } - - IndexBuffer::IndexBuffer(bool useVA) - : m_size(0), m_gpuData(0), m_useVA(useVA), m_isLocked(false) - { - if (!m_useVA) - OGLCHECK(glGenBuffersFn(1, &m_id)); - } - - IndexBuffer::IndexBuffer(size_t size, bool useVA) - : m_size(0), m_gpuData(0), m_useVA(useVA), m_isLocked(false) - { - if (!m_useVA) - OGLCHECK(glGenBuffersFn(1, &m_id)); - resize(size); - } - - void IndexBuffer::resize(size_t size) - { - ASSERT(!m_isLocked, ()); - if (size != m_size) - { - discard(); - m_size = size; - makeCurrent(); - if (!m_useVA) - OGLCHECK(glBufferDataFn(GL_ELEMENT_ARRAY_BUFFER, m_size, 0, GL_DYNAMIC_DRAW)); - } - } - - size_t IndexBuffer::size() const - { - return m_size; - } - - IndexBuffer::~IndexBuffer() - { - if ((!m_useVA) && (g_hasContext)) - OGLCHECK(glDeleteBuffersFn(1, &m_id)); - } - - bool IndexBuffer::isLocked() const - { - return m_isLocked; - } - - void * IndexBuffer::data() - { - ASSERT(m_isLocked, ("IndexBuffer is not locked")); - return m_gpuData; - } - - void * IndexBuffer::lock() - { - ASSERT(!m_isLocked, ()); - m_isLocked = true; - - if (m_useVA) - { - if (!m_sharedBuffer) - m_sharedBuffer = SharedBufferManager::instance().reserveSharedBuffer(m_size); - - m_gpuData = &m_sharedBuffer->at(0); - return m_gpuData; - } - - makeCurrent(); - - /// orphaning the old copy of the buffer data. - /// this provides that the glMapBuffer will not wait. - OGLCHECK(glBufferDataFn(GL_ELEMENT_ARRAY_BUFFER, m_size, 0, GL_DYNAMIC_DRAW)); - - m_gpuData = glMapBufferFn(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY_MWM); - - OGLCHECKAFTER; - return m_gpuData; - } - - void IndexBuffer::unlock() - { - ASSERT(m_isLocked, ()); - m_isLocked = false; - - if (m_useVA) - return; - - ASSERT(m_gpuData != 0, ("IndexBuffer is not locked")); - makeCurrent(); - OGLCHECK(glUnmapBufferFn(GL_ELEMENT_ARRAY_BUFFER)); - m_gpuData = 0; - } - - void IndexBuffer::discard() - { - if (m_useVA) - { - if (m_sharedBuffer) - { - SharedBufferManager::instance().freeSharedBuffer(m_size, m_sharedBuffer); - m_sharedBuffer.reset(); - m_gpuData = 0; - } - } - } - - void IndexBuffer::makeCurrent() - { - if (m_useVA) - return; - -/*#ifndef OMIM_OS_ANDROID - if (m_id != current()) -#endif*/ - OGLCHECK(glBindBufferFn(GL_ELEMENT_ARRAY_BUFFER, m_id)); - } - - void * IndexBuffer::glPtr() - { - if (m_useVA) - return m_gpuData; - else - return 0; - } - } -} - diff --git a/yg/internal/opengl.cpp b/yg/internal/opengl.cpp index 54fd43caa4..8878807bcd 100644 --- a/yg/internal/opengl.cpp +++ b/yg/internal/opengl.cpp @@ -72,6 +72,7 @@ namespace yg void (OPENGL_CALLING_CONVENTION * glDrawElementsFn) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices); bool g_isBufferObjectsSupported = true; + bool g_isMapBufferSupported = true; bool g_isFramebufferSupported = true; bool g_isRenderbufferSupported = true; bool g_isSeparateBlendFuncSupported = false; diff --git a/yg/internal/opengl.hpp b/yg/internal/opengl.hpp index 1c93ab2be9..1108211933 100644 --- a/yg/internal/opengl.hpp +++ b/yg/internal/opengl.hpp @@ -93,8 +93,9 @@ namespace yg /// information about supported extensions - extern bool g_isFramebufferSupported; + extern bool g_isMapBufferSupported; extern bool g_isBufferObjectsSupported; + extern bool g_isFramebufferSupported; extern bool g_isRenderbufferSupported; extern bool g_isSeparateBlendFuncSupported; diff --git a/yg/internal/opengl_es.cpp b/yg/internal/opengl_es.cpp index 6f7311b500..c83ceee677 100644 --- a/yg/internal/opengl_es.cpp +++ b/yg/internal/opengl_es.cpp @@ -63,15 +63,19 @@ namespace yg glOrthoFn = &glOrthof; glDrawElementsFn = &glDrawElements; - g_isBufferObjectsSupported = HasExtension("GL_OES_mapbuffer"); + g_isMapBufferSupported = HasExtension("GL_OES_mapbuffer"); + + glMapBufferFn = &glMapBufferOES; + glUnmapBufferFn = &glUnmapBufferOES; + + /// generally speaking we should check for ARB_vertex_buffer extension + g_isBufferObjectsSupported = g_isMapBufferSupported; glBindBufferFn = &glBindBuffer; glGenBuffersFn = &glGenBuffers; glBufferDataFn = &glBufferData; glBufferSubDataFn = &glBufferSubData; glDeleteBuffersFn = &glDeleteBuffers; - glMapBufferFn = &glMapBufferOES; - glUnmapBufferFn = &glUnmapBufferOES; g_isFramebufferSupported = HasExtension("GL_OES_framebuffer_object"); diff --git a/yg/internal/opengl_ext.cpp b/yg/internal/opengl_ext.cpp index 8432073546..6c02e837ce 100644 --- a/yg/internal/opengl_ext.cpp +++ b/yg/internal/opengl_ext.cpp @@ -60,13 +60,16 @@ namespace yg glDrawElementsFn = &glDrawElements; g_isBufferObjectsSupported = HasExtension("GL_ARB_vertex_buffer_object") - || HasExtension("GLX_ARB_vertex_buffer_object"); + || HasExtension("GLX_ARB_vertex_buffer_object"); glBindBufferFn = &glBindBuffer; glGenBuffersFn = &glGenBuffers; glBufferDataFn = &glBufferData; glBufferSubDataFn = &glBufferSubData; glDeleteBuffersFn = &glDeleteBuffers; + + g_isMapBufferSupported = g_isBufferObjectsSupported; + glMapBufferFn = &glMapBuffer; glUnmapBufferFn = &glUnmapBuffer; diff --git a/yg/internal/opengl_glsl_es2.cpp b/yg/internal/opengl_glsl_es2.cpp index 3c67107fb5..f0d9b91bec 100644 --- a/yg/internal/opengl_glsl_es2.cpp +++ b/yg/internal/opengl_glsl_es2.cpp @@ -51,13 +51,16 @@ namespace yg glOrthoFn = &glsl::glOrtho; glDrawElementsFn = &glsl::glDrawElements; - g_isBufferObjectsSupported = HasExtension("GL_OES_mapbuffer"); + g_isBufferObjectsSupported = true; glBindBufferFn = &glBindBuffer; glGenBuffersFn = &glGenBuffers; glBufferDataFn = &glBufferData; glBufferSubDataFn = &glBufferSubData; glDeleteBuffersFn = &glDeleteBuffers; + + g_isMapBufferSupported = HasExtension("GL_OES_mapbuffer"); + glMapBufferFn = &glMapBufferOES; glUnmapBufferFn = &glUnmapBufferOES; diff --git a/yg/internal/opengl_glsl_ext.cpp b/yg/internal/opengl_glsl_ext.cpp index 6d50e3d5a6..059c67b636 100644 --- a/yg/internal/opengl_glsl_ext.cpp +++ b/yg/internal/opengl_glsl_ext.cpp @@ -45,13 +45,16 @@ namespace yg glOrthoFn = &glsl::glOrtho; glDrawElementsFn = &glsl::glDrawElements; - g_isBufferObjectsSupported = HasExtension("GL_OES_mapbuffer"); + g_isBufferObjectsSupported = true; glBindBufferFn = &glBindBuffer; glGenBuffersFn = &glGenBuffers; glBufferDataFn = &glBufferData; glBufferSubDataFn = &glBufferSubData; glDeleteBuffersFn = &glDeleteBuffers; + + g_isMapBufferSupported = true; + glMapBufferFn = &glMapBuffer; glUnmapBufferFn = &glUnmapBuffer; diff --git a/yg/internal/opengl_win32.cpp b/yg/internal/opengl_win32.cpp index 1b6f82c473..8b41fb566d 100644 --- a/yg/internal/opengl_win32.cpp +++ b/yg/internal/opengl_win32.cpp @@ -61,8 +61,9 @@ namespace yg && glGenBuffersFn && glBufferDataFn && glBufferSubDataFn - && glDeleteBuffersFn - && glMapBufferFn + && glDeleteBuffersFn; + + yg::gl::g_isMapBufferSupported = glMapBufferFn && glUnmapBufferFn; yg::gl::g_isFramebufferSupported = glBindFramebufferFn diff --git a/yg/resource_manager.cpp b/yg/resource_manager.cpp index b8d275ba97..2ec17326fb 100644 --- a/yg/resource_manager.cpp +++ b/yg/resource_manager.cpp @@ -6,8 +6,7 @@ #include "skin_loader.hpp" #include "storage.hpp" #include "texture.hpp" -#include "vertexbuffer.hpp" -#include "indexbuffer.hpp" +#include "buffer_object.hpp" #include "../coding/file_reader.hpp" #include "../coding/parse_xml.hpp" @@ -57,17 +56,16 @@ namespace yg } } - TStorageFactory::TStorageFactory(size_t vbSize, size_t ibSize, bool useVA, bool useSingleThreadedOGL, char const * resName, size_t batchSize) + TStorageFactory::TStorageFactory(size_t vbSize, size_t ibSize, bool useSingleThreadedOGL, char const * resName, size_t batchSize) : BasePoolElemFactory(resName, vbSize + ibSize, batchSize), m_vbSize(vbSize), m_ibSize(ibSize), - m_useVA(useVA), m_useSingleThreadedOGL(useSingleThreadedOGL) {} gl::Storage const TStorageFactory::Create() { - gl::Storage res(m_vbSize, m_ibSize, m_useVA); + gl::Storage res(m_vbSize, m_ibSize); if (m_useSingleThreadedOGL) { @@ -374,7 +372,6 @@ namespace m_texFormat(yg::Data4Bpp), m_texRtFormat(yg::Data4Bpp), m_useSingleThreadedOGL(false), - m_useVA(true), m_videoMemoryLimit(0), m_primaryStoragesParams("primaryStorage"), m_smallStoragesParams("smallStorage"), @@ -407,7 +404,6 @@ namespace { /// general case m_texRtFormat = yg::Data4Bpp; - m_useVA = !yg::gl::g_isBufferObjectsSupported; if (isGPU("Qualcomm", "Adreno", false)) m_texRtFormat = yg::Data8Bpp; @@ -421,10 +417,10 @@ namespace m_texRtFormat = yg::Data8Bpp; } - /// filtering all devices from Vivante Corporation +/* /// filtering all devices from Vivante Corporation /// to use vertex arrays if (isGPU("Vivante Corporation", "", false)) - m_useVA = true; + m_useVA = true;*/ string name; switch (m_texRtFormat) @@ -539,7 +535,7 @@ namespace initTexturePool(p.m_styleCacheTexturesParams, m_styleCacheTextures); initTexturePool(p.m_guiThreadTexturesParams, m_guiThreadTextures); - if (p.m_useVA) + if (!yg::gl::g_isBufferObjectsSupported) LOG(LINFO, ("buffer objects are unsupported. using client vertex array instead.")); } @@ -588,7 +584,7 @@ namespace { if (p.isValid()) { - TStorageFactory storageFactory(p.m_vbSize, p.m_ibSize, m_params.m_useVA, m_params.m_useSingleThreadedOGL, p.m_poolName.c_str(), p.m_allocateOnDemand ? p.m_storagesCount : 0); + TStorageFactory storageFactory(p.m_vbSize, p.m_ibSize, m_params.m_useSingleThreadedOGL, p.m_poolName.c_str(), p.m_allocateOnDemand ? p.m_storagesCount : 0); if (m_params.m_useSingleThreadedOGL) { diff --git a/yg/resource_manager.hpp b/yg/resource_manager.hpp index ab44dff995..73e5230f1b 100644 --- a/yg/resource_manager.hpp +++ b/yg/resource_manager.hpp @@ -44,9 +44,8 @@ namespace yg { size_t m_vbSize; size_t m_ibSize; - bool m_useVA; bool m_useSingleThreadedOGL; - TStorageFactory(size_t vbSize, size_t ibSize, bool useVA, bool useSingleThreadedOGL, char const * resName, size_t batchSize); + TStorageFactory(size_t vbSize, size_t ibSize, bool useSingleThreadedOGL, char const * resName, size_t batchSize); gl::Storage const Create(); void BeforeMerge(gl::Storage const & e); }; @@ -221,7 +220,6 @@ namespace yg DataFormat m_texFormat; DataFormat m_texRtFormat; bool m_useSingleThreadedOGL; - bool m_useVA; size_t m_videoMemoryLimit; diff --git a/yg/skin.hpp b/yg/skin.hpp index f6e82bc0e3..193e28760b 100644 --- a/yg/skin.hpp +++ b/yg/skin.hpp @@ -21,8 +21,6 @@ namespace yg namespace gl { class BaseTexture; - class VertexBuffer; - class IndexBuffer; } class SkinPage; diff --git a/yg/storage.cpp b/yg/storage.cpp index aec4005580..895b83e9ba 100644 --- a/yg/storage.cpp +++ b/yg/storage.cpp @@ -1,7 +1,7 @@ #include "../base/SRC_FIRST.hpp" #include "storage.hpp" -#include "vertexbuffer.hpp" -#include "indexbuffer.hpp" +#include "buffer_object.hpp" +#include "internal/opengl.hpp" namespace yg { @@ -10,9 +10,9 @@ namespace yg Storage::Storage() {} - Storage::Storage(size_t vbSize, size_t ibSize, bool useVA) : - m_vertices(new VertexBuffer(vbSize, useVA)), - m_indices(new IndexBuffer(ibSize, useVA)) + Storage::Storage(size_t vbSize, size_t ibSize) : + m_vertices(new BufferObject(vbSize, GL_ARRAY_BUFFER)), + m_indices(new BufferObject(ibSize, GL_ELEMENT_ARRAY_BUFFER)) {} } } diff --git a/yg/storage.hpp b/yg/storage.hpp index 65723789bc..1403e0af00 100644 --- a/yg/storage.hpp +++ b/yg/storage.hpp @@ -6,17 +6,16 @@ namespace yg { namespace gl { - class VertexBuffer; - class IndexBuffer; + class BufferObject; class Storage { public: - shared_ptr m_vertices; - shared_ptr m_indices; + shared_ptr m_vertices; + shared_ptr m_indices; Storage(); - Storage(size_t vbSize, size_t ibSize, bool useVA); + Storage(size_t vbSize, size_t ibSize); }; } } diff --git a/yg/vertexbuffer.cpp b/yg/vertexbuffer.cpp deleted file mode 100644 index f86465335a..0000000000 --- a/yg/vertexbuffer.cpp +++ /dev/null @@ -1,150 +0,0 @@ -#include "../base/SRC_FIRST.hpp" -#include "../base/logging.hpp" -#include "../base/shared_buffer_manager.hpp" -#include "../base/assert.hpp" - -#include "internal/opengl.hpp" - -#include "vertexbuffer.hpp" -#include "../std/list.hpp" - -namespace yg -{ - namespace gl - { - list vertexBufferStack; - - unsigned VertexBuffer::current() - { - int id; - OGLCHECK(glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &id)); - return id; - } - - VertexBuffer::VertexBuffer(bool useVA) - : m_size(0), m_gpuData(0), m_useVA(useVA), m_isLocked(false) - { - if (!m_useVA) - OGLCHECK(glGenBuffersFn(1, &m_id)); - } - - VertexBuffer::VertexBuffer(size_t size, bool useVA) - : m_size(0), m_gpuData(0), m_useVA(useVA), m_isLocked(false) - { - if (!m_useVA) - OGLCHECK(glGenBuffersFn(1, &m_id)); - resize(size); - } - - void VertexBuffer::resize(size_t size) - { - ASSERT(!m_isLocked, ()); - - if (size != m_size) - { - discard(); - - m_size = size; - makeCurrent(); - if (!m_useVA) - OGLCHECK(glBufferDataFn(GL_ARRAY_BUFFER, m_size, 0, GL_DYNAMIC_DRAW)); - } - } - - size_t VertexBuffer::size() const - { - return m_size; - } - - VertexBuffer::~VertexBuffer() - { - if ((!m_useVA) && (g_hasContext)) - OGLCHECK(glDeleteBuffersFn(1, &m_id)); - } - - void * VertexBuffer::data() - { - ASSERT(m_isLocked, ("IndexBuffer is not locked")); - return m_gpuData; - } - - void * VertexBuffer::lock() - { - ASSERT(!m_isLocked, ()); - m_isLocked = true; - - if (m_useVA) - { - if (!m_sharedBuffer) - m_sharedBuffer = SharedBufferManager::instance().reserveSharedBuffer(m_size); - - m_gpuData = &m_sharedBuffer->at(0); - return m_gpuData; - } - - makeCurrent(); - - /// orphaning the old copy of the buffer data. - /// this provides that the glMapBuffer will not wait. - OGLCHECK(glBufferDataFn(GL_ARRAY_BUFFER, m_size, 0, GL_DYNAMIC_DRAW)); - - m_gpuData = glMapBufferFn(GL_ARRAY_BUFFER, GL_WRITE_ONLY_MWM); - - OGLCHECKAFTER; - return m_gpuData; - } - - void VertexBuffer::unlock() - { - ASSERT(m_isLocked, ()); - m_isLocked = false; - - if (m_useVA) - return; - - ASSERT(m_gpuData != 0, ("VertexBuffer is not locked")); - makeCurrent(); - - OGLCHECK(glUnmapBufferFn(GL_ARRAY_BUFFER)); - - m_gpuData = 0; - } - - void VertexBuffer::discard() - { - if (m_useVA) - { - if (m_sharedBuffer) - { - SharedBufferManager::instance().freeSharedBuffer(m_size, m_sharedBuffer); - m_sharedBuffer.reset(); - m_gpuData = 0; - } - } - } - - void * VertexBuffer::glPtr() - { - if (m_useVA) - return m_gpuData; - return 0; - } - - bool VertexBuffer::isLocked() const - { - return m_isLocked; - } - - void VertexBuffer::makeCurrent() - { - if (m_useVA) - return; - -/*#ifndef OMIM_OS_ANDROID - if (m_id != current()) -#endif*/ - OGLCHECK(glBindBufferFn(GL_ARRAY_BUFFER, m_id)); - } - - } -} diff --git a/yg/vertexbuffer.hpp b/yg/vertexbuffer.hpp deleted file mode 100644 index ec62fea777..0000000000 --- a/yg/vertexbuffer.hpp +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -#include "../std/vector.hpp" -#include "../std/shared_ptr.hpp" - -namespace yg -{ - namespace gl - { - class VertexBuffer - { - private: - - unsigned int m_id; - unsigned int m_size; - void * m_gpuData; - - shared_ptr > m_sharedBuffer; - - /// using VA instead of buffer objects on some old GPU's - bool m_useVA; - bool m_isLocked; - - public: - - VertexBuffer(bool useVA); - VertexBuffer(size_t size, bool useVA); - ~VertexBuffer(); - - void resize(size_t size); - size_t size() const; - - void makeCurrent(); - void * lock(); - void unlock(); - void discard(); - void * glPtr(); - void * data(); - bool isLocked() const; - - static unsigned current(); - }; - } -} diff --git a/yg/yg.pro b/yg/yg.pro index 631eb31780..ccb3a909b8 100644 --- a/yg/yg.pro +++ b/yg/yg.pro @@ -22,8 +22,7 @@ SOURCES += \ color.cpp \ skin_loader.cpp \ framebuffer.cpp \ - vertexbuffer.cpp \ - indexbuffer.cpp \ + buffer_object.cpp \ utils.cpp \ renderbuffer.cpp \ base_texture.cpp \ @@ -76,8 +75,7 @@ HEADERS += \ resource_style.hpp \ color.hpp \ framebuffer.hpp \ - vertexbuffer.hpp \ - indexbuffer.hpp \ + buffer_object.hpp \ utils.hpp \ renderbuffer.hpp \ base_texture.hpp \