[core] merge gl::ObjectStore into gl::Context

This commit is contained in:
Konstantin Käfer
2016-09-27 17:52:14 +02:00
committed by John Firebaugh
parent ce42d22984
commit 44c7e9d05e
76 changed files with 556 additions and 581 deletions

View File

@@ -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

View File

@@ -1,7 +1,6 @@
#pragma once
#include <mbgl/gl/gl.hpp>
#include <mbgl/gl/object_store.hpp>
#include <mbgl/gl/context.hpp>
#include <mbgl/platform/log.hpp>
#include <mbgl/util/noncopyable.hpp>
@@ -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);
}
}

View File

@@ -1,6 +1,5 @@
#include <mbgl/geometry/line_atlas.hpp>
#include <mbgl/gl/gl.hpp>
#include <mbgl/gl/object_store.hpp>
#include <mbgl/gl/context.hpp>
#include <mbgl/platform/log.hpp>
#include <mbgl/platform/platform.hpp>
@@ -121,16 +120,16 @@ LinePatternPos LineAtlas::addDash(const std::vector<float>& 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));

View File

@@ -1,11 +1,12 @@
#pragma once
#include <mbgl/gl/gl.hpp>
#include <mbgl/gl/object_store.hpp>
#include <mbgl/gl/object.hpp>
#include <mbgl/util/optional.hpp>
#include <vector>
#include <unordered_map>
#include <memory>
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<float>&, LinePatternCap);
LinePatternPos addDash(const std::vector<float>& dasharray, LinePatternCap);

View File

@@ -1,6 +1,5 @@
#include <mbgl/geometry/vao.hpp>
#include <mbgl/platform/log.hpp>
#include <mbgl/gl/object_store.hpp>
#include <mbgl/util/string.hpp>
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();
}

View File

@@ -2,7 +2,6 @@
#include <mbgl/shader/shader.hpp>
#include <mbgl/gl/gl.hpp>
#include <mbgl/gl/object_store.hpp>
#include <mbgl/gl/context.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/optional.hpp>
@@ -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);

95
src/mbgl/gl/context.cpp Normal file
View File

@@ -0,0 +1,95 @@
#include <mbgl/gl/context.hpp>
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 <typename Fn>
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

View File

@@ -1,79 +1,81 @@
#pragma once
#include <mbgl/gl/object.hpp>
#include <mbgl/gl/state.hpp>
#include <mbgl/gl/value.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <memory>
#include <vector>
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();
}
vertexBuffer.setDirty();
elementBuffer.setDirty();
vertexArrayObject.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()));
}
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<value::StencilFunc> stencilFunc;
State<value::StencilMask> stencilMask;
State<value::StencilTest> stencilTest;
@@ -102,6 +104,23 @@ public:
State<value::BindBuffer<GL_ARRAY_BUFFER>> vertexBuffer;
State<value::BindBuffer<GL_ELEMENT_ARRAY_BUFFER>> elementBuffer;
State<value::BindVAO> vertexArrayObject;
private:
friend detail::ProgramDeleter;
friend detail::ShaderDeleter;
friend detail::BufferDeleter;
friend detail::TextureDeleter;
friend detail::VAODeleter;
friend detail::FBODeleter;
std::vector<GLuint> pooledTextures;
std::vector<GLuint> abandonedPrograms;
std::vector<GLuint> abandonedShaders;
std::vector<GLuint> abandonedBuffers;
std::vector<GLuint> abandonedTextures;
std::vector<GLuint> abandonedVAOs;
std::vector<GLuint> abandonedFBOs;
};
} // namespace gl

46
src/mbgl/gl/object.cpp Normal file
View File

@@ -0,0 +1,46 @@
#include <mbgl/gl/object.hpp>
#include <mbgl/gl/context.hpp>
#include <cassert>
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

54
src/mbgl/gl/object.hpp Normal file
View File

@@ -0,0 +1,54 @@
#pragma once
#include <mbgl/gl/gl.hpp>
#include <unique_resource.hpp>
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<GLuint, detail::ProgramDeleter>;
using UniqueShader = std_experimental::unique_resource<GLuint, detail::ShaderDeleter>;
using UniqueBuffer = std_experimental::unique_resource<GLuint, detail::BufferDeleter>;
using UniqueTexture = std_experimental::unique_resource<GLuint, detail::TextureDeleter>;
using UniqueVAO = std_experimental::unique_resource<GLuint, detail::VAODeleter>;
using UniqueFBO = std_experimental::unique_resource<GLuint, detail::FBODeleter>;
} // namespace gl
} // namespace mbgl

View File

@@ -1,91 +0,0 @@
#include <mbgl/gl/object_store.hpp>
#include <cassert>
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

View File

@@ -1,134 +0,0 @@
#pragma once
#include <mbgl/gl/gl.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <unique_resource.hpp>
#include <algorithm>
#include <memory>
#include <vector>
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<GLuint, ProgramDeleter>;
using UniqueShader = std_experimental::unique_resource<GLuint, ShaderDeleter>;
using UniqueBuffer = std_experimental::unique_resource<GLuint, BufferDeleter>;
using UniqueTexture = std_experimental::unique_resource<GLuint, TextureDeleter>;
using UniqueVAO = std_experimental::unique_resource<GLuint, VAODeleter>;
using UniqueFBO = std_experimental::unique_resource<GLuint, FBODeleter>;
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<GLuint> pooledTextures;
std::vector<GLuint> abandonedPrograms;
std::vector<GLuint> abandonedShaders;
std::vector<GLuint> abandonedBuffers;
std::vector<GLuint> abandonedTextures;
std::vector<GLuint> abandonedVAOs;
std::vector<GLuint> abandonedFBOs;
};
} // namespace gl
} // namespace mbgl

View File

@@ -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;
}

View File

@@ -15,7 +15,6 @@
#include <mbgl/storage/file_source.hpp>
#include <mbgl/storage/resource.hpp>
#include <mbgl/storage/response.hpp>
#include <mbgl/gl/object_store.hpp>
#include <mbgl/util/projection.hpp>
#include <mbgl/util/math.hpp>
#include <mbgl/util/exception.hpp>
@@ -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<Painter>(transform.getState(), store);
painter = std::make_unique<Painter>(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&) {

View File

@@ -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).

View File

@@ -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));

View File

@@ -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_;

View File

@@ -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())));
}
}

View File

@@ -11,7 +11,6 @@ class OverscaledTileID;
class PlainShader;
namespace gl {
class ObjectStore;
class Context;
} // namespace gl
@@ -24,8 +23,8 @@ public:
optional<Timestamp> 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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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

View File

@@ -3,7 +3,7 @@
#include <array>
#include <mbgl/platform/platform.hpp>
#include <mbgl/gl/object_store.hpp>
#include <mbgl/gl/object.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/optional.hpp>
@@ -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;

View File

@@ -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;

View File

@@ -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 {

View File

@@ -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<Shaders>(store);
shaders = std::make_unique<Shaders>(context);
#ifndef NDEBUG
overdrawShaders = std::make_unique<Shaders>(store, Shader::Overdraw);
overdrawShaders = std::make_unique<Shaders>(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);
}
}
}

View File

@@ -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<float, 2> 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;

View File

@@ -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;

View File

@@ -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

View File

@@ -26,7 +26,7 @@ void Painter::drawClippingMasks(PaintParameters& parameters, const std::map<Unwr
context.colorMask = { GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE };
context.stencilMask = mask;
arrayCoveringPlain.bind(plainShader, tileStencilBuffer, BUFFER_OFFSET_0, store, context);
arrayCoveringPlain.bind(plainShader, tileStencilBuffer, BUFFER_OFFSET_0, context);
for (const auto& stencil : stencils) {
const auto& id = stencil.first;

View File

@@ -46,18 +46,18 @@ void Painter::renderDebugText(Tile& tile, const mat4 &matrix) {
// Draw white outline
plainShader.u_color = Color::white();
context.lineWidth = 4.0f * frame.pixelRatio;
tile.debugBucket->drawLines(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()));

View File

@@ -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());
}
}

View File

@@ -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<SpriteAtlasPosition> 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());
}
}

View File

@@ -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);
}
}

View File

@@ -20,7 +20,7 @@ void Painter::renderSDF(SymbolBucket& bucket,
float sdfFontSize,
std::array<float, 2> 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);
}
}

View File

@@ -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()));
}

View File

@@ -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;
};

View File

@@ -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));
}
}

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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) {

View File

@@ -8,7 +8,7 @@ namespace mbgl {
class CollisionBoxShader : public Shader {
public:
CollisionBoxShader(gl::ObjectStore&);
CollisionBoxShader(gl::Context&);
void bind(GLbyte *offset) final;

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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<std::array<GLfloat, 2>> u_extrude_scale = {"u_extrude_scale", *this};

View File

@@ -1,5 +1,6 @@
#include <mbgl/shader/shader.hpp>
#include <mbgl/gl/gl.hpp>
#include <mbgl/gl/context.hpp>
#include <mbgl/util/stopwatch.hpp>
#include <mbgl/util/exception.hpp>
#include <mbgl/platform/log.hpp>
@@ -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)) {

View File

@@ -1,12 +1,16 @@
#pragma once
#include <mbgl/gl/gl.hpp>
#include <mbgl/gl/object_store.hpp>
#include <mbgl/gl/object.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/optional.hpp>
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;

View File

@@ -1,7 +1,6 @@
#pragma once
#include <mbgl/gl/gl.hpp>
#include <mbgl/gl/object_store.hpp>
#include <mbgl/shader/pattern_shader.hpp>
#include <mbgl/shader/plain_shader.hpp>
@@ -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;

View File

@@ -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

View File

@@ -2,7 +2,7 @@
#include <mbgl/geometry/binpack.hpp>
#include <mbgl/gl/gl.hpp>
#include <mbgl/gl/object_store.hpp>
#include <mbgl/gl/object.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/optional.hpp>
#include <mbgl/sprite/sprite_image.hpp>
@@ -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; }

View File

@@ -2,7 +2,6 @@
#include <mbgl/text/glyph_atlas_observer.hpp>
#include <mbgl/text/glyph_pbf.hpp>
#include <mbgl/gl/gl.hpp>
#include <mbgl/gl/object_store.hpp>
#include <mbgl/gl/context.hpp>
#include <mbgl/platform/log.hpp>
#include <mbgl/platform/platform.hpp>
@@ -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<std::mutex> 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

View File

@@ -9,7 +9,7 @@
#include <mbgl/util/exclusive.hpp>
#include <mbgl/util/work_queue.hpp>
#include <mbgl/gl/gl.hpp>
#include <mbgl/gl/object_store.hpp>
#include <mbgl/gl/object.hpp>
#include <atomic>
#include <string>
@@ -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;

View File

@@ -5,18 +5,17 @@
namespace mbgl {
void OffscreenTexture::bind(gl::ObjectStore& store,
gl::Context& context,
void OffscreenTexture::bind(gl::Context& context,
std::array<uint16_t, 2> 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));

View File

@@ -10,7 +10,7 @@ class Context;
class OffscreenTexture {
public:
void bind(gl::ObjectStore&, gl::Context&, std::array<uint16_t, 2> size);
void bind(gl::Context&, std::array<uint16_t, 2> size);
Raster& getTexture();
std::array<uint16_t, 2> getSize() const;

View File

@@ -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();

View File

@@ -1,6 +1,6 @@
#pragma once
#include <mbgl/gl/object_store.hpp>
#include <mbgl/gl/object.hpp>
#include <mbgl/util/image.hpp>
#include <mbgl/util/optional.hpp>
@@ -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;

View File

@@ -5,7 +5,6 @@
#include <mbgl/gl/gl.hpp>
#include <mbgl/gl/context.hpp>
#include <mbgl/gl/object_store.hpp>
#include <memory>
@@ -71,48 +70,48 @@ TEST(GLObject, Store) {
mbgl::HeadlessView view(std::make_shared<mbgl::HeadlessDisplay>(), 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();
}

View File

@@ -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();
}