Skip to content

Commit 1e8d916

Browse files
committed
[Examples] Use preferred available renderer module in examples instead of hard-coded module name.
Instead of using a fixed module name such as "Direct3D12" on Windows, this uses the first available module. The order of modules returned by RenderSystem::FindModule() has been changed to list the preferred modules first.
1 parent bb303ca commit 1e8d916

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

examples/Cpp/ExampleBase/ExampleBase.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static const char* GetDefaultRendererModule()
156156
#elif defined LLGL_OS_WIN32
157157
return "Direct3D11";
158158
#elif defined LLGL_OS_MACOS
159-
return (IsModuleAvailable("Metal") ? "Metal" : "OpenGL");
159+
return "Metal";
160160
#elif defined LLGL_OS_IOS
161161
return "Metal";
162162
#elif defined LLGL_OS_ANDROID
@@ -168,11 +168,17 @@ static const char* GetDefaultRendererModule()
168168
#endif
169169
}
170170

171+
static std::string GetPreferredRendererModule()
172+
{
173+
auto modules = LLGL::RenderSystem::FindModules();
174+
return (modules.empty() ? "Null" : modules.front());
175+
}
176+
171177
std::string GetSelectedRendererModule(int argc, char* argv[])
172178
{
173179
// Set report callback to standard output
174180
LLGL::Log::RegisterCallbackStd();
175-
std::string rendererModule = GetDefaultRendererModule();
181+
std::string rendererModule = GetPreferredRendererModule();
176182
GetSelectedRendererModuleOrDefault(rendererModule, argc, argv);
177183
return rendererModule;
178184
}

sources/Renderer/RenderSystemModule.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,12 @@ RenderSystemModule::RenderSystemModule(
3535

3636
std::vector<std::string> RenderSystemModule::FindModules()
3737
{
38-
/* Iterate over all known modules and return those that are available on the current platform */
38+
/* Iterate over all known modules (preferred modules first) and return those that are available on the current platform */
3939
constexpr const char* knownModules[] =
4040
{
41-
"Null",
42-
43-
#if defined(LLGL_OS_IOS) || defined(LLGL_OS_ANDROID)
44-
"OpenGLES3",
45-
#else
46-
"OpenGL",
41+
#if defined(LLGL_OS_WIN32) || defined(LLGL_OS_UWP)
42+
"Direct3D12",
43+
"Direct3D11",
4744
#endif
4845

4946
#if defined(LLGL_OS_MACOS) || defined(LLGL_OS_IOS)
@@ -52,10 +49,13 @@ std::vector<std::string> RenderSystemModule::FindModules()
5249
"Vulkan",
5350
#endif
5451

55-
#if defined(LLGL_OS_WIN32) || defined(LLGL_OS_UWP)
56-
"Direct3D11",
57-
"Direct3D12",
52+
#if defined(LLGL_OS_IOS) || defined(LLGL_OS_ANDROID)
53+
"OpenGLES3",
54+
#else
55+
"OpenGL",
5856
#endif
57+
58+
"Null",
5959
};
6060

6161
std::vector<std::string> moduleNames;

0 commit comments

Comments
 (0)