Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Pessimistress committed Mar 4, 2024
1 parent ca836df commit 6927e36
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
19 changes: 11 additions & 8 deletions modules/core/src/lib/attribute/data-column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ import log from '../../utils/log';

import type {TypedArray, NumericArray, TypedArrayConstructor} from '../../types/types';

export type DataType = Exclude<VertexType, 'float16'>;
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. */
Expand Down Expand Up @@ -93,17 +96,17 @@ export type DataColumnOptions<Options> = 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<Options> = DataColumnOptions<Options> & {
type: VertexType;
type: DataType;
size: number;
logicalType?: VertexType | 'float64';
logicalType?: LogicalDataType;
normalized: boolean;
bytesPerElement: number;
defaultValue: number[];
Expand Down Expand Up @@ -144,7 +147,7 @@ export default class DataColumn<Options, State> {
? [defaultValue]
: defaultValue || new Array(this.size).fill(0);

let bufferType: VertexType;
let bufferType: DataType;
if (doublePrecision) {
bufferType = 'float32';
} else if (!logicalType && opts.isIndexed) {
Expand Down Expand Up @@ -371,7 +374,7 @@ export default class DataColumn<Options, State> {
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;
Expand Down
8 changes: 3 additions & 5 deletions modules/core/src/lib/attribute/gl-utils.ts
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 6927e36

Please sign in to comment.