Changeset 8dcbf62 in opengl-game
- Timestamp:
- Jun 8, 2021, 11:19:16 PM (4 years ago)
- Branches:
- feature/imgui-sdl
- Children:
- 6bac215
- Parents:
- 8aa4888
- git-author:
- Dmitry Portnoy <dportnoy@…> (06/08/21 20:38:16)
- git-committer:
- Dmitry Portnoy <dportnoy@…> (06/08/21 23:19:16)
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
sdl-game.cpp
r8aa4888 r8dcbf62 136 136 { 137 137 0, 1, 2, 3, 4, 5 138 }, {138 }, objects_modelPipeline, { 139 139 mat4(1.0f) 140 140 }); 141 142 objects_modelPipeline.numObjects++;143 141 144 142 texturedSquare->model_base = … … 157 155 })), { 158 156 0, 1, 2, 3, 4, 5 159 }, {157 }, objects_modelPipeline, { 160 158 mat4(1.0f) 161 159 }); 162 163 objects_modelPipeline.numObjects++;164 160 165 161 texturedSquare->model_base = … … 381 377 { 382 378 0, 1, 2, 3, 4, 5 383 }, {379 }, objects_modelPipeline, { 384 380 mat4(1.0f) 385 381 }); 386 387 objects_modelPipeline.numObjects++;388 382 389 383 texturedSquare.model_base = … … 834 828 void VulkanGame::createImageResources() { 835 829 VulkanUtils::createDepthImage(device, physicalDevice, resourceCommandPool, findDepthFormat(), swapChainExtent, 836 depthImage, graphicsQueue);830 depthImage, graphicsQueue); 837 831 838 832 createTextureSampler(); … … 1252 1246 // and resizing the window is a common reason to recreate the swapchain 1253 1247 VulkanUtils::createDepthImage(device, physicalDevice, resourceCommandPool, findDepthFormat(), swapChainExtent, 1254 depthImage, graphicsQueue);1248 depthImage, graphicsQueue); 1255 1249 1256 1250 createRenderPass(); -
sdl-game.hpp
r8aa4888 r8dcbf62 311 311 GraphicsPipeline_Vulkan<VertexType>& pipeline, 312 312 const vector<VertexType>& vertices, vector<uint16_t> indices, 313 SSBOType ssbo);313 VulkanBuffer<SSBOType>& objectBuffer, SSBOType ssbo); 314 314 315 315 template<class VertexType> … … 399 399 GraphicsPipeline_Vulkan<VertexType>& pipeline, 400 400 const vector<VertexType>& vertices, vector<uint16_t> indices, 401 SSBOType ssbo) {401 VulkanBuffer<SSBOType>& objectBuffer, SSBOType ssbo) { 402 402 // TODO: Use the model field of ssbo to set the object's model_base 403 403 // currently, the passed in model is useless since it gets overridden in updateObject() anyway … … 409 409 410 410 objects.push_back({ vertices, indices, ssbo, mat4(1.0f), mat4(1.0f), false }); 411 objectBuffer.add(ssbo); 411 412 412 413 SceneObject<VertexType, SSBOType>& obj = objects.back(); … … 415 416 // with a boolean being passed in here, so that I don't have to rely on checking the specific object 416 417 // type 418 // TODO: Actually, I've already defined a no-op centerObject method for explosions 419 // Maybe I should do the same for lasers and remove this conditional altogether 417 420 if (!is_same_v<VertexType, LaserVertex> && !is_same_v<VertexType, ExplosionVertex>) { 418 421 centerObject(obj); -
vulkan-buffer.hpp
r8aa4888 r8dcbf62 1 1 #ifndef _VULKAN_BUFFER_H 2 2 #define _VULKAN_BUFFER_H 3 4 #include <iostream>5 #include <vector>6 7 using namespace std;8 3 9 4 /* … … 16 11 public: 17 12 18 size_t alignment; 13 // TODO: Make these private (maybe make a getter for numObjects) 14 // Externally, they are only used in resizeBufferSet 19 15 size_t capacity; 20 16 size_t numObjects; … … 22 18 VulkanBuffer(); 23 19 VulkanBuffer(size_t capacity, size_t minOffsetAlignment); 24 VulkanBuffer(vector<T>* vData, size_t capacity);25 20 ~VulkanBuffer(); 26 21 27 22 VulkanBuffer<T>& operator=(const VulkanBuffer<T>& other); 28 23 29 T* data(); 30 void* mappedData(); // TODO: Maybe rename this to just mapped() 24 void add(T obj); 31 25 32 26 // TODO: Add a resize function 33 27 34 28 private: 29 30 size_t alignment; 35 31 36 32 T* srcData; // TODO: Rename this to something else probably and rename rawData to data … … 81 77 82 78 template<class T> 83 VulkanBuffer<T>::VulkanBuffer(vector<T>* vData, size_t capacity)84 : alignment(sizeof(T))85 , capacity(capacity)86 , numObjects(0)87 , srcData(nullptr)88 , rawData(nullptr)89 , vData(vData) {90 // TODO: Allocate initial capacity in vector91 }92 93 template<class T>94 79 VulkanBuffer<T>::~VulkanBuffer() { 95 80 if (srcData != nullptr) { … … 132 117 133 118 template<class T> 134 T* VulkanBuffer<T>::data() { 135 if (srcData != nullptr) { 136 return srcData; 137 } else { 138 return vData->data(); 139 } 140 } 141 142 template<class T> 143 void* VulkanBuffer<T>::mappedData() { 144 return rawData; 119 void VulkanBuffer<T>::add(T obj) { 120 numObjects++; 145 121 } 146 122 -
vulkan-game.cpp
r8aa4888 r8dcbf62 160 160 { 161 161 0, 1, 2, 3, 4, 5 162 }, {162 }, objects_modelPipeline, { 163 163 mat4(1.0f) 164 164 }); 165 166 objects_modelPipeline.numObjects++;167 165 168 166 texturedSquare->model_base = … … 182 180 { 183 181 0, 1, 2, 3, 4, 5 184 }, {182 }, objects_modelPipeline, { 185 183 mat4(1.0f) 186 184 }); 187 188 objects_modelPipeline.numObjects++;189 185 190 186 texturedSquare->model_base = … … 445 441 132, 133, 134, 446 442 135, 136, 137, 447 }, {443 }, objects_shipPipeline, { 448 444 mat4(1.0f) 449 445 }); 450 451 objects_shipPipeline.numObjects++;452 446 453 447 ship.model_base = … … 781 775 { 782 776 0, 1, 2, 3, 4, 5 783 }, {777 }, objects_modelPipeline, { 784 778 mat4(1.0f) 785 779 }); 786 787 objects_modelPipeline.numObjects++;788 780 789 781 texturedSquare.model_base = … … 1063 1055 24, 25, 26, 27, 28, 29, 1064 1056 30, 31, 32, 33, 34, 35, 1065 }, {1057 }, objects_asteroidPipeline, { 1066 1058 mat4(1.0f), 1067 1059 10.0f, 1068 1060 false 1069 1061 }); 1070 1071 objects_asteroidPipeline.numObjects++;1072 1062 1073 1063 // This accounts for the scaling in model_base. … … 1551 1541 void VulkanGame::createImageResources() { 1552 1542 VulkanUtils::createDepthImage(device, physicalDevice, resourceCommandPool, findDepthFormat(), swapChainExtent, 1553 depthImage, graphicsQueue);1543 depthImage, graphicsQueue); 1554 1544 1555 1545 createTextureSampler(); … … 1979 1969 4, 5, 1, 4, 1, 0, 1980 1970 6, 7, 5, 6, 5, 4 1981 }, {1971 }, objects_laserPipeline, { 1982 1972 mat4(1.0f), 1983 1973 color, 1984 1974 false 1985 1975 }); 1986 1987 objects_laserPipeline.numObjects++;1988 1976 1989 1977 float xAxisRotation = asin(ray.y / length); … … 2187 2175 iota(indices.begin(), indices.end(), 0); 2188 2176 2189 SceneObject<ExplosionVertex, SSBO_Explosion>& explosion = addObject( 2190 explosionObjects, explosionPipeline, addObjectIndex(explosionObjects.size(), vertices), indices, {2177 SceneObject<ExplosionVertex, SSBO_Explosion>& explosion = addObject(explosionObjects, explosionPipeline, 2178 addObjectIndex(explosionObjects.size(), vertices), indices, objects_explosionPipeline, { 2191 2179 mat4(1.0f), 2192 2180 cur_time, … … 2195 2183 }); 2196 2184 2197 objects_explosionPipeline.numObjects++;2198 2199 2185 explosion.model_base = model_mat; 2200 2186 explosion.model_transform = mat4(1.0f); … … 2216 2202 // and resizing the window is a common reason to recreate the swapchain 2217 2203 VulkanUtils::createDepthImage(device, physicalDevice, resourceCommandPool, findDepthFormat(), swapChainExtent, 2218 depthImage, graphicsQueue);2204 depthImage, graphicsQueue); 2219 2205 2220 2206 createRenderPass(); -
vulkan-game.hpp
r8aa4888 r8dcbf62 446 446 GraphicsPipeline_Vulkan<VertexType>& pipeline, 447 447 const vector<VertexType>& vertices, vector<uint16_t> indices, 448 SSBOType ssbo);448 VulkanBuffer<SSBOType>& objectBuffer, SSBOType ssbo); 449 449 450 450 template<class VertexType> … … 554 554 GraphicsPipeline_Vulkan<VertexType>& pipeline, 555 555 const vector<VertexType>& vertices, vector<uint16_t> indices, 556 SSBOType ssbo) {556 VulkanBuffer<SSBOType>& objectBuffer, SSBOType ssbo) { 557 557 // TODO: Use the model field of ssbo to set the object's model_base 558 558 // currently, the passed in model is useless since it gets overridden in updateObject() anyway … … 564 564 565 565 objects.push_back({ vertices, indices, ssbo, mat4(1.0f), mat4(1.0f), false }); 566 objectBuffer.add(ssbo); 566 567 567 568 SceneObject<VertexType, SSBOType>& obj = objects.back(); … … 570 571 // with a boolean being passed in here, so that I don't have to rely on checking the specific object 571 572 // type 573 // TODO: Actually, I've already defined a no-op centerObject method for explosions 574 // Maybe I should do the same for lasers and remove this conditional altogether 572 575 if (!is_same_v<VertexType, LaserVertex> && !is_same_v<VertexType, ExplosionVertex>) { 573 576 centerObject(obj);
Note:
See TracChangeset
for help on using the changeset viewer.