Skip to content

Commit

Permalink
Respect CLI renderer options
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-johansson committed Sep 16, 2024
1 parent e0fbbcd commit 61a44a5
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
10 changes: 10 additions & 0 deletions source/base/lib/inc/tactile/base/runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class IWindow;
class IRenderer;
class ICompressor;
class ISaveFormat;
struct RendererOptions;

/**
* Interface that defines the primary API used by dynamic Tactile modules.
Expand Down Expand Up @@ -113,6 +114,15 @@ class IRuntime
virtual void get_imgui_allocator_functions(imgui_malloc_fn** malloc_fn,
imgui_free_fn** free_fn,
void** user_data) = 0;

/**
* Returns the configured renderer options.
*
* \return
* The current renderer options.
*/
[[nodiscard]]
virtual auto get_renderer_options() const -> const RendererOptions& = 0;
};

} // namespace tactile
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,7 @@ void OpenGLRendererPlugin::load(IRuntime* runtime)
m_runtime->get_imgui_allocator_functions(&imgui_alloc_fn, &imgui_free_fn, &imgui_user_data);
ImGui::SetAllocatorFunctions(imgui_alloc_fn, imgui_free_fn, imgui_user_data);

// TODO load from CLI via runtime
constexpr RendererOptions options {
.texture_filter_mode = TextureFilterMode::kNearest,
.use_mipmaps = true,
.use_vsync = true,
.limit_fps = false,
};

if (auto renderer = OpenGLRenderer::make(options, window)) {
if (auto renderer = OpenGLRenderer::make(m_runtime->get_renderer_options(), window)) {
m_renderer = std::move(*renderer);
m_runtime->set_renderer(&m_renderer.value());
}
Expand Down
3 changes: 3 additions & 0 deletions source/runtime/lib/inc/tactile/runtime/runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class TACTILE_RUNTIME_API Runtime final : public IRuntime
imgui_free_fn** free_fn,
void** user_data) override;

[[nodiscard]]
auto get_renderer_options() const -> const RendererOptions& override;

private:
struct Data;
std::unique_ptr<Data> mData;
Expand Down
9 changes: 8 additions & 1 deletion source/runtime/lib/src/tactile/runtime/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ auto _make_logger(const LogLevel log_level) -> Logger

struct Runtime::Data final
{
RendererOptions renderer_options;
ProtobufContext protobuf_context;
SDLContext sdl_context;
Logger logger;
Expand All @@ -67,7 +68,8 @@ struct Runtime::Data final
std::unordered_map<SaveFormatId, ISaveFormat*> save_formats {};

explicit Data(const CommandLineOptions& options)
: logger {_make_logger(options.log_level)}
: renderer_options {options.renderer_options},
logger {_make_logger(options.log_level)}
{
set_default_logger(&logger);
TACTILE_LOG_DEBUG("Tactile " TACTILE_VERSION_STRING);
Expand Down Expand Up @@ -175,4 +177,9 @@ void Runtime::get_imgui_allocator_functions(imgui_malloc_fn** malloc_fn,
}
}

auto Runtime::get_renderer_options() const -> const RendererOptions&
{
return mData->renderer_options;
}

} // namespace tactile
10 changes: 1 addition & 9 deletions source/vulkan_renderer/lib/src/vulkan_renderer_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,7 @@ void VulkanRendererPlugin::load(IRuntime* runtime)
&imgui_user_data);
ImGui::SetAllocatorFunctions(imgui_alloc_fn, imgui_free_fn, imgui_user_data);

// TODO load from CLI via runtime
constexpr RendererOptions options {
.texture_filter_mode = TextureFilterMode::kNearest,
.use_mipmaps = true,
.use_vsync = true,
.limit_fps = false,
};

m_renderer = std::make_unique<VulkanRenderer>(options, window);
m_renderer = std::make_unique<VulkanRenderer>(m_runtime->get_renderer_options(), window);
m_runtime->set_renderer(m_renderer.get());
}
catch (...) {
Expand Down

0 comments on commit 61a44a5

Please sign in to comment.