Changeset 8e02b6b in opengl-game for vulkan-game.cpp


Ignore:
Timestamp:
Nov 22, 2019, 6:27:13 PM (5 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
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)
Message:

To move to a more generic way of updating the scene, rename updateUniformBuffers() to updateScene() in VulkanGame and move the code to copy the data into a new copyDataToMemory() function in VulkanUtils.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vulkan-game.cpp

    r683dd55 r8e02b6b  
    2626   framebufferResized = false;
    2727
    28    ubo = {};
     28   modelMvpMats = {};
    2929}
    3030
     
    266266   mat4 T = translate(mat4(1.0f), vec3(-cam_pos.x, -cam_pos.y, -cam_pos.z));
    267267
    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 up
     268   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
    272272}
    273273
     
    342342}
    343343
     344void 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
    344357void VulkanGame::renderUI() {
    345358   SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00);
     
    380393   }
    381394
    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);
    383399
    384400   VkSubmitInfo submitInfo = {};
     
    880896
    881897void VulkanGame::createUniformBuffers() {
    882    VkDeviceSize bufferSize = sizeof(UniformBufferObject);
     898   VkDeviceSize bufferSize = sizeof(UBO_MvpMat);
    883899
    884900   uniformBuffers.resize(swapChainImages.size());
     
    893909      uniformBufferInfoList[i].buffer = uniformBuffers[i];
    894910      uniformBufferInfoList[i].offset = 0;
    895       uniformBufferInfoList[i].range = sizeof(UniformBufferObject);
     911      uniformBufferInfoList[i].range = sizeof(UBO_MvpMat);
    896912   }
    897913}
     
    10051021}
    10061022
    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 
    10231023void VulkanGame::cleanupSwapChain() {
    10241024   VulkanUtils::destroyVulkanImage(device, depthImage);
Note: See TracChangeset for help on using the changeset viewer.