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"
27#include "cycleDataReader.h"
28#include "cycleDataWriter.h"
29#include "pipelineCycler.h"
30#include "sparseArray.h"
31
32class 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 */
45class EXPCL_PANDA_GOBJ TransformBlendTable : public CopyOnWriteObject {
46protected:
47 virtual PT(CopyOnWriteObject) make_cow_copy();
48
49PUBLISHED:
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
79private:
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
89private:
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.
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).
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
130public:
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
135protected:
136 static TypedWritable *make_from_bam(const FactoryParams &params);
137 void fillin(DatagramIterator &scan, BamReader *manager);
138
139public:
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
153private:
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
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 base class provides basic reference counting, but also can be used with a CopyOnWritePointer to ...
This template class calls PipelineCycler::read() in the constructor and PipelineCycler::release_read(...
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
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...
This class records a set of integers, where each integer is either present or not present in the set.
Definition sparseArray.h:43
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
This structure collects together the different combinations of transforms and blend amounts used by a...
This defines a single entry in a TransformBlendTable.
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.
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...
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->read_pointer() was called in fillin().
This is a sequence number that increments monotonically.
Definition updateSeq.h:37
This is an abstract base class that holds a pointer to some transform, computed in some arbitrary way...
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
This is our own Panda specialization on the default STL vector.
Definition pvector.h:42
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.
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(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This class maintains different copies of a page of data between stages of the graphics pipeline (or a...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.