Mercurial > games > semicongine
comparison src/zamikongine/engine.nim @ 33:94c38e4b5782
did: refactoring, move more from make to nimscript
author | Sam <sam@basx.dev> |
---|---|
date | Sun, 15 Jan 2023 23:23:54 +0700 |
parents | 9edca5dc4e93 |
children | c3c963e7c1a6 |
comparison
equal
deleted
inserted
replaced
32:9edca5dc4e93 | 33:94c38e4b5782 |
---|---|
499 result.vulkan.renderFinishedSemaphores, | 499 result.vulkan.renderFinishedSemaphores, |
500 result.vulkan.inFlightFences, | 500 result.vulkan.inFlightFences, |
501 ) = result.vulkan.device.device.setupSyncPrimitives() | 501 ) = result.vulkan.device.device.setupSyncPrimitives() |
502 | 502 |
503 | 503 |
504 proc setupPipeline*[VertexType, UniformType: object, IndexType: uint16|uint32](engine: var Engine, scenedata: ref Thing, vertexShader, fragmentShader: static string): RenderPipeline[VertexType, UniformType] = | 504 proc setupPipeline*[VertexType; UniformType; IndexType: uint16|uint32](engine: var Engine, scenedata: ref Thing, vertexShader, fragmentShader: static string): RenderPipeline[VertexType, UniformType] = |
505 engine.currentscenedata = scenedata | 505 engine.currentscenedata = scenedata |
506 result = initRenderPipeline[VertexType, UniformType]( | 506 result = initRenderPipeline[VertexType, UniformType]( |
507 engine.vulkan.device.device, | 507 engine.vulkan.device.device, |
508 engine.vulkan.frameDimension, | 508 engine.vulkan.frameDimension, |
509 engine.vulkan.renderPass, | 509 engine.vulkan.renderPass, |
574 pBufferInfo: cast[ptr ptr VkDescriptorBufferInfo](addr(bufferInfos[i][0])), | 574 pBufferInfo: cast[ptr ptr VkDescriptorBufferInfo](addr(bufferInfos[i][0])), |
575 ) | 575 ) |
576 vkUpdateDescriptorSets(result.device, 1, addr(descriptorWrite), 0, nil) | 576 vkUpdateDescriptorSets(result.device, 1, addr(descriptorWrite), 0, nil) |
577 | 577 |
578 | 578 |
579 proc runPipeline(commandBuffer: VkCommandBuffer, pipeline: var RenderPipeline, currentFrame: int) = | 579 proc runPipeline[VertexType; Uniforms](commandBuffer: VkCommandBuffer, pipeline: var RenderPipeline[VertexType, Uniforms], currentFrame: int) = |
580 vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline.pipeline) | 580 vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline.pipeline) |
581 | 581 |
582 vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline.layout, 0, 1, addr(pipeline.descriptors[currentFrame]), 0, nil) | 582 vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline.layout, 0, 1, addr(pipeline.descriptors[currentFrame]), 0, nil) |
583 for (vertexBufferSet, vertexCount) in pipeline.vertexBuffers: | 583 for (vertexBufferSet, vertexCount) in pipeline.vertexBuffers: |
584 var | 584 var |
586 offsets: seq[VkDeviceSize] | 586 offsets: seq[VkDeviceSize] |
587 for buffer in vertexBufferSet: | 587 for buffer in vertexBufferSet: |
588 vertexBuffers.add buffer.vkBuffer | 588 vertexBuffers.add buffer.vkBuffer |
589 offsets.add VkDeviceSize(0) | 589 offsets.add VkDeviceSize(0) |
590 | 590 |
591 vkCmdBindVertexBuffers(commandBuffer, firstBinding=0'u32, bindingCount=2'u32, pBuffers=addr(vertexBuffers[0]), pOffsets=addr(offsets[0])) | 591 vkCmdBindVertexBuffers(commandBuffer, firstBinding=0'u32, bindingCount=uint32(vertexBuffers.len), pBuffers=addr(vertexBuffers[0]), pOffsets=addr(offsets[0])) |
592 vkCmdDraw(commandBuffer, vertexCount=vertexCount, instanceCount=1'u32, firstVertex=0'u32, firstInstance=0'u32) | 592 vkCmdDraw(commandBuffer, vertexCount=vertexCount, instanceCount=1'u32, firstVertex=0'u32, firstInstance=0'u32) |
593 | 593 |
594 for (vertexBufferSet, indexBuffer, indicesCount, indexType) in pipeline.indexedVertexBuffers: | 594 for (vertexBufferSet, indexBuffer, indicesCount, indexType) in pipeline.indexedVertexBuffers: |
595 var | 595 var |
596 vertexBuffers: seq[VkBuffer] | 596 vertexBuffers: seq[VkBuffer] |
597 offsets: seq[VkDeviceSize] | 597 offsets: seq[VkDeviceSize] |
598 for buffer in vertexBufferSet: | 598 for buffer in vertexBufferSet: |
599 vertexBuffers.add buffer.vkBuffer | 599 vertexBuffers.add buffer.vkBuffer |
600 offsets.add VkDeviceSize(0) | 600 offsets.add VkDeviceSize(0) |
601 | 601 |
602 vkCmdBindVertexBuffers(commandBuffer, firstBinding=0'u32, bindingCount=2'u32, pBuffers=addr(vertexBuffers[0]), pOffsets=addr(offsets[0])) | 602 vkCmdBindVertexBuffers(commandBuffer, firstBinding=0'u32, bindingCount=uint32(vertexBuffers.len), pBuffers=addr(vertexBuffers[0]), pOffsets=addr(offsets[0])) |
603 vkCmdBindIndexBuffer(commandBuffer, indexBuffer.vkBuffer, VkDeviceSize(0), indexType) | 603 vkCmdBindIndexBuffer(commandBuffer, indexBuffer.vkBuffer, VkDeviceSize(0), indexType) |
604 vkCmdDrawIndexed(commandBuffer, indicesCount, 1, 0, 0, 0) | 604 vkCmdDrawIndexed(commandBuffer, indicesCount, 1, 0, 0, 0) |
605 | 605 |
606 proc recordCommandBuffer(renderPass: VkRenderPass, pipeline: var RenderPipeline, commandBuffer: VkCommandBuffer, framebuffer: VkFramebuffer, frameDimension: VkExtent2D, currentFrame: int) = | 606 proc recordCommandBuffer(renderPass: VkRenderPass, pipeline: var RenderPipeline, commandBuffer: VkCommandBuffer, framebuffer: VkFramebuffer, frameDimension: VkExtent2D, currentFrame: int) = |
607 var | 607 var |