Mercurial > games > semicongine
comparison semiconginev2/rendering/shaders.nim @ 1228:4e465583ea32
did: rename texture to image
author | sam <sam@basx.dev> |
---|---|
date | Thu, 18 Jul 2024 16:33:24 +0700 |
parents | 56781cc0fc7c |
children | 5dcb503ef0c0 |
comparison
equal
deleted
inserted
replaced
1227:4d97cfc4888b | 1228:4e465583ea32 |
---|---|
1 func GlslType[T: SupportedGPUType|Texture](value: T): string = | 1 func GlslType[T: SupportedGPUType|Image](value: T): string = |
2 when T is float32: "float" | 2 when T is float32: "float" |
3 elif T is float64: "double" | 3 elif T is float64: "double" |
4 elif T is int8 or T is int16 or T is int32 or T is int64: "int" | 4 elif T is int8 or T is int16 or T is int32 or T is int64: "int" |
5 elif T is uint8 or T is uint16 or T is uint32 or T is uint64: "uint" | 5 elif T is uint8 or T is uint16 or T is uint32 or T is uint64: "uint" |
6 elif T is TVec2[int32]: "ivec2" | 6 elif T is TVec2[int32]: "ivec2" |
33 elif T is TMat34[float64]: "dmat34" | 33 elif T is TMat34[float64]: "dmat34" |
34 elif T is TMat43[float32]: "mat43" | 34 elif T is TMat43[float32]: "mat43" |
35 elif T is TMat43[float64]: "dmat43" | 35 elif T is TMat43[float64]: "dmat43" |
36 elif T is TMat4[float32]: "mat4" | 36 elif T is TMat4[float32]: "mat4" |
37 elif T is TMat4[float64]: "dmat4" | 37 elif T is TMat4[float64]: "dmat4" |
38 elif T is Texture: "sampler2D" | 38 elif T is Image: "sampler2D" |
39 else: {.error: "Unsupported data type on GPU".} | 39 else: {.error: "Unsupported data type on GPU".} |
40 | 40 |
41 func VkType[T: SupportedGPUType](value: T): VkFormat = | 41 func VkType[T: SupportedGPUType](value: T): VkFormat = |
42 when T is float32: VK_FORMAT_R32_SFLOAT | 42 when T is float32: VK_FORMAT_R32_SFLOAT |
43 elif T is float64: VK_FORMAT_R64_SFLOAT | 43 elif T is float64: VK_FORMAT_R64_SFLOAT |
82 elif T is TMat4[float32]: VK_FORMAT_R32G32B32A32_SFLOAT | 82 elif T is TMat4[float32]: VK_FORMAT_R32G32B32A32_SFLOAT |
83 elif T is TMat4[float64]: VK_FORMAT_R64G64B64A64_SFLOAT | 83 elif T is TMat4[float64]: VK_FORMAT_R64G64B64A64_SFLOAT |
84 else: {.error: "Unsupported data type on GPU".} | 84 else: {.error: "Unsupported data type on GPU".} |
85 | 85 |
86 | 86 |
87 func NumberOfVertexInputAttributeDescriptors[T: SupportedGPUType|Texture](value: T): uint32 = | 87 func NumberOfVertexInputAttributeDescriptors[T: SupportedGPUType|Image](value: T): uint32 = |
88 when T is TMat2[float32] or T is TMat2[float64] or T is TMat23[float32] or T is TMat23[float64]: | 88 when T is TMat2[float32] or T is TMat2[float64] or T is TMat23[float32] or T is TMat23[float64]: |
89 2 | 89 2 |
90 elif T is TMat32[float32] or T is TMat32[float64] or T is TMat3[float32] or T is TMat3[float64] or T is TMat34[float32] or T is TMat34[float64]: | 90 elif T is TMat32[float32] or T is TMat32[float64] or T is TMat3[float32] or T is TMat3[float64] or T is TMat34[float32] or T is TMat34[float64]: |
91 3 | 91 3 |
92 elif T is TMat43[float32] or T is TMat43[float64] or T is TMat4[float32] or T is TMat4[float64]: | 92 elif T is TMat43[float32] or T is TMat43[float64] or T is TMat4[float32] or T is TMat4[float64]: |
93 4 | 93 4 |
94 else: | 94 else: |
95 1 | 95 1 |
96 | 96 |
97 func NLocationSlots[T: SupportedGPUType|Texture](value: T): uint32 = | 97 func NLocationSlots[T: SupportedGPUType|Image](value: T): uint32 = |
98 #[ | 98 #[ |
99 single location: | 99 single location: |
100 - any scalar | 100 - any scalar |
101 - any 16-bit vector | 101 - any 16-bit vector |
102 - any 32-bit vector | 102 - any 32-bit vector |
167 | 167 |
168 var descriptorBinding = 0 | 168 var descriptorBinding = 0 |
169 | 169 |
170 for descriptorName, descriptorValue in fieldPairs(descriptor): | 170 for descriptorName, descriptorValue in fieldPairs(descriptor): |
171 | 171 |
172 when typeof(descriptorValue) is Texture: | 172 when typeof(descriptorValue) is Image: |
173 samplers.add "layout(set=" & $descriptorSetIndex & ", binding = " & $descriptorBinding & ") uniform " & GlslType(descriptorValue) & " " & descriptorName & ";" | 173 samplers.add "layout(set=" & $descriptorSetIndex & ", binding = " & $descriptorBinding & ") uniform " & GlslType(descriptorValue) & " " & descriptorName & ";" |
174 descriptorBinding.inc | 174 descriptorBinding.inc |
175 | 175 |
176 elif typeof(descriptorValue) is GPUValue: | 176 elif typeof(descriptorValue) is GPUValue: |
177 | 177 |
187 {.error: "Unsupported shader descriptor field " & descriptorName & " (must be object)".} | 187 {.error: "Unsupported shader descriptor field " & descriptorName & " (must be object)".} |
188 descriptorBinding.inc | 188 descriptorBinding.inc |
189 | 189 |
190 elif typeof(descriptorValue) is array: | 190 elif typeof(descriptorValue) is array: |
191 | 191 |
192 when elementType(descriptorValue) is Texture: | 192 when elementType(descriptorValue) is Image: |
193 | 193 |
194 let arrayDecl = "[" & $typeof(descriptorValue).len & "]" | 194 let arrayDecl = "[" & $typeof(descriptorValue).len & "]" |
195 samplers.add "layout(set=" & $descriptorSetIndex & ", binding = " & $descriptorBinding & ") uniform " & GlslType(default(elementType(descriptorValue))) & " " & descriptorName & "" & arrayDecl & ";" | 195 samplers.add "layout(set=" & $descriptorSetIndex & ", binding = " & $descriptorBinding & ") uniform " & GlslType(default(elementType(descriptorValue))) & " " & descriptorName & "" & arrayDecl & ";" |
196 descriptorBinding.inc | 196 descriptorBinding.inc |
197 | 197 |