29 TypeHandle DisplayRegionPipelineReader::_type_handle;
35 DisplayRegion(
GraphicsOutput *window,
const LVecBase4 &dimensions) :
37 _incomplete_render(true),
38 _texture_reload_priority(0),
39 _cull_region_pcollector(
"Cull:Invalid"),
40 _draw_region_pcollector(
"Draw:Invalid")
45 set_dimensions(0, dimensions);
46 compute_pixels_all_stages();
48 _window->add_display_region(
this);
61 nassertv(_window ==
nullptr);
71 if (cdata->_camera_node !=
nullptr) {
73 cdata->_camera_node->remove_display_region(
this);
75 cdata->_camera_node =
nullptr;
79 cdata_cull->_cull_result =
nullptr;
93 CDWriter cdata(_cycler,
true, current_thread);
94 cdata->_lens_index = index;
108 CDWriter cdata(_cycler,
true, current_thread);
110 cdata->_regions[i]._dimensions = dimensions;
112 if (_window !=
nullptr && _window->
has_size()) {
123 return (_window !=
nullptr) ? _window->
get_pipe() :
nullptr;
147 CDWriter cdata(_cycler,
true);
149 Camera *camera_node =
nullptr;
151 DCAST_INTO_V(camera_node, camera.
node());
154 if (camera_node != cdata->_camera_node) {
158 if (cdata->_camera_node !=
nullptr) {
160 cdata->_camera_node->remove_display_region(
this);
162 cdata->_camera_node = camera_node;
163 if (cdata->_camera_node !=
nullptr) {
165 cdata->_camera_node->add_display_region(
this);
169 cdata->_camera = camera;
182 CDWriter cdata(_cycler,
true, current_thread);
184 if (active != cdata->_active) {
185 cdata->_active = active;
186 win_display_regions_changed();
201 CDWriter cdata(_cycler,
true, current_thread);
203 if (sort != cdata->_sort) {
205 win_display_regions_changed();
237 nassertv(
is_stereo() || stereo_channel != Lens::SC_stereo);
241 CDWriter cdata(_cycler);
242 cdata->_stereo_channel = stereo_channel;
243 cdata->_tex_view_offset = (stereo_channel == Lens::SC_right) ? 1 : 0;
259 CDWriter cdata(_cycler);
260 cdata->_tex_view_offset = tex_view_offset;
277 _incomplete_render = incomplete_render;
293 _texture_reload_priority = texture_reload_priority;
312 if (_trav ==
nullptr) {
336 CDWriter cdata(_cycler,
true, current_thread);
337 cdata->_target_tex_page = page;
344 output(std::ostream &out)
const {
345 CDReader cdata(_cycler);
346 out <<
"DisplayRegion(" << cdata->_regions[0]._dimensions
347 <<
")=pixels(" << cdata->_regions[0]._pixels <<
")";
361 time_t now = time(
nullptr);
362 struct tm *ttm = localtime(&now);
365 static const int buffer_size = 1024;
366 char buffer[buffer_size];
368 std::ostringstream filename_strm;
371 while (i < screenshot_filename.length()) {
372 char ch1 = screenshot_filename[i++];
373 if (ch1 ==
'%' && i < screenshot_filename.length()) {
374 char ch2 = screenshot_filename[i++];
375 if (ch2 ==
'~' && i < screenshot_filename.length()) {
376 char ch3 = screenshot_filename[i++];
379 filename_strm << prefix;
383 filename_strm << frame_count;
387 filename_strm << screenshot_extension;
393 char format[3] = {
'%', ch2,
'\0'};
394 if (strftime(buffer, buffer_size, format, ttm)) {
395 for (
char *b = buffer; *b !=
'\0'; b++) {
400 filename_strm <<
'-';
413 filename_strm << ch1;
417 return Filename(filename_strm.str());
447 if (!image.
write(filename)) {
461 if (tex ==
nullptr) {
465 if (!tex->store(image)) {
481 nassertr(window !=
nullptr,
nullptr);
484 nassertr(gsg !=
nullptr,
nullptr);
490 return engine->do_get_screenshot(
this, gsg);
494 if (!window->
begin_frame(GraphicsOutput::FM_refresh, current_thread)) {
512 window->
end_frame(GraphicsOutput::FM_refresh, current_thread);
521 clear_cull_result() {
522 CDCullWriter cdata_cull(_cycler_cull,
true);
523 cdata_cull->_cull_result =
nullptr;
542 make_cull_result_graph() {
544 if (cull_result ==
nullptr) {
547 return cull_result->make_result_graph();
556 if (_window !=
nullptr) {
558 for (
size_t i = 0; i < cdata->_regions.size(); ++i) {
571 if (_window !=
nullptr) {
572 OPEN_ITERATE_ALL_STAGES(_cycler) {
574 for (
size_t i = 0; i < cdata->_regions.size(); ++i) {
579 CLOSE_ITERATE_ALL_STAGES(_cycler);
590 for (
size_t i = 0; i < cdata->_regions.size(); ++i) {
591 do_compute_pixels(i, x_size, y_size, cdata);
603 OPEN_ITERATE_ALL_STAGES(_cycler) {
605 for (
size_t i = 0; i < cdata->_regions.size(); ++i) {
606 do_compute_pixels(i, x_size, y_size, cdata);
609 CLOSE_ITERATE_ALL_STAGES(_cycler);
624 if (_window !=
nullptr) {
638 win_display_regions_changed() {
639 if (_window !=
nullptr) {
640 _window->win_display_regions_changed();
649 do_compute_pixels(
int i,
int x_size,
int y_size, CData *cdata) {
650 if (display_cat.is_debug()) {
652 <<
"DisplayRegion::do_compute_pixels(" << x_size <<
", " << y_size <<
")\n";
655 Region ®ion = cdata->_regions[i];
657 region._pixels[0] = int((region._dimensions[0] * x_size) + 0.5);
658 region._pixels[1] = int((region._dimensions[1] * x_size) + 0.5);
659 region._pixels_i[0] = region._pixels[0];
660 region._pixels_i[1] = region._pixels[1];
662 nassertv(_window !=
nullptr);
665 region._pixels[2] = int(((1.0f - region._dimensions[3]) * y_size) + 0.5);
666 region._pixels[3] = int(((1.0f - region._dimensions[2]) * y_size) + 0.5);
667 region._pixels_i[2] = int((region._dimensions[3] * y_size) + 0.5);
668 region._pixels_i[3] = int((region._dimensions[2] * y_size) + 0.5);
672 region._pixels[2] = int((region._dimensions[2] * y_size) + 0.5);
673 region._pixels[3] = int((region._dimensions[3] * y_size) + 0.5);
674 region._pixels_i[2] = int(((1.0f - region._dimensions[2]) * y_size) + 0.5);
675 region._pixels_i[3] = int(((1.0f - region._dimensions[3]) * y_size) + 0.5);
688 set_active_index(
int index) {
689 #if defined(DO_PSTATS) || !defined(NDEBUG)
690 std::ostringstream strm;
697 if (camera_node !=
nullptr) {
707 strm <<
"#" << index;
709 _debug_name = strm.str();
732 DisplayRegion::CData::
735 _camera_node(nullptr),
738 _stereo_channel(
Lens::SC_mono),
740 _target_tex_page(-1),
741 _scissor_enabled(true)
743 _regions.push_back(Region());
749 DisplayRegion::CData::
750 CData(
const DisplayRegion::CData ©) :
751 _regions(copy._regions),
752 _lens_index(copy._lens_index),
753 _camera(copy._camera),
754 _camera_node(copy._camera_node),
755 _active(copy._active),
757 _stereo_channel(copy._stereo_channel),
758 _tex_view_offset(copy._tex_view_offset),
759 _target_tex_page(copy._target_tex_page),
760 _scissor_enabled(copy._scissor_enabled)
769 return new CData(*
this);
777 return new CDataCull(*
this);
786 return (_object->_window !=
nullptr) ? _object->_window->
get_pipe() :
nullptr;
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A node that can be positioned around in the scene graph to represent a point of view for rendering a ...
get_scene
Returns the scene that will be rendered by the camera.
get_frame_count
Returns the number of times tick() has been called since the ClockObject was created,...
static ClockObject * get_global_clock()
Returns a pointer to the global ClockObject.
This defines the abstract interface for an object that receives Geoms identified by the CullTraverser...
This stores the result of a BinCullHandler traversal: an ordered collection of CullBins,...
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
This class is similar to CycleDataWriter, except it allows writing to a particular stage of the pipel...
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
A single page of data maintained by a PipelineCycler.
Encapsulates the data from a DisplayRegion, pre-fetched for one stage of the pipeline.
GraphicsPipe * get_pipe() const
Returns the GraphicsPipe that this DisplayRegion is ultimately associated with, or NULL if no pipe is...
is_stereo
Returns true if this is a StereoDisplayRegion, false otherwise.
get_cull_traverser
Returns the CullTraverser that will be used to draw the contents of this DisplayRegion.
void compute_pixels()
Computes the pixel locations of the DisplayRegion within its window.
bool save_screenshot(const Filename &filename, const std::string &image_comment="")
Saves a screenshot of the region to the indicated filename.
CullResult * get_cull_result(Thread *current_thread) const
Returns the CullResult value that was stored on this DisplayRegion, presumably by the last successful...
set_camera
Sets the camera that is associated with this DisplayRegion.
set_tex_view_offset
Sets the current texture view offset for this DisplayRegion.
set_target_tex_page
This is a special parameter that is only used when rendering the faces of a cube map or multipage and...
bool get_screenshot(PNMImage &image)
Captures the most-recently rendered image from the framebuffer into the indicated PNMImage.
get_camera
Returns the camera associated with this DisplayRegion, or an empty NodePath if no camera is associate...
set_lens_index
Sets the lens index, allows for multiple lenses to be attached to a camera.
get_window
Returns the GraphicsOutput that this DisplayRegion is ultimately associated with, or NULL if no windo...
void cleanup()
Cleans up some pointers associated with the DisplayRegion to help reduce the chance of memory leaks d...
void compute_pixels_all_stages()
Computes the pixel locations of the DisplayRegion within its window.
get_pipe
Returns the GraphicsPipe that this DisplayRegion is ultimately associated with, or NULL if no pipe is...
set_sort
Sets the sort value associated with the DisplayRegion.
static Filename make_screenshot_filename(const std::string &prefix="screenshot")
Synthesizes a suitable default filename for passing to save_screenshot().
set_cull_traverser
Specifies the CullTraverser that will be used to draw the contents of this DisplayRegion.
set_dimensions
Changes the portion of the framebuffer this DisplayRegion corresponds to.
set_active
Sets the active flag associated with the DisplayRegion.
set_stereo_channel
Specifies whether the DisplayRegion represents the left or right channel of a stereo pair,...
set_texture_reload_priority
Specifies an integer priority which is assigned to any asynchronous texture reload requests spawned w...
virtual bool supports_pixel_zoom() const
Returns true if a call to set_pixel_zoom() will be respected, false if it will be ignored.
Filename save_screenshot_default(const std::string &prefix="screenshot")
Saves a screenshot of the region to a default filename, and returns the filename, or empty string if ...
set_incomplete_render
Sets the incomplete_render flag.
int get_draw_buffer_type() const
Returns the RenderBuffer into which the GSG should issue draw commands.
virtual bool supports_pixel_zoom() const
Returns true if a call to set_pixel_zoom() will be respected, false if it will be ignored.
bool get_clear_depth_active() const
Returns the current setting of the flag that indicates whether the depth buffer should be cleared eve...
bool get_clear_color_active() const
Returns the current setting of the flag that indicates whether the color buffer should be cleared eve...
int get_screenshot_buffer_type() const
Returns the RenderBuffer that should be used for capturing screenshots from this particular DrawableR...
The name of a file, such as a texture file or an Egg file.
This class is the main interface to controlling the render process.
static void do_cull(CullHandler *cull_handler, SceneSetup *scene_setup, GraphicsStateGuardian *gsg, Thread *current_thread)
Fires off a cull traversal using the indicated camera.
This is a base class for the various different classes that represent the result of a frame of render...
int get_fb_x_size() const
Returns the internal width of the window or buffer.
get_inverted
Returns the current setting of the inverted flag.
get_pipe
Returns the GraphicsPipe that this window is associated with.
bool has_size() const
Returns true if the size of the window/frame buffer is known, false otherwise.
get_gsg
Returns the GSG that is associated with this window.
PStatCollector & get_draw_window_pcollector()
Returns a PStatCollector for timing the draw operation for just this GraphicsOutput.
PStatCollector & get_cull_window_pcollector()
Returns a PStatCollector for timing the cull operation for just this GraphicsOutput.
virtual void end_frame(FrameMode mode, Thread *current_thread)
This function will be called within the draw thread after rendering is completed for a given frame.
const FrameBufferProperties & get_fb_properties() const
Returns the framebuffer properties of the window.
virtual bool begin_frame(FrameMode mode, Thread *current_thread)
This function will be called within the draw thread before beginning rendering for a given frame.
int get_fb_y_size() const
Returns the internal height of the window or buffer.
get_engine
Returns the graphics engine that created this output.
An object to create GraphicsOutputs that share a particular 3-D API.
Encapsulates all the communication with a particular instance of a given rendering backend.
virtual bool framebuffer_copy_to_ram(Texture *tex, int view, int z, const DisplayRegion *dr, const RenderBuffer &rb)
Copy the pixels within the indicated display region from the framebuffer into system memory,...
virtual void prepare_display_region(DisplayRegionPipelineReader *dr)
Makes the specified DisplayRegion current.
RenderBuffer get_render_buffer(int buffer_type, const FrameBufferProperties &prop)
Returns a RenderBuffer object suitable for operating on the requested set of buffers.
const GraphicsThreadingModel & get_threading_model() const
Returns the threading model that was used to create this GSG.
int get_draw_stage() const
Returns the pipeline stage from which the draw thread should access data.
A base class for any number of different kinds of lenses, linear and otherwise.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
bool is_empty() const
Returns true if the NodePath contains no nodes.
PandaNode * node() const
Returns the referenced node of the path.
NodePath get_top(Thread *current_thread=Thread::get_current_thread()) const
Returns a singleton NodePath that represents the top of the path, or empty NodePath if this path is e...
get_name
Returns the name of the referenced node.
The name of this class derives from the fact that we originally implemented it as a layer on top of t...
bool write(const Filename &filename, PNMFileType *type=nullptr) const
Writes the image to the indicated filename.
A lightweight class that represents a single element that may be timed and/or counted via stats.
A basic node of the scene graph or data graph.
A RenderBuffer is an arbitrary subset of the various layers (depth buffer, color buffer,...
This object holds the camera position, etc., and other general setup information for rendering a part...
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
A thread; that is, a lightweight process.
get_pipeline_stage
Returns the Pipeline stage number associated with this thread.
get_current_pipeline_stage
Returns the integer pipeline stage associated with the current thread.
get_current_thread
Returns a pointer to the currently-executing Thread object.
TypeHandle is the identifier used to differentiate C++ class types.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PT(Texture) DisplayRegion
Captures the most-recently rendered image from the framebuffer and returns it as a Texture,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.