Panda3D
displayRegion.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file displayRegion.h
10  * @author mike
11  * @date 1997-01-09
12  */
13 
14 #ifndef DISPLAYREGION_H
15 #define DISPLAYREGION_H
16 
17 #include "pandabase.h"
18 
19 #include "typedReferenceCount.h"
20 #include "drawableRegion.h"
21 #include "referenceCount.h"
22 #include "nodePath.h"
23 #include "cullResult.h"
24 #include "sceneSetup.h"
25 #include "pointerTo.h"
26 #include "cycleData.h"
27 #include "cycleDataLockedReader.h"
28 #include "cycleDataReader.h"
29 #include "cycleDataWriter.h"
30 #include "cycleDataStageWriter.h"
31 #include "pipelineCycler.h"
32 #include "config_display.h"
33 #include "lens.h"
34 #include "deletedChain.h"
35 #include "plist.h"
36 #include "pStatCollector.h"
37 #include "cullTraverser.h"
38 #include "callbackObject.h"
39 #include "luse.h"
40 #include "epvector.h"
41 
42 class GraphicsOutput;
43 class GraphicsPipe;
44 class CullHandler;
45 class Camera;
46 class PNMImage;
47 class CullTraverser;
48 
49 /**
50  * A rectangular subregion within a window for rendering into. Typically,
51  * there is one DisplayRegion that covers the whole window, but you may also
52  * create smaller DisplayRegions for having different regions within the
53  * window that represent different scenes. You may also stack up
54  * DisplayRegions like panes of glass, usually for layering 2-d interfaces on
55  * top of a 3-d scene.
56  */
57 class EXPCL_PANDA_DISPLAY DisplayRegion : public TypedReferenceCount, public DrawableRegion {
58 protected:
59  DisplayRegion(GraphicsOutput *window, const LVecBase4 &dimensions);
60  DisplayRegion(const DisplayRegion &copy) = delete;
61  void operator = (const DisplayRegion &copy) = delete;
62 
63 public:
64  virtual ~DisplayRegion();
65  void cleanup();
66 
67  INLINE bool operator < (const DisplayRegion &other) const;
68 
69 PUBLISHED:
70  INLINE int get_num_regions() const;
71  INLINE void set_num_regions(int i);
72  INLINE void get_dimensions(PN_stdfloat &l, PN_stdfloat &r, PN_stdfloat &b, PN_stdfloat &t) const;
73  INLINE void get_dimensions(int i, PN_stdfloat &l, PN_stdfloat &r, PN_stdfloat &b, PN_stdfloat &t) const;
74  INLINE LVecBase4 get_dimensions(int i = 0) const;
75  INLINE PN_stdfloat get_left(int i = 0) const;
76  INLINE PN_stdfloat get_right(int i = 0) const;
77  INLINE PN_stdfloat get_bottom(int i = 0) const;
78  INLINE PN_stdfloat get_top(int i = 0) const;
79  INLINE void set_dimensions(PN_stdfloat l, PN_stdfloat r, PN_stdfloat b, PN_stdfloat t);
80  INLINE void set_dimensions(int i, PN_stdfloat l, PN_stdfloat r, PN_stdfloat b, PN_stdfloat t);
81  INLINE void set_dimensions(const LVecBase4 &dimensions);
82  virtual void set_dimensions(int i, const LVecBase4 &dimensions);
83  MAKE_PROPERTY(dimensions, get_dimensions, set_dimensions);
84 
85  INLINE GraphicsOutput *get_window() const;
86  GraphicsPipe *get_pipe() const;
87  virtual bool is_stereo() const;
88  MAKE_PROPERTY(window, get_window);
89  MAKE_PROPERTY(pipe, get_pipe);
90  MAKE_PROPERTY(stereo, is_stereo);
91 
92  virtual void set_camera(const NodePath &camera);
93  INLINE NodePath get_camera(Thread *current_thread = Thread::get_current_thread()) const;
94  MAKE_PROPERTY(camera, get_camera, set_camera);
95 
96  virtual void set_active(bool active);
97  INLINE bool is_active() const;
98  MAKE_PROPERTY(active, is_active, set_active);
99 
100  virtual void set_sort(int sort);
101  INLINE int get_sort() const;
102  MAKE_PROPERTY(sort, get_sort, set_sort);
103 
104  virtual void set_stereo_channel(Lens::StereoChannel stereo_channel);
105  INLINE Lens::StereoChannel get_stereo_channel() const;
106  MAKE_PROPERTY(stereo_channel, get_stereo_channel, set_stereo_channel);
107 
108  virtual void set_tex_view_offset(int tex_view_offset);
109  INLINE int get_tex_view_offset() const;
110  MAKE_PROPERTY(tex_view_offset, get_tex_view_offset, set_tex_view_offset);
111 
112  virtual void set_incomplete_render(bool incomplete_render);
113  INLINE bool get_incomplete_render() const;
114  MAKE_PROPERTY(incomplete_render, get_incomplete_render, set_incomplete_render);
115 
116  virtual void set_texture_reload_priority(int texture_reload_priority);
117  INLINE int get_texture_reload_priority() const;
118  MAKE_PROPERTY(texture_reload_priority, get_texture_reload_priority,
119  set_texture_reload_priority);
120 
121  void set_lens_index(int index);
122  INLINE int get_lens_index() const;
123  MAKE_PROPERTY(lens_index, get_lens_index, set_lens_index);
124 
125  virtual void set_cull_traverser(CullTraverser *trav);
126  CullTraverser *get_cull_traverser();
127  MAKE_PROPERTY(cull_traverser, get_cull_traverser, set_cull_traverser);
128 
129  INLINE void set_cube_map_index(int cube_map_index);
130  virtual void set_target_tex_page(int page);
131  INLINE int get_target_tex_page() const;
132  MAKE_PROPERTY(target_tex_page, get_target_tex_page, set_target_tex_page);
133 
134  INLINE void set_scissor_enabled(bool scissor_enabled);
135  INLINE bool get_scissor_enabled() const;
136  MAKE_PROPERTY(scissor_enabled, get_scissor_enabled, set_scissor_enabled);
137 
138  INLINE void set_cull_callback(CallbackObject *object);
139  INLINE void clear_cull_callback();
140  INLINE CallbackObject *get_cull_callback() const;
141  MAKE_PROPERTY(cull_callback, get_cull_callback, set_cull_callback);
142 
143  INLINE void set_draw_callback(CallbackObject *object);
144  INLINE void clear_draw_callback();
145  INLINE CallbackObject *get_draw_callback() const;
146  MAKE_PROPERTY(draw_callback, get_draw_callback, set_draw_callback);
147 
148  INLINE int get_pixel_width(int i = 0) const;
149  INLINE int get_pixel_height(int i = 0) const;
150  INLINE LVecBase2i get_pixel_size(int i = 0) const;
151  MAKE_PROPERTY(pixel_size, get_pixel_size);
152 
153  virtual void output(std::ostream &out) const;
154 
155  static Filename make_screenshot_filename(
156  const std::string &prefix = "screenshot");
157  Filename save_screenshot_default(const std::string &prefix = "screenshot");
158  bool save_screenshot(
159  const Filename &filename, const std::string &image_comment = "");
160  bool get_screenshot(PNMImage &image);
161  PT(Texture) get_screenshot();
162 
163  void clear_cull_result();
164  virtual PT(PandaNode) make_cull_result_graph();
165 
166 public:
167  void compute_pixels();
168  void compute_pixels_all_stages();
169  void compute_pixels(int x_size, int y_size);
170  void compute_pixels_all_stages(int x_size, int y_size);
171  INLINE void get_pixels(int &pl, int &pr, int &pb, int &pt) const;
172  INLINE void get_pixels(int i, int &pl, int &pr, int &pb, int &pt) const;
173  INLINE void get_region_pixels(int &xo, int &yo, int &w, int &h) const;
174  INLINE void get_region_pixels(int i, int &xo, int &yo, int &w, int &h) const;
175  INLINE void get_region_pixels_i(int &xo, int &yo, int &w, int &h) const;
176  INLINE void get_region_pixels_i(int i, int &xo, int &yo, int &w, int &h) const;
177 
178  virtual bool supports_pixel_zoom() const;
179 
180  INLINE void set_cull_result(PT(CullResult) cull_result, PT(SceneSetup) scene_setup,
181  Thread *current_thread);
182  INLINE CullResult *get_cull_result(Thread *current_thread) const;
183  INLINE SceneSetup *get_scene_setup(Thread *current_thread) const;
184 
185  INLINE PStatCollector &get_cull_region_pcollector();
186  INLINE PStatCollector &get_draw_region_pcollector();
187 
188  INLINE const std::string &get_debug_name() const;
189 
190  struct Region {
191  INLINE Region();
192 
193  LVecBase4 _dimensions; // left, right, bottom, top
194  LVecBase4i _pixels;
195  LVecBase4i _pixels_i;
196  };
197  typedef epvector<Region> Regions;
198 
199 private:
200  class CData;
201 
202  void win_display_regions_changed();
203  void do_compute_pixels(int i, int x_size, int y_size, CData *cdata);
204  void set_active_index(int index);
205 
206 protected:
207  virtual void do_cull(CullHandler *cull_handler, SceneSetup *scene_setup,
208  GraphicsStateGuardian *gsg, Thread *current_thread);
209 
210 protected:
211  // The associated window is a permanent property of the DisplayRegion. It
212  // doesn't need to be cycled.
213  GraphicsOutput *_window;
214 
215  bool _incomplete_render;
216  int _texture_reload_priority;
217 
218  // Ditto for the cull traverser.
219  PT(CullTraverser) _trav;
220 
221 private:
222  // This is the data that is associated with the DisplayRegion that needs to
223  // be cycled every frame, but represents the parameters as specified by the
224  // user, and which probably will not change that often.
225  class EXPCL_PANDA_DISPLAY CData : public CycleData {
226  public:
227  CData();
228  CData(const CData &copy);
229 
230  virtual CycleData *make_copy() const;
231  virtual TypeHandle get_parent_type() const {
232  return DisplayRegion::get_class_type();
233  }
234 
235  Regions _regions;
236 
237  int _lens_index; // index into which lens of a camera is associated with this display region. 0 is default
238 
239  NodePath _camera;
240  Camera *_camera_node;
241 
242  bool _active;
243  int _sort;
244  Lens::StereoChannel _stereo_channel;
245  int _tex_view_offset;
246  int _target_tex_page;
247  bool _scissor_enabled;
248 
249  PT(CallbackObject) _cull_callback;
250  PT(CallbackObject) _draw_callback;
251  };
252 
253  PipelineCycler<CData> _cycler;
254  typedef CycleDataLockedReader<CData> CDLockedReader;
255  typedef CycleDataReader<CData> CDReader;
256  typedef CycleDataWriter<CData> CDWriter;
257  typedef CycleDataStageWriter<CData> CDStageWriter;
258 
259  // This is a special cycler created to hold the results from the cull
260  // traversal, for (a) the draw traversal, and (b) the next frame's cull
261  // traversal. It needs to be cycled, but it gets its own cycler because it
262  // will certainly change every frame, so we don't need to lump all the heavy
263  // data above in with this lightweight cycler.
264  class EXPCL_PANDA_DISPLAY CDataCull : public CycleData {
265  public:
266  CDataCull();
267  CDataCull(const CDataCull &copy);
268 
269  virtual CycleData *make_copy() const;
270  virtual TypeHandle get_parent_type() const {
271  return DisplayRegion::get_class_type();
272  }
273 
274  PT(CullResult) _cull_result;
275  PT(SceneSetup) _scene_setup;
276  };
277  PipelineCycler<CDataCull> _cycler_cull;
278  typedef CycleDataReader<CDataCull> CDCullReader;
279  typedef CycleDataWriter<CDataCull> CDCullWriter;
280 
281  PStatCollector _cull_region_pcollector;
282  PStatCollector _draw_region_pcollector;
283  std::string _debug_name;
284 
285 public:
286  static TypeHandle get_class_type() {
287  return _type_handle;
288  }
289  static void init_type() {
290  TypedReferenceCount::init_type();
291  register_type(_type_handle, "DisplayRegion",
292  TypedReferenceCount::get_class_type());
293  }
294  virtual TypeHandle get_type() const {
295  return get_class_type();
296  }
297  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
298 
299 private:
300  static TypeHandle _type_handle;
301 
302  friend class GraphicsEngine;
303  friend class GraphicsOutput;
304  friend class DisplayRegionCullCallbackData;
305  friend class DisplayRegionPipelineReader;
306 };
307 
308 /**
309  * Encapsulates the data from a DisplayRegion, pre-fetched for one stage of
310  * the pipeline.
311  */
312 class EXPCL_PANDA_DISPLAY DisplayRegionPipelineReader {
313 public:
314  INLINE DisplayRegionPipelineReader(DisplayRegion *object, Thread *current_thread);
316  void operator = (const DisplayRegionPipelineReader &copy) = delete;
317 
318 public:
319  INLINE ~DisplayRegionPipelineReader();
320  ALLOC_DELETED_CHAIN(DisplayRegionPipelineReader);
321 
322  INLINE DisplayRegion *get_object() const;
323  INLINE Thread *get_current_thread() const;
324 
325  INLINE bool is_any_clear_active() const;
326 
327  INLINE int get_num_regions() const;
328  INLINE void get_dimensions(PN_stdfloat &l, PN_stdfloat &r, PN_stdfloat &b, PN_stdfloat &t) const;
329  INLINE void get_dimensions(int i, PN_stdfloat &l, PN_stdfloat &r, PN_stdfloat &b, PN_stdfloat &t) const;
330  INLINE const LVecBase4 &get_dimensions(int i = 0) const;
331  INLINE PN_stdfloat get_left(int i = 0) const;
332  INLINE PN_stdfloat get_right(int i = 0) const;
333  INLINE PN_stdfloat get_bottom(int i = 0) const;
334  INLINE PN_stdfloat get_top(int i = 0) const;
335 
336  INLINE GraphicsOutput *get_window() const;
337  GraphicsPipe *get_pipe() const;
338 
339  INLINE NodePath get_camera() const;
340  INLINE bool is_active() const;
341  INLINE int get_sort() const;
342  INLINE Lens::StereoChannel get_stereo_channel() const;
343  INLINE int get_tex_view_offset();
344  INLINE bool get_clear_depth_between_eyes() const;
345  INLINE int get_target_tex_page() const;
346  INLINE bool get_scissor_enabled() const;
347  INLINE CallbackObject *get_draw_callback() const;
348 
349  INLINE void get_pixels(int &pl, int &pr, int &pb, int &pt) const;
350  INLINE void get_pixels(int i, int &pl, int &pr, int &pb, int &pt) const;
351  INLINE void get_region_pixels(int &xo, int &yo, int &w, int &h) const;
352  INLINE void get_region_pixels(int i, int &xo, int &yo, int &w, int &h) const;
353  INLINE void get_region_pixels_i(int &xo, int &yo, int &w, int &h) const;
354  INLINE void get_region_pixels_i(int i, int &xo, int &yo, int &w, int &h) const;
355 
356  INLINE int get_pixel_width(int i = 0) const;
357  INLINE int get_pixel_height(int i = 0) const;
358 
359  INLINE int get_lens_index() const;
360 
361 private:
362  DisplayRegion *_object;
363  Thread *_current_thread;
364  const DisplayRegion::CData *_cdata;
365 
366 public:
367  static TypeHandle get_class_type() {
368  return _type_handle;
369  }
370  static void init_type() {
371  register_type(_type_handle, "DisplayRegionPipelineReader");
372  }
373 
374 private:
375  static TypeHandle _type_handle;
376 };
377 
378 INLINE std::ostream &operator << (std::ostream &out, const DisplayRegion &dr);
379 
380 #include "displayRegion.I"
381 
382 #endif /* DISPLAYREGION_H */
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is a generic object that can be assigned to a callback at various points in the rendering proces...
A node that can be positioned around in the scene graph to represent a point of view for rendering a ...
Definition: camera.h:35
This defines the abstract interface for an object that receives Geoms identified by the CullTraverser...
Definition: cullHandler.h:28
This stores the result of a BinCullHandler traversal: an ordered collection of CullBins,...
Definition: cullResult.h:44
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
Definition: cullTraverser.h:45
This template class calls PipelineCycler::read() in the constructor and PipelineCycler::release_read(...
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
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.
Definition: cycleData.h:50
This specialization on CallbackData is passed when the callback is initiated from the cull traversal,...
Encapsulates the data from a DisplayRegion, pre-fetched for one stage of the pipeline.
A rectangular subregion within a window for rendering into.
Definition: displayRegion.h:57
This is a base class for GraphicsWindow (actually, GraphicsOutput) and DisplayRegion,...
virtual bool supports_pixel_zoom() const
Returns true if a call to set_pixel_zoom() will be respected, false if it will be ignored.
virtual bool is_any_clear_active() const
Returns true if any of the clear types (so far there are just color or depth) have been set active,...
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
This class is the main interface to controlling the render process.
This is a base class for the various different classes that represent the result of a frame of render...
An object to create GraphicsOutputs that share a particular 3-D API.
Definition: graphicsPipe.h:52
Encapsulates all the communication with a particular instance of a given rendering backend.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:159
The name of this class derives from the fact that we originally implemented it as a layer on top of t...
Definition: pnmImage.h:58
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.
Definition: pandaNode.h:65
This object holds the camera position, etc., and other general setup information for rendering a part...
Definition: sceneSetup.h:32
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Definition: texture.h:71
A thread; that is, a lightweight process.
Definition: thread.h:46
get_current_thread
Returns a pointer to the currently-executing Thread object.
Definition: thread.h:109
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
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.
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.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.