diff options
author | Thomas Moenicke <thomas.moenicke@mapbox.com> | 2020-02-03 19:10:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-03 19:10:57 +0200 |
commit | b64ed754442b894f3914a4191798fbd2f2bc8cd9 (patch) | |
tree | 59bb14829d7cdd5f2466dad4cffb74c4d1b80068 /include/mbgl/gl | |
parent | 2e10d3548a8b3aff1f28b9514594c3c14509f084 (diff) | |
download | qtlocation-mapboxgl-b64ed754442b894f3914a4191798fbd2f2bc8cd9.tar.gz |
[build] Adding a build flag to build without GL if needed (#16120)
* [build] Adding a build flag to build without GL if needed
* [build] Moving custom layer to mbgl/gl
Diffstat (limited to 'include/mbgl/gl')
-rw-r--r-- | include/mbgl/gl/custom_layer.hpp | 88 | ||||
-rw-r--r-- | include/mbgl/gl/custom_layer_factory.hpp | 17 |
2 files changed, 105 insertions, 0 deletions
diff --git a/include/mbgl/gl/custom_layer.hpp b/include/mbgl/gl/custom_layer.hpp new file mode 100644 index 0000000000..5dce484980 --- /dev/null +++ b/include/mbgl/gl/custom_layer.hpp @@ -0,0 +1,88 @@ +#pragma once + +#include <mbgl/style/layer.hpp> + +#include <array> + +namespace mbgl { +namespace style { + +/** + * Parameters that define the current camera position for a `CustomLayerHost::render()` function. + */ +struct CustomLayerRenderParameters { + double width; + double height; + double latitude; + double longitude; + double zoom; + double bearing; + double pitch; + double fieldOfView; + std::array<double, 16> projectionMatrix; +}; + +class CustomLayerHost { +public: + virtual ~CustomLayerHost() = default; + /** + * Initialize any GL state needed by the custom layer. This method is called once, from the + * main thread, at a point when the GL context is active but before rendering for the first + * time. + * + * Resources that are acquired in this method must be released in the `deinitialize` function. + */ + virtual void initialize() = 0; + + /** + * Render the layer. This method is called once per frame. The implementation should not make + * any assumptions about the GL state (other than that the correct context is active). It may + * make changes to the state, and is not required to reset values such as the depth mask, stencil + * mask, and corresponding test flags to their original values. + * Make sure that you are drawing your fragments with a z value of 1 to take advantage of the + * opaque fragment culling in case there are opaque layers above your custom layer. + */ + virtual void render(const CustomLayerRenderParameters&) = 0; + + /** + * Called when the system has destroyed the underlying GL context. The + * `deinitialize` function will not be called in this case, however + * `initialize` will be called instead to prepare for a new render. + * + */ + virtual void contextLost() = 0; + + /** + * Destroy any GL state needed by the custom layer, and deallocate context, if necessary. This + * method is called once, from the main thread, at a point when the GL context is active. + * + * Note that it may be called even when the `initialize` function has not been called. + */ + virtual void deinitialize() = 0; +}; + +class CustomLayer : public Layer { +public: + CustomLayer(const std::string& id, + std::unique_ptr<CustomLayerHost> host); + + ~CustomLayer() final; + + // Dynamic properties + optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value) final; + StyleProperty getProperty(const std::string&) const final; + // Private implementation + + class Impl; + const Impl& impl() const; + + Mutable<Impl> mutableImpl() const; + std::unique_ptr<Layer> cloneRef(const std::string& id) const final; + + CustomLayer(const CustomLayer&) = delete; + + Mutable<Layer::Impl> mutableBaseImpl() const final; +}; + +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/gl/custom_layer_factory.hpp b/include/mbgl/gl/custom_layer_factory.hpp new file mode 100644 index 0000000000..963a3dc2fd --- /dev/null +++ b/include/mbgl/gl/custom_layer_factory.hpp @@ -0,0 +1,17 @@ +#pragma once + +#include <mbgl/layermanager/layer_factory.hpp> +#include <mbgl/style/layer.hpp> + +#include <array> + +namespace mbgl { + +class CustomLayerFactory : public LayerFactory { +protected: + const style::LayerTypeInfo* getTypeInfo() const noexcept final; + std::unique_ptr<style::Layer> createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept final; + std::unique_ptr<RenderLayer> createRenderLayer(Immutable<style::Layer::Impl>) noexcept final; +}; + +} // namespace mbgl |