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;
92 Thread *current_thread = Thread::get_current_thread();
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);
239 nassertv(Thread::get_current_pipeline_stage() == 0);
241 CDWriter cdata(_cycler);
242 cdata->_stereo_channel = stereo_channel;
243 cdata->_tex_view_offset = (stereo_channel == Lens::SC_right) ? 1 : 0;
257 nassertv(Thread::get_current_pipeline_stage() == 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;
311 get_cull_traverser() {
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)) {
478 Thread *current_thread = Thread::get_current_thread();
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;
static ClockObject * get_global_clock()
Returns a pointer to the global ClockObject.
RenderBuffer get_render_buffer(int buffer_type, const FrameBufferProperties &prop)
Returns a RenderBuffer object suitable for operating on the requested set of buffers.
A basic node of the scene graph or data graph.
void cleanup()
Cleans up some pointers associated with the DisplayRegion to help reduce the chance of memory leaks d...
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,...
Encapsulates the data from a DisplayRegion, pre-fetched for one stage of the pipeline.
set_cull_traverser
Specifies the CullTraverser that will be used to draw the contents of this DisplayRegion.
The name of this class derives from the fact that we originally implemented it as a layer on top of t...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A base class for any number of different kinds of lenses, linear and otherwise.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool is_empty() const
Returns true if the NodePath contains no nodes.
virtual void prepare_display_region(DisplayRegionPipelineReader *dr)
Makes the specified DisplayRegion current.
static void do_cull(CullHandler *cull_handler, SceneSetup *scene_setup, GraphicsStateGuardian *gsg, Thread *current_thread)
Fires off a cull traversal using the indicated camera.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool get_screenshot(PNMImage &image)
Captures the most-recently rendered image from the framebuffer into the indicated PNMImage.
This class is similar to CycleDataWriter, except it allows writing to a particular stage of the pipel...
A single page of data maintained by a PipelineCycler.
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
void compute_pixels_all_stages()
Computes the pixel locations of the DisplayRegion within its window.
bool write(const Filename &filename, PNMFileType *type=nullptr) const
Writes the image to the indicated filename.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
is_stereo
Returns true if this is a StereoDisplayRegion, false otherwise.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void compute_pixels()
Computes the pixel locations of the DisplayRegion within its window.
int get_fb_y_size() const
Returns the internal height of the window or buffer.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
get_pipeline_stage
Returns the Pipeline stage number associated with this thread.
static Filename make_screenshot_filename(const std::string &prefix="screenshot")
Synthesizes a suitable default filename for passing to save_screenshot().
PT(Texture) DisplayRegion
Captures the most-recently rendered image from the framebuffer and returns it as a Texture,...
get_engine
Returns the graphics engine that created this output.
set_stereo_channel
Specifies whether the DisplayRegion represents the left or right channel of a stereo pair,...
PStatCollector & get_draw_window_pcollector()
Returns a PStatCollector for timing the draw operation for just this GraphicsOutput.
set_incomplete_render
Sets the incomplete_render flag.
A lightweight class that represents a single element that may be timed and/or counted via stats.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_current_thread
Returns a pointer to the currently-executing Thread object.
virtual bool supports_pixel_zoom() const
Returns true if a call to set_pixel_zoom() will be respected, false if it will be ignored.
CullResult * get_cull_result(Thread *current_thread) const
Returns the CullResult value that was stored on this DisplayRegion, presumably by the last successful...
set_tex_view_offset
Sets the current texture view offset for this DisplayRegion.
This defines the abstract interface for an object that receives Geoms identified by the CullTraverser...
get_frame_count
Returns the number of times tick() has been called since the ClockObject was created,...
The name of a file, such as a texture file or an Egg file.
get_name
Returns the name of the referenced node.
get_camera
Returns the camera associated with this DisplayRegion, or an empty NodePath if no camera is associate...
get_pipe
Returns the GraphicsPipe that this window is associated with.
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_color_active() const
Returns the current setting of the flag that indicates whether the color buffer should be cleared eve...
bool save_screenshot(const Filename &filename, const std::string &image_comment="")
Saves a screenshot of the region to the indicated filename.
An object to create GraphicsOutputs that share a particular 3-D API.
bool get_clear_depth_active() const
Returns the current setting of the flag that indicates whether the depth buffer should be cleared eve...
get_scene
Returns the scene that will be rendered by the camera.
int get_screenshot_buffer_type() const
Returns the RenderBuffer that should be used for capturing screenshots from this particular DrawableR...
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
set_texture_reload_priority
Specifies an integer priority which is assigned to any asynchronous texture reload requests spawned w...
int get_draw_stage() const
Returns the pipeline stage from which the draw thread should access data.
This is a base class for the various different classes that represent the result of a frame of render...
int get_draw_buffer_type() const
Returns the RenderBuffer into which the GSG should issue draw commands.
set_target_tex_page
This is a special parameter that is only used when rendering the faces of a cube map or multipage and...
get_inverted
Returns the current setting of the inverted flag.
set_camera
Sets the camera that is associated with this DisplayRegion.
This stores the result of a BinCullHandler traversal: an ordered collection of CullBins,...
int get_fb_x_size() const
Returns the internal width of the window or buffer.
PandaNode * node() const
Returns the referenced node of the path.
A thread; that is, a lightweight process.
Encapsulates all the communication with a particular instance of a given rendering backend.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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...
set_lens_index
Sets the lens index, allows for multiple lenses to be attached to a camera.
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_active
Sets the active flag associated with the DisplayRegion.
This class is the main interface to controlling the render process.
PStatCollector & get_cull_window_pcollector()
Returns a PStatCollector for timing the cull operation for just this GraphicsOutput.
bool has_size() const
Returns true if the size of the window/frame buffer is known, false otherwise.
TypeHandle is the identifier used to differentiate C++ class types.
set_dimensions
Changes the portion of the framebuffer this DisplayRegion corresponds to.
This object holds the camera position, etc., and other general setup information for rendering a part...
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.
A RenderBuffer is an arbitrary subset of the various layers (depth buffer, color buffer,...
get_gsg
Returns the GSG that is associated with this 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.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
set_sort
Sets the sort value associated with the DisplayRegion.
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
const GraphicsThreadingModel & get_threading_model() const
Returns the threading model that was used to create this GSG.
GraphicsPipe * get_pipe() const
Returns the GraphicsPipe that this DisplayRegion is ultimately associated with, or NULL if no pipe is...
const FrameBufferProperties & get_fb_properties() const
Returns the framebuffer properties of the window.