Changeset 6bac215 in opengl-game for vulkan-buffer.hpp
- Timestamp:
- Jun 9, 2021, 12:38:14 AM (3 years ago)
- Branches:
- feature/imgui-sdl
- Children:
- bb76950
- Parents:
- 8dcbf62
- git-author:
- Dmitry Portnoy <dportnoy@…> (06/09/21 00:38:09)
- git-committer:
- Dmitry Portnoy <dportnoy@…> (06/09/21 00:38:14)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vulkan-buffer.hpp
r8dcbf62 r6bac215 14 14 // Externally, they are only used in resizeBufferSet 15 15 size_t capacity; 16 size_t numObjects; 16 17 // temp field to help with ubo+ssbo resizing until they are added to this class 18 // See if I need a separate field for this or if I can use other fields to check for this 19 // Maybe compare uniform or storage buffer size to the size of the memory allocated here 20 bool resized; 17 21 18 22 VulkanBuffer(); 19 23 VulkanBuffer(size_t capacity, size_t minOffsetAlignment); 24 25 VulkanBuffer(const VulkanBuffer<T>&) = delete; 26 VulkanBuffer(VulkanBuffer<T>&& other); 27 20 28 ~VulkanBuffer(); 21 29 22 VulkanBuffer<T>& operator=(const VulkanBuffer<T>& other); 30 VulkanBuffer<T>& operator=(const VulkanBuffer<T>&) = delete; 31 VulkanBuffer<T>& operator=(VulkanBuffer<T>&& other) noexcept; 32 33 void resize(); 23 34 24 35 void add(T obj); … … 29 40 30 41 size_t alignment; 42 size_t numObjects; 31 43 32 44 T* srcData; // TODO: Rename this to something else probably and rename rawData to data … … 56 68 , capacity(0) 57 69 , numObjects(0) 70 , resized(false) 58 71 , srcData(nullptr) 59 72 , rawData(nullptr) … … 66 79 , capacity(capacity) 67 80 , numObjects(0) 81 , resized(false) 68 82 , srcData(nullptr) 69 83 , rawData(nullptr) … … 77 91 78 92 template<class T> 93 VulkanBuffer<T>::VulkanBuffer(VulkanBuffer<T>&& other) { 94 // TODO: Implement 95 } 96 97 template<class T> 79 98 VulkanBuffer<T>::~VulkanBuffer() { 80 99 if (srcData != nullptr) { … … 84 103 85 104 template<class T> 86 VulkanBuffer<T>& VulkanBuffer<T>::operator=(const VulkanBuffer<T>& other) { 87 if (this == &other) { 88 return *this; 105 VulkanBuffer<T>& VulkanBuffer<T>::operator=(VulkanBuffer<T>&& other) noexcept { 106 if (this != &other) { 107 capacity = other.capacity; 108 numObjects = other.numObjects; 109 resized = other.resized; 110 111 alignment = other.alignment; 112 113 if (srcData != nullptr) { 114 free(srcData); 115 } 116 117 srcData = other.srcData; 118 119 other.capacity = 0; 120 other.numObjects = 0; 121 // TODO: Maybe set rnage to 0 as well 122 123 other.srcData = nullptr; 89 124 } 90 91 /*92 // assume *this manages a reusable resource, such as a heap-allocated buffer mArray93 if (size != other.size) { // resource in *this cannot be reused94 delete[] mArray; // release resource in *this95 mArray = nullptr;96 size = 0; // preserve invariants in case next line throws97 mArray = new int[other.size]; // allocate resource in *this98 size = other.size;99 }100 */101 102 if (srcData != nullptr) {103 free(srcData);104 srcData = nullptr;105 }106 107 alignment = other.alignment;108 capacity = other.capacity;109 110 srcData = (T*)malloc(capacity * alignment);111 // TODO: Check for failure112 113 memcpy(srcData, other.srcData, capacity * alignment);114 125 115 126 return *this; … … 117 128 118 129 template<class T> 130 void VulkanBuffer<T>::resize() { 131 resized = false; 132 } 133 134 template<class T> 119 135 void VulkanBuffer<T>::add(T obj) { 136 if (numObjects == capacity) { 137 // Once I add Vulkan buffer objects in here, make sure this doesn't overlap with resizeBufferSet 138 resized = true; 139 140 capacity *= 2; 141 } 142 120 143 numObjects++; 121 144 }
Note:
See TracChangeset
for help on using the changeset viewer.