Changeset b7fc3c2 in opengl-game for vulkan-buffer.hpp
- Timestamp:
- Jun 10, 2021, 2:58:54 PM (3 years ago)
- Branches:
- feature/imgui-sdl
- Children:
- c1ec4f6
- Parents:
- bb76950
- git-author:
- Dmitry Portnoy <dportnoy@…> (06/10/21 14:53:52)
- git-committer:
- Dmitry Portnoy <dportnoy@…> (06/10/21 14:58:54)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vulkan-buffer.hpp
rbb76950 rb7fc3c2 21 21 22 22 VulkanBuffer(); 23 VulkanBuffer(size_t capacity, size_t minOffsetAlignment);23 VulkanBuffer(size_t capacity, size_t range, size_t minOffsetAlignment); 24 24 25 25 VulkanBuffer(const VulkanBuffer<T>&) = delete; … … 35 35 void add(T obj); 36 36 37 // TODO: Add a resize function37 size_t memorySize(); 38 38 39 39 private: 40 40 41 41 size_t alignment; 42 size_t range; 42 43 size_t numObjects; 43 44 … … 48 49 // Maybe rename it to mappedData or something to make that clearer 49 50 void* rawData; 51 52 size_t memRequirement(size_t capacity); 50 53 }; 51 54 … … 66 69 VulkanBuffer<T>::VulkanBuffer() 67 70 : alignment(0) 71 , range(0) 68 72 , capacity(0) 69 73 , numObjects(0) … … 75 79 76 80 template<class T> 77 VulkanBuffer<T>::VulkanBuffer(size_t capacity, size_t minOffsetAlignment) 78 : alignment(sizeof(T)) 81 VulkanBuffer<T>::VulkanBuffer(size_t capacity, size_t range, size_t minOffsetAlignment) 82 : alignment(range) 83 , range(range / sizeof(T)) 79 84 , capacity(capacity) 80 85 , numObjects(0) … … 87 92 } 88 93 89 srcData = (T*)malloc( capacity * alignment);94 srcData = (T*)malloc(memRequirement(capacity)); 90 95 } 91 96 … … 110 115 111 116 alignment = other.alignment; 117 range = other.range; 112 118 113 119 if (srcData != nullptr) { … … 119 125 other.capacity = 0; 120 126 other.numObjects = 0; 121 // TODO: Maybe set rnage to 0 as well127 other.range = 0; 122 128 123 129 other.srcData = nullptr; … … 144 150 } 145 151 152 template<class T> 153 size_t VulkanBuffer<T>::memorySize() { 154 return memRequirement(capacity); 155 } 156 157 template<class T> 158 size_t VulkanBuffer<T>::memRequirement(size_t capacity) { 159 return (capacity / range) * alignment + (capacity % range) * sizeof(T); 160 } 161 146 162 #endif // _VULKAN_BUFFER_H
Note:
See TracChangeset
for help on using the changeset viewer.