summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngine
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2019-03-07 04:50:24 +0000
committerEgor Yusov <egor.yusov@gmail.com>2019-03-07 04:50:24 +0000
commitb5d6570531da747cbb6ae578b1ded175ec10a1ce (patch)
treec9cc690bd88027018d2eb39b0a7b9fbcf0a49cf7 /Graphics/GraphicsEngine
parentFixed issue with GLContextWindows (diff)
downloadDiligentCore-b5d6570531da747cbb6ae578b1ded175ec10a1ce.tar.gz
DiligentCore-b5d6570531da747cbb6ae578b1ded175ec10a1ce.zip
Made engine factory interfaces derived from IObject (fixed https://github.com/DiligentGraphics/DiligentCore/issues/72)
Diffstat (limited to 'Graphics/GraphicsEngine')
-rw-r--r--Graphics/GraphicsEngine/CMakeLists.txt1
-rw-r--r--Graphics/GraphicsEngine/include/EngineFactoryBase.h136
2 files changed, 137 insertions, 0 deletions
diff --git a/Graphics/GraphicsEngine/CMakeLists.txt b/Graphics/GraphicsEngine/CMakeLists.txt
index 25618d84..a458d2f3 100644
--- a/Graphics/GraphicsEngine/CMakeLists.txt
+++ b/Graphics/GraphicsEngine/CMakeLists.txt
@@ -9,6 +9,7 @@ set(INCLUDE
include/Defines.h
include/DeviceContextBase.h
include/DeviceObjectBase.h
+ include/EngineFactoryBase.h
include/EngineMemory.h
include/FenceBase.h
include/pch.h
diff --git a/Graphics/GraphicsEngine/include/EngineFactoryBase.h b/Graphics/GraphicsEngine/include/EngineFactoryBase.h
new file mode 100644
index 00000000..b22e174f
--- /dev/null
+++ b/Graphics/GraphicsEngine/include/EngineFactoryBase.h
@@ -0,0 +1,136 @@
+/* Copyright 2015-2019 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+/// \file
+/// Implementation of the Diligent::EngineFactoryBase template class
+
+#include "Object.h"
+
+namespace Diligent
+{
+
+/// Template class implementing base functionality for an engine factory
+
+/// \tparam BaseInterface - base interface that this class will inheret
+/// (Diligent::IEngineFactoryD3D11, Diligent::IEngineFactoryD3D12,
+/// Diligent::IEngineFactoryVk or Diligent::IEngineFactoryOpenGL).
+template<class BaseInterface>
+class EngineFactoryBase : public BaseInterface
+{
+public:
+ using CounterValueType = IReferenceCounters::CounterValueType;
+
+ EngineFactoryBase(const INTERFACE_ID& FactoryIID)noexcept :
+ m_FactoryIID(FactoryIID),
+ m_RefCounters(*this)
+ {
+ }
+
+ virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final
+ {
+ if (ppInterface == nullptr)
+ return;
+
+ *ppInterface = nullptr;
+ if (IID == IID_Unknown || IID == m_FactoryIID)
+ {
+ *ppInterface = this;
+ (*ppInterface)->AddRef();
+ }
+ }
+
+ virtual CounterValueType AddRef()override final
+ {
+ return m_RefCounters.AddStrongRef();
+ }
+
+ virtual CounterValueType Release()override final
+ {
+ return m_RefCounters.ReleaseStrongRef();
+ }
+
+ virtual IReferenceCounters* GetReferenceCounters()const override final
+ {
+ return const_cast<IReferenceCounters*>(static_cast<const IReferenceCounters*>(&m_RefCounters));
+ }
+
+private:
+ class DummyReferenceCounters final : public IReferenceCounters
+ {
+ public:
+ DummyReferenceCounters(EngineFactoryBase& Factory)noexcept :
+ m_Factory(Factory)
+ {
+ m_lNumStrongReferences = 0;
+ m_lNumWeakReferences = 0;
+ }
+
+ using IReferenceCounters::CounterValueType;
+ virtual CounterValueType AddStrongRef() override final
+ {
+ return Atomics::AtomicIncrement(m_lNumStrongReferences);
+ }
+
+ virtual CounterValueType ReleaseStrongRef()override final
+ {
+ return Atomics::AtomicDecrement(m_lNumStrongReferences);
+ }
+
+ virtual CounterValueType AddWeakRef()override final
+ {
+ return Atomics::AtomicIncrement(m_lNumWeakReferences);
+ }
+
+ virtual CounterValueType ReleaseWeakRef()override final
+ {
+ return Atomics::AtomicDecrement(m_lNumWeakReferences);
+ }
+
+ virtual void GetObject(IObject** ppObject)override final
+ {
+ if (ppObject != nullptr)
+ m_Factory.QueryInterface(IID_Unknown, ppObject);
+ }
+
+ virtual CounterValueType GetNumStrongRefs()const override final
+ {
+ return m_lNumStrongReferences;
+ }
+
+ virtual CounterValueType GetNumWeakRefs()const override final
+ {
+ return m_lNumWeakReferences;
+ }
+ private:
+ EngineFactoryBase& m_Factory;
+ Atomics::AtomicLong m_lNumStrongReferences;
+ Atomics::AtomicLong m_lNumWeakReferences;
+ };
+
+ const INTERFACE_ID m_FactoryIID;
+ DummyReferenceCounters m_RefCounters;
+};
+
+}