blob: 83c2fed00b0e3027fc35f8935b2b380692faf045 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#include <mbgl/map/backend.hpp>
#include <mbgl/map/backend_scope.hpp>
#include <mbgl/gl/context.hpp>
#include <mbgl/gl/extension.hpp>
#include <mbgl/gl/debugging.hpp>
#include <cassert>
namespace mbgl {
Backend::Backend() = default;
gl::Context& Backend::getContext() {
assert(BackendScope::exists());
std::call_once(initialized, [this] {
context = std::make_unique<gl::Context>();
context->enableDebugging();
context->initializeExtensions(
std::bind(&Backend::initializeExtension, this, std::placeholders::_1));
});
return *context;
}
PremultipliedImage Backend::readFramebuffer(const Size& size) const {
assert(context);
return context->readFramebuffer<PremultipliedImage>(size);
}
void Backend::assumeFramebufferBinding(const gl::FramebufferID fbo) {
getContext().bindFramebuffer.setCurrentValue(fbo);
if (fbo != ImplicitFramebufferBinding) {
assert(gl::value::BindFramebuffer::Get() == getContext().bindFramebuffer.getCurrentValue());
}
}
void Backend::assumeViewport(int32_t x, int32_t y, const Size& size) {
getContext().viewport.setCurrentValue({ x, y, size });
assert(gl::value::Viewport::Get() == getContext().viewport.getCurrentValue());
}
void Backend::assumeScissorTest(bool enabled) {
getContext().scissorTest.setCurrentValue(enabled);
assert(gl::value::ScissorTest::Get() == getContext().scissorTest.getCurrentValue());
}
bool Backend::implicitFramebufferBound() {
return getContext().bindFramebuffer.getCurrentValue() == ImplicitFramebufferBinding;
}
void Backend::setFramebufferBinding(const gl::FramebufferID fbo) {
getContext().bindFramebuffer = fbo;
if (fbo != ImplicitFramebufferBinding) {
assert(gl::value::BindFramebuffer::Get() == getContext().bindFramebuffer.getCurrentValue());
}
}
void Backend::setViewport(int32_t x, int32_t y, const Size& size) {
getContext().viewport = { x, y, size };
assert(gl::value::Viewport::Get() == getContext().viewport.getCurrentValue());
}
void Backend::setScissorTest(bool enabled) {
getContext().scissorTest = enabled;
assert(gl::value::ScissorTest::Get() == getContext().scissorTest.getCurrentValue());
}
Backend::~Backend() = default;
} // namespace mbgl
|