Skip to content

Commit

Permalink
[Examples] Use preferred available renderer module in examples instea…
Browse files Browse the repository at this point in the history
…d 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.
  • Loading branch information
LukasBanana committed Feb 15, 2025
1 parent bb303ca commit 1e8d916
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
10 changes: 8 additions & 2 deletions examples/Cpp/ExampleBase/ExampleBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ static const char* GetDefaultRendererModule()
#elif defined LLGL_OS_WIN32
return "Direct3D11";
#elif defined LLGL_OS_MACOS
return (IsModuleAvailable("Metal") ? "Metal" : "OpenGL");
return "Metal";
#elif defined LLGL_OS_IOS
return "Metal";
#elif defined LLGL_OS_ANDROID
Expand All @@ -168,11 +168,17 @@ static const char* GetDefaultRendererModule()
#endif
}

static std::string GetPreferredRendererModule()
{
auto modules = LLGL::RenderSystem::FindModules();
return (modules.empty() ? "Null" : modules.front());
}

std::string GetSelectedRendererModule(int argc, char* argv[])
{
// Set report callback to standard output
LLGL::Log::RegisterCallbackStd();
std::string rendererModule = GetDefaultRendererModule();
std::string rendererModule = GetPreferredRendererModule();
GetSelectedRendererModuleOrDefault(rendererModule, argc, argv);
return rendererModule;
}
Expand Down
20 changes: 10 additions & 10 deletions sources/Renderer/RenderSystemModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,12 @@ RenderSystemModule::RenderSystemModule(

std::vector<std::string> RenderSystemModule::FindModules()
{
/* Iterate over all known modules and return those that are available on the current platform */
/* Iterate over all known modules (preferred modules first) and return those that are available on the current platform */
constexpr const char* knownModules[] =
{
"Null",

#if defined(LLGL_OS_IOS) || defined(LLGL_OS_ANDROID)
"OpenGLES3",
#else
"OpenGL",
#if defined(LLGL_OS_WIN32) || defined(LLGL_OS_UWP)
"Direct3D12",
"Direct3D11",
#endif

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

#if defined(LLGL_OS_WIN32) || defined(LLGL_OS_UWP)
"Direct3D11",
"Direct3D12",
#if defined(LLGL_OS_IOS) || defined(LLGL_OS_ANDROID)
"OpenGLES3",
#else
"OpenGL",
#endif

"Null",
};

std::vector<std::string> moduleNames;
Expand Down

0 comments on commit 1e8d916

Please sign in to comment.