Add a get_screenshot returning a Texture

This commit is contained in:
rdb 2011-05-01 09:14:18 +00:00
parent 0807a74605
commit cdcd003ec3
4 changed files with 39 additions and 8 deletions

View File

@ -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;
}
////////////////////////////////////////////////////////////////////

View File

@ -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();

View File

@ -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

View File

@ -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();