Changeset 6486ba8 in opengl-game for sdl-game.cpp
- Timestamp:
- Jun 11, 2021, 8:12:29 PM (4 years ago)
- Branches:
- feature/imgui-sdl
- Children:
- 5ea0a37
- Parents:
- c1ec4f6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sdl-game.cpp
rc1ec4f6 r6486ba8 111 111 112 112 createBufferSet(sizeof(UBO_VP_mats), 113 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 114 uniformBuffers_modelPipeline); 113 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 114 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 115 uniformBuffers_modelPipeline); 116 117 createBufferSet(objects_modelPipeline.capacity * sizeof(SSBO_ModelObject), 118 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT 119 | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 120 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 121 storageBuffers_modelPipeline); 115 122 116 123 modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, … … 121 128 VK_SHADER_STAGE_FRAGMENT_BIT, &floorTextureImageDescriptor); 122 129 123 SceneObject<ModelVertex , SSBO_ModelObject>* texturedSquare = nullptr;130 SceneObject<ModelVertex>* texturedSquare = nullptr; 124 131 125 132 texturedSquare = &addObject(modelObjects, modelPipeline, 126 133 addObjectIndex<ModelVertex>(modelObjects.size(), 127 134 addVertexNormals<ModelVertex>({ 128 {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f} , {1.0f, 0.0f, 0.0f}, 0},129 {{ 0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f} , {1.0f, 0.0f, 0.0f}, 0},130 {{ 0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f} , {1.0f, 0.0f, 0.0f}, 0},131 {{ 0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f} , {1.0f, 0.0f, 0.0f}, 0},132 {{-0.5f, 0.5f, 0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f} , {1.0f, 0.0f, 0.0f}, 0},133 {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f} , {1.0f, 0.0f, 0.0f}, 0}135 {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}}, 136 {{ 0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}}, 137 {{ 0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}}, 138 {{ 0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}}, 139 {{-0.5f, 0.5f, 0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}}, 140 {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}} 134 141 })), 135 142 { … … 264 271 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, physicalDevice, device, renderPass, 265 272 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, 16, 24); 266 267 createBufferSet(objects_modelPipeline.capacity * sizeof(SSBO_ModelObject),268 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT269 | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,270 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,271 storageBuffers_modelPipeline);272 273 } 273 274 … … 362 363 float zOffset = -2.0f + (0.5f * modelObjects.size()); 363 364 364 SceneObject<ModelVertex, SSBO_ModelObject>& texturedSquare = 365 addObject(modelObjects, modelPipeline, 366 addObjectIndex<ModelVertex>(modelObjects.size(), 367 addVertexNormals<ModelVertex>({ 368 {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}, {1.0f, 0.0f, 0.0f}, 0}, 369 {{ 0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}, {1.0f, 0.0f, 0.0f}, 0}, 370 {{ 0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0}, 371 {{ 0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0}, 372 {{-0.5f, 0.5f, 0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0}, 373 {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}, {1.0f, 0.0f, 0.0f}, 0} 374 })), 375 { 376 0, 1, 2, 3, 4, 5 377 }, objects_modelPipeline, { 378 mat4(1.0f) 379 }); 365 SceneObject<ModelVertex>& texturedSquare = addObject(modelObjects, modelPipeline, 366 addObjectIndex<ModelVertex>(modelObjects.size(), 367 addVertexNormals<ModelVertex>({ 368 {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}}, 369 {{ 0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}}, 370 {{ 0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}}, 371 {{ 0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}}, 372 {{-0.5f, 0.5f, 0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}}, 373 {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}} 374 })), 375 { 376 0, 1, 2, 3, 4, 5 377 }, objects_modelPipeline, { 378 mat4(1.0f) 379 }); 380 380 381 381 texturedSquare.model_base = … … 455 455 456 456 for (size_t i = 0; i < modelObjects.size(); i++) { 457 SceneObject<ModelVertex , SSBO_ModelObject>& obj = modelObjects[i];458 SSBO_ModelObject& objData = obj .ssbo;457 SceneObject<ModelVertex>& obj = modelObjects[i]; 458 SSBO_ModelObject& objData = objects_modelPipeline.get(i); 459 459 460 460 // Rotate the textured squares … … 488 488 489 489 modelPipeline.cleanupBuffers(); 490 491 for (size_t i = 0; i < storageBuffers_modelPipeline.buffers.size(); i++) {492 vkDestroyBuffer(device, storageBuffers_modelPipeline.buffers[i], nullptr);493 vkFreeMemory(device, storageBuffers_modelPipeline.memory[i], nullptr);494 }495 490 496 491 // END UNREVIEWED SECTION … … 1279 1274 createSyncObjects(); 1280 1275 1281 // TODO: Move UBO creation/management into GraphicsPipeline_Vulkan, like I did with SSBOs1282 // TODO: Check if the shader stages and maybe some other properties of the pipeline can be re-used1283 // instead of recreated every time1284 1285 1276 createBufferSet(sizeof(UBO_VP_mats), 1286 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 1287 uniformBuffers_modelPipeline); 1277 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 1278 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 1279 uniformBuffers_modelPipeline); 1280 1281 createBufferSet(objects_modelPipeline.memorySize(), 1282 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT 1283 | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 1284 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 1285 storageBuffers_modelPipeline); 1288 1286 1289 1287 modelPipeline.updateRenderPass(renderPass); … … 1312 1310 vkDestroyBuffer(device, uniformBuffers_modelPipeline.buffers[i], nullptr); 1313 1311 vkFreeMemory(device, uniformBuffers_modelPipeline.memory[i], nullptr); 1312 } 1313 1314 for (size_t i = 0; i < storageBuffers_modelPipeline.buffers.size(); i++) { 1315 vkDestroyBuffer(device, storageBuffers_modelPipeline.buffers[i], nullptr); 1316 vkFreeMemory(device, storageBuffers_modelPipeline.memory[i], nullptr); 1314 1317 } 1315 1318
Note:
See TracChangeset
for help on using the changeset viewer.