mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 09:52:27 -04:00
Add a get_screenshot returning a Texture
This commit is contained in:
parent
0807a74605
commit
cdcd003ec3
@ -508,6 +508,28 @@ save_screenshot(const Filename &filename, const string &image_comment) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
bool DisplayRegion::
|
bool DisplayRegion::
|
||||||
get_screenshot(PNMImage &image) {
|
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();
|
Thread *current_thread = Thread::get_current_thread();
|
||||||
|
|
||||||
GraphicsOutput *window = get_window();
|
GraphicsOutput *window = get_window();
|
||||||
@ -517,25 +539,20 @@ get_screenshot(PNMImage &image) {
|
|||||||
nassertr(gsg != (GraphicsStateGuardian *)NULL, false);
|
nassertr(gsg != (GraphicsStateGuardian *)NULL, false);
|
||||||
|
|
||||||
if (!window->begin_frame(GraphicsOutput::FM_refresh, current_thread)) {
|
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;
|
PT(Texture) tex = new Texture;
|
||||||
|
|
||||||
RenderBuffer buffer = gsg->get_render_buffer(get_screenshot_buffer_type(),
|
RenderBuffer buffer = gsg->get_render_buffer(get_screenshot_buffer_type(),
|
||||||
_window->get_fb_properties());
|
_window->get_fb_properties());
|
||||||
if (!gsg->framebuffer_copy_to_ram(tex, -1, this, buffer)) {
|
if (!gsg->framebuffer_copy_to_ram(tex, -1, this, buffer)) {
|
||||||
return false;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
window->end_frame(GraphicsOutput::FM_refresh, current_thread);
|
window->end_frame(GraphicsOutput::FM_refresh, current_thread);
|
||||||
|
|
||||||
if (!tex->store(image)) {
|
return tex;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
@ -131,6 +131,7 @@ PUBLISHED:
|
|||||||
bool save_screenshot(
|
bool save_screenshot(
|
||||||
const Filename &filename, const string &image_comment = "");
|
const Filename &filename, const string &image_comment = "");
|
||||||
bool get_screenshot(PNMImage &image);
|
bool get_screenshot(PNMImage &image);
|
||||||
|
PT(Texture) get_screenshot();
|
||||||
|
|
||||||
virtual PT(PandaNode) make_cull_result_graph();
|
virtual PT(PandaNode) make_cull_result_graph();
|
||||||
|
|
||||||
|
@ -766,6 +766,18 @@ get_screenshot(PNMImage &image) {
|
|||||||
return _overlay_display_region->get_screenshot(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
|
// Function: GraphicsOutput::flip_ready
|
||||||
// Access: Public
|
// Access: Public
|
||||||
|
@ -196,6 +196,7 @@ PUBLISHED:
|
|||||||
INLINE bool save_screenshot(
|
INLINE bool save_screenshot(
|
||||||
const Filename &filename, const string &image_comment = "");
|
const Filename &filename, const string &image_comment = "");
|
||||||
INLINE bool get_screenshot(PNMImage &image);
|
INLINE bool get_screenshot(PNMImage &image);
|
||||||
|
INLINE PT(Texture) get_screenshot();
|
||||||
|
|
||||||
NodePath get_texture_card();
|
NodePath get_texture_card();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user