forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeomVertexArrayData.h
More file actions
357 lines (291 loc) · 12.1 KB
/
geomVertexArrayData.h
File metadata and controls
357 lines (291 loc) · 12.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file geomVertexArrayData.h
* @author drose
* @date 2005-03-17
*/
#ifndef GEOMVERTEXARRAYDATA_H
#define GEOMVERTEXARRAYDATA_H
#include "pandabase.h"
#include "copyOnWriteObject.h"
#include "geomVertexArrayFormat.h"
#include "geomEnums.h"
#include "pta_uchar.h"
#include "updateSeq.h"
#include "cycleData.h"
#include "cycleDataReader.h"
#include "cycleDataWriter.h"
#include "cycleDataStageReader.h"
#include "cycleDataStageWriter.h"
#include "pipelineCycler.h"
#include "pmap.h"
#include "reMutex.h"
#include "simpleLru.h"
#include "vertexDataBuffer.h"
#include "config_gobj.h"
#include "bamReader.h"
class PreparedGraphicsObjects;
class VertexBufferContext;
class GraphicsStateGuardianBase;
class GeomVertexArrayDataHandle;
class VertexDataBook;
class SimpleAllocatorBlock;
/**
* This is the data for one array of a GeomVertexData structure. Many
* GeomVertexData structures will only define one array, with all data
* elements interleaved (DirectX 8.0 and before insisted on this format); some
* will define multiple arrays.
*
* DirectX calls this concept of one array a "stream". It also closely
* correlates with the concept of a vertex buffer.
*
* This object is just a block of data. In general, you should not be
* directly messing with this object from application code. See
* GeomVertexData for the organizing structure, and see
* GeomVertexReader/Writer/Rewriter for high-level tools to manipulate the
* actual vertex data.
*/
class EXPCL_PANDA_GOBJ GeomVertexArrayData : public CopyOnWriteObject, public SimpleLruPage, public GeomEnums {
private:
GeomVertexArrayData();
protected:
virtual PT(CopyOnWriteObject) make_cow_copy();
PUBLISHED:
explicit GeomVertexArrayData(const GeomVertexArrayFormat *array_format,
UsageHint usage_hint);
GeomVertexArrayData(const GeomVertexArrayData ©);
void operator = (const GeomVertexArrayData ©);
virtual ~GeomVertexArrayData();
ALLOC_DELETED_CHAIN(GeomVertexArrayData);
int compare_to(const GeomVertexArrayData &other) const;
INLINE const GeomVertexArrayFormat *get_array_format() const;
MAKE_PROPERTY(array_format, get_array_format);
INLINE UsageHint get_usage_hint() const;
void set_usage_hint(UsageHint usage_hint);
MAKE_PROPERTY(usage_hint, get_usage_hint, set_usage_hint);
INLINE bool has_column(const InternalName *name) const;
INLINE int get_num_rows() const;
INLINE bool set_num_rows(int n);
INLINE bool unclean_set_num_rows(int n);
INLINE bool reserve_num_rows(int n);
INLINE void clear_rows();
INLINE size_t get_data_size_bytes() const;
INLINE UpdateSeq get_modified() const;
MAKE_PROPERTY(data_size_bytes, get_data_size_bytes);
MAKE_PROPERTY(modified, get_modified);
void output(std::ostream &out) const;
void write(std::ostream &out, int indent_level = 0) const;
INLINE bool request_resident(Thread *current_thread = Thread::get_current_thread()) const;
INLINE CPT(GeomVertexArrayDataHandle) get_handle(Thread *current_thread = Thread::get_current_thread()) const;
INLINE PT(GeomVertexArrayDataHandle) modify_handle(Thread *current_thread = Thread::get_current_thread());
void prepare(PreparedGraphicsObjects *prepared_objects);
bool is_prepared(PreparedGraphicsObjects *prepared_objects) const;
VertexBufferContext *prepare_now(PreparedGraphicsObjects *prepared_objects,
GraphicsStateGuardianBase *gsg);
bool release(PreparedGraphicsObjects *prepared_objects);
int release_all();
INLINE static SimpleLru *get_independent_lru();
INLINE static SimpleLru *get_small_lru();
static void lru_epoch();
INLINE static VertexDataBook &get_book();
#ifdef HAVE_PYTHON
EXTENSION(int __getbuffer__(PyObject *self, Py_buffer *view, int flags));
EXTENSION(int __getbuffer__(PyObject *self, Py_buffer *view, int flags) const);
EXTENSION(void __releasebuffer__(PyObject *self, Py_buffer *view) const);
#endif
public:
virtual void evict_lru();
private:
INLINE void set_lru_size(size_t lru_size);
INLINE void mark_used();
void clear_prepared(PreparedGraphicsObjects *prepared_objects);
void reverse_data_endianness(unsigned char *dest,
const unsigned char *source, size_t size);
CPT(GeomVertexArrayFormat) _array_format;
// A GeomVertexArrayData keeps a list (actually, a map) of all the
// PreparedGraphicsObjects tables that it has been prepared into. Each PGO
// conversely keeps a list (a set) of all the Geoms that have been prepared
// there. When either destructs, it removes itself from the other's list.
typedef pmap<PreparedGraphicsObjects *, VertexBufferContext *> Contexts;
Contexts *_contexts;
// This data is only needed when reading from a bam file.
class BamAuxData : public BamReader::AuxData {
public:
// set true to indicate the data must be endian-reversed in finalize().
bool _endian_reversed;
};
// This is the data that must be cycled between pipeline stages.
class EXPCL_PANDA_GOBJ CData : public CycleData {
public:
INLINE CData(UsageHint usage_hint = UH_unspecified);
INLINE CData(CData &&from) noexcept;
INLINE CData(const CData ©);
INLINE void operator = (const CData ©);
virtual ~CData();
ALLOC_DELETED_CHAIN(CData);
virtual CycleData *make_copy() const;
virtual void write_datagram(BamWriter *manager, Datagram &dg,
void *extra_data) const;
virtual void fillin(DatagramIterator &scan, BamReader *manager,
void *extra_data);
virtual TypeHandle get_parent_type() const {
return GeomVertexArrayData::get_class_type();
}
UsageHint _usage_hint;
VertexDataBuffer _buffer;
UpdateSeq _modified;
// This implements read-write locking. Anyone who gets the data for
// reading or writing will hold this mutex during the lock.
ReMutex _rw_lock;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
register_type(_type_handle, "GeomVertexArrayData::CData");
}
private:
static TypeHandle _type_handle;
friend class GeomVertexArrayData;
};
PipelineCycler<CData> _cycler;
typedef CycleDataReader<CData> CDReader;
typedef CycleDataWriter<CData> CDWriter;
typedef CycleDataStageReader<CData> CDStageReader;
typedef CycleDataStageWriter<CData> CDStageWriter;
static SimpleLru _independent_lru;
static SimpleLru _small_lru;
static VertexDataBook _book;
public:
static void register_with_read_factory();
virtual void write_datagram(BamWriter *manager, Datagram &dg);
PTA_uchar read_raw_data(BamReader *manager, DatagramIterator &source);
virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
virtual void finalize(BamReader *manager);
protected:
static TypedWritable *make_from_bam(const FactoryParams ¶ms);
void fillin(DatagramIterator &scan, BamReader *manager);
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
CopyOnWriteObject::init_type();
register_type(_type_handle, "GeomVertexArrayData",
CopyOnWriteObject::get_class_type());
CData::init_type();
}
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
private:
static TypeHandle _type_handle;
friend class GeomCacheManager;
friend class GeomVertexData;
friend class PreparedGraphicsObjects;
friend class GeomVertexArrayDataHandle;
friend class GeomPrimitivePipelineReader;
};
/**
* This data object is returned by GeomVertexArrayData::get_handle() or
* modify_handle(). As long as it exists, the data is locked; when the last of
* these destructs, the data is unlocked.
*
* Only one thread at a time may lock the data; other threads attempting to
* lock the data will block. A given thread may simultaneously lock the data
* multiple times.
*
* This class serves in lieu of a pair of GeomVertexArrayDataPipelineReader
* and GeomVertexArrayDataPipelineWriter classes
*/
class EXPCL_PANDA_GOBJ GeomVertexArrayDataHandle : public ReferenceCount, public GeomEnums {
private:
INLINE GeomVertexArrayDataHandle(CPT(GeomVertexArrayData) object,
Thread *current_thread);
INLINE GeomVertexArrayDataHandle(const GeomVertexArrayData *object,
Thread *current_thread);
INLINE GeomVertexArrayDataHandle(PT(GeomVertexArrayData) object,
Thread *current_thread);
INLINE GeomVertexArrayDataHandle(GeomVertexArrayData *object,
Thread *current_thread);
PUBLISHED:
INLINE ~GeomVertexArrayDataHandle();
public:
GeomVertexArrayDataHandle(const GeomVertexArrayDataHandle &) = delete;
ALLOC_DELETED_CHAIN_DECL(GeomVertexArrayDataHandle);
GeomVertexArrayDataHandle &operator = (const GeomVertexArrayDataHandle &) = delete;
INLINE Thread *get_current_thread() const;
INLINE const unsigned char *get_read_pointer(bool force) const RETURNS_ALIGNED(MEMORY_HOOK_ALIGNMENT);
unsigned char *get_write_pointer() RETURNS_ALIGNED(MEMORY_HOOK_ALIGNMENT);
PUBLISHED:
INLINE const GeomVertexArrayData *get_object() const;
INLINE GeomVertexArrayData *get_object();
MAKE_PROPERTY(object, get_object);
INLINE const GeomVertexArrayFormat *get_array_format() const;
INLINE UsageHint get_usage_hint() const;
MAKE_PROPERTY(array_format, get_array_format);
MAKE_PROPERTY(usage_hint, get_usage_hint);
INLINE int get_num_rows() const;
bool set_num_rows(int n);
bool unclean_set_num_rows(int n);
bool reserve_num_rows(int n);
INLINE void clear_rows();
INLINE size_t get_data_size_bytes() const;
INLINE UpdateSeq get_modified() const;
MAKE_PROPERTY(data_size_bytes, get_data_size_bytes);
MAKE_PROPERTY(modified, get_modified);
INLINE bool request_resident() const;
INLINE VertexBufferContext *prepare_now(PreparedGraphicsObjects *prepared_objects,
GraphicsStateGuardianBase *gsg) const;
void copy_data_from(const GeomVertexArrayDataHandle *other);
void copy_subdata_from(size_t to_start, size_t to_size,
const GeomVertexArrayDataHandle *other,
size_t from_start, size_t from_size);
void copy_data_from(const unsigned char *source, size_t size);
void copy_subdata_from(size_t to_start, size_t to_size,
const unsigned char *source,
size_t from_start, size_t from_size);
EXTENSION(void copy_data_from(PyObject *buffer));
EXTENSION(void copy_subdata_from(size_t to_start, size_t to_size,
PyObject *buffer));
EXTENSION(void copy_subdata_from(size_t to_start, size_t to_size,
PyObject *buffer,
size_t from_start, size_t from_size));
INLINE vector_uchar get_data() const;
void set_data(const vector_uchar &data);
INLINE vector_uchar get_subdata(size_t start, size_t size) const;
void set_subdata(size_t start, size_t size, const vector_uchar &data);
INLINE void mark_used() const;
private:
PT(GeomVertexArrayData) _object;
Thread *const _current_thread;
GeomVertexArrayData::CData *_cdata;
bool _writable;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
ReferenceCount::init_type();
register_type(_type_handle, "GeomVertexArrayDataHandle",
ReferenceCount::get_class_type());
}
private:
static TypeHandle _type_handle;
friend class Geom;
friend class GeomPrimitive;
friend class GeomVertexData;
friend class GeomVertexDataPipelineReader;
friend class GeomVertexDataPipelineWriter;
friend class GeomVertexArrayData;
};
INLINE std::ostream &operator << (std::ostream &out, const GeomVertexArrayData &obj);
#include "geomVertexArrayData.I"
#endif