# HG changeset patch # User Sam # Date 1694106319 -25200 # Node ID 73de86a9ec0a8e6ce5a1ad689ce06edb5b2ddc8c # Parent 668eed376029e4f0185f656c2b032f58c2ea43d9 did: try to reduce seq copying... diff -r 668eed376029 -r 73de86a9ec0a src/semicongine/core/gpu_data.nim --- a/src/semicongine/core/gpu_data.nim Thu Sep 07 23:28:36 2023 +0700 +++ b/src/semicongine/core/gpu_data.nim Fri Sep 08 00:05:19 2023 +0700 @@ -102,49 +102,49 @@ DataList* = object len*: int case theType*: DataType - of Float32: float32: seq[float32] - of Float64: float64: seq[float64] - of Int8: int8: seq[int8] - of Int16: int16: seq[int16] - of Int32: int32: seq[int32] - of Int64: int64: seq[int64] - of UInt8: uint8: seq[uint8] - of UInt16: uint16: seq[uint16] - of UInt32: uint32: seq[uint32] - of UInt64: uint64: seq[uint64] - of Vec2I32: vec2i32: seq[TVec2[int32]] - of Vec2I64: vec2i64: seq[TVec2[int64]] - of Vec3I32: vec3i32: seq[TVec3[int32]] - of Vec3I64: vec3i64: seq[TVec3[int64]] - of Vec4I32: vec4i32: seq[TVec4[int32]] - of Vec4I64: vec4i64: seq[TVec4[int64]] - of Vec2U32: vec2u32: seq[TVec2[uint32]] - of Vec2U64: vec2u64: seq[TVec2[uint64]] - of Vec3U32: vec3u32: seq[TVec3[uint32]] - of Vec3U64: vec3u64: seq[TVec3[uint64]] - of Vec4U32: vec4u32: seq[TVec4[uint32]] - of Vec4U64: vec4u64: seq[TVec4[uint64]] - of Vec2F32: vec2f32: seq[TVec2[float32]] - of Vec2F64: vec2f64: seq[TVec2[float64]] - of Vec3F32: vec3f32: seq[TVec3[float32]] - of Vec3F64: vec3f64: seq[TVec3[float64]] - of Vec4F32: vec4f32: seq[TVec4[float32]] - of Vec4F64: vec4f64: seq[TVec4[float64]] - of Mat2F32: mat2f32: seq[TMat2[float32]] - of Mat2F64: mat2f64: seq[TMat2[float64]] - of Mat23F32: mat23f32: seq[TMat23[float32]] - of Mat23F64: mat23f64: seq[TMat23[float64]] - of Mat32F32: mat32f32: seq[TMat32[float32]] - of Mat32F64: mat32f64: seq[TMat32[float64]] - of Mat3F32: mat3f32: seq[TMat3[float32]] - of Mat3F64: mat3f64: seq[TMat3[float64]] - of Mat34F32: mat34f32: seq[TMat34[float32]] - of Mat34F64: mat34f64: seq[TMat34[float64]] - of Mat43F32: mat43f32: seq[TMat43[float32]] - of Mat43F64: mat43f64: seq[TMat43[float64]] - of Mat4F32: mat4f32: seq[TMat4[float32]] - of Mat4F64: mat4f64: seq[TMat4[float64]] - of Sampler2D: texture: seq[Texture] + of Float32: float32: ref seq[float32] + of Float64: float64: ref seq[float64] + of Int8: int8: ref seq[int8] + of Int16: int16: ref seq[int16] + of Int32: int32: ref seq[int32] + of Int64: int64: ref seq[int64] + of UInt8: uint8: ref seq[uint8] + of UInt16: uint16: ref seq[uint16] + of UInt32: uint32: ref seq[uint32] + of UInt64: uint64: ref seq[uint64] + of Vec2I32: vec2i32: ref seq[TVec2[int32]] + of Vec2I64: vec2i64: ref seq[TVec2[int64]] + of Vec3I32: vec3i32: ref seq[TVec3[int32]] + of Vec3I64: vec3i64: ref seq[TVec3[int64]] + of Vec4I32: vec4i32: ref seq[TVec4[int32]] + of Vec4I64: vec4i64: ref seq[TVec4[int64]] + of Vec2U32: vec2u32: ref seq[TVec2[uint32]] + of Vec2U64: vec2u64: ref seq[TVec2[uint64]] + of Vec3U32: vec3u32: ref seq[TVec3[uint32]] + of Vec3U64: vec3u64: ref seq[TVec3[uint64]] + of Vec4U32: vec4u32: ref seq[TVec4[uint32]] + of Vec4U64: vec4u64: ref seq[TVec4[uint64]] + of Vec2F32: vec2f32: ref seq[TVec2[float32]] + of Vec2F64: vec2f64: ref seq[TVec2[float64]] + of Vec3F32: vec3f32: ref seq[TVec3[float32]] + of Vec3F64: vec3f64: ref seq[TVec3[float64]] + of Vec4F32: vec4f32: ref seq[TVec4[float32]] + of Vec4F64: vec4f64: ref seq[TVec4[float64]] + of Mat2F32: mat2f32: ref seq[TMat2[float32]] + of Mat2F64: mat2f64: ref seq[TMat2[float64]] + of Mat23F32: mat23f32: ref seq[TMat23[float32]] + of Mat23F64: mat23f64: ref seq[TMat23[float64]] + of Mat32F32: mat32f32: ref seq[TMat32[float32]] + of Mat32F64: mat32f64: ref seq[TMat32[float64]] + of Mat3F32: mat3f32: ref seq[TMat3[float32]] + of Mat3F64: mat3f64: ref seq[TMat3[float64]] + of Mat34F32: mat34f32: ref seq[TMat34[float32]] + of Mat34F64: mat34f64: ref seq[TMat34[float64]] + of Mat43F32: mat43f32: ref seq[TMat43[float32]] + of Mat43F64: mat43f64: ref seq[TMat43[float64]] + of Mat4F32: mat4f32: ref seq[TMat4[float32]] + of Mat4F64: mat4f64: ref seq[TMat4[float64]] + of Sampler2D: texture: ref seq[Texture] MemoryPerformanceHint* = enum PreferFastRead, PreferFastWrite ShaderAttribute* = object @@ -407,104 +407,104 @@ elif T is Texture: value.texture else: {.error: "Virtual datatype has no value" .} -func setValues*[T: GPUType|int|uint|float](value: var DataList, data: seq[T]) = +proc setValues*[T: GPUType|int|uint|float](value: var DataList, data: seq[T]) = value.len = 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 - elif T is Texture: value.texture = data + 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 + elif T is Texture: value.texture[] = data else: {. error: "Virtual datatype has no values" .} func newDataList*(theType: DataType): DataList = result = DataList(theType: theType) case result.theType - of Float32: result.float32 = newSeq[float32]() - of Float64: result.float64 = newSeq[float64]() - of Int8: result.int8 = newSeq[int8]() - of Int16: result.int16 = newSeq[int16]() - of Int32: result.int32 = newSeq[int32]() - of Int64: result.int64 = newSeq[int64]() - of UInt8: result.uint8 = newSeq[uint8]() - of UInt16: result.uint16 = newSeq[uint16]() - of UInt32: result.uint32 = newSeq[uint32]() - of UInt64: result.uint64 = newSeq[uint64]() - of Vec2I32: result.vec2i32 = newSeq[TVec2[int32]]() - of Vec2I64: result.vec2i64 = newSeq[TVec2[int64]]() - of Vec3I32: result.vec3i32 = newSeq[TVec3[int32]]() - of Vec3I64: result.vec3i64 = newSeq[TVec3[int64]]() - of Vec4I32: result.vec4i32 = newSeq[TVec4[int32]]() - of Vec4I64: result.vec4i64 = newSeq[TVec4[int64]]() - of Vec2U32: result.vec2u32 = newSeq[TVec2[uint32]]() - of Vec2U64: result.vec2u64 = newSeq[TVec2[uint64]]() - of Vec3U32: result.vec3u32 = newSeq[TVec3[uint32]]() - of Vec3U64: result.vec3u64 = newSeq[TVec3[uint64]]() - of Vec4U32: result.vec4u32 = newSeq[TVec4[uint32]]() - of Vec4U64: result.vec4u64 = newSeq[TVec4[uint64]]() - of Vec2F32: result.vec2f32 = newSeq[TVec2[float32]]() - of Vec2F64: result.vec2f64 = newSeq[TVec2[float64]]() - of Vec3F32: result.vec3f32 = newSeq[TVec3[float32]]() - of Vec3F64: result.vec3f64 = newSeq[TVec3[float64]]() - of Vec4F32: result.vec4f32 = newSeq[TVec4[float32]]() - of Vec4F64: result.vec4f64 = newSeq[TVec4[float64]]() - of Mat2F32: result.mat2f32 = newSeq[TMat2[float32]]() - of Mat2F64: result.mat2f64 = newSeq[TMat2[float64]]() - of Mat23F32: result.mat23f32 = newSeq[TMat23[float32]]() - of Mat23F64: result.mat23f64 = newSeq[TMat23[float64]]() - of Mat32F32: result.mat32f32 = newSeq[TMat32[float32]]() - of Mat32F64: result.mat32f64 = newSeq[TMat32[float64]]() - of Mat3F32: result.mat3f32 = newSeq[TMat3[float32]]() - of Mat3F64: result.mat3f64 = newSeq[TMat3[float64]]() - of Mat34F32: result.mat34f32 = newSeq[TMat34[float32]]() - of Mat34F64: result.mat34f64 = newSeq[TMat34[float64]]() - of Mat43F32: result.mat43f32 = newSeq[TMat43[float32]]() - of Mat43F64: result.mat43f64 = newSeq[TMat43[float64]]() - of Mat4F32: result.mat4f32 = newSeq[TMat4[float32]]() - of Mat4F64: result.mat4f64 = newSeq[TMat4[float64]]() + of Float32: result.float32 = new seq[float32] + of Float64: result.float64 = new seq[float64] + of Int8: result.int8 = new seq[int8] + of Int16: result.int16 = new seq[int16] + of Int32: result.int32 = new seq[int32] + of Int64: result.int64 = new seq[int64] + of UInt8: result.uint8 = new seq[uint8] + of UInt16: result.uint16 = new seq[uint16] + of UInt32: result.uint32 = new seq[uint32] + of UInt64: result.uint64 = new seq[uint64] + of Vec2I32: result.vec2i32 = new seq[TVec2[int32]] + of Vec2I64: result.vec2i64 = new seq[TVec2[int64]] + of Vec3I32: result.vec3i32 = new seq[TVec3[int32]] + of Vec3I64: result.vec3i64 = new seq[TVec3[int64]] + of Vec4I32: result.vec4i32 = new seq[TVec4[int32]] + of Vec4I64: result.vec4i64 = new seq[TVec4[int64]] + of Vec2U32: result.vec2u32 = new seq[TVec2[uint32]] + of Vec2U64: result.vec2u64 = new seq[TVec2[uint64]] + of Vec3U32: result.vec3u32 = new seq[TVec3[uint32]] + of Vec3U64: result.vec3u64 = new seq[TVec3[uint64]] + of Vec4U32: result.vec4u32 = new seq[TVec4[uint32]] + of Vec4U64: result.vec4u64 = new seq[TVec4[uint64]] + of Vec2F32: result.vec2f32 = new seq[TVec2[float32]] + of Vec2F64: result.vec2f64 = new seq[TVec2[float64]] + of Vec3F32: result.vec3f32 = new seq[TVec3[float32]] + of Vec3F64: result.vec3f64 = new seq[TVec3[float64]] + of Vec4F32: result.vec4f32 = new seq[TVec4[float32]] + of Vec4F64: result.vec4f64 = new seq[TVec4[float64]] + of Mat2F32: result.mat2f32 = new seq[TMat2[float32]] + of Mat2F64: result.mat2f64 = new seq[TMat2[float64]] + of Mat23F32: result.mat23f32 = new seq[TMat23[float32]] + of Mat23F64: result.mat23f64 = new seq[TMat23[float64]] + of Mat32F32: result.mat32f32 = new seq[TMat32[float32]] + of Mat32F64: result.mat32f64 = new seq[TMat32[float64]] + of Mat3F32: result.mat3f32 = new seq[TMat3[float32]] + of Mat3F64: result.mat3f64 = new seq[TMat3[float64]] + of Mat34F32: result.mat34f32 = new seq[TMat34[float32]] + of Mat34F64: result.mat34f64 = new seq[TMat34[float64]] + of Mat43F32: result.mat43f32 = new seq[TMat43[float32]] + of Mat43F64: result.mat43f64 = new seq[TMat43[float64]] + of Mat4F32: result.mat4f32 = new seq[TMat4[float32]] + of Mat4F64: result.mat4f64 = new seq[TMat4[float64]] of Sampler2D: discard func newDataList*[T: GPUType](len=0): DataList = @@ -524,7 +524,7 @@ result = newDataList[T](value.len) result.setValue(value) -func getValues*[T: GPUType|int|uint|float](value: DataList): seq[T] = +func getValues*[T: GPUType|int|uint|float](value: DataList): ref seq[T] = when T is float32: value.float32 elif T is float64: value.float64 elif T is int8: value.int8 @@ -680,95 +680,95 @@ return (nil, 0) result[1] = value.theType.size * value.len case value.theType - of Float32: result[0] = value.float32.toCPointer - of Float64: result[0] = value.float64.toCPointer - of Int8: result[0] = value.int8.toCPointer - of Int16: result[0] = value.int16.toCPointer - of Int32: result[0] = value.int32.toCPointer - of Int64: result[0] = value.int64.toCPointer - of UInt8: result[0] = value.uint8.toCPointer - of UInt16: result[0] = value.uint16.toCPointer - of UInt32: result[0] = value.uint32.toCPointer - of UInt64: result[0] = value.uint64.toCPointer - of Vec2I32: result[0] = value.vec2i32.toCPointer - of Vec2I64: result[0] = value.vec2i64.toCPointer - of Vec3I32: result[0] = value.vec3i32.toCPointer - of Vec3I64: result[0] = value.vec3i64.toCPointer - of Vec4I32: result[0] = value.vec4i32.toCPointer - of Vec4I64: result[0] = value.vec4i64.toCPointer - of Vec2U32: result[0] = value.vec2u32.toCPointer - of Vec2U64: result[0] = value.vec2u64.toCPointer - of Vec3U32: result[0] = value.vec3u32.toCPointer - of Vec3U64: result[0] = value.vec3u64.toCPointer - of Vec4U32: result[0] = value.vec4u32.toCPointer - of Vec4U64: result[0] = value.vec4u64.toCPointer - of Vec2F32: result[0] = value.vec2f32.toCPointer - of Vec2F64: result[0] = value.vec2f64.toCPointer - of Vec3F32: result[0] = value.vec3f32.toCPointer - of Vec3F64: result[0] = value.vec3f64.toCPointer - of Vec4F32: result[0] = value.vec4f32.toCPointer - of Vec4F64: result[0] = value.vec4f64.toCPointer - of Mat2F32: result[0] = value.mat2f32.toCPointer - of Mat2F64: result[0] = value.mat2f64.toCPointer - of Mat23F32: result[0] = value.mat23f32.toCPointer - of Mat23F64: result[0] = value.mat23f64.toCPointer - of Mat32F32: result[0] = value.mat32f32.toCPointer - of Mat32F64: result[0] = value.mat32f64.toCPointer - of Mat3F32: result[0] = value.mat3f32.toCPointer - of Mat3F64: result[0] = value.mat3f64.toCPointer - of Mat34F32: result[0] = value.mat34f32.toCPointer - of Mat34F64: result[0] = value.mat34f64.toCPointer - of Mat43F32: result[0] = value.mat43f32.toCPointer - of Mat43F64: result[0] = value.mat43f64.toCPointer - of Mat4F32: result[0] = value.mat4f32.toCPointer - of Mat4F64: result[0] = value.mat4f64.toCPointer + of Float32: result[0] = value.float32[].toCPointer + of Float64: result[0] = value.float64[].toCPointer + of Int8: result[0] = value.int8[].toCPointer + of Int16: result[0] = value.int16[].toCPointer + of Int32: result[0] = value.int32[].toCPointer + of Int64: result[0] = value.int64[].toCPointer + of UInt8: result[0] = value.uint8[].toCPointer + of UInt16: result[0] = value.uint16[].toCPointer + of UInt32: result[0] = value.uint32[].toCPointer + of UInt64: result[0] = value.uint64[].toCPointer + of Vec2I32: result[0] = value.vec2i32[].toCPointer + of Vec2I64: result[0] = value.vec2i64[].toCPointer + of Vec3I32: result[0] = value.vec3i32[].toCPointer + of Vec3I64: result[0] = value.vec3i64[].toCPointer + of Vec4I32: result[0] = value.vec4i32[].toCPointer + of Vec4I64: result[0] = value.vec4i64[].toCPointer + of Vec2U32: result[0] = value.vec2u32[].toCPointer + of Vec2U64: result[0] = value.vec2u64[].toCPointer + of Vec3U32: result[0] = value.vec3u32[].toCPointer + of Vec3U64: result[0] = value.vec3u64[].toCPointer + of Vec4U32: result[0] = value.vec4u32[].toCPointer + of Vec4U64: result[0] = value.vec4u64[].toCPointer + of Vec2F32: result[0] = value.vec2f32[].toCPointer + of Vec2F64: result[0] = value.vec2f64[].toCPointer + of Vec3F32: result[0] = value.vec3f32[].toCPointer + of Vec3F64: result[0] = value.vec3f64[].toCPointer + of Vec4F32: result[0] = value.vec4f32[].toCPointer + of Vec4F64: result[0] = value.vec4f64[].toCPointer + of Mat2F32: result[0] = value.mat2f32[].toCPointer + of Mat2F64: result[0] = value.mat2f64[].toCPointer + of Mat23F32: result[0] = value.mat23f32[].toCPointer + of Mat23F64: result[0] = value.mat23f64[].toCPointer + of Mat32F32: result[0] = value.mat32f32[].toCPointer + of Mat32F64: result[0] = value.mat32f64[].toCPointer + of Mat3F32: result[0] = value.mat3f32[].toCPointer + of Mat3F64: result[0] = value.mat3f64[].toCPointer + of Mat34F32: result[0] = value.mat34f32[].toCPointer + of Mat34F64: result[0] = value.mat34f64[].toCPointer + of Mat43F32: result[0] = value.mat43f32[].toCPointer + of Mat43F64: result[0] = value.mat43f64[].toCPointer + of Mat4F32: result[0] = value.mat4f32[].toCPointer + of Mat4F64: result[0] = value.mat4f64[].toCPointer of Sampler2D: result[0] = nil -func initData*(value: var DataList, len: int) = +proc initData*(value: var DataList, len: int) = value.len = len case value.theType - of Float32: value.float32.setLen(len) - of Float64: value.float64.setLen(len) - of Int8: value.int8.setLen(len) - of Int16: value.int16.setLen(len) - of Int32: value.int32.setLen(len) - of Int64: value.int64.setLen(len) - of UInt8: value.uint8.setLen(len) - of UInt16: value.uint16.setLen(len) - of UInt32: value.uint32.setLen(len) - of UInt64: value.uint64.setLen(len) - of Vec2I32: value.vec2i32.setLen(len) - of Vec2I64: value.vec2i64.setLen(len) - of Vec3I32: value.vec3i32.setLen(len) - of Vec3I64: value.vec3i64.setLen(len) - of Vec4I32: value.vec4i32.setLen(len) - of Vec4I64: value.vec4i64.setLen(len) - of Vec2U32: value.vec2u32.setLen(len) - of Vec2U64: value.vec2u64.setLen(len) - of Vec3U32: value.vec3u32.setLen(len) - of Vec3U64: value.vec3u64.setLen(len) - of Vec4U32: value.vec4u32.setLen(len) - of Vec4U64: value.vec4u64.setLen(len) - of Vec2F32: value.vec2f32.setLen(len) - of Vec2F64: value.vec2f64.setLen(len) - of Vec3F32: value.vec3f32.setLen(len) - of Vec3F64: value.vec3f64.setLen(len) - of Vec4F32: value.vec4f32.setLen(len) - of Vec4F64: value.vec4f64.setLen(len) - of Mat2F32: value.mat2f32.setLen(len) - of Mat2F64: value.mat2f64.setLen(len) - of Mat23F32: value.mat23f32.setLen(len) - of Mat23F64: value.mat23f64.setLen(len) - of Mat32F32: value.mat32f32.setLen(len) - of Mat32F64: value.mat32f64.setLen(len) - of Mat3F32: value.mat3f32.setLen(len) - of Mat3F64: value.mat3f64.setLen(len) - of Mat34F32: value.mat34f32.setLen(len) - of Mat34F64: value.mat34f64.setLen(len) - of Mat43F32: value.mat43f32.setLen(len) - of Mat43F64: value.mat43f64.setLen(len) - of Mat4F32: value.mat4f32.setLen(len) - of Mat4F64: value.mat4f64.setLen(len) + of Float32: value.float32[].setLen(len) + of Float64: value.float64[].setLen(len) + of Int8: value.int8[].setLen(len) + of Int16: value.int16[].setLen(len) + of Int32: value.int32[].setLen(len) + of Int64: value.int64[].setLen(len) + of UInt8: value.uint8[].setLen(len) + of UInt16: value.uint16[].setLen(len) + of UInt32: value.uint32[].setLen(len) + of UInt64: value.uint64[].setLen(len) + of Vec2I32: value.vec2i32[].setLen(len) + of Vec2I64: value.vec2i64[].setLen(len) + of Vec3I32: value.vec3i32[].setLen(len) + of Vec3I64: value.vec3i64[].setLen(len) + of Vec4I32: value.vec4i32[].setLen(len) + of Vec4I64: value.vec4i64[].setLen(len) + of Vec2U32: value.vec2u32[].setLen(len) + of Vec2U64: value.vec2u64[].setLen(len) + of Vec3U32: value.vec3u32[].setLen(len) + of Vec3U64: value.vec3u64[].setLen(len) + of Vec4U32: value.vec4u32[].setLen(len) + of Vec4U64: value.vec4u64[].setLen(len) + of Vec2F32: value.vec2f32[].setLen(len) + of Vec2F64: value.vec2f64[].setLen(len) + of Vec3F32: value.vec3f32[].setLen(len) + of Vec3F64: value.vec3f64[].setLen(len) + of Vec4F32: value.vec4f32[].setLen(len) + of Vec4F64: value.vec4f64[].setLen(len) + of Mat2F32: value.mat2f32[].setLen(len) + of Mat2F64: value.mat2f64[].setLen(len) + of Mat23F32: value.mat23f32[].setLen(len) + of Mat23F64: value.mat23f64[].setLen(len) + of Mat32F32: value.mat32f32[].setLen(len) + of Mat32F64: value.mat32f64[].setLen(len) + of Mat3F32: value.mat3f32[].setLen(len) + of Mat3F64: value.mat3f64[].setLen(len) + of Mat34F32: value.mat34f32[].setLen(len) + of Mat34F64: value.mat34f64[].setLen(len) + of Mat43F32: value.mat43f32[].setLen(len) + of Mat43F64: value.mat43f64[].setLen(len) + of Mat4F32: value.mat4f32[].setLen(len) + of Mat4F64: value.mat4f64[].setLen(len) of Sampler2D: discard func setValue*[T: GPUType|int|uint|float](value: var DataValue, data: T) = @@ -823,208 +823,208 @@ elif T is Texture: value.texture = data else: {.error: "Virtual datatype has no value" .} -func appendValues*[T: GPUType|int|uint|float](value: var DataList, data: seq[T]) = +proc appendValues*[T: GPUType|int|uint|float](value: var DataList, data: seq[T]) = value.len += data.len - when T is float32: value.float32.add data - elif T is float64: value.float64.add data - elif T is int8: value.int8.add data - elif T is int16: value.int16.add data - elif T is int32: value.int32.add data - elif T is int64: value.int64.add data - elif T is uint8: value.uint8.add data - elif T is uint16: value.uint16.add data - elif T is uint32: value.uint32.add data - elif T is uint64: value.uint64.add data - elif T is int and sizeof(int) == sizeof(int32): value.int32.add data - elif T is int and sizeof(int) == sizeof(int64): value.int64.add data - elif T is uint and sizeof(uint) == sizeof(uint32): value.uint32.add data - elif T is uint and sizeof(uint) == sizeof(uint64): value.uint64.add data - elif T is float and sizeof(float) == sizeof(float32): value.float32.add data - elif T is float and sizeof(float) == sizeof(float64): value.float64.add data - elif T is TVec2[int32]: value.vec2i32.add data - elif T is TVec2[int64]: value.vec2i64.add data - elif T is TVec3[int32]: value.vec3i32.add data - elif T is TVec3[int64]: value.vec3i64.add data - elif T is TVec4[int32]: value.vec4i32.add data - elif T is TVec4[int64]: value.vec4i64.add data - elif T is TVec2[uint32]: value.vec2u32.add data - elif T is TVec2[uint64]: value.vec2u64.add data - elif T is TVec3[uint32]: value.vec3u32.add data - elif T is TVec3[uint64]: value.vec3u64.add data - elif T is TVec4[uint32]: value.vec4u32.add data - elif T is TVec4[uint64]: value.vec4u64.add data - elif T is TVec2[float32]: value.vec2f32.add data - elif T is TVec2[float64]: value.vec2f64.add data - elif T is TVec3[float32]: value.vec3f32.add data - elif T is TVec3[float64]: value.vec3f64.add data - elif T is TVec4[float32]: value.vec4f32.add data - elif T is TVec4[float64]: value.vec4f64.add data - elif T is TMat2[float32]: value.mat2f32.add data - elif T is TMat2[float64]: value.mat2f64.add data - elif T is TMat23[float32]: value.mat23f32.add data - elif T is TMat23[float64]: value.mat23f64.add data - elif T is TMat32[float32]: value.mat32f32.add data - elif T is TMat32[float64]: value.mat32f64.add data - elif T is TMat3[float32]: value.mat3f32.add data - elif T is TMat3[float64]: value.mat3f64.add data - elif T is TMat34[float32]: value.mat34f32.add data - elif T is TMat34[float64]: value.mat34f64.add data - elif T is TMat43[float32]: value.mat43f32.add data - elif T is TMat43[float64]: value.mat43f64.add data - elif T is TMat4[float32]: value.mat4f32.add data - elif T is TMat4[float64]: value.mat4f64.add data - elif T is Texture: value.texture.add data + when T is float32: value.float32[].add data + elif T is float64: value.float64[].add data + elif T is int8: value.int8[].add data + elif T is int16: value.int16[].add data + elif T is int32: value.int32[].add data + elif T is int64: value.int64[].add data + elif T is uint8: value.uint8[].add data + elif T is uint16: value.uint16[].add data + elif T is uint32: value.uint32[].add data + elif T is uint64: value.uint64[].add data + elif T is int and sizeof(int) == sizeof(int32): value.int32[].add data + elif T is int and sizeof(int) == sizeof(int64): value.int64[].add data + elif T is uint and sizeof(uint) == sizeof(uint32): value.uint32[].add data + elif T is uint and sizeof(uint) == sizeof(uint64): value.uint64[].add data + elif T is float and sizeof(float) == sizeof(float32): value.float32[].add data + elif T is float and sizeof(float) == sizeof(float64): value.float64[].add data + elif T is TVec2[int32]: value.vec2i32[].add data + elif T is TVec2[int64]: value.vec2i64[].add data + elif T is TVec3[int32]: value.vec3i32[].add data + elif T is TVec3[int64]: value.vec3i64[].add data + elif T is TVec4[int32]: value.vec4i32[].add data + elif T is TVec4[int64]: value.vec4i64[].add data + elif T is TVec2[uint32]: value.vec2u32[].add data + elif T is TVec2[uint64]: value.vec2u64[].add data + elif T is TVec3[uint32]: value.vec3u32[].add data + elif T is TVec3[uint64]: value.vec3u64[].add data + elif T is TVec4[uint32]: value.vec4u32[].add data + elif T is TVec4[uint64]: value.vec4u64[].add data + elif T is TVec2[float32]: value.vec2f32[].add data + elif T is TVec2[float64]: value.vec2f64[].add data + elif T is TVec3[float32]: value.vec3f32[].add data + elif T is TVec3[float64]: value.vec3f64[].add data + elif T is TVec4[float32]: value.vec4f32[].add data + elif T is TVec4[float64]: value.vec4f64[].add data + elif T is TMat2[float32]: value.mat2f32[].add data + elif T is TMat2[float64]: value.mat2f64[].add data + elif T is TMat23[float32]: value.mat23f32[].add data + elif T is TMat23[float64]: value.mat23f64[].add data + elif T is TMat32[float32]: value.mat32f32[].add data + elif T is TMat32[float64]: value.mat32f64[].add data + elif T is TMat3[float32]: value.mat3f32[].add data + elif T is TMat3[float64]: value.mat3f64[].add data + elif T is TMat34[float32]: value.mat34f32[].add data + elif T is TMat34[float64]: value.mat34f64[].add data + elif T is TMat43[float32]: value.mat43f32[].add data + elif T is TMat43[float64]: value.mat43f64[].add data + elif T is TMat4[float32]: value.mat4f32[].add data + elif T is TMat4[float64]: value.mat4f64[].add data + elif T is Texture: value.texture[].add data else: {. error: "Virtual datatype has no values" .} -func appendValues*(value: var DataList, data: DataList) = +proc appendValues*(value: var DataList, data: DataList) = assert value.theType == data.theType value.len += data.len case value.theType: - of Float32: value.float32.add data.float32 - of Float64: value.float64.add data.float64 - of Int8: value.int8.add data.int8 - of Int16: value.int16.add data.int16 - of Int32: value.int32.add data.int32 - of Int64: value.int64.add data.int64 - of UInt8: value.uint8.add data.uint8 - of UInt16: value.uint16.add data.uint16 - of UInt32: value.uint32.add data.uint32 - of UInt64: value.uint64.add data.uint64 - of Vec2I32: value.vec2i32.add data.vec2i32 - of Vec2I64: value.vec2i64.add data.vec2i64 - of Vec3I32: value.vec3i32.add data.vec3i32 - of Vec3I64: value.vec3i64.add data.vec3i64 - of Vec4I32: value.vec4i32.add data.vec4i32 - of Vec4I64: value.vec4i64.add data.vec4i64 - of Vec2U32: value.vec2u32.add data.vec2u32 - of Vec2U64: value.vec2u64.add data.vec2u64 - of Vec3U32: value.vec3u32.add data.vec3u32 - of Vec3U64: value.vec3u64.add data.vec3u64 - of Vec4U32: value.vec4u32.add data.vec4u32 - of Vec4U64: value.vec4u64.add data.vec4u64 - of Vec2F32: value.vec2f32.add data.vec2f32 - of Vec2F64: value.vec2f64.add data.vec2f64 - of Vec3F32: value.vec3f32.add data.vec3f32 - of Vec3F64: value.vec3f64.add data.vec3f64 - of Vec4F32: value.vec4f32.add data.vec4f32 - of Vec4F64: value.vec4f64.add data.vec4f64 - of Mat2F32: value.mat2f32.add data.mat2f32 - of Mat2F64: value.mat2f64.add data.mat2f64 - of Mat23F32: value.mat23f32.add data.mat23f32 - of Mat23F64: value.mat23f64.add data.mat23f64 - of Mat32F32: value.mat32f32.add data.mat32f32 - of Mat32F64: value.mat32f64.add data.mat32f64 - of Mat3F32: value.mat3f32.add data.mat3f32 - of Mat3F64: value.mat3f64.add data.mat3f64 - of Mat34F32: value.mat34f32.add data.mat34f32 - of Mat34F64: value.mat34f64.add data.mat34f64 - of Mat43F32: value.mat43f32.add data.mat43f32 - of Mat43F64: value.mat43f64.add data.mat43f64 - of Mat4F32: value.mat4f32.add data.mat4f32 - of Mat4F64: value.mat4f64.add data.mat4f64 + of Float32: value.float32[].add data.float32[] + of Float64: value.float64[].add data.float64[] + of Int8: value.int8[].add data.int8[] + of Int16: value.int16[].add data.int16[] + of Int32: value.int32[].add data.int32[] + of Int64: value.int64[].add data.int64[] + of UInt8: value.uint8[].add data.uint8[] + of UInt16: value.uint16[].add data.uint16[] + of UInt32: value.uint32[].add data.uint32[] + of UInt64: value.uint64[].add data.uint64[] + of Vec2I32: value.vec2i32[].add data.vec2i32[] + of Vec2I64: value.vec2i64[].add data.vec2i64[] + of Vec3I32: value.vec3i32[].add data.vec3i32[] + of Vec3I64: value.vec3i64[].add data.vec3i64[] + of Vec4I32: value.vec4i32[].add data.vec4i32[] + of Vec4I64: value.vec4i64[].add data.vec4i64[] + of Vec2U32: value.vec2u32[].add data.vec2u32[] + of Vec2U64: value.vec2u64[].add data.vec2u64[] + of Vec3U32: value.vec3u32[].add data.vec3u32[] + of Vec3U64: value.vec3u64[].add data.vec3u64[] + of Vec4U32: value.vec4u32[].add data.vec4u32[] + of Vec4U64: value.vec4u64[].add data.vec4u64[] + of Vec2F32: value.vec2f32[].add data.vec2f32[] + of Vec2F64: value.vec2f64[].add data.vec2f64[] + of Vec3F32: value.vec3f32[].add data.vec3f32[] + of Vec3F64: value.vec3f64[].add data.vec3f64[] + of Vec4F32: value.vec4f32[].add data.vec4f32[] + of Vec4F64: value.vec4f64[].add data.vec4f64[] + of Mat2F32: value.mat2f32[].add data.mat2f32[] + of Mat2F64: value.mat2f64[].add data.mat2f64[] + of Mat23F32: value.mat23f32[].add data.mat23f32[] + of Mat23F64: value.mat23f64[].add data.mat23f64[] + of Mat32F32: value.mat32f32[].add data.mat32f32[] + of Mat32F64: value.mat32f64[].add data.mat32f64[] + of Mat3F32: value.mat3f32[].add data.mat3f32[] + of Mat3F64: value.mat3f64[].add data.mat3f64[] + of Mat34F32: value.mat34f32[].add data.mat34f32[] + of Mat34F64: value.mat34f64[].add data.mat34f64[] + of Mat43F32: value.mat43f32[].add data.mat43f32[] + of Mat43F64: value.mat43f64[].add data.mat43f64[] + of Mat4F32: value.mat4f32[].add data.mat4f32[] + of Mat4F64: value.mat4f64[].add data.mat4f64[] else: raise newException(Exception, &"Unsupported data type for GPU data:" ) -func appendValue*(value: var DataList, data: DataValue) = +proc appendValue*(value: var DataList, data: DataValue) = assert value.theType == data.theType, &"appendValue expected {value.theType} but got {data.theType}" value.len += 1 case value.theType: - of Float32: value.float32.add data.float32 - of Float64: value.float64.add data.float64 - of Int8: value.int8.add data.int8 - of Int16: value.int16.add data.int16 - of Int32: value.int32.add data.int32 - of Int64: value.int64.add data.int64 - of UInt8: value.uint8.add data.uint8 - of UInt16: value.uint16.add data.uint16 - of UInt32: value.uint32.add data.uint32 - of UInt64: value.uint64.add data.uint64 - of Vec2I32: value.vec2i32.add data.vec2i32 - of Vec2I64: value.vec2i64.add data.vec2i64 - of Vec3I32: value.vec3i32.add data.vec3i32 - of Vec3I64: value.vec3i64.add data.vec3i64 - of Vec4I32: value.vec4i32.add data.vec4i32 - of Vec4I64: value.vec4i64.add data.vec4i64 - of Vec2U32: value.vec2u32.add data.vec2u32 - of Vec2U64: value.vec2u64.add data.vec2u64 - of Vec3U32: value.vec3u32.add data.vec3u32 - of Vec3U64: value.vec3u64.add data.vec3u64 - of Vec4U32: value.vec4u32.add data.vec4u32 - of Vec4U64: value.vec4u64.add data.vec4u64 - of Vec2F32: value.vec2f32.add data.vec2f32 - of Vec2F64: value.vec2f64.add data.vec2f64 - of Vec3F32: value.vec3f32.add data.vec3f32 - of Vec3F64: value.vec3f64.add data.vec3f64 - of Vec4F32: value.vec4f32.add data.vec4f32 - of Vec4F64: value.vec4f64.add data.vec4f64 - of Mat2F32: value.mat2f32.add data.mat2f32 - of Mat2F64: value.mat2f64.add data.mat2f64 - of Mat23F32: value.mat23f32.add data.mat23f32 - of Mat23F64: value.mat23f64.add data.mat23f64 - of Mat32F32: value.mat32f32.add data.mat32f32 - of Mat32F64: value.mat32f64.add data.mat32f64 - of Mat3F32: value.mat3f32.add data.mat3f32 - of Mat3F64: value.mat3f64.add data.mat3f64 - of Mat34F32: value.mat34f32.add data.mat34f32 - of Mat34F64: value.mat34f64.add data.mat34f64 - of Mat43F32: value.mat43f32.add data.mat43f32 - of Mat43F64: value.mat43f64.add data.mat43f64 - of Mat4F32: value.mat4f32.add data.mat4f32 - of Mat4F64: value.mat4f64.add data.mat4f64 + of Float32: value.float32[].add data.float32 + of Float64: value.float64[].add data.float64 + of Int8: value.int8[].add data.int8 + of Int16: value.int16[].add data.int16 + of Int32: value.int32[].add data.int32 + of Int64: value.int64[].add data.int64 + of UInt8: value.uint8[].add data.uint8 + of UInt16: value.uint16[].add data.uint16 + of UInt32: value.uint32[].add data.uint32 + of UInt64: value.uint64[].add data.uint64 + of Vec2I32: value.vec2i32[].add data.vec2i32 + of Vec2I64: value.vec2i64[].add data.vec2i64 + of Vec3I32: value.vec3i32[].add data.vec3i32 + of Vec3I64: value.vec3i64[].add data.vec3i64 + of Vec4I32: value.vec4i32[].add data.vec4i32 + of Vec4I64: value.vec4i64[].add data.vec4i64 + of Vec2U32: value.vec2u32[].add data.vec2u32 + of Vec2U64: value.vec2u64[].add data.vec2u64 + of Vec3U32: value.vec3u32[].add data.vec3u32 + of Vec3U64: value.vec3u64[].add data.vec3u64 + of Vec4U32: value.vec4u32[].add data.vec4u32 + of Vec4U64: value.vec4u64[].add data.vec4u64 + of Vec2F32: value.vec2f32[].add data.vec2f32 + of Vec2F64: value.vec2f64[].add data.vec2f64 + of Vec3F32: value.vec3f32[].add data.vec3f32 + of Vec3F64: value.vec3f64[].add data.vec3f64 + of Vec4F32: value.vec4f32[].add data.vec4f32 + of Vec4F64: value.vec4f64[].add data.vec4f64 + of Mat2F32: value.mat2f32[].add data.mat2f32 + of Mat2F64: value.mat2f64[].add data.mat2f64 + of Mat23F32: value.mat23f32[].add data.mat23f32 + of Mat23F64: value.mat23f64[].add data.mat23f64 + of Mat32F32: value.mat32f32[].add data.mat32f32 + of Mat32F64: value.mat32f64[].add data.mat32f64 + of Mat3F32: value.mat3f32[].add data.mat3f32 + of Mat3F64: value.mat3f64[].add data.mat3f64 + of Mat34F32: value.mat34f32[].add data.mat34f32 + of Mat34F64: value.mat34f64[].add data.mat34f64 + of Mat43F32: value.mat43f32[].add data.mat43f32 + of Mat43F64: value.mat43f64[].add data.mat43f64 + of Mat4F32: value.mat4f32[].add data.mat4f32 + of Mat4F64: value.mat4f64[].add data.mat4f64 else: raise newException(Exception, &"Unsupported data type for GPU data:" ) -func setValue*[T: GPUType|int|uint|float](value: var DataList, data: seq[T]) = - 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 - elif T is Texture: value.texture = data +proc setValue*[T: GPUType|int|uint|float](value: var DataList, data: seq[T]) = + 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 + elif T is Texture: value.texture[] = data else: {. error: "Virtual datatype has no values" .} -func setValue*[T: GPUType|int|uint|float](value: var DataList, i: int, data: T) = +proc setValue*[T: GPUType|int|uint|float](value: var DataList, i: int, data: T) = assert i < value.len when T is float32: value.float32[i] = data elif T is float64: value.float64[i] = data diff -r 668eed376029 -r 73de86a9ec0a src/semicongine/mesh.nim --- a/src/semicongine/mesh.nim Thu Sep 07 23:28:36 2023 +0700 +++ b/src/semicongine/mesh.nim Fri Sep 08 00:05:19 2023 +0700 @@ -89,30 +89,30 @@ of Big: mesh.bigIndices.len ) * 3 -func initVertexAttribute*[T](mesh: var MeshObject, attribute: string, value: seq[T]) = +proc initVertexAttribute*[T](mesh: var MeshObject, attribute: string, value: seq[T]) = assert not mesh.vertexData.contains(attribute) and not mesh.instanceData.contains(attribute) mesh.vertexData[attribute] = newDataList(thetype=getDataType[T]()) mesh.vertexData[attribute].initData(mesh.vertexCount) mesh.vertexData[attribute].setValues(value) -func initVertexAttribute*[T](mesh: var MeshObject, attribute: string, value: T) = +proc initVertexAttribute*[T](mesh: var MeshObject, attribute: string, value: T) = initVertexAttribute(mesh, attribute, newSeqWith(mesh.vertexCount, value)) -func initVertexAttribute*[T](mesh: var MeshObject, attribute: string) = +proc initVertexAttribute*[T](mesh: var MeshObject, attribute: string) = initVertexAttribute(mesh=mesh, attribute=attribute, value=default(T)) -func initVertexAttribute*(mesh: var MeshObject, attribute: string, datatype: DataType) = +proc initVertexAttribute*(mesh: var MeshObject, attribute: string, datatype: DataType) = assert not mesh.vertexData.contains(attribute) and not mesh.instanceData.contains(attribute) mesh.vertexData[attribute] = newDataList(thetype=datatype) mesh.vertexData[attribute].initData(mesh.vertexCount) -func initInstanceAttribute*[T](mesh: var MeshObject, attribute: string, value: seq[T]) = +proc initInstanceAttribute*[T](mesh: var MeshObject, attribute: string, value: seq[T]) = assert not mesh.vertexData.contains(attribute) and not mesh.instanceData.contains(attribute) mesh.instanceData[attribute] = newDataList(thetype=getDataType[T]()) mesh.instanceData[attribute].initData(mesh.instanceCount) mesh.instanceData[attribute].setValues(value) -func initInstanceAttribute*[T](mesh: var MeshObject, attribute: string, value: T) = +proc initInstanceAttribute*[T](mesh: var MeshObject, attribute: string, value: T) = initInstanceAttribute(mesh, attribute, newSeqWith(mesh.instanceCount, value)) -func initInstanceAttribute*[T](mesh: var MeshObject, attribute: string) = +proc initInstanceAttribute*[T](mesh: var MeshObject, attribute: string) = initInstanceAttribute(mesh=mesh, attribute=attribute, value=default(T)) -func initInstanceAttribute*(mesh: var MeshObject, attribute: string, datatype: DataType) = +proc initInstanceAttribute*(mesh: var MeshObject, attribute: string, datatype: DataType) = assert not mesh.vertexData.contains(attribute) and not mesh.instanceData.contains(attribute) mesh.instanceData[attribute] = newDataList(thetype=datatype) mesh.instanceData[attribute].initData(mesh.instanceCount) @@ -227,7 +227,7 @@ else: raise newException(Exception, &"Attribute {attribute} is not defined for mesh {mesh}") -proc getAttribute[T: GPUType|int|uint|float](mesh: MeshObject, attribute: string): seq[T] = +proc getAttribute[T: GPUType|int|uint|float](mesh: MeshObject, attribute: string): ref seq[T] = if mesh.vertexData.contains(attribute): getValues[T](mesh.vertexData[attribute]) elif mesh.instanceData.contains(attribute): @@ -235,9 +235,9 @@ else: raise newException(Exception, &"Attribute {attribute} is not defined for mesh {mesh}") -template `[]`*(mesh: MeshObject, attribute: string, t: typedesc): seq[t] = +template `[]`*(mesh: MeshObject, attribute: string, t: typedesc): ref seq[t] = getAttribute[t](mesh, attribute) -template `[]`*(mesh: Mesh, attribute: string, t: typedesc): seq[t] = +template `[]`*(mesh: Mesh, attribute: string, t: typedesc): ref seq[t] = getAttribute[t](mesh[], attribute) proc updateAttributeData[T: GPUType|int|uint|float](mesh: var MeshObject, attribute: string, data: seq[T]) = @@ -332,7 +332,7 @@ raise newException(Exception, &"Attribute {attribute} is not defined for mesh {mesh}") func getCollisionPoints*(mesh: MeshObject, positionAttribute="position"): seq[Vec3f] = - for p in mesh[positionAttribute, Vec3f]: + for p in mesh[positionAttribute, Vec3f][]: result.add mesh.transform * p # GENERATORS ============================================================================ diff -r 668eed376029 -r 73de86a9ec0a src/semicongine/renderer.nim --- a/src/semicongine/renderer.nim Thu Sep 07 23:28:36 2023 +0700 +++ b/src/semicongine/renderer.nim Fri Sep 08 00:05:19 2023 +0700 @@ -167,7 +167,7 @@ if value.theType == Sampler2D: assert not scenedata.textures.contains(name) # should be handled by the above code scenedata.textures[name] = @[] - for texture in getValues[Texture](value): + for texture in getValues[Texture](value)[]: scenedata.textures[name].add renderer.device.uploadTexture(texture) @@ -320,9 +320,9 @@ # ignore attributes that are not used in this shader if not (attribute in renderer.scenedata[scene].attributeLocation): return + let (pdata, size) = mesh[].getRawData(attribute) let memoryPerformanceHint = renderer.scenedata[scene].attributeLocation[attribute] - renderer.scenedata[scene].vertexBuffers[memoryPerformanceHint].setData(pdata, size, renderer.scenedata[scene].vertexBufferOffsets[(mesh, attribute)]) proc updateMeshData*(renderer: var Renderer, scene: var Scene, forceAll=false) = diff -r 668eed376029 -r 73de86a9ec0a src/semicongine/resources/mesh.nim --- a/src/semicongine/resources/mesh.nim Thu Sep 07 23:28:36 2023 +0700 +++ b/src/semicongine/resources/mesh.nim Fri Sep 08 00:05:19 2023 +0700 @@ -234,14 +234,14 @@ var tri: seq[int] case data.thetype of UInt16: - for entry in getValues[uint16](data): + for entry in getValues[uint16](data)[]: tri.add int(entry) + baseIndex if tri.len == 3: # FYI gltf uses counter-clockwise indexing mesh[].appendIndicesData(tri[0], tri[1], tri[2]) tri.setLen(0) of UInt32: - for entry in getValues[uint32](data): + for entry in getValues[uint32](data)[]: tri.add int(entry) if tri.len == 3: # FYI gltf uses counter-clockwise indexing diff -r 668eed376029 -r 73de86a9ec0a src/semicongine/scene.nim --- a/src/semicongine/scene.nim Thu Sep 07 23:28:36 2023 +0700 +++ b/src/semicongine/scene.nim Fri Sep 08 00:05:19 2023 +0700 @@ -23,12 +23,12 @@ proc add*[T](scene: var Scene, obj: T) = scene.meshes.add obj.mesh -func addShaderGlobal*[T](scene: var Scene, name: string, data: T) = +proc addShaderGlobal*[T](scene: var Scene, name: string, data: T) = scene.shaderGlobals[name] = newDataList(thetype=getDataType[T]()) setValues(scene.shaderGlobals[name], @[data]) scene.dirtyShaderGlobals.add name -func addShaderGlobalArray*[T](scene: var Scene, name: string, data: seq[T]) = +proc addShaderGlobalArray*[T](scene: var Scene, name: string, data: seq[T]) = scene.shaderGlobals[name] = newDataList(thetype=getDataType[T]()) setValues(scene.shaderGlobals[name], data) scene.dirtyShaderGlobals.add name @@ -39,12 +39,12 @@ func getShaderGlobalArray*[T](scene: Scene, name: string): seq[T] = getValues[T](scene.shaderGlobals[name]) -func setShaderGlobal*[T](scene: var Scene, name: string, value: T) = +proc setShaderGlobal*[T](scene: var Scene, name: string, value: T) = setValues[T](scene.shaderGlobals[name], @[value]) if not scene.dirtyShaderGlobals.contains(name): scene.dirtyShaderGlobals.add name -func setShaderGlobalArray*[T](scene: var Scene, name: string, value: seq[T]) = +proc setShaderGlobalArray*[T](scene: var Scene, name: string, value: seq[T]) = setValues[T](scene.shaderGlobals[name], value) if not scene.dirtyShaderGlobals.contains(name): scene.dirtyShaderGlobals.add name