Diligent Engine API Reference
RenderDeviceFactoryD3D11.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 "EngineD3D11Attribs.h"
31 #include "RenderDevice.h"
32 #include "DeviceContext.h"
33 #include "SwapChain.h"
34 
35 #if PLATFORM_UNIVERSAL_WINDOWS && defined(ENGINE_DLL)
36 # include "StringTools.h"
37 #endif
38 
39 namespace Diligent
40 {
41 
42 class IEngineFactoryD3D11
43 {
44 public:
45  virtual void CreateDeviceAndContextsD3D11( const EngineD3D11Attribs& EngineAttribs,
46  IRenderDevice **ppDevice,
47  IDeviceContext **ppContexts,
48  Uint32 NumDeferredContexts ) = 0;
49 
50  virtual void CreateSwapChainD3D11( IRenderDevice *pDevice,
51  IDeviceContext *pImmediateContext,
52  const SwapChainDesc& SCDesc,
53  void* pNativeWndHandle,
54  ISwapChain **ppSwapChain ) = 0;
55 
56  virtual void AttachToD3D11Device(void *pd3d11NativeDevice,
57  void *pd3d11ImmediateContext,
58  const EngineD3D11Attribs& EngineAttribs,
59  IRenderDevice **ppDevice,
60  IDeviceContext **ppContexts,
61  Uint32 NumDeferredContexts) = 0;
62 };
63 
64 }
65 
66 extern "C"
67 {
68 #ifdef ENGINE_DLL
69 
70  typedef Diligent::IEngineFactoryD3D11* (*GetEngineFactoryD3D11Type)();
71 
72  static bool LoadGraphicsEngineD3D11(GetEngineFactoryD3D11Type &GetFactoryFunc)
73  {
74  GetFactoryFunc = nullptr;
75  std::string LibName = "GraphicsEngineD3D11_";
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  if( hModule == NULL )
98  {
99  LOG_ERROR_MESSAGE( "Failed to load ", LibName, " library." );
100  return false;
101  }
102 
103  GetFactoryFunc = reinterpret_cast<GetEngineFactoryD3D11Type>( GetProcAddress(hModule, "GetEngineFactoryD3D11") );
104  if( GetFactoryFunc == NULL )
105  {
106  LOG_ERROR_MESSAGE( "Failed to load GetEngineFactoryD3D11() from ", LibName, " library." );
107  FreeLibrary( hModule );
108  return false;
109  }
110 
111  return true;
112  }
113 #else
114 
115  Diligent::IEngineFactoryD3D11* GetEngineFactoryD3D11();
116 
117 #endif
118 }
void LoadGraphicsEngineD3D11(GetEngineFactoryD3D11Type &GetFactoryFunc)
Loads Direct3D11-based engine implementation and exports factory functions.
Definition: RenderDeviceFactoryD3D11.cpp:339
Namespace for the OpenGL implementation of the graphics engine.
Definition: BufferD3D11Impl.h:34