| 53 | } |
| 54 | |
| 55 | ref<RenderGraph> RenderGraph::createFromFile(ref<Device> pDevice, const std::filesystem::path& path) |
| 56 | { |
| 57 | using namespace pybind11::literals; |
| 58 | |
| 59 | ref<RenderGraph> pGraph; |
| 60 | |
| 61 | // Setup a temporary scripting context that defines a local variable 'm' that |
| 62 | // has a 'addGraph' function exposed. This mimmicks the old Mogwai Python API |
| 63 | // allowing to load python based render graph scripts. |
| 64 | auto addGraph = pybind11::cpp_function([&pGraph](ref<RenderGraph> graph) { pGraph = graph; }); |
| 65 | |
| 66 | auto SimpleNamespace = pybind11::module_::import("types").attr("SimpleNamespace"); |
| 67 | pybind11::object m = SimpleNamespace("addGraph"_a = addGraph); |
| 68 | |
| 69 | Scripting::Context ctx; |
| 70 | ctx.setObject("m", m); |
| 71 | |
| 72 | ref<Device> pPrevDevice = getActivePythonRenderGraphDevice(); |
| 73 | setActivePythonRenderGraphDevice(pDevice); |
| 74 | Scripting::runScriptFromFile(path, ctx); |
| 75 | setActivePythonRenderGraphDevice(pPrevDevice); |
| 76 | |
| 77 | return pGraph; |
| 78 | } |
| 79 | |
| 80 | ref<RenderGraph> RenderGraph::createFromString(ref<Device> pDevice, const std::string_view script) |
| 81 | { |
nothing calls this directly
no test coverage detected