Panda3D
geomNode.h
1 // Filename: geomNode.h
2 // Created by: drose (22eb02)
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 GEOMNODE_H
16 #define GEOMNODE_H
17 
18 #include "pandabase.h"
19 #include "config_pgraph.h"
20 #include "pandaNode.h"
21 #include "pointerToArray.h"
22 #include "geom.h"
23 #include "pipelineCycler.h"
24 #include "cycleData.h"
25 #include "pvector.h"
26 #include "copyOnWritePointer.h"
27 
29 
30 ////////////////////////////////////////////////////////////////////
31 // Class : GeomNode
32 // Description : A node that holds Geom objects, renderable pieces of
33 // geometry. This is the primary kind of leaf node in
34 // the scene graph; almost all visible objects will be
35 // contained in a GeomNode somewhere.
36 ////////////////////////////////////////////////////////////////////
37 class EXPCL_PANDA_PGRAPH GeomNode : public PandaNode {
38 PUBLISHED:
39  GeomNode(const string &name);
40 
41 protected:
42  GeomNode(const GeomNode &copy);
43 public:
44  virtual ~GeomNode();
45  virtual PandaNode *make_copy() const;
46  virtual void apply_attribs_to_vertices(const AccumulatedAttribs &attribs,
47  int attrib_types,
48  GeomTransformer &transformer);
49  virtual void xform(const LMatrix4 &mat);
50  virtual PandaNode *combine_with(PandaNode *other);
51  virtual CPT(TransformState)
52  calc_tight_bounds(LPoint3 &min_point, LPoint3 &max_point,
53  bool &found_any,
54  const TransformState *transform,
55  Thread *current_thread) const;
56  virtual bool is_renderable() const;
57  virtual void add_for_draw(CullTraverser *trav, CullTraverserData &data);
58  virtual CollideMask get_legal_collide_mask() const;
59 
60  virtual bool safe_to_flatten() const;
61  virtual bool safe_to_combine() const;
62 
64  const RenderState *node_state,
65  GeomTransformer &transformer,
66  Thread *current_thread);
67 
68 PUBLISHED:
69  INLINE void set_preserved(bool value);
70  INLINE bool get_preserved() const;
71 
72  INLINE int get_num_geoms() const;
73  INLINE CPT(Geom) get_geom(int n) const;
74  MAKE_SEQ(get_geoms, get_num_geoms, get_geom);
75  INLINE PT(Geom) modify_geom(int n);
76  MAKE_SEQ(modify_geoms, get_num_geoms, modify_geom);
77  INLINE const RenderState *get_geom_state(int n) const;
78  MAKE_SEQ(get_geom_states, get_num_geoms, get_geom_state);
79  INLINE void set_geom_state(int n, const RenderState *state);
80 
81  void add_geom(Geom *geom, const RenderState *state = RenderState::make_empty());
82  void add_geoms_from(const GeomNode *other);
83  void set_geom(int n, Geom *geom);
84  INLINE void remove_geom(int n);
85  INLINE void remove_all_geoms();
86  bool check_valid() const;
87 
88  void decompose();
89  void unify(int max_indices, bool preserve_order);
90 
91  void write_geoms(ostream &out, int indent_level) const;
92  void write_verbose(ostream &out, int indent_level) const;
93 
94  INLINE static CollideMask get_default_collide_mask();
95 
96 public:
97  virtual void output(ostream &out) const;
98 
99  virtual bool is_geom_node() const;
100 
101  void do_premunge(GraphicsStateGuardianBase *gsg,
102  const RenderState *node_state,
103  GeomTransformer &transformer);
104 
105 protected:
106  virtual void r_mark_geom_bounds_stale(Thread *current_thread);
107  virtual void compute_internal_bounds(CPT(BoundingVolume) &internal_bounds,
108  int &internal_vertices,
109  int pipeline_stage,
110  Thread *current_thread) const;
111 
112 public:
113  // This must be declared public so that VC6 will allow the nested
114  // CData class to access it.
115  class GeomEntry {
116  public:
117  INLINE GeomEntry(Geom *geom, const RenderState *state);
118  COWPT(Geom) _geom;
119  CPT(RenderState) _state;
120  };
121 
123 
124 private:
125 
126  bool _preserved;
128 
129  INLINE void count_name(NameCount &name_count, const InternalName *name);
130  INLINE int get_name_count(const NameCount &name_count, const InternalName *name);
131 
132  // This is the data that must be cycled between pipeline stages.
133  class EXPCL_PANDA_PGRAPH CData : public CycleData {
134  public:
135  INLINE CData();
136  CData(const CData &copy);
137  virtual CycleData *make_copy() const;
138  virtual void write_datagram(BamWriter *manager, Datagram &dg) const;
139  virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
140  virtual void fillin(DatagramIterator &scan, BamReader *manager);
141  virtual TypeHandle get_parent_type() const {
142  return GeomNode::get_class_type();
143  }
144 
145  INLINE CPT(GeomList) get_geoms() const;
146  INLINE PT(GeomList) modify_geoms();
147  INLINE void set_geoms(GeomList *geoms);
148 
149  private:
150  COWPT(GeomList) _geoms;
151  };
152 
153  PipelineCycler<CData> _cycler;
159 
160 public:
161  // This class is returned from get_geoms(). It is similar to
162  // PandaNode::get_children(); use this to walk through the list of
163  // geoms faster than walking through the geoms directly from the
164  // node.
165  class EXPCL_PANDA_PGRAPH Geoms {
166  public:
167  INLINE Geoms();
168  INLINE Geoms(const CData *cdata);
169  INLINE Geoms(const Geoms &copy);
170  INLINE void operator = (const Geoms &copy);
171 
172 #ifdef USE_MOVE_SEMANTICS
173  INLINE Geoms(Geoms &&from) NOEXCEPT;
174  INLINE void operator = (Geoms &&from) NOEXCEPT;
175 #endif
176 
177  INLINE int get_num_geoms() const;
178  INLINE CPT(Geom) get_geom(int n) const;
179  INLINE const RenderState *get_geom_state(int n) const;
180 
181  private:
182  CPT(GeomList) _geoms;
183  };
184 
185  INLINE Geoms get_geoms(Thread *current_thread = Thread::get_current_thread()) const;
186 
187  // This data is only needed when reading from a bam file.
189  public:
190  // We just hold a pointer to the RenderState that may otherwise
191  // lose its pointers before it can finalize.
192  CPT(RenderState) _hold_state;
193  };
194 
195 public:
196  static void register_with_read_factory();
197  virtual void write_datagram(BamWriter *manager, Datagram &dg);
198 
199  virtual void finalize(BamReader *manager);
200 
201 protected:
202  static TypedWritable *make_from_bam(const FactoryParams &params);
203  void fillin(DatagramIterator &scan, BamReader *manager);
204 
205 public:
206  static TypeHandle get_class_type() {
207  return _type_handle;
208  }
209  static void init_type() {
210  GeomList::init_type();
211  PandaNode::init_type();
212  register_type(_type_handle, "GeomNode",
213  PandaNode::get_class_type());
214  }
215  virtual TypeHandle get_type() const {
216  return get_class_type();
217  }
218  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
219 
220 private:
221  static TypeHandle _type_handle;
222 
223  friend class GeomTransformer;
224 };
225 
226 #include "geomNode.I"
227 
228 #endif
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
virtual CollideMask get_legal_collide_mask() const
Returns the subset of CollideMask bits that may be set for this particular type of PandaNode...
Definition: pandaNode.cxx:2069
This is our own Panda specialization on the default STL map.
Definition: pmap.h:52
virtual void apply_attribs_to_vertices(const AccumulatedAttribs &attribs, int attrib_types, GeomTransformer &transformer)
Applies whatever attributes are specified in the AccumulatedAttribs object (and by the attrib_types b...
Definition: pandaNode.cxx:352
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
virtual PandaNode * combine_with(PandaNode *other)
Collapses this PandaNode with the other PandaNode, if possible, and returns a pointer to the combined...
Definition: pandaNode.cxx:397
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
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This collects together the pieces of data that are accumulated for each node while walking the scene ...
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
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 safe_to_combine() const
Returns true if it is generally safe to combine this particular kind of PandaNode with other kinds of...
Definition: pandaNode.cxx:281
static Thread * get_current_thread()
Returns a pointer to the currently-executing Thread object.
Definition: thread.I:145
virtual void r_prepare_scene(GraphicsStateGuardianBase *gsg, const RenderState *node_state, GeomTransformer &transformer, Thread *current_thread)
The recursive implementation of prepare_scene().
Definition: pandaNode.cxx:2925
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
This is an abstract class for any volume in any sense which can be said to define the locality of ref...
virtual void xform(const LMatrix4 &mat)
Transforms the contents of this PandaNode by the indicated matrix, if it means anything to do so...
Definition: pandaNode.cxx:377
This class is used by the SceneGraphReducer to maintain and accumulate the set of attributes we have ...
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
A container for geometry primitives.
Definition: geom.h:58
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
virtual void add_for_draw(CullTraverser *trav, CullTraverserData &data)
Adds the node&#39;s contents to the CullResult we are building up during the cull traversal, so that it will be drawn at render time.
Definition: pandaNode.cxx:591
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
virtual PandaNode * make_copy() const
Returns a newly-allocated PandaNode that is a shallow copy of this one.
Definition: pandaNode.cxx:604
This class is similar to CycleDataLockedReader, except it allows reading from a particular stage of t...
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:53
This class is similar to CycleDataReader, except it allows reading from a particular stage of the pip...
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
A thread; that is, a lightweight process.
Definition: thread.h:51
This is similar to RefCountObj, but it implements a CopyOnWriteObject inheritance instead of a Refere...
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
virtual bool is_geom_node() const
A simple downcast check.
Definition: pandaNode.cxx:2486
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
virtual bool is_renderable() const
Returns true if there is some value to visiting this particular node during the cull traversal for an...
Definition: pandaNode.cxx:578
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
Definition: cullTraverser.h:48
A node that holds Geom objects, renderable pieces of geometry.
Definition: geomNode.h:37
virtual bool safe_to_flatten() const
Returns true if it is generally safe to flatten out this particular kind of PandaNode by duplicating ...
Definition: pandaNode.cxx:237
An object specifically designed to transform the vertices of a Geom without disturbing indexing or af...