Changeset 8e02b6b in opengl-game for vulkan-game.cpp
- Timestamp:
- Nov 22, 2019, 6:27:13 PM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- f97c5e7
- Parents:
- 683dd55
- git-author:
- Dmitry Portnoy <dmitry.portnoy@…> (11/22/19 18:26:59)
- git-committer:
- Dmitry Portnoy <dmitry.portnoy@…> (11/22/19 18:27:13)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vulkan-game.cpp
r683dd55 r8e02b6b 26 26 framebufferResized = false; 27 27 28 ubo= {};28 modelMvpMats = {}; 29 29 } 30 30 … … 266 266 mat4 T = translate(mat4(1.0f), vec3(-cam_pos.x, -cam_pos.y, -cam_pos.z)); 267 267 268 ubo.view = R * T;269 270 ubo.proj = perspective(radians(FOV_ANGLE), (float)swapChainExtent.width / (float)swapChainExtent.height, NEAR_CLIP, FAR_CLIP);271 ubo.proj[1][1] *= -1; // flip the y-axis so that +y is up268 modelMvpMats.view = R * T; 269 270 modelMvpMats.proj = perspective(radians(FOV_ANGLE), (float)swapChainExtent.width / (float)swapChainExtent.height, NEAR_CLIP, FAR_CLIP); 271 modelMvpMats.proj[1][1] *= -1; // flip the y-axis so that +y is up 272 272 } 273 273 … … 342 342 } 343 343 344 void VulkanGame::updateScene(uint32_t currentImage) { 345 static auto startTime = chrono::high_resolution_clock::now(); 346 347 auto currentTime = chrono::high_resolution_clock::now(); 348 float time = chrono::duration<float, chrono::seconds::period>(currentTime - startTime).count(); 349 350 modelMvpMats.model = 351 translate(mat4(1.0f), vec3(0.0f, -2.0f, -0.0f)) * 352 rotate(mat4(1.0f), time * radians(90.0f), vec3(0.0f, 0.0f, 1.0f)); 353 354 VulkanUtils::copyDataToMemory(device, uniformBuffersMemory[currentImage], modelMvpMats); 355 } 356 344 357 void VulkanGame::renderUI() { 345 358 SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00); … … 380 393 } 381 394 382 updateUniformBuffer(imageIndex); 395 // TODO: Figure out a more elegant way to only do updates and render the UI once per scene render 396 // Probably move some of the renderScene() code into a higher function that updates the UI, and renders 397 // the UI and scene 398 updateScene(imageIndex); 383 399 384 400 VkSubmitInfo submitInfo = {}; … … 880 896 881 897 void VulkanGame::createUniformBuffers() { 882 VkDeviceSize bufferSize = sizeof(U niformBufferObject);898 VkDeviceSize bufferSize = sizeof(UBO_MvpMat); 883 899 884 900 uniformBuffers.resize(swapChainImages.size()); … … 893 909 uniformBufferInfoList[i].buffer = uniformBuffers[i]; 894 910 uniformBufferInfoList[i].offset = 0; 895 uniformBufferInfoList[i].range = sizeof(U niformBufferObject);911 uniformBufferInfoList[i].range = sizeof(UBO_MvpMat); 896 912 } 897 913 } … … 1005 1021 } 1006 1022 1007 void VulkanGame::updateUniformBuffer(uint32_t currentImage) {1008 static auto startTime = chrono::high_resolution_clock::now();1009 1010 auto currentTime = chrono::high_resolution_clock::now();1011 float time = chrono::duration<float, chrono::seconds::period>(currentTime - startTime).count();1012 1013 ubo.model =1014 translate(mat4(1.0f), vec3(0.0f, -2.0f, -0.0f)) *1015 rotate(mat4(1.0f), time * radians(90.0f), vec3(0.0f, 0.0f, 1.0f));1016 1017 void* data;1018 vkMapMemory(device, uniformBuffersMemory[currentImage], 0, sizeof(ubo), 0, &data);1019 memcpy(data, &ubo, sizeof(ubo));1020 vkUnmapMemory(device, uniformBuffersMemory[currentImage]);1021 }1022 1023 1023 void VulkanGame::cleanupSwapChain() { 1024 1024 VulkanUtils::destroyVulkanImage(device, depthImage);
Note:
See TracChangeset
for help on using the changeset viewer.