forked from maplibre/maplibre-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
glfw_renderer_frontend.cpp
47 lines (36 loc) · 1.46 KB
/
glfw_renderer_frontend.cpp
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
#include "glfw_renderer_frontend.hpp"
#include <mbgl/renderer/renderer.hpp>
#include <mbgl/gfx/backend_scope.hpp>
GLFWRendererFrontend::GLFWRendererFrontend(std::unique_ptr<mbgl::Renderer> renderer_, GLFWView& glfwView_)
: glfwView(glfwView_)
, renderer(std::move(renderer_)) {
glfwView.setRenderFrontend(this);
}
GLFWRendererFrontend::~GLFWRendererFrontend() = default;
void GLFWRendererFrontend::reset() {
assert(renderer);
renderer.reset();
}
void GLFWRendererFrontend::setObserver(mbgl::RendererObserver& observer) {
assert(renderer);
renderer->setObserver(&observer);
}
void GLFWRendererFrontend::update(std::shared_ptr<mbgl::UpdateParameters> params) {
updateParameters = std::move(params);
glfwView.invalidate();
}
void GLFWRendererFrontend::render() {
assert(renderer);
if (!updateParameters) return;
mbgl::gfx::BackendScope guard { glfwView.getRendererBackend(), mbgl::gfx::BackendScope::ScopeType::Implicit };
// onStyleImageMissing might be called during a render. The user implemented method
// could trigger a call to MGLRenderFrontend#update which overwrites `updateParameters`.
// Copy the shared pointer here so that the parameters aren't destroyed while `render(...)` is
// still using them.
auto updateParameters_ = updateParameters;
renderer->render(updateParameters_);
}
mbgl::Renderer* GLFWRendererFrontend::getRenderer() {
assert(renderer);
return renderer.get();
}