diff --git a/panda/src/display/displayRegion.cxx b/panda/src/display/displayRegion.cxx index cfe048f56d..4ecebb3074 100644 --- a/panda/src/display/displayRegion.cxx +++ b/panda/src/display/displayRegion.cxx @@ -508,6 +508,28 @@ save_screenshot(const Filename &filename, const string &image_comment) { //////////////////////////////////////////////////////////////////// bool DisplayRegion:: get_screenshot(PNMImage &image) { + PT(Texture) tex = get_screenshot(); + + if (tex == NULL) { + return false; + } + + if (!tex->store(image)) { + return false; + } + + return true; +} + +//////////////////////////////////////////////////////////////////// +// Function: DisplayRegion::get_screenshot +// Access: Published +// Description: Captures the most-recently rendered image from the +// framebuffer and returns it as a Texture, or NULL +// on failure. +//////////////////////////////////////////////////////////////////// +PT(Texture) DisplayRegion:: +get_screenshot() { Thread *current_thread = Thread::get_current_thread(); GraphicsOutput *window = get_window(); @@ -517,25 +539,20 @@ get_screenshot(PNMImage &image) { nassertr(gsg != (GraphicsStateGuardian *)NULL, false); if (!window->begin_frame(GraphicsOutput::FM_refresh, current_thread)) { - return false; + return NULL; } - // Create a temporary texture to receive the framebuffer image. PT(Texture) tex = new Texture; RenderBuffer buffer = gsg->get_render_buffer(get_screenshot_buffer_type(), _window->get_fb_properties()); if (!gsg->framebuffer_copy_to_ram(tex, -1, this, buffer)) { - return false; + return NULL; } window->end_frame(GraphicsOutput::FM_refresh, current_thread); - if (!tex->store(image)) { - return false; - } - - return true; + return tex; } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/display/displayRegion.h b/panda/src/display/displayRegion.h index cbdb6972b2..da49292d5d 100644 --- a/panda/src/display/displayRegion.h +++ b/panda/src/display/displayRegion.h @@ -131,6 +131,7 @@ PUBLISHED: bool save_screenshot( const Filename &filename, const string &image_comment = ""); bool get_screenshot(PNMImage &image); + PT(Texture) get_screenshot(); virtual PT(PandaNode) make_cull_result_graph(); diff --git a/panda/src/display/graphicsOutput.I b/panda/src/display/graphicsOutput.I index e230bb5fdf..8a67eed033 100644 --- a/panda/src/display/graphicsOutput.I +++ b/panda/src/display/graphicsOutput.I @@ -766,6 +766,18 @@ get_screenshot(PNMImage &image) { return _overlay_display_region->get_screenshot(image); } +//////////////////////////////////////////////////////////////////// +// Function: GraphicsOutput::get_screenshot +// Access: Published +// Description: Captures the most-recently rendered image from the +// framebuffer and returns it as Texture, or NULL on +// failure. +//////////////////////////////////////////////////////////////////// +INLINE PT(Texture) GraphicsOutput:: +get_screenshot() { + return _overlay_display_region->get_screenshot(); +} + //////////////////////////////////////////////////////////////////// // Function: GraphicsOutput::flip_ready // Access: Public diff --git a/panda/src/display/graphicsOutput.h b/panda/src/display/graphicsOutput.h index d4fcf95dd9..3d96276171 100644 --- a/panda/src/display/graphicsOutput.h +++ b/panda/src/display/graphicsOutput.h @@ -196,6 +196,7 @@ PUBLISHED: INLINE bool save_screenshot( const Filename &filename, const string &image_comment = ""); INLINE bool get_screenshot(PNMImage &image); + INLINE PT(Texture) get_screenshot(); NodePath get_texture_card();