Browse Source

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()
rdb 10 months ago
parent
commit
91f124e2f1
2 changed files with 9 additions and 7 deletions
  1. 5 6
      panda/src/display/graphicsEngine.cxx
  2. 4 1
      panda/src/display/graphicsEngine.h

+ 5 - 6
panda/src/display/graphicsEngine.cxx

@@ -152,8 +152,9 @@ INLINE static bool operator < (const CullKey &a, const CullKey &b) {
  * any Pipeline you choose.
  * any Pipeline you choose.
  */
  */
 GraphicsEngine::
 GraphicsEngine::
-GraphicsEngine(Pipeline *pipeline) :
+GraphicsEngine(ClockObject *clock, Pipeline *pipeline) :
   _pipeline(pipeline),
   _pipeline(pipeline),
+  _clock(clock),
   _app("app"),
   _app("app"),
   _lock("GraphicsEngine::_lock"),
   _lock("GraphicsEngine::_lock"),
   _loaded_textures_lock("GraphicsEngine::_loaded_textures_lock")
   _loaded_textures_lock("GraphicsEngine::_loaded_textures_lock")
@@ -729,11 +730,9 @@ render_frame() {
   // been rendered).
   // been rendered).
   open_windows();
   open_windows();
 
 
-  ClockObject *global_clock = ClockObject::get_global_clock();
-
   if (display_cat.is_spam()) {
   if (display_cat.is_spam()) {
     display_cat.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
 #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");
       throw_event("clock_error");
     }
     }
 
 

+ 4 - 1
panda/src/display/graphicsEngine.h

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