Skip to content

Commit

Permalink
[render] add postDraw member function to Drawers
Browse files Browse the repository at this point in the history
  • Loading branch information
alemuntoni committed Jan 9, 2025
1 parent f92446f commit 5ff2d13
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
12 changes: 7 additions & 5 deletions vclib/render/include/vclib/bgfx/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ class CanvasBGFX
}
else {
mCurrFrame = bgfx::frame();

// this is required only when using Qt in macOS
#if defined(__APPLE__)
bgfx::frame();
#endif // __APPLE__

DRT::CNV::postDraw(derived());
}

if (mReadRequest != std::nullopt) {
Expand All @@ -200,11 +207,6 @@ class CanvasBGFX
// solicit new frame
derived()->update();
}

// this is probably required only when using Qt
#if defined(__APPLE__) || defined(__linux__)
bgfx::frame(); // needed on unix systems
#endif // __APPLE__ || __linux__
}

/**
Expand Down
1 change: 1 addition & 0 deletions vclib/render/include/vclib/render/concepts/drawer.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ concept DrawerConcept = requires(T&& obj)
{ obj.onResize(uint(), uint()) } -> std::same_as<void>;
{ obj.onDraw(uint()) } -> std::same_as<void>;
{ obj.onDrawContent(uint()) } -> std::same_as<void>;
{ obj.onPostDraw() } -> std::same_as<void>;
};
};

Expand Down
2 changes: 2 additions & 0 deletions vclib/render/include/vclib/render/drawers/plain_drawer.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class PlainDrawer

virtual void onDrawContent(uint viewId) {}

virtual void onPostDraw() {}

protected:
auto* derived() { return static_cast<DRT*>(this); }

Expand Down
15 changes: 15 additions & 0 deletions vclib/render/include/vclib/render/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,14 @@ class Renderer :
...);
}

void cnvPostDraw()
{
// call the onPostDraw member function of each Drawer object.
// NOTE: use static_cast<Drawers*>(this)->function() to call the
// right VIRTUAL function of the Drawer object.
(static_cast<Drawers<Renderer>*>(this)->onPostDraw(), ...);
}

/***** Member functions called by Drawer objects *****/
// Documentation is in the Renderer::DRW inner class

Expand Down Expand Up @@ -528,6 +536,13 @@ class Renderer<WindowManagerT, CanvasT, Drawers...>::CNV
* `onDrawContent(uint())` function for every Drawer object.
*/
static void drawContent(Renderer* r) { r->cnvDrawContent(); }

/**
* @brief The CanvasType has finished drawing and has submitted the new
* frame, and asks the Renderer to call the `onPostDraw()` function for
* every Drawer object.
*/
static void postDraw(Renderer* r) { r->cnvPostDraw(); }
};

/**
Expand Down

0 comments on commit 5ff2d13

Please sign in to comment.