Changeset c8b0357 in opengl-game
- Timestamp:
- Aug 16, 2019, 9:31:26 PM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- b8b32bd
- Parents:
- 9cd92ae
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
shaders/shader.vert
r9cd92ae rc8b0357 17 17 18 18 void main() { 19 if (gl_VertexIndex < 8 19 if (gl_VertexIndex < 8) { 20 20 gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 1.0); 21 21 fragColor = inColor; -
vulkan-game.cpp
r9cd92ae rc8b0357 111 111 }; 112 112 113 const vector<Vertex> vertices = { 114 {{-0.5f, -0.5f, -0.5f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}}, 115 {{ 0.5f, -0.5f, -0.5f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}}, 116 {{ 0.5f, 0.5f, -0.5f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}}, 117 {{-0.5f, 0.5f, -0.5f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}}, 118 119 {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}}, 120 {{ 0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}}, 121 {{ 0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}}, 122 {{-0.5f, 0.5f, 0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}}, 123 124 {{-1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}}, 125 {{ 1.0f, 1.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}}, 126 {{ 1.0f, -1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}}, 127 {{-1.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}} 128 }; 129 130 const vector<uint16_t> indices = { 131 0, 1, 2, 2, 3, 0, 132 4, 5, 6, 6, 7, 4, 133 8, 9, 10, 10, 11, 8 113 struct BufferInfo { 114 VkBuffer vertexBuffer; 115 VkDeviceMemory vertexBufferMemory; 116 size_t numVertices; 117 118 VkBuffer indexBuffer; 119 VkDeviceMemory indexBufferMemory; 120 size_t numIndices; 134 121 }; 135 122 … … 224 211 VkSampler textureSampler; 225 212 226 VkBuffer vertexBuffer; 227 VkDeviceMemory vertexBufferMemory; 228 229 VkBuffer indexBuffer; 230 VkDeviceMemory indexBufferMemory; 213 BufferInfo sceneBuffers; 214 BufferInfo overlayBuffers; 231 215 232 216 vector<VkBuffer> uniformBuffers; … … 336 320 createImageResourcesFromSDLTexture(uiOverlay, sdlOverlayImage, sdlOverlayImageMemory, sdlOverlayImageView); 337 321 createTextureSampler(); 338 createVertexBuffer(); 339 createIndexBuffer(); 322 323 createShaderBuffers(sceneBuffers, { 324 {{-0.5f, -0.5f, -0.5f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}}, 325 {{ 0.5f, -0.5f, -0.5f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}}, 326 {{ 0.5f, 0.5f, -0.5f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}}, 327 {{-0.5f, 0.5f, -0.5f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}}, 328 329 {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}}, 330 {{ 0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}}, 331 {{ 0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}}, 332 {{-0.5f, 0.5f, 0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}} 333 }, { 334 0, 1, 2, 2, 3, 0, 335 4, 5, 6, 6, 7, 4 336 }); 337 338 createShaderBuffers(overlayBuffers, { 339 // Filler vertices to increase the overlay vertex indices to at least 8 340 {{-1.0f, -1.0f, 3.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}}, 341 {{-1.0f, -1.0f, 3.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}}, 342 {{-1.0f, -1.0f, 3.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}}, 343 {{-1.0f, -1.0f, 3.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}}, 344 {{-1.0f, -1.0f, 3.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}}, 345 {{-1.0f, -1.0f, 3.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}}, 346 {{-1.0f, -1.0f, 3.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}}, 347 {{-1.0f, -1.0f, 3.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}}, 348 349 {{-1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}}, 350 {{ 1.0f, 1.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}}, 351 {{ 1.0f, -1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}}, 352 {{-1.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}} 353 }, { 354 8, 9, 10, 10, 11, 8 355 }); 356 340 357 createUniformBuffers(); 341 358 createDescriptorPool(); … … 1317 1334 } 1318 1335 1319 void createVertexBuffer() { 1336 void createShaderBuffers(BufferInfo& info, const vector<Vertex>& vertices, const vector<uint16_t>& indices) { 1337 createVertexBuffer(info.vertexBuffer, info.vertexBufferMemory, vertices); 1338 info.numVertices = vertices.size(); 1339 1340 createIndexBuffer(info.indexBuffer, info.indexBufferMemory, indices); 1341 info.numIndices = indices.size(); 1342 } 1343 1344 void createVertexBuffer(VkBuffer& vertexBuffer, VkDeviceMemory& vertexBufferMemory, 1345 const vector<Vertex>& vertices) { 1320 1346 VkDeviceSize bufferSize = sizeof(vertices[0]) * vertices.size(); 1321 1347 … … 1340 1366 } 1341 1367 1342 void createIndexBuffer() { 1368 void createIndexBuffer(VkBuffer& indexBuffer, VkDeviceMemory& indexBufferMemory, 1369 const vector<uint16_t>& indices) { 1343 1370 VkDeviceSize bufferSize = sizeof(indices[0]) * indices.size(); 1344 1371 … … 1585 1612 vkCmdBindPipeline(commandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, graphicsPipeline); 1586 1613 1587 VkBuffer vertexBuffers[] = { vertexBuffer }; 1614 vkCmdBindDescriptorSets(commandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSets[i], 0, nullptr); 1615 1616 VkBuffer vertexBuffers[] = { sceneBuffers.vertexBuffer }; 1588 1617 VkDeviceSize offsets[] = { 0 }; 1589 1618 vkCmdBindVertexBuffers(commandBuffers[i], 0, 1, vertexBuffers, offsets); 1590 1619 1591 vkCmdBindIndexBuffer(commandBuffers[i], indexBuffer, 0, VK_INDEX_TYPE_UINT16); 1592 vkCmdBindDescriptorSets(commandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSets[i], 0, nullptr); 1593 1594 vkCmdDrawIndexed(commandBuffers[i], static_cast<uint32_t>(indices.size()), 1, 0, 0, 0); 1620 vkCmdBindIndexBuffer(commandBuffers[i], sceneBuffers.indexBuffer, 0, VK_INDEX_TYPE_UINT16); 1621 1622 vkCmdDrawIndexed(commandBuffers[i], static_cast<uint32_t>(sceneBuffers.numIndices), 1, 0, 0, 0); 1623 1624 vkCmdBindPipeline(commandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, graphicsPipeline); 1625 1626 VkBuffer vertexBuffersOverlay[] = { overlayBuffers.vertexBuffer }; 1627 vkCmdBindVertexBuffers(commandBuffers[i], 0, 1, vertexBuffersOverlay, offsets); 1628 1629 vkCmdBindIndexBuffer(commandBuffers[i], overlayBuffers.indexBuffer, 0, VK_INDEX_TYPE_UINT16); 1630 1631 vkCmdDrawIndexed(commandBuffers[i], static_cast<uint32_t>(overlayBuffers.numIndices), 1, 0, 0, 0); 1595 1632 1596 1633 vkCmdEndRenderPass(commandBuffers[i]); … … 1813 1850 vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr); 1814 1851 1815 vkDestroyBuffer(device, indexBuffer, nullptr); 1816 vkFreeMemory(device, indexBufferMemory, nullptr); 1817 1818 vkDestroyBuffer(device, vertexBuffer, nullptr); 1819 vkFreeMemory(device, vertexBufferMemory, nullptr); 1852 vkDestroyBuffer(device, sceneBuffers.vertexBuffer, nullptr); 1853 vkFreeMemory(device, sceneBuffers.vertexBufferMemory, nullptr); 1854 vkDestroyBuffer(device, sceneBuffers.indexBuffer, nullptr); 1855 vkFreeMemory(device, sceneBuffers.indexBufferMemory, nullptr); 1856 1857 vkDestroyBuffer(device, overlayBuffers.vertexBuffer, nullptr); 1858 vkFreeMemory(device, overlayBuffers.vertexBufferMemory, nullptr); 1859 vkDestroyBuffer(device, overlayBuffers.indexBuffer, nullptr); 1860 vkFreeMemory(device, overlayBuffers.indexBufferMemory, nullptr); 1820 1861 1821 1862 for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
Note:
See TracChangeset
for help on using the changeset viewer.