Add EventHandle to manage smartptr based events more conveniently
This commit is contained in:
@@ -18,7 +18,6 @@ namespace OpenVulkano::Scene
|
||||
|
||||
ArBackgroundDrawable::ArBackgroundDrawable(const Ptr<AR::ArSession>& arSession)
|
||||
: Drawable(DrawEncoder::GetDrawEncoder<ArBackgroundDrawable>(), DrawPhase::BACKGROUND)
|
||||
, m_arSession(arSession)
|
||||
{
|
||||
m_shader.topology = Topology::TRIANGLE_STRIP;
|
||||
m_shader.AddShaderProgram(ShaderProgramType::VERTEX, "Shader/background");
|
||||
@@ -29,27 +28,21 @@ namespace OpenVulkano::Scene
|
||||
SetShader(&m_shader);
|
||||
m_intrinsicsBuffer.Init(sizeof(Math::CameraIntrinsicWithResolution), &FALLBACK_INTRINSICS);
|
||||
m_intrinsicsBuffer.updateFrequency = UpdateFrequency::Always;
|
||||
if (m_arSession)
|
||||
m_arSession->OnNewFrame += EventHandler(this, &ArBackgroundDrawable::OnNewArFrame);
|
||||
Init(arSession);
|
||||
}
|
||||
|
||||
void ArBackgroundDrawable::Init(const Ptr<AR::ArSession>& arSession)
|
||||
{
|
||||
if (m_arSession)
|
||||
{
|
||||
if (m_arSession == arSession) return;
|
||||
Close();
|
||||
}
|
||||
if (m_eventHandle) Close();
|
||||
if (!arSession) return;
|
||||
m_arSession = arSession;
|
||||
m_arSession->OnNewFrame += EventHandler(this, &ArBackgroundDrawable::OnNewArFrame);
|
||||
m_eventHandle = { arSession, &AR::ArSession::OnNewFrame, EventHandler(this, &ArBackgroundDrawable::OnNewArFrame) };
|
||||
}
|
||||
|
||||
void ArBackgroundDrawable::Close()
|
||||
{
|
||||
if (m_arSession) m_arSession->OnNewFrame -= EventHandler(this, &ArBackgroundDrawable::OnNewArFrame);
|
||||
m_arSession = nullptr;
|
||||
m_nextFrame = nullptr;
|
||||
m_eventHandle.Close();
|
||||
m_lastFrame = m_nextFrame = nullptr;
|
||||
m_texture = nullptr;
|
||||
Drawable::Close();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user