18 get_array_format()
const {
26 INLINE GeomVertexArrayData::UsageHint GeomVertexArrayData::
27 get_usage_hint()
const {
28 CDReader cdata(_cycler);
29 return cdata->_usage_hint;
38 return _array_format->has_column(name);
49 nassertr(_array_format->get_stride() != 0, 0);
50 return cdata->_buffer.get_size() / _array_format->get_stride();
71 return modify_handle()->set_num_rows(n);
85 return modify_handle()->unclean_set_num_rows(n);
97 return modify_handle()->reserve_num_rows(n);
106 return modify_handle()->clear_rows();
112 INLINE
size_t GeomVertexArrayData::
113 get_data_size_bytes()
const {
114 CDReader cdata(_cycler);
115 return cdata->_buffer.get_size();
123 get_modified()
const {
124 CDReader cdata(_cycler);
125 return cdata->_modified;
136 const GeomVertexArrayData::CData *cdata = _cycler.
read_unlocked(current_thread);
142 cdata->_rw_lock.acquire();
145 bool is_resident = (cdata->_buffer.get_read_pointer(
false) !=
nullptr);
147 cdata->_rw_lock.release();
163 get_handle(
Thread *current_thread)
const {
174 modify_handle(
Thread *current_thread) {
184 return &_independent_lru;
208 INLINE
void GeomVertexArrayData::
209 set_lru_size(
size_t lru_size) {
212 if ((
int)lru_size <= vertex_data_small_size) {
221 INLINE
void GeomVertexArrayData::
233 INLINE GeomVertexArrayData::CData::
234 CData(UsageHint usage_hint) :
235 _usage_hint(usage_hint),
236 _rw_lock(
"GeomVertexArrayData::CData::_rw_lock")
243 INLINE GeomVertexArrayData::CData::
244 CData(GeomVertexArrayData::CData &&from) noexcept :
245 _usage_hint(std::move(from._usage_hint)),
246 _buffer(std::move(from._buffer)),
247 _modified(std::move(from._modified)),
248 _rw_lock(
"GeomVertexArrayData::CData::_rw_lock")
255 INLINE GeomVertexArrayData::CData::
256 CData(
const GeomVertexArrayData::CData ©) :
257 _usage_hint(copy._usage_hint),
258 _buffer(copy._buffer),
259 _modified(copy._modified),
260 _rw_lock(
"GeomVertexArrayData::CData::_rw_lock")
267 INLINE
void GeomVertexArrayData::CData::
268 operator = (
const GeomVertexArrayData::CData ©) {
269 _usage_hint = copy._usage_hint;
270 _buffer = copy._buffer;
271 _modified = copy._modified;
277 INLINE GeomVertexArrayDataHandle::
280 _current_thread(current_thread),
284 _object.swap(
object);
287 nassertv(_object->test_ref_count_nonzero());
291 #endif // DO_PIPELINING 294 _cdata->_rw_lock.acquire();
295 #ifdef DO_MEMORY_USAGE 303 INLINE GeomVertexArrayDataHandle::
307 _current_thread(current_thread),
312 nassertv(_object->test_ref_count_nonzero());
316 #endif // DO_PIPELINING 319 _cdata->_rw_lock.acquire();
320 #ifdef DO_MEMORY_USAGE 328 INLINE GeomVertexArrayDataHandle::
331 _current_thread(current_thread),
332 _cdata(object->_cycler.write_upstream(true, current_thread)),
335 _object.swap(
object);
338 nassertv(_object->test_ref_count_nonzero());
342 #endif // DO_PIPELINING 345 _cdata->_rw_lock.acquire();
346 #ifdef DO_MEMORY_USAGE 354 INLINE GeomVertexArrayDataHandle::
358 _current_thread(current_thread),
359 _cdata(object->_cycler.write_upstream(true, current_thread)),
363 nassertv(_object->test_ref_count_nonzero());
367 #endif // DO_PIPELINING 370 _cdata->_rw_lock.acquire();
371 #ifdef DO_MEMORY_USAGE 379 INLINE GeomVertexArrayDataHandle::
380 ~GeomVertexArrayDataHandle() {
382 nassertv(_object->test_ref_count_nonzero());
386 _object->_cycler.release_write(_cdata);
391 _cdata->_rw_lock.release();
395 #endif // DO_PIPELINING 406 INLINE
Thread *GeomVertexArrayDataHandle::
407 get_current_thread()
const {
408 return _current_thread;
422 return _cdata->_buffer.get_read_pointer(force);
445 get_array_format()
const {
446 return _object->_array_format;
452 INLINE GeomVertexArrayDataHandle::UsageHint GeomVertexArrayDataHandle::
453 get_usage_hint()
const {
454 return _cdata->_usage_hint;
460 INLINE
int GeomVertexArrayDataHandle::
461 get_num_rows()
const {
462 nassertr(_object->_array_format->get_stride() != 0, 0);
463 return get_data_size_bytes() / _object->_array_format->get_stride();
469 INLINE
void GeomVertexArrayDataHandle::
477 INLINE
size_t GeomVertexArrayDataHandle::
478 get_data_size_bytes()
const {
479 return _cdata->_buffer.get_size();
485 INLINE
UpdateSeq GeomVertexArrayDataHandle::
486 get_modified()
const {
487 return _cdata->_modified;
515 return _object->prepare_now(prepared_objects, gsg);
526 const unsigned char *ptr = _cdata->_buffer.get_read_pointer(
true);
527 return vector_uchar(ptr, ptr + _cdata->_buffer.get_size());
538 start = std::min(start, _cdata->_buffer.get_size());
539 size = std::min(size, _cdata->_buffer.get_size() - start);
540 const unsigned char *ptr = _cdata->_buffer.get_read_pointer(
true) + start;
541 return vector_uchar(ptr, ptr + size);
549 _object->mark_used();
552 INLINE std::ostream &
An implementation of a very simple LRU algorithm.
static SimpleLru * get_small_lru()
Returns a pointer to the global LRU object that manages the GeomVertexArrayData's that are deemed too...
bool has_column(const InternalName *name) const
Returns true if the array has the named column, false otherwise.
bool request_resident(Thread *current_thread=Thread::get_current_thread()) const
Returns true if the vertex data is currently resident in memory.
void mark_used_lru() const
To be called when the page is used; this will move it to the tail of the SimpleLru queue it is alread...
A single page of data maintained by a PipelineCycler.
static VertexDataBook & get_book()
Returns the global VertexDataBook that will be used to allocate vertex data buffers.
size_t get_lru_size() const
Returns the size of this page as reported to the LRU, presumably in bytes.
This data object is returned by GeomVertexArrayData::get_handle() or modify_handle().
A table of objects that are saved within the graphics context for reference by handle later.
bool request_resident() const
Returns true if the vertex data is currently resident in memory.
void set_lru_size(size_t lru_size)
Specifies the size of this page, presumably in bytes, although any unit is possible.
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
bool reserve_num_rows(int n)
This ensures that enough memory space for n rows is allocated, so that you may increase the number of...
CPT(GeomVertexArrayDataHandle) GeomVertexArrayData
Returns an object that can be used to read the actual data bytes stored in the array.
VertexBufferContext * prepare_now(PreparedGraphicsObjects *prepared_objects, GraphicsStateGuardianBase *gsg) const
Creates a context for the data on the particular GSG, if it does not already exist.
Encodes a string name in a hash table, mapping it to a pointer.
A collection of VertexDataPages, which can be used to allocate new VertexDataBlock objects.
static void update_type(ReferenceCount *ptr, TypeHandle type)
Associates the indicated type with the given pointer.
const unsigned char * get_read_pointer(bool force) const
Returns a readable pointer to the beginning of the actual data stream, or NULL if the data is not cur...
static SimpleLru * get_independent_lru()
Returns a pointer to the global LRU object that manages the GeomVertexArrayData's that have not (yet)...
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
int get_num_rows() const
Returns the number of rows stored in the array, based on the number of bytes and the stride.
const CycleDataType * read_unlocked(Thread *current_thread) const
See PipelineCyclerBase::read_unlocked().
void mark_used() const
Marks the array data recently-used.
A thread; that is, a lightweight process.
This is a special class object that holds all the information returned by a particular GSG to indicat...
bool unclean_set_num_rows(int n)
This method behaves like set_num_rows(), except the new data is not initialized.
void clear_rows()
Removes all of the rows in the array.
This is a sequence number that increments monotonically.
bool set_num_rows(int n)
Sets the length of the array to n rows.
vector_uchar get_data() const
Returns the entire raw data of the GeomVertexArrayData object, formatted as a string.
void unref_delete(RefCountType *ptr)
This global helper function will unref the given ReferenceCount object, and if the reference count re...
This is the data for one array of a GeomVertexData structure.
vector_uchar get_subdata(size_t start, size_t size) const
Returns a subset of the raw data of the GeomVertexArrayData object, formatted as a string.