Changeset 87c8f1a in opengl-game for vulkan-game.cpp


Ignore:
Timestamp:
Nov 1, 2019, 5:11:45 PM (5 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
d2d9286
Parents:
34bdf3a
git-author:
Dmitry Portnoy <dmitry.portnoy@…> (11/01/19 17:09:16)
git-committer:
Dmitry Portnoy <dmitry.portnoy@…> (11/01/19 17:11:45)
Message:

In vaulkangame, define vertex buffer and index buffer data and transfer it to the gpu

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vulkan-game.cpp

    r34bdf3a r87c8f1a  
    2121   gui = nullptr;
    2222   window = nullptr;
     23
     24   currentFrame = 0;
     25   framebufferResized = false;
    2326}
    2427
     
    138141   createUniformBuffers();
    139142
    140    graphicsPipelines.push_back(GraphicsPipeline_Vulkan(device, renderPass,
     143   vector<Vertex> sceneVertices = {
     144      {{-0.5f, -0.5f, -0.5f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}},
     145      {{ 0.5f, -0.5f, -0.5f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}},
     146      {{ 0.5f,  0.5f, -0.5f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}},
     147      {{-0.5f,  0.5f, -0.5f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}},
     148
     149      {{-0.5f, -0.5f,  0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}},
     150      {{ 0.5f, -0.5f,  0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}},
     151      {{ 0.5f,  0.5f,  0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}},
     152      {{-0.5f,  0.5f,  0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}}
     153   };
     154   vector<uint16_t> sceneIndices = {
     155      0, 1, 2, 2, 3, 0,
     156      4, 5, 6, 6, 7, 4
     157   };
     158
     159   graphicsPipelines.push_back(GraphicsPipeline_Vulkan(physicalDevice, device, renderPass,
    141160      { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, sizeof(Vertex)));
     161
     162   graphicsPipelines.back().bindData(sceneVertices, sceneIndices, commandPool, graphicsQueue);
    142163
    143164   graphicsPipelines.back().addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&Vertex::pos));
     
    155176   graphicsPipelines.back().createDescriptorSets(swapChainImages);
    156177
    157    graphicsPipelines.push_back(GraphicsPipeline_Vulkan(device, renderPass,
     178   vector<OverlayVertex> overlayVertices = {
     179      {{-1.0f,  1.0f,  0.0f}, {0.0f, 1.0f}},
     180      {{ 1.0f,  1.0f,  0.0f}, {1.0f, 1.0f}},
     181      {{ 1.0f, -1.0f,  0.0f}, {1.0f, 0.0f}},
     182      {{-1.0f, -1.0f,  0.0f}, {0.0f, 0.0f}}
     183   };
     184   vector<uint16_t> overlayIndices = {
     185      0, 1, 2, 2, 3, 0
     186   };
     187
     188   graphicsPipelines.push_back(GraphicsPipeline_Vulkan(physicalDevice, device, renderPass,
    158189      { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, sizeof(OverlayVertex)));
     190
     191   graphicsPipelines.back().bindData(overlayVertices, overlayIndices, commandPool, graphicsQueue);
    159192
    160193   graphicsPipelines.back().addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&OverlayVertex::pos));
     
    238271
    239272void VulkanGame::renderScene() {
     273   vkWaitForFences(device, 1, &inFlightFences[currentFrame], VK_TRUE, numeric_limits<uint64_t>::max());
     274
     275   uint32_t imageIndex;
     276
     277   currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
     278   currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
    240279}
    241280
Note: See TracChangeset for help on using the changeset viewer.