[core] custom layer - add contextLost callback
- optional callback method that can be used to do cleanup when the context has been lost before re-initialisation
This commit is contained in:
committed by
Ivo van Dongen
parent
b0c06c764b
commit
97a010cc9b
@@ -38,6 +38,14 @@ struct CustomLayerRenderParameters {
|
||||
*/
|
||||
using CustomLayerRenderFunction = void (*)(void* context, const CustomLayerRenderParameters&);
|
||||
|
||||
/**
|
||||
* Called when the system has destroyed the underlying GL context. The
|
||||
* `CustomLayerDeinitializeFunction` will not be called in this case, however
|
||||
* `CustomLayerInitializeFunction` will be called instead to prepare for a new render.
|
||||
*
|
||||
*/
|
||||
using CustomLayerContextLostFunction = void (*)(void* context);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@@ -51,8 +59,16 @@ public:
|
||||
CustomLayer(const std::string& id,
|
||||
CustomLayerInitializeFunction,
|
||||
CustomLayerRenderFunction,
|
||||
CustomLayerContextLostFunction,
|
||||
CustomLayerDeinitializeFunction,
|
||||
void* context);
|
||||
|
||||
CustomLayer(const std::string& id,
|
||||
CustomLayerInitializeFunction,
|
||||
CustomLayerRenderFunction,
|
||||
CustomLayerDeinitializeFunction,
|
||||
void* context);
|
||||
|
||||
~CustomLayer() final;
|
||||
|
||||
// Visibility
|
||||
|
||||
@@ -16,8 +16,12 @@ RenderCustomLayer::RenderCustomLayer(Immutable<style::CustomLayer::Impl> _impl)
|
||||
|
||||
RenderCustomLayer::~RenderCustomLayer() {
|
||||
assert(BackendScope::exists());
|
||||
if (initialized && !contextDestroyed && impl().deinitializeFn) {
|
||||
impl().deinitializeFn(impl().context);
|
||||
if (initialized) {
|
||||
if (contextDestroyed && impl().contextLostFn ) {
|
||||
impl().contextLostFn(impl().context);
|
||||
} else if (!contextDestroyed && impl().deinitializeFn) {
|
||||
impl().deinitializeFn(impl().context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,9 +8,18 @@ namespace style {
|
||||
CustomLayer::CustomLayer(const std::string& layerID,
|
||||
CustomLayerInitializeFunction init,
|
||||
CustomLayerRenderFunction render,
|
||||
CustomLayerContextLostFunction contextLost,
|
||||
CustomLayerDeinitializeFunction deinit,
|
||||
void* context)
|
||||
: Layer(makeMutable<Impl>(layerID, init, render, deinit, context)) {
|
||||
: Layer(makeMutable<Impl>(layerID, init, render, contextLost, deinit, context)) {
|
||||
}
|
||||
|
||||
CustomLayer::CustomLayer(const std::string& layerID,
|
||||
CustomLayerInitializeFunction init,
|
||||
CustomLayerRenderFunction render,
|
||||
CustomLayerDeinitializeFunction deinit,
|
||||
void* context)
|
||||
: Layer(makeMutable<Impl>(layerID, init, render, nullptr, deinit, context)) {
|
||||
}
|
||||
|
||||
CustomLayer::~CustomLayer() = default;
|
||||
|
||||
@@ -6,12 +6,14 @@ namespace style {
|
||||
CustomLayer::Impl::Impl(const std::string& id_,
|
||||
CustomLayerInitializeFunction initializeFn_,
|
||||
CustomLayerRenderFunction renderFn_,
|
||||
CustomLayerContextLostFunction contextLostFn_,
|
||||
CustomLayerDeinitializeFunction deinitializeFn_,
|
||||
void* context_)
|
||||
: Layer::Impl(LayerType::Custom, id_, std::string()) {
|
||||
initializeFn = initializeFn_;
|
||||
renderFn = renderFn_;
|
||||
deinitializeFn = deinitializeFn_;
|
||||
contextLostFn = contextLostFn_;
|
||||
context = context_;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ public:
|
||||
Impl(const std::string& id,
|
||||
CustomLayerInitializeFunction,
|
||||
CustomLayerRenderFunction,
|
||||
CustomLayerContextLostFunction,
|
||||
CustomLayerDeinitializeFunction,
|
||||
void* context);
|
||||
|
||||
@@ -22,6 +23,7 @@ public:
|
||||
|
||||
CustomLayerInitializeFunction initializeFn = nullptr;
|
||||
CustomLayerRenderFunction renderFn = nullptr;
|
||||
CustomLayerContextLostFunction contextLostFn = nullptr;
|
||||
CustomLayerDeinitializeFunction deinitializeFn = nullptr;
|
||||
void* context = nullptr;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user