Panda3D

Loading...
Searching...
No Matches
transformBlendTable.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 transformBlendTable.h
10 * @author drose
11 * @date 2005-03-24
12 */
13
14#ifndef TRANSFORMBLENDTABLE_H
15#define TRANSFORMBLENDTABLE_H
16
17#include "pandabase.h"
18#include "transformBlend.h"
19#include "vertexTransform.h"
20#include "copyOnWriteObject.h"
21#include "pointerTo.h"
22#include "pvector.h"
23#include "pmap.h"
24#include "indirectLess.h"
25#include "cycleData.h"
26#include "cycleDataLockedReader.h"
27#include "cycleDataReader.h"
28#include "cycleDataWriter.h"
29#include "pipelineCycler.h"
30#include "sparseArray.h"
31
32 class FactoryParams;
33
34/**
35 * This structure collects together the different combinations of transforms
36 * and blend amounts used by a GeomVertexData, to facilitate computing dynamic
37 * vertices on the CPU at runtime. Each vertex has a pointer to exactly one
38 * of the entries in this table, and each entry defines a number of
39 * transform/blend combinations.
40 *
41 * This structure is used for a GeomVertexData set up to compute its dynamic
42 * vertices on the CPU. See TransformTable for one set up to compute its
43 * dynamic vertices on the graphics card.
44 */
45 class EXPCL_PANDA_GOBJ TransformBlendTable : public CopyOnWriteObject {
46 protected:
47 virtual PT(CopyOnWriteObject) make_cow_copy();
48
49PUBLISHED:
50 TransformBlendTable();
51 TransformBlendTable(const TransformBlendTable &copy);
52 void operator = (const TransformBlendTable &copy);
53 virtual ~TransformBlendTable();
54
55 INLINE size_t get_num_blends() const;
56 INLINE const TransformBlend &get_blend(size_t n) const;
57 MAKE_SEQ(get_blends, get_num_blends, get_blend);
58 INLINE UpdateSeq get_modified(Thread *current_thread = Thread::get_current_thread()) const;
59
60 void set_blend(size_t n, const TransformBlend &blend);
61 void remove_blend(size_t n);
62 size_t add_blend(const TransformBlend &blend);
63
64 INLINE int get_num_transforms() const;
65 INLINE int get_max_simultaneous_transforms() const;
66
67 INLINE void set_rows(const SparseArray &rows);
68 INLINE const SparseArray &get_rows() const;
69 INLINE SparseArray &modify_rows();
70
71 void write(std::ostream &out, int indent_level) const;
72
73 MAKE_SEQ_PROPERTY(blends, get_num_blends, get_blend, set_blend, remove_blend);
74 MAKE_PROPERTY(modified, get_modified);
75 MAKE_PROPERTY(num_transforms, get_num_transforms);
76 MAKE_PROPERTY(max_simultaneous_transforms, get_max_simultaneous_transforms);
77 MAKE_PROPERTY(rows, get_rows, set_rows);
78
79 private:
80 class CData;
81
82 void clear_index();
83 INLINE void consider_rebuild_index() const;
84 void rebuild_index();
85
86 void recompute_modified(CData *cdata, Thread *current_thread);
87 void clear_modified(Thread *current_thread);
88
89 private:
90 // We don't bother with registering the table, or protecting its data in a
91 // CycleData structure--the interface on GeomVertexData guarantees that the
92 // pointer will be copied if we modify the table.
93 typedef pvector<TransformBlend> Blends;
94 Blends _blends;
95
96 SparseArray _rows;
97
98 // This map indexes directly into the above vector. That means any time we
99 // add or remove anything from the vector, we must completely rebuild the
100 // index (since the vector might reallocate, invalidating all the pointers
101 // into it).
102 typedef pmap<const TransformBlend *, int, IndirectLess<TransformBlend> > BlendIndex;
103 BlendIndex _blend_index;
104 int _num_transforms;
105 int _max_simultaneous_transforms;
106
107 // Even though we don't store the actual blend table data in a CycleData
108 // structure, we do need to keep a local cache of the relevant modified
109 // stamps there, so it can be updated per-thread.
110 class EXPCL_PANDA_GOBJ CData : public CycleData {
111 public:
112 INLINE CData();
113 INLINE CData(const CData &copy);
114 virtual CycleData *make_copy() const;
115 virtual void write_datagram(BamWriter *manager, Datagram &dg) const;
116 virtual void fillin(DatagramIterator &scan, BamReader *manager);
117 virtual TypeHandle get_parent_type() const {
118 return TransformBlendTable::get_class_type();
119 }
120
121 UpdateSeq _modified;
122 UpdateSeq _global_modified;
123 };
124
125 PipelineCycler<CData> _cycler;
126 typedef CycleDataLockedReader<CData> CDLockedReader;
127 typedef CycleDataReader<CData> CDReader;
128 typedef CycleDataWriter<CData> CDWriter;
129
130 public:
131 static void register_with_read_factory();
132 virtual void write_datagram(BamWriter *manager, Datagram &dg);
133 virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
134
135 protected:
136 static TypedWritable *make_from_bam(const FactoryParams &params);
137 void fillin(DatagramIterator &scan, BamReader *manager);
138
139 public:
140 static TypeHandle get_class_type() {
141 return _type_handle;
142 }
143 static void init_type() {
144 CopyOnWriteObject::init_type();
145 register_type(_type_handle, "TransformBlendTable",
146 CopyOnWriteObject::get_class_type());
147 }
148 virtual TypeHandle get_type() const {
149 return get_class_type();
150 }
151 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
152
153 private:
154 static TypeHandle _type_handle;
155
156 friend class VertexTransform;
157};
158
159INLINE std::ostream &operator << (std::ostream &out, const TransformBlendTable &obj);
160
161#include "transformBlendTable.I"
162
163#endif
BamReader
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
BamWriter
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition bamWriter.h:63
CycleData
A single page of data maintained by a PipelineCycler.
Definition cycleData.h:50
DatagramIterator
A class to retrieve the individual data elements previously stored in a Datagram.
Definition datagramIterator.h:30
Datagram
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
FactoryParams
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition factoryParams.h:36
SparseArray
This class records a set of integers, where each integer is either present or not present in the set.
Definition sparseArray.h:43
Thread
A thread; that is, a lightweight process.
Definition thread.h:46
Thread::get_current_thread
get_current_thread
Returns a pointer to the currently-executing Thread object.
Definition thread.h:109
TransformBlendTable
This structure collects together the different combinations of transforms and blend amounts used by a...
Definition transformBlendTable.h:45
TransformBlendTable::remove_blend
remove_blend
Removes the blend at the nth position.
Definition transformBlendTable.h:73
TransformBlendTable::set_blend
set_blend
Replaces the blend at the nth position with the indicated value.
Definition transformBlendTable.h:73
TransformBlendTable::get_max_simultaneous_transforms
get_max_simultaneous_transforms
Returns the maximum number of unique VertexTransform objects that are applied to any one vertex simul...
Definition transformBlendTable.h:76
TransformBlendTable::get_rows
get_rows
Returns the subset of rows (vertices) in the associated GeomVertexData that this TransformBlendTable ...
Definition transformBlendTable.h:77
TransformBlendTable::set_rows
set_rows
Specifies the subset of rows (vertices) in the associated GeomVertexData that this TransformBlendTabl...
Definition transformBlendTable.h:77
TransformBlendTable::get_num_blends
get_num_blends
Returns the total number of different blend combinations in the table.
Definition transformBlendTable.h:57
TransformBlendTable::add_blend
size_t add_blend(const TransformBlend &blend)
Adds a new blend to the table, and returns its index number.
Definition transformBlendTable.cxx:87
TransformBlendTable::get_modified
get_modified
Returns a counter which is guaranteed to increment at least when any TransformBlends within the table...
Definition transformBlendTable.h:74
TransformBlendTable::get_blend
get_blend
Returns the nth blend in the table.
Definition transformBlendTable.h:57
TransformBlendTable::modify_rows
SparseArray & modify_rows()
Returns a modifiable reference to the SparseArray that specifies the subset of rows (vertices) in the...
Definition transformBlendTable.I:102
TransformBlendTable::get_num_transforms
get_num_transforms
Returns the number of unique VertexTransform objects represented in the table.
Definition transformBlendTable.h:75
TransformBlend
This defines a single entry in a TransformBlendTable.
Definition transformBlend.h:32
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
TypedWritable::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 typedWritable.cxx:103
TypedWritable::write_datagram
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 typedWritable.cxx:54
TypedWritable::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 typedWritable.cxx:81
UpdateSeq
This is a sequence number that increments monotonically.
Definition updateSeq.h:37
copyOnWriteObject.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
cycleDataLockedReader.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
cycleDataReader.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
cycleDataWriter.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
cycleData.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
indirectLess.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pipelineCycler.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pmap.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pointerTo.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pvector.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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
sparseArray.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
transformBlendTable.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
transformBlend.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
vertexTransform.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.