Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to list rendering backends #1831

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion application/F3DOptionsTools.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ static inline const std::array<CLIGroup, 8> CLIOptions = {{
{ "dry-run", "", "Do not read the configuration file", "<bool>", "1" },
{ "no-render", "", "Do not read the configuration file", "<bool>", "1" },
{ "rendering-backend", "", "Backend to use when rendering (auto|glx|wgl|egl|osmesa)", "<string>", "" },
{ "rendering-backend-list", "", "List of rendering backends available on this system", "", "" },
{ "max-size", "", "Maximum size in Mib of a file to load, leave empty for unlimited", "<size in Mib>", "" },
#if F3D_MODULE_DMON
{ "watch", "", "Watch current file and automatically reload it whenever it is modified on disk", "<bool>", "1" },
Expand Down Expand Up @@ -175,7 +176,7 @@ static inline const std::array<CLIGroup, 8> CLIOptions = {{
* True boolean options need to be filtered out in ParseCLIOptions
* This is the easiest, compile time way to do it
*/
constexpr std::array<std::string_view, 4> CLIBooleans = {"version", "help", "readers-list", "scan-plugins"};
constexpr std::array CLIBooleans = {"version", "help", "readers-list", "scan-plugins", "renderin-backend-list"};
Meakk marked this conversation as resolved.
Show resolved Hide resolved

//----------------------------------------------------------------------------
/**
Expand Down Expand Up @@ -269,6 +270,19 @@ void PrintVersion()
f3d::log::setUseColoring(true);
}

//----------------------------------------------------------------------------
void PrintRenderingBackendList()
{
auto backends = f3d::engine::getRenderingBackendList();

f3d::log::setUseColoring(false);
f3d::log::info("Rendering backends:");
for (const auto& [name, available] : backends)
{
f3d::log::info(name + ": " + (available ? "available" : "unavailable"));
}
}

//----------------------------------------------------------------------------
void PrintReadersList()
{
Expand Down Expand Up @@ -484,6 +498,11 @@ F3DOptionsTools::OptionsDict F3DOptionsTools::ParseCLIOptions(
::PrintVersion();
throw F3DExNoProcess("version requested");
}
if (result.count("rendering-backend-list") > 0)
{
::PrintRenderingBackendList();
throw F3DExNoProcess("rendering backend list requested");
}
if (result.count("scan-plugins") > 0)
{
::PrintPluginsScan();
Expand Down
19 changes: 19 additions & 0 deletions application/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,25 @@ f3d_test(NAME TestHelpPrecedenceWithUnknownOption ARGS --help --unknown REGEXP "
# Test that --version is displayed even when there is an unknown option
f3d_test(NAME TestVersionPrecedenceWithUnknownOption ARGS --version --unknown REGEXP "Version:" NO_BASELINE)

# Test rendering backend list
if(WIN32)
f3d_test(NAME TestRenderingBackenListWGL ARGS --rendering-backend-list NO_RENDER NO_BASELINE REGEXP "wgl: available")
elseif(APPLE)
f3d_test(NAME TestRenderingBackenListCOCOA ARGS --rendering-backend-list NO_RENDER NO_BASELINE REGEXP "cocoa: available")
endif()

if(F3D_TESTING_ENABLE_GLX_TESTS)
f3d_test(NAME TestRenderingBackenListGLX ARGS --rendering-backend-list NO_RENDER NO_BASELINE REGEXP "glx: available")
endif()
Meakk marked this conversation as resolved.
Show resolved Hide resolved

if(F3D_TESTING_ENABLE_EGL_TESTS)
f3d_test(NAME TestRenderingBackenListEGL ARGS --rendering-backend-list NO_RENDER NO_BASELINE REGEXP "egl: available")
endif()

if(F3D_TESTING_ENABLE_OSMESA_TESTS)
f3d_test(NAME TestRenderingBackenListOSMesa ARGS --rendering-backend-list NO_RENDER NO_BASELINE REGEXP "osmesa: available")
endif()

# Test scan plugins
if(NOT F3D_MACOS_BUNDLE)
f3d_test(NAME TestScanPluginsCheckNative ARGS --scan-plugins NO_RENDER NO_BASELINE REGEXP " - native")
Expand Down
6 changes: 6 additions & 0 deletions library/public/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ class F3D_EXPORT engine
*/
interactor& getInteractor();

/**
* List rendering backends supported by libf3d.
* All backends have an associated boolean flag indicating if it can be used.
*/
static std::map<std::string, bool> getRenderingBackendList();

/**
* Load a plugin.
* Supports full path, relative path, and plugin name.
Expand Down
27 changes: 27 additions & 0 deletions library/src/engine.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ namespace f3d
class engine::internals
{
public:
template<typename F>
static bool BackendAvailable(F&& func)
{
try
{
return func() != nullptr;
}
catch (const context::loading_exception&)
{
return false;
}
}

std::unique_ptr<options> Options;
std::unique_ptr<detail::window_impl> Window;
std::unique_ptr<detail::scene_impl> Scene;
Expand Down Expand Up @@ -212,6 +225,20 @@ interactor& engine::getInteractor()
return *this->Internals->Interactor;
}

//----------------------------------------------------------------------------
std::map<std::string, bool> engine::getRenderingBackendList()
{
std::map<std::string, bool> backends;

backends["glx"] = engine::internals::BackendAvailable(context::glx);
backends["wgl"] = engine::internals::BackendAvailable(context::wgl);
backends["cocoa"] = engine::internals::BackendAvailable(context::cocoa);
backends["egl"] = engine::internals::BackendAvailable(context::egl);
backends["osmesa"] = engine::internals::BackendAvailable(context::osmesa);

return backends;
}

//----------------------------------------------------------------------------
void engine::loadPlugin(const std::string& pathOrName, const std::vector<std::string>& searchPaths)
{
Expand Down
3 changes: 2 additions & 1 deletion python/F3DPythonBindings.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,8 @@ PYBIND11_MODULE(pyf3d, module)
"autoload_plugins", &f3d::engine::autoloadPlugins, "Automatically load internal plugins")
.def_static("get_plugins_list", &f3d::engine::getPluginsList)
.def_static("get_lib_info", &f3d::engine::getLibInfo, py::return_value_policy::reference)
.def_static("get_readers_info", &f3d::engine::getReadersInfo);
.def_static("get_readers_info", &f3d::engine::getReadersInfo)
.def_static("get_rendering_backend_list", &f3d::engine::getRenderingBackendList);

// libInformation
py::class_<f3d::engine::libInformation>(module, "LibInformation")
Expand Down
6 changes: 6 additions & 0 deletions python/testing/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,9 @@ def test_get_readers_info():
assert isinstance(reader.plugin_name, str) and reader.plugin_name
assert isinstance(reader.has_scene_reader, bool)
assert isinstance(reader.has_geometry_reader, bool)


def test_get_rendering_backend_list():
backends = f3d.Engine.get_rendering_backend_list()

assert isinstance(backends, dict) and len(backends) == 5
Loading