* [ios, macos] Replaced custom style layer API with MGLOpenGLStyleLayer Replaced the custom style layer API on MGLMapView with an equally unsupported MGLOpenGLStyleLayer API that nonetheless is consistent with the broader runtime styling API and is compatible with macOS. Fixed an unrecognized selector crash when wrapping a layer of unrecognized type coming from mbgl. * [macos] Added lime green layer demo to macosapp Reprised the demo removed from iosapp in #5091. * [ios, macos] Rationalized MGLOpenGLStyleLayer API MGLStyle now strongly references any MGLOpenGLStyleLayer object that’s added to it, in order to prevent pointers from going stale and make it easy for layer drawing code to get more information about the map view. Replaced the MGLOpenGLStyleLayer callback blocks with overridable instance methods. Added internal documentation for each method. Subclassed MGLOpenGLStyleLayer as LimeGreenStyleLayer inside macosapp. Consolidated -addToMapView: into -addToMapView:belowLayer: to ensure that MGLRedundantLayerException gets raised even if the layer is being inserted rather than added to the bottom of the stack. * [core] Clarified that rendering happens on the main thread * [ios, macos] Fixed removing and re-adding MGLOpenGLStyleLayer Don’t allow index-based layer removal to circumvent -removeFromMapView:, which MGLOpenGLStyleLayer relies on to synchronize the style’s array of MGLOpenGLStyleLayers. When obtaining an MGLOpenGLStyleLayer, get the instance already added to the style instead of creating a new one to wrap the underlying CustomLayer.
74 lines
2.2 KiB
C++
74 lines
2.2 KiB
C++
#pragma once
|
|
|
|
#include <mbgl/style/layer.hpp>
|
|
|
|
namespace mbgl {
|
|
namespace style {
|
|
|
|
/**
|
|
* 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 UninitializeFunction.
|
|
*/
|
|
using CustomLayerInitializeFunction = void (*)(void* context);
|
|
|
|
/**
|
|
* Parameters that define the current camera position for a CustomLayerRenderFunction.
|
|
*/
|
|
struct CustomLayerRenderParameters {
|
|
double width;
|
|
double height;
|
|
double latitude;
|
|
double longitude;
|
|
double zoom;
|
|
double bearing;
|
|
double pitch;
|
|
double altitude;
|
|
};
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
using CustomLayerRenderFunction = void (*)(void* context, const CustomLayerRenderParameters&);
|
|
|
|
/**
|
|
* 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 InitializeFunction has not been called.
|
|
*/
|
|
using CustomLayerDeinitializeFunction = void (*)(void* context);
|
|
|
|
class CustomLayer : public Layer {
|
|
public:
|
|
CustomLayer(const std::string& id,
|
|
CustomLayerInitializeFunction,
|
|
CustomLayerRenderFunction,
|
|
CustomLayerDeinitializeFunction,
|
|
void* context);
|
|
~CustomLayer() final;
|
|
|
|
// Private implementation
|
|
|
|
class Impl;
|
|
Impl* impl;
|
|
|
|
CustomLayer(const Impl&);
|
|
CustomLayer(const CustomLayer&) = delete;
|
|
};
|
|
|
|
template <>
|
|
inline bool Layer::is<CustomLayer>() const {
|
|
return type == Type::Custom;
|
|
}
|
|
|
|
} // namespace style
|
|
} // namespace mbgl
|