Skip to content

Commit 7b6adaf

Browse files
Use convenience functions to load the engine dll and get the factory
1 parent 18cbf37 commit 7b6adaf

File tree

3 files changed

+28
-70
lines changed

3 files changed

+28
-70
lines changed

SampleBase/src/SampleApp.cpp

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,8 @@ void SampleApp::InitializeDiligentEngine(const NativeWindow* pWindow)
231231
#if D3D11_SUPPORTED
232232
case RENDER_DEVICE_TYPE_D3D11:
233233
{
234-
# if ENGINE_DLL
235-
// Load the dll and import GetEngineFactoryD3D11() function
236-
GetEngineFactoryD3D11Type GetEngineFactoryD3D11 = LoadGraphicsEngineD3D11();
237-
# endif
238-
IEngineFactoryD3D11* pFactoryD3D11 = GetEngineFactoryD3D11();
234+
// Load the dll and get the factory
235+
IEngineFactoryD3D11* pFactoryD3D11 = LoadAndGetEngineFactoryD3D11();
239236
m_pEngineFactory = pFactoryD3D11;
240237

241238
EngineD3D11CreateInfo EngineCI;
@@ -277,11 +274,8 @@ void SampleApp::InitializeDiligentEngine(const NativeWindow* pWindow)
277274
#if D3D12_SUPPORTED
278275
case RENDER_DEVICE_TYPE_D3D12:
279276
{
280-
# if ENGINE_DLL
281-
// Load the dll and import GetEngineFactoryD3D12() function
282-
GetEngineFactoryD3D12Type GetEngineFactoryD3D12 = LoadGraphicsEngineD3D12();
283-
# endif
284-
IEngineFactoryD3D12* pFactoryD3D12 = GetEngineFactoryD3D12();
277+
// Load the dll and get the factory
278+
IEngineFactoryD3D12* pFactoryD3D12 = LoadAndGetEngineFactoryD3D12();
285279
if (!pFactoryD3D12->LoadD3D12())
286280
{
287281
LOG_ERROR_AND_THROW("Failed to load Direct3D12");
@@ -342,11 +336,8 @@ void SampleApp::InitializeDiligentEngine(const NativeWindow* pWindow)
342336
# if !PLATFORM_MACOS
343337
VERIFY_EXPR(pWindow != nullptr);
344338
# endif
345-
# if EXPLICITLY_LOAD_ENGINE_GL_DLL
346-
// Load the dll and import GetEngineFactoryOpenGL() function
347-
GetEngineFactoryOpenGLType GetEngineFactoryOpenGL = LoadGraphicsEngineOpenGL();
348-
# endif
349-
IEngineFactoryOpenGL* pFactoryOpenGL = GetEngineFactoryOpenGL();
339+
// Load the dll and get the factory
340+
IEngineFactoryOpenGL* pFactoryOpenGL = LoadAndGetEngineFactoryOpenGL();
350341
m_pEngineFactory = pFactoryOpenGL;
351342

352343
EngineGLCreateInfo EngineCI;
@@ -384,10 +375,6 @@ void SampleApp::InitializeDiligentEngine(const NativeWindow* pWindow)
384375
#if VULKAN_SUPPORTED
385376
case RENDER_DEVICE_TYPE_VULKAN:
386377
{
387-
# if EXPLICITLY_LOAD_ENGINE_VK_DLL
388-
// Load the dll and import GetEngineFactoryVk() function
389-
GetEngineFactoryVkType GetEngineFactoryVk = LoadGraphicsEngineVk();
390-
# endif
391378
EngineVkCreateInfo EngineCI;
392379
if (m_ValidationLevel >= 0)
393380
EngineCI.SetValidationLevel(static_cast<VALIDATION_LEVEL>(m_ValidationLevel));
@@ -404,7 +391,8 @@ void SampleApp::InitializeDiligentEngine(const NativeWindow* pWindow)
404391
EngineCI.ppIgnoreDebugMessageNames = ppIgnoreDebugMessages;
405392
EngineCI.IgnoreDebugMessageCount = _countof(ppIgnoreDebugMessages);
406393

407-
IEngineFactoryVk* pFactoryVk = GetEngineFactoryVk();
394+
// Load the dll and get the factory
395+
IEngineFactoryVk* pFactoryVk = LoadAndGetEngineFactoryVk();
408396
m_pEngineFactory = pFactoryVk;
409397

410398
EngineCI.AdapterId = FindAdapter(pFactoryVk, EngineCI.GraphicsAPIVersion, m_AdapterAttribs);
@@ -461,15 +449,12 @@ void SampleApp::InitializeDiligentEngine(const NativeWindow* pWindow)
461449
#if WEBGPU_SUPPORTED
462450
case RENDER_DEVICE_TYPE_WEBGPU:
463451
{
464-
# if EXPLICITLY_LOAD_ENGINE_WEBGPU_DLL
465-
// Load the dll and import LoadGraphicsEngineWebGPU() function
466-
GetEngineFactoryWebGPUType GetEngineFactoryWebGPU = LoadGraphicsEngineWebGPU();
467-
# endif
468452
EngineWebGPUCreateInfo EngineCI;
469453
if (m_ValidationLevel >= 0)
470454
EngineCI.SetValidationLevel(static_cast<VALIDATION_LEVEL>(m_ValidationLevel));
471455

472-
IEngineFactoryWebGPU* pFactoryWebGPU = GetEngineFactoryWebGPU();
456+
// Load the dll and get the factory
457+
IEngineFactoryWebGPU* pFactoryWebGPU = LoadAndGetEngineFactoryWebGPU();
473458
m_pEngineFactory = pFactoryWebGPU;
474459

475460
NumImmediateContexts = std::max(1u, EngineCI.NumImmediateContexts);

Samples/GLFWDemo/src/GLFWDemo.cpp

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,8 @@ bool GLFWDemo::InitEngine(RENDER_DEVICE_TYPE DevType)
182182
#if D3D11_SUPPORTED
183183
case RENDER_DEVICE_TYPE_D3D11:
184184
{
185-
# if ENGINE_DLL
186-
// Load the dll and import GetEngineFactoryD3D11() function
187-
GetEngineFactoryD3D11Type GetEngineFactoryD3D11 = LoadGraphicsEngineD3D11();
188-
# endif
189-
IEngineFactoryD3D11* pFactoryD3D11 = GetEngineFactoryD3D11();
185+
// Load the dll and get the factory
186+
IEngineFactoryD3D11* pFactoryD3D11 = LoadAndGetEngineFactoryD3D11();
190187

191188
EngineD3D11CreateInfo EngineCI;
192189
pFactoryD3D11->CreateDeviceAndContextsD3D11(EngineCI, &m_pDevice, &m_pImmediateContext);
@@ -199,11 +196,8 @@ bool GLFWDemo::InitEngine(RENDER_DEVICE_TYPE DevType)
199196
#if D3D12_SUPPORTED
200197
case RENDER_DEVICE_TYPE_D3D12:
201198
{
202-
# if ENGINE_DLL
203-
// Load the dll and import GetEngineFactoryD3D12() function
204-
GetEngineFactoryD3D12Type GetEngineFactoryD3D12 = LoadGraphicsEngineD3D12();
205-
# endif
206-
IEngineFactoryD3D12* pFactoryD3D12 = GetEngineFactoryD3D12();
199+
// Load the dll and get the factory
200+
IEngineFactoryD3D12* pFactoryD3D12 = LoadAndGetEngineFactoryD3D12();
207201

208202
EngineD3D12CreateInfo EngineCI;
209203
pFactoryD3D12->CreateDeviceAndContextsD3D12(EngineCI, &m_pDevice, &m_pImmediateContext);
@@ -216,11 +210,8 @@ bool GLFWDemo::InitEngine(RENDER_DEVICE_TYPE DevType)
216210
#if GL_SUPPORTED
217211
case RENDER_DEVICE_TYPE_GL:
218212
{
219-
# if EXPLICITLY_LOAD_ENGINE_GL_DLL
220-
// Load the dll and import GetEngineFactoryOpenGL() function
221-
GetEngineFactoryOpenGLType GetEngineFactoryOpenGL = LoadGraphicsEngineOpenGL();
222-
# endif
223-
IEngineFactoryOpenGL* pFactoryOpenGL = GetEngineFactoryOpenGL();
213+
// Load the dll and get the factory
214+
IEngineFactoryOpenGL* pFactoryOpenGL = LoadAndGetEngineFactoryOpenGL();
224215

225216
EngineGLCreateInfo EngineCI;
226217
EngineCI.Window = Window;
@@ -233,11 +224,8 @@ bool GLFWDemo::InitEngine(RENDER_DEVICE_TYPE DevType)
233224
#if VULKAN_SUPPORTED
234225
case RENDER_DEVICE_TYPE_VULKAN:
235226
{
236-
# if EXPLICITLY_LOAD_ENGINE_VK_DLL
237-
// Load the dll and import GetEngineFactoryVk() function
238-
GetEngineFactoryVkType GetEngineFactoryVk = LoadGraphicsEngineVk();
239-
# endif
240-
IEngineFactoryVk* pFactoryVk = GetEngineFactoryVk();
227+
// Load the dll and get the factory
228+
IEngineFactoryVk* pFactoryVk = LoadAndGetEngineFactoryVk();
241229

242230
EngineVkCreateInfo EngineCI;
243231
pFactoryVk->CreateDeviceAndContextsVk(EngineCI, &m_pDevice, &m_pImmediateContext);
@@ -261,11 +249,8 @@ bool GLFWDemo::InitEngine(RENDER_DEVICE_TYPE DevType)
261249
#if WEBGPU_SUPPORTED
262250
case RENDER_DEVICE_TYPE_WEBGPU:
263251
{
264-
# if ENGINE_DLL
265-
// Load the dll and import LoadGraphicsEngineWebGPU() function
266-
GetEngineFactoryWebGPUType GetEngineFactoryWGPU = LoadGraphicsEngineWebGPU();
267-
# endif
268-
IEngineFactoryWebGPU* pFactoryWGPU = GetEngineFactoryWGPU();
252+
// Load the dll and get the factory
253+
IEngineFactoryWebGPU* pFactoryWGPU = LoadAndGetEngineFactoryWebGPU();
269254

270255
EngineWebGPUCreateInfo EngineCI;
271256
EngineCI.Features.TimestampQueries = DEVICE_FEATURE_STATE_ENABLED;

Tutorials/Tutorial28_HelloOpenXR/src/Tutorial28_HelloOpenXR.cpp

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -585,11 +585,8 @@ class Tutorial28_HelloOpenXR
585585
{
586586
EngineD3D11CreateInfo EngineCI;
587587
EngineCI.pXRAttribs = &XRAttribs;
588-
# if ENGINE_DLL
589-
// Load the dll and import GetEngineFactoryD3D11() function
590-
GetEngineFactoryD3D11Type GetEngineFactoryD3D11 = LoadGraphicsEngineD3D11();
591-
# endif
592-
IEngineFactoryD3D11* pFactoryD3D11 = GetEngineFactoryD3D11();
588+
// Load the dll and get the factory
589+
IEngineFactoryD3D11* pFactoryD3D11 = LoadAndGetEngineFactoryD3D11();
593590
pFactoryD3D11->CreateDeviceAndContextsD3D11(EngineCI, &pDevice, &m_pImmediateContext);
594591
}
595592
break;
@@ -599,14 +596,11 @@ class Tutorial28_HelloOpenXR
599596
#if D3D12_SUPPORTED
600597
case RENDER_DEVICE_TYPE_D3D12:
601598
{
602-
# if ENGINE_DLL
603-
// Load the dll and import GetEngineFactoryD3D12() function
604-
GetEngineFactoryD3D12Type GetEngineFactoryD3D12 = LoadGraphicsEngineD3D12();
605-
# endif
606599
EngineD3D12CreateInfo EngineCI;
607600
EngineCI.pXRAttribs = &XRAttribs;
608601

609-
IEngineFactoryD3D12* pFactoryD3D12 = GetEngineFactoryD3D12();
602+
// Load the dll and get the factory
603+
IEngineFactoryD3D12* pFactoryD3D12 = LoadAndGetEngineFactoryD3D12();
610604
pFactoryD3D12->CreateDeviceAndContextsD3D12(EngineCI, &pDevice, &m_pImmediateContext);
611605
}
612606
break;
@@ -617,11 +611,8 @@ class Tutorial28_HelloOpenXR
617611
case RENDER_DEVICE_TYPE_GL:
618612
{
619613
# if 0
620-
# if EXPLICITLY_LOAD_ENGINE_GL_DLL
621-
// Load the dll and import GetEngineFactoryOpenGL() function
622-
auto GetEngineFactoryOpenGL = LoadGraphicsEngineOpenGL();
623-
# endif
624-
auto* pFactoryOpenGL = GetEngineFactoryOpenGL();
614+
// Load the dll and get the factory
615+
auto* pFactoryOpenGL = LoadAndGetEngineFactoryOpenGL();
625616

626617
EngineGLCreateInfo EngineCI;
627618
EngineCI.pXRAttribs = &XRAttribs;
@@ -637,14 +628,11 @@ class Tutorial28_HelloOpenXR
637628
#if VULKAN_SUPPORTED
638629
case RENDER_DEVICE_TYPE_VULKAN:
639630
{
640-
# if EXPLICITLY_LOAD_ENGINE_VK_DLL
641-
// Load the dll and import GetEngineFactoryVk() function
642-
GetEngineFactoryVkType GetEngineFactoryVk = LoadGraphicsEngineVk();
643-
# endif
644631
EngineVkCreateInfo EngineCI;
645632
EngineCI.pXRAttribs = &XRAttribs;
646633

647-
IEngineFactoryVk* pFactoryVk = GetEngineFactoryVk();
634+
// Load the dll and get the factory
635+
IEngineFactoryVk* pFactoryVk = LoadAndGetEngineFactoryVk();
648636
pFactoryVk->CreateDeviceAndContextsVk(EngineCI, &pDevice, &m_pImmediateContext);
649637
}
650638
break;

0 commit comments

Comments
 (0)