Mercurial > games > semicongine
annotate semiconginev2/old/vulkan/drawable.nim @ 1221:000befd9479f compiletime-tests
did: remove support for git, for now
author | sam <sam@basx.dev> |
---|---|
date | Wed, 17 Jul 2024 21:05:47 +0700 |
parents | 56781cc0fc7c |
children |
rev | line source |
---|---|
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
1 import std/tables |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
2 import std/strformat |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
3 import std/logging |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
4 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
5 import ../core |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
6 import ./buffer |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
7 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
8 type |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
9 Drawable* = object |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
10 name*: string |
959
c104dbf5bbb8
did: adjust integer sizes to match vulkan API (more) directly
sam <sam@basx.dev>
parents:
920
diff
changeset
|
11 elementCount*: int # number of vertices or indices |
c104dbf5bbb8
did: adjust integer sizes to match vulkan API (more) directly
sam <sam@basx.dev>
parents:
920
diff
changeset
|
12 bufferOffsets*: Table[VkPipeline, seq[(string, MemoryPerformanceHint, uint64)]] # list of buffers and list of offset for each attribute in that buffer |
c104dbf5bbb8
did: adjust integer sizes to match vulkan API (more) directly
sam <sam@basx.dev>
parents:
920
diff
changeset
|
13 instanceCount*: int # number of instance |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
14 case indexed*: bool |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
15 of true: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
16 indexType*: VkIndexType |
959
c104dbf5bbb8
did: adjust integer sizes to match vulkan API (more) directly
sam <sam@basx.dev>
parents:
920
diff
changeset
|
17 indexBufferOffset*: uint64 |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
18 of false: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
19 discard |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
20 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
21 func `$`*(drawable: Drawable): string = |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
22 if drawable.indexed: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
23 &"Drawable({drawable.name}, elementCount: {drawable.elementCount}, instanceCount: {drawable.instanceCount}, bufferOffsets: {drawable.bufferOffsets}, indexType: {drawable.indexType}, indexBufferOffset: {drawable.indexBufferOffset})" |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
24 else: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
25 &"Drawable({drawable.name}, elementCount: {drawable.elementCount}, instanceCount: {drawable.instanceCount}, bufferOffsets: {drawable.bufferOffsets})" |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
26 |
1138 | 27 proc Draw*(drawable: Drawable, commandBuffer: VkCommandBuffer, vertexBuffers: Table[MemoryPerformanceHint, Buffer], indexBuffer: Buffer, pipeline: VkPipeline) = |
1001 | 28 debug &"Draw {drawable} with pipeline {pipeline}" |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
29 |
902 | 30 var buffers: seq[VkBuffer] |
31 var offsets: seq[VkDeviceSize] | |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
32 |
902 | 33 for (name, performanceHint, offset) in drawable.bufferOffsets[pipeline]: |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
34 assert vertexBuffers[performanceHint].vk.Valid |
902 | 35 buffers.add vertexBuffers[performanceHint].vk |
36 offsets.add VkDeviceSize(offset) | |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
37 |
963 | 38 debug "Binding buffers: ", buffers |
1001 | 39 debug "with offsets ", offsets |
902 | 40 commandBuffer.vkCmdBindVertexBuffers( |
41 firstBinding = 0'u32, | |
42 bindingCount = uint32(buffers.len), | |
1137 | 43 pBuffers = buffers.ToCPointer(), |
44 pOffsets = offsets.ToCPointer() | |
902 | 45 ) |
46 if drawable.indexed: | |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
47 assert indexBuffer.vk.Valid |
902 | 48 commandBuffer.vkCmdBindIndexBuffer(indexBuffer.vk, VkDeviceSize(drawable.indexBufferOffset), drawable.indexType) |
49 commandBuffer.vkCmdDrawIndexed( | |
50 indexCount = uint32(drawable.elementCount), | |
51 instanceCount = uint32(drawable.instanceCount), | |
52 firstIndex = 0, | |
53 vertexOffset = 0, | |
54 firstInstance = 0 | |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
55 ) |
902 | 56 else: |
57 commandBuffer.vkCmdDraw( | |
58 vertexCount = uint32(drawable.elementCount), | |
59 instanceCount = uint32(drawable.instanceCount), | |
60 firstVertex = 0, | |
61 firstInstance = 0 | |
62 ) |