Mercurial > games > semicongine
comparison semiconginev2/old/core/dynamic_arrays.nim @ 1218:56781cc0fc7c compiletime-tests
did: renamge main package
author | sam <sam@basx.dev> |
---|---|
date | Wed, 17 Jul 2024 21:01:37 +0700 |
parents | semicongine/old/core/dynamic_arrays.nim@a3eb305bcac2 |
children |
comparison
equal
deleted
inserted
replaced
1217:f819a874058f | 1218:56781cc0fc7c |
---|---|
1 import std/hashes | |
2 import std/tables | |
3 import std/strformat | |
4 | |
5 import ./gpu_types | |
6 import ./vector | |
7 import ./matrix | |
8 import ./utils | |
9 import ./imagetypes | |
10 | |
11 type | |
12 DataList* = object | |
13 len*: int | |
14 case theType*: DataType | |
15 of Float32: float32: ref seq[float32] | |
16 of Float64: float64: ref seq[float64] | |
17 of Int8: int8: ref seq[int8] | |
18 of Int16: int16: ref seq[int16] | |
19 of Int32: int32: ref seq[int32] | |
20 of Int64: int64: ref seq[int64] | |
21 of UInt8: uint8: ref seq[uint8] | |
22 of UInt16: uint16: ref seq[uint16] | |
23 of UInt32: uint32: ref seq[uint32] | |
24 of UInt64: uint64: ref seq[uint64] | |
25 of Vec2I32: vec2i32: ref seq[TVec2[int32]] | |
26 of Vec2I64: vec2i64: ref seq[TVec2[int64]] | |
27 of Vec3I32: vec3i32: ref seq[TVec3[int32]] | |
28 of Vec3I64: vec3i64: ref seq[TVec3[int64]] | |
29 of Vec4I32: vec4i32: ref seq[TVec4[int32]] | |
30 of Vec4I64: vec4i64: ref seq[TVec4[int64]] | |
31 of Vec2U32: vec2u32: ref seq[TVec2[uint32]] | |
32 of Vec2U64: vec2u64: ref seq[TVec2[uint64]] | |
33 of Vec3U32: vec3u32: ref seq[TVec3[uint32]] | |
34 of Vec3U64: vec3u64: ref seq[TVec3[uint64]] | |
35 of Vec4U32: vec4u32: ref seq[TVec4[uint32]] | |
36 of Vec4U64: vec4u64: ref seq[TVec4[uint64]] | |
37 of Vec2F32: vec2f32: ref seq[TVec2[float32]] | |
38 of Vec2F64: vec2f64: ref seq[TVec2[float64]] | |
39 of Vec3F32: vec3f32: ref seq[TVec3[float32]] | |
40 of Vec3F64: vec3f64: ref seq[TVec3[float64]] | |
41 of Vec4F32: vec4f32: ref seq[TVec4[float32]] | |
42 of Vec4F64: vec4f64: ref seq[TVec4[float64]] | |
43 of Mat2F32: mat2f32: ref seq[TMat2[float32]] | |
44 of Mat2F64: mat2f64: ref seq[TMat2[float64]] | |
45 of Mat23F32: mat23f32: ref seq[TMat23[float32]] | |
46 of Mat23F64: mat23f64: ref seq[TMat23[float64]] | |
47 of Mat32F32: mat32f32: ref seq[TMat32[float32]] | |
48 of Mat32F64: mat32f64: ref seq[TMat32[float64]] | |
49 of Mat3F32: mat3f32: ref seq[TMat3[float32]] | |
50 of Mat3F64: mat3f64: ref seq[TMat3[float64]] | |
51 of Mat34F32: mat34f32: ref seq[TMat34[float32]] | |
52 of Mat34F64: mat34f64: ref seq[TMat34[float64]] | |
53 of Mat43F32: mat43f32: ref seq[TMat43[float32]] | |
54 of Mat43F64: mat43f64: ref seq[TMat43[float64]] | |
55 of Mat4F32: mat4f32: ref seq[TMat4[float32]] | |
56 of Mat4F64: mat4f64: ref seq[TMat4[float64]] | |
57 of TextureType: texture: ref seq[Texture] | |
58 | |
59 func Size*(value: DataList): uint64 = | |
60 value.theType.Size * value.len.uint64 | |
61 | |
62 func hash*(value: DataList): Hash = | |
63 case value.theType | |
64 of Float32: hash(value.float32) | |
65 of Float64: hash(value.float64) | |
66 of Int8: hash(value.int8) | |
67 of Int16: hash(value.int16) | |
68 of Int32: hash(value.int32) | |
69 of Int64: hash(value.int64) | |
70 of UInt8: hash(value.uint8) | |
71 of UInt16: hash(value.uint16) | |
72 of UInt32: hash(value.uint32) | |
73 of UInt64: hash(value.uint64) | |
74 of Vec2I32: hash(value.vec2i32) | |
75 of Vec2I64: hash(value.vec2i64) | |
76 of Vec3I32: hash(value.vec3i32) | |
77 of Vec3I64: hash(value.vec3i64) | |
78 of Vec4I32: hash(value.vec4i32) | |
79 of Vec4I64: hash(value.vec4i64) | |
80 of Vec2U32: hash(value.vec2u32) | |
81 of Vec2U64: hash(value.vec2u64) | |
82 of Vec3U32: hash(value.vec3u32) | |
83 of Vec3U64: hash(value.vec3u64) | |
84 of Vec4U32: hash(value.vec4u32) | |
85 of Vec4U64: hash(value.vec4u64) | |
86 of Vec2F32: hash(value.vec2f32) | |
87 of Vec2F64: hash(value.vec2f64) | |
88 of Vec3F32: hash(value.vec3f32) | |
89 of Vec3F64: hash(value.vec3f64) | |
90 of Vec4F32: hash(value.vec4f32) | |
91 of Vec4F64: hash(value.vec4f64) | |
92 of Mat2F32: hash(value.mat2f32) | |
93 of Mat2F64: hash(value.mat2f64) | |
94 of Mat23F32: hash(value.mat23f32) | |
95 of Mat23F64: hash(value.mat23f64) | |
96 of Mat32F32: hash(value.mat32f32) | |
97 of Mat32F64: hash(value.mat32f64) | |
98 of Mat3F32: hash(value.mat3f32) | |
99 of Mat3F64: hash(value.mat3f64) | |
100 of Mat34F32: hash(value.mat34f32) | |
101 of Mat34F64: hash(value.mat34f64) | |
102 of Mat43F32: hash(value.mat43f32) | |
103 of Mat43F64: hash(value.mat43f64) | |
104 of Mat4F32: hash(value.mat4f32) | |
105 of Mat4F64: hash(value.mat4f64) | |
106 of TextureType: hash(value.texture) | |
107 | |
108 func `==`*(a, b: DataList): bool = | |
109 if a.theType != b.theType: | |
110 return false | |
111 case a.theType | |
112 of Float32: return a.float32 == b.float32 | |
113 of Float64: return a.float64 == b.float64 | |
114 of Int8: return a.int8 == b.int8 | |
115 of Int16: return a.int16 == b.int16 | |
116 of Int32: return a.int32 == b.int32 | |
117 of Int64: return a.int64 == b.int64 | |
118 of UInt8: return a.uint8 == b.uint8 | |
119 of UInt16: return a.uint16 == b.uint16 | |
120 of UInt32: return a.uint32 == b.uint32 | |
121 of UInt64: return a.uint64 == b.uint64 | |
122 of Vec2I32: return a.vec2i32 == b.vec2i32 | |
123 of Vec2I64: return a.vec2i64 == b.vec2i64 | |
124 of Vec3I32: return a.vec3i32 == b.vec3i32 | |
125 of Vec3I64: return a.vec3i64 == b.vec3i64 | |
126 of Vec4I32: return a.vec4i32 == b.vec4i32 | |
127 of Vec4I64: return a.vec4i64 == b.vec4i64 | |
128 of Vec2U32: return a.vec2u32 == b.vec2u32 | |
129 of Vec2U64: return a.vec2u64 == b.vec2u64 | |
130 of Vec3U32: return a.vec3u32 == b.vec3u32 | |
131 of Vec3U64: return a.vec3u64 == b.vec3u64 | |
132 of Vec4U32: return a.vec4u32 == b.vec4u32 | |
133 of Vec4U64: return a.vec4u64 == b.vec4u64 | |
134 of Vec2F32: return a.vec2f32 == b.vec2f32 | |
135 of Vec2F64: return a.vec2f64 == b.vec2f64 | |
136 of Vec3F32: return a.vec3f32 == b.vec3f32 | |
137 of Vec3F64: return a.vec3f64 == b.vec3f64 | |
138 of Vec4F32: return a.vec4f32 == b.vec4f32 | |
139 of Vec4F64: return a.vec4f64 == b.vec4f64 | |
140 of Mat2F32: return a.mat2f32 == b.mat2f32 | |
141 of Mat2F64: return a.mat2f64 == b.mat2f64 | |
142 of Mat23F32: return a.mat23f32 == b.mat23f32 | |
143 of Mat23F64: return a.mat23f64 == b.mat23f64 | |
144 of Mat32F32: return a.mat32f32 == b.mat32f32 | |
145 of Mat32F64: return a.mat32f64 == b.mat32f64 | |
146 of Mat3F32: return a.mat3f32 == b.mat3f32 | |
147 of Mat3F64: return a.mat3f64 == b.mat3f64 | |
148 of Mat34F32: return a.mat34f32 == b.mat34f32 | |
149 of Mat34F64: return a.mat34f64 == b.mat34f64 | |
150 of Mat43F32: return a.mat43f32 == b.mat43f32 | |
151 of Mat43F64: return a.mat43f64 == b.mat43f64 | |
152 of Mat4F32: return a.mat4f32 == b.mat4f32 | |
153 of Mat4F64: return a.mat4f64 == b.mat4f64 | |
154 of TextureType: a.texture == b.texture | |
155 | |
156 proc SetLen*(value: var DataList, len: int) = | |
157 value.len = len | |
158 case value.theType | |
159 of Float32: value.float32[].setLen(len) | |
160 of Float64: value.float64[].setLen(len) | |
161 of Int8: value.int8[].setLen(len) | |
162 of Int16: value.int16[].setLen(len) | |
163 of Int32: value.int32[].setLen(len) | |
164 of Int64: value.int64[].setLen(len) | |
165 of UInt8: value.uint8[].setLen(len) | |
166 of UInt16: value.uint16[].setLen(len) | |
167 of UInt32: value.uint32[].setLen(len) | |
168 of UInt64: value.uint64[].setLen(len) | |
169 of Vec2I32: value.vec2i32[].setLen(len) | |
170 of Vec2I64: value.vec2i64[].setLen(len) | |
171 of Vec3I32: value.vec3i32[].setLen(len) | |
172 of Vec3I64: value.vec3i64[].setLen(len) | |
173 of Vec4I32: value.vec4i32[].setLen(len) | |
174 of Vec4I64: value.vec4i64[].setLen(len) | |
175 of Vec2U32: value.vec2u32[].setLen(len) | |
176 of Vec2U64: value.vec2u64[].setLen(len) | |
177 of Vec3U32: value.vec3u32[].setLen(len) | |
178 of Vec3U64: value.vec3u64[].setLen(len) | |
179 of Vec4U32: value.vec4u32[].setLen(len) | |
180 of Vec4U64: value.vec4u64[].setLen(len) | |
181 of Vec2F32: value.vec2f32[].setLen(len) | |
182 of Vec2F64: value.vec2f64[].setLen(len) | |
183 of Vec3F32: value.vec3f32[].setLen(len) | |
184 of Vec3F64: value.vec3f64[].setLen(len) | |
185 of Vec4F32: value.vec4f32[].setLen(len) | |
186 of Vec4F64: value.vec4f64[].setLen(len) | |
187 of Mat2F32: value.mat2f32[].setLen(len) | |
188 of Mat2F64: value.mat2f64[].setLen(len) | |
189 of Mat23F32: value.mat23f32[].setLen(len) | |
190 of Mat23F64: value.mat23f64[].setLen(len) | |
191 of Mat32F32: value.mat32f32[].setLen(len) | |
192 of Mat32F64: value.mat32f64[].setLen(len) | |
193 of Mat3F32: value.mat3f32[].setLen(len) | |
194 of Mat3F64: value.mat3f64[].setLen(len) | |
195 of Mat34F32: value.mat34f32[].setLen(len) | |
196 of Mat34F64: value.mat34f64[].setLen(len) | |
197 of Mat43F32: value.mat43f32[].setLen(len) | |
198 of Mat43F64: value.mat43f64[].setLen(len) | |
199 of Mat4F32: value.mat4f32[].setLen(len) | |
200 of Mat4F64: value.mat4f64[].setLen(len) | |
201 of TextureType: discard | |
202 | |
203 | |
204 proc setValues[T: GPUType|int|uint|float](value: var DataList, data: openArray[T]) = | |
205 value.SetLen(data.len) | |
206 when T is float32: value.float32[] = @data | |
207 elif T is float64: value.float64[] = @data | |
208 elif T is int8: value.int8[] = @data | |
209 elif T is int16: value.int16[] = @data | |
210 elif T is int32: value.int32[] = @data | |
211 elif T is int64: value.int64[] = @data | |
212 elif T is uint8: value.uint8[] = @data | |
213 elif T is uint16: value.uint16[] = @data | |
214 elif T is uint32: value.uint32[] = @data | |
215 elif T is uint64: value.uint64[] = @data | |
216 elif T is int and sizeof(int) == sizeof(int32): value.int32[] = @data | |
217 elif T is int and sizeof(int) == sizeof(int64): value.int64[] = @data | |
218 elif T is uint and sizeof(uint) == sizeof(uint32): value.uint32[] = @data | |
219 elif T is uint and sizeof(uint) == sizeof(uint64): value.uint64[] = @data | |
220 elif T is float and sizeof(float) == sizeof(float32): value.float32[] = @data | |
221 elif T is float and sizeof(float) == sizeof(float64): value.float64[] = @data | |
222 elif T is TVec2[int32]: value.vec2i32[] = @data | |
223 elif T is TVec2[int64]: value.vec2i64[] = @data | |
224 elif T is TVec3[int32]: value.vec3i32[] = @data | |
225 elif T is TVec3[int64]: value.vec3i64[] = @data | |
226 elif T is TVec4[int32]: value.vec4i32[] = @data | |
227 elif T is TVec4[int64]: value.vec4i64[] = @data | |
228 elif T is TVec2[uint32]: value.vec2u32[] = @data | |
229 elif T is TVec2[uint64]: value.vec2u64[] = @data | |
230 elif T is TVec3[uint32]: value.vec3u32[] = @data | |
231 elif T is TVec3[uint64]: value.vec3u64[] = @data | |
232 elif T is TVec4[uint32]: value.vec4u32[] = @data | |
233 elif T is TVec4[uint64]: value.vec4u64[] = @data | |
234 elif T is TVec2[float32]: value.vec2f32[] = @data | |
235 elif T is TVec2[float64]: value.vec2f64[] = @data | |
236 elif T is TVec3[float32]: value.vec3f32[] = @data | |
237 elif T is TVec3[float64]: value.vec3f64[] = @data | |
238 elif T is TVec4[float32]: value.vec4f32[] = @data | |
239 elif T is TVec4[float64]: value.vec4f64[] = @data | |
240 elif T is TMat2[float32]: value.mat2f32[] = @data | |
241 elif T is TMat2[float64]: value.mat2f64[] = @data | |
242 elif T is TMat23[float32]: value.mat23f32[] = @data | |
243 elif T is TMat23[float64]: value.mat23f64[] = @data | |
244 elif T is TMat32[float32]: value.mat32f32[] = @data | |
245 elif T is TMat32[float64]: value.mat32f64[] = @data | |
246 elif T is TMat3[float32]: value.mat3f32[] = @data | |
247 elif T is TMat3[float64]: value.mat3f64[] = @data | |
248 elif T is TMat34[float32]: value.mat34f32[] = @data | |
249 elif T is TMat34[float64]: value.mat34f64[] = @data | |
250 elif T is TMat43[float32]: value.mat43f32[] = @data | |
251 elif T is TMat43[float64]: value.mat43f64[] = @data | |
252 elif T is TMat4[float32]: value.mat4f32[] = @data | |
253 elif T is TMat4[float64]: value.mat4f64[] = @data | |
254 elif T is Texture: value.texture[] = @data | |
255 else: {.error: "Virtual datatype has no values".} | |
256 | |
257 proc setValue[T: GPUType|int|uint|float](value: var DataList, i: int, data: T) = | |
258 assert i < value.len | |
259 when T is float32: value.float32[i] = data | |
260 elif T is float64: value.float64[i] = data | |
261 elif T is int8: value.int8[i] = data | |
262 elif T is int16: value.int16[i] = data | |
263 elif T is int32: value.int32[i] = data | |
264 elif T is int64: value.int64[i] = data | |
265 elif T is uint8: value.uint8[i] = data | |
266 elif T is uint16: value.uint16[i] = data | |
267 elif T is uint32: value.uint32[i] = data | |
268 elif T is uint64: value.uint64[i] = data | |
269 elif T is int and sizeof(int) == sizeof(int32): value.int32[i] = data | |
270 elif T is int and sizeof(int) == sizeof(int64): value.int64[i] = data | |
271 elif T is uint and sizeof(uint) == sizeof(uint32): value.uint32[i] = data | |
272 elif T is uint and sizeof(uint) == sizeof(uint64): value.uint64[i] = data | |
273 elif T is float and sizeof(float) == sizeof(float32): value.float32[i] = data | |
274 elif T is float and sizeof(float) == sizeof(float64): value.float64[i] = data | |
275 elif T is TVec2[int32]: value.vec2i32[i] = data | |
276 elif T is TVec2[int64]: value.vec2i64[i] = data | |
277 elif T is TVec3[int32]: value.vec3i32[i] = data | |
278 elif T is TVec3[int64]: value.vec3i64[i] = data | |
279 elif T is TVec4[int32]: value.vec4i32[i] = data | |
280 elif T is TVec4[int64]: value.vec4i64[i] = data | |
281 elif T is TVec2[uint32]: value.vec2u32[i] = data | |
282 elif T is TVec2[uint64]: value.vec2u64[i] = data | |
283 elif T is TVec3[uint32]: value.vec3u32[i] = data | |
284 elif T is TVec3[uint64]: value.vec3u64[i] = data | |
285 elif T is TVec4[uint32]: value.vec4u32[i] = data | |
286 elif T is TVec4[uint64]: value.vec4u64[i] = data | |
287 elif T is TVec2[float32]: value.vec2f32[i] = data | |
288 elif T is TVec2[float64]: value.vec2f64[i] = data | |
289 elif T is TVec3[float32]: value.vec3f32[i] = data | |
290 elif T is TVec3[float64]: value.vec3f64[i] = data | |
291 elif T is TVec4[float32]: value.vec4f32[i] = data | |
292 elif T is TVec4[float64]: value.vec4f64[i] = data | |
293 elif T is TMat2[float32]: value.mat2f32[i] = data | |
294 elif T is TMat2[float64]: value.mat2f64[i] = data | |
295 elif T is TMat23[float32]: value.mat23f32[i] = data | |
296 elif T is TMat23[float64]: value.mat23f64[i] = data | |
297 elif T is TMat32[float32]: value.mat32f32[i] = data | |
298 elif T is TMat32[float64]: value.mat32f64[i] = data | |
299 elif T is TMat3[float32]: value.mat3f32[i] = data | |
300 elif T is TMat3[float64]: value.mat3f64[i] = data | |
301 elif T is TMat34[float32]: value.mat34f32[i] = data | |
302 elif T is TMat34[float64]: value.mat34f64[i] = data | |
303 elif T is TMat43[float32]: value.mat43f32[i] = data | |
304 elif T is TMat43[float64]: value.mat43f64[i] = data | |
305 elif T is TMat4[float32]: value.mat4f32[i] = data | |
306 elif T is TMat4[float64]: value.mat4f64[i] = data | |
307 elif T is Texture: value.texture[i] = data | |
308 else: {.error: "Virtual datatype has no values".} | |
309 | |
310 proc InitDataList*(theType: DataType, len = 0): DataList = | |
311 result = DataList(theType: theType) | |
312 case result.theType | |
313 of Float32: result.float32 = new seq[float32] | |
314 of Float64: result.float64 = new seq[float64] | |
315 of Int8: result.int8 = new seq[int8] | |
316 of Int16: result.int16 = new seq[int16] | |
317 of Int32: result.int32 = new seq[int32] | |
318 of Int64: result.int64 = new seq[int64] | |
319 of UInt8: result.uint8 = new seq[uint8] | |
320 of UInt16: result.uint16 = new seq[uint16] | |
321 of UInt32: result.uint32 = new seq[uint32] | |
322 of UInt64: result.uint64 = new seq[uint64] | |
323 of Vec2I32: result.vec2i32 = new seq[TVec2[int32]] | |
324 of Vec2I64: result.vec2i64 = new seq[TVec2[int64]] | |
325 of Vec3I32: result.vec3i32 = new seq[TVec3[int32]] | |
326 of Vec3I64: result.vec3i64 = new seq[TVec3[int64]] | |
327 of Vec4I32: result.vec4i32 = new seq[TVec4[int32]] | |
328 of Vec4I64: result.vec4i64 = new seq[TVec4[int64]] | |
329 of Vec2U32: result.vec2u32 = new seq[TVec2[uint32]] | |
330 of Vec2U64: result.vec2u64 = new seq[TVec2[uint64]] | |
331 of Vec3U32: result.vec3u32 = new seq[TVec3[uint32]] | |
332 of Vec3U64: result.vec3u64 = new seq[TVec3[uint64]] | |
333 of Vec4U32: result.vec4u32 = new seq[TVec4[uint32]] | |
334 of Vec4U64: result.vec4u64 = new seq[TVec4[uint64]] | |
335 of Vec2F32: result.vec2f32 = new seq[TVec2[float32]] | |
336 of Vec2F64: result.vec2f64 = new seq[TVec2[float64]] | |
337 of Vec3F32: result.vec3f32 = new seq[TVec3[float32]] | |
338 of Vec3F64: result.vec3f64 = new seq[TVec3[float64]] | |
339 of Vec4F32: result.vec4f32 = new seq[TVec4[float32]] | |
340 of Vec4F64: result.vec4f64 = new seq[TVec4[float64]] | |
341 of Mat2F32: result.mat2f32 = new seq[TMat2[float32]] | |
342 of Mat2F64: result.mat2f64 = new seq[TMat2[float64]] | |
343 of Mat23F32: result.mat23f32 = new seq[TMat23[float32]] | |
344 of Mat23F64: result.mat23f64 = new seq[TMat23[float64]] | |
345 of Mat32F32: result.mat32f32 = new seq[TMat32[float32]] | |
346 of Mat32F64: result.mat32f64 = new seq[TMat32[float64]] | |
347 of Mat3F32: result.mat3f32 = new seq[TMat3[float32]] | |
348 of Mat3F64: result.mat3f64 = new seq[TMat3[float64]] | |
349 of Mat34F32: result.mat34f32 = new seq[TMat34[float32]] | |
350 of Mat34F64: result.mat34f64 = new seq[TMat34[float64]] | |
351 of Mat43F32: result.mat43f32 = new seq[TMat43[float32]] | |
352 of Mat43F64: result.mat43f64 = new seq[TMat43[float64]] | |
353 of Mat4F32: result.mat4f32 = new seq[TMat4[float32]] | |
354 of Mat4F64: result.mat4f64 = new seq[TMat4[float64]] | |
355 of TextureType: result.texture = new seq[Texture] | |
356 result.SetLen(len) | |
357 | |
358 proc InitDataList*[T: GPUType](len = 1): DataList = | |
359 result = InitDataList(GetDataType[T]()) | |
360 result.SetLen(len) | |
361 | |
362 proc InitDataList*[T: GPUType](data: openArray[T]): DataList = | |
363 result = InitDataList(GetDataType[T]()) | |
364 result.setValues(@data) | |
365 | |
366 func getValues[T: GPUType|int|uint|float](value: DataList): ref seq[T] = | |
367 when T is float32: value.float32 | |
368 elif T is float64: value.float64 | |
369 elif T is int8: value.int8 | |
370 elif T is int16: value.int16 | |
371 elif T is int32: value.int32 | |
372 elif T is int64: value.int64 | |
373 elif T is uint8: value.uint8 | |
374 elif T is uint16: value.uint16 | |
375 elif T is uint32: value.uint32 | |
376 elif T is uint64: value.uint64 | |
377 elif T is int and sizeof(int) == sizeof(int32): value.int32 | |
378 elif T is int and sizeof(int) == sizeof(int64): value.int64 | |
379 elif T is uint and sizeof(uint) == sizeof(uint32): value.uint32 | |
380 elif T is uint and sizeof(uint) == sizeof(uint64): value.uint64 | |
381 elif T is float and sizeof(float) == sizeof(float32): value.float32 | |
382 elif T is float and sizeof(float) == sizeof(float64): value.float64 | |
383 elif T is TVec2[int32]: value.vec2i32 | |
384 elif T is TVec2[int64]: value.vec2i64 | |
385 elif T is TVec3[int32]: value.vec3i32 | |
386 elif T is TVec3[int64]: value.vec3i64 | |
387 elif T is TVec4[int32]: value.vec4i32 | |
388 elif T is TVec4[int64]: value.vec4i64 | |
389 elif T is TVec2[uint32]: value.vec2u32 | |
390 elif T is TVec2[uint64]: value.vec2u64 | |
391 elif T is TVec3[uint32]: value.vec3u32 | |
392 elif T is TVec3[uint64]: value.vec3u64 | |
393 elif T is TVec4[uint32]: value.vec4u32 | |
394 elif T is TVec4[uint64]: value.vec4u64 | |
395 elif T is TVec2[float32]: value.vec2f32 | |
396 elif T is TVec2[float64]: value.vec2f64 | |
397 elif T is TVec3[float32]: value.vec3f32 | |
398 elif T is TVec3[float64]: value.vec3f64 | |
399 elif T is TVec4[float32]: value.vec4f32 | |
400 elif T is TVec4[float64]: value.vec4f64 | |
401 elif T is TMat2[float32]: value.mat2f32 | |
402 elif T is TMat2[float64]: value.mat2f64 | |
403 elif T is TMat23[float32]: value.mat23f | |
404 elif T is TMat23[float64]: value.mat23f64 | |
405 elif T is TMat32[float32]: value.mat32f32 | |
406 elif T is TMat32[float64]: value.mat32f64 | |
407 elif T is TMat3[float32]: value.mat3f32 | |
408 elif T is TMat3[float64]: value.mat3f64 | |
409 elif T is TMat34[float32]: value.mat34f32 | |
410 elif T is TMat34[float64]: value.mat34f64 | |
411 elif T is TMat43[float32]: value.mat43f32 | |
412 elif T is TMat43[float64]: value.mat43f64 | |
413 elif T is TMat4[float32]: value.mat4f32 | |
414 elif T is TMat4[float64]: value.mat4f64 | |
415 elif T is Texture: value.texture | |
416 else: {.error: "Virtual datatype has no values".} | |
417 | |
418 func getValue[T: GPUType|int|uint|float](value: DataList, i: int): T = | |
419 when T is float32: value.float32[i] | |
420 elif T is float64: value.float64[i] | |
421 elif T is int8: value.int8[i] | |
422 elif T is int16: value.int16[i] | |
423 elif T is int32: value.int32[i] | |
424 elif T is int64: value.int64[i] | |
425 elif T is uint8: value.uint8[i] | |
426 elif T is uint16: value.uint16[i] | |
427 elif T is uint32: value.uint32[i] | |
428 elif T is uint64: value.uint64[i] | |
429 elif T is int and sizeof(int) == sizeof(int32): value.int32[i] | |
430 elif T is int and sizeof(int) == sizeof(int64): value.int64[i] | |
431 elif T is uint and sizeof(uint) == sizeof(uint32): value.uint32[i] | |
432 elif T is uint and sizeof(uint) == sizeof(uint64): value.uint64[i] | |
433 elif T is float and sizeof(float) == sizeof(float32): value.float32[i] | |
434 elif T is float and sizeof(float) == sizeof(float64): value.float64[i] | |
435 elif T is TVec2[int32]: value.vec2i32[i] | |
436 elif T is TVec2[int64]: value.vec2i64[i] | |
437 elif T is TVec3[int32]: value.vec3i32[i] | |
438 elif T is TVec3[int64]: value.vec3i64[i] | |
439 elif T is TVec4[int32]: value.vec4i32[i] | |
440 elif T is TVec4[int64]: value.vec4i64[i] | |
441 elif T is TVec2[uint32]: value.vec2u32[i] | |
442 elif T is TVec2[uint64]: value.vec2u64[i] | |
443 elif T is TVec3[uint32]: value.vec3u32[i] | |
444 elif T is TVec3[uint64]: value.vec3u64[i] | |
445 elif T is TVec4[uint32]: value.vec4u32[i] | |
446 elif T is TVec4[uint64]: value.vec4u64[i] | |
447 elif T is TVec2[float32]: value.vec2f32[i] | |
448 elif T is TVec2[float64]: value.vec2f64[i] | |
449 elif T is TVec3[float32]: value.vec3f32[i] | |
450 elif T is TVec3[float64]: value.vec3f64[i] | |
451 elif T is TVec4[float32]: value.vec4f32[i] | |
452 elif T is TVec4[float64]: value.vec4f64[i] | |
453 elif T is TMat2[float32]: value.mat2f32[i] | |
454 elif T is TMat2[float64]: value.mat2f64[i] | |
455 elif T is TMat23[float32]: value.mat23f[i] | |
456 elif T is TMat23[float64]: value.mat23f64[i] | |
457 elif T is TMat32[float32]: value.mat32f32[i] | |
458 elif T is TMat32[float64]: value.mat32f64[i] | |
459 elif T is TMat3[float32]: value.mat3f32[i] | |
460 elif T is TMat3[float64]: value.mat3f64[i] | |
461 elif T is TMat34[float32]: value.mat34f32[i] | |
462 elif T is TMat34[float64]: value.mat34f64[i] | |
463 elif T is TMat43[float32]: value.mat43f32[i] | |
464 elif T is TMat43[float64]: value.mat43f64[i] | |
465 elif T is TMat4[float32]: value.mat4f32[i] | |
466 elif T is TMat4[float64]: value.mat4f64[i] | |
467 elif T is Texture: value.texture[i] | |
468 else: {.error: "Virtual datatype has no values".} | |
469 | |
470 template `[]`*(list: DataList, t: typedesc): ref seq[t] = | |
471 getValues[t](list) | |
472 template `[]`*(list: DataList, i: int, t: typedesc): untyped = | |
473 getValue[t](list, i) | |
474 | |
475 # since we use this often with tables, add this for an easy assignment | |
476 template `[]`*(table: Table[string, DataList], key: string, t: typedesc): ref seq[t] = | |
477 getValues[t](table[key]) | |
478 template `[]=`*[T](table: var Table[string, DataList], key: string, values: openArray[T]) = | |
479 if table.contains(key): | |
480 table[key].setValues(values) | |
481 else: | |
482 table[key] = InitDataList(values) | |
483 | |
484 template `[]=`*[T](list: var DataList, values: openArray[T]) = | |
485 list.setValues(values) | |
486 template `[]=`*[T](list: var DataList, i: int, value: T) = | |
487 list.setValue(i, value) | |
488 | |
489 func GetPointer*(value: var DataList): pointer = | |
490 if value.len == 0: | |
491 result = nil | |
492 case value.theType | |
493 of Float32: result = value.float32[].ToCPointer | |
494 of Float64: result = value.float64[].ToCPointer | |
495 of Int8: result = value.int8[].ToCPointer | |
496 of Int16: result = value.int16[].ToCPointer | |
497 of Int32: result = value.int32[].ToCPointer | |
498 of Int64: result = value.int64[].ToCPointer | |
499 of UInt8: result = value.uint8[].ToCPointer | |
500 of UInt16: result = value.uint16[].ToCPointer | |
501 of UInt32: result = value.uint32[].ToCPointer | |
502 of UInt64: result = value.uint64[].ToCPointer | |
503 of Vec2I32: result = value.vec2i32[].ToCPointer | |
504 of Vec2I64: result = value.vec2i64[].ToCPointer | |
505 of Vec3I32: result = value.vec3i32[].ToCPointer | |
506 of Vec3I64: result = value.vec3i64[].ToCPointer | |
507 of Vec4I32: result = value.vec4i32[].ToCPointer | |
508 of Vec4I64: result = value.vec4i64[].ToCPointer | |
509 of Vec2U32: result = value.vec2u32[].ToCPointer | |
510 of Vec2U64: result = value.vec2u64[].ToCPointer | |
511 of Vec3U32: result = value.vec3u32[].ToCPointer | |
512 of Vec3U64: result = value.vec3u64[].ToCPointer | |
513 of Vec4U32: result = value.vec4u32[].ToCPointer | |
514 of Vec4U64: result = value.vec4u64[].ToCPointer | |
515 of Vec2F32: result = value.vec2f32[].ToCPointer | |
516 of Vec2F64: result = value.vec2f64[].ToCPointer | |
517 of Vec3F32: result = value.vec3f32[].ToCPointer | |
518 of Vec3F64: result = value.vec3f64[].ToCPointer | |
519 of Vec4F32: result = value.vec4f32[].ToCPointer | |
520 of Vec4F64: result = value.vec4f64[].ToCPointer | |
521 of Mat2F32: result = value.mat2f32[].ToCPointer | |
522 of Mat2F64: result = value.mat2f64[].ToCPointer | |
523 of Mat23F32: result = value.mat23f32[].ToCPointer | |
524 of Mat23F64: result = value.mat23f64[].ToCPointer | |
525 of Mat32F32: result = value.mat32f32[].ToCPointer | |
526 of Mat32F64: result = value.mat32f64[].ToCPointer | |
527 of Mat3F32: result = value.mat3f32[].ToCPointer | |
528 of Mat3F64: result = value.mat3f64[].ToCPointer | |
529 of Mat34F32: result = value.mat34f32[].ToCPointer | |
530 of Mat34F64: result = value.mat34f64[].ToCPointer | |
531 of Mat43F32: result = value.mat43f32[].ToCPointer | |
532 of Mat43F64: result = value.mat43f64[].ToCPointer | |
533 of Mat4F32: result = value.mat4f32[].ToCPointer | |
534 of Mat4F64: result = value.mat4f64[].ToCPointer | |
535 of TextureType: nil | |
536 | |
537 proc AppendValues*[T: GPUType|int|uint|float](value: var DataList, data: openArray[T]) = | |
538 value.len += data.len | |
539 when T is float32: value.float32[].add @data | |
540 elif T is float64: value.float64[].add @data | |
541 elif T is int8: value.int8[].add @data | |
542 elif T is int16: value.int16[].add @data | |
543 elif T is int32: value.int32[].add @data | |
544 elif T is int64: value.int64[].add @data | |
545 elif T is uint8: value.uint8[].add @data | |
546 elif T is uint16: value.uint16[].add @data | |
547 elif T is uint32: value.uint32[].add @data | |
548 elif T is uint64: value.uint64[].add @data | |
549 elif T is int and sizeof(int) == sizeof(int32): value.int32[].add @data | |
550 elif T is int and sizeof(int) == sizeof(int64): value.int64[].add @data | |
551 elif T is uint and sizeof(uint) == sizeof(uint32): value.uint32[].add @data | |
552 elif T is uint and sizeof(uint) == sizeof(uint64): value.uint64[].add @data | |
553 elif T is float and sizeof(float) == sizeof(float32): value.float32[].add @data | |
554 elif T is float and sizeof(float) == sizeof(float64): value.float64[].add @data | |
555 elif T is TVec2[int32]: value.vec2i32[].add @data | |
556 elif T is TVec2[int64]: value.vec2i64[].add @data | |
557 elif T is TVec3[int32]: value.vec3i32[].add @data | |
558 elif T is TVec3[int64]: value.vec3i64[].add @data | |
559 elif T is TVec4[int32]: value.vec4i32[].add @data | |
560 elif T is TVec4[int64]: value.vec4i64[].add @data | |
561 elif T is TVec2[uint32]: value.vec2u32[].add @data | |
562 elif T is TVec2[uint64]: value.vec2u64[].add @data | |
563 elif T is TVec3[uint32]: value.vec3u32[].add @data | |
564 elif T is TVec3[uint64]: value.vec3u64[].add @data | |
565 elif T is TVec4[uint32]: value.vec4u32[].add @data | |
566 elif T is TVec4[uint64]: value.vec4u64[].add @data | |
567 elif T is TVec2[float32]: value.vec2f32[].add @data | |
568 elif T is TVec2[float64]: value.vec2f64[].add @data | |
569 elif T is TVec3[float32]: value.vec3f32[].add @data | |
570 elif T is TVec3[float64]: value.vec3f64[].add @data | |
571 elif T is TVec4[float32]: value.vec4f32[].add @data | |
572 elif T is TVec4[float64]: value.vec4f64[].add @data | |
573 elif T is TMat2[float32]: value.mat2f32[].add @data | |
574 elif T is TMat2[float64]: value.mat2f64[].add @data | |
575 elif T is TMat23[float32]: value.mat23f32[].add @data | |
576 elif T is TMat23[float64]: value.mat23f64[].add @data | |
577 elif T is TMat32[float32]: value.mat32f32[].add @data | |
578 elif T is TMat32[float64]: value.mat32f64[].add @data | |
579 elif T is TMat3[float32]: value.mat3f32[].add @data | |
580 elif T is TMat3[float64]: value.mat3f64[].add @data | |
581 elif T is TMat34[float32]: value.mat34f32[].add @data | |
582 elif T is TMat34[float64]: value.mat34f64[].add @data | |
583 elif T is TMat43[float32]: value.mat43f32[].add @data | |
584 elif T is TMat43[float64]: value.mat43f64[].add @data | |
585 elif T is TMat4[float32]: value.mat4f32[].add @data | |
586 elif T is TMat4[float64]: value.mat4f64[].add @data | |
587 elif T is Texture: value.texture[].add @data | |
588 else: {.error: "Virtual datatype has no values".} | |
589 | |
590 proc AppendValues*(value: var DataList, data: DataList) = | |
591 assert value.theType == data.theType, &"Expected datalist of type {value.theType} but got {data.theType}" | |
592 value.len += data.len | |
593 case value.theType: | |
594 of Float32: value.float32[].add data.float32[] | |
595 of Float64: value.float64[].add data.float64[] | |
596 of Int8: value.int8[].add data.int8[] | |
597 of Int16: value.int16[].add data.int16[] | |
598 of Int32: value.int32[].add data.int32[] | |
599 of Int64: value.int64[].add data.int64[] | |
600 of UInt8: value.uint8[].add data.uint8[] | |
601 of UInt16: value.uint16[].add data.uint16[] | |
602 of UInt32: value.uint32[].add data.uint32[] | |
603 of UInt64: value.uint64[].add data.uint64[] | |
604 of Vec2I32: value.vec2i32[].add data.vec2i32[] | |
605 of Vec2I64: value.vec2i64[].add data.vec2i64[] | |
606 of Vec3I32: value.vec3i32[].add data.vec3i32[] | |
607 of Vec3I64: value.vec3i64[].add data.vec3i64[] | |
608 of Vec4I32: value.vec4i32[].add data.vec4i32[] | |
609 of Vec4I64: value.vec4i64[].add data.vec4i64[] | |
610 of Vec2U32: value.vec2u32[].add data.vec2u32[] | |
611 of Vec2U64: value.vec2u64[].add data.vec2u64[] | |
612 of Vec3U32: value.vec3u32[].add data.vec3u32[] | |
613 of Vec3U64: value.vec3u64[].add data.vec3u64[] | |
614 of Vec4U32: value.vec4u32[].add data.vec4u32[] | |
615 of Vec4U64: value.vec4u64[].add data.vec4u64[] | |
616 of Vec2F32: value.vec2f32[].add data.vec2f32[] | |
617 of Vec2F64: value.vec2f64[].add data.vec2f64[] | |
618 of Vec3F32: value.vec3f32[].add data.vec3f32[] | |
619 of Vec3F64: value.vec3f64[].add data.vec3f64[] | |
620 of Vec4F32: value.vec4f32[].add data.vec4f32[] | |
621 of Vec4F64: value.vec4f64[].add data.vec4f64[] | |
622 of Mat2F32: value.mat2f32[].add data.mat2f32[] | |
623 of Mat2F64: value.mat2f64[].add data.mat2f64[] | |
624 of Mat23F32: value.mat23f32[].add data.mat23f32[] | |
625 of Mat23F64: value.mat23f64[].add data.mat23f64[] | |
626 of Mat32F32: value.mat32f32[].add data.mat32f32[] | |
627 of Mat32F64: value.mat32f64[].add data.mat32f64[] | |
628 of Mat3F32: value.mat3f32[].add data.mat3f32[] | |
629 of Mat3F64: value.mat3f64[].add data.mat3f64[] | |
630 of Mat34F32: value.mat34f32[].add data.mat34f32[] | |
631 of Mat34F64: value.mat34f64[].add data.mat34f64[] | |
632 of Mat43F32: value.mat43f32[].add data.mat43f32[] | |
633 of Mat43F64: value.mat43f64[].add data.mat43f64[] | |
634 of Mat4F32: value.mat4f32[].add data.mat4f32[] | |
635 of Mat4F64: value.mat4f64[].add data.mat4f64[] | |
636 of TextureType: value.texture[].add data.texture[] | |
637 | |
638 proc AppendFrom*(a: var DataList, i: int, b: DataList, j: int) = | |
639 assert a.theType == b.theType | |
640 case a.theType | |
641 of Float32: a.float32[i] = b.float32[j] | |
642 of Float64: a.float64[i] = b.float64[j] | |
643 of Int8: a.int8[i] = b.int8[j] | |
644 of Int16: a.int16[i] = b.int16[j] | |
645 of Int32: a.int32[i] = b.int32[j] | |
646 of Int64: a.int64[i] = b.int64[j] | |
647 of UInt8: a.uint8[i] = b.uint8[j] | |
648 of UInt16: a.uint16[i] = b.uint16[j] | |
649 of UInt32: a.uint32[i] = b.uint32[j] | |
650 of UInt64: a.uint64[i] = b.uint64[j] | |
651 of Vec2I32: a.vec2i32[i] = b.vec2i32[j] | |
652 of Vec2I64: a.vec2i64[i] = b.vec2i64[j] | |
653 of Vec3I32: a.vec3i32[i] = b.vec3i32[j] | |
654 of Vec3I64: a.vec3i64[i] = b.vec3i64[j] | |
655 of Vec4I32: a.vec4i32[i] = b.vec4i32[j] | |
656 of Vec4I64: a.vec4i64[i] = b.vec4i64[j] | |
657 of Vec2U32: a.vec2u32[i] = b.vec2u32[j] | |
658 of Vec2U64: a.vec2u64[i] = b.vec2u64[j] | |
659 of Vec3U32: a.vec3u32[i] = b.vec3u32[j] | |
660 of Vec3U64: a.vec3u64[i] = b.vec3u64[j] | |
661 of Vec4U32: a.vec4u32[i] = b.vec4u32[j] | |
662 of Vec4U64: a.vec4u64[i] = b.vec4u64[j] | |
663 of Vec2F32: a.vec2f32[i] = b.vec2f32[j] | |
664 of Vec2F64: a.vec2f64[i] = b.vec2f64[j] | |
665 of Vec3F32: a.vec3f32[i] = b.vec3f32[j] | |
666 of Vec3F64: a.vec3f64[i] = b.vec3f64[j] | |
667 of Vec4F32: a.vec4f32[i] = b.vec4f32[j] | |
668 of Vec4F64: a.vec4f64[i] = b.vec4f64[j] | |
669 of Mat2F32: a.mat2f32[i] = b.mat2f32[j] | |
670 of Mat2F64: a.mat2f64[i] = b.mat2f64[j] | |
671 of Mat23F32: a.mat23f32[i] = b.mat23f32[j] | |
672 of Mat23F64: a.mat23f64[i] = b.mat23f64[j] | |
673 of Mat32F32: a.mat32f32[i] = b.mat32f32[j] | |
674 of Mat32F64: a.mat32f64[i] = b.mat32f64[j] | |
675 of Mat3F32: a.mat3f32[i] = b.mat3f32[j] | |
676 of Mat3F64: a.mat3f64[i] = b.mat3f64[j] | |
677 of Mat34F32: a.mat34f32[i] = b.mat34f32[j] | |
678 of Mat34F64: a.mat34f64[i] = b.mat34f64[j] | |
679 of Mat43F32: a.mat43f32[i] = b.mat43f32[j] | |
680 of Mat43F64: a.mat43f64[i] = b.mat43f64[j] | |
681 of Mat4F32: a.mat4f32[i] = b.mat4f32[j] | |
682 of Mat4F64: a.mat4f64[i] = b.mat4f64[j] | |
683 of TextureType: a.texture[i] = b.texture[j] | |
684 | |
685 proc Copy*(datalist: DataList): DataList = | |
686 result = InitDataList(datalist.theType) | |
687 result.AppendValues(datalist) | |
688 | |
689 func `$`*(list: DataList): string = | |
690 case list.theType | |
691 of Float32: $list.float32[] | |
692 of Float64: $list.float64[] | |
693 of Int8: $list.int8[] | |
694 of Int16: $list.int16[] | |
695 of Int32: $list.int32[] | |
696 of Int64: $list.int64[] | |
697 of UInt8: $list.uint8[] | |
698 of UInt16: $list.uint16[] | |
699 of UInt32: $list.uint32[] | |
700 of UInt64: $list.uint64[] | |
701 of Vec2I32: $list.vec2i32[] | |
702 of Vec2I64: $list.vec2i64[] | |
703 of Vec3I32: $list.vec3i32[] | |
704 of Vec3I64: $list.vec3i64[] | |
705 of Vec4I32: $list.vec4i32[] | |
706 of Vec4I64: $list.vec4i64[] | |
707 of Vec2U32: $list.vec2u32[] | |
708 of Vec2U64: $list.vec2u64[] | |
709 of Vec3U32: $list.vec3u32[] | |
710 of Vec3U64: $list.vec3u64[] | |
711 of Vec4U32: $list.vec4u32[] | |
712 of Vec4U64: $list.vec4u64[] | |
713 of Vec2F32: $list.vec2f32[] | |
714 of Vec2F64: $list.vec2f64[] | |
715 of Vec3F32: $list.vec3f32[] | |
716 of Vec3F64: $list.vec3f64[] | |
717 of Vec4F32: $list.vec4f32[] | |
718 of Vec4F64: $list.vec4f64[] | |
719 of Mat2F32: $list.mat2f32[] | |
720 of Mat2F64: $list.mat2f64[] | |
721 of Mat23F32: $list.mat23f32[] | |
722 of Mat23F64: $list.mat23f64[] | |
723 of Mat32F32: $list.mat32f32[] | |
724 of Mat32F64: $list.mat32f64[] | |
725 of Mat3F32: $list.mat3f32[] | |
726 of Mat3F64: $list.mat3f64[] | |
727 of Mat34F32: $list.mat34f32[] | |
728 of Mat34F64: $list.mat34f64[] | |
729 of Mat43F32: $list.mat43f32[] | |
730 of Mat43F64: $list.mat43f64[] | |
731 of Mat4F32: $list.mat4f32[] | |
732 of Mat4F64: $list.mat4f64[] | |
733 of TextureType: $list.texture[] |