diff src/semicongine/core/gpu_data.nim @ 225:d078b19bf531

fix: a ton of bug after refactoring gpu_data, start to add ideas for materials
author Sam <sam@basx.dev>
date Mon, 15 May 2023 18:24:52 +0700
parents 634c302869d5
children 297bffdf3d94
line wrap: on
line diff
--- a/src/semicongine/core/gpu_data.nim	Mon May 15 14:25:04 2023 +0700
+++ b/src/semicongine/core/gpu_data.nim	Mon May 15 18:24:52 2023 +0700
@@ -349,6 +349,58 @@
   elif T is TMat4[float64]: value.mat4f64
   else: {.error: "Virtual datatype has no value" .}
 
+func setValues*[T: GPUType|int|uint|float](value: var DataList, data: seq[T]) =
+  value.len = uint32(data.len)
+  when T is float32: value.float32[] = data
+  elif T is float64: value.float64[] = data
+  elif T is int8: value.int8[] = data
+  elif T is int16: value.int16[] = data
+  elif T is int32: value.int32[] = data
+  elif T is int64: value.int64[] = data
+  elif T is uint8: value.uint8[] = data
+  elif T is uint16: value.uint16[] = data
+  elif T is uint32: value.uint32[] = data
+  elif T is uint64: value.uint64[] = data
+  elif T is int and sizeof(int) == sizeof(int32): value.int32[] = data
+  elif T is int and sizeof(int) == sizeof(int64): value.int64[] = data
+  elif T is uint and sizeof(uint) == sizeof(uint32): value.uint32[] = data
+  elif T is uint and sizeof(uint) == sizeof(uint64): value.uint64[] = data
+  elif T is float and sizeof(float) == sizeof(float32): value.float32[] = data
+  elif T is float and sizeof(float) == sizeof(float64): value.float64[] = data
+  elif T is TVec2[int32]: value.vec2i32[] = data
+  elif T is TVec2[int64]: value.vec2i64[] = data
+  elif T is TVec3[int32]: value.vec3i32[] = data
+  elif T is TVec3[int64]: value.vec3i64[] = data
+  elif T is TVec4[int32]: value.vec4i32[] = data
+  elif T is TVec4[int64]: value.vec4i64[] = data
+  elif T is TVec2[uint32]: value.vec2u32[] = data
+  elif T is TVec2[uint64]: value.vec2u64[] = data
+  elif T is TVec3[uint32]: value.vec3u32[] = data
+  elif T is TVec3[uint64]: value.vec3u64[] = data
+  elif T is TVec4[uint32]: value.vec4u32[] = data
+  elif T is TVec4[uint64]: value.vec4u64[] = data
+  elif T is TVec2[float32]: value.vec2f32[] = data
+  elif T is TVec2[float64]: value.vec2f64[] = data
+  elif T is TVec3[float32]: value.vec3f32[] = data
+  elif T is TVec3[float64]: value.vec3f64[] = data
+  elif T is TVec4[float32]: value.vec4f32[] = data
+  elif T is TVec4[float64]: value.vec4f64[] = data
+  elif T is TMat2[float32]: value.mat2f32[] = data
+  elif T is TMat2[float64]: value.mat2f64[] = data
+  elif T is TMat23[float32]: value.mat23f32[] = data
+  elif T is TMat23[float64]: value.mat23f64[] = data
+  elif T is TMat32[float32]: value.mat32f32[] = data
+  elif T is TMat32[float64]: value.mat32f64[] = data
+  elif T is TMat3[float32]: value.mat3f32[] = data
+  elif T is TMat3[float64]: value.mat3f64[] = data
+  elif T is TMat34[float32]: value.mat34f32[] = data
+  elif T is TMat34[float64]: value.mat34f64[] = data
+  elif T is TMat43[float32]: value.mat43f32[] = data
+  elif T is TMat43[float64]: value.mat43f64[] = data
+  elif T is TMat4[float32]: value.mat4f32[] = data
+  elif T is TMat4[float64]: value.mat4f64[] = data
+  else: {. error: "Virtual datatype has no values" .}
+
 func newDataList*(thetype: DataType): DataList =
   result = DataList(thetype: thetype)
   case result.thetype
@@ -403,8 +455,7 @@
 
 func newDataList*[T: GPUType](data: seq[T]): DataList =
   result = newDataList(getDataType[T]())
-  result.setValues[T](data)
-
+  setValues[T](result, data)
 
 func getValues*[T: GPUType|int|uint|float](value: DataList): ref seq[T] =
   when T is float32: value.float32
@@ -651,58 +702,6 @@
   elif T is TMat4[float64]: value.mat4f64 = data
   else: {.error: "Virtual datatype has no value" .}
 
-func setValues*[T: GPUType|int|uint|float](value: var DataList, data: seq[T]) =
-  value.len = uint32(data.len)
-  when T is float32: value.float32[] = data
-  elif T is float64: value.float64[] = data
-  elif T is int8: value.int8[] = data
-  elif T is int16: value.int16[] = data
-  elif T is int32: value.int32[] = data
-  elif T is int64: value.int64[] = data
-  elif T is uint8: value.uint8[] = data
-  elif T is uint16: value.uint16[] = data
-  elif T is uint32: value.uint32[] = data
-  elif T is uint64: value.uint64[] = data
-  elif T is int and sizeof(int) == sizeof(int32): value.int32[] = data
-  elif T is int and sizeof(int) == sizeof(int64): value.int64[] = data
-  elif T is uint and sizeof(uint) == sizeof(uint32): value.uint32[] = data
-  elif T is uint and sizeof(uint) == sizeof(uint64): value.uint64[] = data
-  elif T is float and sizeof(float) == sizeof(float32): value.float32[] = data
-  elif T is float and sizeof(float) == sizeof(float64): value.float64[] = data
-  elif T is TVec2[int32]: value.vec2i32[] = data
-  elif T is TVec2[int64]: value.vec2i64[] = data
-  elif T is TVec3[int32]: value.vec3i32[] = data
-  elif T is TVec3[int64]: value.vec3i64[] = data
-  elif T is TVec4[int32]: value.vec4i32[] = data
-  elif T is TVec4[int64]: value.vec4i64[] = data
-  elif T is TVec2[uint32]: value.vec2u32[] = data
-  elif T is TVec2[uint64]: value.vec2u64[] = data
-  elif T is TVec3[uint32]: value.vec3u32[] = data
-  elif T is TVec3[uint64]: value.vec3u64[] = data
-  elif T is TVec4[uint32]: value.vec4u32[] = data
-  elif T is TVec4[uint64]: value.vec4u64[] = data
-  elif T is TVec2[float32]: value.vec2f32[] = data
-  elif T is TVec2[float64]: value.vec2f64[] = data
-  elif T is TVec3[float32]: value.vec3f32[] = data
-  elif T is TVec3[float64]: value.vec3f64[] = data
-  elif T is TVec4[float32]: value.vec4f32[] = data
-  elif T is TVec4[float64]: value.vec4f64[] = data
-  elif T is TMat2[float32]: value.mat2f32[] = data
-  elif T is TMat2[float64]: value.mat2f64[] = data
-  elif T is TMat23[float32]: value.mat23f32[] = data
-  elif T is TMat23[float64]: value.mat23f64[] = data
-  elif T is TMat32[float32]: value.mat32f32[] = data
-  elif T is TMat32[float64]: value.mat32f64[] = data
-  elif T is TMat3[float32]: value.mat3f32[] = data
-  elif T is TMat3[float64]: value.mat3f64[] = data
-  elif T is TMat34[float32]: value.mat34f32[] = data
-  elif T is TMat34[float64]: value.mat34f64[] = data
-  elif T is TMat43[float32]: value.mat43f32[] = data
-  elif T is TMat43[float64]: value.mat43f64[] = data
-  elif T is TMat4[float32]: value.mat4f32[] = data
-  elif T is TMat4[float64]: value.mat4f64[] = data
-  else: {. error: "Virtual datatype has no values" .}
-
 func appendValues*[T: GPUType|int|uint|float](value: var DataList, data: seq[T]) =
   value.len += data.len
   when T is float32: value.float32[].add data