From 6927e36e9be2f4afc53459fd3e7c00e8c18bdd8b Mon Sep 17 00:00:00 2001 From: Xiaoji Chen Date: Mon, 4 Mar 2024 08:24:50 -0800 Subject: [PATCH] address comments --- modules/core/src/lib/attribute/data-column.ts | 19 +++++++++++-------- modules/core/src/lib/attribute/gl-utils.ts | 8 +++----- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/modules/core/src/lib/attribute/data-column.ts b/modules/core/src/lib/attribute/data-column.ts index b0ab727b23a..958b561ac25 100644 --- a/modules/core/src/lib/attribute/data-column.ts +++ b/modules/core/src/lib/attribute/data-column.ts @@ -14,13 +14,16 @@ import log from '../../utils/log'; import type {TypedArray, NumericArray, TypedArrayConstructor} from '../../types/types'; +export type DataType = Exclude; +export type LogicalDataType = DataType | 'float64'; + export type BufferAccessor = { /** Vertex data type. */ - type?: VertexType; + type?: DataType; /** The number of elements per vertex attribute. */ size?: number; /** 1 if instanced. */ - divisor?: 1 | 0; + divisor?: number; /** Offset of the first vertex attribute into the buffer, in bytes. */ offset?: number; /** The offset between the beginning of consecutive vertex attributes, in bytes. */ @@ -93,17 +96,17 @@ export type DataColumnOptions = Options & /** Vertex data type. * @default 'float32' */ - type?: VertexType | 'float64'; + type?: LogicalDataType; /** Internal API, use `type` instead */ - logicalType?: VertexType | 'float64'; + logicalType?: LogicalDataType; isIndexed?: boolean; defaultValue?: number | number[]; }; export type DataColumnSettings = DataColumnOptions & { - type: VertexType; + type: DataType; size: number; - logicalType?: VertexType | 'float64'; + logicalType?: LogicalDataType; normalized: boolean; bytesPerElement: number; defaultValue: number[]; @@ -144,7 +147,7 @@ export default class DataColumn { ? [defaultValue] : defaultValue || new Array(this.size).fill(0); - let bufferType: VertexType; + let bufferType: DataType; if (doublePrecision) { bufferType = 'float32'; } else if (!logicalType && opts.isIndexed) { @@ -371,7 +374,7 @@ export default class DataColumn { accessor.type = 'float32'; } else { const type = dataTypeFromTypedArray(opts.value); - accessor.type = accessor.normalized ? (type.replace('int', 'norm') as VertexType) : type; + accessor.type = accessor.normalized ? (type.replace('int', 'norm') as DataType) : type; } } accessor.bytesPerElement = opts.value.BYTES_PER_ELEMENT; diff --git a/modules/core/src/lib/attribute/gl-utils.ts b/modules/core/src/lib/attribute/gl-utils.ts index 1c463606c1f..19724a64823 100644 --- a/modules/core/src/lib/attribute/gl-utils.ts +++ b/modules/core/src/lib/attribute/gl-utils.ts @@ -1,13 +1,11 @@ import {getTypedArrayFromDataType, getDataTypeFromTypedArray} from '@luma.gl/core'; -import type {BufferAttributeLayout, VertexType, VertexFormat} from '@luma.gl/core'; +import type {BufferAttributeLayout, VertexFormat} from '@luma.gl/core'; import type {TypedArrayConstructor} from '../../types/types'; -import type {BufferAccessor, DataColumnSettings} from './data-column'; +import type {BufferAccessor, DataColumnSettings, LogicalDataType} from './data-column'; -export function typedArrayFromDataType(type: VertexType | 'float64'): TypedArrayConstructor { +export function typedArrayFromDataType(type: LogicalDataType): TypedArrayConstructor { // Sorted in some order of likelihood to reduce amount of comparisons switch (type) { - case 'float16': - return Float32Array; case 'float64': return Float64Array; default: