Changeset b8b32bd in opengl-game
- Timestamp:
- Aug 19, 2019, 9:51:48 PM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 58b95b3, d22ae72
- Parents:
- c8b0357
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vulkan-game.cpp
rc8b0357 rb8b32bd 111 111 }; 112 112 113 struct BufferInfo { 113 struct GraphicsPipelineInfo { 114 VkPipeline pipeline; 115 114 116 VkBuffer vertexBuffer; 115 117 VkDeviceMemory vertexBufferMemory; … … 187 189 VkDescriptorSetLayout descriptorSetLayout; 188 190 VkPipelineLayout pipelineLayout; 189 VkPipeline graphicsPipeline;190 191 VkDescriptorPool descriptorPool; 191 192 vector<VkDescriptorSet> descriptorSets; … … 211 212 VkSampler textureSampler; 212 213 213 BufferInfo sceneBuffers;214 BufferInfo overlayBuffers;214 GraphicsPipelineInfo scenePipeline; 215 GraphicsPipelineInfo overlayPipeline; 215 216 216 217 vector<VkBuffer> uniformBuffers; … … 313 314 createRenderPass(); 314 315 createDescriptorSetLayout(); 315 createGraphicsPipeline(); 316 createGraphicsPipeline("shaders/vert.spv", "shaders/frag.spv", &scenePipeline.pipeline); 317 createGraphicsPipeline("shaders/vert.spv", "shaders/frag.spv", &overlayPipeline.pipeline); 316 318 createCommandPool(); 317 319 createDepthResources(); … … 321 323 createTextureSampler(); 322 324 323 createShaderBuffers(scene Buffers, {325 createShaderBuffers(scenePipeline, { 324 326 {{-0.5f, -0.5f, -0.5f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}}, 325 327 {{ 0.5f, -0.5f, -0.5f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}}, … … 336 338 }); 337 339 338 createShaderBuffers(overlay Buffers, {340 createShaderBuffers(overlayPipeline, { 339 341 // Filler vertices to increase the overlay vertex indices to at least 8 340 342 {{-1.0f, -1.0f, 3.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}}, … … 797 799 } 798 800 799 void createGraphicsPipeline( ) {800 auto vertShaderCode = readFile( "shaders/vert.spv");801 auto fragShaderCode = readFile( "shaders/frag.spv");801 void createGraphicsPipeline(string vertShaderFile, string fragShaderFile, VkPipeline* pipeline) { 802 auto vertShaderCode = readFile(vertShaderFile); 803 auto fragShaderCode = readFile(fragShaderFile); 802 804 803 805 VkShaderModule vertShaderModule = createShaderModule(vertShaderCode); … … 929 931 pipelineInfo.basePipelineIndex = -1; 930 932 931 if (vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &graphicsPipeline) != VK_SUCCESS) {933 if (vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, pipeline) != VK_SUCCESS) { 932 934 throw runtime_error("failed to create graphics pipeline!"); 933 935 } … … 1334 1336 } 1335 1337 1336 void createShaderBuffers( BufferInfo& info, const vector<Vertex>& vertices, const vector<uint16_t>& indices) {1338 void createShaderBuffers(GraphicsPipelineInfo& info, const vector<Vertex>& vertices, const vector<uint16_t>& indices) { 1337 1339 createVertexBuffer(info.vertexBuffer, info.vertexBufferMemory, vertices); 1338 1340 info.numVertices = vertices.size(); … … 1610 1612 vkCmdBeginRenderPass(commandBuffers[i], &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE); 1611 1613 1612 vkCmdBindPipeline(commandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, graphicsPipeline);1614 vkCmdBindPipeline(commandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, scenePipeline.pipeline); 1613 1615 1614 1616 vkCmdBindDescriptorSets(commandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSets[i], 0, nullptr); 1615 1617 1616 VkBuffer vertexBuffers[] = { scene Buffers.vertexBuffer };1618 VkBuffer vertexBuffers[] = { scenePipeline.vertexBuffer }; 1617 1619 VkDeviceSize offsets[] = { 0 }; 1618 1620 vkCmdBindVertexBuffers(commandBuffers[i], 0, 1, vertexBuffers, offsets); 1619 1621 1620 vkCmdBindIndexBuffer(commandBuffers[i], scene Buffers.indexBuffer, 0, VK_INDEX_TYPE_UINT16);1621 1622 vkCmdDrawIndexed(commandBuffers[i], static_cast<uint32_t>(scene Buffers.numIndices), 1, 0, 0, 0);1623 1624 vkCmdBindPipeline(commandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, graphicsPipeline);1625 1626 VkBuffer vertexBuffersOverlay[] = { overlay Buffers.vertexBuffer };1622 vkCmdBindIndexBuffer(commandBuffers[i], scenePipeline.indexBuffer, 0, VK_INDEX_TYPE_UINT16); 1623 1624 vkCmdDrawIndexed(commandBuffers[i], static_cast<uint32_t>(scenePipeline.numIndices), 1, 0, 0, 0); 1625 1626 vkCmdBindPipeline(commandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, overlayPipeline.pipeline); 1627 1628 VkBuffer vertexBuffersOverlay[] = { overlayPipeline.vertexBuffer }; 1627 1629 vkCmdBindVertexBuffers(commandBuffers[i], 0, 1, vertexBuffersOverlay, offsets); 1628 1630 1629 vkCmdBindIndexBuffer(commandBuffers[i], overlay Buffers.indexBuffer, 0, VK_INDEX_TYPE_UINT16);1630 1631 vkCmdDrawIndexed(commandBuffers[i], static_cast<uint32_t>(overlay Buffers.numIndices), 1, 0, 0, 0);1631 vkCmdBindIndexBuffer(commandBuffers[i], overlayPipeline.indexBuffer, 0, VK_INDEX_TYPE_UINT16); 1632 1633 vkCmdDrawIndexed(commandBuffers[i], static_cast<uint32_t>(overlayPipeline.numIndices), 1, 0, 0, 0); 1632 1634 1633 1635 vkCmdEndRenderPass(commandBuffers[i]); … … 1822 1824 createImageViews(); 1823 1825 createRenderPass(); 1824 createGraphicsPipeline(); 1826 createGraphicsPipeline("shaders/vert.spv", "shaders/frag.spv", &scenePipeline.pipeline); 1827 createGraphicsPipeline("shaders/vert.spv", "shaders/frag.spv", &overlayPipeline.pipeline); 1825 1828 createDepthResources(); 1826 1829 createFramebuffers(); … … 1850 1853 vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr); 1851 1854 1852 vkDestroyBuffer(device, scene Buffers.vertexBuffer, nullptr);1853 vkFreeMemory(device, scene Buffers.vertexBufferMemory, nullptr);1854 vkDestroyBuffer(device, scene Buffers.indexBuffer, nullptr);1855 vkFreeMemory(device, scene Buffers.indexBufferMemory, nullptr);1856 1857 vkDestroyBuffer(device, overlay Buffers.vertexBuffer, nullptr);1858 vkFreeMemory(device, overlay Buffers.vertexBufferMemory, nullptr);1859 vkDestroyBuffer(device, overlay Buffers.indexBuffer, nullptr);1860 vkFreeMemory(device, overlay Buffers.indexBufferMemory, nullptr);1855 vkDestroyBuffer(device, scenePipeline.vertexBuffer, nullptr); 1856 vkFreeMemory(device, scenePipeline.vertexBufferMemory, nullptr); 1857 vkDestroyBuffer(device, scenePipeline.indexBuffer, nullptr); 1858 vkFreeMemory(device, scenePipeline.indexBufferMemory, nullptr); 1859 1860 vkDestroyBuffer(device, overlayPipeline.vertexBuffer, nullptr); 1861 vkFreeMemory(device, overlayPipeline.vertexBufferMemory, nullptr); 1862 vkDestroyBuffer(device, overlayPipeline.indexBuffer, nullptr); 1863 vkFreeMemory(device, overlayPipeline.indexBufferMemory, nullptr); 1861 1864 1862 1865 for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) { … … 1917 1920 vkFreeCommandBuffers(device, commandPool, static_cast<uint32_t>(commandBuffers.size()), commandBuffers.data()); 1918 1921 1919 vkDestroyPipeline(device, graphicsPipeline, nullptr); 1922 vkDestroyPipeline(device, scenePipeline.pipeline, nullptr); 1923 vkDestroyPipeline(device, overlayPipeline.pipeline, nullptr); 1924 1920 1925 vkDestroyPipelineLayout(device, pipelineLayout, nullptr); 1921 1926 vkDestroyRenderPass(device, renderPass, nullptr);
Note:
See TracChangeset
for help on using the changeset viewer.