From 44c7e9d05edbe6fee9e8f98b91380b6c07e57ac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Tue, 27 Sep 2016 17:52:14 +0200 Subject: [core] merge gl::ObjectStore into gl::Context --- cmake/core-files.cmake | 5 +- src/mbgl/geometry/buffer.hpp | 9 +- src/mbgl/geometry/line_atlas.cpp | 9 +- src/mbgl/geometry/line_atlas.hpp | 7 +- src/mbgl/geometry/vao.cpp | 5 +- src/mbgl/geometry/vao.hpp | 15 ++-- src/mbgl/gl/context.cpp | 95 ++++++++++++++++++++ src/mbgl/gl/context.hpp | 143 +++++++++++++++++------------- src/mbgl/gl/object.cpp | 46 ++++++++++ src/mbgl/gl/object.hpp | 54 +++++++++++ src/mbgl/gl/object_store.cpp | 91 ------------------- src/mbgl/gl/object_store.hpp | 134 ---------------------------- src/mbgl/gl/state.hpp | 3 + src/mbgl/map/map.cpp | 22 ++--- src/mbgl/renderer/bucket.hpp | 3 +- src/mbgl/renderer/circle_bucket.cpp | 10 +-- src/mbgl/renderer/circle_bucket.hpp | 4 +- src/mbgl/renderer/debug_bucket.cpp | 8 +- src/mbgl/renderer/debug_bucket.hpp | 5 +- src/mbgl/renderer/fill_bucket.cpp | 20 ++--- src/mbgl/renderer/fill_bucket.hpp | 10 +-- src/mbgl/renderer/frame_history.cpp | 8 +- src/mbgl/renderer/frame_history.hpp | 6 +- src/mbgl/renderer/line_bucket.cpp | 15 ++-- src/mbgl/renderer/line_bucket.hpp | 8 +- src/mbgl/renderer/painter.cpp | 32 +++---- src/mbgl/renderer/painter.hpp | 11 +-- src/mbgl/renderer/painter_background.cpp | 6 +- src/mbgl/renderer/painter_circle.cpp | 2 +- src/mbgl/renderer/painter_clipping.cpp | 2 +- src/mbgl/renderer/painter_debug.cpp | 8 +- src/mbgl/renderer/painter_fill.cpp | 14 +-- src/mbgl/renderer/painter_line.cpp | 10 +-- src/mbgl/renderer/painter_raster.cpp | 2 +- src/mbgl/renderer/painter_symbol.cpp | 18 ++-- src/mbgl/renderer/raster_bucket.cpp | 13 ++- src/mbgl/renderer/raster_bucket.hpp | 4 +- src/mbgl/renderer/symbol_bucket.cpp | 22 ++--- src/mbgl/renderer/symbol_bucket.hpp | 10 +-- src/mbgl/shader/circle_shader.cpp | 4 +- src/mbgl/shader/circle_shader.hpp | 2 +- src/mbgl/shader/collision_box_shader.cpp | 4 +- src/mbgl/shader/collision_box_shader.hpp | 2 +- src/mbgl/shader/icon_shader.cpp | 4 +- src/mbgl/shader/icon_shader.hpp | 2 +- src/mbgl/shader/line_shader.cpp | 4 +- src/mbgl/shader/line_shader.hpp | 2 +- src/mbgl/shader/linepattern_shader.cpp | 4 +- src/mbgl/shader/linepattern_shader.hpp | 2 +- src/mbgl/shader/linesdf_shader.cpp | 4 +- src/mbgl/shader/linesdf_shader.hpp | 2 +- src/mbgl/shader/outline_shader.cpp | 4 +- src/mbgl/shader/outline_shader.hpp | 2 +- src/mbgl/shader/outlinepattern_shader.cpp | 4 +- src/mbgl/shader/outlinepattern_shader.hpp | 2 +- src/mbgl/shader/pattern_shader.cpp | 4 +- src/mbgl/shader/pattern_shader.hpp | 2 +- src/mbgl/shader/plain_shader.cpp | 4 +- src/mbgl/shader/plain_shader.hpp | 2 +- src/mbgl/shader/raster_shader.cpp | 4 +- src/mbgl/shader/raster_shader.hpp | 2 +- src/mbgl/shader/sdf_shader.cpp | 4 +- src/mbgl/shader/sdf_shader.hpp | 2 +- src/mbgl/shader/shader.cpp | 16 ++-- src/mbgl/shader/shader.hpp | 8 +- src/mbgl/shader/shaders.hpp | 31 ++++--- src/mbgl/sprite/sprite_atlas.cpp | 8 +- src/mbgl/sprite/sprite_atlas.hpp | 6 +- src/mbgl/text/glyph_atlas.cpp | 9 +- src/mbgl/text/glyph_atlas.hpp | 6 +- src/mbgl/util/offscreen_texture.cpp | 7 +- src/mbgl/util/offscreen_texture.hpp | 2 +- src/mbgl/util/raster.cpp | 9 +- src/mbgl/util/raster.hpp | 7 +- test/gl/object.cpp | 53 ++++++----- test/util/offscreen_texture.cpp | 12 +-- 76 files changed, 555 insertions(+), 580 deletions(-) create mode 100644 src/mbgl/gl/context.cpp create mode 100644 src/mbgl/gl/object.cpp create mode 100644 src/mbgl/gl/object.hpp delete mode 100644 src/mbgl/gl/object_store.cpp delete mode 100644 src/mbgl/gl/object_store.hpp diff --git a/cmake/core-files.cmake b/cmake/core-files.cmake index 91252c7acd..b7ee4ee313 100644 --- a/cmake/core-files.cmake +++ b/cmake/core-files.cmake @@ -77,12 +77,13 @@ set(MBGL_CORE_FILES # gl include/mbgl/gl/gl.hpp + src/mbgl/gl/context.cpp src/mbgl/gl/context.hpp src/mbgl/gl/debugging.cpp src/mbgl/gl/debugging.hpp src/mbgl/gl/gl.cpp - src/mbgl/gl/object_store.cpp - src/mbgl/gl/object_store.hpp + src/mbgl/gl/object.cpp + src/mbgl/gl/object.hpp src/mbgl/gl/state.hpp src/mbgl/gl/value.cpp src/mbgl/gl/value.hpp diff --git a/src/mbgl/geometry/buffer.hpp b/src/mbgl/geometry/buffer.hpp index cfa96b8fed..8e58af8927 100644 --- a/src/mbgl/geometry/buffer.hpp +++ b/src/mbgl/geometry/buffer.hpp @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include #include @@ -40,10 +39,10 @@ public: } // Transfers this buffer to the GPU and binds the buffer to the GL context. - void bind(gl::ObjectStore& store, gl::Context& context) { + void bind(gl::Context& context) { const bool initialized { buffer }; if (!initialized) { - buffer = store.createBuffer(); + buffer = context.createBuffer(); } if (target == GL_ARRAY_BUFFER) { @@ -76,9 +75,9 @@ public: } // Uploads the buffer to the GPU to be available when we need it. - void upload(gl::ObjectStore& store, gl::Context& context) { + void upload(gl::Context& context) { if (!buffer) { - bind(store, context); + bind(context); } } diff --git a/src/mbgl/geometry/line_atlas.cpp b/src/mbgl/geometry/line_atlas.cpp index 2f4616f6e6..2131c43966 100644 --- a/src/mbgl/geometry/line_atlas.cpp +++ b/src/mbgl/geometry/line_atlas.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include #include @@ -121,16 +120,16 @@ LinePatternPos LineAtlas::addDash(const std::vector& dasharray, LinePatte return position; } -void LineAtlas::upload(gl::ObjectStore& store, gl::Context& context, uint32_t unit) { +void LineAtlas::upload(gl::Context& context, uint32_t unit) { if (dirty) { - bind(store, context, unit); + bind(context, unit); } } -void LineAtlas::bind(gl::ObjectStore& store, gl::Context& context, uint32_t unit) { +void LineAtlas::bind(gl::Context& context, uint32_t unit) { bool first = false; if (!texture) { - texture = store.createTexture(); + texture = context.createTexture(); context.activeTexture = unit; context.texture[unit] = *texture; MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); diff --git a/src/mbgl/geometry/line_atlas.hpp b/src/mbgl/geometry/line_atlas.hpp index 701c12c1ce..cb957901f3 100644 --- a/src/mbgl/geometry/line_atlas.hpp +++ b/src/mbgl/geometry/line_atlas.hpp @@ -1,11 +1,12 @@ #pragma once #include -#include +#include #include #include #include +#include namespace mbgl { @@ -30,11 +31,11 @@ public: ~LineAtlas(); // Binds the atlas texture to the GPU, and uploads data if it is out of date. - void bind(gl::ObjectStore&, gl::Context&, uint32_t unit); + void bind(gl::Context&, uint32_t unit); // 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(gl::ObjectStore&, gl::Context&, uint32_t unit); + void upload(gl::Context&, uint32_t unit); LinePatternPos getDashPosition(const std::vector&, LinePatternCap); LinePatternPos addDash(const std::vector& dasharray, LinePatternCap); diff --git a/src/mbgl/geometry/vao.cpp b/src/mbgl/geometry/vao.cpp index 283c45289e..6a95127970 100644 --- a/src/mbgl/geometry/vao.cpp +++ b/src/mbgl/geometry/vao.cpp @@ -1,6 +1,5 @@ #include #include -#include #include namespace mbgl { @@ -10,7 +9,7 @@ VertexArrayObject::VertexArrayObject() { VertexArrayObject::~VertexArrayObject() = default; -void VertexArrayObject::bindVertexArrayObject(gl::ObjectStore& store, gl::Context& context) { +void VertexArrayObject::bindVertexArrayObject(gl::Context& context) { if (!gl::GenVertexArrays || !gl::BindVertexArray) { static bool reported = false; if (!reported) { @@ -21,7 +20,7 @@ void VertexArrayObject::bindVertexArrayObject(gl::ObjectStore& store, gl::Contex } if (!vao) { - vao = store.createVAO(); + vao = context.createVAO(); context.vertexBuffer.setDirty(); context.elementBuffer.setDirty(); } diff --git a/src/mbgl/geometry/vao.hpp b/src/mbgl/geometry/vao.hpp index 98ce3527cc..2cb81481f2 100644 --- a/src/mbgl/geometry/vao.hpp +++ b/src/mbgl/geometry/vao.hpp @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -20,11 +19,10 @@ public: void bind(Shader& shader, VertexBuffer& vertexBuffer, GLbyte* offset, - gl::ObjectStore& store, gl::Context& context) { - bindVertexArrayObject(store, context); + bindVertexArrayObject(context); if (bound_shader == 0) { - vertexBuffer.bind(store, context); + vertexBuffer.bind(context); shader.bind(offset); if (vao) { storeBinding(shader, vertexBuffer.getID(), 0, offset); @@ -39,12 +37,11 @@ public: VertexBuffer& vertexBuffer, ElementsBuffer& elementsBuffer, GLbyte* offset, - gl::ObjectStore& store, gl::Context& context) { - bindVertexArrayObject(store, context); + bindVertexArrayObject(context); if (bound_shader == 0) { - vertexBuffer.bind(store, context); - elementsBuffer.bind(store, context); + vertexBuffer.bind(context); + elementsBuffer.bind(context); shader.bind(offset); if (vao) { storeBinding(shader, vertexBuffer.getID(), elementsBuffer.getID(), offset); @@ -59,7 +56,7 @@ public: } private: - void bindVertexArrayObject(gl::ObjectStore&, gl::Context&); + void bindVertexArrayObject(gl::Context&); void storeBinding(Shader &shader, GLuint vertexBuffer, GLuint elementsBuffer, GLbyte *offset); void verifyBinding(Shader &shader, GLuint vertexBuffer, GLuint elementsBuffer, GLbyte *offset); diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp new file mode 100644 index 0000000000..101e11f4d8 --- /dev/null +++ b/src/mbgl/gl/context.cpp @@ -0,0 +1,95 @@ +#include + +namespace mbgl { +namespace gl { + +Context::~Context() { + reset(); +} + +void Context::reset() { + std::copy(pooledTextures.begin(), pooledTextures.end(), std::back_inserter(abandonedTextures)); + pooledTextures.resize(0); + performCleanup(); +} + +namespace { + +template +void applyStateFunction(Context& context, Fn&& fn) { + fn(context.stencilFunc); + fn(context.stencilMask); + fn(context.stencilTest); + fn(context.stencilOp); + fn(context.depthRange); + fn(context.depthMask); + fn(context.depthTest); + fn(context.depthFunc); + fn(context.blend); + fn(context.blendFunc); + fn(context.blendColor); + fn(context.colorMask); + fn(context.clearDepth); + fn(context.clearColor); + fn(context.clearStencil); + fn(context.program); + fn(context.lineWidth); + fn(context.activeTexture); + fn(context.bindFramebuffer); + fn(context.viewport); +#ifndef GL_ES_VERSION_2_0 + fn(context.pixelZoom); + fn(context.rasterPos); +#endif // GL_ES_VERSION_2_0 + for (auto& tex : context.texture) { + fn(tex); + } + fn(context.vertexBuffer); + fn(context.elementBuffer); + fn(context.vertexArrayObject); +} + +} // namespace + +void Context::resetState() { + applyStateFunction(*this, [](auto& state) { state.reset(); }); +} + +void Context::setDirtyState() { + applyStateFunction(*this, [](auto& state) { state.setDirty(); }); +} + +void Context::performCleanup() { + for (GLuint id : abandonedPrograms) { + MBGL_CHECK_ERROR(glDeleteProgram(id)); + } + abandonedPrograms.clear(); + + for (GLuint id : abandonedShaders) { + MBGL_CHECK_ERROR(glDeleteShader(id)); + } + abandonedShaders.clear(); + + if (!abandonedBuffers.empty()) { + MBGL_CHECK_ERROR(glDeleteBuffers(int(abandonedBuffers.size()), abandonedBuffers.data())); + abandonedBuffers.clear(); + } + + if (!abandonedTextures.empty()) { + MBGL_CHECK_ERROR(glDeleteTextures(int(abandonedTextures.size()), abandonedTextures.data())); + abandonedTextures.clear(); + } + + if (!abandonedVAOs.empty()) { + MBGL_CHECK_ERROR(gl::DeleteVertexArrays(int(abandonedVAOs.size()), abandonedVAOs.data())); + abandonedVAOs.clear(); + } + + if (!abandonedFBOs.empty()) { + MBGL_CHECK_ERROR(glDeleteFramebuffers(int(abandonedFBOs.size()), abandonedFBOs.data())); + abandonedFBOs.clear(); + } +} + +} // namespace gl +} // namespace mbgl diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp index 995f087c6b..5aa55b6a28 100644 --- a/src/mbgl/gl/context.hpp +++ b/src/mbgl/gl/context.hpp @@ -1,79 +1,81 @@ #pragma once +#include #include #include +#include + +#include +#include namespace mbgl { namespace gl { -class Context { +constexpr GLsizei TextureMax = 64; + +class Context : private util::noncopyable { public: - void resetState() { - stencilFunc.reset(); - stencilMask.reset(); - stencilTest.reset(); - stencilOp.reset(); - depthRange.reset(); - depthMask.reset(); - depthTest.reset(); - depthFunc.reset(); - blend.reset(); - blendFunc.reset(); - blendColor.reset(); - colorMask.reset(); - clearDepth.reset(); - clearColor.reset(); - clearStencil.reset(); - program.reset(); - lineWidth.reset(); - activeTexture.reset(); - bindFramebuffer.reset(); - viewport.reset(); -#ifndef GL_ES_VERSION_2_0 - pixelZoom.reset(); - rasterPos.reset(); -#endif // GL_ES_VERSION_2_0 - for (auto& tex : texture) { - tex.reset(); - } - vertexBuffer.reset(); - elementBuffer.reset(); - vertexArrayObject.reset(); + ~Context(); + + UniqueProgram createProgram() { + return UniqueProgram { MBGL_CHECK_ERROR(glCreateProgram()), { this } }; } - void setDirtyState() { - stencilFunc.setDirty(); - stencilMask.setDirty(); - stencilTest.setDirty(); - stencilOp.setDirty(); - depthRange.setDirty(); - depthMask.setDirty(); - depthTest.setDirty(); - depthFunc.setDirty(); - blend.setDirty(); - blendFunc.setDirty(); - blendColor.setDirty(); - colorMask.setDirty(); - clearDepth.setDirty(); - clearColor.setDirty(); - clearStencil.setDirty(); - program.setDirty(); - lineWidth.setDirty(); - activeTexture.setDirty(); - bindFramebuffer.setDirty(); - viewport.setDirty(); -#ifndef GL_ES_VERSION_2_0 - pixelZoom.setDirty(); - rasterPos.setDirty(); -#endif // GL_ES_VERSION_2_0 - for (auto& tex : texture) { - tex.setDirty(); + UniqueShader createShader(GLenum type) { + return UniqueShader { MBGL_CHECK_ERROR(glCreateShader(type)), { this } }; + } + + UniqueBuffer createBuffer() { + GLuint id = 0; + MBGL_CHECK_ERROR(glGenBuffers(1, &id)); + return UniqueBuffer { std::move(id), { this } }; + } + + UniqueTexture createTexture() { + if (pooledTextures.empty()) { + pooledTextures.resize(TextureMax); + MBGL_CHECK_ERROR(glGenTextures(TextureMax, pooledTextures.data())); } - vertexBuffer.setDirty(); - elementBuffer.setDirty(); - vertexArrayObject.setDirty(); + + GLuint id = pooledTextures.back(); + pooledTextures.pop_back(); + return UniqueTexture { std::move(id), { this } }; } + UniqueVAO createVAO() { + GLuint id = 0; + MBGL_CHECK_ERROR(gl::GenVertexArrays(1, &id)); + return UniqueVAO { std::move(id), { this } }; + } + + UniqueFBO createFBO() { + GLuint id = 0; + MBGL_CHECK_ERROR(glGenFramebuffers(1, &id)); + return UniqueFBO { std::move(id), { this } }; + } + + // Actually remove the objects we marked as abandoned with the above methods. + // Only call this while the OpenGL context is exclusive to this thread. + void performCleanup(); + + // Drain pools and remove abandoned objects, in preparation for destroying the store. + // Only call this while the OpenGL context is exclusive to this thread. + void reset(); + + bool empty() const { + return pooledTextures.empty() + && abandonedPrograms.empty() + && abandonedShaders.empty() + && abandonedBuffers.empty() + && abandonedTextures.empty() + && abandonedVAOs.empty() + && abandonedFBOs.empty(); + } + + void resetState(); + + void setDirtyState(); + State stencilFunc; State stencilMask; State stencilTest; @@ -102,6 +104,23 @@ public: State> vertexBuffer; State> elementBuffer; State vertexArrayObject; + +private: + friend detail::ProgramDeleter; + friend detail::ShaderDeleter; + friend detail::BufferDeleter; + friend detail::TextureDeleter; + friend detail::VAODeleter; + friend detail::FBODeleter; + + std::vector pooledTextures; + + std::vector abandonedPrograms; + std::vector abandonedShaders; + std::vector abandonedBuffers; + std::vector abandonedTextures; + std::vector abandonedVAOs; + std::vector abandonedFBOs; }; } // namespace gl diff --git a/src/mbgl/gl/object.cpp b/src/mbgl/gl/object.cpp new file mode 100644 index 0000000000..b9cabb8d9a --- /dev/null +++ b/src/mbgl/gl/object.cpp @@ -0,0 +1,46 @@ +#include +#include + +#include + +namespace mbgl { +namespace gl { +namespace detail { + +void ProgramDeleter::operator()(GLuint id) const { + assert(context); + context->abandonedPrograms.push_back(id); +} + +void ShaderDeleter::operator()(GLuint id) const { + assert(context); + context->abandonedShaders.push_back(id); +} + +void BufferDeleter::operator()(GLuint id) const { + assert(context); + context->abandonedBuffers.push_back(id); +} + +void TextureDeleter::operator()(GLuint id) const { + assert(context); + if (context->pooledTextures.size() >= TextureMax) { + context->abandonedTextures.push_back(id); + } else { + context->pooledTextures.push_back(id); + } +} + +void VAODeleter::operator()(GLuint id) const { + assert(context); + context->abandonedVAOs.push_back(id); +} + +void FBODeleter::operator()(GLuint id) const { + assert(context); + context->abandonedFBOs.push_back(id); +} + +} // namespace detail +} // namespace gl +} // namespace mbgl diff --git a/src/mbgl/gl/object.hpp b/src/mbgl/gl/object.hpp new file mode 100644 index 0000000000..44da13042f --- /dev/null +++ b/src/mbgl/gl/object.hpp @@ -0,0 +1,54 @@ +#pragma once + +#include + +#include + +namespace mbgl { +namespace gl { + +class Context; + +namespace detail { + +struct ProgramDeleter { + Context* context; + void operator()(GLuint) const; +}; + +struct ShaderDeleter { + Context* context; + void operator()(GLuint) const; +}; + +struct BufferDeleter { + Context* context; + void operator()(GLuint) const; +}; + +struct TextureDeleter { + Context* context; + void operator()(GLuint) const; +}; + +struct VAODeleter { + Context* context; + void operator()(GLuint) const; +}; + +struct FBODeleter { + Context* context; + void operator()(GLuint) const; +}; + +} // namespace detail + +using UniqueProgram = std_experimental::unique_resource; +using UniqueShader = std_experimental::unique_resource; +using UniqueBuffer = std_experimental::unique_resource; +using UniqueTexture = std_experimental::unique_resource; +using UniqueVAO = std_experimental::unique_resource; +using UniqueFBO = std_experimental::unique_resource; + +} // namespace gl +} // namespace mbgl diff --git a/src/mbgl/gl/object_store.cpp b/src/mbgl/gl/object_store.cpp deleted file mode 100644 index 9ddbaa7c8c..0000000000 --- a/src/mbgl/gl/object_store.cpp +++ /dev/null @@ -1,91 +0,0 @@ -#include - -#include - -namespace mbgl { -namespace gl { - -void ProgramDeleter::operator()(GLuint id) const { - assert(store); - store->abandonedPrograms.push_back(id); -} - -void ShaderDeleter::operator()(GLuint id) const { - assert(store); - store->abandonedShaders.push_back(id); -} - -void BufferDeleter::operator()(GLuint id) const { - assert(store); - store->abandonedBuffers.push_back(id); -} - -void TextureDeleter::operator()(GLuint id) const { - assert(store); - if (store->pooledTextures.size() >= TextureMax) { - store->abandonedTextures.push_back(id); - } else { - store->pooledTextures.push_back(id); - } -} - -void VAODeleter::operator()(GLuint id) const { - assert(store); - store->abandonedVAOs.push_back(id); -} - -void FBODeleter::operator()(GLuint id) const { - assert(store); - store->abandonedFBOs.push_back(id); -} - -ObjectStore::~ObjectStore() { - assert(pooledTextures.empty()); - assert(abandonedPrograms.empty()); - assert(abandonedShaders.empty()); - assert(abandonedBuffers.empty()); - assert(abandonedTextures.empty()); - assert(abandonedVAOs.empty()); - assert(abandonedFBOs.empty()); -} - -void ObjectStore::reset() { - std::copy(pooledTextures.begin(), pooledTextures.end(), std::back_inserter(abandonedTextures)); - pooledTextures.resize(0); - performCleanup(); -} - -void ObjectStore::performCleanup() { - for (GLuint id : abandonedPrograms) { - MBGL_CHECK_ERROR(glDeleteProgram(id)); - } - abandonedPrograms.clear(); - - for (GLuint id : abandonedShaders) { - MBGL_CHECK_ERROR(glDeleteShader(id)); - } - abandonedShaders.clear(); - - if (!abandonedBuffers.empty()) { - MBGL_CHECK_ERROR(glDeleteBuffers(int(abandonedBuffers.size()), abandonedBuffers.data())); - abandonedBuffers.clear(); - } - - if (!abandonedTextures.empty()) { - MBGL_CHECK_ERROR(glDeleteTextures(int(abandonedTextures.size()), abandonedTextures.data())); - abandonedTextures.clear(); - } - - if (!abandonedVAOs.empty()) { - MBGL_CHECK_ERROR(gl::DeleteVertexArrays(int(abandonedVAOs.size()), abandonedVAOs.data())); - abandonedVAOs.clear(); - } - - if (!abandonedFBOs.empty()) { - MBGL_CHECK_ERROR(glDeleteFramebuffers(int(abandonedFBOs.size()), abandonedFBOs.data())); - abandonedFBOs.clear(); - } -} - -} // namespace gl -} // namespace mbgl diff --git a/src/mbgl/gl/object_store.hpp b/src/mbgl/gl/object_store.hpp deleted file mode 100644 index ad9725c556..0000000000 --- a/src/mbgl/gl/object_store.hpp +++ /dev/null @@ -1,134 +0,0 @@ -#pragma once - -#include -#include - -#include - -#include -#include -#include - -namespace mbgl { -namespace gl { - -constexpr GLsizei TextureMax = 64; - -class ObjectStore; - -struct ProgramDeleter { - ObjectStore* store; - void operator()(GLuint) const; -}; - -struct ShaderDeleter { - ObjectStore* store; - void operator()(GLuint) const; -}; - -struct BufferDeleter { - ObjectStore* store; - void operator()(GLuint) const; -}; - -struct TextureDeleter { - ObjectStore* store; - void operator()(GLuint) const; -}; - -struct VAODeleter { - ObjectStore* store; - void operator()(GLuint) const; -}; - -struct FBODeleter { - ObjectStore* store; - void operator()(GLuint) const; -}; - -using UniqueProgram = std_experimental::unique_resource; -using UniqueShader = std_experimental::unique_resource; -using UniqueBuffer = std_experimental::unique_resource; -using UniqueTexture = std_experimental::unique_resource; -using UniqueVAO = std_experimental::unique_resource; -using UniqueFBO = std_experimental::unique_resource; - -class ObjectStore : private util::noncopyable { -public: - ~ObjectStore(); - - UniqueProgram createProgram() { - return UniqueProgram { MBGL_CHECK_ERROR(glCreateProgram()), { this } }; - } - - UniqueShader createShader(GLenum type) { - return UniqueShader { MBGL_CHECK_ERROR(glCreateShader(type)), { this } }; - } - - UniqueBuffer createBuffer() { - GLuint id = 0; - MBGL_CHECK_ERROR(glGenBuffers(1, &id)); - return UniqueBuffer { std::move(id), { this } }; - } - - UniqueTexture createTexture() { - if (pooledTextures.empty()) { - pooledTextures.resize(TextureMax); - MBGL_CHECK_ERROR(glGenTextures(TextureMax, pooledTextures.data())); - } - - GLuint id = pooledTextures.back(); - pooledTextures.pop_back(); - return UniqueTexture { std::move(id), { this } }; - } - - UniqueVAO createVAO() { - GLuint id = 0; - MBGL_CHECK_ERROR(gl::GenVertexArrays(1, &id)); - return UniqueVAO { std::move(id), { this } }; - } - - UniqueFBO createFBO() { - GLuint id = 0; - MBGL_CHECK_ERROR(glGenFramebuffers(1, &id)); - return UniqueFBO { std::move(id), { this } }; - } - - // Actually remove the objects we marked as abandoned with the above methods. - // Only call this while the OpenGL context is exclusive to this thread. - void performCleanup(); - - // Drain pools and remove abandoned objects, in preparation for destroying the store. - // Only call this while the OpenGL context is exclusive to this thread. - void reset(); - - bool empty() const { - return pooledTextures.empty() - && abandonedPrograms.empty() - && abandonedShaders.empty() - && abandonedBuffers.empty() - && abandonedTextures.empty() - && abandonedVAOs.empty() - && abandonedFBOs.empty(); - } - -private: - friend ProgramDeleter; - friend ShaderDeleter; - friend BufferDeleter; - friend TextureDeleter; - friend VAODeleter; - friend FBODeleter; - - std::vector pooledTextures; - - std::vector abandonedPrograms; - std::vector abandonedShaders; - std::vector abandonedBuffers; - std::vector abandonedTextures; - std::vector abandonedVAOs; - std::vector abandonedFBOs; -}; - -} // namespace gl -} // namespace mbgl diff --git a/src/mbgl/gl/state.hpp b/src/mbgl/gl/state.hpp index 274ae5e2fe..c7a7d74c63 100644 --- a/src/mbgl/gl/state.hpp +++ b/src/mbgl/gl/state.hpp @@ -45,10 +45,13 @@ public: return dirty || currentValue != value; } + // Explicitly resets the piece of OpenGL state to its default value. void reset() { *this = defaultValue; } + // Mark the state as dirty. This means that the next time we are assigning a value to this + // piece of OpenGL state will always result in an actual OpenGL call. void setDirty() { dirty = true; } diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index ce5e743868..fbc156d67a 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -61,7 +60,6 @@ public: MapDebugOptions debugOptions { MapDebugOptions::NoDebug }; - gl::ObjectStore store; Update updateFlags = Update::Nothing; util::AsyncTask asyncUpdate; ThreadPool workerThreadPool; @@ -113,11 +111,10 @@ Map::~Map() { impl->styleRequest = nullptr; // Explicit resets currently necessary because these abandon resources that need to be - // cleaned up by store.reset(); + // cleaned up by context.reset(); impl->style.reset(); - impl->painter.reset(); impl->annotationManager.reset(); - impl->store.reset(); + impl->painter.reset(); impl->view.deactivate(); } @@ -253,7 +250,7 @@ void Map::Impl::update() { void Map::Impl::render() { if (!painter) { - painter = std::make_unique(transform.getState(), store); + painter = std::make_unique(transform.getState()); } FrameData frameData { view.getFramebufferSize(), @@ -272,7 +269,7 @@ void Map::Impl::render() { callback = nullptr; } - store.performCleanup(); + painter->cleanup(); if (style->hasTransitions()) { updateFlags |= Update::RecalculateStyle; @@ -975,10 +972,13 @@ void Map::setSourceTileCacheSize(size_t size) { } void Map::onLowMemory() { - impl->store.performCleanup(); - if (!impl->style) return; - impl->style->onLowMemory(); - impl->view.invalidate(); + if (impl->painter) { + impl->painter->cleanup(); + } + if (impl->style) { + impl->style->onLowMemory(); + impl->view.invalidate(); + } } void Map::Impl::onSourceAttributionChanged(style::Source&, const std::string&) { diff --git a/src/mbgl/renderer/bucket.hpp b/src/mbgl/renderer/bucket.hpp index 957bfade49..48f6747447 100644 --- a/src/mbgl/renderer/bucket.hpp +++ b/src/mbgl/renderer/bucket.hpp @@ -16,7 +16,6 @@ class PaintParameters; class RenderTile; namespace gl { -class ObjectStore; class Context; } // namespace gl @@ -30,7 +29,7 @@ public: // As long as this bucket has a Prepare render pass, this function is getting called. Typically, // this only happens once when the bucket is being rendered for the first time. - virtual void upload(gl::ObjectStore&, gl::Context&) = 0; + virtual void upload(gl::Context&) = 0; // Every time this bucket is getting rendered, this function is called. This happens either // once or twice (for Opaque and Transparent render passes). diff --git a/src/mbgl/renderer/circle_bucket.cpp b/src/mbgl/renderer/circle_bucket.cpp index f33c893b04..2dcc71fd4b 100644 --- a/src/mbgl/renderer/circle_bucket.cpp +++ b/src/mbgl/renderer/circle_bucket.cpp @@ -16,9 +16,9 @@ CircleBucket::~CircleBucket() { // Do not remove. header file only contains forward definitions to unique pointers. } -void CircleBucket::upload(gl::ObjectStore& store, gl::Context& context) { - vertexBuffer_.upload(store, context); - elementsBuffer_.upload(store, context); +void CircleBucket::upload(gl::Context& context) { + vertexBuffer_.upload(context); + elementsBuffer_.upload(context); uploaded = true; } @@ -82,7 +82,7 @@ void CircleBucket::addGeometry(const GeometryCollection& geometryCollection) { } } -void CircleBucket::drawCircles(CircleShader& shader, gl::ObjectStore& store, gl::Context& context) { +void CircleBucket::drawCircles(CircleShader& shader, gl::Context& context) { GLbyte* vertexIndex = BUFFER_OFFSET(0); GLbyte* elementsIndex = BUFFER_OFFSET(0); @@ -91,7 +91,7 @@ void CircleBucket::drawCircles(CircleShader& shader, gl::ObjectStore& store, gl: if (!group->elements_length) continue; - group->array[0].bind(shader, vertexBuffer_, elementsBuffer_, vertexIndex, store, context); + group->array[0].bind(shader, vertexBuffer_, elementsBuffer_, vertexIndex, context); MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, group->elements_length * 3, GL_UNSIGNED_SHORT, elementsIndex)); diff --git a/src/mbgl/renderer/circle_bucket.hpp b/src/mbgl/renderer/circle_bucket.hpp index 045ddfab72..9e9357d77f 100644 --- a/src/mbgl/renderer/circle_bucket.hpp +++ b/src/mbgl/renderer/circle_bucket.hpp @@ -18,14 +18,14 @@ public: CircleBucket(const MapMode); ~CircleBucket() override; - void upload(gl::ObjectStore&, gl::Context&) override; + void upload(gl::Context&) override; void render(Painter&, PaintParameters&, const style::Layer&, const RenderTile&) override; bool hasData() const override; bool needsClipping() const override; void addGeometry(const GeometryCollection&); - void drawCircles(CircleShader&, gl::ObjectStore&, gl::Context&); + void drawCircles(CircleShader&, gl::Context&); private: CircleVertexBuffer vertexBuffer_; diff --git a/src/mbgl/renderer/debug_bucket.cpp b/src/mbgl/renderer/debug_bucket.cpp index 69e060c1bd..249924abb7 100644 --- a/src/mbgl/renderer/debug_bucket.cpp +++ b/src/mbgl/renderer/debug_bucket.cpp @@ -38,16 +38,16 @@ DebugBucket::DebugBucket(const OverscaledTileID& id, } } -void DebugBucket::drawLines(PlainShader& shader, gl::ObjectStore& store, gl::Context& context) { +void DebugBucket::drawLines(PlainShader& shader, gl::Context& context) { if (!fontBuffer.empty()) { - array.bind(shader, fontBuffer, BUFFER_OFFSET_0, store, context); + array.bind(shader, fontBuffer, BUFFER_OFFSET_0, context); MBGL_CHECK_ERROR(glDrawArrays(GL_LINES, 0, (GLsizei)(fontBuffer.index()))); } } -void DebugBucket::drawPoints(PlainShader& shader, gl::ObjectStore& store, gl::Context& context) { +void DebugBucket::drawPoints(PlainShader& shader, gl::Context& context) { if (!fontBuffer.empty()) { - array.bind(shader, fontBuffer, BUFFER_OFFSET_0, store, context); + array.bind(shader, fontBuffer, BUFFER_OFFSET_0, context); MBGL_CHECK_ERROR(glDrawArrays(GL_POINTS, 0, (GLsizei)(fontBuffer.index()))); } } diff --git a/src/mbgl/renderer/debug_bucket.hpp b/src/mbgl/renderer/debug_bucket.hpp index 413714178e..51315967da 100644 --- a/src/mbgl/renderer/debug_bucket.hpp +++ b/src/mbgl/renderer/debug_bucket.hpp @@ -11,7 +11,6 @@ class OverscaledTileID; class PlainShader; namespace gl { -class ObjectStore; class Context; } // namespace gl @@ -24,8 +23,8 @@ public: optional expires, MapDebugOptions); - void drawLines(PlainShader&, gl::ObjectStore&, gl::Context&); - void drawPoints(PlainShader&, gl::ObjectStore&, gl::Context&); + void drawLines(PlainShader&, gl::Context&); + void drawPoints(PlainShader&, gl::Context&); const bool renderable; const bool complete; diff --git a/src/mbgl/renderer/fill_bucket.cpp b/src/mbgl/renderer/fill_bucket.cpp index 868ab6afe4..d07fe5c725 100644 --- a/src/mbgl/renderer/fill_bucket.cpp +++ b/src/mbgl/renderer/fill_bucket.cpp @@ -95,10 +95,10 @@ void FillBucket::addGeometry(const GeometryCollection& geometry) { } } -void FillBucket::upload(gl::ObjectStore& store, gl::Context& context) { - vertexBuffer.upload(store, context); - triangleElementsBuffer.upload(store, context); - lineElementsBuffer.upload(store, context); +void FillBucket::upload(gl::Context& context) { + vertexBuffer.upload(context); + triangleElementsBuffer.upload(context); + lineElementsBuffer.upload(context); // From now on, we're going to render during the opaque and translucent pass. uploaded = true; @@ -120,7 +120,6 @@ bool FillBucket::needsClipping() const { } void FillBucket::drawElements(PlainShader& shader, - gl::ObjectStore& store, gl::Context& context, PaintMode paintMode) { GLbyte* vertex_index = BUFFER_OFFSET(0); @@ -128,7 +127,7 @@ void FillBucket::drawElements(PlainShader& shader, for (auto& group : triangleGroups) { assert(group); group->array[paintMode == PaintMode::Overdraw ? 1 : 0].bind( - shader, vertexBuffer, triangleElementsBuffer, vertex_index, store, context); + shader, vertexBuffer, triangleElementsBuffer, vertex_index, context); MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, group->elements_length * 3, GL_UNSIGNED_SHORT, elements_index)); vertex_index += group->vertex_length * vertexBuffer.itemSize; @@ -137,7 +136,6 @@ void FillBucket::drawElements(PlainShader& shader, } void FillBucket::drawElements(PatternShader& shader, - gl::ObjectStore& store, gl::Context& context, PaintMode paintMode) { GLbyte* vertex_index = BUFFER_OFFSET(0); @@ -145,7 +143,7 @@ void FillBucket::drawElements(PatternShader& shader, for (auto& group : triangleGroups) { assert(group); group->array[paintMode == PaintMode::Overdraw ? 3 : 2].bind( - shader, vertexBuffer, triangleElementsBuffer, vertex_index, store, context); + shader, vertexBuffer, triangleElementsBuffer, vertex_index, context); MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, group->elements_length * 3, GL_UNSIGNED_SHORT, elements_index)); vertex_index += group->vertex_length * vertexBuffer.itemSize; @@ -154,7 +152,6 @@ void FillBucket::drawElements(PatternShader& shader, } void FillBucket::drawVertices(OutlineShader& shader, - gl::ObjectStore& store, gl::Context& context, PaintMode paintMode) { GLbyte* vertex_index = BUFFER_OFFSET(0); @@ -162,7 +159,7 @@ void FillBucket::drawVertices(OutlineShader& shader, for (auto& group : lineGroups) { assert(group); group->array[paintMode == PaintMode::Overdraw ? 1 : 0].bind( - shader, vertexBuffer, lineElementsBuffer, vertex_index, store, context); + shader, vertexBuffer, lineElementsBuffer, vertex_index, context); MBGL_CHECK_ERROR(glDrawElements(GL_LINES, group->elements_length * 2, GL_UNSIGNED_SHORT, elements_index)); vertex_index += group->vertex_length * vertexBuffer.itemSize; @@ -171,7 +168,6 @@ void FillBucket::drawVertices(OutlineShader& shader, } void FillBucket::drawVertices(OutlinePatternShader& shader, - gl::ObjectStore& store, gl::Context& context, PaintMode paintMode) { GLbyte* vertex_index = BUFFER_OFFSET(0); @@ -179,7 +175,7 @@ void FillBucket::drawVertices(OutlinePatternShader& shader, for (auto& group : lineGroups) { assert(group); group->array[paintMode == PaintMode::Overdraw ? 3 : 2].bind( - shader, vertexBuffer, lineElementsBuffer, vertex_index, store, context); + shader, vertexBuffer, lineElementsBuffer, vertex_index, context); MBGL_CHECK_ERROR(glDrawElements(GL_LINES, group->elements_length * 2, GL_UNSIGNED_SHORT, elements_index)); vertex_index += group->vertex_length * vertexBuffer.itemSize; diff --git a/src/mbgl/renderer/fill_bucket.hpp b/src/mbgl/renderer/fill_bucket.hpp index b8c18545f7..2e6d390bfe 100644 --- a/src/mbgl/renderer/fill_bucket.hpp +++ b/src/mbgl/renderer/fill_bucket.hpp @@ -20,17 +20,17 @@ public: FillBucket(); ~FillBucket() override; - void upload(gl::ObjectStore&, gl::Context&) override; + void upload(gl::Context&) override; void render(Painter&, PaintParameters&, const style::Layer&, const RenderTile&) override; bool hasData() const override; bool needsClipping() const override; void addGeometry(const GeometryCollection&); - void drawElements(PlainShader&, gl::ObjectStore&, gl::Context&, PaintMode); - void drawElements(PatternShader&, gl::ObjectStore&, gl::Context&, PaintMode); - void drawVertices(OutlineShader&, gl::ObjectStore&, gl::Context&, PaintMode); - void drawVertices(OutlinePatternShader&, gl::ObjectStore&, gl::Context&, PaintMode); + void drawElements(PlainShader&, gl::Context&, PaintMode); + void drawElements(PatternShader&, gl::Context&, PaintMode); + void drawVertices(OutlineShader&, gl::Context&, PaintMode); + void drawVertices(OutlinePatternShader&, gl::Context&, PaintMode); private: FillVertexBuffer vertexBuffer; diff --git a/src/mbgl/renderer/frame_history.cpp b/src/mbgl/renderer/frame_history.cpp index 066d999b9a..bd35cbc090 100644 --- a/src/mbgl/renderer/frame_history.cpp +++ b/src/mbgl/renderer/frame_history.cpp @@ -58,11 +58,11 @@ bool FrameHistory::needsAnimation(const Duration& duration) const { return (time - previousTime) < duration; } -void FrameHistory::upload(gl::ObjectStore& store, gl::Context& context, uint32_t unit) { +void FrameHistory::upload(gl::Context& context, uint32_t unit) { if (changed) { const bool first = !texture; - bind(store, context, unit); + bind(context, unit); if (first) { MBGL_CHECK_ERROR(glTexImage2D( @@ -95,9 +95,9 @@ void FrameHistory::upload(gl::ObjectStore& store, gl::Context& context, uint32_t } } -void FrameHistory::bind(gl::ObjectStore& store, gl::Context& context, uint32_t unit) { +void FrameHistory::bind(gl::Context& context, uint32_t unit) { if (!texture) { - texture = store.createTexture(); + texture = context.createTexture(); context.activeTexture = unit; context.texture[unit] = *texture; #ifndef GL_ES_VERSION_2_0 diff --git a/src/mbgl/renderer/frame_history.hpp b/src/mbgl/renderer/frame_history.hpp index 88c4ebe301..063930af26 100644 --- a/src/mbgl/renderer/frame_history.hpp +++ b/src/mbgl/renderer/frame_history.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include @@ -19,8 +19,8 @@ public: void record(const TimePoint&, float zoom, const Duration&); bool needsAnimation(const Duration&) const; - void bind(gl::ObjectStore&, gl::Context&, uint32_t); - void upload(gl::ObjectStore&, gl::Context&, uint32_t); + void bind(gl::Context&, uint32_t); + void upload(gl::Context&, uint32_t); private: const int width = 256; diff --git a/src/mbgl/renderer/line_bucket.cpp b/src/mbgl/renderer/line_bucket.cpp index 56e07afe53..f9693ee538 100644 --- a/src/mbgl/renderer/line_bucket.cpp +++ b/src/mbgl/renderer/line_bucket.cpp @@ -437,9 +437,9 @@ void LineBucket::addPieSliceVertex(const GeometryCoordinate& currentVertex, } } -void LineBucket::upload(gl::ObjectStore& store, gl::Context& context) { - vertexBuffer.upload(store, context); - triangleElementsBuffer.upload(store, context); +void LineBucket::upload(gl::Context& context) { + vertexBuffer.upload(context); + triangleElementsBuffer.upload(context); // From now on, we're only going to render during the translucent pass. uploaded = true; @@ -461,7 +461,6 @@ bool LineBucket::needsClipping() const { } void LineBucket::drawLines(LineShader& shader, - gl::ObjectStore& store, gl::Context& context, PaintMode paintMode) { GLbyte* vertex_index = BUFFER_OFFSET(0); @@ -472,7 +471,7 @@ void LineBucket::drawLines(LineShader& shader, continue; } group->array[paintMode == PaintMode::Overdraw ? 1 : 0].bind( - shader, vertexBuffer, triangleElementsBuffer, vertex_index, store, context); + shader, vertexBuffer, triangleElementsBuffer, vertex_index, context); MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, group->elements_length * 3, GL_UNSIGNED_SHORT, elements_index)); vertex_index += group->vertex_length * vertexBuffer.itemSize; @@ -481,7 +480,6 @@ void LineBucket::drawLines(LineShader& shader, } void LineBucket::drawLineSDF(LineSDFShader& shader, - gl::ObjectStore& store, gl::Context& context, PaintMode paintMode) { GLbyte* vertex_index = BUFFER_OFFSET(0); @@ -492,7 +490,7 @@ void LineBucket::drawLineSDF(LineSDFShader& shader, continue; } group->array[paintMode == PaintMode::Overdraw ? 3 : 2].bind( - shader, vertexBuffer, triangleElementsBuffer, vertex_index, store, context); + shader, vertexBuffer, triangleElementsBuffer, vertex_index, context); MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, group->elements_length * 3, GL_UNSIGNED_SHORT, elements_index)); vertex_index += group->vertex_length * vertexBuffer.itemSize; @@ -501,7 +499,6 @@ void LineBucket::drawLineSDF(LineSDFShader& shader, } void LineBucket::drawLinePatterns(LinepatternShader& shader, - gl::ObjectStore& store, gl::Context& context, PaintMode paintMode) { GLbyte* vertex_index = BUFFER_OFFSET(0); @@ -512,7 +509,7 @@ void LineBucket::drawLinePatterns(LinepatternShader& shader, continue; } group->array[paintMode == PaintMode::Overdraw ? 5 : 4].bind( - shader, vertexBuffer, triangleElementsBuffer, vertex_index, store, context); + shader, vertexBuffer, triangleElementsBuffer, vertex_index, context); MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, group->elements_length * 3, GL_UNSIGNED_SHORT, elements_index)); vertex_index += group->vertex_length * vertexBuffer.itemSize; diff --git a/src/mbgl/renderer/line_bucket.hpp b/src/mbgl/renderer/line_bucket.hpp index 578aa764d3..112e5bd8c5 100644 --- a/src/mbgl/renderer/line_bucket.hpp +++ b/src/mbgl/renderer/line_bucket.hpp @@ -24,7 +24,7 @@ public: LineBucket(uint32_t overscaling); ~LineBucket() override; - void upload(gl::ObjectStore&, gl::Context&) override; + void upload(gl::Context&) override; void render(Painter&, PaintParameters&, const style::Layer&, const RenderTile&) override; bool hasData() const override; bool needsClipping() const override; @@ -32,9 +32,9 @@ public: void addGeometry(const GeometryCollection&); void addGeometry(const GeometryCoordinates& line); - void drawLines(LineShader&, gl::ObjectStore&, gl::Context&, PaintMode); - void drawLineSDF(LineSDFShader&, gl::ObjectStore&, gl::Context&, PaintMode); - void drawLinePatterns(LinepatternShader&, gl::ObjectStore&, gl::Context&, PaintMode); + void drawLines(LineShader&, gl::Context&, PaintMode); + void drawLineSDF(LineSDFShader&, gl::Context&, PaintMode); + void drawLinePatterns(LinepatternShader&, gl::Context&, PaintMode); private: struct TriangleElement { diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index 2a974f7d27..3d257c21f9 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -37,19 +37,17 @@ namespace mbgl { using namespace style; -Painter::Painter(const TransformState& state_, - gl::ObjectStore& store_) - : state(state_), store(store_) { +Painter::Painter(const TransformState& state_) + : state(state_) { gl::debugging::enable(); - shaders = std::make_unique(store); + shaders = std::make_unique(context); #ifndef NDEBUG - overdrawShaders = std::make_unique(store, Shader::Overdraw); + overdrawShaders = std::make_unique(context, Shader::Overdraw); #endif // Reset GL values context.setDirtyState(); - context.resetState(); } Painter::~Painter() = default; @@ -64,6 +62,10 @@ void Painter::setClipping(const ClipID& clip) { context.stencilFunc = { GL_EQUAL, ref, mask }; } +void Painter::cleanup() { + context.performCleanup(); +} + void Painter::render(const Style& style, const FrameData& frame_, SpriteAtlas& annotationSpriteAtlas) { if (frame.framebufferSize != frame_.framebufferSize) { context.viewport.setDefaultValue( @@ -104,18 +106,18 @@ void Painter::render(const Style& style, const FrameData& frame_, SpriteAtlas& a { MBGL_DEBUG_GROUP("upload"); - tileStencilBuffer.upload(store, context); - rasterBoundsBuffer.upload(store, context); - tileBorderBuffer.upload(store, context); - spriteAtlas->upload(store, context, 0); - lineAtlas->upload(store, context, 0); - glyphAtlas->upload(store, context, 0); - frameHistory.upload(store, context, 0); - annotationSpriteAtlas.upload(store, context, 0); + tileStencilBuffer.upload(context); + rasterBoundsBuffer.upload(context); + tileBorderBuffer.upload(context); + spriteAtlas->upload(context, 0); + lineAtlas->upload(context, 0); + glyphAtlas->upload(context, 0); + frameHistory.upload(context, 0); + annotationSpriteAtlas.upload(context, 0); for (const auto& item : order) { if (item.bucket && item.bucket->needsUpload()) { - item.bucket->upload(store, context); + item.bucket->upload(context); } } } diff --git a/src/mbgl/renderer/painter.hpp b/src/mbgl/renderer/painter.hpp index 31c840372f..6e11dd2599 100644 --- a/src/mbgl/renderer/painter.hpp +++ b/src/mbgl/renderer/painter.hpp @@ -47,10 +47,6 @@ class PaintParameters; struct ClipID; -namespace util { -class ObjectStore; -} // namespace util - namespace style { class Style; class Source; @@ -73,13 +69,15 @@ struct FrameData { class Painter : private util::noncopyable { public: - Painter(const TransformState&, gl::ObjectStore&); + Painter(const TransformState&); ~Painter(); void render(const style::Style&, const FrameData&, SpriteAtlas& annotationSpriteAtlas); + void cleanup(); + // Renders debug information for a tile. void renderTileDebug(const RenderTile&); @@ -125,7 +123,7 @@ private: float scaleDivisor, std::array texsize, SDFShader& sdfShader, - void (SymbolBucket::*drawSDF)(SDFShader&, gl::ObjectStore&, gl::Context&, PaintMode), + void (SymbolBucket::*drawSDF)(SDFShader&, gl::Context&, PaintMode), // Layout style::AlignmentType rotationAlignment, @@ -166,7 +164,6 @@ private: }(); const TransformState& state; - gl::ObjectStore& store; FrameData frame; diff --git a/src/mbgl/renderer/painter_background.cpp b/src/mbgl/renderer/painter_background.cpp index b19a7563eb..d8bb3f9218 100644 --- a/src/mbgl/renderer/painter_background.cpp +++ b/src/mbgl/renderer/painter_background.cpp @@ -44,15 +44,15 @@ void Painter::renderBackground(PaintParameters& parameters, const BackgroundLaye patternShader.u_mix = properties.backgroundPattern.value.t; patternShader.u_opacity = properties.backgroundOpacity; - spriteAtlas->bind(true, store, context, 0); - arrayBackgroundPattern.bind(patternShader, tileStencilBuffer, BUFFER_OFFSET(0), store, context); + spriteAtlas->bind(true, context, 0); + arrayBackgroundPattern.bind(patternShader, tileStencilBuffer, BUFFER_OFFSET(0), context); } else { context.program = plainShader.getID(); plainShader.u_color = properties.backgroundColor; plainShader.u_opacity = properties.backgroundOpacity; - arrayBackground.bind(plainShader, tileStencilBuffer, BUFFER_OFFSET(0), store, context); + arrayBackground.bind(plainShader, tileStencilBuffer, BUFFER_OFFSET(0), context); } context.stencilTest = GL_FALSE; diff --git a/src/mbgl/renderer/painter_circle.cpp b/src/mbgl/renderer/painter_circle.cpp index 14eb957dfd..0894e9b261 100644 --- a/src/mbgl/renderer/painter_circle.cpp +++ b/src/mbgl/renderer/painter_circle.cpp @@ -51,7 +51,7 @@ void Painter::renderCircle(PaintParameters& parameters, circleShader.u_blur = properties.circleBlur; circleShader.u_opacity = properties.circleOpacity; - bucket.drawCircles(circleShader, store, context); + bucket.drawCircles(circleShader, context); } } // namespace mbgl diff --git a/src/mbgl/renderer/painter_clipping.cpp b/src/mbgl/renderer/painter_clipping.cpp index 14808310e4..7e9fb1c737 100644 --- a/src/mbgl/renderer/painter_clipping.cpp +++ b/src/mbgl/renderer/painter_clipping.cpp @@ -26,7 +26,7 @@ void Painter::drawClippingMasks(PaintParameters& parameters, const std::mapdrawLines(plainShader, store, context); + tile.debugBucket->drawLines(plainShader, context); #ifndef GL_ES_VERSION_2_0 // Draw line "end caps" MBGL_CHECK_ERROR(glPointSize(2)); - tile.debugBucket->drawPoints(plainShader, store, context); + tile.debugBucket->drawPoints(plainShader, context); #endif // Draw black text. plainShader.u_color = Color::black(); context.lineWidth = 2.0f * frame.pixelRatio; - tile.debugBucket->drawLines(plainShader, store, context); + tile.debugBucket->drawLines(plainShader, context); context.depthFunc.reset(); context.depthTest = GL_TRUE; @@ -79,7 +79,7 @@ void Painter::renderDebugFrame(const mat4 &matrix) { plainShader.u_opacity = 1.0f; // draw tile outline - tileBorderArray.bind(plainShader, tileBorderBuffer, BUFFER_OFFSET_0, store, context); + tileBorderArray.bind(plainShader, tileBorderBuffer, BUFFER_OFFSET_0, context); plainShader.u_color = { 1.0f, 0.0f, 0.0f, 1.0f }; context.lineWidth = 4.0f * frame.pixelRatio; MBGL_CHECK_ERROR(glDrawArrays(GL_LINE_STRIP, 0, (GLsizei)tileBorderBuffer.index())); diff --git a/src/mbgl/renderer/painter_fill.cpp b/src/mbgl/renderer/painter_fill.cpp index c6f36dd209..57db012b0c 100644 --- a/src/mbgl/renderer/painter_fill.cpp +++ b/src/mbgl/renderer/painter_fill.cpp @@ -69,7 +69,7 @@ void Painter::renderFill(PaintParameters& parameters, // the (non-antialiased) fill. setDepthSublayer(0); // OK } - bucket.drawVertices(outlineShader, store, context, paintMode()); + bucket.drawVertices(outlineShader, context, paintMode()); } if (pattern) { @@ -101,11 +101,11 @@ void Painter::renderFill(PaintParameters& parameters, patternShader.u_pixel_coord_upper = {{ float(pixelX >> 16), float(pixelY >> 16) }}; patternShader.u_pixel_coord_lower = {{ float(pixelX & 0xFFFF), float(pixelY & 0xFFFF) }}; - spriteAtlas->bind(true, store, context, 0); + spriteAtlas->bind(true, context, 0); // Draw the actual triangles into the color & stencil buffer. setDepthSublayer(0); - bucket.drawElements(patternShader, store, context, paintMode()); + bucket.drawElements(patternShader, context, paintMode()); if (properties.fillAntialias && !isOutlineColorDefined) { context.program = outlinePatternShader.getID(); @@ -129,10 +129,10 @@ void Painter::renderFill(PaintParameters& parameters, // Draw the entire line outlinePatternShader.u_world = worldSize; - spriteAtlas->bind(true, store, context, 0); + spriteAtlas->bind(true, context, 0); setDepthSublayer(2); - bucket.drawVertices(outlinePatternShader, store, context, paintMode()); + bucket.drawVertices(outlinePatternShader, context, paintMode()); } } } else { @@ -149,7 +149,7 @@ void Painter::renderFill(PaintParameters& parameters, // Draw the actual triangles into the color & stencil buffer. setDepthSublayer(1); - bucket.drawElements(plainShader, store, context, paintMode()); + bucket.drawElements(plainShader, context, paintMode()); } } @@ -166,7 +166,7 @@ void Painter::renderFill(PaintParameters& parameters, outlineShader.u_world = worldSize; setDepthSublayer(2); - bucket.drawVertices(outlineShader, store, context, paintMode()); + bucket.drawVertices(outlineShader, context, paintMode()); } } diff --git a/src/mbgl/renderer/painter_line.cpp b/src/mbgl/renderer/painter_line.cpp index 97e64027da..4658812ef3 100644 --- a/src/mbgl/renderer/painter_line.cpp +++ b/src/mbgl/renderer/painter_line.cpp @@ -96,9 +96,9 @@ void Painter::renderLine(PaintParameters& parameters, linesdfShader.u_antialiasingmatrix = antialiasingMatrix; linesdfShader.u_image = 0; - lineAtlas->bind(store, context, 0); + lineAtlas->bind(context, 0); - bucket.drawLineSDF(linesdfShader, store, context, paintMode()); + bucket.drawLineSDF(linesdfShader, context, paintMode()); } else if (!properties.linePattern.value.from.empty()) { optional imagePosA = spriteAtlas->getPosition( @@ -139,9 +139,9 @@ void Painter::renderLine(PaintParameters& parameters, linepatternShader.u_antialiasingmatrix = antialiasingMatrix; linepatternShader.u_image = 0; - spriteAtlas->bind(true, store, context, 0); + spriteAtlas->bind(true, context, 0); - bucket.drawLinePatterns(linepatternShader, store, context, paintMode()); + bucket.drawLinePatterns(linepatternShader, context, paintMode()); } else { context.program = lineShader.getID(); @@ -159,7 +159,7 @@ void Painter::renderLine(PaintParameters& parameters, lineShader.u_color = color; lineShader.u_opacity = opacity; - bucket.drawLines(lineShader, store, context, paintMode()); + bucket.drawLines(lineShader, context, paintMode()); } } diff --git a/src/mbgl/renderer/painter_raster.cpp b/src/mbgl/renderer/painter_raster.cpp index 16808f80a6..bb956cce8b 100644 --- a/src/mbgl/renderer/painter_raster.cpp +++ b/src/mbgl/renderer/painter_raster.cpp @@ -47,7 +47,7 @@ void Painter::renderRaster(PaintParameters& parameters, context.depthMask = GL_FALSE; setDepthSublayer(0); - bucket.drawRaster(rasterShader, rasterBoundsBuffer, rasterVAO, context, store); + bucket.drawRaster(rasterShader, rasterBoundsBuffer, rasterVAO, context); } } diff --git a/src/mbgl/renderer/painter_symbol.cpp b/src/mbgl/renderer/painter_symbol.cpp index 635c81fbf7..74cdcb4b08 100644 --- a/src/mbgl/renderer/painter_symbol.cpp +++ b/src/mbgl/renderer/painter_symbol.cpp @@ -20,7 +20,7 @@ void Painter::renderSDF(SymbolBucket& bucket, float sdfFontSize, std::array texsize, SDFShader& sdfShader, - void (SymbolBucket::*drawSDF)(SDFShader&, gl::ObjectStore&, gl::Context&, PaintMode), + void (SymbolBucket::*drawSDF)(SDFShader&, gl::Context&, PaintMode), // Layout AlignmentType rotationAlignment, @@ -76,7 +76,7 @@ void Painter::renderSDF(SymbolBucket& bucket, sdfShader.u_zoom = (state.getZoom() - zoomAdjust) * 10; // current zoom level - frameHistory.bind(store, context, 1); + frameHistory.bind(context, 1); sdfShader.u_fadetexture = 1; // The default gamma value has to be adjust for the current pixelratio so that we're not @@ -94,7 +94,7 @@ void Painter::renderSDF(SymbolBucket& bucket, sdfShader.u_color = haloColor; sdfShader.u_opacity = opacity; sdfShader.u_buffer = (haloOffset - haloWidth / fontScale) / sdfPx; - (bucket.*drawSDF)(sdfShader, store, context, paintMode()); + (bucket.*drawSDF)(sdfShader, context, paintMode()); } // Then, we draw the text/icon over the halo @@ -103,7 +103,7 @@ void Painter::renderSDF(SymbolBucket& bucket, sdfShader.u_color = color; sdfShader.u_opacity = opacity; sdfShader.u_buffer = (256.0f - 64.0f) / 256.0f; - (bucket.*drawSDF)(sdfShader, store, context, paintMode()); + (bucket.*drawSDF)(sdfShader, context, paintMode()); } } @@ -160,7 +160,7 @@ void Painter::renderSymbol(PaintParameters& parameters, SpriteAtlas* activeSpriteAtlas = layer.impl->spriteAtlas; const bool iconScaled = fontScale != 1 || frame.pixelRatio != activeSpriteAtlas->getPixelRatio() || bucket.iconsNeedLinear; const bool iconTransformed = layout.iconRotationAlignment == AlignmentType::Map || angleOffset != 0 || state.getPitch() != 0; - activeSpriteAtlas->bind(sdf || state.isChanging() || iconScaled || iconTransformed, store, context, 0); + activeSpriteAtlas->bind(sdf || state.isChanging() || iconScaled || iconTransformed, context, 0); if (sdf) { renderSDF(bucket, @@ -213,10 +213,10 @@ void Painter::renderSymbol(PaintParameters& parameters, iconShader.u_zoom = (state.getZoom() - zoomAdjust) * 10; // current zoom level iconShader.u_opacity = paint.iconOpacity; - frameHistory.bind(store, context, 1); + frameHistory.bind(context, 1); iconShader.u_fadetexture = 1; - bucket.drawIcons(iconShader, store, context, paintMode()); + bucket.drawIcons(iconShader, context, paintMode()); } } @@ -228,7 +228,7 @@ void Painter::renderSymbol(PaintParameters& parameters, context.depthTest = GL_FALSE; } - glyphAtlas->bind(store, context, 0); + glyphAtlas->bind(context, 0); renderSDF(bucket, tile, @@ -262,7 +262,7 @@ void Painter::renderSymbol(PaintParameters& parameters, collisionBoxShader.u_maxzoom = (tile.id.canonical.z + 1) * 10; context.lineWidth = 1.0f; - bucket.drawCollisionBoxes(collisionBoxShader, store, context); + bucket.drawCollisionBoxes(collisionBoxShader, context); } } diff --git a/src/mbgl/renderer/raster_bucket.cpp b/src/mbgl/renderer/raster_bucket.cpp index 32db44f16b..f40bfcf27c 100644 --- a/src/mbgl/renderer/raster_bucket.cpp +++ b/src/mbgl/renderer/raster_bucket.cpp @@ -7,9 +7,9 @@ namespace mbgl { using namespace style; -void RasterBucket::upload(gl::ObjectStore& store, gl::Context& context) { +void RasterBucket::upload(gl::Context& context) { if (hasData()) { - raster.upload(store, context, 0); + raster.upload(context, 0); uploaded = true; } } @@ -28,11 +28,10 @@ void RasterBucket::setImage(PremultipliedImage image) { void RasterBucket::drawRaster(RasterShader& shader, StaticRasterVertexBuffer& vertices, VertexArrayObject& array, - gl::Context& context, - gl::ObjectStore& store) { - raster.bind(store, context, 0, Raster::Scaling::Linear); - raster.bind(store, context, 1, Raster::Scaling::Linear); - array.bind(shader, vertices, BUFFER_OFFSET_0, store, context); + gl::Context& context) { + raster.bind(context, 0, Raster::Scaling::Linear); + raster.bind(context, 1, Raster::Scaling::Linear); + array.bind(shader, vertices, BUFFER_OFFSET_0, context); MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)vertices.index())); } diff --git a/src/mbgl/renderer/raster_bucket.hpp b/src/mbgl/renderer/raster_bucket.hpp index 68dc3f0ad5..24f3f8864a 100644 --- a/src/mbgl/renderer/raster_bucket.hpp +++ b/src/mbgl/renderer/raster_bucket.hpp @@ -12,14 +12,14 @@ class VertexArrayObject; class RasterBucket : public Bucket { public: - void upload(gl::ObjectStore&, gl::Context&) override; + void upload(gl::Context&) override; void render(Painter&, PaintParameters&, const style::Layer&, const RenderTile&) override; bool hasData() const override; bool needsClipping() const override; void setImage(PremultipliedImage); - void drawRaster(RasterShader&, StaticRasterVertexBuffer&, VertexArrayObject&, gl::Context&, gl::ObjectStore&); + void drawRaster(RasterShader&, StaticRasterVertexBuffer&, VertexArrayObject&, gl::Context&); Raster raster; }; diff --git a/src/mbgl/renderer/symbol_bucket.cpp b/src/mbgl/renderer/symbol_bucket.cpp index a692281fa6..694e77d45b 100644 --- a/src/mbgl/renderer/symbol_bucket.cpp +++ b/src/mbgl/renderer/symbol_bucket.cpp @@ -19,14 +19,14 @@ SymbolBucket::SymbolBucket(const MapMode mode_, iconsNeedLinear(iconsNeedLinear_) { } -void SymbolBucket::upload(gl::ObjectStore& store, gl::Context& context) { +void SymbolBucket::upload(gl::Context& context) { if (hasTextData()) { - text.vertices.upload(store, context); - text.triangles.upload(store, context); + text.vertices.upload(context); + text.triangles.upload(context); } if (hasIconData()) { - icon.vertices.upload(store, context); - icon.triangles.upload(store, context); + icon.vertices.upload(context); + icon.triangles.upload(context); } uploaded = true; @@ -61,7 +61,6 @@ bool SymbolBucket::needsClipping() const { } void SymbolBucket::drawGlyphs(SDFShader& shader, - gl::ObjectStore& store, gl::Context& context, PaintMode paintMode) { GLbyte* vertex_index = BUFFER_OFFSET_0; @@ -69,7 +68,7 @@ void SymbolBucket::drawGlyphs(SDFShader& shader, for (auto& group : text.groups) { assert(group); group->array[paintMode == PaintMode::Overdraw ? 1 : 0].bind( - shader, text.vertices, text.triangles, vertex_index, store, context); + shader, text.vertices, text.triangles, vertex_index, context); MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, group->elements_length * 3, GL_UNSIGNED_SHORT, elements_index)); vertex_index += group->vertex_length * text.vertices.itemSize; @@ -78,7 +77,6 @@ void SymbolBucket::drawGlyphs(SDFShader& shader, } void SymbolBucket::drawIcons(SDFShader& shader, - gl::ObjectStore& store, gl::Context& context, PaintMode paintMode) { GLbyte* vertex_index = BUFFER_OFFSET_0; @@ -86,7 +84,7 @@ void SymbolBucket::drawIcons(SDFShader& shader, for (auto& group : icon.groups) { assert(group); group->array[paintMode == PaintMode::Overdraw ? 1 : 0].bind( - shader, icon.vertices, icon.triangles, vertex_index, store, context); + shader, icon.vertices, icon.triangles, vertex_index, context); MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, group->elements_length * 3, GL_UNSIGNED_SHORT, elements_index)); vertex_index += group->vertex_length * icon.vertices.itemSize; @@ -95,7 +93,6 @@ void SymbolBucket::drawIcons(SDFShader& shader, } void SymbolBucket::drawIcons(IconShader& shader, - gl::ObjectStore& store, gl::Context& context, PaintMode paintMode) { GLbyte* vertex_index = BUFFER_OFFSET_0; @@ -103,7 +100,7 @@ void SymbolBucket::drawIcons(IconShader& shader, for (auto& group : icon.groups) { assert(group); group->array[paintMode == PaintMode::Overdraw ? 3 : 2].bind( - shader, icon.vertices, icon.triangles, vertex_index, store, context); + shader, icon.vertices, icon.triangles, vertex_index, context); MBGL_CHECK_ERROR(glDrawElements(GL_TRIANGLES, group->elements_length * 3, GL_UNSIGNED_SHORT, elements_index)); vertex_index += group->vertex_length * icon.vertices.itemSize; @@ -112,11 +109,10 @@ void SymbolBucket::drawIcons(IconShader& shader, } void SymbolBucket::drawCollisionBoxes(CollisionBoxShader& shader, - gl::ObjectStore& store, gl::Context& context) { GLbyte* vertex_index = BUFFER_OFFSET_0; for (auto& group : collisionBox.groups) { - group->array[0].bind(shader, collisionBox.vertices, vertex_index, store, context); + group->array[0].bind(shader, collisionBox.vertices, vertex_index, context); MBGL_CHECK_ERROR(glDrawArrays(GL_LINES, 0, group->vertex_length)); } } diff --git a/src/mbgl/renderer/symbol_bucket.hpp b/src/mbgl/renderer/symbol_bucket.hpp index a915df5424..87c8250d55 100644 --- a/src/mbgl/renderer/symbol_bucket.hpp +++ b/src/mbgl/renderer/symbol_bucket.hpp @@ -25,7 +25,7 @@ public: bool sdfIcons, bool iconsNeedLinear); - void upload(gl::ObjectStore&, gl::Context&) override; + void upload(gl::Context&) override; void render(Painter&, PaintParameters&, const style::Layer&, const RenderTile&) override; bool hasData() const override; bool hasTextData() const; @@ -33,10 +33,10 @@ public: bool hasCollisionBoxData() const; bool needsClipping() const override; - void drawGlyphs(SDFShader&, gl::ObjectStore&, gl::Context&, PaintMode); - void drawIcons(SDFShader&, gl::ObjectStore&, gl::Context&, PaintMode); - void drawIcons(IconShader&, gl::ObjectStore&, gl::Context&, PaintMode); - void drawCollisionBoxes(CollisionBoxShader&, gl::ObjectStore&, gl::Context&); + void drawGlyphs(SDFShader&, gl::Context&, PaintMode); + void drawIcons(SDFShader&, gl::Context&, PaintMode); + void drawIcons(IconShader&, gl::Context&, PaintMode); + void drawCollisionBoxes(CollisionBoxShader&, gl::Context&); const MapMode mode; const style::SymbolLayoutProperties layout; diff --git a/src/mbgl/shader/circle_shader.cpp b/src/mbgl/shader/circle_shader.cpp index b19dbeba68..99ae647544 100644 --- a/src/mbgl/shader/circle_shader.cpp +++ b/src/mbgl/shader/circle_shader.cpp @@ -5,11 +5,11 @@ namespace mbgl { -CircleShader::CircleShader(gl::ObjectStore& store, Defines defines) +CircleShader::CircleShader(gl::Context& context, Defines defines) : Shader(shaders::circle::name, shaders::circle::vertex, shaders::circle::fragment, - store, defines) { + context, defines) { } void CircleShader::bind(GLbyte* offset) { diff --git a/src/mbgl/shader/circle_shader.hpp b/src/mbgl/shader/circle_shader.hpp index c454fc1337..dbe7ac811c 100644 --- a/src/mbgl/shader/circle_shader.hpp +++ b/src/mbgl/shader/circle_shader.hpp @@ -8,7 +8,7 @@ namespace mbgl { class CircleShader : public Shader { public: - CircleShader(gl::ObjectStore&, Defines defines = None); + CircleShader(gl::Context&, Defines defines = None); void bind(GLbyte *offset) final; diff --git a/src/mbgl/shader/collision_box_shader.cpp b/src/mbgl/shader/collision_box_shader.cpp index bfee89fac2..c0a24f0f6f 100644 --- a/src/mbgl/shader/collision_box_shader.cpp +++ b/src/mbgl/shader/collision_box_shader.cpp @@ -5,11 +5,11 @@ namespace mbgl { -CollisionBoxShader::CollisionBoxShader(gl::ObjectStore& store) +CollisionBoxShader::CollisionBoxShader(gl::Context& context) : Shader(shaders::collisionbox::name, shaders::collisionbox::vertex, shaders::collisionbox::fragment, - store) { + context) { } void CollisionBoxShader::bind(GLbyte *offset) { diff --git a/src/mbgl/shader/collision_box_shader.hpp b/src/mbgl/shader/collision_box_shader.hpp index bbd2611ce8..a3f61dea54 100644 --- a/src/mbgl/shader/collision_box_shader.hpp +++ b/src/mbgl/shader/collision_box_shader.hpp @@ -8,7 +8,7 @@ namespace mbgl { class CollisionBoxShader : public Shader { public: - CollisionBoxShader(gl::ObjectStore&); + CollisionBoxShader(gl::Context&); void bind(GLbyte *offset) final; diff --git a/src/mbgl/shader/icon_shader.cpp b/src/mbgl/shader/icon_shader.cpp index 148cf30043..58b9f8069e 100644 --- a/src/mbgl/shader/icon_shader.cpp +++ b/src/mbgl/shader/icon_shader.cpp @@ -5,11 +5,11 @@ namespace mbgl { -IconShader::IconShader(gl::ObjectStore& store, Defines defines) +IconShader::IconShader(gl::Context& context, Defines defines) : Shader(shaders::icon::name, shaders::icon::vertex, shaders::icon::fragment, - store, defines) { + context, defines) { } void IconShader::bind(GLbyte* offset) { diff --git a/src/mbgl/shader/icon_shader.hpp b/src/mbgl/shader/icon_shader.hpp index 86c7b8ece0..57941cf172 100644 --- a/src/mbgl/shader/icon_shader.hpp +++ b/src/mbgl/shader/icon_shader.hpp @@ -7,7 +7,7 @@ namespace mbgl { class IconShader : public Shader { public: - IconShader(gl::ObjectStore&, Defines defines = None); + IconShader(gl::Context&, Defines defines = None); void bind(GLbyte *offset) final; diff --git a/src/mbgl/shader/line_shader.cpp b/src/mbgl/shader/line_shader.cpp index 8c3ad32d73..73bb1e2f40 100644 --- a/src/mbgl/shader/line_shader.cpp +++ b/src/mbgl/shader/line_shader.cpp @@ -5,11 +5,11 @@ namespace mbgl { -LineShader::LineShader(gl::ObjectStore& store, Defines defines) +LineShader::LineShader(gl::Context& context, Defines defines) : Shader(shaders::line::name, shaders::line::vertex, shaders::line::fragment, - store, defines) { + context, defines) { } void LineShader::bind(GLbyte* offset) { diff --git a/src/mbgl/shader/line_shader.hpp b/src/mbgl/shader/line_shader.hpp index a2cda56314..1ad4b56b01 100644 --- a/src/mbgl/shader/line_shader.hpp +++ b/src/mbgl/shader/line_shader.hpp @@ -8,7 +8,7 @@ namespace mbgl { class LineShader : public Shader { public: - LineShader(gl::ObjectStore&, Defines defines = None); + LineShader(gl::Context&, Defines defines = None); void bind(GLbyte *offset) final; diff --git a/src/mbgl/shader/linepattern_shader.cpp b/src/mbgl/shader/linepattern_shader.cpp index 48375dec24..3adcd193d8 100644 --- a/src/mbgl/shader/linepattern_shader.cpp +++ b/src/mbgl/shader/linepattern_shader.cpp @@ -5,11 +5,11 @@ namespace mbgl { -LinepatternShader::LinepatternShader(gl::ObjectStore& store, Defines defines) +LinepatternShader::LinepatternShader(gl::Context& context, Defines defines) : Shader(shaders::linepattern::name, shaders::linepattern::vertex, shaders::linepattern::fragment, - store, defines) { + context, defines) { } void LinepatternShader::bind(GLbyte* offset) { diff --git a/src/mbgl/shader/linepattern_shader.hpp b/src/mbgl/shader/linepattern_shader.hpp index 6c44716d10..8f6a54de2c 100644 --- a/src/mbgl/shader/linepattern_shader.hpp +++ b/src/mbgl/shader/linepattern_shader.hpp @@ -7,7 +7,7 @@ namespace mbgl { class LinepatternShader : public Shader { public: - LinepatternShader(gl::ObjectStore&, Defines defines = None); + LinepatternShader(gl::Context&, Defines defines = None); void bind(GLbyte *offset) final; diff --git a/src/mbgl/shader/linesdf_shader.cpp b/src/mbgl/shader/linesdf_shader.cpp index 8b2e983e0d..0706fe4ea8 100644 --- a/src/mbgl/shader/linesdf_shader.cpp +++ b/src/mbgl/shader/linesdf_shader.cpp @@ -5,11 +5,11 @@ namespace mbgl { -LineSDFShader::LineSDFShader(gl::ObjectStore& store, Defines defines) +LineSDFShader::LineSDFShader(gl::Context& context, Defines defines) : Shader(shaders::linesdfpattern::name, shaders::linesdfpattern::vertex, shaders::linesdfpattern::fragment, - store, defines) { + context, defines) { } void LineSDFShader::bind(GLbyte* offset) { diff --git a/src/mbgl/shader/linesdf_shader.hpp b/src/mbgl/shader/linesdf_shader.hpp index ce1fe4d17c..9f4fb720ee 100644 --- a/src/mbgl/shader/linesdf_shader.hpp +++ b/src/mbgl/shader/linesdf_shader.hpp @@ -8,7 +8,7 @@ namespace mbgl { class LineSDFShader : public Shader { public: - LineSDFShader(gl::ObjectStore&, Defines defines = None); + LineSDFShader(gl::Context&, Defines defines = None); void bind(GLbyte *offset) final; diff --git a/src/mbgl/shader/outline_shader.cpp b/src/mbgl/shader/outline_shader.cpp index 58f73d9f44..4609e536bb 100644 --- a/src/mbgl/shader/outline_shader.cpp +++ b/src/mbgl/shader/outline_shader.cpp @@ -5,11 +5,11 @@ namespace mbgl { -OutlineShader::OutlineShader(gl::ObjectStore& store, Defines defines) +OutlineShader::OutlineShader(gl::Context& context, Defines defines) : Shader(shaders::outline::name, shaders::outline::vertex, shaders::outline::fragment, - store, defines) { + context, defines) { } void OutlineShader::bind(GLbyte* offset) { diff --git a/src/mbgl/shader/outline_shader.hpp b/src/mbgl/shader/outline_shader.hpp index 5840ad2238..a0135fb8ec 100644 --- a/src/mbgl/shader/outline_shader.hpp +++ b/src/mbgl/shader/outline_shader.hpp @@ -8,7 +8,7 @@ namespace mbgl { class OutlineShader : public Shader { public: - OutlineShader(gl::ObjectStore&, Defines defines = None); + OutlineShader(gl::Context&, Defines defines = None); void bind(GLbyte *offset) final; diff --git a/src/mbgl/shader/outlinepattern_shader.cpp b/src/mbgl/shader/outlinepattern_shader.cpp index 2373a75370..b33c2b2c1f 100644 --- a/src/mbgl/shader/outlinepattern_shader.cpp +++ b/src/mbgl/shader/outlinepattern_shader.cpp @@ -5,11 +5,11 @@ namespace mbgl { -OutlinePatternShader::OutlinePatternShader(gl::ObjectStore& store, Defines defines) +OutlinePatternShader::OutlinePatternShader(gl::Context& context, Defines defines) : Shader(shaders::outlinepattern::name, shaders::outlinepattern::vertex, shaders::outlinepattern::fragment, - store, defines) { + context, defines) { } void OutlinePatternShader::bind(GLbyte *offset) { diff --git a/src/mbgl/shader/outlinepattern_shader.hpp b/src/mbgl/shader/outlinepattern_shader.hpp index 6869763412..0fd6882876 100644 --- a/src/mbgl/shader/outlinepattern_shader.hpp +++ b/src/mbgl/shader/outlinepattern_shader.hpp @@ -7,7 +7,7 @@ namespace mbgl { class OutlinePatternShader : public Shader { public: - OutlinePatternShader(gl::ObjectStore&, Defines defines = None); + OutlinePatternShader(gl::Context&, Defines defines = None); void bind(GLbyte *offset) final; diff --git a/src/mbgl/shader/pattern_shader.cpp b/src/mbgl/shader/pattern_shader.cpp index 5caa892feb..dba12155f9 100644 --- a/src/mbgl/shader/pattern_shader.cpp +++ b/src/mbgl/shader/pattern_shader.cpp @@ -5,11 +5,11 @@ namespace mbgl { -PatternShader::PatternShader(gl::ObjectStore& store, Defines defines) +PatternShader::PatternShader(gl::Context& context, Defines defines) : Shader(shaders::pattern::name, shaders::pattern::vertex, shaders::pattern::fragment, - store, defines) { + context, defines) { } void PatternShader::bind(GLbyte *offset) { diff --git a/src/mbgl/shader/pattern_shader.hpp b/src/mbgl/shader/pattern_shader.hpp index ae356fdfb7..1710806141 100644 --- a/src/mbgl/shader/pattern_shader.hpp +++ b/src/mbgl/shader/pattern_shader.hpp @@ -7,7 +7,7 @@ namespace mbgl { class PatternShader : public Shader { public: - PatternShader(gl::ObjectStore&, Defines defines = None); + PatternShader(gl::Context&, Defines defines = None); void bind(GLbyte *offset) final; diff --git a/src/mbgl/shader/plain_shader.cpp b/src/mbgl/shader/plain_shader.cpp index 1309c4f14a..7b52ae407a 100644 --- a/src/mbgl/shader/plain_shader.cpp +++ b/src/mbgl/shader/plain_shader.cpp @@ -5,11 +5,11 @@ namespace mbgl { -PlainShader::PlainShader(gl::ObjectStore& store, Defines defines) +PlainShader::PlainShader(gl::Context& context, Defines defines) : Shader(shaders::fill::name, shaders::fill::vertex, shaders::fill::fragment, - store, defines) { + context, defines) { } void PlainShader::bind(GLbyte* offset) { diff --git a/src/mbgl/shader/plain_shader.hpp b/src/mbgl/shader/plain_shader.hpp index a126fa30a9..d08991e594 100644 --- a/src/mbgl/shader/plain_shader.hpp +++ b/src/mbgl/shader/plain_shader.hpp @@ -8,7 +8,7 @@ namespace mbgl { class PlainShader : public Shader { public: - PlainShader(gl::ObjectStore&, Defines defines = None); + PlainShader(gl::Context&, Defines defines = None); void bind(GLbyte *offset) final; diff --git a/src/mbgl/shader/raster_shader.cpp b/src/mbgl/shader/raster_shader.cpp index 76723b06e9..a83032820e 100644 --- a/src/mbgl/shader/raster_shader.cpp +++ b/src/mbgl/shader/raster_shader.cpp @@ -5,11 +5,11 @@ namespace mbgl { -RasterShader::RasterShader(gl::ObjectStore& store, Defines defines) +RasterShader::RasterShader(gl::Context& context, Defines defines) : Shader(shaders::raster::name, shaders::raster::vertex, shaders::raster::fragment, - store, defines) { + context, defines) { } void RasterShader::bind(GLbyte* offset) { diff --git a/src/mbgl/shader/raster_shader.hpp b/src/mbgl/shader/raster_shader.hpp index 4b3ba9168b..b89b1351c6 100644 --- a/src/mbgl/shader/raster_shader.hpp +++ b/src/mbgl/shader/raster_shader.hpp @@ -7,7 +7,7 @@ namespace mbgl { class RasterShader : public Shader { public: - RasterShader(gl::ObjectStore&, Defines defines = None); + RasterShader(gl::Context&, Defines defines = None); void bind(GLbyte *offset) final; diff --git a/src/mbgl/shader/sdf_shader.cpp b/src/mbgl/shader/sdf_shader.cpp index 5de68e0e40..459a00375c 100644 --- a/src/mbgl/shader/sdf_shader.cpp +++ b/src/mbgl/shader/sdf_shader.cpp @@ -5,11 +5,11 @@ namespace mbgl { -SDFShader::SDFShader(gl::ObjectStore& store, Defines defines) +SDFShader::SDFShader(gl::Context& context, Defines defines) : Shader(shaders::sdf::name, shaders::sdf::vertex, shaders::sdf::fragment, - store, defines) { + context, defines) { } void SDFShader::bind(GLbyte* offset) { diff --git a/src/mbgl/shader/sdf_shader.hpp b/src/mbgl/shader/sdf_shader.hpp index f2f79f1cc9..a6e9d84fa3 100644 --- a/src/mbgl/shader/sdf_shader.hpp +++ b/src/mbgl/shader/sdf_shader.hpp @@ -8,7 +8,7 @@ namespace mbgl { class SDFShader : public Shader { public: - SDFShader(gl::ObjectStore&, Defines defines = None); + SDFShader(gl::Context&, Defines defines = None); UniformMatrix<4> u_matrix = {"u_matrix", *this}; Uniform> u_extrude_scale = {"u_extrude_scale", *this}; diff --git a/src/mbgl/shader/shader.cpp b/src/mbgl/shader/shader.cpp index 34813ac7d6..46b9b0a63e 100644 --- a/src/mbgl/shader/shader.cpp +++ b/src/mbgl/shader/shader.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -15,12 +16,15 @@ namespace mbgl { -Shader::Shader(const char* name_, const char* vertexSource, const char* fragmentSource, gl::ObjectStore& store, Defines defines) - : name(name_) - , program(store.createProgram()) - , vertexShader(store.createShader(GL_VERTEX_SHADER)) - , fragmentShader(store.createShader(GL_FRAGMENT_SHADER)) -{ +Shader::Shader(const char* name_, + const char* vertexSource, + const char* fragmentSource, + gl::Context& context, + Defines defines) + : name(name_), + program(context.createProgram()), + vertexShader(context.createShader(GL_VERTEX_SHADER)), + fragmentShader(context.createShader(GL_FRAGMENT_SHADER)) { util::stopwatch stopwatch("shader compilation", Event::Shader); if (!compileShader(vertexShader, vertexSource)) { diff --git a/src/mbgl/shader/shader.hpp b/src/mbgl/shader/shader.hpp index 620e8f1368..b04c88548d 100644 --- a/src/mbgl/shader/shader.hpp +++ b/src/mbgl/shader/shader.hpp @@ -1,12 +1,16 @@ #pragma once #include -#include +#include #include #include namespace mbgl { +namespace gl { +class Context; +} // namespace gl + class Shader : private util::noncopyable { public: ~Shader(); @@ -27,7 +31,7 @@ protected: Shader(const char* name_, const char* vertex, const char* fragment, - gl::ObjectStore&, + gl::Context&, Defines defines = Defines::None); static constexpr GLint a_pos = 0; diff --git a/src/mbgl/shader/shaders.hpp b/src/mbgl/shader/shaders.hpp index 088e351d37..d2d1d9e621 100644 --- a/src/mbgl/shader/shaders.hpp +++ b/src/mbgl/shader/shaders.hpp @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include @@ -20,21 +19,21 @@ namespace mbgl { class Shaders { public: - Shaders(gl::ObjectStore& store, Shader::Defines defines = Shader::None) - : plain(store, defines), - outline(store, defines), - outlinePattern(store, defines), - line(store, defines), - linesdf(store, defines), - linepattern(store, defines), - pattern(store, defines), - icon(store, defines), - raster(store, defines), - sdfGlyph(store, defines), - sdfIcon(store, defines), - collisionBox(store), - circle(store, defines) - {} + Shaders(gl::Context& context, Shader::Defines defines = Shader::None) + : plain(context, defines), + outline(context, defines), + outlinePattern(context, defines), + line(context, defines), + linesdf(context, defines), + linepattern(context, defines), + pattern(context, defines), + icon(context, defines), + raster(context, defines), + sdfGlyph(context, defines), + sdfIcon(context, defines), + collisionBox(context), + circle(context, defines) { + } PlainShader plain; OutlineShader outline; diff --git a/src/mbgl/sprite/sprite_atlas.cpp b/src/mbgl/sprite/sprite_atlas.cpp index f94943be1a..b17bb7c2ec 100644 --- a/src/mbgl/sprite/sprite_atlas.cpp +++ b/src/mbgl/sprite/sprite_atlas.cpp @@ -282,9 +282,9 @@ void SpriteAtlas::copy(const Holder& holder, const SpritePatternMode mode) { dirtyFlag = true; } -void SpriteAtlas::upload(gl::ObjectStore& objectStore, gl::Context& context, uint32_t unit) { +void SpriteAtlas::upload(gl::Context& context, uint32_t unit) { if (dirtyFlag) { - bind(false, objectStore, context, unit); + bind(false, context, unit); } } @@ -316,13 +316,13 @@ void SpriteAtlas::updateDirty() { dirtySprites.clear(); } -void SpriteAtlas::bind(bool linear, gl::ObjectStore& objectStore, gl::Context& context, uint32_t unit) { +void SpriteAtlas::bind(bool linear, gl::Context& context, uint32_t unit) { if (!data) { return; // Empty atlas } if (!texture) { - texture = objectStore.createTexture(); + texture = context.createTexture(); context.activeTexture = unit; context.texture[unit] = *texture; #ifndef GL_ES_VERSION_2_0 diff --git a/src/mbgl/sprite/sprite_atlas.hpp b/src/mbgl/sprite/sprite_atlas.hpp index 89ae148c30..b4ee5ae48c 100644 --- a/src/mbgl/sprite/sprite_atlas.hpp +++ b/src/mbgl/sprite/sprite_atlas.hpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include #include @@ -83,14 +83,14 @@ public: SpritePatternMode mode = SpritePatternMode::Single); // Binds the atlas texture to the GPU, and uploads data if it is out of date. - void bind(bool linear, gl::ObjectStore&, gl::Context&, uint32_t unit); + void bind(bool linear, gl::Context&, uint32_t unit); // Updates sprites in the atlas texture that may have changed. void updateDirty(); // 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(gl::ObjectStore&, gl::Context&, uint32_t unit); + void upload(gl::Context&, uint32_t unit); dimension getWidth() const { return width; } dimension getHeight() const { return height; } diff --git a/src/mbgl/text/glyph_atlas.cpp b/src/mbgl/text/glyph_atlas.cpp index d5938ec0ed..b5b62062f3 100644 --- a/src/mbgl/text/glyph_atlas.cpp +++ b/src/mbgl/text/glyph_atlas.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include #include #include @@ -204,10 +203,10 @@ void GlyphAtlas::removeGlyphs(uintptr_t tileUID) { } } -void GlyphAtlas::upload(gl::ObjectStore& store, gl::Context& context, uint32_t unit) { +void GlyphAtlas::upload(gl::Context& context, uint32_t unit) { if (dirty) { const bool first = !texture; - bind(store, context, unit); + bind(context, unit); std::lock_guard lock(mtx); @@ -242,9 +241,9 @@ void GlyphAtlas::upload(gl::ObjectStore& store, gl::Context& context, uint32_t u } } -void GlyphAtlas::bind(gl::ObjectStore& store, gl::Context& context, uint32_t unit) { +void GlyphAtlas::bind(gl::Context& context, uint32_t unit) { if (!texture) { - texture = store.createTexture(); + texture = context.createTexture(); context.activeTexture = unit; context.texture[unit] = *texture; #ifndef GL_ES_VERSION_2_0 diff --git a/src/mbgl/text/glyph_atlas.hpp b/src/mbgl/text/glyph_atlas.hpp index 7c901e4989..966ac76f91 100644 --- a/src/mbgl/text/glyph_atlas.hpp +++ b/src/mbgl/text/glyph_atlas.hpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include @@ -61,11 +61,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(gl::ObjectStore&, gl::Context&, uint32_t unit); + void bind(gl::Context&, uint32_t unit); // 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(gl::ObjectStore&, gl::Context&, uint32_t unit); + void upload(gl::Context&, uint32_t unit); const GLsizei width; const GLsizei height; diff --git a/src/mbgl/util/offscreen_texture.cpp b/src/mbgl/util/offscreen_texture.cpp index 404aaaab67..602dd8092a 100644 --- a/src/mbgl/util/offscreen_texture.cpp +++ b/src/mbgl/util/offscreen_texture.cpp @@ -5,18 +5,17 @@ namespace mbgl { -void OffscreenTexture::bind(gl::ObjectStore& store, - gl::Context& context, +void OffscreenTexture::bind(gl::Context& context, std::array size) { assert(size[0] > 0 && size[1] > 0); if (raster.getSize() != size) { raster.load(PremultipliedImage(size[0], size[1], nullptr)); - raster.upload(store, context, 0); + raster.upload(context, 0); } if (!fbo) { - fbo = store.createFBO(); + fbo = context.createFBO(); context.bindFramebuffer = *fbo; MBGL_CHECK_ERROR(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, raster.getID(), 0)); diff --git a/src/mbgl/util/offscreen_texture.hpp b/src/mbgl/util/offscreen_texture.hpp index 3aeab76748..e0a61eb4aa 100644 --- a/src/mbgl/util/offscreen_texture.hpp +++ b/src/mbgl/util/offscreen_texture.hpp @@ -10,7 +10,7 @@ class Context; class OffscreenTexture { public: - void bind(gl::ObjectStore&, gl::Context&, std::array size); + void bind(gl::Context&, std::array size); Raster& getTexture(); std::array getSize() const; diff --git a/src/mbgl/util/raster.cpp b/src/mbgl/util/raster.cpp index 0a98bc4df5..6ed8c62b6d 100644 --- a/src/mbgl/util/raster.cpp +++ b/src/mbgl/util/raster.cpp @@ -31,8 +31,7 @@ void Raster::load(PremultipliedImage image, uint32_t mipmapLevel) { loaded = true; } -void Raster::bind(gl::ObjectStore& store, - gl::Context& context, +void Raster::bind(gl::Context& context, uint32_t unit, Scaling newFilter, MipMap newMipMap) { @@ -43,7 +42,7 @@ void Raster::bind(gl::ObjectStore& store, Log::Error(Event::OpenGL, "trying to bind texture without images"); return; } else { - upload(store, context, unit); + upload(context, unit); filterNeedsUpdate = true; } } else { @@ -71,9 +70,9 @@ void Raster::updateFilter() { filter == Scaling::Linear ? GL_LINEAR : GL_NEAREST)); } -void Raster::upload(gl::ObjectStore& store, gl::Context& context, uint32_t unit) { +void Raster::upload(gl::Context& context, uint32_t unit) { if (!images.empty() && !texture) { - texture = store.createTexture(); + texture = context.createTexture(); context.activeTexture = unit; context.texture[unit] = *texture; updateFilter(); diff --git a/src/mbgl/util/raster.hpp b/src/mbgl/util/raster.hpp index 82f5039a71..9f496484ea 100644 --- a/src/mbgl/util/raster.hpp +++ b/src/mbgl/util/raster.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include @@ -22,14 +22,13 @@ public: void load(PremultipliedImage, uint32_t mipmapLevel = 0); // bind current texture - void bind(gl::ObjectStore&, - gl::Context&, + void bind(gl::Context&, uint32_t unit, Scaling = Scaling::Nearest, MipMap = MipMap::No); // uploads the texture if it hasn't been uploaded yet. - void upload(gl::ObjectStore&, gl::Context&, uint32_t unit); + void upload(gl::Context&, uint32_t unit); // loaded status bool isLoaded() const; diff --git a/test/gl/object.cpp b/test/gl/object.cpp index c70f3ad489..2722669e84 100644 --- a/test/gl/object.cpp +++ b/test/gl/object.cpp @@ -5,7 +5,6 @@ #include #include -#include #include @@ -71,48 +70,48 @@ TEST(GLObject, Store) { mbgl::HeadlessView view(std::make_shared(), 1); view.activate(); - mbgl::gl::ObjectStore store; - EXPECT_TRUE(store.empty()); + mbgl::gl::Context context; + EXPECT_TRUE(context.empty()); - mbgl::gl::UniqueProgram program = store.createProgram(); + mbgl::gl::UniqueProgram program = context.createProgram(); EXPECT_NE(program.get(), 0u); program.reset(); - EXPECT_FALSE(store.empty()); - store.performCleanup(); - EXPECT_TRUE(store.empty()); + EXPECT_FALSE(context.empty()); + context.performCleanup(); + EXPECT_TRUE(context.empty()); - mbgl::gl::UniqueShader shader = store.createShader(GL_VERTEX_SHADER); + mbgl::gl::UniqueShader shader = context.createShader(GL_VERTEX_SHADER); EXPECT_NE(shader.get(), 0u); shader.reset(); - EXPECT_FALSE(store.empty()); - store.performCleanup(); - EXPECT_TRUE(store.empty()); + EXPECT_FALSE(context.empty()); + context.performCleanup(); + EXPECT_TRUE(context.empty()); - mbgl::gl::UniqueBuffer buffer = store.createBuffer(); + mbgl::gl::UniqueBuffer buffer = context.createBuffer(); EXPECT_NE(buffer.get(), 0u); buffer.reset(); - EXPECT_FALSE(store.empty()); - store.performCleanup(); - EXPECT_TRUE(store.empty()); + EXPECT_FALSE(context.empty()); + context.performCleanup(); + EXPECT_TRUE(context.empty()); - mbgl::gl::UniqueTexture texture = store.createTexture(); + mbgl::gl::UniqueTexture texture = context.createTexture(); EXPECT_NE(texture.get(), 0u); texture.reset(); - EXPECT_FALSE(store.empty()); - store.performCleanup(); - EXPECT_FALSE(store.empty()); - store.reset(); - EXPECT_TRUE(store.empty()); + EXPECT_FALSE(context.empty()); + context.performCleanup(); + EXPECT_FALSE(context.empty()); + context.reset(); + EXPECT_TRUE(context.empty()); - mbgl::gl::UniqueVAO vao = store.createVAO(); + mbgl::gl::UniqueVAO vao = context.createVAO(); EXPECT_NE(vao.get(), 0u); vao.reset(); - EXPECT_FALSE(store.empty()); - store.performCleanup(); - EXPECT_TRUE(store.empty()); + EXPECT_FALSE(context.empty()); + context.performCleanup(); + EXPECT_TRUE(context.empty()); - store.reset(); - EXPECT_TRUE(store.empty()); + context.reset(); + EXPECT_TRUE(context.empty()); view.deactivate(); } diff --git a/test/util/offscreen_texture.cpp b/test/util/offscreen_texture.cpp index 64b7608906..2c80c04c41 100644 --- a/test/util/offscreen_texture.cpp +++ b/test/util/offscreen_texture.cpp @@ -68,8 +68,8 @@ TEST(OffscreenTexture, RenderToTexture) { HeadlessView view(1.0f, 512, 256); view.activate(); gl::Context context; - gl::ObjectStore store; - + context.viewport.setDefaultValue(gl::value::Viewport::Get()); + context.bindFramebuffer.setDefaultValue(gl::value::BindFramebuffer::Get()); MBGL_CHECK_ERROR(glEnable(GL_BLEND)); MBGL_CHECK_ERROR(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); @@ -105,7 +105,7 @@ void main() { Buffer triangleBuffer({ 0, 0.5, 0.5, -0.5, -0.5, -0.5 }); Buffer viewportBuffer({ -1, -1, 1, -1, -1, 1, 1, 1 }); - // Make sure the texture gets destructed before we call store.reset(); + // Make sure the texture gets destructed before we call context.reset(); { // First, draw red to the bound FBO. context.clearColor = { 1, 0, 0, 1 }; @@ -114,7 +114,7 @@ void main() { // Then, create a texture, bind it, and render yellow to that texture. This should not // affect the originally bound FBO. OffscreenTexture texture; - texture.bind(store, context, {{ 128, 128 }}); + texture.bind(context, {{ 128, 128 }}); context.clearColor = { 0, 0, 0, 0 }; MBGL_CHECK_ERROR(glClear(GL_COLOR_BUFFER_BIT)); @@ -137,7 +137,7 @@ void main() { // Now, composite the Framebuffer texture we've rendered to onto the main FBO. context.program = compositeShader.program; - texture.getTexture().bind(store, context, 0, Raster::Scaling::Linear); + texture.getTexture().bind(context, 0, Raster::Scaling::Linear); MBGL_CHECK_ERROR(glUniform1i(u_texture, 0)); MBGL_CHECK_ERROR(glBindBuffer(GL_ARRAY_BUFFER, viewportBuffer.buffer)); MBGL_CHECK_ERROR(glEnableVertexAttribArray(compositeShader.a_pos)); @@ -149,5 +149,5 @@ void main() { test::checkImage("test/fixtures/offscreen_texture/render-to-fbo-composited", image, 0, 0.1); } - store.reset(); + context.reset(); } -- cgit v1.2.1