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