Panda3D
geomNode.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file geomNode.h
10  * @author drose
11  * @date 2002-02-22
12  */
13 
14 #ifndef GEOMNODE_H
15 #define GEOMNODE_H
16 
17 #include "pandabase.h"
18 #include "config_pgraph.h"
19 #include "pandaNode.h"
20 #include "pointerToArray.h"
21 #include "geom.h"
22 #include "pipelineCycler.h"
23 #include "cycleData.h"
24 #include "pvector.h"
25 #include "copyOnWritePointer.h"
26 
28 
29 /**
30  * A node that holds Geom objects, renderable pieces of geometry. This is the
31  * primary kind of leaf node in the scene graph; almost all visible objects
32  * will be contained in a GeomNode somewhere.
33  */
34 class EXPCL_PANDA_PGRAPH GeomNode : public PandaNode {
35 PUBLISHED:
36  explicit GeomNode(const std::string &name);
37 
38 protected:
39  GeomNode(const GeomNode &copy);
40 public:
41  virtual ~GeomNode();
42  virtual PandaNode *make_copy() const;
43  virtual void apply_attribs_to_vertices(const AccumulatedAttribs &attribs,
44  int attrib_types,
45  GeomTransformer &transformer);
46  virtual void xform(const LMatrix4 &mat);
47  virtual PandaNode *combine_with(PandaNode *other);
48  virtual CPT(TransformState)
49  calc_tight_bounds(LPoint3 &min_point, LPoint3 &max_point,
50  bool &found_any,
51  const TransformState *transform,
52  Thread *current_thread) const;
53  virtual bool is_renderable() const;
54  virtual void add_for_draw(CullTraverser *trav, CullTraverserData &data);
55  virtual CollideMask get_legal_collide_mask() const;
56 
57  virtual bool safe_to_flatten() const;
58  virtual bool safe_to_combine() const;
59 
61  const RenderState *node_state,
62  GeomTransformer &transformer,
63  Thread *current_thread);
64 
65 PUBLISHED:
66  INLINE void set_preserved(bool value);
67  INLINE bool get_preserved() const;
68 
69  INLINE int get_num_geoms() const;
70  INLINE CPT(Geom) get_geom(int n) const;
71  MAKE_SEQ(get_geoms, get_num_geoms, get_geom);
72  INLINE PT(Geom) modify_geom(int n);
73  MAKE_SEQ(modify_geoms, get_num_geoms, modify_geom);
74  INLINE const RenderState *get_geom_state(int n) const;
75  MAKE_SEQ(get_geom_states, get_num_geoms, get_geom_state);
76  INLINE void set_geom_state(int n, const RenderState *state);
77 
78  void add_geom(Geom *geom, const RenderState *state = RenderState::make_empty());
79  void add_geoms_from(const GeomNode *other);
80  void set_geom(int n, Geom *geom);
81  INLINE void remove_geom(int n);
82  INLINE void remove_all_geoms();
83  bool check_valid() const;
84 
85  void decompose();
86  void unify(int max_indices, bool preserve_order);
87 
88  void write_geoms(std::ostream &out, int indent_level) const;
89  void write_verbose(std::ostream &out, int indent_level) const;
90 
91  INLINE static CollideMask get_default_collide_mask();
92  MAKE_PROPERTY(default_collide_mask, get_default_collide_mask);
93 
94 public:
95  virtual void output(std::ostream &out) const;
96 
97  virtual bool is_geom_node() const;
98 
99  void do_premunge(GraphicsStateGuardianBase *gsg,
100  const RenderState *node_state,
101  GeomTransformer &transformer);
102 
103 protected:
104  virtual void r_mark_geom_bounds_stale(Thread *current_thread);
105  virtual void compute_internal_bounds(CPT(BoundingVolume) &internal_bounds,
106  int &internal_vertices,
107  int pipeline_stage,
108  Thread *current_thread) const;
109 
110 public:
111  // This must be declared public so that VC6 will allow the nested CData
112  // class to access it.
113  class GeomEntry {
114  public:
115  INLINE GeomEntry(Geom *geom, const RenderState *state);
116  COWPT(Geom) _geom;
117  CPT(RenderState) _state;
118  };
119 
121 
122 private:
123 
124  bool _preserved;
126 
127  INLINE void count_name(NameCount &name_count, const InternalName *name);
128  INLINE int get_name_count(const NameCount &name_count, const InternalName *name);
129 
130  // This is the data that must be cycled between pipeline stages.
131  class EXPCL_PANDA_PGRAPH CData : public CycleData {
132  public:
133  INLINE CData();
134  CData(const CData &copy);
135  virtual CycleData *make_copy() const;
136  virtual void write_datagram(BamWriter *manager, Datagram &dg) const;
137  virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
138  virtual void fillin(DatagramIterator &scan, BamReader *manager);
139  virtual TypeHandle get_parent_type() const {
140  return GeomNode::get_class_type();
141  }
142 
143  INLINE CPT(GeomList) get_geoms() const;
144  INLINE PT(GeomList) modify_geoms();
145  INLINE void set_geoms(GeomList *geoms);
146 
147  private:
148  COWPT(GeomList) _geoms;
149  };
150 
151  PipelineCycler<CData> _cycler;
152  typedef CycleDataReader<CData> CDReader;
153  typedef CycleDataWriter<CData> CDWriter;
154  typedef CycleDataStageReader<CData> CDStageReader;
155  typedef CycleDataLockedStageReader<CData> CDLockedStageReader;
156  typedef CycleDataStageWriter<CData> CDStageWriter;
157 
158 public:
159  // This class is returned from get_geoms(). It is similar to
160  // PandaNode::get_children(); use this to walk through the list of geoms
161  // faster than walking through the geoms directly from the node.
162  class EXPCL_PANDA_PGRAPH Geoms {
163  public:
164  INLINE Geoms();
165  INLINE Geoms(const CData *cdata);
166  INLINE Geoms(const Geoms &copy);
167  INLINE Geoms(Geoms &&from) noexcept;
168 
169  INLINE void operator = (const Geoms &copy);
170  INLINE void operator = (Geoms &&from) noexcept;
171 
172  INLINE int get_num_geoms() const;
173  INLINE CPT(Geom) get_geom(int n) const;
174  INLINE const RenderState *get_geom_state(int n) const;
175 
176  private:
177  CPT(GeomList) _geoms;
178  };
179 
180  INLINE Geoms get_geoms(Thread *current_thread = Thread::get_current_thread()) const;
181 
182  // This data is only needed when reading from a bam file.
184  public:
185  // We just hold a pointer to the RenderState that may otherwise lose its
186  // pointers before it can finalize.
187  CPT(RenderState) _hold_state;
188  };
189 
190 public:
191  static void register_with_read_factory();
192  virtual void write_datagram(BamWriter *manager, Datagram &dg);
193 
194  virtual void finalize(BamReader *manager);
195 
196 protected:
197  static TypedWritable *make_from_bam(const FactoryParams &params);
198  void fillin(DatagramIterator &scan, BamReader *manager);
199 
200 public:
201  static TypeHandle get_class_type() {
202  return _type_handle;
203  }
204  static void init_type() {
205  GeomList::init_type();
206  PandaNode::init_type();
207  register_type(_type_handle, "GeomNode",
208  PandaNode::get_class_type());
209  }
210  virtual TypeHandle get_type() const {
211  return get_class_type();
212  }
213  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
214 
215 private:
216  static TypeHandle _type_handle;
217 
218  friend class GeomTransformer;
219 };
220 
221 #include "geomNode.I"
222 
223 #endif
Geom
A container for geometry primitives.
Definition: geom.h:54
PandaNode::combine_with
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:319
PandaNode::is_geom_node
virtual bool is_geom_node() const
A simple downcast check.
Definition: pandaNode.cxx:2062
GeomNode::Geoms
Definition: geomNode.h:162
pandaNode.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
CycleData
A single page of data maintained by a PipelineCycler.
Definition: cycleData.h:50
CycleData::get_parent_type
virtual TypeHandle get_parent_type() const
Returns the type of the container that owns the CycleData.
Definition: cycleData.cxx:76
geomNode.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
GeomTransformer
An object specifically designed to transform the vertices of a Geom without disturbing indexing or af...
Definition: geomTransformer.h:42
pvector.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
CycleDataStageReader
This class is similar to CycleDataReader, except it allows reading from a particular stage of the pip...
Definition: cycleDataStageReader.h:27
DatagramIterator
A class to retrieve the individual data elements previously stored in a Datagram.
Definition: datagramIterator.h:27
pmap
This is our own Panda specialization on the default STL map.
Definition: pmap.h:49
register_type
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
BamReader
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
CycleDataLockedStageReader
This class is similar to CycleDataLockedReader, except it allows reading from a particular stage of t...
Definition: cycleDataLockedStageReader.h:27
PandaNode::apply_attribs_to_vertices
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:282
BamWriter
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
CullTraverser
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
Definition: cullTraverser.h:45
InternalName
Encodes a string name in a hash table, mapping it to a pointer.
Definition: internalName.h:38
BitMask< uint32_t, 32 >
TypedWritable
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
Datagram
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
RenderState
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:47
CycleData::write_datagram
virtual void write_datagram(BamWriter *, Datagram &) const
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: cycleData.cxx:32
Thread::get_current_thread
get_current_thread
Returns a pointer to the currently-executing Thread object.
Definition: thread.h:109
AccumulatedAttribs
This class is used by the SceneGraphReducer to maintain and accumulate the set of attributes we have ...
Definition: accumulatedAttribs.h:30
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
GeomNode
A node that holds Geom objects, renderable pieces of geometry.
Definition: geomNode.h:34
CopyOnWriteObj
This is similar to RefCountObj, but it implements a CopyOnWriteObject inheritance instead of a Refere...
Definition: copyOnWriteObject.h:102
FactoryParams
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
CycleDataWriter
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
Definition: cycleDataWriter.h:34
cycleData.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
GeomNode::GeomEntry
Definition: geomNode.h:113
TransformState
Indicates a coordinate-system transform on vertices.
Definition: transformState.h:54
CycleDataReader
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
Definition: cycleDataReader.h:35
CullTraverserData
This collects together the pieces of data that are accumulated for each node while walking the scene ...
Definition: cullTraverserData.h:40
CycleData::fillin
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class's make_from_bam() method to read in all...
Definition: cycleData.cxx:58
PandaNode::r_prepare_scene
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:2436
plist
This is our own Panda specialization on the default STL list.
Definition: plist.h:35
geom.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
CycleDataStageWriter
This class is similar to CycleDataWriter, except it allows writing to a particular stage of the pipel...
Definition: cycleDataStageWriter.h:31
pipelineCycler.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
GeomNode::is_renderable
virtual bool is_renderable() const
Returns true if there is some value to visiting this particular node during the cull traversal for an...
PandaNode::make_copy
virtual PandaNode * make_copy() const
Returns a newly-allocated PandaNode that is a shallow copy of this one.
Definition: pandaNode.cxx:481
PandaNode::safe_to_flatten
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:195
copyOnWritePointer.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
GraphicsStateGuardianBase
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
Definition: graphicsStateGuardianBase.h:110
BoundingVolume
This is an abstract class for any volume in any sense which can be said to define the locality of ref...
Definition: boundingVolume.h:41
PandaNode::get_legal_collide_mask
get_legal_collide_mask
Returns the subset of CollideMask bits that may be set for this particular type of PandaNode.
Definition: pandaNode.h:265
PandaNode
A basic node of the scene graph or data graph.
Definition: pandaNode.h:65
BamReader::AuxData
Definition: bamReader.h:228
pointerToArray.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Thread
A thread; that is, a lightweight process.
Definition: thread.h:46
config_pgraph.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
CycleData::complete_pointers
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
Definition: cycleData.cxx:48
PandaNode::xform
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:304
GeomNode::BamAuxData
Definition: geomNode.h:183
PipelineCycler< CData >
GeomNode::add_for_draw
virtual void add_for_draw(CullTraverser *trav, CullTraverserData &data)
Adds the node's contents to the CullResult we are building up during the cull traversal,...
PandaNode::safe_to_combine
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:228