From 11f94c964a9ea5eede88d04a3ab5d479d87a691a Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 20 Feb 2004 02:01:50 +0000 Subject: [PATCH] try some more to get pbuffers to work without call to SwapBuffers --- panda/src/wgldisplay/wglGraphicsBuffer.cxx | 56 ++++++++++------------ panda/src/wgldisplay/wglGraphicsBuffer.h | 2 - panda/src/wgldisplay/wglGraphicsWindow.cxx | 4 +- 3 files changed, 25 insertions(+), 37 deletions(-) diff --git a/panda/src/wgldisplay/wglGraphicsBuffer.cxx b/panda/src/wgldisplay/wglGraphicsBuffer.cxx index 3ed82ed9b4..49f37e2d59 100644 --- a/panda/src/wgldisplay/wglGraphicsBuffer.cxx +++ b/panda/src/wgldisplay/wglGraphicsBuffer.cxx @@ -42,6 +42,14 @@ wglGraphicsBuffer(GraphicsPipe *pipe, GraphicsStateGuardian *gsg, _window_dc = (HDC)0; _pbuffer = (HPBUFFERARB)0; _pbuffer_dc = (HDC)0; + + // Since the pbuffer (or window, if we use a hidden window) never + // gets flipped, we get screenshots from the same buffer we draw + // into. + + // Actually, because of an apparent driver bug in nVidia drivers, we + // must flip the pbuffer after all. + // _screenshot_buffer_type = _draw_buffer_type; } //////////////////////////////////////////////////////////////////// @@ -123,9 +131,23 @@ end_frame() { // texture in the first place (but I don't have a card that // supports that right now). nassertv(has_texture()); + DisplayRegion dr(this, _x_size, _y_size); RenderBuffer buffer = _gsg->get_render_buffer(get_draw_buffer_type()); get_texture()->copy(_gsg, &dr, buffer); + + // It appears that the nVidia graphics driver 5.3.0.3, dated + // 11/17/2003 will get confused with the above copy operation and + // copy the texture from the wrong window, unless we immediately + // swap buffers in the pbuffer, even though there's no reason to + // swap buffers otherwise. This is unfortunate, because it means + // we can't use single-buffered pbuffers (for which SwapBuffers is + // a no-op). + if (_pbuffer_dc) { + SwapBuffers(_pbuffer_dc); + } else if (_window_dc) { + SwapBuffers(_window_dc); + } } } @@ -166,38 +188,6 @@ release_gsg() { GraphicsBuffer::release_gsg(); } -//////////////////////////////////////////////////////////////////// -// Function: wglGraphicsBuffer::begin_flip -// Access: Public, Virtual -// Description: This function will be called within the draw thread -// after end_frame() has been called on all windows, to -// initiate the exchange of the front and back buffers. -// -// This should instruct the window to prepare for the -// flip at the next video sync, but it should not wait. -// -// We have the two separate functions, begin_flip() and -// end_flip(), to make it easier to flip all of the -// windows at the same time. -//////////////////////////////////////////////////////////////////// -void wglGraphicsBuffer:: -begin_flip() { - // In principle, we shouldn't need to flip the pbuffer. But it - // seems that if we don't, at least on my nVidia driver, it won't - // copy to texture properly somehow. - - if (_gsg != (GraphicsStateGuardian *)NULL) { - make_current(); - glFinish(); - - if (_pbuffer_dc) { - SwapBuffers(_pbuffer_dc); - } else { - SwapBuffers(_window_dc); - } - } -} - //////////////////////////////////////////////////////////////////// // Function: wglGraphicsBuffer::process_events // Access: Public, Virtual @@ -300,6 +290,8 @@ open_buffer() { DestroyWindow(_window); _window = 0; } + + SwapBuffers(_pbuffer_dc); } _is_valid = true; diff --git a/panda/src/wgldisplay/wglGraphicsBuffer.h b/panda/src/wgldisplay/wglGraphicsBuffer.h index 2a81ba272f..0b0af8132d 100644 --- a/panda/src/wgldisplay/wglGraphicsBuffer.h +++ b/panda/src/wgldisplay/wglGraphicsBuffer.h @@ -52,8 +52,6 @@ public: virtual void make_current(); virtual void release_gsg(); - virtual void begin_flip(); - virtual void process_events(); protected: diff --git a/panda/src/wgldisplay/wglGraphicsWindow.cxx b/panda/src/wgldisplay/wglGraphicsWindow.cxx index d06c9737c2..06e760d34a 100644 --- a/panda/src/wgldisplay/wglGraphicsWindow.cxx +++ b/panda/src/wgldisplay/wglGraphicsWindow.cxx @@ -200,9 +200,7 @@ release_gsg() { //////////////////////////////////////////////////////////////////// void wglGraphicsWindow:: begin_flip() { - if (_gsg != (GraphicsStateGuardian *)NULL) { - make_current(); - glFinish(); + if (_hdc) { SwapBuffers(_hdc); } }