Panda3D
 All Classes Functions Variables Enumerations
clipPlaneAttrib.h
1 // Filename: clipPlaneAttrib.h
2 // Created by: drose (11Jul02)
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 CLIPPINGPLANEATTRIB_H
16 #define CLIPPINGPLANEATTRIB_H
17 
18 #include "pandabase.h"
19 
20 #include "planeNode.h"
21 #include "renderAttrib.h"
22 #include "nodePath.h"
23 #include "ordered_vector.h"
24 #include "pmap.h"
25 
26 ////////////////////////////////////////////////////////////////////
27 // Class : ClipPlaneAttrib
28 // Description : This functions similarly to a LightAttrib. It
29 // indicates the set of clipping planes that modify the
30 // geometry at this level and below. A ClipPlaneAttrib
31 // can either add planes or remove planes from the total
32 // set of clipping planes in effect.
33 ////////////////////////////////////////////////////////////////////
34 class EXPCL_PANDA_PGRAPH ClipPlaneAttrib : public RenderAttrib {
35 private:
36  INLINE ClipPlaneAttrib();
37  INLINE ClipPlaneAttrib(const ClipPlaneAttrib &copy);
38 
39 PUBLISHED:
40 
41  // This is the old, deprecated interface to ClipPlaneAttrib. Do not
42  // use any of these methods for new code; these methods will be
43  // removed soon.
44  enum Operation {
45  O_set,
46  O_add,
47  O_remove
48  };
49 
50  static CPT(RenderAttrib) make(Operation op,
51  PlaneNode *plane);
52  static CPT(RenderAttrib) make(Operation op,
53  PlaneNode *plane1, PlaneNode *plane2);
54  static CPT(RenderAttrib) make(Operation op,
55  PlaneNode *plane1, PlaneNode *plane2,
56  PlaneNode *plane3);
57  static CPT(RenderAttrib) make(Operation op,
58  PlaneNode *plane1, PlaneNode *plane2,
59  PlaneNode *plane3, PlaneNode *plane4);
60  static CPT(RenderAttrib) make_default();
61 
62  Operation get_operation() const;
63 
64  int get_num_planes() const;
65  PlaneNode *get_plane(int n) const;
66  bool has_plane(PlaneNode *plane) const;
67 
68  CPT(RenderAttrib) add_plane(PlaneNode *plane) const;
69  CPT(RenderAttrib) remove_plane(PlaneNode *plane) const;
70 
71 
72  // The following is the new, more general interface to the
73  // ClipPlaneAttrib.
74  static CPT(RenderAttrib) make();
75  static CPT(RenderAttrib) make_all_off();
76 
77  INLINE int get_num_on_planes() const;
78  INLINE NodePath get_on_plane(int n) const;
79  MAKE_SEQ(get_on_planes, get_num_on_planes, get_on_plane);
80  INLINE bool has_on_plane(const NodePath &plane) const;
81 
82  INLINE int get_num_off_planes() const;
83  INLINE NodePath get_off_plane(int n) const;
84  MAKE_SEQ(get_off_planes, get_num_off_planes, get_off_plane);
85  INLINE bool has_off_plane(const NodePath &plane) const;
86  INLINE bool has_all_off() const;
87 
88  INLINE bool is_identity() const;
89 
90  CPT(RenderAttrib) add_on_plane(const NodePath &plane) const;
91  CPT(RenderAttrib) remove_on_plane(const NodePath &plane) const;
92  CPT(RenderAttrib) add_off_plane(const NodePath &plane) const;
93  CPT(RenderAttrib) remove_off_plane(const NodePath &plane) const;
94 
95  CPT(ClipPlaneAttrib) filter_to_max(int max_clip_planes) const;
96 
97 public:
98  CPT(RenderAttrib) compose_off(const RenderAttrib *other) const;
99  virtual void output(ostream &out) const;
100 
101 protected:
102  virtual int compare_to_impl(const RenderAttrib *other) const;
103  virtual size_t get_hash_impl() const;
104  virtual CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const;
105  virtual CPT(RenderAttrib) invert_compose_impl(const RenderAttrib *other) const;
106  virtual CPT(RenderAttrib) get_auto_shader_attrib_impl(const RenderState *state) const;
107 
108 private:
109  INLINE void check_filtered() const;
110  void sort_on_planes();
111 
112 private:
113  typedef ov_set<NodePath> Planes;
114  Planes _on_planes, _off_planes;
115  bool _off_all_planes;
116 
118  Filtered _filtered;
119 
120  UpdateSeq _sort_seq;
121 
122  static CPT(RenderAttrib) _empty_attrib;
123  static CPT(RenderAttrib) _all_off_attrib;
124 
125 PUBLISHED:
126  static int get_class_slot() {
127  return _attrib_slot;
128  }
129  virtual int get_slot() const {
130  return get_class_slot();
131  }
132 
133 public:
134  static void register_with_read_factory();
135  virtual void write_datagram(BamWriter *manager, Datagram &dg);
136  virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
137  virtual bool require_fully_complete() const;
138 
139 protected:
140  static TypedWritable *make_from_bam(const FactoryParams &params);
141  void fillin(DatagramIterator &scan, BamReader *manager);
142 
143 public:
144  static TypeHandle get_class_type() {
145  return _type_handle;
146  }
147  static void init_type() {
148  RenderAttrib::init_type();
149  register_type(_type_handle, "ClipPlaneAttrib",
150  RenderAttrib::get_class_type());
151  _attrib_slot = register_slot(_type_handle, 100, make_default);
152  }
153  virtual TypeHandle get_type() const {
154  return get_class_type();
155  }
156  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
157 
158 private:
159  static TypeHandle _type_handle;
160  static int _attrib_slot;
161 };
162 
163 #include "clipPlaneAttrib.I"
164 
165 #endif
166 
static int register_slot(TypeHandle type_handle, int sort, RenderAttribRegistry::MakeDefaultFunc *make_default_func)
Adds the indicated TypeHandle to the registry, if it is not there already, and returns a unique slot ...
Definition: renderAttrib.I:163
This is the base class for a number of render attributes (other than transform) that may be set on sc...
Definition: renderAttrib.h:60
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This functions similarly to a LightAttrib.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
This is our own Panda specialization on the default STL list.
Definition: plist.h:38
virtual bool require_fully_complete() const
Some objects require all of their nested pointers to have been completed before the objects themselve...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager-&gt;read_pointer() was called in fillin()...
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:53
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
This is a sequence number that increments monotonically.
Definition: updateSeq.h:43
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165
A node that contains a plane.
Definition: planeNode.h:39