-
-
Notifications
You must be signed in to change notification settings - Fork 338
/
Copy pathrenderer_backend.hpp
82 lines (62 loc) · 2.14 KB
/
renderer_backend.hpp
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
#pragma once
#include <mbgl/util/util.hpp>
#include <memory>
#include <mutex>
namespace mbgl {
class ProgramParameters;
namespace gfx {
class BackendScope;
class Context;
class Renderable;
class ShaderRegistry;
// We can make some optimizations if we know that the drawing context is not shared with other code.
enum class ContextMode : bool {
Unique,
Shared,
};
class RendererBackend {
protected:
explicit RendererBackend(ContextMode);
public:
virtual ~RendererBackend();
RendererBackend(const RendererBackend&) = delete;
RendererBackend& operator=(const RendererBackend&) = delete;
/// Returns the device's context.
Context& getContext();
template <typename T>
T& getContext() {
return static_cast<T&>(getContext());
}
bool contextIsShared() const { return contextMode == ContextMode::Shared; }
/// Returns a reference to the default surface that should be rendered on.
virtual Renderable& getDefaultRenderable() = 0;
#if MLN_DRAWABLE_RENDERER
/// One-time shader initialization
virtual void initShaders(gfx::ShaderRegistry&, const ProgramParameters&) = 0;
#endif
protected:
virtual std::unique_ptr<Context> createContext() = 0;
/// Called when the backend's GL context needs to be made active or
/// inactive. These are called, as a matched pair, exclusively through
/// BackendScope, in two situations:
///
/// 1. When releasing GL resources during Renderer destruction
/// (Including calling CustomLayerHost::deinitialize during
/// RenderCustomLayer destruction)
/// 2. When renderering through Renderer::render()
/// (Including calling CustomLayerHost::initialize for newly added
/// custom layers and
/// CustomLayerHost::deinitialize on layer removal)
virtual void activate() = 0;
virtual void deactivate() = 0;
protected:
std::unique_ptr<Context> context;
const ContextMode contextMode;
std::once_flag initialized;
friend class BackendScope;
};
constexpr bool operator==(const RendererBackend& a, const RendererBackend& b) {
return &a == &b;
}
} // namespace gfx
} // namespace mbgl