AGX Dynamics 2.41.2.0
Loading...
Searching...
No Matches
Buffer.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#pragma once
18
19
20#include <agx/agx.h>
21#include <agx/Component.h>
22#include <agx/Event.h>
23
24#include <agxData/Array.h>
25#include <agxData/Value.h>
26#include <agxData/ShareHandle.h>
27
28#include <agx/Vector.h>
29
30#ifdef _MSC_VER
31# pragma warning(push)
32# pragma warning(disable: 6011) // Disable warningC6011: dereferencing nullptr pointer
33#endif
34
35
36namespace agx
37{
38 typedef VectorPOD<Index> IndexVector;
39 class GlobalResultBuffer;
40}
41
42namespace agxData
43{
44 class Attribute;
45 class EntityStorage;
46
49
56 {
57 public:
59
60 static Buffer *load(agx::TiXmlElement *eBuffer, agx::Device *device);
61 virtual void configure(agx::TiXmlElement *eBuffer) override;
62 virtual void snapshot(agx::TiXmlNode *eParent, const agx::String& directory) const override;
63
64 public:
68
69 // Generated event interface, defined in Buffer.agxEvent
71
72#ifndef SWIG
73 void addListener(EventListener *listener);
74 void removeListener(EventListener *listener);
75 bool hasListener(EventListener *listener);
76#endif
77
80
81
83
86
87 public:
88 Buffer(const agx::Name& name, const agxData::Format *format);
89 Buffer(const agxData::Format *format);
90
95 const agxData::Type *getType() const;
96
101 const agxData::Format *getFormat() const;
102
103
105 template <typename T>
107
108 template <typename T>
110
111
112 agxData::AbstractArray& getArray();
113 const agxData::AbstractArray& getArray() const;
114
118 size_t size() const;
119
123 size_t capacity() const;
124
128 bool empty() const;
129
133 void resize(size_t size, bool initializeElements = true);
134 void presize(size_t size, size_t initialSize); // Resize without generating events, use with caution
135
139 void clear();
144 void reserve(size_t size);
145
149 agx::UInt64 getRevision() const;
154 void* ptr();
155 const void* ptr() const;
157 template <typename T>
158 T *ptr();
160 template <typename T>
161 const T *ptr() const;
162
166 void initialize(const agx::IndexRange& range);
171 template <typename T>
172 T& getElement(size_t index);
173
174 template <typename T>
175 const T& getElement(size_t index) const;
176
178 void commit();
180 void commit(agx::Index index);
181 void commit(const agxData::IndexArray& indexList);
183
187 void *getElement(size_t index);
188 const void *getElement(size_t index) const;
189
190 void *kernelOverflowReallocation(size_t size);
191 void deleteOverflowBuffer(void *buffer, size_t numElements);
192
194 void swapBackBuffer(void *backBuffer);
195
199 size_t getElementArraySize() const;
201
205 Buffer *clone() const;
206
210 Buffer *clone(const agx::IndexRange& range) const;
211 Buffer *clone(const agxData::IndexArray& indices) const;
212 Buffer *clone(const agx::IndexVector& indices) const;
213
217 static void copy(Buffer *target, const Buffer *source);
218 static void copy(Buffer *target, size_t targetOffset, const Buffer *source, size_t sourceOffset, size_t numElements);
219 static void copyGather(Buffer *target, const Buffer *source, const agxData::IndexArray& indices);
220 static void copyScatter(Buffer *target, const Buffer *source, const agxData::IndexArray& indices);
222
226 void print() const;
227 void print(agx::IndexRange range) const;
228
229 void print(std::ostream& stream) const;
230 void print(std::ostream& stream, agx::IndexRange range) const;
231
235 agxData::EntityStorage *getStorage();
236 const agxData::EntityStorage *getStorage() const;
237
241 agxData::Attribute *getAttribute();
242 const agxData::Attribute *getAttribute() const;
243
247 agx::GlobalResultBuffer *getGlobalResult();
248 const agx::GlobalResultBuffer *getGlobalResult() const;
249
250
254 Buffer *getGlobalOrderBuffer();
255 const Buffer *getGlobalOrderBuffer() const;
256
258
259
263 Buffer *getElementBuffer();
264 const Buffer *getElementBuffer() const;
265
270
275
279 agxData::Value *getDefaultValue();
280 const agxData::Value *getDefaultValue() const;
281
287 void setElementDestructor(const RangeCallback& callback);
288
290 const Buffer *getOriginalBuffer() const;
291
294
295 virtual void buildNavigationTree(agxJson::Value& eNode) const override;
296
297 public:
300
301 void setRevision(agx::UInt64 revision);
302
303 protected:
304 virtual ~Buffer();
305
306 virtual void reallocate(size_t size);
307 static void initializeElements(Buffer *buffer, const agx::IndexRange& range);
308 static void destroyElements(Buffer *buffer, const agx::IndexRange& range);
309
310 private:
312 void setGlobalResult(agx::GlobalResultBuffer *globalResult);
313 void signalReallocation();
314
315 private:
316 friend class EntityStorage;
318 void keyFrameReserve(size_t capacity);
319
320 void init();
321 void resizeCallback(agxData::Value *value);
322 void reserveCallback(agxData::Value *value);
323 void readBinaryDump(const agx::String& path);
324 void writeBinaryDump(const agx::String& path);
325 void connect(EntityStorage *storage, Attribute *attribute);
326 void setElementArraySize(const agxData::Value *value);
327
328
329 agxData::ValueRefT<agx::UInt> m_elementArraySize;
330
331 private:
332 friend class agx::Device;
333 void setOriginalBuffer(Buffer *buffer);
334
335 protected:
336 size_t m_size;
339
340 void *m_ptr;
355 EventDispatch m_eventDispatch;
356
359
360 friend class ShareHandle;
363
364 template <typename T>
365 friend class Vector;
366 };
367
368 // Container allocator for Vector, HashTable, etc.
370 {
371 public:
372 BufferProxyAllocator(Buffer *buffer = nullptr);
374
375 void setBuffer(Buffer *buffer);
376
377 void update() const;
378 void commit();
379
380 // Automatically called by container
381 void setContainer(agx::Container *container);
382
383 void *allocateBytes(size_t numBytes);
384 void deallocateBytes(void *buffer, size_t numBytes);
385
387 private:
388 BufferRef m_buffer;
389 agx::Container *m_container;
390 int m_reallocations;
391 };
392
393
394 // Templated buffer
395 template <typename T>
396 class BufferT : public Buffer
397 {
398 public:
399 template <typename T2>
400 static bool ValidateCast(const agx::Referenced *object);
401
402 public:
403 typedef T Type;
404 typedef T value_type;
405 typedef T* iterator;
406 typedef const T* const_iterator;
407
408 public:
409 BufferT();
410 BufferT(const agx::Name& name);
411
412
413 void push_back(const T& value);
414 void pop_back();
415
416 void clear();
417
418 template <typename T2>
419 bool contains(const T2& value) const;
420
421 template <typename T2>
422 size_t find(const T2& value) const;
423
424 T& operator[] (size_t index);
425 const T& operator[] (size_t index) const;
426
427 T& at(size_t index);
428 const T& at(size_t index) const;
429
430 T& front();
431 const T& front() const;
432
433 T& back();
434 const T& back() const;
435
436
437 iterator begin();
438 const_iterator begin() const;
439
440 iterator end();
441 const_iterator end() const;
442
443 void commit();
444 void commit(agx::IndexRange32 range);
445 void commit(agx::Index index);
446 void commit(const agxData::IndexArray& indexList);
447 void commit(const agx::IndexVector& indexList);
448
449 protected:
450 virtual ~BufferT();
451
452 private:
453 Array<T>& array();
454 const Array<T>& array() const;
455 };
456
457
458 /* Implementation */
459 AGX_FORCE_INLINE size_t Buffer::size() const { return m_size; }
461 AGX_FORCE_INLINE bool Buffer::empty() const { return m_size == 0; }
462
463
465
466 AGX_FORCE_INLINE size_t Buffer::getElementArraySize() const { return m_elementArraySize.get() ? m_elementArraySize->get() : 1; }
467
470
473
475 AGX_FORCE_INLINE const Type *Buffer::getType() const { return m_format->getType(); }
478
481
482 template <typename T>
484 {
485 agxAssertN(m_format->is(agxData::getFormat<T>()) && m_format->getSize() == agxData::getFormat<T>()->getSize(), "Type mismatch! Buffer has type %s, requested array of type %s", m_format->fullName().c_str(), agxData::getFormat<T>()->fullName().c_str());
486 return reinterpret_cast<agxData::Array<T>&>(m_array);
487 }
488
489 template <typename T>
491 {
492 return const_cast<Buffer *>(this)->getArray<T>();
493 }
494
497
498
500 AGX_FORCE_INLINE const void *Buffer::ptr() const { return m_ptr; }
501
502 template <typename T>
504 {
505 agxAssertN(agxCore::isShutdown() || this->getFormat()->is(agxData::getFormat<T>()), "%s not the same as %s", agxData::getFormat<T>()->fullName().c_str(), this->getFormat()->fullName().c_str());
506 return static_cast<T *>(m_ptr);
507 }
508
509 template <typename T>
511 {
512 return const_cast<Buffer *>(this)->ptr<T>();
513 }
514
515
516 template <typename T>
518 {
520 agxAssert(index < this->capacity());
521 agxAssertN(agxCore::isShutdown() || this->getFormat()->is(agxData::getFormat<T>()), "%s not the same as %s", agxData::getFormat<T>()->fullName().c_str(), this->getFormat()->fullName().c_str());
522 agxAssert(this->getFormat()->getSize() == sizeof(T));
523
524 T *tmp = (T *)m_ptr;
525 return tmp[index];
526 }
527
528 template <typename T>
529 AGX_FORCE_INLINE const T& Buffer::getElement(size_t index) const
530 {
531 return const_cast<Buffer *>(this)->getElement<T>(index);
532 }
533
534
536 {
538 agxAssert(index < this->capacity());
539 return (void *)((char *)m_ptr + index * this->getFormat()->getSize());
540 }
541
542 AGX_FORCE_INLINE const void *Buffer::getElement(size_t index) const
543 {
544 return const_cast<Buffer *>(this)->getElement(index);
545 }
546
547
550
551 AGX_FORCE_INLINE void Buffer::setGlobalResult(agx::GlobalResultBuffer *globalResult) { m_globalResult = globalResult; }
552
553
556
559
560 //--------------------------------------------
561
562
563 template <typename T>
565 {
566 agxAssert(m_buffer);
567 agxAssert(m_buffer->getGlobalResult());
568 return m_buffer->getGlobalResult();
569 }
570
571 template <typename T>
573 {
574 return this->getGlobalResult()->allocateResult(numElements);
575 }
576
577 template <typename T>
578 AGX_FORCE_INLINE size_t Array<T>::commitResult(size_t numElements, const void *localResult, agx::Index sortIndex)
579 {
580 if (numElements == 0)
581 return agx::InvalidIndex;
582
583 return this->getGlobalResult()->commit(*this, numElements, localResult, sortIndex);
584 }
585
586 template <typename T>
587 AGX_FORCE_INLINE size_t Array<T>::commitResult(size_t numElements, const void *localResult)
588 {
589 if (numElements == 0)
590 return agx::InvalidIndex;
591
592 return this->getGlobalResult()->commit(*this, numElements, localResult);
593 }
594
595 template <typename T> template <typename T2>
596 AGX_FORCE_INLINE size_t Array<T>::commitResult(const T2& vector, agx::Index sortIndex)
597 {
598 if (vector.empty())
599 return agx::InvalidIndex;
600
601 return this->getGlobalResult()->commit(*this, vector, sortIndex);
602 }
603
604
605 template <typename T> template <typename T2>
607 {
608 if (vector.empty())
609 return agx::InvalidIndex;
610
611 return this->getGlobalResult()->commit(*this, vector);
612 }
613
614 //---------------------------------------------------------------
615
616 AGX_FORCE_INLINE AbstractArray& Data::asArray() { return *static_cast<AbstractArray *>(this); }
617 AGX_FORCE_INLINE const AbstractArray& Data::asArray() const { return *static_cast<const AbstractArray *>(this); }
618
619 template <typename T>
620 AGX_FORCE_INLINE Array<T>& Data::asArray() { return *static_cast<Array<T> *>(this); }
621
622 template <typename T>
623 AGX_FORCE_INLINE const Array<T>& Data::asArray() const { return *static_cast<const Array<T> *>(this); }
624
625 //---------------------------------------------------------------
626
628 {}
629
631 {
632 if (buffer != nullptr)
633 {
634 this->init(buffer);
635 }
636 else
637 {
638 this->init();
639 }
640 }
641
643 {
644 this->init(buffer, range);
645 }
646
648 {
649 agxAssert(localRange.end() <= other.m_range.size());
650 agx::IndexRange32 range(other.m_range.begin() + localRange.begin(), other.m_range.begin() + localRange.end());
651 this->init(other.m_buffer, range);
652 }
653
655 {
656 m_ptr = nullptr;
657 m_buffer = nullptr;
659 }
660
662 {
664 // agxAssert(buffer->getType() == this->getType());
665 agxAssert(range.end() <= std::max(buffer->size(), (size_t)buffer->getArray().range().end()));
666
668 m_range = range;
669 this->sync();
670 }
671
672
674 {
676 this->init(buffer, agx::IndexRange32(0, agx::UInt32(buffer->size())));
677 }
678
680 {
683 this->sync();
684 }
685
686
688 {
690 agxAssert(range.end() <= std::max(m_buffer->size(), (size_t)m_buffer->getArray().range().end()));
691 m_range = range;
692 this->sync();
693 }
694
695
696 AGX_FORCE_INLINE void AbstractArray::setRange(size_t startIndex, size_t endIndex)
697 {
698 this->setRange(agx::IndexRange32(agx::UInt32(startIndex), agx::UInt32(endIndex)));
699 }
700
701
703 {
705 m_ptr = ((char*)m_buffer->ptr()) + m_range.begin() * m_buffer->getFormat()->getSize();
706 }
707
709 {
710 return m_range.size();
711 }
712
714 {
715 return m_range.size() == 0;
716 }
717
718
723
724 AGX_FORCE_INLINE bool AbstractArray::isValid() const { return m_buffer != nullptr; }
725
727 AGX_FORCE_INLINE const Format* AbstractArray::getFormat() const { return m_buffer != nullptr ? m_buffer->getFormat() : nullptr; }
728
729
730 //---------------------------------------------------------------
731
732 template <typename T>
734 {
735 Array<T> result;
737 result.m_ptr = buffer;
738 result.m_range = agx::IndexRange32(0, size);
739 #include <agx/PopDisableWarnings.h>
740 return result;
741 }
742
743 template <typename T>
745 {
746 Array<T> result;
748 result.m_ptr = (T *)buffer;
749 result.m_range = agx::IndexRange32(0, size);
750 #include <agx/PopDisableWarnings.h>
751 return result;
752 }
753
754 template <typename T>
756 {
757 }
758
759 template <typename T>
761 {
762 #ifndef AGX_ENTITY_WRAPPER
763 agxAssert( agxCore::isShutdown() || (buffer->getFormat()->is(agxData::getFormat<T>()) && buffer->getFormat()->getSize() == agxData::getFormat<T>()->getSize()));
764 #endif
765 }
766
767
768 template <typename T>
770 {
771 #ifndef AGX_ENTITY_WRAPPER
772 agxAssert( agxCore::isShutdown() || (buffer->getFormat()->is(agxData::getFormat<T>()) && buffer->getFormat()->getSize() == agxData::getFormat<T>()->getSize()));
773 #endif
774 }
775
776 template <typename T>
777 AGX_FORCE_INLINE Array<T>::Array(const Array<T>& other, agx::IndexRange32 localRange) : AbstractArray(other, localRange)
778 {
779 }
780
781 template <typename T>
783 {
784 this->m_ptr = vec.ptr();
785 this->m_range = agx::IndexRange32(0, (agx::Index)vec.size());
786 }
787
788 template <typename T>
790 {
791 agxAssert(range.begin() < range.end() && range.end() <= vec.size());
792 this->m_ptr = vec.ptr();
793 this->m_range = range;
794 }
795
796 template <typename T>
798 {
799 this->m_ptr = vec.ptr();
800 this->m_range = agx::IndexRange32(0, (agx::Index)vec.size());
801 }
802
803 template <typename T>
805 {
806 agxAssert(range.begin() < range.end() && range.end() <= vec.size());
807 this->m_ptr = vec.ptr();
808 this->m_range = range;
809 }
810
811 template <typename T>
813 {
814 agxAssert(m_ptr);
815 agxAssert1(!m_range.empty(), "Can not take back element of an empty array!");
816 return ((T*)m_ptr)[m_range.size()-1];
817 }
818
819 template <typename T>
821 {
822 agxAssert(m_ptr);
823 agxAssert1(!m_range.empty(), "Can not take back element of an empty array!");
824 return ((T*)m_ptr)[m_range.size()-1];
825 }
826
827 template <typename T>
829 {
830 agxAssert(m_ptr);
831 agxAssert1(!m_range.empty(), "Can not take front element of an empty array!");
832 return ((T*)m_ptr)[0];
833 }
834
835 template <typename T>
837 {
838 agxAssert(m_ptr);
839 agxAssert1(!m_range.empty(), "Can not take front element of an empty array!");
840 return ((T*)m_ptr)[0];
841 }
842
843
844 template <typename T>
846 {
847 agxAssert1(m_ptr, "Array does not have an active buffer!");
848 agxAssertN(index < m_range.size(), "Array index %llu is out of bounds, size is %llu", (long long unsigned)index, (long long unsigned)m_range.size());
849 return ((T*)m_ptr)[index];
850 }
851
852
853 template <typename T>
854 AGX_FORCE_INLINE const T& Array<T>::operator[] (size_t index) const
855 {
856 return const_cast<Array<T>*>(this)->operator[](index);
857 }
858
859 template <typename T>
861 {
862 agxAssert(m_ptr);
863 agxVerifyN(index < m_range.size(), "Array index %llu is out of bounds, size is %llu", (long long unsigned)index, (long long unsigned)m_range.size());
864 return ((T*)m_ptr)[index];
865 }
866
867 template <typename T>
868 AGX_FORCE_INLINE const T& Array<T>::at(size_t index) const
869 {
870 return const_cast<Array<T>*>(this)->at(index);
871 }
872
873
874 template <typename T>
876 {
877 return Array<T>(m_buffer, agx::IndexRange32(m_range.begin() + subRange.begin(), m_range.begin() + subRange.end()));
878 }
879
880
881 template <typename T>
883 {
884 return this->slice(subRange);
885 }
886
887 template <typename T>
889
890 template <typename T>
892
893 template <typename T>
894 AGX_FORCE_INLINE typename Array<T>::iterator Array<T>::end() { return ptr() + size(); }
895
896 template <typename T>
897 AGX_FORCE_INLINE typename Array<T>::const_iterator Array<T>::end() const { return ptr() + size(); }
898
899 template <typename T>
900 AGX_FORCE_INLINE T* Array<T>::ptr() { return (T*)m_ptr; }
901
902
903 template <typename T>
904 AGX_FORCE_INLINE const T* Array<T>::ptr() const { return (const T*)m_ptr; }
905
906
907 template <typename T> template <typename T2>
908 AGX_FORCE_INLINE size_t Array<T>::find(const T2& element) const
909 {
910 for (size_t i = 0, numElements = size(); i < numElements; ++i)
911 {
912 if ((*this)[i] == element)
913 return i;
914 }
915
916 return agx::InvalidIndex;
917 }
918
919 template <typename T> template <typename T2>
920 AGX_FORCE_INLINE bool Array<T>::contains(const T2& element) const
921 {
922 return this->find(element) != agx::InvalidIndex;
923 }
924
925
926 template <typename T>
927 std::ostream& operator << ( std::ostream& output, const Array<T>& array)
928 {
929 for (size_t i = 0; i < array.size(); i++)
930 {
931 output << array[i];
932
933 if (i < array.size()-1)
934 output << ", ";
935 }
936
937 return output;
938 }
939
940
941 //--------------------------------------------
942
943
944 template <typename T> template <typename T2>
946 {
947 const Buffer *buffer = dynamic_cast<const Buffer *>(object);
948 return buffer ? buffer->getFormat() == agxData::getFormat<T>() : false;
949 }
950
951 template <typename T>
953 {
954 }
955
956 template <typename T>
958 {
959 }
960
961 template <typename T>
963 {
964 }
965
966
967 template <typename T>
969 {
970 agxAssert(agxData::getFormat<T>() == this->getFormat());
971 return reinterpret_cast<Array<T>&>(m_array);
972 }
973
974 template <typename T>
975 AGX_FORCE_INLINE const Array<T>& BufferT<T>::array() const
976 {
977 return const_cast<BufferT<T> *>(this)->array();
978 }
979
980
981
982 template <typename T>
984 {
985 if (m_size == m_capacity)
986 this->reserve(std::max((size_t)4, (size_t)((agx::Real)m_size * Buffer::CAPACITY_MULTIPLIER)));
987
988 m_size++;
989 array().range().end()++;
990 ::new((void *)&array().back()) T(value);
991 }
992
993 template <typename T>
995 {
996 agxAssert(!array().empty());
997
998 array().back().~T();
999 array().range().end()--;
1000 m_size--;
1001 }
1002
1003 template <typename T>
1005 {
1006 for (size_t i = 0; i < m_size; ++i)
1007 array()[i].~T();
1008
1009 m_size = 0;
1010 array().range().end() = 0;
1011 }
1012
1013 template <typename T> template <typename T2>
1014 AGX_FORCE_INLINE bool BufferT<T>::contains(const T2& value) const
1015 {
1016 return array().contains(value);
1017 }
1018
1019 template <typename T> template <typename T2>
1020 AGX_FORCE_INLINE size_t BufferT<T>::find(const T2& value) const
1021 {
1022 return array().find(value);
1023 }
1024
1025 template <typename T>
1027 {
1028 return array()[index];
1029 }
1030
1031 template <typename T>
1032 AGX_FORCE_INLINE const T& BufferT<T>::operator[] (size_t index) const
1033 {
1034 return const_cast<BufferT<T> *>(this)->operator[](index);
1035 }
1036
1037 template <typename T>
1039 {
1040 return array().at(index);
1041 }
1042
1043 template <typename T>
1044 AGX_FORCE_INLINE const T& BufferT<T>::at(size_t index) const
1045 {
1046 return const_cast<BufferT<T> *>(this)->at(index);
1047 }
1048
1049 template <typename T>
1051 {
1052 return array().front();
1053 }
1054
1055 template <typename T>
1057 {
1058 return const_cast<BufferT<T> *>(this)->front();
1059 }
1060
1061 template <typename T>
1063 {
1064 return array().back();
1065 }
1066
1067 template <typename T>
1069 {
1070 return const_cast<BufferT<T> *>(this)->back();
1071 }
1072
1073
1074
1075 template <typename T>
1077 {
1078 return array().begin();
1079 }
1080
1081 template <typename T>
1083 {
1084 return array().begin();
1085 }
1086
1087 template <typename T>
1089 {
1090 return array().end();
1091 }
1092
1093 template <typename T>
1095 {
1096 return array().end();
1097 }
1098
1099 template <typename T>
1101 {
1103 }
1104
1105 template <typename T>
1107 {
1108 Buffer::commit(range);
1109 }
1110
1111 template <typename T>
1113 {
1114 Buffer::commit(index);
1115 }
1116
1117 template <typename T>
1119 {
1120 Buffer::commit(indexList);
1121 }
1122
1123 template <typename T>
1125 {
1126 Buffer::commit(agxData::IndexArray::raw(indexList.ptr(), static_cast<agx::Index>(indexList.size())));
1127 }
1128
1129
1130}
1131
1133
1134#ifdef _MSC_VER
1135# pragma warning(pop)
1136#endif
1137
1138
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGXCORE_EXPORT
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: agx/Vector.h:34
#define m_size
Definition: agx/Vector.h:429
#define m_capacity
Definition: agx/Vector.h:430
Arrays are fast accessors into the data, or a portion of it, held by a Buffer.
Definition: Array.h:37
const agxData::Buffer * buffer() const
Definition: Buffer.h:720
void _setBuffer(agxData::Buffer *buffer)
Set the buffer while maintaining the current range, should normally not be used.
Definition: Buffer.h:679
void init()
Set to empty array.
Definition: Buffer.h:654
bool isValid() const
Definition: Buffer.h:724
agx::IndexRange32 m_range
Definition: Array.h:97
agx::IndexRange32 & range()
Definition: Buffer.h:721
size_t size() const
Definition: Buffer.h:708
agxData::Format * getFormat()
Definition: Buffer.h:726
void sync()
Updates the internal data access pointer. Called when the back end buffer is reallocated.
Definition: Buffer.h:702
agxData::Buffer * m_buffer
Definition: Array.h:96
AbstractArray()
Create a new invalid array.
Definition: Buffer.h:627
bool empty() const
Definition: Buffer.h:713
void setRange(size_t startIndex, size_t endIndex)
Set the range of the buffer that the array will cover.
Definition: Buffer.h:696
Type-specific Array used for fast access into the data held by a Buffer.
Definition: Array.h:107
agx::GlobalResult::Transaction allocateResult(size_t numElements)
Definition: Buffer.h:572
const T * const_iterator
Definition: Array.h:117
T * ptr()
Definition: Buffer.h:900
Array()
Create a new invalid array.
Definition: Buffer.h:755
size_t commitResult(size_t numElements, const void *localResult, agx::Index sortIndex)
Definition: Buffer.h:578
size_t find(const T2 &element) const
The index of the first occurrence of an element that is equal to the given element.
Definition: Buffer.h:908
bool contains(const T2 &element) const
Definition: Buffer.h:920
static agxData::Array< T > raw(T *buffer, agx::Index size)
Array creation helper method that creates an array covering the given memory area.
Definition: Buffer.h:733
T * iterator
Definition: Array.h:116
T & back()
Definition: Buffer.h:820
T & front()
Definition: Buffer.h:836
agx::GlobalResult * getGlobalResult()
Definition: Buffer.h:564
iterator end()
Definition: Buffer.h:894
T & at(size_t index)
Definition: Buffer.h:860
iterator begin()
Definition: Buffer.h:888
T & operator[](size_t index)
Definition: Buffer.h:845
agxData::Array< T > slice(agx::IndexRange32 subRange) const
Definition: Buffer.h:875
An abstract attribute description, part of an Entity.
Definition: Attribute.h:58
void deallocateBytes(void *buffer, size_t numBytes)
BufferProxyAllocator & operator=(const BufferProxyAllocator &other)
BufferProxyAllocator(Buffer *buffer=nullptr)
void setBuffer(Buffer *buffer)
void setContainer(agx::Container *container)
void * allocateBytes(size_t numBytes)
T & at(size_t index)
Definition: Buffer.h:1038
void clear()
Definition: Buffer.h:1004
const T * const_iterator
Definition: Buffer.h:406
void push_back(const T &value)
Definition: Buffer.h:983
iterator begin()
Definition: Buffer.h:1076
bool contains(const T2 &value) const
Definition: Buffer.h:1014
void commit()
Definition: Buffer.h:1100
size_t find(const T2 &value) const
Definition: Buffer.h:1020
virtual ~BufferT()
Definition: Buffer.h:962
static bool ValidateCast(const agx::Referenced *object)
Definition: Buffer.h:945
void pop_back()
Definition: Buffer.h:994
T & operator[](size_t index)
Definition: Buffer.h:1026
iterator end()
Definition: Buffer.h:1088
Abstract representation of a data buffer.
Definition: Buffer.h:56
agx::Event1< Buffer * > Event
Definition: Buffer.h:82
RangeCallback m_initializer
Definition: Buffer.h:357
Attribute * m_attribute
Definition: Buffer.h:346
bool empty() const
Definition: Buffer.h:461
void addListener(EventListener *listener)
agxData::Buffer * m_originalBuffer
Definition: Buffer.h:362
static void copy(Buffer *target, size_t targetOffset, const Buffer *source, size_t sourceOffset, size_t numElements)
T & getElement(size_t index)
Definition: Buffer.h:517
static void destroyElements(Buffer *buffer, const agx::IndexRange &range)
agxData::Value::Event::CallbackType m_resizeCallback
Definition: Buffer.h:352
AbstractArray m_array
Definition: Buffer.h:342
const agxData::Value::Event::CallbackType & getReserveCallback() const
static void copyScatter(Buffer *target, const Buffer *source, const agxData::IndexArray &indices)
void commit(agx::Index index)
agxData::Type * getType()
Definition: Buffer.h:474
EntityStorage * m_storage
Definition: Buffer.h:345
Buffer(const agxData::Format *format)
size_t m_size
Definition: Buffer.h:336
size_t getElementArraySize() const
Definition: Buffer.h:466
static void copy(Buffer *target, const Buffer *source)
Copy one buffer to another.
bool m_initElements
Definition: Buffer.h:343
agxData::Array< T > & getArray()
Convenience method to get an direct data array.
agx::UInt64 getRevision() const
Definition: Buffer.h:464
agx::Callback2< Buffer *, const agx::IndexRange & > RangeCallback
Specify a custom element initializer callback.
Definition: Buffer.h:285
Buffer(const agx::Name &name, const agxData::Format *format)
void commit(const agxData::IndexArray &indexList)
void presize(size_t size, size_t initialSize)
void * allocateBackBuffer()
agx::GlobalResultBuffer * getGlobalResult()
Definition: Buffer.h:548
Buffer * getOriginalBuffer()
const Buffer * getOriginalBuffer() const
agxData::BufferRef m_elementBuffer
Definition: Buffer.h:349
RangeCallback m_destructor
Definition: Buffer.h:358
virtual ~Buffer()
agxData::Attribute * getAttribute()
Definition: Buffer.h:471
virtual void configure(agx::TiXmlElement *eBuffer) override
void * ptr()
Get access to the raw data buffer.
Definition: Buffer.h:499
size_t size() const
Definition: Buffer.h:459
const agxData::Array< T > & getArray() const
agxData::EntityStorage * getStorage()
Definition: Buffer.h:468
agxData::Format * getFormat()
Definition: Buffer.h:476
void clear()
Clear the buffer.
void registerSharedContainer(agx::Container *container)
Buffer * clone(const agxData::IndexArray &indices) const
void setElementInitializer(const RangeCallback &callback)
static void initializeElements(Buffer *buffer, const agx::IndexRange &range)
agxData::Value * getDefaultValue()
Definition: Buffer.h:479
agxData::ValueRefT< agx::UInt > capacityParameter
Definition: Buffer.h:79
void print(std::ostream &stream) const
void setDefaultValue(agxData::Value *value)
Set the default element value.
Buffer * clone(const agx::IndexRange &range) const
Clone a subset of the buffer.
bool m_usedResizeMethod
Definition: Buffer.h:344
void print(std::ostream &stream, agx::IndexRange range) const
size_t m_capacity
Definition: Buffer.h:337
void reserve(size_t size)
Reserve space for future buffer expansion.
agxData::ShareHandleRef m_shareHandle
Definition: Buffer.h:361
virtual void reallocate(size_t size)
void * kernelOverflowReallocation(size_t size)
agx::ByteAllocator m_allocator
Definition: Buffer.h:341
static agx::UInt ALIGNMENT
Definition: Buffer.h:67
agxData::ValueRef m_defaultElementValue
Definition: Buffer.h:348
void swapBackBuffer(void *backBuffer)
void unregisterSharedContainer(agx::Container *container)
virtual void buildNavigationTree(agxJson::Value &eNode) const override
agx::Container * m_sharedContainer
Definition: Buffer.h:351
const agxData::Value::Event::CallbackType & getResizeCallback() const
void setRevision(agx::UInt64 revision)
Event reallocationEvent
Triggered when buffer is reallocated.
Definition: Buffer.h:85
agxData::Value::Event::CallbackType m_reserveCallback
Definition: Buffer.h:353
Buffer * clone() const
Clone the buffer.
bool hasListener(EventListener *listener)
agx::GlobalResultBuffer * m_globalResult
Definition: Buffer.h:354
void removeListener(EventListener *listener)
void initialize(const agx::IndexRange &range)
Initialize a range of elements.
void * m_ptr
Definition: Buffer.h:340
virtual void snapshot(agx::TiXmlNode *eParent, const agx::String &directory) const override
static Buffer * load(agx::TiXmlElement *eBuffer, agx::Device *device)
Buffer * getElementBuffer()
If the buffer contains arrays/vectors, the actual elements are stored in another buffer.
Definition: Buffer.h:554
void deleteOverflowBuffer(void *buffer, size_t numElements)
EventDispatch m_eventDispatch
Definition: Buffer.h:355
agxData::BufferRef m_globalOrderBuffer
Definition: Buffer.h:350
FormatRef m_format
Definition: Buffer.h:347
void setElementBuffer(Buffer *buffer)
Set the element buffer, internal use only.
void print(agx::IndexRange range) const
Buffer * getOrCreateGlobalOrderBuffer()
agx::UInt64 m_revision
Definition: Buffer.h:338
agxData::ValueRefT< agx::UInt > sizeParameter
Definition: Buffer.h:78
size_t capacity() const
Definition: Buffer.h:460
Buffer * getGlobalOrderBuffer()
If the buffer is used as a global result, we provide a permutation buffer for parallel determinism.
Definition: Buffer.h:557
void setElementDestructor(const RangeCallback &callback)
void commit(agx::IndexRange32 range)
void print() const
Print the buffer.
static agx::UInt MIN_BUFFER_CAPACITY
Definition: Buffer.h:66
static agx::Model * ClassModel()
static agx::Real CAPACITY_MULTIPLIER
Definition: Buffer.h:65
void * m_ptr
Definition: Data.h:72
const AbstractArray & asArray() const
Definition: Buffer.h:617
Data storage for a collection of entity instances of a specified EntityModel.
Definition: EntityStorage.h:73
A format is an implementation of a agxData::Type.
Definition: Format.h:64
size_t getSize() const
Definition: Format.h:593
Abstracted type.
Definition: Type.h:98
Templated value-reference.
Definition: Value.h:263
Abstract representation of a value.
Definition: Value.h:49
Byte allocator.
Definition: Allocator.h:55
Templated callback with two arguments.
Definition: Callback.h:140
A component is an object containing other objects, enabling hierarchical structuring.
Definition: Component.h:39
The Container is the base class for several of the container classes proided by AGX,...
Definition: Container.h:35
size_t size() const
Definition: Container.h:134
An agx::Device is an abstract representation of a device on which data can be stored and processed.
Definition: Device.h:58
An event with one argument.
Definition: Event.h:103
T CallbackType
Definition: Event.h:37
Transactions are used to reserve exclusive memory areas in which the threads can write their data.
Definition: GlobalResult.h:73
GlobalResult is used by kernels to generate result data from different threads.
Definition: GlobalResult.h:52
T size() const
Definition: IndexRange.h:168
A model is an abstract representation of the class of an agx::Object.
Definition: Model.h:41
bool is(const agx::Model *other) const
Representation of a name string.
Definition: Name.h:33
agx::String fullName() const
Base class providing referencing counted objects.
Definition: Referenced.h:120
bool is() const
Subclass test.
T * ptr()
Get access to the internal data buffer.
Definition: agx/Vector.h:1324
Templated vector class.
Definition: agx/Vector.h:53
T * ptr()
Get access to the internal data buffer.
Definition: agx/Vector.h:677
T * get() const
Definition: ref_ptr.h:256
#define agxAssert1(expr, msg)
Definition: debug.h:144
#define agxAssertN(expr, format,...)
Definition: debug.h:145
#define agxVerifyN(expr, format,...)
Definition: debug.h:133
#define agxAssert(expr)
Definition: debug.h:143
#define AGX_FORCE_INLINE
Definition: macros.h:58
bool AGXCORE_EXPORT isShutdown()
Contains classes for low level data storage for AGX.
Definition: Container.h:23
Format * getFormat()
Definition: Type.h:269
AGXCORE_EXPORT Format * getFormat(const agx::String &typeFormatName)
AGXCORE_EXPORT Type * getType(const agx::String &name)
std::ostream & operator<<(std::ostream &output, const Attribute &attribute)
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint32_t UInt32
Definition: Integer.h:32
uint64_t UInt64
Definition: Integer.h:33
IndexRangeT< agx::UInt32 > IndexRange32
Definition: IndexRange.h:141
uint64_t UInt
Definition: Integer.h:27
VectorPOD< Index > IndexVector
double Real
Definition: Real.h:42
AGXCORE_EXPORT const InvalidIndexStruct InvalidIndex
UInt32 Index
Definition: Integer.h:44