From 4d416cce51f18477d9fd2d3764023adf8a0a57e8 Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 18 Feb 2004 19:23:36 +0000 Subject: [PATCH] pbuffers shouldn't flip --- panda/src/display/graphicsOutput.cxx | 16 ++++++- panda/src/display/graphicsOutput.h | 2 + panda/src/glxdisplay/glxGraphicsBuffer.cxx | 49 +++++++++++----------- panda/src/glxdisplay/glxGraphicsBuffer.h | 4 +- 4 files changed, 44 insertions(+), 27 deletions(-) diff --git a/panda/src/display/graphicsOutput.cxx b/panda/src/display/graphicsOutput.cxx index 20ab9ed60f..4633f38e5a 100644 --- a/panda/src/display/graphicsOutput.cxx +++ b/panda/src/display/graphicsOutput.cxx @@ -392,8 +392,7 @@ get_screenshot(PNMImage &image) { PixelBuffer::F_rgb); DisplayRegion dr(_x_size, _y_size); - RenderBuffer rb = _gsg->get_render_buffer(RenderBuffer::T_front); - if (!p.copy(_gsg, &dr, rb)) { + if (!p.copy(_gsg, &dr, get_screenshot_buffer())) { return false; } @@ -630,6 +629,19 @@ declare_channel(int index, GraphicsChannel *chan) { _channels[index] = chan; } +//////////////////////////////////////////////////////////////////// +// Function: GraphicsOutput::get_screenshot_buffer +// Access: Protected, Virtual +// Description: Returns the RenderBuffer that should be used for +// capturing screenshots from this particular +// GraphicsOutput. +//////////////////////////////////////////////////////////////////// +RenderBuffer GraphicsOutput:: +get_screenshot_buffer() { + // By default, this is the front buffer. + return _gsg->get_render_buffer(RenderBuffer::T_front); +} + //////////////////////////////////////////////////////////////////// // Function: GraphicsOutput::do_determine_display_regions // Access: Private diff --git a/panda/src/display/graphicsOutput.h b/panda/src/display/graphicsOutput.h index 3ed8491caf..059cc00c68 100644 --- a/panda/src/display/graphicsOutput.h +++ b/panda/src/display/graphicsOutput.h @@ -26,6 +26,7 @@ #include "displayRegion.h" #include "graphicsStateGuardian.h" #include "clearableRegion.h" +#include "renderBuffer.h" #include "typedWritableReferenceCount.h" #include "pStatCollector.h" @@ -129,6 +130,7 @@ public: protected: void declare_channel(int index, GraphicsChannel *chan); + virtual RenderBuffer get_screenshot_buffer(); protected: PT(GraphicsStateGuardian) _gsg; diff --git a/panda/src/glxdisplay/glxGraphicsBuffer.cxx b/panda/src/glxdisplay/glxGraphicsBuffer.cxx index 12a1781323..d380eacbf9 100644 --- a/panda/src/glxdisplay/glxGraphicsBuffer.cxx +++ b/panda/src/glxdisplay/glxGraphicsBuffer.cxx @@ -91,34 +91,21 @@ release_gsg() { } //////////////////////////////////////////////////////////////////// -// Function: glxGraphicsBuffer::begin_flip +// Function: glxGraphicsBuffer::end_frame // 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. +// after rendering is completed for a given frame. It +// should do whatever finalization is required. //////////////////////////////////////////////////////////////////// void glxGraphicsBuffer:: -begin_flip() { - if (_gsg != (GraphicsStateGuardian *)NULL) { - make_current(); - - if (has_texture()) { - // Use glCopyTexImage2D to copy the framebuffer to the texture. - // This appears to be the only way to "render to a texture" in - // OpenGL; there's no interface to make the offscreen buffer - // itself be a texture. - DisplayRegion dr(_x_size, _y_size); - get_texture()->copy(_gsg, &dr, _gsg->get_render_buffer(RenderBuffer::T_back)); - } - - glXSwapBuffers(_display, _pbuffer); +end_frame() { + if (has_texture()) { + // Use glCopyTexImage2D to copy the framebuffer to the texture. + // This appears to be the only way to "render to a texture" in + // OpenGL; there's no interface to make the offscreen buffer + // itself be a texture. + DisplayRegion dr(_x_size, _y_size); + get_texture()->copy(_gsg, &dr, _gsg->get_render_buffer(RenderBuffer::T_back)); } } @@ -186,3 +173,17 @@ open_buffer() { _is_valid = true; return true; } + +//////////////////////////////////////////////////////////////////// +// Function: glxGraphicsBuffer::get_screenshot_buffer +// Access: Protected, Virtual +// Description: Returns the RenderBuffer that should be used for +// capturing screenshots from this particular +// GraphicsOutput. +//////////////////////////////////////////////////////////////////// +RenderBuffer glxGraphicsBuffer:: +get_screenshot_buffer() { + // Since the pbuffer never gets flipped, we get screenshots from the + // back buffer only. + return _gsg->get_render_buffer(RenderBuffer::T_back); +} diff --git a/panda/src/glxdisplay/glxGraphicsBuffer.h b/panda/src/glxdisplay/glxGraphicsBuffer.h index 5b9487f1ba..797e75842a 100644 --- a/panda/src/glxdisplay/glxGraphicsBuffer.h +++ b/panda/src/glxdisplay/glxGraphicsBuffer.h @@ -39,12 +39,14 @@ public: virtual void make_current(); virtual void release_gsg(); - virtual void begin_flip(); + virtual void end_frame(); protected: virtual void close_buffer(); virtual bool open_buffer(); + virtual RenderBuffer get_screenshot_buffer(); + private: Display *_display; GLXPbuffer _pbuffer;