Diligent Engine API Reference
RenderDeviceFactoryD3D12.h
1 /* Copyright 2015-2018 Egor Yusov
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
10  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
11  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
12  *
13  * In no event and under no legal theory, whether in tort (including negligence),
14  * contract, or otherwise, unless required by applicable law (such as deliberate
15  * and grossly negligent acts) or agreed to in writing, shall any Contributor be
16  * liable for any damages, including any direct, indirect, special, incidental,
17  * or consequential damages of any character arising as a result of this License or
18  * out of the use or inability to use the software (including but not limited to damages
19  * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
20  * all other commercial damages or losses), even if such Contributor has been advised
21  * of the possibility of such damages.
22  */
23 
24 #pragma once
25 
28 
29 #include "Errors.h"
30 #include "RenderDevice.h"
31 #include "DeviceContext.h"
32 #include "SwapChain.h"
33 
34 #if PLATFORM_UNIVERSAL_WINDOWS && defined(ENGINE_DLL)
35 # include "StringTools.h"
36 #endif
37 
38 namespace Diligent
39 {
40 
41 class IEngineFactoryD3D12
42 {
43 public:
44  virtual void CreateDeviceAndContextsD3D12( const EngineD3D12Attribs& CreationAttribs,
45  IRenderDevice **ppDevice,
46  IDeviceContext **ppContexts,
47  Uint32 NumDeferredContexts) = 0;
48 
49  virtual void AttachToD3D12Device(void *pd3d12NativeDevice,
50  class ICommandQueueD3D12 *pCommandQueue,
51  const EngineD3D12Attribs& EngineAttribs,
52  IRenderDevice **ppDevice,
53  IDeviceContext **ppContexts,
54  Uint32 NumDeferredContexts) = 0;
55 
56  virtual void CreateSwapChainD3D12( IRenderDevice *pDevice,
57  IDeviceContext *pImmediateContext,
58  const SwapChainDesc& SwapChainDesc,
59  void* pNativeWndHandle,
60  ISwapChain **ppSwapChain ) = 0;
61 
62 };
63 
64 }
65 
66 extern "C"
67 {
68 #ifdef ENGINE_DLL
69 
70  typedef Diligent::IEngineFactoryD3D12* (*GetEngineFactoryD3D12Type)();
71 
72  static bool LoadGraphicsEngineD3D12(GetEngineFactoryD3D12Type &GetFactoryFunc)
73  {
74  GetFactoryFunc = nullptr;
75  std::string LibName = "GraphicsEngineD3D12_";
76 
77 #if _WIN64
78  LibName += "64";
79 #else
80  LibName += "32";
81 #endif
82 
83 #ifdef _DEBUG
84  LibName += "d";
85 #else
86  LibName += "r";
87 #endif
88 
89  LibName += ".dll";
90 #if PLATFORM_WIN32
91  auto hModule = LoadLibraryA(LibName.c_str());
92 #elif PLATFORM_UNIVERSAL_WINDOWS
93  auto hModule = LoadPackagedLibrary(Diligent::WidenString(LibName).c_str(), 0);
94 #else
95 # error Unexpected platform
96 #endif
97 
98  if( hModule == NULL )
99  {
100  LOG_ERROR_MESSAGE( "Failed to load ", LibName, " library." );
101  return false;
102  }
103 
104  GetFactoryFunc = reinterpret_cast<GetEngineFactoryD3D12Type>( GetProcAddress(hModule, "GetEngineFactoryD3D12") );
105  if( GetFactoryFunc == NULL )
106  {
107  LOG_ERROR_MESSAGE( "Failed to load GetEngineFactoryD3D12() from ", LibName, " library." );
108  FreeLibrary( hModule );
109  return false;
110  }
111 
112  return true;
113  }
114 #else
115 
116  Diligent::IEngineFactoryD3D12* GetEngineFactoryD3D12();
117 
118 #endif
119 }
void LoadGraphicsEngineD3D12(GetEngineFactoryD3D12Type &GetFactoryFunc)
Loads Direct3D12-based engine implementation and exports factory functions.
Definition: RenderDeviceFactoryD3D12.cpp:393
Namespace for the OpenGL implementation of the graphics engine.
Definition: BufferD3D11Impl.h:34