Panda3D
|
00001 // Filename: clipPlaneAttrib.h 00002 // Created by: drose (11Jul02) 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 CLIPPINGPLANEATTRIB_H 00016 #define CLIPPINGPLANEATTRIB_H 00017 00018 #include "pandabase.h" 00019 00020 #include "planeNode.h" 00021 #include "renderAttrib.h" 00022 #include "nodePath.h" 00023 #include "ordered_vector.h" 00024 #include "pmap.h" 00025 00026 //////////////////////////////////////////////////////////////////// 00027 // Class : ClipPlaneAttrib 00028 // Description : This functions similarly to a LightAttrib. It 00029 // indicates the set of clipping planes that modify the 00030 // geometry at this level and below. A ClipPlaneAttrib 00031 // can either add planes or remove planes from the total 00032 // set of clipping planes in effect. 00033 //////////////////////////////////////////////////////////////////// 00034 class EXPCL_PANDA_PGRAPH ClipPlaneAttrib : public RenderAttrib { 00035 private: 00036 INLINE ClipPlaneAttrib(); 00037 INLINE ClipPlaneAttrib(const ClipPlaneAttrib ©); 00038 00039 PUBLISHED: 00040 00041 // This is the old, deprecated interface to ClipPlaneAttrib. Do not 00042 // use any of these methods for new code; these methods will be 00043 // removed soon. 00044 enum Operation { 00045 O_set, 00046 O_add, 00047 O_remove 00048 }; 00049 00050 static CPT(RenderAttrib) make(Operation op, 00051 PlaneNode *plane); 00052 static CPT(RenderAttrib) make(Operation op, 00053 PlaneNode *plane1, PlaneNode *plane2); 00054 static CPT(RenderAttrib) make(Operation op, 00055 PlaneNode *plane1, PlaneNode *plane2, 00056 PlaneNode *plane3); 00057 static CPT(RenderAttrib) make(Operation op, 00058 PlaneNode *plane1, PlaneNode *plane2, 00059 PlaneNode *plane3, PlaneNode *plane4); 00060 static CPT(RenderAttrib) make_default(); 00061 00062 Operation get_operation() const; 00063 00064 int get_num_planes() const; 00065 PlaneNode *get_plane(int n) const; 00066 bool has_plane(PlaneNode *plane) const; 00067 00068 CPT(RenderAttrib) add_plane(PlaneNode *plane) const; 00069 CPT(RenderAttrib) remove_plane(PlaneNode *plane) const; 00070 00071 00072 // The following is the new, more general interface to the 00073 // ClipPlaneAttrib. 00074 static CPT(RenderAttrib) make(); 00075 static CPT(RenderAttrib) make_all_off(); 00076 00077 INLINE int get_num_on_planes() const; 00078 INLINE NodePath get_on_plane(int n) const; 00079 MAKE_SEQ(get_on_planes, get_num_on_planes, get_on_plane); 00080 INLINE bool has_on_plane(const NodePath &plane) const; 00081 00082 INLINE int get_num_off_planes() const; 00083 INLINE NodePath get_off_plane(int n) const; 00084 MAKE_SEQ(get_off_planes, get_num_off_planes, get_off_plane); 00085 INLINE bool has_off_plane(const NodePath &plane) const; 00086 INLINE bool has_all_off() const; 00087 00088 INLINE bool is_identity() const; 00089 00090 CPT(RenderAttrib) add_on_plane(const NodePath &plane) const; 00091 CPT(RenderAttrib) remove_on_plane(const NodePath &plane) const; 00092 CPT(RenderAttrib) add_off_plane(const NodePath &plane) const; 00093 CPT(RenderAttrib) remove_off_plane(const NodePath &plane) const; 00094 00095 CPT(ClipPlaneAttrib) filter_to_max(int max_clip_planes) const; 00096 00097 public: 00098 CPT(RenderAttrib) compose_off(const RenderAttrib *other) const; 00099 virtual void output(ostream &out) const; 00100 00101 protected: 00102 virtual int compare_to_impl(const RenderAttrib *other) const; 00103 virtual size_t get_hash_impl() const; 00104 virtual CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const; 00105 virtual CPT(RenderAttrib) invert_compose_impl(const RenderAttrib *other) const; 00106 virtual CPT(RenderAttrib) get_auto_shader_attrib_impl(const RenderState *state) const; 00107 00108 private: 00109 INLINE void check_filtered() const; 00110 void sort_on_planes(); 00111 00112 private: 00113 typedef ov_set<NodePath> Planes; 00114 Planes _on_planes, _off_planes; 00115 bool _off_all_planes; 00116 00117 typedef pmap< int, CPT(ClipPlaneAttrib) > Filtered; 00118 Filtered _filtered; 00119 00120 UpdateSeq _sort_seq; 00121 00122 static CPT(RenderAttrib) _empty_attrib; 00123 static CPT(RenderAttrib) _all_off_attrib; 00124 00125 PUBLISHED: 00126 static int get_class_slot() { 00127 return _attrib_slot; 00128 } 00129 virtual int get_slot() const { 00130 return get_class_slot(); 00131 } 00132 00133 public: 00134 static void register_with_read_factory(); 00135 virtual void write_datagram(BamWriter *manager, Datagram &dg); 00136 virtual int complete_pointers(TypedWritable **plist, BamReader *manager); 00137 virtual bool require_fully_complete() const; 00138 00139 protected: 00140 static TypedWritable *make_from_bam(const FactoryParams ¶ms); 00141 void fillin(DatagramIterator &scan, BamReader *manager); 00142 00143 public: 00144 static TypeHandle get_class_type() { 00145 return _type_handle; 00146 } 00147 static void init_type() { 00148 RenderAttrib::init_type(); 00149 register_type(_type_handle, "ClipPlaneAttrib", 00150 RenderAttrib::get_class_type()); 00151 _attrib_slot = register_slot(_type_handle, 100, make_default); 00152 } 00153 virtual TypeHandle get_type() const { 00154 return get_class_type(); 00155 } 00156 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00157 00158 private: 00159 static TypeHandle _type_handle; 00160 static int _attrib_slot; 00161 }; 00162 00163 #include "clipPlaneAttrib.I" 00164 00165 #endif 00166