display: Allow setting a custom clock for a GraphicsEngine

This is essential for supporting multiple engines, otherwise both engines will try to tick the global clock in render_frame()
This commit is contained in:
rdb 2025-01-21 12:16:09 +01:00
parent 8c9ba6dc38
commit 91f124e2f1
2 changed files with 9 additions and 7 deletions

View File

@ -152,8 +152,9 @@ INLINE static bool operator < (const CullKey &a, const CullKey &b) {
* any Pipeline you choose.
*/
GraphicsEngine::
GraphicsEngine(Pipeline *pipeline) :
GraphicsEngine(ClockObject *clock, Pipeline *pipeline) :
_pipeline(pipeline),
_clock(clock),
_app("app"),
_lock("GraphicsEngine::_lock"),
_loaded_textures_lock("GraphicsEngine::_loaded_textures_lock")
@ -729,11 +730,9 @@ render_frame() {
// been rendered).
open_windows();
ClockObject *global_clock = ClockObject::get_global_clock();
if (display_cat.is_spam()) {
display_cat.spam()
<< "render_frame() - frame " << global_clock->get_frame_count() << "\n";
<< "render_frame() - frame " << _clock->get_frame_count() << "\n";
}
{
@ -846,8 +845,8 @@ render_frame() {
}
#endif // THREADED_PIPELINE
global_clock->tick(current_thread);
if (global_clock->check_errors(current_thread)) {
_clock->tick(current_thread);
if (_clock->check_errors(current_thread)) {
throw_event("clock_error");
}

View File

@ -33,6 +33,7 @@
#include "loader.h"
#include "referenceCount.h"
#include "renderState.h"
#include "clockObject.h"
class Pipeline;
class DisplayRegion;
@ -53,7 +54,8 @@ class Texture;
*/
class EXPCL_PANDA_DISPLAY GraphicsEngine : public ReferenceCount {
PUBLISHED:
explicit GraphicsEngine(Pipeline *pipeline = nullptr);
explicit GraphicsEngine(ClockObject *clock = ClockObject::get_global_clock(),
Pipeline *pipeline = nullptr);
BLOCKING ~GraphicsEngine();
void set_threading_model(const GraphicsThreadingModel &threading_model);
@ -320,6 +322,7 @@ private:
WindowRenderer *get_window_renderer(const std::string &name, int pipeline_stage);
Pipeline *_pipeline;
ClockObject *const _clock;
Windows _windows;
bool _windows_sorted;