Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions src/ruis/render/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ context::~context()

if (!cur_context_stack.empty()) {
cur_context_stack.back()->native_window.get().bind_rendering_context();
} else {
// no render contexts are left, so make the factory's shared rendering
// context current: the shared render objects created by the factory
// must be destroyed with a valid current context
this->factory.get().bind();
}
}

Expand Down
19 changes: 18 additions & 1 deletion src/ruis/render/factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "vertex_buffer.hpp"

namespace ruis::render {
class context;

/**
* @brief Render object factory.
Expand All @@ -62,6 +63,10 @@ namespace ruis::render {
*/
class factory : public std::enable_shared_from_this<factory>
{
// ruis::render::context calls the protected bind() when the last render
// context is destroyed, to make the shared rendering context current
friend class context;

public:
virtual ~factory() = default;

Expand All @@ -80,11 +85,23 @@ class factory : public std::enable_shared_from_this<factory>
* therefore call its private bind_rendering_context(). Concrete renderer
* factories use this to make their headless (shared) GL context current.
*/
void bind(ruis::render::native_window& win) const
static void bind_window_context(ruis::render::native_window& win)
{
win.bind_rendering_context();
}

/**
* @brief Make this factory's shared rendering context current.
*
* The default (empty) implementation is for renderers that have no notion
* of a current context (e.g. Vulkan). GL-based factories override it to
* make their shared (headless) GL context current. Called by
* ruis::render::context when the last render context is destroyed, so
* that the shared render objects created by the factory can be destroyed
* with a valid current context.
*/
virtual void bind() const {}

public:
factory(const factory&) = delete;
factory& operator=(const factory&) = delete;
Expand Down
Loading