comparison semiconginev2/rendering.nim @ 1228:4e465583ea32

did: rename texture to image
author sam <sam@basx.dev>
date Thu, 18 Jul 2024 16:33:24 +0700
parents c8e3037aca66
children 5dcb503ef0c0
comparison
equal deleted inserted replaced
1227:4d97cfc4888b 1228:4e465583ea32
73 func currentFiF*(swapchain: Swapchain): int = swapchain.currentFiF 73 func currentFiF*(swapchain: Swapchain): int = swapchain.currentFiF
74 74
75 type 75 type
76 # type aliases 76 # type aliases
77 SupportedGPUType = float32 | float64 | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | TVec2[int32] | TVec2[int64] | TVec3[int32] | TVec3[int64] | TVec4[int32] | TVec4[int64] | TVec2[uint32] | TVec2[uint64] | TVec3[uint32] | TVec3[uint64] | TVec4[uint32] | TVec4[uint64] | TVec2[float32] | TVec2[float64] | TVec3[float32] | TVec3[float64] | TVec4[float32] | TVec4[float64] | TMat2[float32] | TMat2[float64] | TMat23[float32] | TMat23[float64] | TMat32[float32] | TMat32[float64] | TMat3[float32] | TMat3[float64] | TMat34[float32] | TMat34[float64] | TMat43[float32] | TMat43[float64] | TMat4[float32] | TMat4[float64] 77 SupportedGPUType = float32 | float64 | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | TVec2[int32] | TVec2[int64] | TVec3[int32] | TVec3[int64] | TVec4[int32] | TVec4[int64] | TVec2[uint32] | TVec2[uint64] | TVec3[uint32] | TVec3[uint64] | TVec4[uint32] | TVec4[uint64] | TVec2[float32] | TVec2[float64] | TVec3[float32] | TVec3[float64] | TVec4[float32] | TVec4[float64] | TMat2[float32] | TMat2[float64] | TMat23[float32] | TMat23[float64] | TMat32[float32] | TMat32[float64] | TMat3[float32] | TMat3[float64] | TMat34[float32] | TMat34[float64] | TMat43[float32] | TMat43[float64] | TMat4[float32] | TMat4[float64]
78 TextureType = TVec1[uint8] | TVec4[uint8] 78 PixelType = TVec1[uint8] | TVec4[uint8]
79 79
80 # shader related types 80 # shader related types
81 DescriptorSet*[T: object] = object 81 DescriptorSet*[T: object] = object
82 data*: T 82 data*: T
83 vk: array[INFLIGHTFRAMES.int, VkDescriptorSet] 83 vk: array[INFLIGHTFRAMES.int, VkDescriptorSet]
104 Buffer* = object 104 Buffer* = object
105 vk: VkBuffer 105 vk: VkBuffer
106 size: uint64 106 size: uint64
107 rawPointer: pointer # if not nil, buffer is using mapped memory 107 rawPointer: pointer # if not nil, buffer is using mapped memory
108 offsetNextFree: uint64 108 offsetNextFree: uint64
109 Texture*[T: TextureType] = object 109 Image*[T: PixelType] = object
110 width*: uint32 110 width*: uint32
111 height*: uint32 111 height*: uint32
112 interpolation*: VkFilter = VK_FILTER_LINEAR 112 interpolation*: VkFilter = VK_FILTER_LINEAR
113 data*: seq[T] 113 data*: seq[T]
114 vk*: VkImage 114 vk*: VkImage
134 samplers: seq[VkSampler] 134 samplers: seq[VkSampler]
135 135
136 template ForDescriptorFields(shader: typed, fieldname, valuename, typename, countname, bindingNumber, body: untyped): untyped = 136 template ForDescriptorFields(shader: typed, fieldname, valuename, typename, countname, bindingNumber, body: untyped): untyped =
137 var `bindingNumber` {.inject.} = 0'u32 137 var `bindingNumber` {.inject.} = 0'u32
138 for theFieldname, value in fieldPairs(shader): 138 for theFieldname, value in fieldPairs(shader):
139 when typeof(value) is Texture: 139 when typeof(value) is Image:
140 block: 140 block:
141 const `fieldname` {.inject.} = theFieldname 141 const `fieldname` {.inject.} = theFieldname
142 const `typename` {.inject.} = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER 142 const `typename` {.inject.} = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
143 const `countname` {.inject.} = 1'u32 143 const `countname` {.inject.} = 1'u32
144 let `valuename` {.inject.} = value 144 let `valuename` {.inject.} = value
151 const `countname` {.inject.} = 1'u32 151 const `countname` {.inject.} = 1'u32
152 let `valuename` {.inject.} = value 152 let `valuename` {.inject.} = value
153 body 153 body
154 `bindingNumber`.inc 154 `bindingNumber`.inc
155 elif typeof(value) is array: 155 elif typeof(value) is array:
156 when elementType(value) is Texture: 156 when elementType(value) is Image:
157 block: 157 block:
158 const `fieldname` {.inject.} = theFieldname 158 const `fieldname` {.inject.} = theFieldname
159 const `typename` {.inject.} = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER 159 const `typename` {.inject.} = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
160 const `countname` {.inject.} = uint32(typeof(value).len) 160 const `countname` {.inject.} = uint32(typeof(value).len)
161 let `valuename` {.inject.} = value 161 let `valuename` {.inject.} = value
329 limits.framebufferColorSampleCounts.uint32 and limits.framebufferDepthSampleCounts.uint32 329 limits.framebufferColorSampleCounts.uint32 and limits.framebufferDepthSampleCounts.uint32
330 ).toEnums 330 ).toEnums
331 return min(max(available), maxSamples) 331 return min(max(available), maxSamples)
332 332
333 333
334 proc `[]`*(texture: Texture, x, y: uint32): auto = 334 proc `[]`*(image: Image, x, y: uint32): auto =
335 assert x < texture.width, &"{x} < {texture.width} is not true" 335 assert x < image.width, &"{x} < {image.width} is not true"
336 assert y < texture.height, &"{y} < {texture.height} is not true" 336 assert y < image.height, &"{y} < {image.height} is not true"
337 337
338 texture[].imagedata[y * texture.width + x] 338 image[].imagedata[y * image.width + x]
339 339
340 proc `[]=`*[T](texture: var Texture[T], x, y: uint32, value: T) = 340 proc `[]=`*[T](image: var Image[T], x, y: uint32, value: T) =
341 assert x < texture.width 341 assert x < image.width
342 assert y < texture.height 342 assert y < image.height
343 343
344 texture[].imagedata[y * texture.width + x] = value 344 image[].imagedata[y * image.width + x] = value