Explorar el Código

Add a get_screenshot returning a Texture

rdb hace 14 años
padre
commit
cdcd003ec3

+ 25 - 8
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;
 }
 
 ////////////////////////////////////////////////////////////////////

+ 1 - 0
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();
 

+ 12 - 0
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

+ 1 - 0
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();