Panda3D

displayRegion.h

00001 // Filename: displayRegion.h
00002 // Created by:  mike (09Jan97)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef DISPLAYREGION_H
00016 #define DISPLAYREGION_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "displayRegionBase.h"
00021 #include "drawableRegion.h"
00022 #include "referenceCount.h"
00023 #include "nodePath.h"
00024 #include "cullResult.h"
00025 #include "sceneSetup.h"
00026 #include "pointerTo.h"
00027 #include "cycleData.h"
00028 #include "cycleDataLockedReader.h"
00029 #include "cycleDataReader.h"
00030 #include "cycleDataWriter.h"
00031 #include "cycleDataStageWriter.h"
00032 #include "pipelineCycler.h"
00033 #include "config_display.h"
00034 #include "lens.h"
00035 #include "deletedChain.h"
00036 #include "plist.h"
00037 #include "pStatCollector.h"
00038 #include "cullTraverser.h"
00039 #include "callbackObject.h"
00040 
00041 class GraphicsOutput;
00042 class GraphicsPipe;
00043 class CullHandler;
00044 class Camera;
00045 class PNMImage;
00046 class CullTraverser;
00047 
00048 ////////////////////////////////////////////////////////////////////
00049 //       Class : DisplayRegion
00050 // Description : A rectangular subregion within a window for rendering
00051 //               into.  Typically, there is one DisplayRegion that
00052 //               covers the whole window, but you may also create
00053 //               smaller DisplayRegions for having different regions
00054 //               within the window that represent different scenes.
00055 //               You may also stack up DisplayRegions like panes of
00056 //               glass, usually for layering 2-d interfaces on top of
00057 //               a 3-d scene.
00058 ////////////////////////////////////////////////////////////////////
00059 class EXPCL_PANDA_DISPLAY DisplayRegion : public DisplayRegionBase, public DrawableRegion {
00060 protected:
00061   DisplayRegion(GraphicsOutput *window,
00062                 float l, float r, float b, float t);
00063 
00064 private:
00065   DisplayRegion(const DisplayRegion &copy);
00066   void operator = (const DisplayRegion &copy);
00067 
00068 public:
00069   virtual ~DisplayRegion();
00070   void cleanup();
00071 
00072   INLINE bool operator < (const DisplayRegion &other) const;
00073 
00074 PUBLISHED:
00075   INLINE void get_dimensions(float &l, float &r, float &b, float &t) const;
00076   INLINE float get_left() const;
00077   INLINE float get_right() const;
00078   INLINE float get_bottom() const;
00079   INLINE float get_top() const;
00080   virtual void set_dimensions(float l, float r, float b, float t);
00081 
00082   INLINE GraphicsOutput *get_window() const;
00083   GraphicsPipe *get_pipe() const;
00084   virtual bool is_stereo() const;
00085 
00086   virtual void set_camera(const NodePath &camera);
00087   INLINE NodePath get_camera(Thread *current_thread = Thread::get_current_thread()) const;
00088 
00089   virtual void set_active(bool active);
00090   INLINE bool is_active() const;
00091 
00092   virtual void set_sort(int sort);
00093   INLINE int get_sort() const;
00094 
00095   virtual void set_stereo_channel(Lens::StereoChannel stereo_channel);
00096   INLINE Lens::StereoChannel get_stereo_channel();
00097 
00098   virtual void set_incomplete_render(bool incomplete_render);
00099   INLINE bool get_incomplete_render() const;
00100 
00101   virtual void set_texture_reload_priority(int texture_reload_priority);
00102   INLINE int get_texture_reload_priority() const;
00103 
00104   void set_lens_index(int index);
00105   INLINE int get_lens_index() const;
00106 
00107   virtual void set_cull_traverser(CullTraverser *trav);
00108   CullTraverser *get_cull_traverser();
00109 
00110   virtual void set_cube_map_index(int cube_map_index);
00111   INLINE int get_cube_map_index() const;
00112 
00113   INLINE void set_cull_callback(CallbackObject *object);
00114   INLINE void clear_cull_callback();
00115   INLINE CallbackObject *get_cull_callback() const;
00116 
00117   INLINE void set_draw_callback(CallbackObject *object);
00118   INLINE void clear_draw_callback();
00119   INLINE CallbackObject *get_draw_callback() const;
00120 
00121   INLINE int get_pixel_width() const;
00122   INLINE int get_pixel_height() const;
00123 
00124   virtual void output(ostream &out) const;
00125 
00126   static Filename make_screenshot_filename(
00127     const string &prefix = "screenshot");
00128   Filename save_screenshot_default(const string &prefix = "screenshot");
00129   bool save_screenshot(
00130     const Filename &filename, const string &image_comment = "");
00131   bool get_screenshot(PNMImage &image);
00132 
00133   virtual PT(PandaNode) make_cull_result_graph();
00134 
00135 public:
00136   void compute_pixels();
00137   void compute_pixels_all_stages();
00138   void compute_pixels(int x_size, int y_size);
00139   void compute_pixels_all_stages(int x_size, int y_size);
00140   INLINE void get_pixels(int &pl, int &pr, int &pb, int &pt) const;
00141   INLINE void get_region_pixels(int &xo, int &yo, int &w, int &h) const;
00142   INLINE void get_region_pixels_i(int &xo, int &yo, int &w, int &h) const;
00143 
00144   virtual bool supports_pixel_zoom() const;
00145 
00146   INLINE void set_cull_result(CullResult *cull_result, SceneSetup *scene_setup,
00147                               Thread *current_thread);
00148   INLINE CullResult *get_cull_result(Thread *current_thread) const;
00149   INLINE SceneSetup *get_scene_setup(Thread *current_thread) const;
00150 
00151   INLINE PStatCollector &get_cull_region_pcollector();
00152   INLINE PStatCollector &get_draw_region_pcollector();
00153 
00154 private:
00155   class CData;
00156 
00157   void win_display_regions_changed();
00158   void do_compute_pixels(int x_size, int y_size, CData *cdata);
00159   void set_active_index(int index);
00160 
00161 protected:
00162   // The associated window is a permanent property of the
00163   // DisplayRegion.  It doesn't need to be cycled.
00164   GraphicsOutput *_window;
00165 
00166   bool _incomplete_render;
00167   int _texture_reload_priority;
00168 
00169   // Ditto for the cull traverser.
00170   PT(CullTraverser) _trav;
00171 
00172 private:
00173   // This is the data that is associated with the DisplayRegion that
00174   // needs to be cycled every frame, but represents the parameters as
00175   // specified by the user, and which probably will not change that
00176   // often.
00177   class EXPCL_PANDA_DISPLAY CData : public CycleData {
00178   public:
00179     CData();
00180     CData(const CData &copy);
00181 
00182     virtual CycleData *make_copy() const;
00183     virtual TypeHandle get_parent_type() const {
00184       return DisplayRegion::get_class_type();
00185     }
00186 
00187     float _l;
00188     float _r;
00189     float _b;
00190     float _t;
00191     
00192     int _pl;
00193     int _pr;
00194     int _pb;
00195     int _pt;
00196     int _pbi;
00197     int _pti;
00198     int _lens_index; // index into which lens of a camera is associated with this display region.  0 is default
00199     
00200     NodePath _camera;
00201     Camera *_camera_node;
00202     
00203     bool _active;
00204     int _sort;
00205     Lens::StereoChannel _stereo_channel;
00206     int _cube_map_index;
00207 
00208     PT(CallbackObject) _cull_callback;
00209     PT(CallbackObject) _draw_callback;
00210   };
00211 
00212   PipelineCycler<CData> _cycler;
00213   typedef CycleDataLockedReader<CData> CDLockedReader;
00214   typedef CycleDataReader<CData> CDReader;
00215   typedef CycleDataWriter<CData> CDWriter;
00216   typedef CycleDataStageWriter<CData> CDStageWriter;
00217 
00218   // This is a special cycler created to hold the results from the
00219   // cull traversal, for (a) the draw traversal, and (b) the next
00220   // frame's cull traversal.  It needs to be cycled, but it gets its
00221   // own cycler because it will certainly change every frame, so we
00222   // don't need to lump all the heavy data above in with this
00223   // lightweight cycler.
00224   class EXPCL_PANDA_DISPLAY CDataCull : public CycleData {
00225   public:
00226     CDataCull();
00227     CDataCull(const CDataCull &copy);
00228 
00229     virtual CycleData *make_copy() const;
00230     virtual TypeHandle get_parent_type() const {
00231       return DisplayRegion::get_class_type();
00232     }
00233 
00234     PT(CullResult) _cull_result;
00235     PT(SceneSetup) _scene_setup;
00236   };
00237   PipelineCycler<CDataCull> _cycler_cull;
00238   typedef CycleDataReader<CDataCull> CDCullReader;
00239   typedef CycleDataWriter<CDataCull> CDCullWriter;
00240 
00241   PStatCollector _cull_region_pcollector;
00242   PStatCollector _draw_region_pcollector;
00243 
00244 public:
00245   static TypeHandle get_class_type() {
00246     return _type_handle;
00247   }
00248   static void init_type() {
00249     DisplayRegionBase::init_type();
00250     register_type(_type_handle, "DisplayRegion",
00251                   DisplayRegionBase::get_class_type());
00252   }
00253   virtual TypeHandle get_type() const {
00254     return get_class_type();
00255   }
00256   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00257 
00258 private:
00259   static TypeHandle _type_handle;
00260 
00261   friend class GraphicsOutput;
00262   friend class DisplayRegionPipelineReader;
00263 };
00264 
00265 ////////////////////////////////////////////////////////////////////
00266 //       Class : DisplayRegionPipelineReader
00267 // Description : Encapsulates the data from a DisplayRegion,
00268 //               pre-fetched for one stage of the pipeline.
00269 ////////////////////////////////////////////////////////////////////
00270 class EXPCL_PANDA_DISPLAY DisplayRegionPipelineReader {
00271 public:
00272   INLINE DisplayRegionPipelineReader(DisplayRegion *object, Thread *current_thread);
00273 private:
00274   INLINE DisplayRegionPipelineReader(const DisplayRegionPipelineReader &copy);
00275   INLINE void operator = (const DisplayRegionPipelineReader &copy);
00276 
00277 public:
00278   INLINE ~DisplayRegionPipelineReader();
00279   ALLOC_DELETED_CHAIN(DisplayRegionPipelineReader);
00280 
00281   INLINE DisplayRegion *get_object() const;
00282   INLINE Thread *get_current_thread() const;
00283 
00284   INLINE bool is_any_clear_active() const;
00285 
00286   INLINE void get_dimensions(float &l, float &r, float &b, float &t) const;
00287   INLINE float get_left() const;
00288   INLINE float get_right() const;
00289   INLINE float get_bottom() const;
00290   INLINE float get_top() const;
00291 
00292   INLINE GraphicsOutput *get_window() const;
00293   GraphicsPipe *get_pipe() const;
00294 
00295   INLINE NodePath get_camera() const;
00296   INLINE bool is_active() const;
00297   INLINE int get_sort() const;
00298   INLINE Lens::StereoChannel get_stereo_channel();
00299   INLINE bool get_clear_depth_between_eyes() const;
00300   INLINE int get_cube_map_index() const;
00301   INLINE CallbackObject *get_draw_callback() const;
00302 
00303   INLINE void get_pixels(int &pl, int &pr, int &pb, int &pt) const;
00304   INLINE void get_region_pixels(int &xo, int &yo, int &w, int &h) const;
00305   INLINE void get_region_pixels_i(int &xo, int &yo, int &w, int &h) const;
00306 
00307   INLINE int get_pixel_width() const;
00308   INLINE int get_pixel_height() const;
00309 
00310   INLINE int get_lens_index() const;
00311 
00312 private:
00313   DisplayRegion *_object;
00314   Thread *_current_thread;
00315   const DisplayRegion::CData *_cdata;
00316 
00317 public:
00318   static TypeHandle get_class_type() {
00319     return _type_handle;
00320   }
00321   static void init_type() {
00322     register_type(_type_handle, "DisplayRegionPipelineReader");
00323   }
00324 
00325 private:
00326   static TypeHandle _type_handle;
00327 };
00328 
00329 #include "displayRegion.I"
00330 
00331 #endif /* DISPLAYREGION_H */
 All Classes Functions Variables Enumerations