Go to the documentation of this file.
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);
533 make_cull_result_graph() {
535 if (cull_result ==
nullptr) {
538 return cull_result->make_result_graph();
547 if (_window !=
nullptr) {
549 for (
size_t i = 0; i < cdata->_regions.size(); ++i) {
562 if (_window !=
nullptr) {
563 OPEN_ITERATE_ALL_STAGES(_cycler) {
565 for (
size_t i = 0; i < cdata->_regions.size(); ++i) {
570 CLOSE_ITERATE_ALL_STAGES(_cycler);
581 for (
size_t i = 0; i < cdata->_regions.size(); ++i) {
582 do_compute_pixels(i, x_size, y_size, cdata);
594 OPEN_ITERATE_ALL_STAGES(_cycler) {
596 for (
size_t i = 0; i < cdata->_regions.size(); ++i) {
597 do_compute_pixels(i, x_size, y_size, cdata);
600 CLOSE_ITERATE_ALL_STAGES(_cycler);
615 if (_window !=
nullptr) {
629 win_display_regions_changed() {
630 if (_window !=
nullptr) {
631 _window->win_display_regions_changed();
640 do_compute_pixels(
int i,
int x_size,
int y_size, CData *cdata) {
641 if (display_cat.is_debug()) {
643 <<
"DisplayRegion::do_compute_pixels(" << x_size <<
", " << y_size <<
")\n";
646 Region ®ion = cdata->_regions[i];
648 region._pixels[0] = int((region._dimensions[0] * x_size) + 0.5);
649 region._pixels[1] = int((region._dimensions[1] * x_size) + 0.5);
650 region._pixels_i[0] = region._pixels[0];
651 region._pixels_i[1] = region._pixels[1];
653 nassertv(_window !=
nullptr);
656 region._pixels[2] = int(((1.0f - region._dimensions[3]) * y_size) + 0.5);
657 region._pixels[3] = int(((1.0f - region._dimensions[2]) * y_size) + 0.5);
658 region._pixels_i[2] = int((region._dimensions[3] * y_size) + 0.5);
659 region._pixels_i[3] = int((region._dimensions[2] * y_size) + 0.5);
663 region._pixels[2] = int((region._dimensions[2] * y_size) + 0.5);
664 region._pixels[3] = int((region._dimensions[3] * y_size) + 0.5);
665 region._pixels_i[2] = int(((1.0f - region._dimensions[2]) * y_size) + 0.5);
666 region._pixels_i[3] = int(((1.0f - region._dimensions[3]) * y_size) + 0.5);
679 set_active_index(
int index) {
680 #if defined(DO_PSTATS) || !defined(NDEBUG)
681 std::ostringstream strm;
688 if (camera_node !=
nullptr) {
698 strm <<
"#" << index;
700 _debug_name = strm.str();
723 DisplayRegion::CData::
726 _camera_node(nullptr),
729 _stereo_channel(
Lens::SC_mono),
731 _target_tex_page(-1),
732 _scissor_enabled(true)
734 _regions.push_back(Region());
740 DisplayRegion::CData::
741 CData(
const DisplayRegion::CData ©) :
742 _regions(copy._regions),
743 _lens_index(copy._lens_index),
744 _camera(copy._camera),
745 _camera_node(copy._camera_node),
746 _active(copy._active),
748 _stereo_channel(copy._stereo_channel),
749 _tex_view_offset(copy._tex_view_offset),
750 _target_tex_page(copy._target_tex_page),
751 _scissor_enabled(copy._scissor_enabled)
760 return new CData(*
this);
768 return new CDataCull(*
this);
777 return (_object->_window !=
nullptr) ? _object->_window->
get_pipe() :
nullptr;
PStatCollector & get_cull_window_pcollector()
Returns a PStatCollector for timing the cull operation for just this GraphicsOutput.
get_scene
Returns the scene that will be rendered by the camera.
set_tex_view_offset
Sets the current texture view offset for this DisplayRegion.
PStatCollector & get_draw_window_pcollector()
Returns a PStatCollector for timing the draw operation for just this GraphicsOutput.
PT(Texture) DisplayRegion
Captures the most-recently rendered image from the framebuffer and returns it as a Texture,...
bool get_clear_color_active() const
Returns the current setting of the flag that indicates whether the color buffer should be cleared eve...
A single page of data maintained by a PipelineCycler.
bool get_screenshot(PNMImage &image)
Captures the most-recently rendered image from the framebuffer into the indicated PNMImage.
void cleanup()
Cleans up some pointers associated with the DisplayRegion to help reduce the chance of memory leaks d...
A node that can be positioned around in the scene graph to represent a point of view for rendering a ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_engine
Returns the graphics engine that created this output.
set_active
Sets the active flag associated with the DisplayRegion.
A RenderBuffer is an arbitrary subset of the various layers (depth buffer, color buffer,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool get_clear_depth_active() const
Returns the current setting of the flag that indicates whether the depth buffer should be cleared eve...
int get_fb_x_size() const
Returns the internal width of the window or buffer.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int get_screenshot_buffer_type() const
Returns the RenderBuffer that should be used for capturing screenshots from this particular DrawableR...
get_cull_traverser
Returns the CullTraverser that will be used to draw the contents of this DisplayRegion.
static ClockObject * get_global_clock()
Returns a pointer to the global ClockObject.
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
GraphicsPipe * get_pipe() const
Returns the GraphicsPipe that this DisplayRegion is ultimately associated with, or NULL if no pipe is...
set_incomplete_render
Sets the incomplete_render flag.
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
virtual bool supports_pixel_zoom() const
Returns true if a call to set_pixel_zoom() will be respected, false if it will be ignored.
The name of this class derives from the fact that we originally implemented it as a layer on top of t...
RenderBuffer get_render_buffer(int buffer_type, const FrameBufferProperties &prop)
Returns a RenderBuffer object suitable for operating on the requested set of buffers.
void compute_pixels_all_stages()
Computes the pixel locations of the DisplayRegion within its window.
void compute_pixels()
Computes the pixel locations of the DisplayRegion within its window.
This class is the main interface to controlling the render process.
const GraphicsThreadingModel & get_threading_model() const
Returns the threading model that was used to create this GSG.
get_current_thread
Returns a pointer to the currently-executing Thread object.
get_gsg
Returns the GSG that is associated with this window.
This object holds the camera position, etc., and other general setup information for rendering a part...
TypeHandle is the identifier used to differentiate C++ class types.
static Filename make_screenshot_filename(const std::string &prefix="screenshot")
Synthesizes a suitable default filename for passing to save_screenshot().
This is a base class for the various different classes that represent the result of a frame of render...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
int get_draw_stage() const
Returns the pipeline stage from which the draw thread should access data.
bool has_size() const
Returns true if the size of the window/frame buffer is known, false otherwise.
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,...
set_stereo_channel
Specifies whether the DisplayRegion represents the left or right channel of a stereo pair,...
A lightweight class that represents a single element that may be timed and/or counted via stats.
set_dimensions
Changes the portion of the framebuffer this DisplayRegion corresponds to.
set_lens_index
Sets the lens index, allows for multiple lenses to be attached to a camera.
virtual void prepare_display_region(DisplayRegionPipelineReader *dr)
Makes the specified DisplayRegion current.
An object to create GraphicsOutputs that share a particular 3-D API.
A base class for any number of different kinds of lenses, linear and otherwise.
bool save_screenshot(const Filename &filename, const std::string &image_comment="")
Saves a screenshot of the region to the indicated filename.
is_stereo
Returns true if this is a StereoDisplayRegion, false otherwise.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
const FrameBufferProperties & get_fb_properties() const
Returns the framebuffer properties of the window.
This class is similar to CycleDataWriter, except it allows writing to a particular stage of the pipel...
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
get_name
Returns the name of the referenced node.
get_frame_count
Returns the number of times tick() has been called since the ClockObject was created,...
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 ...
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...
int get_fb_y_size() const
Returns the internal height of the window or buffer.
set_target_tex_page
This is a special parameter that is only used when rendering the faces of a cube map or multipage and...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_pipe
Returns the GraphicsPipe that this window is associated with.
set_camera
Sets the camera that is associated with this DisplayRegion.
static void do_cull(CullHandler *cull_handler, SceneSetup *scene_setup, GraphicsStateGuardian *gsg, Thread *current_thread)
Fires off a cull traversal using the indicated camera.
get_current_pipeline_stage
Returns the integer pipeline stage associated with the current thread.
get_pipe
Returns the GraphicsPipe that this DisplayRegion is ultimately associated with, or NULL if no pipe is...
get_camera
Returns the camera associated with this DisplayRegion, or an empty NodePath if no camera is associate...
int get_draw_buffer_type() const
Returns the RenderBuffer into which the GSG should issue draw commands.
CullResult * get_cull_result(Thread *current_thread) const
Returns the CullResult value that was stored on this DisplayRegion, presumably by the last successful...
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.
set_sort
Sets the sort value associated with the DisplayRegion.
get_window
Returns the GraphicsOutput that this DisplayRegion is ultimately associated with, or NULL if no windo...
bool write(const Filename &filename, PNMFileType *type=nullptr) const
Writes the image to the indicated filename.
Encapsulates all the communication with a particular instance of a given rendering backend.
get_pipeline_stage
Returns the Pipeline stage number associated with this thread.
A basic node of the scene graph or data graph.
PandaNode * node() const
Returns the referenced node of the path.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_inverted
Returns the current setting of the inverted flag.
virtual bool supports_pixel_zoom() const
Returns true if a call to set_pixel_zoom() will be respected, false if it will be ignored.
A thread; that is, a lightweight process.
Encapsulates the data from a DisplayRegion, pre-fetched for one stage of the pipeline.
This stores the result of a BinCullHandler traversal: an ordered collection of CullBins,...
set_cull_traverser
Specifies the CullTraverser that will be used to draw the contents of this DisplayRegion.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
set_texture_reload_priority
Specifies an integer priority which is assigned to any asynchronous texture reload requests spawned w...
The name of a file, such as a texture file or an Egg file.
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.
This defines the abstract interface for an object that receives Geoms identified by the CullTraverser...
bool is_empty() const
Returns true if the NodePath contains no nodes.