blob: 410a408d1b7430f0fb3871b474f8a5366ac175f6 (
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
#include <mbgl/renderer/layers/render_custom_layer.hpp>
#include <mbgl/renderer/paint_parameters.hpp>
#include <mbgl/renderer/backend_scope.hpp>
#include <mbgl/renderer/renderer_backend.hpp>
#include <mbgl/renderer/bucket.hpp>
#include <mbgl/style/layers/custom_layer_impl.hpp>
#include <mbgl/map/transform_state.hpp>
namespace mbgl {
using namespace style;
RenderCustomLayer::RenderCustomLayer(Immutable<style::CustomLayer::Impl> _impl)
: RenderLayer(LayerType::Custom, _impl) {
}
RenderCustomLayer::~RenderCustomLayer() {
assert(BackendScope::exists());
if (initialized && impl().context) {
if (contextDestroyed) {
impl().context->lost();
}
else {
impl().context->deinitialize();
}
impl().context->detach();
// if (contextDestroyed && impl().contextLostFn ) {
// impl().contextLostFn(impl().context);
// } else if (!contextDestroyed && impl().deinitializeFn) {
// impl().deinitializeFn(impl().context);
// }
//
// impl().detachFn(impl().context);
}
}
const CustomLayer::Impl& RenderCustomLayer::impl() const {
return static_cast<const CustomLayer::Impl&>(*baseImpl);
}
void RenderCustomLayer::evaluate(const PropertyEvaluationParameters&) {
passes = RenderPass::Translucent;
}
bool RenderCustomLayer::hasTransition() const {
return false;
}
std::unique_ptr<Bucket> RenderCustomLayer::createBucket(const BucketParameters&, const std::vector<const RenderLayer*>&) const {
assert(false);
return nullptr;
}
void RenderCustomLayer::render(PaintParameters& paintParameters, RenderSource*) {
if (context != impl().context || !initialized) {
if (!contextDestroyed && context) {
context->deinitialize();
context->detach();
}
context = impl().context;
if (context) {
context->attach();
context->initialize();
}
initialized = true;
}
gl::Context& glContext = paintParameters.context;
const TransformState& state = paintParameters.state;
// Reset GL state to a known state so the CustomLayer always has a clean slate.
glContext.bindVertexArray = 0;
glContext.setDepthMode(paintParameters.depthModeForSublayer(0, gl::DepthMode::ReadOnly));
glContext.setStencilMode(gl::StencilMode::disabled());
glContext.setColorMode(paintParameters.colorModeForRenderPass());
CustomLayerRenderParameters parameters;
parameters.width = state.getSize().width;
parameters.height = state.getSize().height;
parameters.latitude = state.getLatLng().latitude();
parameters.longitude = state.getLatLng().longitude();
parameters.zoom = state.getZoom();
parameters.bearing = -state.getAngle() * util::RAD2DEG;
parameters.pitch = state.getPitch();
parameters.fieldOfView = state.getFieldOfView();
// assert(impl().renderFn);
context->render(parameters);
// impl().renderFn(context, parameters);
// Reset the view back to our original one, just in case the CustomLayer changed
// the viewport or Framebuffer.
paintParameters.backend.bind();
glContext.setDirtyState();
}
} // namespace mbgl
|