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  virtual PT(PandaNode) make_cull_result_graph();
164 
165 public:
166  void compute_pixels();
167  void compute_pixels_all_stages();
168  void compute_pixels(int x_size, int y_size);
169  void compute_pixels_all_stages(int x_size, int y_size);
170  INLINE void get_pixels(int &pl, int &pr, int &pb, int &pt) const;
171  INLINE void get_pixels(int i, int &pl, int &pr, int &pb, int &pt) const;
172  INLINE void get_region_pixels(int &xo, int &yo, int &w, int &h) const;
173  INLINE void get_region_pixels(int i, int &xo, int &yo, int &w, int &h) const;
174  INLINE void get_region_pixels_i(int &xo, int &yo, int &w, int &h) const;
175  INLINE void get_region_pixels_i(int i, int &xo, int &yo, int &w, int &h) const;
176 
177  virtual bool supports_pixel_zoom() const;
178 
179  INLINE void set_cull_result(PT(CullResult) cull_result, PT(SceneSetup) scene_setup,
180  Thread *current_thread);
181  INLINE CullResult *get_cull_result(Thread *current_thread) const;
182  INLINE SceneSetup *get_scene_setup(Thread *current_thread) const;
183 
184  INLINE PStatCollector &get_cull_region_pcollector();
185  INLINE PStatCollector &get_draw_region_pcollector();
186 
187  INLINE const std::string &get_debug_name() const;
188 
189  struct Region {
190  INLINE Region();
191 
192  LVecBase4 _dimensions; // left, right, bottom, top
193  LVecBase4i _pixels;
194  LVecBase4i _pixels_i;
195  };
196  typedef epvector<Region> Regions;
197 
198 private:
199  class CData;
200 
201  void win_display_regions_changed();
202  void do_compute_pixels(int i, int x_size, int y_size, CData *cdata);
203  void set_active_index(int index);
204 
205 protected:
206  virtual void do_cull(CullHandler *cull_handler, SceneSetup *scene_setup,
207  GraphicsStateGuardian *gsg, Thread *current_thread);
208 
209 protected:
210  // The associated window is a permanent property of the DisplayRegion. It
211  // doesn't need to be cycled.
212  GraphicsOutput *_window;
213 
214  bool _incomplete_render;
215  int _texture_reload_priority;
216 
217  // Ditto for the cull traverser.
218  PT(CullTraverser) _trav;
219 
220 private:
221  // This is the data that is associated with the DisplayRegion that needs to
222  // be cycled every frame, but represents the parameters as specified by the
223  // user, and which probably will not change that often.
224  class EXPCL_PANDA_DISPLAY CData : public CycleData {
225  public:
226  CData();
227  CData(const CData &copy);
228 
229  virtual CycleData *make_copy() const;
230  virtual TypeHandle get_parent_type() const {
231  return DisplayRegion::get_class_type();
232  }
233 
234  Regions _regions;
235 
236  int _lens_index; // index into which lens of a camera is associated with this display region. 0 is default
237 
238  NodePath _camera;
239  Camera *_camera_node;
240 
241  bool _active;
242  int _sort;
243  Lens::StereoChannel _stereo_channel;
244  int _tex_view_offset;
245  int _target_tex_page;
246  bool _scissor_enabled;
247 
248  PT(CallbackObject) _cull_callback;
249  PT(CallbackObject) _draw_callback;
250  };
251 
252  PipelineCycler<CData> _cycler;
253  typedef CycleDataLockedReader<CData> CDLockedReader;
254  typedef CycleDataReader<CData> CDReader;
255  typedef CycleDataWriter<CData> CDWriter;
256  typedef CycleDataStageWriter<CData> CDStageWriter;
257 
258  // This is a special cycler created to hold the results from the cull
259  // traversal, for (a) the draw traversal, and (b) the next frame's cull
260  // traversal. It needs to be cycled, but it gets its own cycler because it
261  // will certainly change every frame, so we don't need to lump all the heavy
262  // data above in with this lightweight cycler.
263  class EXPCL_PANDA_DISPLAY CDataCull : public CycleData {
264  public:
265  CDataCull();
266  CDataCull(const CDataCull &copy);
267 
268  virtual CycleData *make_copy() const;
269  virtual TypeHandle get_parent_type() const {
270  return DisplayRegion::get_class_type();
271  }
272 
273  PT(CullResult) _cull_result;
274  PT(SceneSetup) _scene_setup;
275  };
276  PipelineCycler<CDataCull> _cycler_cull;
277  typedef CycleDataReader<CDataCull> CDCullReader;
278  typedef CycleDataWriter<CDataCull> CDCullWriter;
279 
280  PStatCollector _cull_region_pcollector;
281  PStatCollector _draw_region_pcollector;
282  std::string _debug_name;
283 
284 public:
285  static TypeHandle get_class_type() {
286  return _type_handle;
287  }
288  static void init_type() {
289  TypedReferenceCount::init_type();
290  register_type(_type_handle, "DisplayRegion",
291  TypedReferenceCount::get_class_type());
292  }
293  virtual TypeHandle get_type() const {
294  return get_class_type();
295  }
296  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
297 
298 private:
299  static TypeHandle _type_handle;
300 
301  friend class GraphicsEngine;
302  friend class GraphicsOutput;
303  friend class DisplayRegionCullCallbackData;
304  friend class DisplayRegionPipelineReader;
305 };
306 
307 /**
308  * Encapsulates the data from a DisplayRegion, pre-fetched for one stage of
309  * the pipeline.
310  */
311 class EXPCL_PANDA_DISPLAY DisplayRegionPipelineReader {
312 public:
313  INLINE DisplayRegionPipelineReader(DisplayRegion *object, Thread *current_thread);
315  void operator = (const DisplayRegionPipelineReader &copy) = delete;
316 
317 public:
318  INLINE ~DisplayRegionPipelineReader();
319  ALLOC_DELETED_CHAIN(DisplayRegionPipelineReader);
320 
321  INLINE DisplayRegion *get_object() const;
322  INLINE Thread *get_current_thread() const;
323 
324  INLINE bool is_any_clear_active() const;
325 
326  INLINE int get_num_regions() const;
327  INLINE void get_dimensions(PN_stdfloat &l, PN_stdfloat &r, PN_stdfloat &b, PN_stdfloat &t) const;
328  INLINE void get_dimensions(int i, PN_stdfloat &l, PN_stdfloat &r, PN_stdfloat &b, PN_stdfloat &t) const;
329  INLINE const LVecBase4 &get_dimensions(int i = 0) const;
330  INLINE PN_stdfloat get_left(int i = 0) const;
331  INLINE PN_stdfloat get_right(int i = 0) const;
332  INLINE PN_stdfloat get_bottom(int i = 0) const;
333  INLINE PN_stdfloat get_top(int i = 0) const;
334 
335  INLINE GraphicsOutput *get_window() const;
336  GraphicsPipe *get_pipe() const;
337 
338  INLINE NodePath get_camera() const;
339  INLINE bool is_active() const;
340  INLINE int get_sort() const;
341  INLINE Lens::StereoChannel get_stereo_channel() const;
342  INLINE int get_tex_view_offset();
343  INLINE bool get_clear_depth_between_eyes() const;
344  INLINE int get_target_tex_page() const;
345  INLINE bool get_scissor_enabled() const;
346  INLINE CallbackObject *get_draw_callback() const;
347 
348  INLINE void get_pixels(int &pl, int &pr, int &pb, int &pt) const;
349  INLINE void get_pixels(int i, int &pl, int &pr, int &pb, int &pt) const;
350  INLINE void get_region_pixels(int &xo, int &yo, int &w, int &h) const;
351  INLINE void get_region_pixels(int i, int &xo, int &yo, int &w, int &h) const;
352  INLINE void get_region_pixels_i(int &xo, int &yo, int &w, int &h) const;
353  INLINE void get_region_pixels_i(int i, int &xo, int &yo, int &w, int &h) const;
354 
355  INLINE int get_pixel_width(int i = 0) const;
356  INLINE int get_pixel_height(int i = 0) const;
357 
358  INLINE int get_lens_index() const;
359 
360 private:
361  DisplayRegion *_object;
362  Thread *_current_thread;
363  const DisplayRegion::CData *_cdata;
364 
365 public:
366  static TypeHandle get_class_type() {
367  return _type_handle;
368  }
369  static void init_type() {
370  register_type(_type_handle, "DisplayRegionPipelineReader");
371  }
372 
373 private:
374  static TypeHandle _type_handle;
375 };
376 
377 INLINE std::ostream &operator << (std::ostream &out, const DisplayRegion &dr);
378 
379 #include "displayRegion.I"
380 
381 #endif /* DISPLAYREGION_H */
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
Encapsulates the data from a DisplayRegion, pre-fetched for one stage of the pipeline.
This is a base class for GraphicsWindow (actually, GraphicsOutput) and DisplayRegion,...
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
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
Definition: cycleData.h:47
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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
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.
virtual TypeHandle get_parent_type() const
Returns the type of the container that owns the CycleData.
Definition: cycleData.cxx:76
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This specialization on CallbackData is passed when the callback is initiated from the cull traversal,...
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
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.
This defines the abstract interface for an object that receives Geoms identified by the CullTraverser...
Definition: cullHandler.h:28
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual bool supports_pixel_zoom() const
Returns true if a call to set_pixel_zoom() will be respected, false if it will be ignored.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An object to create GraphicsOutputs that share a particular 3-D API.
Definition: graphicsPipe.h:52
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This template class calls PipelineCycler::read() in the constructor and PipelineCycler::release_read(...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
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.
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...
This stores the result of a BinCullHandler traversal: an ordered collection of CullBins,...
Definition: cullResult.h:44
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A thread; that is, a lightweight process.
Definition: thread.h:46
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Encapsulates all the communication with a particular instance of a given rendering backend.
A rectangular subregion within a window for rendering into.
Definition: displayRegion.h:57
This class is the main interface to controlling the render process.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
This object holds the camera position, etc., and other general setup information for rendering a part...
Definition: sceneSetup.h:32
A node that can be positioned around in the scene graph to represent a point of view for rendering a ...
Definition: camera.h:35
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:161
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
Definition: cullTraverser.h:45
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.