From 307b0afd05b49f95cc8725dfedbcf18066c0a948 Mon Sep 17 00:00:00 2001 From: khillesl <> Date: Thu, 2 Aug 2001 18:29:14 +0000 Subject: [PATCH] If the sync flag is set in GraphicsWindow, end_frame flushes the pipe, but doesn't swap buffers. To swap buffers, call GraphicsWindow.swap() --- panda/src/display/graphicsWindow.I | 23 ++++++++++++++++++++++ panda/src/display/graphicsWindow.cxx | 12 +++++++++++ panda/src/display/graphicsWindow.h | 7 +++++++ panda/src/glxdisplay/glxGraphicsWindow.cxx | 8 +++++++- panda/src/glxdisplay/glxGraphicsWindow.h | 2 ++ panda/src/wgldisplay/wglGraphicsWindow.cxx | 12 ++++++++++- panda/src/wgldisplay/wglGraphicsWindow.h | 1 + 7 files changed, 63 insertions(+), 2 deletions(-) diff --git a/panda/src/display/graphicsWindow.I b/panda/src/display/graphicsWindow.I index 6baff9a4ee..23920519c4 100644 --- a/panda/src/display/graphicsWindow.I +++ b/panda/src/display/graphicsWindow.I @@ -288,3 +288,26 @@ get_button_event(int device) { return _input_devices[device].get_button_event(); } +//////////////////////////////////////////////////////////////////// +// Function: GraphicsWindow::set_sync +// Access: Public +// Description: Sets flag for whether the buffer swap is done +// implicitely at the end of each frame, or done +// explicitely for the purpose of synchronization. +//////////////////////////////////////////////////////////////////// +INLINE void GraphicsWindow:: +set_sync(const bool b) { + _is_synced = b; +} + +//////////////////////////////////////////////////////////////////// +// Function: GraphicsWindow::get_sync +// Access: Public +// Description: Returns whether buffer swap is done explicitely by +// call to swap() method. +//////////////////////////////////////////////////////////////////// +INLINE bool GraphicsWindow:: +get_sync() const { + return _is_synced; +} + diff --git a/panda/src/display/graphicsWindow.cxx b/panda/src/display/graphicsWindow.cxx index 89c5bb6211..0147cffd92 100644 --- a/panda/src/display/graphicsWindow.cxx +++ b/panda/src/display/graphicsWindow.cxx @@ -140,6 +140,7 @@ GraphicsWindow(GraphicsPipe *pipe) : Configurable() { _idle_callback = NULL; _resize_callback = NULL; _frame_number = 0; + _is_synced = false; } //////////////////////////////////////////////////////////////////// @@ -157,6 +158,7 @@ GraphicsWindow(GraphicsPipe *pipe, _draw_callback = NULL; _idle_callback = NULL; _resize_callback = NULL; + _is_synced = false; } //////////////////////////////////////////////////////////////////// @@ -601,6 +603,16 @@ void GraphicsWindow::read_priorities(void) { } } +//////////////////////////////////////////////////////////////////// +// Function: GraphicsWindow::swap +// Access: Public +// Description: Swaps buffers explicitely as synchronization +// mechanism. +//////////////////////////////////////////////////////////////////// +void GraphicsWindow:: +swap() { +} + void GraphicsWindow::deactivate_window(void) { return; } void GraphicsWindow::reactivate_window(void) { return; } diff --git a/panda/src/display/graphicsWindow.h b/panda/src/display/graphicsWindow.h index 421d905a6f..fc228dd3f7 100644 --- a/panda/src/display/graphicsWindow.h +++ b/panda/src/display/graphicsWindow.h @@ -121,6 +121,11 @@ PUBLISHED: INLINE void set_frame_number(const int); INLINE int get_frame_number() const; + INLINE void set_sync(const bool); + INLINE bool get_sync() const; + + virtual void swap(); + public: virtual void resized(const int, const int); @@ -196,6 +201,8 @@ protected: vfnii _resize_function; int _frame_number; + bool _is_synced; + protected: Callback *_draw_callback; diff --git a/panda/src/glxdisplay/glxGraphicsWindow.cxx b/panda/src/glxdisplay/glxGraphicsWindow.cxx index cf767c6c01..50872ea746 100644 --- a/panda/src/glxdisplay/glxGraphicsWindow.cxx +++ b/panda/src/glxdisplay/glxGraphicsWindow.cxx @@ -673,12 +673,18 @@ void glxGraphicsWindow::end_frame( void ) { PStatTimer timer(_swap_pcollector); - glXSwapBuffers(_display, _xwindow); + if(_is_synced)glFinish(); + else glXSwapBuffers(_display, _xwindow); } GraphicsWindow::end_frame(); } +void glxGraphicsWindow::swap() +{ + if(_is_synced) glXSwapBuffers(_display, _xwindow); +} + //////////////////////////////////////////////////////////////////// // Function: handle_reshape // Access: diff --git a/panda/src/glxdisplay/glxGraphicsWindow.h b/panda/src/glxdisplay/glxGraphicsWindow.h index 037ca57c40..17d19d8c19 100644 --- a/panda/src/glxdisplay/glxGraphicsWindow.h +++ b/panda/src/glxdisplay/glxGraphicsWindow.h @@ -55,6 +55,8 @@ public: virtual void update(void); virtual void end_frame( void ); + virtual void swap(void); + INLINE Window get_xwindow(void) { return _xwindow; } virtual TypeHandle get_gsg_type() const; diff --git a/panda/src/wgldisplay/wglGraphicsWindow.cxx b/panda/src/wgldisplay/wglGraphicsWindow.cxx index 9153497f20..91dd4181bf 100644 --- a/panda/src/wgldisplay/wglGraphicsWindow.cxx +++ b/panda/src/wgldisplay/wglGraphicsWindow.cxx @@ -1022,11 +1022,21 @@ void wglGraphicsWindow::end_frame(void) { { PStatTimer timer(_swap_pcollector); - SwapBuffers(_hdc); + if(_is_synced) glFinish(); + else SwapBuffers(_hdc); } GraphicsWindow::end_frame(); } +//////////////////////////////////////////////////////////////////// +// Function: swap +// Access: +// Description: Swaps the front and back buffers explicitly. +//////////////////////////////////////////////////////////////////// +void wglGraphicsWindow::swap(void) { + if(_is_synced)SwapBuffers(_hdc); +} + //////////////////////////////////////////////////////////////////// // Function: handle_reshape // Access: diff --git a/panda/src/wgldisplay/wglGraphicsWindow.h b/panda/src/wgldisplay/wglGraphicsWindow.h index e37b118c29..b217d7d5df 100644 --- a/panda/src/wgldisplay/wglGraphicsWindow.h +++ b/panda/src/wgldisplay/wglGraphicsWindow.h @@ -66,6 +66,7 @@ public: virtual bool supports_update() const; virtual void update(void); virtual void end_frame( void ); + virtual void swap( void ); virtual TypeHandle get_gsg_type() const; static GraphicsWindow* make_wglGraphicsWindow(const FactoryParams ¶ms);