23 void VertexDataBuffer::
28 if (_resident_data !=
nullptr) {
29 nassertv(_reserved_size != 0);
31 _resident_data =
nullptr;
33 if (copy._resident_data !=
nullptr && copy._size != 0) {
36 _resident_data = (
unsigned char *)get_class_type().
allocate_array(copy._size);
37 memcpy(_resident_data, copy._resident_data, copy._size);
40 _reserved_size = copy._size;
42 nassertv(_reserved_size >= _size);
53 unsigned char *resident_data = _resident_data;
55 size_t reserved_size = _reserved_size;
57 _block.swap(other._block);
59 _resident_data = other._resident_data;
61 _reserved_size = other._reserved_size;
63 other._resident_data = resident_data;
65 other._reserved_size = reserved_size;
66 nassertv(_reserved_size >= _size);
76 void VertexDataBuffer::
77 do_clean_realloc(
size_t reserved_size) {
78 if (reserved_size != _reserved_size) {
79 if (reserved_size == 0 || _size == 0) {
80 do_unclean_realloc(reserved_size);
84 if (gobj_cat.is_debug()) {
86 <<
this <<
".clean_realloc(" << reserved_size <<
")\n";
90 if (_reserved_size != 0 && _resident_data ==
nullptr) {
94 if (_reserved_size == 0) {
95 nassertv(_resident_data ==
nullptr);
96 _resident_data = (
unsigned char *)get_class_type().
allocate_array(reserved_size);
98 nassertv(_resident_data !=
nullptr);
99 _resident_data = (
unsigned char *)get_class_type().
reallocate_array(_resident_data, reserved_size);
101 nassertv(_resident_data !=
nullptr);
102 _reserved_size = reserved_size;
105 _size = std::min(_size, _reserved_size);
114 void VertexDataBuffer::
115 do_unclean_realloc(
size_t reserved_size) {
116 if (reserved_size != _reserved_size || _resident_data ==
nullptr) {
117 if (gobj_cat.is_debug()) {
119 <<
this <<
".unclean_realloc(" << reserved_size <<
")\n";
125 if (_resident_data !=
nullptr) {
126 nassertv(_reserved_size != 0);
129 _resident_data =
nullptr;
133 if (reserved_size != 0) {
134 nassertv(_resident_data ==
nullptr);
135 _resident_data = (
unsigned char *)get_class_type().
allocate_array(reserved_size);
138 _reserved_size = reserved_size;
152 void VertexDataBuffer::
154 if (_block !=
nullptr || _reserved_size == 0) {
158 nassertv(_resident_data !=
nullptr);
164 _resident_data =
nullptr;
170 _block = book.
alloc(_size);
171 nassertv(_block !=
nullptr);
172 unsigned char *pointer = _block->get_pointer(
true);
173 nassertv(pointer !=
nullptr);
174 memcpy(pointer, _resident_data, _size);
177 _resident_data =
nullptr;
179 _reserved_size = _size;
181 nassertv(_reserved_size >= _size);
190 void VertexDataBuffer::
192 if (_resident_data !=
nullptr || _reserved_size == 0) {
197 nassertv(_block !=
nullptr);
198 nassertv(_reserved_size == _size);
200 _resident_data = (
unsigned char *)get_class_type().
allocate_array(_size);
201 nassertv(_resident_data !=
nullptr);
203 memcpy(_resident_data, _block->get_pointer(
true), _size);
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void deallocate_array(void *ptr)
Deallocates memory, subtracting it from the total amount of memory allocated for this type.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Similar to MutexHolder, but for a light mutex.
void swap(VertexDataBuffer &other)
Swaps the data buffers between this one and the other one.
A block of bytes that stores the actual raw vertex data referenced by a GeomVertexArrayData object.
VertexDataBlock * alloc(size_t size)
Allocates and returns a new VertexDataBuffer of the requested size.
A collection of VertexDataPages, which can be used to allocate new VertexDataBlock objects.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void * reallocate_array(void *ptr, size_t size)
Reallocates memory, adjusting the total amount of memory allocated for this type.
void * allocate_array(size_t size)
Allocates memory, adding it to the total amount of memory allocated for this type.
TypeHandle is the identifier used to differentiate C++ class types.