diff options
Diffstat (limited to 'src/mbgl/geometry')
-rw-r--r-- | src/mbgl/geometry/buffer.hpp | 31 | ||||
-rw-r--r-- | src/mbgl/geometry/circle_buffer.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/geometry/collision_box_buffer.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/geometry/debug_font_buffer.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/geometry/fill_buffer.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/geometry/glyph_atlas.cpp | 21 | ||||
-rw-r--r-- | src/mbgl/geometry/glyph_atlas.hpp | 9 | ||||
-rw-r--r-- | src/mbgl/geometry/icon_buffer.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/geometry/line_atlas.cpp | 29 | ||||
-rw-r--r-- | src/mbgl/geometry/line_atlas.hpp | 14 | ||||
-rw-r--r-- | src/mbgl/geometry/line_buffer.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/geometry/static_vertex_buffer.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/geometry/text_buffer.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/geometry/vao.cpp | 52 | ||||
-rw-r--r-- | src/mbgl/geometry/vao.hpp | 28 |
15 files changed, 76 insertions, 124 deletions
diff --git a/src/mbgl/geometry/buffer.hpp b/src/mbgl/geometry/buffer.hpp index c7278a1036..143597ed0a 100644 --- a/src/mbgl/geometry/buffer.hpp +++ b/src/mbgl/geometry/buffer.hpp @@ -1,12 +1,13 @@ #ifndef MBGL_GEOMETRY_BUFFER #define MBGL_GEOMETRY_BUFFER -#include <mbgl/platform/gl.hpp> +#include <mbgl/gl/gl.hpp> +#include <mbgl/gl/gl_object_store.hpp> #include <mbgl/platform/log.hpp> -#include <mbgl/util/gl_object_store.hpp> #include <mbgl/util/noncopyable.hpp> #include <mbgl/util/thread_context.hpp> +#include <memory> #include <cstdlib> #include <cassert> #include <stdexcept> @@ -23,10 +24,6 @@ class Buffer : private util::noncopyable { public: ~Buffer() { cleanup(); - if (buffer != 0) { - util::ThreadContext::getGLObjectStore()->abandonBuffer(buffer); - buffer = 0; - } } // Returns the number of elements in this buffer. This is not the number of @@ -40,12 +37,12 @@ public: } // Transfers this buffer to the GPU and binds the buffer to the GL context. - void bind() { + void bind(gl::GLObjectStore& glObjectStore) { if (buffer) { - MBGL_CHECK_ERROR(glBindBuffer(bufferType, buffer)); + MBGL_CHECK_ERROR(glBindBuffer(bufferType, getID())); } else { - MBGL_CHECK_ERROR(glGenBuffers(1, &buffer)); - MBGL_CHECK_ERROR(glBindBuffer(bufferType, buffer)); + buffer.create(glObjectStore); + MBGL_CHECK_ERROR(glBindBuffer(bufferType, getID())); if (array == nullptr) { Log::Debug(Event::OpenGL, "Buffer doesn't contain elements"); pos = 0; @@ -64,21 +61,21 @@ public: } } - inline GLuint getID() const { - return buffer; + GLuint getID() const { + return buffer.getID(); } // Uploads the buffer to the GPU to be available when we need it. - inline void upload() { + inline void upload(gl::GLObjectStore& glObjectStore) { if (!buffer) { - bind(); + bind(glObjectStore); } } protected: // increase the buffer size by at least /required/ bytes. inline void *addElement() { - if (buffer != 0) { + if (buffer) { throw std::runtime_error("Can't add elements after buffer was bound to GPU"); } if (length < pos + itemSize) { @@ -118,8 +115,8 @@ private: // Number of bytes that are valid in this buffer. size_t length = 0; - // GL buffer ID - GLuint buffer = 0; + // GL buffer object handle. + gl::BufferHolder buffer; }; } // namespace mbgl diff --git a/src/mbgl/geometry/circle_buffer.cpp b/src/mbgl/geometry/circle_buffer.cpp index f4b0cddec3..74ccfa8267 100644 --- a/src/mbgl/geometry/circle_buffer.cpp +++ b/src/mbgl/geometry/circle_buffer.cpp @@ -1,6 +1,6 @@ #include <mbgl/geometry/circle_buffer.hpp> -#include <mbgl/platform/gl.hpp> +#include <mbgl/gl/gl.hpp> #include <climits> diff --git a/src/mbgl/geometry/collision_box_buffer.cpp b/src/mbgl/geometry/collision_box_buffer.cpp index f4f8075e10..a47267d566 100644 --- a/src/mbgl/geometry/collision_box_buffer.cpp +++ b/src/mbgl/geometry/collision_box_buffer.cpp @@ -1,5 +1,5 @@ #include <mbgl/geometry/collision_box_buffer.hpp> -#include <mbgl/platform/gl.hpp> +#include <mbgl/gl/gl.hpp> #include <mbgl/util/math.hpp> #include <cmath> diff --git a/src/mbgl/geometry/debug_font_buffer.cpp b/src/mbgl/geometry/debug_font_buffer.cpp index e4af707660..5df67accd6 100644 --- a/src/mbgl/geometry/debug_font_buffer.cpp +++ b/src/mbgl/geometry/debug_font_buffer.cpp @@ -1,7 +1,7 @@ #include <mbgl/geometry/debug_font_buffer.hpp> #include <mbgl/geometry/debug_font_data.hpp> -#include <mbgl/platform/gl.hpp> +#include <mbgl/gl/gl.hpp> #include <cmath> #include <cstring> diff --git a/src/mbgl/geometry/fill_buffer.cpp b/src/mbgl/geometry/fill_buffer.cpp index 3392699431..ee70dfc53b 100644 --- a/src/mbgl/geometry/fill_buffer.cpp +++ b/src/mbgl/geometry/fill_buffer.cpp @@ -1,6 +1,6 @@ #include <mbgl/geometry/fill_buffer.hpp> -#include <mbgl/platform/gl.hpp> +#include <mbgl/gl/gl.hpp> #include <climits> diff --git a/src/mbgl/geometry/glyph_atlas.cpp b/src/mbgl/geometry/glyph_atlas.cpp index b90444e582..24c1b8c8db 100644 --- a/src/mbgl/geometry/glyph_atlas.cpp +++ b/src/mbgl/geometry/glyph_atlas.cpp @@ -2,10 +2,10 @@ #include <mbgl/text/font_stack.hpp> -#include <mbgl/platform/gl.hpp> +#include <mbgl/gl/gl.hpp> +#include <mbgl/gl/gl_object_store.hpp> #include <mbgl/platform/log.hpp> #include <mbgl/platform/platform.hpp> -#include <mbgl/util/gl_object_store.hpp> #include <mbgl/util/thread_context.hpp> #include <cassert> @@ -24,11 +24,6 @@ GlyphAtlas::GlyphAtlas(uint16_t width_, uint16_t height_) GlyphAtlas::~GlyphAtlas() { assert(util::ThreadContext::currentlyOn(util::ThreadType::Map)); - - if (texture) { - mbgl::util::ThreadContext::getGLObjectStore()->abandonTexture(texture); - texture = 0; - } } void GlyphAtlas::addGlyphs(uintptr_t tileUID, @@ -151,10 +146,10 @@ void GlyphAtlas::removeGlyphs(uintptr_t tileUID) { } } -void GlyphAtlas::upload() { +void GlyphAtlas::upload(gl::GLObjectStore& glObjectStore) { if (dirty) { const bool first = !texture; - bind(); + bind(glObjectStore); std::lock_guard<std::mutex> lock(mtx); @@ -192,10 +187,10 @@ void GlyphAtlas::upload() { } } -void GlyphAtlas::bind() { +void GlyphAtlas::bind(gl::GLObjectStore& glObjectStore) { if (!texture) { - MBGL_CHECK_ERROR(glGenTextures(1, &texture)); - MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, texture)); + texture.create(glObjectStore); + MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, texture.getID())); #ifndef GL_ES_VERSION_2_0 MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0)); #endif @@ -204,6 +199,6 @@ void GlyphAtlas::bind() { MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); } else { - MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, texture)); + MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, texture.getID())); } }; diff --git a/src/mbgl/geometry/glyph_atlas.hpp b/src/mbgl/geometry/glyph_atlas.hpp index 5b4ae1fc6b..2758ac7cee 100644 --- a/src/mbgl/geometry/glyph_atlas.hpp +++ b/src/mbgl/geometry/glyph_atlas.hpp @@ -4,7 +4,8 @@ #include <mbgl/geometry/binpack.hpp> #include <mbgl/text/glyph_store.hpp> #include <mbgl/util/noncopyable.hpp> -#include <mbgl/platform/gl.hpp> +#include <mbgl/gl/gl.hpp> +#include <mbgl/gl/gl_object_store.hpp> #include <string> #include <set> @@ -27,11 +28,11 @@ public: void removeGlyphs(uintptr_t tileUID); // Binds the atlas texture to the GPU, and uploads data if it is out of date. - void bind(); + void bind(gl::GLObjectStore&); // Uploads the texture to the GPU to be available when we need it. This is a lazy operation; // the texture is only bound when the data is out of date (=dirty). - void upload(); + void upload(gl::GLObjectStore&); const GLsizei width; const GLsizei height; @@ -53,7 +54,7 @@ private: std::map<std::string, std::map<uint32_t, GlyphValue>> index; const std::unique_ptr<uint8_t[]> data; std::atomic<bool> dirty; - GLuint texture = 0; + gl::TextureHolder texture; }; } // namespace mbgl diff --git a/src/mbgl/geometry/icon_buffer.cpp b/src/mbgl/geometry/icon_buffer.cpp index 4e6a1c52e7..101132ddbc 100644 --- a/src/mbgl/geometry/icon_buffer.cpp +++ b/src/mbgl/geometry/icon_buffer.cpp @@ -1,5 +1,5 @@ #include <mbgl/geometry/icon_buffer.hpp> -#include <mbgl/platform/gl.hpp> +#include <mbgl/gl/gl.hpp> #include <mbgl/util/math.hpp> #include <cmath> diff --git a/src/mbgl/geometry/line_atlas.cpp b/src/mbgl/geometry/line_atlas.cpp index bbda2dce6f..9b133319dc 100644 --- a/src/mbgl/geometry/line_atlas.cpp +++ b/src/mbgl/geometry/line_atlas.cpp @@ -1,8 +1,8 @@ #include <mbgl/geometry/line_atlas.hpp> -#include <mbgl/platform/gl.hpp> +#include <mbgl/gl/gl.hpp> +#include <mbgl/gl/gl_object_store.hpp> #include <mbgl/platform/log.hpp> #include <mbgl/platform/platform.hpp> -#include <mbgl/util/gl_object_store.hpp> #include <mbgl/util/thread_context.hpp> #include <boost/functional/hash.hpp> @@ -21,14 +21,9 @@ LineAtlas::LineAtlas(GLsizei w, GLsizei h) LineAtlas::~LineAtlas() { assert(util::ThreadContext::currentlyOn(util::ThreadType::Map)); - - if (texture) { - mbgl::util::ThreadContext::getGLObjectStore()->abandonTexture(texture); - texture = 0; - } } -LinePatternPos LineAtlas::getDashPosition(const std::vector<float> &dasharray, bool round) { +LinePatternPos LineAtlas::getDashPosition(const std::vector<float> &dasharray, bool round, gl::GLObjectStore& glObjectStore) { assert(util::ThreadContext::currentlyOn(util::ThreadType::Map)); size_t key = round ? std::numeric_limits<size_t>::min() : std::numeric_limits<size_t>::max(); @@ -39,7 +34,7 @@ LinePatternPos LineAtlas::getDashPosition(const std::vector<float> &dasharray, b // Note: We're not handling hash collisions here. const auto it = positions.find(key); if (it == positions.end()) { - auto inserted = positions.emplace(key, addDash(dasharray, round)); + auto inserted = positions.emplace(key, addDash(dasharray, round, glObjectStore)); assert(inserted.second); return inserted.first->second; } else { @@ -47,7 +42,7 @@ LinePatternPos LineAtlas::getDashPosition(const std::vector<float> &dasharray, b } } -LinePatternPos LineAtlas::addDash(const std::vector<float> &dasharray, bool round) { +LinePatternPos LineAtlas::addDash(const std::vector<float> &dasharray, bool round, gl::GLObjectStore& glObjectStore) { int n = round ? 7 : 0; int dashheight = 2 * n + 1; @@ -125,31 +120,31 @@ LinePatternPos LineAtlas::addDash(const std::vector<float> &dasharray, bool roun nextRow += dashheight; dirty = true; - bind(); + bind(glObjectStore); return position; }; -void LineAtlas::upload() { +void LineAtlas::upload(gl::GLObjectStore& glObjectStore) { if (dirty) { - bind(); + bind(glObjectStore); } } -void LineAtlas::bind() { +void LineAtlas::bind(gl::GLObjectStore& glObjectStore) { assert(util::ThreadContext::currentlyOn(util::ThreadType::Map)); bool first = false; if (!texture) { - MBGL_CHECK_ERROR(glGenTextures(1, &texture)); - MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, texture)); + texture.create(glObjectStore); + MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, texture.getID())); MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)); MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); first = true; } else { - MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, texture)); + MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, texture.getID())); } if (dirty) { diff --git a/src/mbgl/geometry/line_atlas.hpp b/src/mbgl/geometry/line_atlas.hpp index e76a91b61d..e94b399457 100644 --- a/src/mbgl/geometry/line_atlas.hpp +++ b/src/mbgl/geometry/line_atlas.hpp @@ -1,11 +1,11 @@ #ifndef MBGL_GEOMETRY_LINE_ATLAS #define MBGL_GEOMETRY_LINE_ATLAS -#include <mbgl/platform/gl.hpp> +#include <mbgl/gl/gl.hpp> +#include <mbgl/gl/gl_object_store.hpp> #include <vector> #include <map> -#include <memory> namespace mbgl { @@ -21,14 +21,14 @@ public: ~LineAtlas(); // Binds the atlas texture to the GPU, and uploads data if it is out of date. - void bind(); + void bind(gl::GLObjectStore&); // Uploads the texture to the GPU to be available when we need it. This is a lazy operation; // the texture is only bound when the data is out of date (=dirty). - void upload(); + void upload(gl::GLObjectStore&); - LinePatternPos getDashPosition(const std::vector<float>&, bool); - LinePatternPos addDash(const std::vector<float> &dasharray, bool round); + LinePatternPos getDashPosition(const std::vector<float>&, bool, gl::GLObjectStore&); + LinePatternPos addDash(const std::vector<float> &dasharray, bool round, gl::GLObjectStore&); const GLsizei width; const GLsizei height; @@ -36,7 +36,7 @@ public: private: const std::unique_ptr<GLbyte[]> data; bool dirty; - GLuint texture = 0; + gl::TextureHolder texture; int nextRow = 0; std::map<size_t, LinePatternPos> positions; }; diff --git a/src/mbgl/geometry/line_buffer.cpp b/src/mbgl/geometry/line_buffer.cpp index f775a4589f..b35d3e8f47 100644 --- a/src/mbgl/geometry/line_buffer.cpp +++ b/src/mbgl/geometry/line_buffer.cpp @@ -1,5 +1,5 @@ #include <mbgl/geometry/line_buffer.hpp> -#include <mbgl/platform/gl.hpp> +#include <mbgl/gl/gl.hpp> #include <cmath> diff --git a/src/mbgl/geometry/static_vertex_buffer.cpp b/src/mbgl/geometry/static_vertex_buffer.cpp index e8dad0ba9b..254b01b6b6 100644 --- a/src/mbgl/geometry/static_vertex_buffer.cpp +++ b/src/mbgl/geometry/static_vertex_buffer.cpp @@ -1,5 +1,5 @@ #include <mbgl/geometry/static_vertex_buffer.hpp> -#include <mbgl/platform/gl.hpp> +#include <mbgl/gl/gl.hpp> namespace mbgl { diff --git a/src/mbgl/geometry/text_buffer.cpp b/src/mbgl/geometry/text_buffer.cpp index 530048a6dd..1aa65146a4 100644 --- a/src/mbgl/geometry/text_buffer.cpp +++ b/src/mbgl/geometry/text_buffer.cpp @@ -1,5 +1,5 @@ #include <mbgl/geometry/text_buffer.hpp> -#include <mbgl/platform/gl.hpp> +#include <mbgl/gl/gl.hpp> #include <mbgl/util/math.hpp> #include <cmath> diff --git a/src/mbgl/geometry/vao.cpp b/src/mbgl/geometry/vao.cpp index d3ad16e64f..8239604264 100644 --- a/src/mbgl/geometry/vao.cpp +++ b/src/mbgl/geometry/vao.cpp @@ -1,59 +1,23 @@ #include <mbgl/geometry/vao.hpp> #include <mbgl/platform/log.hpp> -#include <mbgl/util/gl_object_store.hpp> +#include <mbgl/gl/gl_object_store.hpp> #include <mbgl/util/string.hpp> -#include <mbgl/util/thread_context.hpp> namespace mbgl { -static gl::ExtensionFunction< - void (GLuint array)> - BindVertexArray({ - {"GL_ARB_vertex_array_object", "glBindVertexArray"}, - {"GL_OES_vertex_array_object", "glBindVertexArrayOES"}, - {"GL_APPLE_vertex_array_object", "glBindVertexArrayAPPLE"} - }); - -static gl::ExtensionFunction< - void (GLsizei n, - const GLuint* arrays)> - DeleteVertexArrays({ - {"GL_ARB_vertex_array_object", "glDeleteVertexArrays"}, - {"GL_OES_vertex_array_object", "glDeleteVertexArraysOES"}, - {"GL_APPLE_vertex_array_object", "glDeleteVertexArraysAPPLE"} - }); - -static gl::ExtensionFunction< - void (GLsizei n, - GLuint* arrays)> - GenVertexArrays({ - {"GL_ARB_vertex_array_object", "glGenVertexArrays"}, - {"GL_OES_vertex_array_object", "glGenVertexArraysOES"}, - {"GL_APPLE_vertex_array_object", "glGenVertexArraysAPPLE"} - }); - void VertexArrayObject::Unbind() { - if (!BindVertexArray) return; - MBGL_CHECK_ERROR(BindVertexArray(0)); -} - -void VertexArrayObject::Delete(GLsizei n, const GLuint* arrays) { - MBGL_CHECK_ERROR(DeleteVertexArrays(n, arrays)); + if (!gl::BindVertexArray) return; + MBGL_CHECK_ERROR(gl::BindVertexArray(0)); } VertexArrayObject::VertexArrayObject() { } VertexArrayObject::~VertexArrayObject() { - if (!DeleteVertexArrays) return; - - if (vao) { - util::ThreadContext::getGLObjectStore()->abandonVAO(vao); - } } -void VertexArrayObject::bindVertexArrayObject() { - if (!GenVertexArrays || !BindVertexArray) { +void VertexArrayObject::bindVertexArrayObject(gl::GLObjectStore& glObjectStore) { + if (!gl::GenVertexArrays || !gl::BindVertexArray) { static bool reported = false; if (!reported) { Log::Warning(Event::OpenGL, "Not using Vertex Array Objects"); @@ -62,10 +26,8 @@ void VertexArrayObject::bindVertexArrayObject() { return; } - if (!vao) { - MBGL_CHECK_ERROR(GenVertexArrays(1, &vao)); - } - MBGL_CHECK_ERROR(BindVertexArray(vao)); + if (!vao) vao.create(glObjectStore); + MBGL_CHECK_ERROR(gl::BindVertexArray(vao.getID())); } void VertexArrayObject::verifyBinding(Shader &shader, GLuint vertexBuffer, GLuint elementsBuffer, diff --git a/src/mbgl/geometry/vao.hpp b/src/mbgl/geometry/vao.hpp index 2dcc02c76b..dcb66dd41d 100644 --- a/src/mbgl/geometry/vao.hpp +++ b/src/mbgl/geometry/vao.hpp @@ -2,26 +2,28 @@ #define MBGL_GEOMETRY_VAO #include <mbgl/shader/shader.hpp> -#include <mbgl/platform/gl.hpp> +#include <mbgl/gl/gl.hpp> +#include <mbgl/gl/gl_object_store.hpp> #include <mbgl/util/noncopyable.hpp> #include <stdexcept> namespace mbgl { +class Shader; + class VertexArrayObject : public util::noncopyable { public: static void Unbind(); - static void Delete(GLsizei n, const GLuint* arrays); VertexArrayObject(); ~VertexArrayObject(); template <typename Shader, typename VertexBuffer> - inline void bind(Shader& shader, VertexBuffer &vertexBuffer, GLbyte *offset) { - bindVertexArrayObject(); + inline void bind(Shader& shader, VertexBuffer &vertexBuffer, GLbyte *offset, gl::GLObjectStore& glObjectStore) { + bindVertexArrayObject(glObjectStore); if (bound_shader == 0) { - vertexBuffer.bind(); + vertexBuffer.bind(glObjectStore); shader.bind(offset); if (vao) { storeBinding(shader, vertexBuffer.getID(), 0, offset); @@ -32,11 +34,11 @@ public: } template <typename Shader, typename VertexBuffer, typename ElementsBuffer> - inline void bind(Shader& shader, VertexBuffer &vertexBuffer, ElementsBuffer &elementsBuffer, GLbyte *offset) { - bindVertexArrayObject(); + inline void bind(Shader& shader, VertexBuffer &vertexBuffer, ElementsBuffer &elementsBuffer, GLbyte *offset, gl::GLObjectStore& glObjectStore) { + bindVertexArrayObject(glObjectStore); if (bound_shader == 0) { - vertexBuffer.bind(); - elementsBuffer.bind(); + vertexBuffer.bind(glObjectStore); + elementsBuffer.bind(glObjectStore); shader.bind(offset); if (vao) { storeBinding(shader, vertexBuffer.getID(), elementsBuffer.getID(), offset); @@ -46,16 +48,16 @@ public: } } - inline GLuint getID() const { - return vao; + GLuint getID() const { + return vao.getID(); } private: - void bindVertexArrayObject(); + void bindVertexArrayObject(gl::GLObjectStore&); void storeBinding(Shader &shader, GLuint vertexBuffer, GLuint elementsBuffer, GLbyte *offset); void verifyBinding(Shader &shader, GLuint vertexBuffer, GLuint elementsBuffer, GLbyte *offset); - GLuint vao = 0; + gl::VAOHolder vao; // For debug reasons, we're storing the bind information so that we can // detect errors and report |