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 */
34class EXPCL_PANDA_PGRAPH GeomNode : public PandaNode {
35PUBLISHED:
36 explicit GeomNode(const std::string &name);
37
38protected:
39 GeomNode(const GeomNode &copy);
40public:
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
65PUBLISHED:
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
94public:
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
103protected:
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
110public:
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
122private:
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
158public:
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
190public:
191 static void register_with_read_factory();
192 virtual void write_datagram(BamWriter *manager, Datagram &dg);
193
194 virtual void finalize(BamReader *manager);
195
196protected:
197 static TypedWritable *make_from_bam(const FactoryParams &params);
198 void fillin(DatagramIterator &scan, BamReader *manager);
199
200public:
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
215private:
216 static TypeHandle _type_handle;
217
218 friend class GeomTransformer;
219};
220
221#include "geomNode.I"
222
223#endif
This class is used by the SceneGraphReducer to maintain and accumulate the set of attributes we have ...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
This is an abstract class for any volume in any sense which can be said to define the locality of ref...
This is similar to RefCountObj, but it implements a CopyOnWriteObject inheritance instead of a Refere...
This collects together the pieces of data that are accumulated for each node while walking the scene ...
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
Definition: cullTraverser.h:45
This class is similar to CycleDataLockedReader, except it allows reading from a particular stage of t...
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
This class is similar to CycleDataReader, except it allows reading from a particular stage of the pip...
This class is similar to CycleDataWriter, except it allows writing to a particular stage of the pipel...
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
A single page of data maintained by a PipelineCycler.
Definition: cycleData.h:50
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
A node that holds Geom objects, renderable pieces of geometry.
Definition: geomNode.h:34
virtual bool is_renderable() const
Returns true if there is some value to visiting this particular node during the cull traversal for an...
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,...
An object specifically designed to transform the vertices of a Geom without disturbing indexing or af...
A container for geometry primitives.
Definition: geom.h:54
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
Encodes a string name in a hash table, mapping it to a pointer.
Definition: internalName.h:38
A basic node of the scene graph or data graph.
Definition: pandaNode.h:65
virtual bool is_geom_node() const
A simple downcast check.
Definition: pandaNode.cxx:2062
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
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
get_legal_collide_mask
Returns the subset of CollideMask bits that may be set for this particular type of PandaNode.
Definition: pandaNode.h:265
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
static void register_with_read_factory()
Tells the BamReader how to create objects of type PandaNode.
Definition: pandaNode.cxx:3574
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
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
virtual PandaNode * make_copy() const
Returns a newly-allocated PandaNode that is a shallow copy of this one.
Definition: pandaNode.cxx:481
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: pandaNode.cxx:3583
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
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:47
A thread; that is, a lightweight process.
Definition: thread.h:46
get_current_thread
Returns a pointer to the currently-executing Thread object.
Definition: thread.h:109
Indicates a coordinate-system transform on vertices.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
virtual void finalize(BamReader *manager)
Called by the BamReader to perform any final actions needed for setting up the object after all objec...
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().
This is our own Panda specialization on the default STL list.
Definition: plist.h:35
This is our own Panda specialization on the default STL map.
Definition: pmap.h:49
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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