Mercurial > games > semicongine
changeset 685:269bd721ffbe
did: refactor gpu data, fix some errors
author | Sam <sam@basx.dev> |
---|---|
date | Mon, 15 May 2023 14:25:04 +0700 |
parents | 3e81b82852b2 |
children | c671452564cd |
files | src/semicongine/core/gpu_data.nim src/semicongine/mesh.nim src/semicongine/resources/mesh.nim |
diffstat | 3 files changed, 391 insertions(+), 322 deletions(-) [+] |
line wrap: on
line diff
--- a/src/semicongine/core/gpu_data.nim Mon May 15 00:36:25 2023 +0700 +++ b/src/semicongine/core/gpu_data.nim Mon May 15 14:25:04 2023 +0700 @@ -101,48 +101,48 @@ DataList* = object len*: uint32 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 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: discard MemoryPerformanceHint* = enum PreferFastRead, PreferFastWrite @@ -349,7 +349,64 @@ elif T is TMat4[float64]: value.mat4f64 else: {.error: "Virtual datatype has no value" .} -func getValues*[T: GPUType|int|uint|float](value: DataList): seq[T] = +func newDataList*(thetype: DataType): DataList = + result = DataList(thetype: thetype) + case result.thetype + 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 = + result = newDataList(getDataType[T]()) + if len > 0: + result.initData(len) + +func newDataList*[T: GPUType](data: seq[T]): DataList = + result = newDataList(getDataType[T]()) + result.setValues[T](data) + + +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 @@ -452,95 +509,95 @@ return (nil, 0'u32) result[1] = value.thetype.size * value.len case value.thetype - of Float32: result[0] = addr value.float32[0] - of Float64: result[0] = addr value.float64[0] - of Int8: result[0] = addr value.int8[0] - of Int16: result[0] = addr value.int16[0] - of Int32: result[0] = addr value.int32[0] - of Int64: result[0] = addr value.int64[0] - of UInt8: result[0] = addr value.uint8[0] - of UInt16: result[0] = addr value.uint16[0] - of UInt32: result[0] = addr value.uint32[0] - of UInt64: result[0] = addr value.uint64[0] - of Vec2I32: result[0] = addr value.vec2i32[0] - of Vec2I64: result[0] = addr value.vec2i64[0] - of Vec3I32: result[0] = addr value.vec3i32[0] - of Vec3I64: result[0] = addr value.vec3i64[0] - of Vec4I32: result[0] = addr value.vec4i32[0] - of Vec4I64: result[0] = addr value.vec4i64[0] - of Vec2U32: result[0] = addr value.vec2u32[0] - of Vec2U64: result[0] = addr value.vec2u64[0] - of Vec3U32: result[0] = addr value.vec3u32[0] - of Vec3U64: result[0] = addr value.vec3u64[0] - of Vec4U32: result[0] = addr value.vec4u32[0] - of Vec4U64: result[0] = addr value.vec4u64[0] - of Vec2F32: result[0] = addr value.vec2f32[0] - of Vec2F64: result[0] = addr value.vec2f64[0] - of Vec3F32: result[0] = addr value.vec3f32[0] - of Vec3F64: result[0] = addr value.vec3f64[0] - of Vec4F32: result[0] = addr value.vec4f32[0] - of Vec4F64: result[0] = addr value.vec4f64[0] - of Mat2F32: result[0] = addr value.mat2f32[0] - of Mat2F64: result[0] = addr value.mat2f64[0] - of Mat23F32: result[0] = addr value.mat23f32[0] - of Mat23F64: result[0] = addr value.mat23f64[0] - of Mat32F32: result[0] = addr value.mat32f32[0] - of Mat32F64: result[0] = addr value.mat32f64[0] - of Mat3F32: result[0] = addr value.mat3f32[0] - of Mat3F64: result[0] = addr value.mat3f64[0] - of Mat34F32: result[0] = addr value.mat34f32[0] - of Mat34F64: result[0] = addr value.mat34f64[0] - of Mat43F32: result[0] = addr value.mat43f32[0] - of Mat43F64: result[0] = addr value.mat43f64[0] - of Mat4F32: result[0] = addr value.mat4f32[0] - of Mat4F64: result[0] = addr value.mat4f64[0] + of Float32: result[0] = addr value.float32[][0] + of Float64: result[0] = addr value.float64[][0] + of Int8: result[0] = addr value.int8[][0] + of Int16: result[0] = addr value.int16[][0] + of Int32: result[0] = addr value.int32[][0] + of Int64: result[0] = addr value.int64[][0] + of UInt8: result[0] = addr value.uint8[][0] + of UInt16: result[0] = addr value.uint16[][0] + of UInt32: result[0] = addr value.uint32[][0] + of UInt64: result[0] = addr value.uint64[][0] + of Vec2I32: result[0] = addr value.vec2i32[][0] + of Vec2I64: result[0] = addr value.vec2i64[][0] + of Vec3I32: result[0] = addr value.vec3i32[][0] + of Vec3I64: result[0] = addr value.vec3i64[][0] + of Vec4I32: result[0] = addr value.vec4i32[][0] + of Vec4I64: result[0] = addr value.vec4i64[][0] + of Vec2U32: result[0] = addr value.vec2u32[][0] + of Vec2U64: result[0] = addr value.vec2u64[][0] + of Vec3U32: result[0] = addr value.vec3u32[][0] + of Vec3U64: result[0] = addr value.vec3u64[][0] + of Vec4U32: result[0] = addr value.vec4u32[][0] + of Vec4U64: result[0] = addr value.vec4u64[][0] + of Vec2F32: result[0] = addr value.vec2f32[][0] + of Vec2F64: result[0] = addr value.vec2f64[][0] + of Vec3F32: result[0] = addr value.vec3f32[][0] + of Vec3F64: result[0] = addr value.vec3f64[][0] + of Vec4F32: result[0] = addr value.vec4f32[][0] + of Vec4F64: result[0] = addr value.vec4f64[][0] + of Mat2F32: result[0] = addr value.mat2f32[][0] + of Mat2F64: result[0] = addr value.mat2f64[][0] + of Mat23F32: result[0] = addr value.mat23f32[][0] + of Mat23F64: result[0] = addr value.mat23f64[][0] + of Mat32F32: result[0] = addr value.mat32f32[][0] + of Mat32F64: result[0] = addr value.mat32f64[][0] + of Mat3F32: result[0] = addr value.mat3f32[][0] + of Mat3F64: result[0] = addr value.mat3f64[][0] + of Mat34F32: result[0] = addr value.mat34f32[][0] + of Mat34F64: result[0] = addr value.mat34f64[][0] + of Mat43F32: result[0] = addr value.mat43f32[][0] + of Mat43F64: result[0] = addr value.mat43f64[][0] + of Mat4F32: result[0] = addr value.mat4f32[][0] + of Mat4F64: result[0] = addr value.mat4f64[][0] of Sampler2D: result[0] = nil func initData*(value: var DataList, len: uint32) = 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) = @@ -596,206 +653,206 @@ 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 + 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 - 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 + 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 else: {. error: "Virtual datatype has no values" .} func 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 setValue*[T: GPUType|int|uint|float](value: var DataList, i: uint32, data: T) = assert i < value.len - when T is float32: value.float32[i] = data - elif T is float64: value.float64[i] = data - elif T is int8: value.int8[i] = data - elif T is int16: value.int16[i] = data - elif T is int32: value.int32[i] = data - elif T is int64: value.int64[i] = data - elif T is uint8: value.uint8[i] = data - elif T is uint16: value.uint16[i] = data - elif T is uint32: value.uint32[i] = data - elif T is uint64: value.uint64[i] = data - elif T is int and sizeof(int) == sizeof(int32): value.int32[i] = data - elif T is int and sizeof(int) == sizeof(int64): value.int64[i] = data - elif T is uint and sizeof(uint) == sizeof(uint32): value.uint32[i] = data - elif T is uint and sizeof(uint) == sizeof(uint64): value.uint64[i] = data - elif T is float and sizeof(float) == sizeof(float32): value.float32[i] = data - elif T is float and sizeof(float) == sizeof(float64): value.float64[i] = data - elif T is TVec2[int32]: value.vec2i32[i] = data - elif T is TVec2[int64]: value.vec2i64[i] = data - elif T is TVec3[int32]: value.vec3i32[i] = data - elif T is TVec3[int64]: value.vec3i64[i] = data - elif T is TVec4[int32]: value.vec4i32[i] = data - elif T is TVec4[int64]: value.vec4i64[i] = data - elif T is TVec2[uint32]: value.vec2u32[i] = data - elif T is TVec2[uint64]: value.vec2u64[i] = data - elif T is TVec3[uint32]: value.vec3u32[i] = data - elif T is TVec3[uint64]: value.vec3u64[i] = data - elif T is TVec4[uint32]: value.vec4u32[i] = data - elif T is TVec4[uint64]: value.vec4u64[i] = data - elif T is TVec2[float32]: value.vec2f32[i] = data - elif T is TVec2[float64]: value.vec2f64[i] = data - elif T is TVec3[float32]: value.vec3f32[i] = data - elif T is TVec3[float64]: value.vec3f64[i] = data - elif T is TVec4[float32]: value.vec4f32[i] = data - elif T is TVec4[float64]: value.vec4f64[i] = data - elif T is TMat2[float32]: value.mat2f32[i] = data - elif T is TMat2[float64]: value.mat2f64[i] = data - elif T is TMat23[float32]: value.mat23f32[i] = data - elif T is TMat23[float64]: value.mat23f64[i] = data - elif T is TMat32[float32]: value.mat32f32[i] = data - elif T is TMat32[float64]: value.mat32f64[i] = data - elif T is TMat3[float32]: value.mat3f32[i] = data - elif T is TMat3[float64]: value.mat3f64[i] = data - elif T is TMat34[float32]: value.mat34f32[i] = data - elif T is TMat34[float64]: value.mat34f64[i] = data - elif T is TMat43[float32]: value.mat43f32[i] = data - elif T is TMat43[float64]: value.mat43f64[i] = data - elif T is TMat4[float32]: value.mat4f32[i] = data - elif T is TMat4[float64]: value.mat4f64[i] = data + when T is float32: value.float32[][i] = data + elif T is float64: value.float64[][i] = data + elif T is int8: value.int8[][i] = data + elif T is int16: value.int16[][i] = data + elif T is int32: value.int32[][i] = data + elif T is int64: value.int64[][i] = data + elif T is uint8: value.uint8[][i] = data + elif T is uint16: value.uint16[][i] = data + elif T is uint32: value.uint32[][i] = data + elif T is uint64: value.uint64[][i] = data + elif T is int and sizeof(int) == sizeof(int32): value.int32[][i] = data + elif T is int and sizeof(int) == sizeof(int64): value.int64[][i] = data + elif T is uint and sizeof(uint) == sizeof(uint32): value.uint32[][i] = data + elif T is uint and sizeof(uint) == sizeof(uint64): value.uint64[][i] = data + elif T is float and sizeof(float) == sizeof(float32): value.float32[][i] = data + elif T is float and sizeof(float) == sizeof(float64): value.float64[][i] = data + elif T is TVec2[int32]: value.vec2i32[][i] = data + elif T is TVec2[int64]: value.vec2i64[][i] = data + elif T is TVec3[int32]: value.vec3i32[][i] = data + elif T is TVec3[int64]: value.vec3i64[][i] = data + elif T is TVec4[int32]: value.vec4i32[][i] = data + elif T is TVec4[int64]: value.vec4i64[][i] = data + elif T is TVec2[uint32]: value.vec2u32[][i] = data + elif T is TVec2[uint64]: value.vec2u64[][i] = data + elif T is TVec3[uint32]: value.vec3u32[][i] = data + elif T is TVec3[uint64]: value.vec3u64[][i] = data + elif T is TVec4[uint32]: value.vec4u32[][i] = data + elif T is TVec4[uint64]: value.vec4u64[][i] = data + elif T is TVec2[float32]: value.vec2f32[][i] = data + elif T is TVec2[float64]: value.vec2f64[][i] = data + elif T is TVec3[float32]: value.vec3f32[][i] = data + elif T is TVec3[float64]: value.vec3f64[][i] = data + elif T is TVec4[float32]: value.vec4f32[][i] = data + elif T is TVec4[float64]: value.vec4f64[][i] = data + elif T is TMat2[float32]: value.mat2f32[][i] = data + elif T is TMat2[float64]: value.mat2f64[][i] = data + elif T is TMat23[float32]: value.mat23f32[][i] = data + elif T is TMat23[float64]: value.mat23f64[][i] = data + elif T is TMat32[float32]: value.mat32f32[][i] = data + elif T is TMat32[float64]: value.mat32f64[][i] = data + elif T is TMat3[float32]: value.mat3f32[][i] = data + elif T is TMat3[float64]: value.mat3f64[][i] = data + elif T is TMat34[float32]: value.mat34f32[][i] = data + elif T is TMat34[float64]: value.mat34f64[][i] = data + elif T is TMat43[float32]: value.mat43f32[][i] = data + elif T is TMat43[float64]: value.mat43f64[][i] = data + elif T is TMat4[float32]: value.mat4f32[][i] = data + elif T is TMat4[float64]: value.mat4f64[][i] = data else: {. error: "Virtual datatype has no values" .} const TYPEMAP = {
--- a/src/semicongine/mesh.nim Mon May 15 00:36:25 2023 +0700 +++ b/src/semicongine/mesh.nim Mon May 15 14:25:04 2023 +0700 @@ -139,13 +139,13 @@ func getRawData*(mesh: Mesh, attribute: string): (pointer, uint32) = mesh.data[attribute].getRawData() -proc getMeshData*[T: GPUType|int|uint|float](mesh: Mesh, attribute: string): seq[T] = +proc getMeshData*[T: GPUType|int|uint|float](mesh: Mesh, attribute: string): ref seq[T] = assert attribute in mesh.data getValues[T](mesh.data[attribute]) proc initData*(mesh: var Mesh, attribute: ShaderAttribute) = assert not (attribute.name in mesh.data) - mesh.data[attribute.name] = DataList(thetype: attribute.thetype) + mesh.data[attribute.name] = newDataList(thetype=attribute.thetype) if attribute.perInstance: mesh.data[attribute.name].initData(mesh.instanceCount) else: @@ -153,8 +153,7 @@ proc setMeshData*[T: GPUType|int|uint|float](mesh: var Mesh, attribute: string, data: seq[T]) = assert not (attribute in mesh.data) - mesh.data[attribute] = DataList(thetype: getDataType[T]()) - setValues(mesh.data[attribute], data) + mesh.data[attribute] = newDataList[T](data) proc setMeshData*(mesh: var Mesh, attribute: string, data: DataList) = assert not (attribute in mesh.data) @@ -213,6 +212,16 @@ proc clearDataChanged*(mesh: var Mesh) = mesh.changedAttributes = @[] +proc transform*[T: GPUType](mesh: var Mesh, attribute: string, transform: Mat4) = + assert attribute in mesh.data + echo "=========", getMeshData[Vec3f](mesh, attribute)[][0 .. 3] + for v in getValues[T](mesh.data[attribute])[].mitems: + when T is Vec3f: + v = (transform * newVec4f(v.x, v.y, v.z)).xyz + else: + v = transform * v + echo "=========", getMeshData[Vec3f](mesh, attribute)[][0 .. 3] + func rect*(width=1'f32, height=1'f32, color="ffffffff"): Mesh = result = new Mesh result.instanceCount = 1
--- a/src/semicongine/resources/mesh.nim Mon May 15 00:36:25 2023 +0700 +++ b/src/semicongine/resources/mesh.nim Mon May 15 14:25:04 2023 +0700 @@ -37,7 +37,6 @@ func getGPUType(accessor: JsonNode): DataType = # TODO: no full support for all datatypes that glTF may provide # semicongine/core/gpu_data should maybe generated with macros to allow for all combinations - debugecho accessor.pretty() let componentType = ACCESSOR_TYPE_MAP[accessor["componentType"].getInt()] let theType = accessor["type"].getStr() case theType @@ -73,7 +72,7 @@ proc getAccessorData(root: JsonNode, accessor: JsonNode, mainBuffer: var seq[uint8]): DataList = - result.thetype = accessor.getGPUType() + result = newDataList(thetype=accessor.getGPUType()) result.initData(uint32(accessor["count"].getInt())) let bufferView = root["bufferViews"][accessor["bufferView"].getInt()] @@ -104,6 +103,8 @@ for attribute, accessor in primitiveNode["attributes"].pairs: let data = root.getAccessorData(root["accessors"][accessor.getInt()], mainBuffer) mesh.appendMeshData(attribute, data) + if attribute == "POSITION": + transform[Vec3f](mesh, "POSITION", scale3d(1'f32, -1'f32, 1'f32)) if primitiveNode.hasKey("indices"): assert mesh.indexType != None @@ -111,13 +112,13 @@ var tri: seq[uint32] case data.thetype of UInt16: - for entry in getValues[uint16](data): + for entry in getValues[uint16](data)[]: tri.add uint32(entry) if tri.len == 3: 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 uint32(entry) if tri.len == 3: mesh.appendIndicesData(tri[0], tri[1], tri[2]) @@ -149,7 +150,7 @@ # prepare mesh attributes for attribute, accessor in meshNode["primitives"][0]["attributes"].pairs: - result.setMeshData(attribute, DataList(thetype: root["accessors"][accessor.getInt()].getGPUType())) + result.setMeshData(attribute, newDataList(thetype=root["accessors"][accessor.getInt()].getGPUType())) # add all mesh data for primitive in meshNode["primitives"]: @@ -235,3 +236,5 @@ for scene in data.structuredContent["scenes"]: result.add data.structuredContent.loadScene(scene, data.binaryBufferData) + + debugecho data.structuredContent.pretty()